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
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 Summary
FieldsModifier and TypeFieldDescriptionstatic int
Specify the the selection query operator should add records to the currently selected set.static int
Specify the the selection query operator should remove records from the currently selected set.static int
Specify the the selection query operator should create a new selected set. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic File
absoluteFile(File file)
Convert a relative path to an absolute filestatic File
absoluteFile(String fileName)
Convert a relative path to an absolute filestatic String
absolutePath(File file)
Convert a relative path to an absolute pathstatic String
absolutePath(String fileName)
Convert a relative path to an absolute pathvoid
addCellEditors(JTable table, int offset)
This method will be called by components that want to set up custom cell editors on JTables.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.void
Add a PopupActivationListener to this table.addRelate(AttributeStore join, String column1, String column2)
Join a table to the current table, creating a new table having columns from both.addRelate(AttributeStore join, String column1, String column2, int rowDelta)
Join a table to the current table, creating a new table having columns from both.void
addTableModelListener(TableModelListener listener)
static AttributeStore
Add this table to the global list of open tables.boolean
Query if this layer supports extended editing of features.boolean
booleanValue(int row, int column)
Get a boolean value from a cell using the default period for the table.boolean
booleanValue(int row, int column, int period)
Get a boolean value from a cell.void
buildIndex(int column)
Build an index on the column.boolean
Compute the value of a field based on an expression.void
calculateField(Frame owner, String field)
Calculate the values of a field, using the query builder to determine the new value to assign.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.boolean
canIndex(int column)
Test to see if the column can be indexed.void
changeSelection(BitSet values)
Change the list of selected records to the selection in the BitSetvoid
clearSelection(Frame owner)
Clear the record selection.void
close()
Close the table and release resources.int
Compare tables based on titles.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.double
doubleValue(int row, int column)
Get a double value from a cell using the default period for the table.double
doubleValue(int row, int column, int period)
Get a double value from a cell.void
exportCSV(Window parent, String filename, String[] columns, int[] remapRows, int period, String reselect)
Export selected columns to a CSV file.void
exportCSV(Window parent, String filename, ArrayList defs, int[] remap, int period, String reselect)
void
Export all columns of the selected rows to a CSV file.void
Export selected columns to a CSV file.void
exportCSV(String filename, String[] columns, int[] remapRows, int period, String reselect, Observer obs)
Export selected columns to a CSV file.void
exportCSV(String filename, ArrayList<DBFColumnSpec> defs, int[] remapRows, Observer obs)
Export selected columns of the selected rows to a CSV file.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.void
exportDBF(Window parent, String filename, ArrayList<DBFColumnSpec> defs, int[] remap)
Export all columns of the selected rows to a DBF file.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.void
Export all columns of the selected rows to a DBF file.void
Export all columns of the selected rows to a DBF file.int
findColumn(String field)
Get the column number of the given field in the table.int
findColumn(String field, String shortName)
Get the column number of the given field in the given table.findSimilarColumnNames(String field)
Return a list of column names that have a similar spelling to a given name.getAttributeFormat(int field)
Get the format descriptor for a given column.Return the parent data source from within a caching layer.static AttributeStore
Wrap the specified store up in a caching layer.static AttributeStore
getCachingLayer(AttributeStore as, int size)
Wrap the specified store up in a caching layer.Return a string that uniquely identifies this table and provides information can be used to reconstruct the table.getColumnClass(int column)
Get the class of the column if interest.int
Get the number of columns in this storegetColumnName(int column)
Return the name of a column at a given position.String[]
Get an array of all the column names in this store.int[]
Return an array of periods that represent what is contained in this tablestatic File
getCwd()
Retireve the default working directoryboolean
Get the status of the extended editing mode.getFullColumnName(int column)
Return the full name of a column at a given position, including the short name of the table.Get the selection model that keeps track of selected records.double[]
getMinMax(int pos, int period)
Calculate the numeric range of a column by index, for a specified period.double[]
Calculate the numeric range of a column by index, for a specified period.double[]
Calculate the numeric range of a column, for a specified period.double[]
Calculate the numeric range of a column, for the default period.double[]
Calculate the numeric range of a column, for a specified period.static AttributeStore
getOpenStore(TableSpec tablespec)
Try to find a cached file that has the same filename as the name that is provided.static AttributeStore
getOpenStore(String spec)
Try to find a cached file that has the same filename as the name that is provided, using the default character encoding.static AttributeStore
getOpenStore(String spec, String encoding)
Try to find a cached file that has the same filename as the name that is provided.static Set<AttributeStore>
Get the global list of open tables.int
Get the default time period that is used by this table when an explicit time period is not provided.abstract int
Get the total number of periods that this store supportsint
getPeriodWidth(int period)
How many years in each period?abstract int
Get the number of rows in this storeint
Return the number of selected rowsGet aBitSet
BitSet that represents the current selected records.getSelection(String expression, int period)
Get aBitSet
BitSet that represents the records that match the query.BitSet[]
getSelection(String expression, int[] periods)
Get aBitSet
BitSet that represents the records that match the query.Get the short name for this table.getSnapshot(boolean useSelected)
Return a snapshot of the dataset at a given moment.getSnapshot(boolean useSelected, Observer progress)
Return a snapshot of the dataset at a given moment.static AttributeStore
getStoreByShortName(String shortName)
Search the global list of open tables and return the first one that matches the specified short name.static AttributeStore
getStoreByTitle(String title)
Search the global list of open tables and return the first one that matches the specified title.Get the synchronizer object for this table.Return a string that uniquely identifies this table and provides information can be used to reconstruct the table.Return a structure that describes this tablegetTitle()
Get the title of this datasetgetValueAt(int row, int column)
Get a cell value using the default period for the table.abstract Object
getValueAt(int row, int column, int period)
Get a cell valueabstract int
getYearForPeriod(int period)
Get the ending year for a given period.boolean
hasIndex(int column)
Indicate if an index has been build on a columnvoid
identifyRecords(int row)
Show the specified row in theIdentifyViewer
viewer.int
integerValue(int row, int column)
Get an int value from a cell using the default period for the table.int
integerValue(int row, int column, int period)
Get an int value from a cell.boolean
isCellEditable(int row, int column)
Determine if the cell at the specified row and column is eligible for editing.boolean
isSelectedIndex(int row)
Check if the specified record is currently selected.boolean
Check if the selection emptystatic Object[]
Convert an object into list format.Object[]
listValue(int row, int column)
Get a value from a field as a list object.Object[]
listValue(int row, int column, int period)
Get a value from a field as a list object for the specified period.int
Look up the row number for a key value in given column number.Create a lookup table.void
maybePopup(MouseEvent e, int row, int period)
Potentially display a popup menu.void
notifyPopupActivationListeners(JPopupMenu jpm, AttributeStore l, int row, int period)
Notify listeners that a popup is about to happen.static AttributeStore
openOrReuse(String spec)
Try to find a cached file that has the same filename as the name that is provided.static AttributeStore
openOrReuse(String spec, String encoding)
Try to find a cached file that has the same filename as the name that is provided.void
queryTable(Frame owner)
Obtain a query builder for this table, initialized to the default time period.void
queryTable(Frame owner, int period)
Show the query builder, initialized to a given time period.static String
quoteIfRequired(String value)
This method will add double quotes around a string.static String
relativePath(String filename, int maxUplinks)
Make a relative pathstatic void
Remove a table from the global list of open tables.void
Remove a PopupActivationListener from this table.void
removeTableModelListener(TableModelListener listener)
boolean
Change the selection status of records based on the result of evaluating an expression.boolean
Select records based on an expression.boolean
Select additional records based on an expression.boolean
selectFrom(Window owner, int period, String expression)
Select records based on an expression.boolean
Select a new set of records based on an expression.static void
static void
Set the default working directoryvoid
setEditMode(boolean mode)
Enable or disable the extended editing mode.void
setListSelectionModel(DefaultListSelectionModel listSelectionModel)
void
setPeriod(int period)
Set the default time period that is used by this table when an explicit time period is not provided.void
setRowNodeRemap(RowNodeRemap rowNodeRemap)
setShortName(String name)
Set the short name for this table.void
setTableSpec(TableSpec spec)
Set the table spec structure that describes this data set.void
Set the title for this dataset.void
setValueAt(Object aValue, int row, int column)
Set the value in a cell using the default period for the table.void
setValueAt(Object aValue, int row, int column, int period)
Set the value in a cell and notify listeners that the value has changed.showCube(boolean visible)
Show this table in a viewer that supports scrolling through time periods.showTable(boolean visible)
Display this table model in a TableViewer control.toString()
Returns the title of this AttributeStoreuniqueValues(int pos, int period)
Return an array containing uniques values contained in a column.uniqueValues(Window owner, int pos, int period)
Return an array containing uniques values contained in a column.uniqueValues(Window owner, Expression expr, int period)
Return an array containing uniques values derived from an expression.uniqueValues(Window owner, Expression expr, String reselect, int period)
Return an array containing uniques values derived from an expression.uniqueValues(Window owner, String column, int period)
Return an array containing uniques values contained in a column.uniqueValues(Window owner, String column, String reselect, int period)
Return an array containing uniques values contained in a column.uniqueValues(String column)
Get a sorted array of unique values found within a column.uniqueValues(String column, int period)
Get a sorted array of unique values found within a column.void
React to changes from the ListSelectionModel.Methods inherited from class javax.swing.table.AbstractTableModel
fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getListeners, getTableModelListeners
-
Field Details
-
SELECT_NEW
public static final int SELECT_NEWSpecify the the selection query operator should create a new selected set.- See Also:
- Constant Field Values
-
SELECT_ADD
public static final int SELECT_ADDSpecify 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_FROMSpecify 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
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
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 theclose()
method.- Parameters:
as
- The reference to the AttributeStore to remove from the global list
-
getOpenStores
Get the global list of open tables.- Returns:
- A
Set
containing references currently contained in the global list
-
getStoreByTitle
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
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
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
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 openencoding
- 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
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 openencoding
- 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
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
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
- ATableSpec
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
Return a structure that describes this table- Returns:
- The
TableSpec
for this file
-
setTableSpec
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
Return a string that uniquely identifies this table and provides information can be used to reconstruct the table. This handle can be passed to theopenOrReuse(java.lang.String)
method to get an existing or new instance of the table.- Returns:
- The canonical name of this store.
-
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 theopenOrReuse(java.lang.String)
method to get an existing or new instance of the table.- Returns:
- The common name of this store.
-
setCwd
Set the default working directory -
setCwd
-
getCwd
Retireve the default working directory -
absoluteFile
Convert a relative path to an absolute file -
absoluteFile
Convert a relative path to an absolute file -
absolutePath
Convert a relative path to an absolute path -
absolutePath
Convert a relative path to an absolute path -
relativePath
Make a relative path- Parameters:
filename
- the filename to convert to relativemaxUplinks
- 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
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
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 asCrosstabStore
), 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
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 layersize
- the number of rows in the cache- Returns:
- A row-cached version of the input AttributeStore
-
getCachingLayer
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
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 ExceptionJoin 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 tablecolumn1
- The foreign key in the original tablecolumn2
- 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 ExceptionJoin 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 tablecolumn1
- The foreign key in the original tablecolumn2
- The primary key in the table to be joinedrowDelta
- 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
-
getRowNodeRemap
-
addTableModelListener
- Specified by:
addTableModelListener
in interfaceTableModel
- Overrides:
addTableModelListener
in classAbstractTableModel
-
removeTableModelListener
- Specified by:
removeTableModelListener
in interfaceTableModel
- Overrides:
removeTableModelListener
in classAbstractTableModel
-
addMenuItems
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 interfacePopupActivationListener
- Parameters:
jpm
- The menu that the items should be added intol
- 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 toperiod
- The period that the request applies to.
-
addPopupActivationListener
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
Remove a PopupActivationListener from this table.- Parameters:
p
- The listener to be removed
-
maybePopup
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
- TheMouseEvent
that triggered the popuprow
- The row in the dataset that the popup is related toperiod
- 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 screenl
- The AttributeStore that is the source of the eventrow
- The row in the dataset that the popup is related toperiod
- The period of interest.
-
showCube
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
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
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 interfaceTableModel
- 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 interfaceTableModel
- 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
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
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 classAbstractTableModel
- Parameters:
field
- The name of the field to look up
-
findColumn
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 upshortName
- 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
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
Get an array of all the column names in this store.- Returns:
- An array of all the column names in this store.
-
getColumnName
Return the name of a column at a given position.- Specified by:
getColumnName
in interfaceTableModel
- Overrides:
getColumnName
in classAbstractTableModel
- Parameters:
column
- the column number of interest- Returns:
- the name of the column
-
getFullColumnName
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
Get the class of the column if interest. This returns types that the JTable will use for renderers and editors.- Specified by:
getColumnClass
in interfaceTableModel
- Overrides:
getColumnClass
in classAbstractTableModel
- Parameters:
column
- the column of interest- Returns:
- the Class of the data held in this column
-
addCellEditors
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
- AJTable
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 interfaceTableModel
- Overrides:
isCellEditable
in classAbstractTableModel
- Parameters:
row
- Unused valuecolumn
- the column of interest- Returns:
- A boolean value that indicates if the column can be edited.
-
getAttributeFormat
Get the format descriptor for a given column.- Parameters:
field
- The column of interest- Returns:
- The
AttributeFormat
for this field
-
lookupRow
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 forcolumn
- 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. SeelookupRow(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
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 cellcolumn
- The column containing the cellperiod
- The period of interest
-
getValueAt
Get a cell value- Parameters:
row
- The row containing the cellcolumn
- The column containing the cellperiod
- The period of interest- Returns:
- An object containing the cell value.
-
setValueAt
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 interfaceTableModel
- Overrides:
setValueAt
in classAbstractTableModel
- Parameters:
aValue
- The value to be set.row
- The row containing the cellcolumn
- The column containing the cell
-
getValueAt
Get a cell value using the default period for the table.- Specified by:
getValueAt
in interfaceTableModel
- Parameters:
row
- The row containing the cellcolumn
- 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 cellcolumn
- 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 cellcolumn
- The column containing the cellperiod
- The period of interest Conversion will occur if the cell value is not anInteger
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 cellcolumn
- 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 cellcolumn
- The column containing the cellperiod
- 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 cellcolumn
- 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 cellcolumn
- The column containing the cellperiod
- 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
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 interestcolumn
- The Column of interest- Returns:
- A list of value, converted from a comma delimited string.
-
listValue
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 interestcolumn
- The Column of interestperiod
- The period of interest- Returns:
- A list of value, converted from a comma delimited string.
-
listify
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
Get the title of this dataset- Returns:
- the title of this store
-
setTitle
Set the title for this dataset.- Parameters:
title
- The value to be used as the title for this store
-
makeLu
Create a lookup table. The lookup table is aHashMap
that is populated with the specified key and values.- Parameters:
keyExpression
- An expression that evaluates to the the primary key value of the lookup tablevalueExpression
- 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
Get the selection model that keeps track of selected records.- Returns:
- the ListSelectionModel
-
setListSelectionModel
-
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
React to changes from the ListSelectionModel.- Specified by:
valueChanged
in interfaceListSelectionListener
- Parameters:
e
- The ListSelectionEvent to process
-
getSelection
Get aBitSet
BitSet that represents the current selected records.- Returns:
- a
BitSet
representing the current selected records
-
getSelection
Get aBitSet
BitSet that represents the records that match the query.- Parameters:
expression
- the query to evaluateperiod
- the period to evaluate the query in- Returns:
- a
BitSet
representing the matching records
-
getSelection
Get aBitSet
BitSet that represents the records that match the query.- Parameters:
expression
- the query to evaluateperiods
- the period to evaluate the query in- Returns:
- a
BitSet
representing the matching records
-
changeSelection
Change the list of selected records to the selection in the BitSet- Parameters:
values
- The new selection
-
clearSelection
Clear the record selection.- Parameters:
owner
- A reference to the controlling window (may be null).
-
select
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
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
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
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
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
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
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 interestperiod
- The period of interest- Returns:
- An array of objects. The type of object will be appropriate to the column
-
uniqueValues
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 interestreselect
- An expression to restirict the queryperiod
- The period of interest- Returns:
- An array of objects. The type of object will be appropriate to the column
-
uniqueValues
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 interestperiod
- The period of interest- Returns:
- An array of objects. The type of object will be appropriate to the column
-
uniqueValues
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 interestperiod
- The period of interest- Returns:
- An array of objects. The type of object will be appropriate to the column
-
uniqueValues
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 interestreselect
- An expression that restricts the queryperiod
- The period of interest- Returns:
- An array of objects. The type of object will be appropriate to the column
-
uniqueValues
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 interestperiod
- The period of interest- Returns:
- An array of objects. The type of object will be appropriate to the column
-
uniqueValues
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
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 interestperiod
- 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 rangeperiod
- The period of interest- Returns:
- An array of two values: the minimum and maximum numeric value found in this column.
-
getMinMax
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 barpos
- The column position to calculate the rangeperiod
- The period of interest- Returns:
- An array of two values: the minimum and maximum numeric value found in this column.
-
getMinMax
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
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 interestperiod
- The period of interest- Returns:
- An array of two values: the minimum and maximum numeric value found in this column.
-
getMinMax
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 interestperiod
- The period of interest- Returns:
- An array of two values: the minimum and maximum numeric value found in this column.
-
calculateField
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 toolfield
- The field to be updated.
-
calculateField
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 toolfield
- The field to be updated.period
- The period used as the context for the update
-
queryTable
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
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 toolperiod
- The period used as the context for the query
-
identifyRecords
public void identifyRecords(int row)Show the specified row in theIdentifyViewer
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 windowfilename
- 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 exportreselect
- 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
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 windowfilename
- The output file name.defs
- AnArrayList
ofDBFColumnSpec
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 windowfilename
- The output file name.defs
- AnArrayList
ofDBFColumnSpec
values that decribe the column transformations.remap
- A row remap table to change the sorted order of output.period
- the planning period to exportreselect
- 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
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
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
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 windowfilename
- 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 anObserver
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 exportremapRows
- 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 anObserver
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
-
quoteIfRequired
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
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
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
Returns the title of this AttributeStore -
compareTo
Compare tables based on titles.- Specified by:
compareTo
in interfaceComparable
- 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
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.
-