ewe.data
Class FieldTableModel

java.lang.Object
  extended byewe.ui.TableModel
      extended byewe.data.FieldTableModel
All Implemented Interfaces:
CellConstants, ControlConstants, EventListener, UIConstants
Direct Known Subclasses:
DatabaseTableModel

public class FieldTableModel
extends TableModel

This is a very useful class that allows the display of public fields of an object within cells of the table - even allowing you to edit the fields within the table.

Once you create a new FieldTableModel, you call the setFields() method to specify which fields to display. There is a setFields() method that allows you to specify that all the object fields should be displayed.

The objects member is a Vector that holds the list of objects to display - call setObjects() to set it. However if you do not wish to use a Vector then you will need to override two methods: calculateNumRows() and loadObjectAtRow(int row)

The constructor FieldTableModel(Object anObject,Vector objectList) is the quickest way to display a set of objects in a table. After calling this constructor you can call getTableForm() to get a Form that contains a scrollable table that uses this FieldTableModel.


Nested Class Summary
 
Nested classes inherited from class ewe.ui.TableModel
TableModel.CellControl, TableModel.ControlProxy
 
Field Summary
 MultiListSelect.SingleListSelect allColumns
          This is a list of all the possible fields that can be displayed by the model.
 int cacheSize
          The number of objects to cache - 20 by default.
 Vector displayFields
          This holds the list of fields that are being displayed.
 boolean dontCacheObjects
          Set this true if you don't want objects to be cached.
protected  Lock getLock
           
 Reflect objectClass
          This is a Reflect that represents the class of the objects being displayed.
 Object objectData
          This is an example (an instance of) the objectClass.
 Vector objects
          This can be used to hold the objects being displayed (one per row) - however implementations are free to ignore this and use some other method of accessing the object for a particular row.
 boolean readOnly
          Set this true to have a read-only display.
 
Fields inherited from class ewe.ui.TableModel
activeCellControl, allColumnsSameSize, allRowsSameSize, canHScroll, canVScroll, cellInsets, charHeight, clipData, controlProxy, cursorSize, fillToEqualHeights, fillToEqualWidths, gap, hasColumnHeaders, hasPreferredSize, hasRowHeaders, hasSpanningColumns, hasSpanningRows, horizontalScrollUnit, insets, numCols, numRows, preferredCols, preferredRows, rect, selectRowWhenEditing, shadeAlternateRows, table, tca, verticalScrollUnit
 
Fields inherited from interface ewe.ui.UIConstants
BDR_DOTTED, BDR_INNER, BDR_NOBORDER, BDR_OUTER, BDR_OUTLINE, BDR_RAISEDINNER, BDR_RAISEDOUTER, BDR_SUNKENINNER, BDR_SUNKENOUTER, BF_BOTTOM, BF_BOTTOMLEFT, BF_BOTTOMRIGHT, BF_BUTTON, BF_DIAGONAL, BF_DIAGONAL_ENDBOTTOMLEFT, BF_DIAGONAL_ENDBOTTOMRIGHT, BF_DIAGONAL_ENDTOPLEFT, BF_DIAGONAL_ENDTOPRIGHT, BF_EXACT, BF_FLAT, BF_LEFT, BF_MIDDLE, BF_MONO, BF_PALM, BF_RECT, BF_RIGHT, BF_SOFT, BF_SQUARE, BF_TOP, BF_TOPLEFT, BF_TOPRIGHT, EDGE_BUMP, EDGE_ETCHED, EDGE_RAISED, EDGE_SUNKEN
 
Fields inherited from interface ewe.ui.CellConstants
BORDER, BOTTOM, CELLFLAG, CELLMASK, CENTER, CONTROLMASK, DONTCHANGE, DONTFILL, DONTSTRETCH, EAST, FILL, FIXEDSIZE, GROW, HCENTER, HCONTRACT, HEXPAND, HFILL, HGROW, HSHRINK, HSTRETCH, INITIALLY_CLOSED, INITIALLY_MINIMIZED, INITIALLY_PREFERRED_SIZE, INSETS, LEFT, MAXIMUMSIZE, MINIMUMSIZE, NORTH, NORTHEAST, NORTHWEST, PREFERREDSIZE, RECT, RIGHT, SHRINK, SOUTH, SOUTHEAST, SOUTHWEST, SPAN, STRETCH, TEXTSIZE, TOP, VCENTER, VCONTRACT, VEXPAND, VFILL, VGROW, VSHRINK, VSTRETCH, WEST
 
