Class AttributeStore

All Implemented Interfaces:
PopupActivationListener, Serializable, Comparable, EventListener, ListSelectionListener, TableModel
Direct Known Subclasses:
AccessTableModel, AppendStore, BlockStore, CoreTable, CrosstabStore, CrosstabStore.Snapshot, CSVStore, CubeStore, DBaseAttributeStore, FormatTable, InfoFile, JDBCStore, MultiPeriodRamAttributeStore, MultiRowCache, PatchStore, PeriodFlattenedStore, RamAttributeStore, RangeStore, RelationalStore, RowCacheStore, ShapeStore, TargetTable, TextStore, TrackAttributeStore, TransientUpdateStore, TransposePeriodTable, TransposeRowTable, TransposeTable

public abstract class AttributeStore extends AbstractTableModel implements ListSelectionListener, PopupActivationListener, Comparable
The AttributeStore is a fundemental base class for representing tabular data. This class has methods for retrieving column names, cell values, managing selected rows and other utility methods such as obtaining lists of uniques column values.

The model for AttributeStore object is simple: data values are retrieved by row and column number. Column have names and data types determined from the input dataset. Use the findColumn(String) method to determine the column number for a column number. To retrieve data use one of the getValueAt(int, int, int), doubleValue(int, int), integerValue(int, int) or booleanValue(int, int) methods.

AttributeStore is an abstract class, and cannot be instantiated directly. If you want to open a file then use the static method openOrReuse(String). This will determine the correct classes to use to open file and access the data.

The subclasses of AttributeStore load shapefiles, coverages, dbase files, info tables or temporary memory based files. In addition the Patchworks model creates many AttributeStore objects that reflect the inner structures of the simulation model.

Here are examples of opening files:

 // Open a dBase file
 table1 = AttributeStore.openOrReuse("C:/Projects/proj1/data/attributes.dbf");

 // Open a CSV file
 table2 = AttributeStore.openOrReuse("C:/Projects/proj1/data/sheet.csv");

 // Open a Shapefile (including associated attributes)
 table3 = AttributeStore.openOrReuse("C:/Projects/proj1/data/spatial.shp");
 

The Patchworks model exports a number of AttributeStore object that reflect internal simulation data. Here are a few examples:

 /* Get a reference to the block attribute table */
 blocks  = control.getBlockTable();
 
 /* Get a reference to the road network table */
 net = control.getNetworkTable();
 
 /* Get a reference to the targets table */
 net = control.getTargetTable();
 
See the documentation of the Control object for more information.

The simulation model tables often contain temporal data. Many of the data access methods provide options to specify the planning period to retrieve the data from.

Many of the reports and tools in the Patchworks toolkit use expressions to select and extract data from the tables, such as the select(java.awt.Window, java.lang.String) or uniqueValues(String) methods. Expressions follow the syntax described in the Expression class.

Tables may be joined together using the addRelate(ca.spatial.table.AttributeStore, java.lang.String, java.lang.String) method. This method performs a 1:MANY relate between the base and joined table (left outer join in SQL parlance). Joined tables may be joined to other tables, allowing a flexible scheme to manage relates. Here is an example of a relational join:

 base = Control.getBlockTable();
 table1 = AttributeStore.openOrReuse("C:/Projects/proj1/data/attributes.dbf");
 myrelate = base.addRelate(table1, "BLOCK", "BLOCK");
 
