# Class StoreConfiguration

java.lang.Object
javax.swing.table.AbstractTableModel
uk.ac.starlink.util.gui.StoreConfiguration

All Implemented Interfaces:
  `Serializable, TableModel`

public class StoreConfiguration extends AbstractTableModel
This class interacts with a permanent set of configuration states stored in an XML-format disk file. Each state is identified by a description and date stamp, which are added when a state is stored. The content of the state isn't actually understood at this level that is left to more specific classes.

An instance of this class presents itself as two services. One is as a JTable model, this provides a model of two columns, the first being the state description the second the date stamp. The second set of services are provided to get at states and to store new ones. These latter options are provided by passing back references to suitable Elements of a Document, which then act as roots for the state.

The format of the XML file is just determined by the practices adopted in this file and by the `StoreSource` implementation, rather than by a DTD or Schema. The root element is <configs> each child of this element is called whatever `StoreSource.getTagName()` returns, with the attributes "description" and "date-stamp", what goes after this is determined by the writer of the configurations, but the general idea is for each object in the configuration to write its state to a new Element.

Author:
  Peter W. Draper
See Also:
  - `Element`
  - `StoreControlFrame`
  - `StoreSource`
  - Serialized Form

## Field Summary

Fields
Modifier and Type
Field
Description
`protected String`
`applicationName`
Name of the application (used for name of config directory).
`protected Document`
`document`
The Document.
`protected Element`
`rootElement`
Document root Element.
`protected String`
`storeName`
Name of the file used for storage.

### Fields inherited from class AbstractTableModel

`listenerList`

## Constructor Summary

Constructors
Constructor
Description
`StoreConfiguration(InputStream inputStream)`
Create an instance.
`StoreConfiguration(String applicationName, String storeName)`
Create an instance.

## Method Summary

Modifier and Type
Method
Description
`protected void`
`createEmptyDoc()`
Create an empty document
`static List<Element>`
`getChildElements(Element element)`
Return all the Elements that are children of another Element.
`int`
`getColumnCount()`
Get the number of columns.
`String`
`getColumnName(int column)`
Get the name of a column.
`int`
`getCount()`
Get the number of states that are stored.
`String`
`getDateStamp(int index)`
Get the date stamp of a state by index.
`String`
`getDescription(int index)`
Get the description of a state by index.
`int`
`getRowCount()`
Return the numbers of states that we're currently storing.
`Element`
`getState(int index)`
Get a state from the store.
`Object`
`getValueAt(int row, int column)`
Return either the description or date stamp of a state.
`void`
`initFromBackingStore()`
Initialise the local DOM from the backing store file.
`void`
`initFromBackingStore(InputStream inputStream)`
Initialise the local DOM from an InputStream.
`boolean`
`isCellEditable(int row, int column)`
Let the JTable know that the descriptions are edittable.
`Element`
`newState(String elementName, String description)`
Create a new Element ready for attaching a configuration state to (i.e.
`Element`
`reGetState(int index)`
Re-get a state from the store.
`void`
`removeState(int index)`
Permanently remove a state from store.
`void`
`setDateStamp(int index)`
Set the date stamp of a state by index.
`void`
`setDescription(int index, String value)`
Set the description of a state by index.
`void`
`setValueAt(Object value, int row, int column)`
Change a description in response to a user edit.
`void`
`stateCompleted(Element newState)`
Add a new state root in a given Element.
`void`
`writeToBackingStore()`
Save the Document to backing store.

### Methods inherited from class AbstractTableModel

`addTableModelListener, findColumn, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getColumnClass, getListeners, getTableModelListeners, removeTableModelListener`

### Methods inherited from class Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### document

protected Document document
The Document.

### rootElement

protected Element rootElement
Document root Element.

### applicationName

protected String applicationName
Name of the application (used for name of config directory).

### storeName

protected String storeName
Name of the file used for storage.

## Constructor Details

### StoreConfiguration

public StoreConfiguration(String applicationName, String storeName)
Create an instance. This synchronises the current total state with that of the backing store.

Parameters:
  `applicationName` - name of the application controlling this store. Used to create a top-element, also defines the configuration directory. XXX use Properties for this?
  `storeName` - name of the file that contains the configuration

### StoreConfiguration

public StoreConfiguration(InputStream inputStream)
Create an instance. This synchronises the current total state with that read from a given InputStream (useful when want to get a default configuration using a getResource()). If you use this method it is not possible to save to backing store.

Parameters:
  `inputStream` - InputStream that contains an XML description of a series of configurations (i.e. a wrapped backing store file).

## Method Details

### initFromBackingStore

public void initFromBackingStore(InputStream inputStream)
Initialise the local DOM from an InputStream.

### initFromBackingStore

public void initFromBackingStore()
Initialise the local DOM from the backing store file. If this doesn't exist then just create an empty Document with a basic root Element.

### createEmptyDoc

protected void createEmptyDoc()
Create an empty document

### getChildElements

public static List<Element> getChildElements(Element element)
Return all the Elements that are children of another Element.

### getCount

public int getCount()
Get the number of states that are stored.

### getState

public Element getState(int index)
Get a state from the store. These are indexed simply by the order in the current document.

### reGetState

public Element reGetState(int index)
Re-get a state from the store. Re-getting implies that this will be overwritten so all children are removed.

### getDescription

public String getDescription(int index)
Get the description of a state by index.

### setDescription

public void setDescription(int index, String value)
Set the description of a state by index.

### getDateStamp

public String getDateStamp(int index)
Get the date stamp of a state by index.

### setDateStamp

public void setDateStamp(int index)
Set the date stamp of a state by index. Updates to representation of the current time.

### stateCompleted

public void stateCompleted(Element newState)
Add a new state root in a given Element. The Element should be created by the newState method.

### newState

public Element newState(String elementName, String description)
Create a new Element ready for attaching a configuration state to (i.e. get this Element then write the configuration data attached to it). When the new configuration is completed invoke the stateCompleted method, the configuration will not be part of the structure until then.

### removeState

public void removeState(int index)
Permanently remove a state from store.

### writeToBackingStore

public void writeToBackingStore()
Save the Document to backing store.

### getRowCount

public int getRowCount()
Return the numbers of states that we're currently storing.

### getColumnCount

public int getColumnCount()
Get the number of columns. Always 2.

### getValueAt

public Object getValueAt(int row, int column)
Return either the description or date stamp of a state.

### getColumnName

public String getColumnName(int column)
Get the name of a column.

Specified by:
  `getColumnName` in interface `TableModel`
Overrides:
  `getColumnName` in class `AbstractTableModel`

### setValueAt

public void setValueAt(Object value, int row, int column)
Change a description in response to a user edit.

Specified by:
  `setValueAt` in interface `TableModel`
Overrides:
  `setValueAt` in class `AbstractTableModel`

### isCellEditable

public boolean isCellEditable(int row, int column)
Let the JTable know that the descriptions are edittable.

Specified by:
  `isCellEditable` in interface `TableModel`
Overrides:
  `isCellEditable` in class `AbstractTableModel`