Fields inherited from interface ewe.ui.ControlConstants
All, AlwaysEnabled, AlwaysRecalculateSizes, ByDeferredMouse, ByDeferredPen, ByFrameChange, ByKeyboard, ByMouse, ByPen, ByRequest, CalculatedSizes, Disabled, DisablePopupMenu, DisplayOnly, Down, DrawFlat, Flag, ForceResize, HasData, Invisible, KeepImage, KeepSIP, Left, MakeMenuAtLeastAsWide, Maximize, Minimize, MouseSensitive, NoFocus, NotAnEditor, NotEditable, PaintDataOnly, PaintOutsideOnly, PenTransparent, PreferredSizeOnly, Right, SendUpKeyEvents, SendUpPenEvents, ShowSIP, ShrinkToNothing, SmallControl, SpecialBackground, TakeControlEvents, TakesKeyFocus, Transparent, Up, WantDrag, WantHoldDown
 
Constructor Summary
FieldTableModel()
          Create an empty FieldTableModel.
FieldTableModel(Object anObject, Vector objects)
          Create a new FieldTableModel using an instance of a specific object and an array of objects.
 
Method Summary
protected  void cacheObject(int row, Object obj)
          Assign the specified object to the cache for a particular row.
 int calculateColWidth(int col)
          This returns the full width of the column.
protected  int calculateNumRows()
          This calculates the number of rows in the table.
 int calculateRowHeight(int row)
          This returns the full height of the row.
protected  int calculateTextCharsInColumn(int col)
          This is called by calculateColWidth().
 int countEntries()
          This calls calculateNumRows() which is what you should override.
protected  void dataChanged(FieldTransfer ft, Point cell)
           
protected  void dataChanged(Object obj, int row, String fieldName)
           
 void doColumnSelection()
           
 boolean doHotKey(KeyEvent ev)
           
 void entriesChanged()
          Call this to notify the table that the entries to be displayed have been changed in some way.
 void entriesChanged(int selectIndex)
          This calls entriesChanged and then selects a specified row.
 Vector getAllFields()
          Get all the available fields as a list of FieldData objects.
protected  Object getCachedObject(int row)
           
 TableCellAttributes getCellAttributes(int row, int col, boolean sel, TableCellAttributes tca)
          Get the attributes for a cell.
protected  TableModel.CellControl getCellControlFor(Point p)
          Get a Control to edit data within a particular cell within a CellControl object.
 Object getCellText(int row, int col)
          This may return a String or an array of Strings (for multiline text) or it may return null.
 Editor getColumnSelector(MultiListSelect.SingleListSelect columns)
          Get an Editor that you can use to decide which columns are being displayed in the table.
 Control getColumnSelectorButton(boolean textLabel)
           
 Task getExportTask(FieldTableExportSpecs specs)
          Get a TaskObject that will, when started, export the data as specified in the provided FieldTableExportSpecs.
 FieldData getField(String fieldName)
          Get the FieldData for a particular field name.
 FieldData getFieldData(int col)
          Get the field data for a particular column.
 Object getFieldValue(FieldData fd, int row)
          Get the value of a field at the specified row.
protected  int getMaxColWidth(int col)
          If this returns -1 there will be no maximum.
protected  int getMinColWidth(int col)
           
 Object getNew()
          Get a new instance of the object being edited if possible.
protected  Object getObjectAtRow(int row)
          Don't override this, you should override loadObjectAtRow() instead.
 int getSelectedEntry()
          If only one entry is selected, return the row index of that entry.
 Control getTableExportButton(boolean textLabel)
           
 Editor getTableExporter()
          Get an Editor that can be used to allow the user to export the table data.
 Form getTableForm(Form f)
          Get a Form that contains a scrollable Table with this FieldTableModel.
 Form getTableForm(Form f, boolean putExtraControls)
          Get a Form that contains a scrollable Table with this FieldTableModel.
 void invalidateCache()
           
 void invalidateCachedObject()
          Deprecated. use invalidateCache() or invalidateCachedObject(int row);
 void invalidateCachedObject(int row)
           
