Package mgui.datasources
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
-
Nested Class Summary
Nested classes/interfaces inherited from interface mgui.interfaces.xml.XMLObject
XMLObject.XMLEncoding, XMLObject.XMLType
-
Field Summary
Fields Modifier and Type Field Description DataSource
dataSource
protected java.util.HashMap<java.lang.String,DataField>
fields
protected java.util.HashMap<java.lang.String,DataIndex<?>>
indexes
protected boolean
sort_fields
java.util.ArrayList<java.lang.String>
sortFields
DataSetTreeNode
treeNode
Fields inherited from class mgui.interfaces.AbstractInterfaceObject
isDestroyed, tree_nodes
-
Constructor Summary
-
Method Summary
Modifier and Type Method Description boolean
addField(DataField field)
Adds a new field to this table.void
addIndex(java.lang.String name, DataIndex<?> index)
java.lang.Object
clone()
void
dataFieldChanged(DataFieldEvent e)
AttributeList
getAttributeList()
DataSource
getDataSource()
java.lang.String
getDTD()
Returns the Data Type Declaration (DTD) for this object's XML representationDataField
getField(java.lang.String name)
java.lang.Class<? extends java.lang.Comparable<?>>
getFieldClass(java.lang.String name)
java.util.ArrayList<DataField>
getFieldList()
java.util.HashMap<java.lang.String,DataField>
getFields()
DataTable
getFilteredByList(java.util.ArrayList<java.lang.Comparable> list, java.lang.String filter_field)
Enumerates the indices of records in this table wherefilter_field
matches an element inlist
.static javax.swing.Icon
getIcon()
DataIndex<?>
getIndex(java.lang.String name)
java.util.HashMap<java.lang.String,DataIndex<?>>
getIndexes()
java.util.ArrayList<java.lang.String>
getKeyFields()
Returns a list of this table's key fields.java.lang.String
getLocalName()
Returns the local name associated with this XML object.javax.swing.Icon
getObjectIcon()
Returns theIcon
associated with this object.InterfacePopupMenu
getPopupMenu()
Produces and returns a popup menu for this object.InterfacePopupMenu
getPopupMenu(java.util.List<java.lang.Object> selected)
Produces and returns a popup menu for this object.java.util.ArrayList<java.lang.String>
getPrimaryKeys()
Returns a list of the primary keys in this tablejava.lang.String
getShortXML(int tab)
Returns a short XML representation of this object.java.lang.String
getSQLSortStr()
java.lang.String
getSQLSortStr(java.lang.String[] sort_fields)
java.lang.String
getSQLSortStr(java.lang.String[] sort_fields, DataSourceDriver driver)
java.lang.String
getSQLSortStr(DataSourceDriver driver)
java.lang.String
getSQLStatement()
Produces an SQL statement with the default character setjava.lang.String
getSQLStatement(java.lang.String[] sort_fields)
java.lang.String
getSQLStatement(java.lang.String[] sort_fields, DataSourceDriver driver)
java.lang.String
getSQLStatement(DataSourceDriver driver)
Produces an SQL statement with a driver-specific character setjava.lang.String
getTreeLabel()
Returns the label text to appear in a tree node.java.lang.String
getXML()
Returns this object's XML representation as a single string.java.lang.String
getXML(int tab)
Returns this object's XML representation as a single string.java.lang.String
getXMLSchema()
Returns the XML schema for this object's XML representationvoid
handlePopupEvent(java.awt.event.ActionEvent e)
Handles an event on this object's popup menu.void
handleXMLElementEnd(java.lang.String localName)
Handles the end of an XML element.void
handleXMLElementStart(java.lang.String localName, org.xml.sax.Attributes attributes, XMLObject.XMLType type)
Handles the start of an XML element.void
handleXMLString(java.lang.String s)
Handles a string within an XML element.boolean
hasField(java.lang.String name)
boolean
hasSortedFields()
protected void
init()
boolean
removeField(java.lang.String field)
boolean
removeField(DataField field)
void
setDataSource(DataSource ds)
void
setFields(java.util.ArrayList<DataField> f)
boolean
setKeyField(java.lang.String name)
void
setSortedFields(boolean b)
void
setTreeNode(InterfaceTreeNode treeNode)
Sets the children for this node'sInterfaceTreeNode
.void
showPopupMenu(java.awt.event.MouseEvent e)
Shows a popup menu at the point of the givenMouseEvent
.java.lang.String
toString()
boolean
unsetKeyField(java.lang.String name)
void
writeXML(int tab, java.io.Writer writer)
Writes the XML representation of this object to file.void
writeXML(int tab, java.io.Writer writer, ProgressUpdater progress_bar)
Writes the XML representation of this object to file, asXMLType.Normal
.void
writeXML(int tab, java.io.Writer writer, XMLOutputOptions options, ProgressUpdater progress_bar)
Writes the XML representation of this object to file.Methods inherited from class mgui.interfaces.AbstractInterfaceObject
clean, destroy, getName, isDestroyed, issueTreeNode, setName, updateTreeNodes
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface mgui.interfaces.util.CleanableObject
clean
Methods inherited from interface mgui.interfaces.InterfaceObject
destroy, isDestroyed
Methods inherited from interface mgui.interfaces.NamedObject
getName, setName
Methods inherited from interface mgui.interfaces.trees.TreeObject
issueTreeNode
-
Field Details
-
sortFields
public java.util.ArrayList<java.lang.String> sortFields -
fields
-
indexes
-
treeNode
-
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 theIcon
associated with this object.- Specified by:
getObjectIcon
in interfaceIconObject
- Returns:
-
init
protected void init() -
setDataSource
- Specified by:
setDataSource
in interfaceDataSourceItem
-
getDataSource
- Specified by:
getDataSource
in interfaceDataSourceItem
-
hasSortedFields
public boolean hasSortedFields()- Specified by:
hasSortedFields
in interfaceDataSourceItem
-
setSortedFields
public void setSortedFields(boolean b) -
setFields
-
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 interfaceSQLObject
- Returns:
-
getSQLStatement
-
getSQLStatement
Description copied from interface:SQLObject
Produces an SQL statement with a driver-specific character set- Specified by:
getSQLStatement
in interfaceSQLObject
- Returns:
-
getSQLSortStr
public java.lang.String getSQLSortStr(java.lang.String[] sort_fields) -
getSQLSortStr
-
getSQLSortStr
public java.lang.String getSQLSortStr() -
getSQLSortStr
-
addField
Adds a new field to this table. Note: this does not update the data source. To add a field to a live table, useDataSource.addField
.- Parameters:
field
-- Returns:
-
hasField
public boolean hasField(java.lang.String name) -
removeField
-
removeField
public boolean removeField(java.lang.String field) -
getFields
-
getFieldList
-
getField
-
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
-
getIndexes
-
getIndex
-
getFilteredByList
public DataTable getFilteredByList(java.util.ArrayList<java.lang.Comparable> list, java.lang.String filter_field) throws DataSourceExceptionEnumerates the indices of records in this table wherefilter_field
matches an element inlist
. Creates a temporary table in this table'sDataSource
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 classjava.lang.Object
-
setTreeNode
Description copied from interface:TreeObject
Sets the children for this node'sInterfaceTreeNode
.- Specified by:
setTreeNode
in interfaceTreeObject
- Overrides:
setTreeNode
in classAbstractInterfaceObject
-
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 interfaceTreeObject
- Overrides:
getTreeLabel
in classAbstractInterfaceObject
- Returns:
-
getPopupMenu
Description copied from interface:PopupMenuObject
Produces and returns a popup menu for this object.- Specified by:
getPopupMenu
in interfacePopupMenuObject
- Returns:
-
getPopupMenu
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 interfacePopupMenuObject
- 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 interfacePopupMenuObject
-
showPopupMenu
public void showPopupMenu(java.awt.event.MouseEvent e)Description copied from interface:PopupMenuObject
Shows a popup menu at the point of the givenMouseEvent
.- Specified by:
showPopupMenu
in interfacePopupMenuObject
-
getAttributeList
-
toString
public java.lang.String toString()- Overrides:
toString
in classjava.lang.Object
-
getDTD
public java.lang.String getDTD()Description copied from interface:XMLObject
Returns the Data Type Declaration (DTD) for this object's XML representationSee http://en.wikipedia.org/wiki/Document_Type_Definition for a description.
-
getXMLSchema
public java.lang.String getXMLSchema()Description copied from interface:XMLObject
Returns the XML schema for this object's XML representation- Specified by:
getXMLSchema
in interfaceXMLObject
- 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 theXMLObject.writeXML(int,java.io.Writer,mgui.io.standard.xml.XMLOutputOptions,mgui.interfaces.ProgressUpdater)
functions to write larger objects to file. -
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 theXMLObject.writeXML(int,java.io.Writer,mgui.io.standard.xml.XMLOutputOptions,mgui.interfaces.ProgressUpdater)
functions to write larger objects to file. -
handleXMLElementStart
public void handleXMLElementStart(java.lang.String localName, org.xml.sax.Attributes attributes, XMLObject.XMLType type) throws org.xml.sax.SAXExceptionDescription copied from interface:XMLObject
Handles the start of an XML element.- Specified by:
handleXMLElementStart
in interfaceXMLObject
- Parameters:
localName
- Local name of the elementattributes
- Set of element attributestype
- TheXMLType
of this element- Throws:
org.xml.sax.SAXException
-
handleXMLElementEnd
public void handleXMLElementEnd(java.lang.String localName) throws org.xml.sax.SAXExceptionDescription copied from interface:XMLObject
Handles the end of an XML element.- Specified by:
handleXMLElementEnd
in interfaceXMLObject
- Parameters:
localName
- Local name of the element- Throws:
org.xml.sax.SAXException
-
handleXMLString
public void handleXMLString(java.lang.String s) throws org.xml.sax.SAXExceptionDescription copied from interface:XMLObject
Handles a string within an XML element.- Specified by:
handleXMLString
in interfaceXMLObject
- 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 interfaceXMLObject
- Returns:
-
writeXML
public void writeXML(int tab, java.io.Writer writer, XMLOutputOptions options, ProgressUpdater progress_bar) throws java.io.IOExceptionDescription 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 ofXMLFormat.Ascii
will be used. -
writeXML
public void writeXML(int tab, java.io.Writer writer, ProgressUpdater progress_bar) throws java.io.IOExceptionDescription copied from interface:XMLObject
Writes the XML representation of this object to file, asXMLType.Normal
. The default format ofXMLFormat.Ascii
will be used. The basic contract for this method is that it should not write a newline character at its start or end. -
writeXML
public void writeXML(int tab, java.io.Writer writer) throws java.io.IOExceptionDescription 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 ofXMLFormat.Ascii
will be used. -
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 interfaceXMLObject
- Returns:
-
getPrimaryKeys
public java.util.ArrayList<java.lang.String> getPrimaryKeys()Returns a list of the primary keys in this table- Returns:
-
dataFieldChanged
- Specified by:
dataFieldChanged
in interfaceDataFieldListener
-