The result of the join is a new AttributeStore reference and the original AttributeStore references are unchanged. The original AttributeStore references must remain open and available however, because these will be used by the new relational AttributeStore reference to access it's data.
See Also:
GeoRelationalStore, CrosstabStore, AppendStore, Serialized Form
  • Field Details

    • SELECT_NEW

      public static final int SELECT_NEW
      Specify the the selection query operator should create a new selected set.
      See Also:
      Constant Field Values
    • SELECT_ADD

      public static final int SELECT_ADD
      Specify the the selection query operator should add records to the currently selected set.
      See Also:
      Constant Field Values
    • SELECT_FROM

      public static final int SELECT_FROM
      Specify the the selection query operator should remove records from the currently selected set.
      See Also:
      Constant Field Values
  • Constructor Details

    • AttributeStore

      public AttributeStore()
  • Method Details

    • addToGlobalStoreList

      public static AttributeStore addToGlobalStoreList(AttributeStore as)
      Add this table to the global list of open tables. This list is presented in the 'Use existing' list of the 'Add Layer' dialog. Tables that are added to this list will be automatically removed when they are no longer being used.
      Parameters:
      as - The reference to the AttributeStore to add to the global list
      Returns:
      If an AttributeStore with the same cannonical identifier is already store in the global list then this refererence is returned, otherwise return as.
    • removeFromGlobalStoreList

      public static void removeFromGlobalStoreList(AttributeStore as)
      Remove a table from the global list of open tables. This is usually not necessary since an automatic mechanism is used to remove unreferenced tables. References are also removed when the table is manually closed using the close() method.
      Parameters:
      as - The reference to the AttributeStore to remove from the global list
    • getOpenStores

      public static Set<AttributeStore> getOpenStores()
      Get the global list of open tables.
      Returns:
      A Set containing references currently contained in the global list
    • getStoreByTitle

      public static AttributeStore getStoreByTitle(String title)
      Search the global list of open tables and return the first one that matches the specified title.
      Parameters:
      title - The title of the AttributeStore to be searched for.
      Returns:
      An AttributeStore with the matching title, or null if no matching title is found.
    • getStoreByShortName

      public static AttributeStore getStoreByShortName(String shortName)
      Search the global list of open tables and return the first one that matches the specified short name.
      Parameters:
      shortName - The short name of the AttributeStore to be searched for.
      Returns:
      An AttributeStore with the matching short name, or null if no matching short name is found.
    • openOrReuse

      public static AttributeStore openOrReuse(String spec) throws Exception
      Try to find a cached file that has the same filename as the name that is provided. If a file with this name has already been opened then it will be returned. If the file does not exist in the cache then it will be opened and added to the cache.
      Parameters:
      spec - The name of the file or specification string to open
      Returns:
      A handle to the opened file.
      Throws:
      Exception - An exception if the file cannot be opened.
    • openOrReuse

      public static AttributeStore openOrReuse(String spec, String encoding) throws Exception
      Try to find a cached file that has the same filename as the name that is provided. If a file with this name has already been opened then it will be returned. If the file does not exist in the cache then it will be opened and added to the cache.
      Parameters:
      spec - The name of the file or specification string to open
      encoding - The encoding to be used to read the file contents. This parameter only applies to a few of the file types (e.g. DBaseAttributeStore, ShapeStore, CSVStore).
      Returns:
      A handle to the opened file.
      Throws:
      Exception - An exception if the file cannot be opened.
    • getOpenStore

      public static AttributeStore getOpenStore(String spec, String encoding) throws Exception
      Try to find a cached file that has the same filename as the name that is provided. If the file does not exist in the cache then the method will return null.
      Parameters:
      spec - The name of the file or specification string to open
      encoding - the character encoding to use
      Returns:
      A handle to the opened file, or null if the file is not already cached.
      Throws:
      Exception - An exception if the specification string cannot be parsed successfully.
    • getOpenStore

      public static AttributeStore getOpenStore(String spec) throws Exception
      Try to find a cached file that has the same filename as the name that is provided, using the default character encoding. If the file does not exist in the cache then the method will return null.
      Parameters:
      spec - The name of the file or specification string to open
      Returns:
      A handle to the opened file, or null if the file is not already cached.
      Throws:
      Exception - An exception if the specification string cannot be parsed successfully.
    • getOpenStore

      public static AttributeStore getOpenStore(TableSpec tablespec)
      Try to find a cached file that has the same filename as the name that is provided. If the file does not exist in the cache then the mthod will return null.
      Parameters:
      tablespec - A TableSpec object that describes the data set of interest.
      Returns:
      A handle to the opened file, or null if the file is not already cached.
    • getTableSpec

      public final TableSpec getTableSpec()
      Return a structure that describes this table
      Returns:
      The TableSpec for this file
    • setTableSpec

      public final void setTableSpec(TableSpec spec)
      Set the table spec structure that describes this data set. This routine should only be called if implementing a new type of virtual data store.
      Parameters:
      spec - A {*link TableSpec} that describes this AttributeStore.
    • getCanonicalName

      public String getCanonicalName()
      Return a string that uniquely identifies this table and provides information can be used to reconstruct the table. This handle can be passed to the openOrReuse(java.lang.String) method to get an existing or new instance of the table.
      Returns:
      The canonical name of this store.
    • getTableName

      public String getTableName()
      Return a string that uniquely identifies this table and provides information can be used to reconstruct the table. This handle can be passed to the openOrReuse(java.lang.String) method to get an existing or new instance of the table.
      Returns:
      The common name of this store.
    • setCwd

      public static void setCwd(String path)
      Set the default working directory
    • setCwd

      public static void setCwd(File f)
    • getCwd

      public static File getCwd()
      Retireve the default working directory
    • absoluteFile

      public static File absoluteFile(String fileName)
      Convert a relative path to an absolute file
    • absoluteFile

      public static File absoluteFile(File file)
      Convert a relative path to an absolute file
    • absolutePath

      public static String absolutePath(File file)
      Convert a relative path to an absolute path
    • absolutePath

      public static String absolutePath(String fileName)
      Convert a relative path to an absolute path
    • relativePath

      public static String relativePath(String filename, int maxUplinks)
      Make a relative path
      Parameters:
      filename - the filename to convert to relative
      maxUplinks - the maximum number of upward links allowed. If more uplinks occur then the filename will not be relativized.
    • close

      public void close()
      Close the table and release resources. The table should be used again after this method has been called.

      In many cases you do not need to call this method when you are finished using a table. Most tables will close automatically when they are no longer referenced.

      It is possible that this method will be deprecated or removed in a future release.

    • getSnapshot

      public AttributeStore getSnapshot(boolean useSelected)
      Return a snapshot of the dataset at a given moment. The general behaviour of this method is to simply return the same datastore. Some specialized datastores (CrosstabStore), will compute an instance that can be used and then disposed.

      The default behaviour for concrete store types simply returns 'this'. Synthetic types (e.g. CrosstabStore will return a materialization of the view.

      Parameters:
      useSelected - If true then only use the currently selected records in computing the snapshot.
      Returns:
      An AttributeStore representing a materialization of the store.
    • getSnapshot

      public AttributeStore getSnapshot(boolean useSelected, Observer progress)
      Return a snapshot of the dataset at a given moment. The general behaviour of this method is to simply return the same datastore. Some specialized datastores (such as CrosstabStore), will compute an instance that can be used and then disposed.

      The default behaviour simply returns 'this'.

      Parameters:
      useSelected - If true then only use the currently selected records in computing the snapshot.
      progress - An optional progress bar. This parameter may be null.
      Returns:
      An AttributeStore representing a materialization of the store.
    • getCachingLayer

      public static AttributeStore getCachingLayer(AttributeStore as, int size)
      Wrap the specified store up in a caching layer. This may help to improve performance on complex queries and reports, where the same value is retrieved many times for each row that is queried.
      Parameters:
      as - The AttributeStore to wrap with a caching layer
      size - the number of rows in the cache
      Returns:
      A row-cached version of the input AttributeStore
    • getCachingLayer

      public static AttributeStore getCachingLayer(AttributeStore as)
      Wrap the specified store up in a caching layer. This may help to improve performance on complex queries and reports, where the same value is retrieved many times for each row that is queried. The default cache size is one row.
      Parameters:
      as - The AttributeStore to wrap with a caching layer
      Returns:
      A row-cached version of the input AttributeStore
    • getSynchronizer

      public Suspendable getSynchronizer()
      Get the synchronizer object for this table. This object can be used to suspend the scheduling task as a set of calculations are carried out. Most tables will not have a synchronizer object. The only tables that will are tables that provide simulation results.
    • addRelate

      public RelationalStore addRelate(AttributeStore join, String column1, String column2) throws Exception
      Join a table to the current table, creating a new table having columns from both. The method returns a reference to the new table. You must use the table provided in the reference to see the join. The old table will not have changed at all.

      When you are finished using the new table then simply drop the reference to it, and it will be garbage collected.

      Parameters:
      join - The table that should be joined to this table
      column1 - The foreign key in the original table
      column2 - The primary key in the table to be joined
      Returns:
      The joined RelationalStore
      Throws:
      Exception - if errors occur while setting up the relate
    • addRelate

      public RelationalStore addRelate(AttributeStore join, String column1, String column2, int rowDelta) throws Exception
      Join a table to the current table, creating a new table having columns from both. The method returns a reference to the new table. You must use the table provided in the reference to see the join. The old table will not have changed at all.

      When you are finished using the new table then simply drop the reference to it, and it will be garbage collected.

      Parameters:
      join - The table that should be joined to this table
      column1 - The foreign key in the original table
      column2 - The primary key in the table to be joined
      rowDelta - A row offset between the two tables that is used when the tables are joined by row number.
      Returns:
      The joined RelationalStore
      Throws:
      Exception - if errors occur while setting up the relate
    • setRowNodeRemap

      public void setRowNodeRemap(RowNodeRemap rowNodeRemap)
    • getRowNodeRemap

      public RowNodeRemap getRowNodeRemap()
    • addTableModelListener

      public void addTableModelListener(TableModelListener listener)
      Specified by:
      addTableModelListener in interface TableModel
      Overrides:
      addTableModelListener in class AbstractTableModel
    • removeTableModelListener

      public void removeTableModelListener(TableModelListener listener)
      Specified by:
      removeTableModelListener in interface TableModel
      Overrides:
      removeTableModelListener in class AbstractTableModel
    • addMenuItems

      public void addMenuItems(JPopupMenu jpm, AttributeStore l, int row, int period)
      Add menu items to be displayed when a popup menu is activated on this table. This method when a popup mouse click happens on a map layer, just before the popup menu appears. Each layer is given an opportunity to add menu items into the popup that are specific to the functionality that the layer provides. The menu items that are added must contain the functionality to perform the requested action.
      Specified by:
      addMenuItems in interface PopupActivationListener
      Parameters:
      jpm - The menu that the items should be added into
      l - The main AttributeStore that initiated this request. This may be different than the current AttributeStore if the main table is a RelationalStore composed of a number of parts.
      row - The row in the table that this event applies to
      period - The period that the request applies to.
    • addPopupActivationListener

      public void addPopupActivationListener(PopupActivationListener p)
      Add a PopupActivationListener to this table. The listener will be informed when a menu is popped up.
      Parameters:
      p - The listener to be added
    • removePopupActivationListener

      public void removePopupActivationListener(PopupActivationListener p)
      Remove a PopupActivationListener from this table.
      Parameters:
      p - The listener to be removed
    • maybePopup

      public void maybePopup(MouseEvent e, int row, int period)
      Potentially display a popup menu. This method will see if there are popup menu actions, and if so it will display the popup menu. This routine is automatically called by the GUI code.
      Parameters:
      e - The MouseEvent that triggered the popup
      row - The row in the dataset that the popup is related to
      period - The period of interest.
    • notifyPopupActivationListeners

      public final void notifyPopupActivationListeners(JPopupMenu jpm, AttributeStore l, int row, int period)
      Notify listeners that a popup is about to happen. This allows custom addition of menu options when a mouse button is clicked on a map.
      Parameters:
      jpm - The popup menu that is about to be shown on the screen
      l - The AttributeStore that is the source of the event
      row - The row in the dataset that the popup is related to
      period - The period of interest.
    • showCube

      public TableViewer showCube(boolean visible)
      Show this table in a viewer that supports scrolling through time periods.
      Parameters:
      visible - Controls the initial visibility of the table. This parameter should usually be true.
      Returns:
      The Frame object that holds the viewer.
    • showTable

      public TableViewer showTable(boolean visible)
      Display this table model in a TableViewer control.
      Parameters:
      visible - Controls the initial visibility of the table. This parameter should usually be true.
      Returns:
      The Frame object that holds the viewer.
    • getCacheParent

      public AttributeStore getCacheParent()
      Return the parent data source from within a caching layer. In case the data source is not being cached then this will simply return itself.
    • setPeriod

      public void setPeriod(int period)
      Set the default time period that is used by this table when an explicit time period is not provided. When the time period changes send out notifications for the columns that are dynamically dependent on period.
      Parameters:
      period - the default period for this store
    • getPeriod

      public int getPeriod()
      Get the default time period that is used by this table when an explicit time period is not provided.
      Returns:
      the default period used for this store
    • getPeriodCount

      public abstract int getPeriodCount()
      Get the total number of periods that this store supports
      Returns:
      The number of periods in this store
    • getContextPeriods

      public int[] getContextPeriods()
      Return an array of periods that represent what is contained in this table
    • getYearForPeriod

      public abstract int getYearForPeriod(int period)
      Get the ending year for a given period.
      Parameters:
      period - The period of interest
      Returns:
      the year for a given period
    • getPeriodWidth

      public int getPeriodWidth(int period)
      How many years in each period?
      Parameters:
      period - The period of interest
      Returns:
      the number of years in that period.
    • getColumnCount

      public int getColumnCount()
      Get the number of columns in this store
      Specified by:
      getColumnCount in interface TableModel
      Returns:
      the number of columns in this store
    • getRowCount

      public abstract int getRowCount()
      Get the number of rows in this store
      Specified by:
      getRowCount in interface TableModel
      Returns:
      the number of rows in this store
    • allowsEditing

      public boolean allowsEditing()
      Query if this layer supports extended editing of features. Extended editing usually means that values can be written out to disk.
      Returns:
      true if the store allows editing
    • setEditMode

      public void setEditMode(boolean mode) throws IOException
      Enable or disable the extended editing mode.
      Parameters:
      mode - the editing mode to use
      Throws:
      IOException - if an error occurs while trying to change the edit mode.
    • getEditMode

      public boolean getEditMode()
      Get the status of the extended editing mode.
      Returns:
      the editing mode in use
    • findColumn

      public int findColumn(String field)
      Get the column number of the given field in the table. The first matching column is returned. If the column is not found then return -1.
      Overrides:
      findColumn in class AbstractTableModel
      Parameters:
      field - The name of the field to look up
    • findColumn

      public int findColumn(String field, String shortName)
      Get the column number of the given field in the given table. If the column is not found then return -1.
      Parameters:
      field - The name of the field to look up
      shortName - The short name of the table to look up the the column in. If this attribute store has related tables, the column from the related table with the matching short name will be returned. If there is no table with a matching short name an exception will be thrown.
    • findSimilarColumnNames

      public String findSimilarColumnNames(String field)
      Return a list of column names that have a similar spelling to a given name.
      Parameters:
      field - The name of a field to check
      Returns:
      A String containing a list of fields that have a similar spelling.
    • getColumnNames

      public String[] getColumnNames()
      Get an array of all the column names in this store.
      Returns:
      An array of all the column names in this store.
    • getColumnName

      public String getColumnName(int column)
      Return the name of a column at a given position.
      Specified by:
      getColumnName in interface TableModel
      Overrides:
      getColumnName in class AbstractTableModel
      Parameters:
      column - the column number of interest
      Returns:
      the name of the column
    • getFullColumnName

      public FullColumnName getFullColumnName(int column)
      Return the full name of a column at a given position, including the short name of the table.
      Parameters:
      column - the column number of interest
      Returns:
      the name of the column
    • getColumnClass

      public Class getColumnClass(int column)
      Get the class of the column if interest. This returns types that the JTable will use for renderers and editors.
      Specified by:
      getColumnClass in interface TableModel
      Overrides:
      getColumnClass in class AbstractTableModel
      Parameters:
      column - the column of interest
      Returns:
      the Class of the data held in this column
    • addCellEditors

      public void addCellEditors(JTable table, int offset)
      This method will be called by components that want to set up custom cell editors on JTables. If your table has custom editing behaviour then you can hook it in using this method.
      Parameters:
      table - A JTable
      offset - the column number in the store that will have a custom cell editor
    • isCellEditable

      public boolean isCellEditable(int row, int column)
      Determine if the cell at the specified row and column is eligible for editing.
      Specified by:
      isCellEditable in interface TableModel
      Overrides:
      isCellEditable in class AbstractTableModel
      Parameters:
      row - Unused value
      column - the column of interest
      Returns:
      A boolean value that indicates if the column can be edited.
    • getAttributeFormat

      public AttributeFormat getAttributeFormat(int field)
      Get the format descriptor for a given column.
      Parameters:
      field - The column of interest
      Returns:
      The AttributeFormat for this field
    • lookupRow

      public int lookupRow(Object key, int column)
      Look up the row number for a key value in given column number. This will search the column for a value, and return the row number that the value was found in. If the record is not found then -1 is returned. There is no guarantee of which record will be returned if there more than one record has the same value.
      Parameters:
      key - The data value to search for
      column - the column to search within
      Returns:
      the row number where the value was found
    • canIndex

      public boolean canIndex(int column)
      Test to see if the column can be indexed. The system will only allow joins on fields that can be indexed, such as integer and string keys. Column -1 is a special indicator that the join is a 'link by row number' relate.
      Parameters:
      column - the column number to index
      Returns:
      true if the column can be indexed
    • buildIndex

      public void buildIndex(int column)
      Build an index on the column. The index can then be used for speedy lookups. See lookupRow(java.lang.Object, int).
      Parameters:
      column - the column of interest
    • hasIndex

      public boolean hasIndex(int column)
      Indicate if an index has been build on a column
      Parameters:
      column - the column of interest
      Returns:
      true if this column has an index
    • setValueAt

      public void setValueAt(Object aValue, int row, int column, int period)
      Set the value in a cell and notify listeners that the value has changed.

      Implementing classes that override must call this method to ensure that joins are properly maintained.

      Parameters:
      aValue - The value to be set.
      row - The row containing the cell
      column - The column containing the cell
      period - The period of interest
    • getValueAt

      public abstract Object getValueAt(int row, int column, int period)
      Get a cell value
      Parameters:
      row - The row containing the cell
      column - The column containing the cell
      period - The period of interest
      Returns:
      An object containing the cell value.
    • setValueAt

      public void setValueAt(Object aValue, int row, int column)
      Set the value in a cell using the default period for the table.

      Implementing classes that override must call this method to ensure that joins are properly maintained.

      Specified by:
      setValueAt in interface TableModel
      Overrides:
      setValueAt in class AbstractTableModel
      Parameters:
      aValue - The value to be set.
      row - The row containing the cell
      column - The column containing the cell
    • getValueAt

      public Object getValueAt(int row, int column)
      Get a cell value using the default period for the table.
      Specified by:
      getValueAt in interface TableModel
      Parameters:
      row - The row containing the cell
      column - The column containing the cell
      Returns:
      An object containing the cell value.
    • integerValue

      public int integerValue(int row, int column)
      Get an int value from a cell using the default period for the table.
      Parameters:
      row - The row containing the cell
      column - The column containing the cell
      Returns:
      An int value representing the contents of the cell. Conversion will occur if the cell value is not an Integer type.
    • integerValue

      public int integerValue(int row, int column, int period)
      Get an int value from a cell.
      Parameters:
      row - The row containing the cell
      column - The column containing the cell
      period - The period of interest Conversion will occur if the cell value is not an Integer type.
      Returns:
      An int value representing the contents of the cell.
    • doubleValue

      public double doubleValue(int row, int column)
      Get a double value from a cell using the default period for the table.
      Parameters:
      row - The row containing the cell
      column - The column containing the cell
      Returns:
      A double value representing the contents of the cell. Conversion will occur if the cell value is not a Number type.
    • doubleValue

      public double doubleValue(int row, int column, int period)
      Get a double value from a cell.
      Parameters:
      row - The row containing the cell
      column - The column containing the cell
      period - The period of interest
      Returns:
      A double value representing the contents of the cell. Conversion will occur if the cell value is not a Number type.
    • booleanValue

      public boolean booleanValue(int row, int column)
      Get a boolean value from a cell using the default period for the table.
      Parameters:
      row - The row containing the cell
      column - The column containing the cell
      Returns:
      A boolean value representing the contents of the cell. Conversion will occur if the cell value is not a Boolean type.
    • booleanValue

      public boolean booleanValue(int row, int column, int period)
      Get a boolean value from a cell.
      Parameters:
      row - The row containing the cell
      column - The column containing the cell
      period - The period of interest
      Returns:
      A boolean value representing the contents of the cell. Conversion will occur if the cell value is not a Boolean type.
    • listValue

      public Object[] listValue(int row, int column)
      Get a value from a field as a list object. The period of interest is the default period for this dataset. A list value is always expressed as an array of string values.
      Parameters:
      row - The row of interest
      column - The Column of interest
      Returns:
      A list of value, converted from a comma delimited string.
    • listValue

      public Object[] listValue(int row, int column, int period)
      Get a value from a field as a list object for the specified period. A list value is always expressed as an array of string values.
      Parameters:
      row - The row of interest
      column - The Column of interest
      period - The period of interest
      Returns:
      A list of value, converted from a comma delimited string.
    • listify

      public static Object[] listify(Object o)
      Convert an object into list format. List format is an array of string values.
      Parameters:
      o - The object to convert to string, and then split on ','
      Returns:
      an array of values based on splitting the string value of the parameter
    • getTitle

      public String getTitle()
      Get the title of this dataset
      Returns:
      the title of this store
    • setTitle

      public void setTitle(String title)
      Set the title for this dataset.
      Parameters:
      title - The value to be used as the title for this store
    • makeLu

      public HashMap makeLu(String keyExpression, String valueExpression, int period)
      Create a lookup table. The lookup table is a HashMap that is populated with the specified key and values.
      Parameters:
      keyExpression - An expression that evaluates to the the primary key value of the lookup table
      valueExpression - An expression that evaluates the values of the lookup table.
      period - The period to evalute the expressions in
      Returns:
      A HashMap containing keys and values
    • getListSelectionModel

      public DefaultListSelectionModel getListSelectionModel()
      Get the selection model that keeps track of selected records.
      Returns:
      the ListSelectionModel
    • setListSelectionModel

      public void setListSelectionModel(DefaultListSelectionModel listSelectionModel)
    • isSelectedIndex

      public boolean isSelectedIndex(int row)
      Check if the specified record is currently selected.
      Parameters:
      row - The row of interest
      Returns:
      true if the record is selected
    • isSelectionEmpty

      public boolean isSelectionEmpty()
      Check if the selection empty
      Returns:
      true if the selection is empty
    • getSelectedRowCount

      public int getSelectedRowCount()
      Return the number of selected rows
      Returns:
      the number of selected rows
    • valueChanged

      public void valueChanged(ListSelectionEvent e)
      React to changes from the ListSelectionModel.
      Specified by:
      valueChanged in interface ListSelectionListener
      Parameters:
      e - The ListSelectionEvent to process
    • getSelection

      public BitSet getSelection()
      Get a BitSetBitSet that represents the current selected records.
      Returns:
      a BitSet representing the current selected records
    • getSelection

      public BitSet getSelection(String expression, int period)
      Get a BitSetBitSet that represents the records that match the query.
      Parameters:
      expression - the query to evaluate
      period - the period to evaluate the query in
      Returns:
      a BitSet representing the matching records
    • getSelection

      public BitSet[] getSelection(String expression, int[] periods)
      Get a BitSetBitSet that represents the records that match the query.
      Parameters:
      expression - the query to evaluate
      periods - the period to evaluate the query in
      Returns:
      a BitSet representing the matching records
    • changeSelection

      public void changeSelection(BitSet values)
      Change the list of selected records to the selection in the BitSet
      Parameters:
      values - The new selection
    • clearSelection

      public void clearSelection(Frame owner)
      Clear the record selection.
      Parameters:
      owner - A reference to the controlling window (may be null).
    • select

      public boolean select(Window owner, String expression)
      Select records based on an expression. The expression will be evaluated in the context of the default period for this dataset.
      Parameters:
      owner - A reference to the controlling window.
      expression - The reselect expression.
      Returns:
      true if query is executed
    • selectNew

      public boolean selectNew(Window owner, int period, String expression)
      Select a new set of records based on an expression. This selection will replace the previous selection.
      Parameters:
      owner - A reference to the controlling window.
      period - The period to evaluate the expression against.
      expression - The reselect expression.
      Returns:
      true if query is executed
    • selectAdd

      public boolean selectAdd(Window owner, int period, String expression)
      Select additional records based on an expression. This selection will add to the previous selection.
      Parameters:
      owner - A reference to the controlling window.
      period - The period to evaluate the expression against.
      expression - The reselect expression.
      Returns:
      true if query is executed
    • selectFrom

      public boolean selectFrom(Window owner, int period, String expression)
      Select records based on an expression. This selection will select records out of the previous selection.
      Parameters:
      owner - A reference to the controlling window.
      period - The period to evaluate the expression against.
      expression - The reselect expression.
      Returns:
      true if query is executed
    • select

      public boolean select(Window owner, int period, String expression, int type)
      Change the selection status of records based on the result of evaluating an expression.
      Parameters:
      owner - A reference to the controlling window.
      period - The period to evaluate the expression against.
      expression - The reselect expression.
      type - The type of selection, which may be one of SELECT_NEW, SELECT_ADD, or SELECT_FROM.
      Returns:
      true if query is executed
    • calculate

      public boolean calculate(Window owner, int period, String expression, String field)
      Compute the value of a field based on an expression.
      Parameters:
      owner - A reference to the controlling window.
      period - The period to evaluate the expression against.
      expression - The expression.
      field - The field that should receive the results of the expression.
      Returns:
      true if the assignment succeeds, false if not.
    • uniqueValues

      public Comparable[] uniqueValues(Window owner, Expression expr, int period)
      Return an array containing uniques values derived from an expression. A modal progress bar will be displayed above the specified window.
      Parameters:
      owner - The window that will be the owner of the modal progress bar.
      expr - The expression of interest
      period - The period of interest
      Returns:
      An array of objects. The type of object will be appropriate to the column
    • uniqueValues

      public Comparable[] uniqueValues(Window owner, Expression expr, String reselect, int period)
      Return an array containing uniques values derived from an expression. A modal progress bar will be displayed above the specified window.
      Parameters:
      owner - The window that will be the owner of the modal progress bar.
      expr - The expression of interest
      reselect - An expression to restirict the query
      period - The period of interest
      Returns:
      An array of objects. The type of object will be appropriate to the column
    • uniqueValues

      public Comparable[] uniqueValues(int pos, int period)
      Return an array containing uniques values contained in a column. A modal progress bar will be displayed above the default window.
      Parameters:
      pos - The column position of interest
      period - The period of interest
      Returns:
      An array of objects. The type of object will be appropriate to the column
    • uniqueValues

      public Comparable[] uniqueValues(Window owner, int pos, int period)
      Return an array containing uniques values contained in a column. A modal progress bar will be displayed above the specified window.
      Parameters:
      owner - The window that will be the owner of the modal progress bar.
      pos - The column position of interest
      period - The period of interest
      Returns:
      An array of objects. The type of object will be appropriate to the column
    • uniqueValues

      public Comparable[] uniqueValues(Window owner, String column, String reselect, int period)
      Return an array containing uniques values contained in a column. A modal progress bar will be displayed above the specified window.
      Parameters:
      owner - The window that will be the owner of the modal progress bar.
      column - The column or expression of interest
      reselect - An expression that restricts the query
      period - The period of interest
      Returns:
      An array of objects. The type of object will be appropriate to the column
    • uniqueValues

      public Comparable[] uniqueValues(Window owner, String column, int period)
      Return an array containing uniques values contained in a column. A modal progress bar will be displayed above the specified window.
      Parameters:
      owner - The window that will be the owner of the modal progress bar.
      column - The column or expression of interest
      period - The period of interest
      Returns:
      An array of objects. The type of object will be appropriate to the column
    • uniqueValues

      public Comparable[] uniqueValues(String column)
      Get a sorted array of unique values found within a column. The values will be those found in the default period for this table. A modal progress bar will be owned by the default window.
      Parameters:
      column - The name of the column of interest
      Returns:
      An array of objects. The type of object will be appropriate to the column
    • uniqueValues

      public Comparable[] uniqueValues(String column, int period)
      Get a sorted array of unique values found within a column. The values will be those found in the specified period. A modal progress bar will be owned by the default window.
      Parameters:
      column - The name of the column of interest
      period - The period to search for the values of ineterst.
      Returns:
      An array of objects. The type of object will be appropriate to the column
    • getMinMax

      public double[] getMinMax(int pos, int period)
      Calculate the numeric range of a column by index, for a specified period. Use the main window as the parent window of the progress bar.
      Parameters:
      pos - The column position to calculate the range
      period - The period of interest
      Returns:
      An array of two values: the minimum and maximum numeric value found in this column.
    • getMinMax

      public double[] getMinMax(Window owner, int pos, int period)
      Calculate the numeric range of a column by index, for a specified period. Use the specified window as the parent window of the progress bar.
      Parameters:
      owner - The owner of the modal progress bar
      pos - The column position to calculate the range
      period - The period of interest
      Returns:
      An array of two values: the minimum and maximum numeric value found in this column.
    • getMinMax

      public double[] getMinMax(String column)
      Calculate the numeric range of a column, for the default period. Use the main window as the parent window of the progress bar.
      Parameters:
      column - The name of the column of interest
      Returns:
      An array of two values: the minimum and maximum numeric value found in this column.
    • getMinMax

      public double[] getMinMax(String column, int period)
      Calculate the numeric range of a column, for a specified period. Use the main window as the parent window of the progress bar.
      Parameters:
      column - The name of the column of interest
      period - The period of interest
      Returns:
      An array of two values: the minimum and maximum numeric value found in this column.
    • getMinMax

      public double[] getMinMax(Window owner, String column, int period)
      Calculate the numeric range of a column, for a specified period. Also identify the parent window for the progress bar.
      Parameters:
      owner - The window that should be the owner of the modal progress bar.
      column - The name of the column of interest
      period - The period of interest
      Returns:
      An array of two values: the minimum and maximum numeric value found in this column.
    • calculateField

      public void calculateField(Frame owner, String field)
      Calculate the values of a field, using the query builder to determine the new value to assign. Only selected rows will be updated. The update will be made in the context of the default period for this table.
      Parameters:
      owner - The owner of the modal query tool
      field - The field to be updated.
    • calculateField

      public void calculateField(Frame owner, String field, int period)
      Calculate the values of a field, using the query builder to determine the new value to assign. Specify the initial time period to display in the query builder.
      Parameters:
      owner - The owner of the modal query tool
      field - The field to be updated.
      period - The period used as the context for the update
    • queryTable

      public void queryTable(Frame owner)
      Obtain a query builder for this table, initialized to the default time period. The query builder will have buttons to control the reselection action.
      Parameters:
      owner - The owner of the modal query tool
    • queryTable

      public void queryTable(Frame owner, int period)
      Show the query builder, initialized to a given time period. The query builder will have buttons to control the reselection action.
      Parameters:
      owner - The owner of the modal query tool
      period - The period used as the context for the query
    • identifyRecords

      public void identifyRecords(int row)
      Show the specified row in the IdentifyViewer viewer.
      Parameters:
      row - The row of interest
    • exportDBF

      public void exportDBF(Window parent, String filename, String[] columns, int[] remap, int period, String reselect)
      Export all columns of the selected rows to a DBF file. The output file should not exist.
      Parameters:
      parent - The reference to the selection window, or null if there is no selection window
      filename - The output file name.
      columns - The columns to output.
      remap - A row remap table to change the sorted order of output.
      period - the period to export
      reselect - a reselect expression to identify records to export. If null then export the selected rows. If null and no rows are selected then export all rows.
    • exportDBF

      public void exportDBF(Window parent, String filename, ArrayList<DBFColumnSpec> defs, int[] remap)
      Export all columns of the selected rows to a DBF file. The output file should not exist. If no rows are selected then export all rows will be exported.
      Parameters:
      parent - The reference to the selection window, or null if there is no selection window
      filename - The output file name.
      defs - An ArrayList of DBFColumnSpec values that decribe the column transformations.
      remap - A row remap table to change the sorted order of output.
    • exportDBF

      public void exportDBF(Window parent, String filename, ArrayList<DBFColumnSpec> defs, int[] remap, int period, String reselect)
      Export all columns of the selected rows to a DBF file. The output file should not exist.
      Parameters:
      parent - The reference to the selection window, or null if there is no selection window
      filename - The output file name.
      defs - An ArrayList of DBFColumnSpec values that decribe the column transformations.
      remap - A row remap table to change the sorted order of output.
      period - the planning period to export
      reselect - a reselect expression to identify records to export. If null then export the selected rows. If null and no rows are selected then export all rows.
    • exportDBF

      public void exportDBF(String filename, String[] columns)
      Export all columns of the selected rows to a DBF file. The output file should not exist. If no rows are selected then export all rows will be exported.
      Parameters:
      filename - The output file name.
      columns - The columns to output.
    • exportDBF

      public void exportDBF(String filename)
      Export all columns of the selected rows to a DBF file. The output file should not exist. If no rows are selected then export all rows will be exported.
      Parameters:
      filename - The output file name.
    • exportCSV

      public void exportCSV(String filename)
      Export all columns of the selected rows to a CSV file. If no rows are selected then export all rows will be exported.
      Parameters:
      filename - The name of the output file. If no rows are selected then export all rows.
    • exportCSV

      public void exportCSV(String filename, String[] columns, int[] remapRows, int period, String reselect)
      Export selected columns to a CSV file.
      Parameters:
      filename - The name of the output file.
      columns - The columns to export. If null then export all columns.
      remapRows - A row remap table to change the sorted order of output. The first value in the remap array indicates the first row to be written, and so on. If a value in the remap list is negative or larger than the number of original rows then it is skipped. This value for the parameter can be null, in which case the original order will be used.
      reselect - a reselect expression to identify records to export. If null then export the selected rows. If null and no rows are selected then export all rows.
    • exportCSV

      public void exportCSV(Window parent, String filename, String[] columns, int[] remapRows, int period, String reselect)
      Export selected columns to a CSV file.
      Parameters:
      parent - The reference to the selection window, or null if there is no selection window
      filename - The name of the output file.
      columns - The columns to export. If null then export all columns.
      remapRows - A row remap table to change the sorted order of output. The first value in the remap array indicates the first row to be written, and so on. If a value in the remap list is negative or larger than the number of original rows then it is skipped. This value for the parameter can be null, in which case the original order will be used.
      reselect - a reselect expression to identify records to export. If null then export the selected rows. If null and no rows are selected then export all rows.
    • exportCSV

      public void exportCSV(String filename, String[] columns, int[] remapRows, int period, String reselect, Observer obs)
      Export selected columns to a CSV file.
      Parameters:
      filename - The name of the output file.
      columns - The columns to export. If null then export all columns.
      remapRows - A row remap table to change the sorted order of output. The first value in the remap array indicates the first row to be written, and so on. If a value in the remap list is negative or larger than the number of original rows then it is skipped. This value for the parameter can be null, in which case the original order will be used.
      reselect - a reselect expression to identify records to export. If null then export the selected rows. If null and no rows are selected then export all rows.
      obs - A reference to an Observer that will be called with progress information. The argument to the update method will be an Integer indicated the percent completion. This argument may be null.
    • exportCSV

      public void exportCSV(String filename, ArrayList<DBFColumnSpec> defs, int[] remapRows, Observer obs)
      Export selected columns of the selected rows to a CSV file. If no rows are selected then export all rows.
      Parameters:
      filename - The name of the output file.
      defs - The columns to export
      remapRows - A row remap table to change the sorted order of output. The first value in the remap array indicates the first row to be written, and so on. If a value in the remap list is negative or larger than the number of original rows then it is skipped. This value for the parameter can be null, in which case the original order will be used.
      obs - A reference to an Observer that will be called with progress information. The argument to the update method will be an Integer indicated the percent completion. This argument may be null.
    • exportCSV

      public void exportCSV(Window parent, String filename, ArrayList defs, int[] remap, int period, String reselect)
    • quoteIfRequired

      public static String quoteIfRequired(String value)
      This method will add double quotes around a string. This is so that the string can be read back in correctly in Excel without appearing to contain extra columns in case is contains a comma character. In addition to surrounding the string with quotes, this routine will also double up any existing quote characters (" ==> ""). This also will prevent Excel from seeing a premature string termination.
      Parameters:
      value - The String to be transformed
      Returns:
      the quoted String
    • getShortName

      public String getShortName()
      Get the short name for this table. This value can be used in column lookups to differentiate similarly named columns from different joined tables.
    • setShortName

      public AttributeStore setShortName(String name)
      Set the short name for this table. This value can be used in column lookups to differentiate similarly named columns from different joined tables.
    • toString

      public String toString()
      Returns the title of this AttributeStore
      Overrides:
      toString in class Object
      Returns:
      The title of this AttributeStore
    • compareTo

      public int compareTo(Object o)
      Compare tables based on titles.
      Specified by:
      compareTo in interface Comparable
      Parameters:
      o - The other AttributeStore to compare to
      Returns:
      an integer value that is less than zero, equal to zero, or greater to zero based on whether the title is less than, equal to, or greater than the other title.
    • decodeCharset

      public static Charset decodeCharset(String charset, String filename)
      Try to figure out the charset from either a specified charset token or by reading the CPG file.
      Parameters:
      charset - the character set token. If null then try reading the CPG file.
      filename - The name of the file to be used as the base for the CPG file. Change extension to .CPG and try reading the code set.