protected  Object loadObjectAtRow(int row)
          Override this to use a different method of retrieving the object at a particular row.
 void made()
          This is called after the TableControl has been made.
static void main(String[] args)
          This allows you to execute the following command line:
 FieldTableModel modifyFields(Object objectOrReflect, String headersAndFields)
          This can be used to modify any of the fields.
 void onEvent(Event ev)
           
 void rowChanged(int row)
           
 void selectEntry(int index)
          Select a particular row and make it visible if it is not so already.
 void setFields(MultiListSelect.SingleListSelect fields)
           
 FieldTableModel setFields(Object objectOrReflect)
          This can be used to set all the fields.
 FieldTableModel setFields(Object objectOrReflect, int[] initial)
          This can be used to set all the fields.
 void setFields(Object objectOrReflect, String[] fieldProperties, int[] initialChoices)
          Set all the fields given a set of String encoded properties for each field.
 FieldTableModel setFields(Object objectOrReflect, String headersAndFields, int[] initial)
          This can be used to set all the fields.
 void setFields(Vector allFields, int[] initialChoices)
          Set all the fields.
 FieldTableModel setObjects(Vector objs)
          This sets the "objects" variable which is usually used to get the object for each row.
 
Methods inherited from class ewe.ui.TableModel
calculateTextLinesInRow, canScreenScroll, canSelect, checkControlFor, clearCellAdjustments, closeActiveControl, deferPaintTableCell, findCellsInArea, fixBorder, getCellData, getCellInsets, getCellPreferredSize, getCellRect, getColWidth, getControlFor, getLinesFor, getMaxRowHeight, getMenuFor, getMenuOutsideCells, getMinRowHeight, getPreferredSize, getRowHeight, getToolTip, hasActiveControls, inset, isActiveCellControl, notifyDataChange, onKeyEvent, paintTableCell, paintTableCell, paintTableCellData, paintTableCellText, penPressed, popupMenuEvent, remapColumns, resized, scrollTo, select, show, startedEditing
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, toString
 

Field Detail

displayFields

public Vector displayFields
This holds the list of fields that are being displayed.


objects

public Vector objects
This can be used to hold the objects being displayed (one per row) - however implementations are free to ignore this and use some other method of accessing the object for a particular row.


allColumns

public MultiListSelect.SingleListSelect allColumns
This is a list of all the possible fields that can be displayed by the model.


objectClass

public Reflect objectClass
This is a Reflect that represents the class of the objects being displayed.


objectData

public Object objectData
This is an example (an instance of) the objectClass. This is not necessary, but without it certain functions cannot be done.


readOnly

public boolean readOnly
Set this true to have a read-only display.


getLock

protected Lock getLock

dontCacheObjects

public boolean dontCacheObjects
Set this true if you don't want objects to be cached.


cacheSize

public int cacheSize
The number of objects to cache - 20 by default.

Constructor Detail

FieldTableModel

public FieldTableModel()
Create an empty FieldTableModel. You will need to set the object class and fields yourself.


FieldTableModel

public FieldTableModel(Object anObject,
                       Vector objects)
Create a new FieldTableModel using an instance of a specific object and an array of objects. All the public fields of the object will be displayed.

Parameters:
anObject - An instance of the object to be displayed.
objects - A list of objects to display.
Method Detail

setFields

public FieldTableModel setFields(Object objectOrReflect,
                                 String headersAndFields,
                                 int[] initial)
This can be used to set all the fields. The format for each entry in headersAndFields is either:

[fieldName];[length[:height]];[flags];[alignment|anchor];[control anchor]

separated by commas OR

[headerName]|[fieldName];[length[:height]];[flags];[alignment|anchor];[control anchor]

separated by '|' symbols.

[flags] should be a combination of: 'r' for Read-Only

[alignment] should be one of: L, R [anchor] should be one of: N, S, E, W, H, h, V, v, F

Parameters:
objectOrReflect - The object being edited or the class of the object.
headersAndFields - The list of headers and fields with optional formatting info.
initial - the list of field indexes to show initially. This can be null in which case all the fields are shown.
Returns:
this FieldTableModel

modifyFields

public FieldTableModel modifyFields(Object objectOrReflect,
                                    String headersAndFields)
This can be used to modify any of the fields. The format for each entry in headersAndFields is either:

