Class DataTable

java.lang.Object
mgui.interfaces.AbstractInterfaceObject
mgui.datasources.DataTable
All Implemented Interfaces:
java.lang.Cloneable, DataFieldListener, DataSourceItem, SQLObject, InterfaceObject, PopupMenuObject, NamedObject, TreeObject, CleanableObject, XMLObject, IconObject

public class DataTable
extends AbstractInterfaceObject
implements java.lang.Cloneable, IconObject, PopupMenuObject, DataSourceItem, DataFieldListener
General data table object specifying the organization of data into fields.
Since:
1.0
Version:
1.0
Author:
Andrew Reid
  • Field Details

    • sortFields

      public java.util.ArrayList<java.lang.String> sortFields
    • fields

      protected java.util.HashMap<java.lang.String,​DataField> fields
    • indexes

      protected java.util.HashMap<java.lang.String,​DataIndex<?>> indexes
    • treeNode

      public DataSetTreeNode treeNode
    • dataSource

      public DataSource dataSource
    • sort_fields

      protected boolean sort_fields
  • Constructor Details

    • DataTable

      public DataTable()
    • DataTable

      public DataTable​(java.lang.String name)
  • Method Details

    • getIcon

      public static javax.swing.Icon getIcon()
    • getObjectIcon

      public javax.swing.Icon getObjectIcon()
      Description copied from interface: IconObject
      Returns the Icon associated with this object.
      Specified by:
      getObjectIcon in interface IconObject
      Returns:
    • init

      protected void init()
    • setDataSource

      public void setDataSource​(DataSource ds)
      Specified by:
      setDataSource in interface DataSourceItem
    • getDataSource

      public DataSource getDataSource()
      Specified by:
      getDataSource in interface DataSourceItem
    • hasSortedFields

      public boolean hasSortedFields()
      Specified by:
      hasSortedFields in interface DataSourceItem
    • setSortedFields

      public void setSortedFields​(boolean b)
    • setFields

      public void setFields​(java.util.ArrayList<DataField> f)
    • getKeyFields

      public java.util.ArrayList<java.lang.String> getKeyFields()
      Returns a list of this table's key fields.
      Returns:
    • getSQLStatement

      public java.lang.String getSQLStatement​(java.lang.String[] sort_fields)
    • getSQLStatement

      public java.lang.String getSQLStatement()
      Description copied from interface: SQLObject
      Produces an SQL statement with the default character set
      Specified by:
      getSQLStatement in interface SQLObject
      Returns:
    • getSQLStatement

      public java.lang.String getSQLStatement​(java.lang.String[] sort_fields, DataSourceDriver driver)
    • getSQLStatement

      public java.lang.String getSQLStatement​(DataSourceDriver driver)
      Description copied from interface: SQLObject
      Produces an SQL statement with a driver-specific character set
      Specified by:
      getSQLStatement in interface SQLObject
      Returns:
    • getSQLSortStr

      public java.lang.String getSQLSortStr​(java.lang.String[] sort_fields)
    • getSQLSortStr

      public java.lang.String getSQLSortStr​(java.lang.String[] sort_fields, DataSourceDriver driver)
    • getSQLSortStr

      public java.lang.String getSQLSortStr()
    • getSQLSortStr

      public java.lang.String getSQLSortStr​(DataSourceDriver driver)
    • addField

      public boolean addField​(DataField field)
      Adds a new field to this table. Note: this does not update the data source. To add a field to a live table, use DataSource.addField.
      Parameters:
      field -
      Returns:
    • hasField

      public boolean hasField​(java.lang.String name)
    • removeField

      public boolean removeField​(DataField field)
    • removeField

      public boolean removeField​(java.lang.String field)
    • getFields

      public java.util.HashMap<java.lang.String,​DataField> getFields()
    • getFieldList

      public java.util.ArrayList<DataField> getFieldList()
    • getField

      public DataField getField​(java.lang.String name)
    • setKeyField

      public boolean setKeyField​(java.lang.String name)
    • unsetKeyField

      public boolean unsetKeyField​(java.lang.String name)
    • getFieldClass

      public java.lang.Class<? extends java.lang.Comparable<?>> getFieldClass​(java.lang.String name)
    • addIndex

      public void addIndex​(java.lang.String name, DataIndex<?> index)
    • getIndexes

      public java.util.HashMap<java.lang.String,​DataIndex<?>> getIndexes()
    • getIndex

      public DataIndex<?> getIndex​(java.lang.String name)
    • getFilteredByList

      public DataTable getFilteredByList​(java.util.ArrayList<java.lang.Comparable> list, java.lang.String filter_field) throws DataSourceException
      Enumerates the indices of records in this table where filter_field matches an element in list. Creates a temporary table in this table's DataSource and returns that table.

      If an error is encountered in the table creation process, a DataSourceException is thrown.

      Parameters:
      list -
      join_field -
      Returns:
      Throws:
      DataSourceException
    • clone

      public java.lang.Object clone()
      Overrides:
      clone in class java.lang.Object
    • setTreeNode

      public void setTreeNode​(InterfaceTreeNode treeNode)
      Description copied from interface: TreeObject
      Sets the children for this node's InterfaceTreeNode.
      Specified by:
      setTreeNode in interface TreeObject
      Overrides:
      setTreeNode in class AbstractInterfaceObject
    • getTreeLabel

      public java.lang.String getTreeLabel()
      Description copied from interface: TreeObject
      Returns the label text to appear in a tree node.
      Specified by:
      getTreeLabel in interface TreeObject
      Overrides:
      getTreeLabel in class AbstractInterfaceObject
      Returns:
    • getPopupMenu

      public InterfacePopupMenu getPopupMenu()
      Description copied from interface: PopupMenuObject
      Produces and returns a popup menu for this object.
      Specified by:
      getPopupMenu in interface PopupMenuObject
      Returns:
    • getPopupMenu

      public InterfacePopupMenu getPopupMenu​(java.util.List<java.lang.Object> selected)
      Description copied from interface: PopupMenuObject
      Produces and returns a popup menu for this object. Allows an associated list of objects to be passed as an argument.
      Specified by:
      getPopupMenu in interface PopupMenuObject
      Returns:
    • handlePopupEvent

      public void handlePopupEvent​(java.awt.event.ActionEvent e)
      Description copied from interface: PopupMenuObject
      Handles an event on this object's popup menu.
      Specified by:
      handlePopupEvent in interface PopupMenuObject
    • showPopupMenu

      public void showPopupMenu​(java.awt.event.MouseEvent e)
      Description copied from interface: PopupMenuObject
      Shows a popup menu at the point of the given MouseEvent.
      Specified by:
      showPopupMenu in interface PopupMenuObject
    • getAttributeList

      public AttributeList getAttributeList()
    • toString

      public java.lang.String toString()
      Overrides:
      toString in class java.lang.Object
    • getDTD

      public java.lang.String getDTD()
      Description copied from interface: XMLObject
      Returns the Data Type Declaration (DTD) for this object's XML representation

      See http://en.wikipedia.org/wiki/Document_Type_Definition for a description.

      Specified by:
      getDTD in interface XMLObject
      Returns:
    • getXMLSchema

      public java.lang.String getXMLSchema()
      Description copied from interface: XMLObject
      Returns the XML schema for this object's XML representation

      See http://en.wikipedia.org/wiki/XML_schema.

      Specified by:
      getXMLSchema in interface XMLObject
      Returns:
    • getXML

      public java.lang.String getXML()
      Description copied from interface: XMLObject
      Returns this object's XML representation as a single string. NOTE: this is not feasible for larger objects and containers, thus may not be implemented for these objects. Use the XMLObject.writeXML(int,java.io.Writer,mgui.io.standard.xml.XMLOutputOptions,mgui.interfaces.ProgressUpdater) functions to write larger objects to file.
      Specified by:
      getXML in interface XMLObject
      Returns:
    • getXML

      public java.lang.String getXML​(int tab)
      Description copied from interface: XMLObject
      Returns this object's XML representation as a single string. NOTE: this is not feasible for larger objects and containers, thus may not be implemented for these objects. Use the XMLObject.writeXML(int,java.io.Writer,mgui.io.standard.xml.XMLOutputOptions,mgui.interfaces.ProgressUpdater) functions to write larger objects to file.
      Specified by:
      getXML in interface XMLObject
      Parameters:
      tab - The number of tabs to place before the opening XML wrapper
      Returns:
    • handleXMLElementStart

      public void handleXMLElementStart​(java.lang.String localName, org.xml.sax.Attributes attributes, XMLObject.XMLType type) throws org.xml.sax.SAXException
      Description copied from interface: XMLObject
      Handles the start of an XML element.
      Specified by:
      handleXMLElementStart in interface XMLObject
      Parameters:
      localName - Local name of the element
      attributes - Set of element attributes
      type - The XMLType of this element
      Throws:
      org.xml.sax.SAXException
    • handleXMLElementEnd

      public void handleXMLElementEnd​(java.lang.String localName) throws org.xml.sax.SAXException
      Description copied from interface: XMLObject
      Handles the end of an XML element.
      Specified by:
      handleXMLElementEnd in interface XMLObject
      Parameters:
      localName - Local name of the element
      Throws:
      org.xml.sax.SAXException
    • handleXMLString

      public void handleXMLString​(java.lang.String s) throws org.xml.sax.SAXException
      Description copied from interface: XMLObject
      Handles a string within an XML element.
      Specified by:
      handleXMLString in interface XMLObject
      Parameters:
      s - String to handle
      Throws:
      org.xml.sax.SAXException
    • getLocalName

      public java.lang.String getLocalName()
      Description copied from interface: XMLObject
      Returns the local name associated with this XML object.
      Specified by:
      getLocalName in interface XMLObject
      Returns:
    • writeXML

      public void writeXML​(int tab, java.io.Writer writer, XMLOutputOptions options, ProgressUpdater progress_bar) throws java.io.IOException
      Description copied from interface: XMLObject
      Writes the XML representation of this object to file. The basic contract for this method is that it should not write a newline character at its start or end. The default format of XMLFormat.Ascii will be used.
      Specified by:
      writeXML in interface XMLObject
      Parameters:
      tab - The number of tabs to place before the XML text
      writer - The writer
      options - XMLOutputOptions defining the write parameters
      progress_bar - Optional progress updater (may be null)
      Throws:
      java.io.IOException
    • writeXML

      public void writeXML​(int tab, java.io.Writer writer, ProgressUpdater progress_bar) throws java.io.IOException
      Description copied from interface: XMLObject
      Writes the XML representation of this object to file, as XMLType.Normal. The default format of XMLFormat.Ascii will be used. The basic contract for this method is that it should not write a newline character at its start or end.
      Specified by:
      writeXML in interface XMLObject
      Parameters:
      tab - The number of tabs to place before the XML text
      writer - The writer
      progress_bar - Optional progress updater (may be null)
      Throws:
      java.io.IOException
    • writeXML

      public void writeXML​(int tab, java.io.Writer writer) throws java.io.IOException
      Description copied from interface: XMLObject
      Writes the XML representation of this object to file. The basic contract for this method is that it should not write a newline character at its start or end. The default format of XMLFormat.Ascii will be used.
      Specified by:
      writeXML in interface XMLObject
      Parameters:
      tab - The number of tabs to place before the XML text
      writer - The writer
      Throws:
      java.io.IOException
    • getShortXML

      public java.lang.String getShortXML​(int tab)
      Description copied from interface: XMLObject
      Returns a short XML representation of this object.
      Specified by:
      getShortXML in interface XMLObject
      Returns:
    • getPrimaryKeys

      public java.util.ArrayList<java.lang.String> getPrimaryKeys()
      Returns a list of the primary keys in this table
      Returns:
    • dataFieldChanged

      public void dataFieldChanged​(DataFieldEvent e)
      Specified by:
      dataFieldChanged in interface DataFieldListener