Class CrosstabStore
- All Implemented Interfaces:
PopupActivationListener
,Serializable
,Comparable
,EventListener
,ListSelectionListener
,TableModel
getSnapshot(boolean)
method. The summary is 'static' and
will not change in response to changes in the underlying table.
All of the predefined report templates are aware of CrosstabStore's,
and they will request a snapshot when each report is generated,
thus providing up to date values.
Crosstab's are useful to reorganize data so that it may be more easily presented in reports. One common example is to create a report of average values. Consider getting a report of the average harvest age. The block table contains the treatment age and area harvested for each polygon. In order to get the average harvest age we need to sum the harvest age of each polygon, and then divide by the total area harvested. This operation can be expressed in as follows:
CrosstabStore cts = new CrosstabStore(blockData, "CURRENTTREATMENT ne ''", Horizon.periodList); cts.addValue("AgeArea", "TREATMENTAGE*MANAGEDAREA"); cts.addValue("Area", "MANAGEDAREA"); Report r = new PeriodValueReport("avAge", "Average treatment age", "Age", cts, new String[] {"AgeArea/Area"}, new String[] {"AvAge"}, "Area > 0", Horizon.periodList, null, false); reportWriter.addReport(r);You can view the contents of a snapshot by displaying the table:
cts.getSnapshot(false).showCube(true);
- See Also:
- Serialized Form
-
Nested Class Summary
Nested Classes -
Field Summary
Fields inherited from class ca.spatial.table.AttributeStore
SELECT_ADD, SELECT_FROM, SELECT_NEW
-
Constructor Summary
ConstructorsConstructorDescriptionCrosstabStore(AttributeStore parent, String reselectExpression, int[] periods)
CrosstabStore(AttributeStore parent, String reselectExpression, int[] periods, boolean transpose)
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addCategory(String label, String expression, Comparable[] originalCategories)
Add a category breakdown to the table.void
addProportion(String label, String pattern)
void
addProportion(String label, String[] columns)
Add a proportional breakdown to the table.void
addProportion(String label, String[] columns, String[] labels, int offset)
Add a proportional breakdown to the table.void
addProportion(String label, String pattern, int offset)
Add a proportional breakdown to the table.void
addRange(String label, String expression, RangeLabel[] ranges)
Add a numeric range breakdown to the table.void
Add a value to the table.int
findColumn(String field)
Get the column number of the given field in the table.getAttributeFormat(int field)
Get the format descriptor for a given column.int
Get the number of columns in this storeReturn a reference to the parent tableint
Get the total number of periods that this store supportsint[]
Return the periods that the table will be calculated forReturn the reselect expressionint
Get the number of rows in this storegetSnapshot(boolean useSelected)
Get a snapshot of this crosstab definition.getSnapshot(boolean useSelected, Observer progress)
Get a snapshot of this crosstab definition.boolean
Return the indicator if the columns in the table will be transposedgetValueAt(int row, int column, int period)
Get a cell valueint
getYearForPeriod(int period)
Get the ending year for a given period.setCategoryName(String columnName)
Set the name of the column that will be used to hold the categories when the transposition option is used.setValueName(String columnName)
Set the name of the column that will be used to hold values when the transposition option is used.Methods inherited from class ca.spatial.table.AttributeStore
absoluteFile, absoluteFile, absolutePath, absolutePath, addCellEditors, addMenuItems, addPopupActivationListener, addRelate, addRelate, addTableModelListener, addToGlobalStoreList, allowsEditing, booleanValue, booleanValue, buildIndex, calculate, calculateField, calculateField, canIndex, changeSelection, clearSelection, close, compareTo, decodeCharset, doubleValue, doubleValue, exportCSV, exportCSV, exportCSV, exportCSV, exportCSV, exportCSV, exportDBF, exportDBF, exportDBF, exportDBF, exportDBF, findColumn, findSimilarColumnNames, getCacheParent, getCachingLayer, getCachingLayer, getCanonicalName, getColumnClass, getColumnName, getColumnNames, getContextPeriods, getCwd, getEditMode, getFullColumnName, getListSelectionModel, getMinMax, getMinMax, getMinMax, getMinMax, getMinMax, getOpenStore, getOpenStore, getOpenStore, getOpenStores, getPeriod, getPeriodWidth, getRowNodeRemap, getSelectedRowCount, getSelection, getSelection, getSelection, getShortName, getStoreByShortName, getStoreByTitle, getSynchronizer, getTableName, getTableSpec, getTitle, getValueAt, hasIndex, identifyRecords, integerValue, integerValue, isCellEditable, isSelectedIndex, isSelectionEmpty, listify, listValue, listValue, lookupRow, makeLu, maybePopup, notifyPopupActivationListeners, openOrReuse, openOrReuse, queryTable, queryTable, quoteIfRequired, relativePath, removeFromGlobalStoreList, removePopupActivationListener, removeTableModelListener, select, select, selectAdd, selectFrom, selectNew, setCwd, setCwd, setEditMode, setListSelectionModel, setPeriod, setRowNodeRemap, setShortName, setTableSpec, setTitle, setValueAt, setValueAt, showCube, showTable, toString, uniqueValues, uniqueValues, uniqueValues, uniqueValues, uniqueValues, uniqueValues, uniqueValues, uniqueValues, valueChanged
Methods inherited from class javax.swing.table.AbstractTableModel
fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getListeners, getTableModelListeners
-
Constructor Details
-
CrosstabStore
-
CrosstabStore
public CrosstabStore(AttributeStore parent, String reselectExpression, int[] periods, boolean transpose)
-
-
Method Details
-
getParent
Return a reference to the parent table -
getReselectExpression
Return the reselect expression -
getPeriods
public int[] getPeriods()Return the periods that the table will be calculated for -
getTranspose
public boolean getTranspose()Return the indicator if the columns in the table will be transposed -
getSnapshot
Get a snapshot of this crosstab definition. The queries will be run to compute the categories and expressions for the current values in the underlying dataset. The results will be contained in the snapshot and will not change even if the underlying data set changes.- Overrides:
getSnapshot
in classAttributeStore
- Parameters:
useSelected
- The calculations will only be computed on the selected records.- Returns:
- This method will return a new shapshot that captures the state of the crosstab definition for the current data set.
-
getSnapshot
Get a snapshot of this crosstab definition. The queries will be run to compute the categories and expressions for the current values in the underlying dataset. The results will be contained in the snapshot and will not change even if the underlying data set changes.- Overrides:
getSnapshot
in classAttributeStore
- Parameters:
useSelected
- The calculations will only be computed on the selected records.progress
- A reference to a progress widget that will be updated with the progress of the calculations.- Returns:
- This method will return a new shapshot that captures the state of the crosstab definition for the current data set.
-
setCategoryName
Set the name of the column that will be used to hold the categories when the transposition option is used. The default value is 'Categories'. -
setValueName
Set the name of the column that will be used to hold values when the transposition option is used. The default value is 'Values'. -
addCategory
Add a category breakdown to the table. This will result in a new column in the table that will contain rows for each of the possible discrete values that can be returned by the expression.- Parameters:
label
- The name to be given to the column headingexpression
- The expression to evaluate to compute the category valueoriginalCategories
- A list of the potential category values that should be summarized into this report. Only values in this list will be included in the report.
-
addRange
Add a numeric range breakdown to the table. This will result in a new column in the table that will contains additional rows for each range of input values.- Parameters:
label
- The name to be given to the column headingexpression
- The expression to evaluate to compute the numeric valueranges
- A list of the potential ranges that should be summarized into this report. Only ranges in this list will be included in the report. The input value will be excluded if the expression returns a value that falls outside all of the ranges.
-
addProportion
Add a proportional breakdown to the table. This will result in a new column in the table that will contains additional rows for each input column used in the proportion calculation.Proportions work by adding new rows to the table, and then distributing the contents of the values columns proportionally between these rows. This is done by reading a row from the input table, summing the values of the proportional columns, and then dividing each proportional column by the total. The results of the value columns (see
addValue(java.lang.String, java.lang.String)
are then multiplied by these proportions.The column that is created by this method will contain the labels of the columns that are used to calculate the proportions.
- Parameters:
label
- The name to be given to the column headingcolumns
- A list of the columns that will be used to determine the proportional split.labels
- A list of labels that will be used to represent each column value.offset
- This value will be added to the year of interest when looking up values from the underlying table. This makes it possible to compare values from different years. For example, an offset of -1 will use the values from the previous planning period for the calculation. This could be used to compute change in volume from one period to the next, or perhaps change in area as a result of succession.
-
addProportion
Add a proportional breakdown to the table. This will result in a new column in the table that will contains additional rows for each input column used in the proportion calculation.Proportions work by adding new rows to the table, and then distributing the contents of the values columns proportionally between these rows. This is done by reading a row from the input table, summing the values of the proportional columns, and then dividing each proportional column by the total. The results of the value columns (see
addValue(java.lang.String, java.lang.String)
are then multiplied by these proportions.This method is identical to using
addProportion(label, columns, columns, 0);
The column that is created by this method will contain the names of the columns that are used to calculate the proportions.
- Parameters:
label
- The name to be given to the column headingcolumns
- A list of the columns that will be used to determine the proportional split.
-
addProportion
Add a proportional breakdown to the table. This will result in a new column in the table that will contains additional rows for each input column used in the proportion calculation.Proportions work by adding new rows to the table, and then distributing the contents of the values columns proportionally between these rows. This is done by reading a row from the input table, summing the values of the proportional columns, and then dividing each proportional column by the total. The results of the value columns (see
addValue(java.lang.String, java.lang.String)
are then multiplied by these proportions.The column that is created by this method will contain the names of the columns that are used to calculate the proportions.
- Parameters:
label
- The name to be given to the column headingpattern
- A pattern that identifies the columns that will be used to determine the proportional split.offset
- This value will be added to the year of interest when looking up values from the underlying table. This makes it possible to compare values from different years. For example, an offset of -1 will use the values from the previous planning period for the calculation. This could be used to compute change in volume from one period to the next, or perhaps change in area as a result of succession.
-
addProportion
-
addValue
Add a value to the table. The result of the expression will be added into the table that matches the row with the right combination of categories, ranges and proportions for the input record.- Parameters:
label
- The name give to the columnexpression
- The value to be computed and added to the column
-
getRowCount
public int getRowCount()Description copied from class:AttributeStore
Get the number of rows in this store- Specified by:
getRowCount
in interfaceTableModel
- Specified by:
getRowCount
in classAttributeStore
- Returns:
- the number of rows in this store
-
getPeriodCount
public int getPeriodCount()Description copied from class:AttributeStore
Get the total number of periods that this store supports- Specified by:
getPeriodCount
in classAttributeStore
- Returns:
- The number of periods in this store
-
getYearForPeriod
public int getYearForPeriod(int period)Description copied from class:AttributeStore
Get the ending year for a given period.- Specified by:
getYearForPeriod
in classAttributeStore
- Parameters:
period
- The period of interest- Returns:
- the year for a given period
-
getColumnCount
public int getColumnCount()Description copied from class:AttributeStore
Get the number of columns in this store- Specified by:
getColumnCount
in interfaceTableModel
- Overrides:
getColumnCount
in classAttributeStore
- Returns:
- the number of columns in this store
-
getValueAt
Description copied from class:AttributeStore
Get a cell value- Specified by:
getValueAt
in classAttributeStore
- Parameters:
row
- The row containing the cellcolumn
- The column containing the cellperiod
- The period of interest- Returns:
- An object containing the cell value.
-
findColumn
Description copied from class:AttributeStore
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 classAttributeStore
- Parameters:
field
- The name of the field to look up
-
getAttributeFormat
Description copied from class:AttributeStore
Get the format descriptor for a given column.- Overrides:
getAttributeFormat
in classAttributeStore
- Parameters:
field
- The column of interest- Returns:
- The
AttributeFormat
for this field
-