[fieldName];[length[:height]];[flags];[alignment|anchor];[control anchor]

separated by commas OR

[headerName]|[fieldName];[length[:height]];[flags];[alignment|anchor];[control anchor]

separated by '|' symbols.

[flags] should be a combination of: 'r' for Read-Only

[alignment] should be one of: L, R [anchor] should be one of: N, S, E, W, H, h, V, v, F

Parameters:
objectOrReflect - The object being edited or the class of the object.
headersAndFields - The list of headers and fields with optional formatting info.
Returns:
this FieldTableModel

setFields

public FieldTableModel setFields(Object objectOrReflect,
                                 int[] initial)
This can be used to set all the fields.

Parameters:
objectOrReflect - The object being edited or the class of the object.
initial - the list of field indexes to show initially. This can be null in which case
Returns:
this FieldTableModel

setFields

public FieldTableModel setFields(Object objectOrReflect)
This can be used to set all the fields.

Parameters:
objectOrReflect - The object being edited or the class of the object.
Returns:
this FieldTableModel

setFields

public void setFields(Vector allFields,
                      int[] initialChoices)
Set all the fields. Each field item must be of the type FieldData.

Parameters:
allFields - The fields stored in a Vector.
initialChoices - the indexes of the field that will be displayed initially. This can be null.

setFields

public void setFields(Object objectOrReflect,
                      String[] fieldProperties,
                      int[] initialChoices)
Set all the fields given a set of String encoded properties for each field. Each element of the fieldProperties must be of the form: "field|lastName|header|Last Name|editable|false". See the FieldData.decode(PropertyList) method for the listof possible properties.

Parameters:
objectOrReflect - The data object or the Class/Reflect object for the data object.
fieldProperties - An array of String encoded properties for the fields.
initialChoices - the indexes of the field that will be displayed initially. This can be null.

setFields

public void setFields(MultiListSelect.SingleListSelect fields)

setObjects

public FieldTableModel setObjects(Vector objs)
This sets the "objects" variable which is usually used to get the object for each row.


getNew

public Object getNew()
Get a new instance of the object being edited if possible.


getTableForm

public Form getTableForm(Form f,
                         boolean putExtraControls)
Get a Form that contains a scrollable Table with this FieldTableModel.

Parameters:
f - A destination form to add to, which can be null.
putExtraControls - If this is true then a "Column Selector" button and a "Table Export" button will be added.
Returns:
a Form that contains a scrollable Table with this FieldTableModel.

getTableForm

public Form getTableForm(Form f)
Get a Form that contains a scrollable Table with this FieldTableModel. A "Column Selector" button and a "Table Export" button will be added to the form.

Parameters:
f - A destination form to add to, which can be null.
Returns:
a Form that contains a scrollable Table with this FieldTableModel.

getColumnSelector

public Editor getColumnSelector(MultiListSelect.SingleListSelect columns)
Get an Editor that you can use to decide which columns are being displayed in the table.


getMinColWidth

protected int getMinColWidth(int col)
Overrides:
getMinColWidth in class TableModel

getMaxColWidth

protected int getMaxColWidth(int col)
Description copied from class: TableModel
If this returns -1 there will be no maximum.

Overrides:
getMaxColWidth in class TableModel

getAllFields

public Vector getAllFields()
Get all the available fields as a list of FieldData objects.


getField

public FieldData getField(String fieldName)
Get the FieldData for a particular field name.


getTableExporter

public Editor getTableExporter()
Get an Editor that can be used to allow the user to export the table data.


getExportTask

public Task getExportTask(FieldTableExportSpecs specs)
Get a TaskObject that will, when started, export the data as specified in the provided FieldTableExportSpecs. Note that you do not need this if you use display the Editor provided by getTableExporter() since that handles the export task itself.


getTableExportButton

public Control getTableExportButton(boolean textLabel)

doColumnSelection

public void doColumnSelection()

getColumnSelectorButton

public Control getColumnSelectorButton(boolean textLabel)

loadObjectAtRow

protected Object loadObjectAtRow(int row)
                          throws Exception
Override this to use a different method of retrieving the object at a particular row.

Throws:
Exception

cacheObject

protected void cacheObject(int row,
                           Object obj)
Assign the specified object to the cache for a particular row.


getCachedObject

protected Object getCachedObject(int row)

invalidateCachedObject

public void invalidateCachedObject(int row)

rowChanged

public void rowChanged(int row)

invalidateCachedObject

public void invalidateCachedObject()
Deprecated. use invalidateCache() or invalidateCachedObject(int row);

This is the same as invalidateCache().


invalidateCache

public void invalidateCache()

getObjectAtRow

protected Object getObjectAtRow(int row)
Don't override this, you should override loadObjectAtRow() instead. This method checks the cache first.


getFieldData

public FieldData getFieldData(int col)
Get the field data for a particular column.


getCellAttributes

public TableCellAttributes getCellAttributes(int row,
                                             int col,
                                             boolean sel,
                                             TableCellAttributes tca)
Description copied from class: TableModel
Get the attributes for a cell. Note that even though a TableCellAttributes is passed to the method, for effeciency a completely different one may be returned. You should therefore not attempt to modify or reuse the one that is returned.

Overrides:
getCellAttributes in class TableModel

getFieldValue

public Object getFieldValue(FieldData fd,
                            int row)
Get the value of a field at the specified row.


getCellText

public Object getCellText(int row,
                          int col)
Description copied from class: TableModel
This may return a String or an array of Strings (for multiline text) or it may return null. If it returns null then the value returned by getCellData(r,c) will be used to paint the cell contents.

Overrides:
getCellText in class TableModel

calculateRowHeight

public int calculateRowHeight(int row)
Description copied from class: TableModel
This returns the full height of the row. If the requested row is -1 (header row) and there are no column headers it should return 0.

Overrides:
calculateRowHeight in class TableModel

calculateColWidth

public int calculateColWidth(int col)
Description copied from class: TableModel
This returns the full width of the column. If the requested col is -1 (header col) and there are no row headers it should return 0.

Overrides:
calculateColWidth in class TableModel

made

public void made()
Description copied from class: TableModel
This is called after the TableControl has been made.

Overrides:
made in class TableModel

dataChanged

protected void dataChanged(Object obj,
                           int row,
                           String fieldName)

dataChanged

protected void dataChanged(FieldTransfer ft,
                           Point cell)

onEvent

public void onEvent(Event ev)
Specified by:
onEvent in interface EventListener
Overrides:
onEvent in class TableModel

getCellControlFor

protected TableModel.CellControl getCellControlFor(Point p)
Description copied from class: TableModel
Get a Control to edit data within a particular cell within a CellControl object. This is called when the pen is pressed on a Control. By default this method calls getControlFor() and if that does not return null, then a new CellControl is created and returned for that Control.

Overrides:
getCellControlFor in class TableModel
Parameters:
p - the cell the CellControl is for.
Returns:
a CellControl used to edit data for a particular cell, or null if editing that cell data is not allowed.

calculateNumRows

protected int calculateNumRows()
This calculates the number of rows in the table. By default this will return the size of the objects Vector. If this Vector is null it will return zero. Override this if you are not using the objects Vector - in which case you must also override loadObjectAtRow().


entriesChanged

public void entriesChanged()
Call this to notify the table that the entries to be displayed have been changed in some way. It recalculates the number of rows and redisplays the table.


calculateTextCharsInColumn

protected int calculateTextCharsInColumn(int col)
Description copied from class: TableModel
This is called by calculateColWidth(). It should give the number of characters that should fit in a column.

Overrides:
calculateTextCharsInColumn in class TableModel

entriesChanged

public void entriesChanged(int selectIndex)
This calls entriesChanged and then selects a specified row.

Parameters:
selectIndex - the row to select, or -1 to clear the selection.
Returns:

getSelectedEntry

public int getSelectedEntry()
If only one entry is selected, return the row index of that entry.


selectEntry

public void selectEntry(int index)
Select a particular row and make it visible if it is not so already.


countEntries

public int countEntries()
This calls calculateNumRows() which is what you should override.


doHotKey

public boolean doHotKey(KeyEvent ev)
Overrides:
doHotKey in class TableModel

main

public static void main(String[] args)
                 throws Exception
This allows you to execute the following command line:

ewe ewe.data.FieldTableModel []

to bring up a demo/test Table that will display/edit the public fields of the specified object. Try it out on: ewe ewe.data.FieldTableModel ewe.sys.MemoryStatus 10

Throws:
Exception