public class FieldTableModel extends TableModel
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.
TableModel.CellControl, TableModel.ControlProxy
Modifier and Type | Field and Description |
---|---|
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.
|
protected int |
charWidth
This is the width of an average character.
|
Vector |
displayFields
This holds the list of fields that are being displayed.
|
Locale |
displayLocale
This is the Locale used to format decimal data for display.
|
boolean |
dontCacheObjects
Set this true if you don't want objects to be cached.
|
boolean |
dontSplitHeaders
Set this true to tell the TableModel not to split headers into separate lines
if they are wider than their specified width.
|
protected Gate |
getLock |
protected int |
headerRowHeight |
Class |
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.
|
protected int |
rowHeight |
protected int |
rowLines |
activeCellControl, allColumnsSameSize, allRowsSameSize, canHScroll, canMoveColumnHeaders, canVScroll, cellInsets, charHeight, clipData, colAdjustments, controlProxy, cursorSize, fillToEqualHeights, fillToEqualWidths, gap, hasColumnHeaders, hasPreferredSize, hasRowHeaders, hasSpanningColumns, hasSpanningRows, horizontalScrollUnit, keepSIP, mouseIsOverCell, numCols, numRows, preferredCols, preferredRows, selectRowWhenEditing, shadeAlternateRows, shadeColor, table, verticalScrollUnit
BDR_DOTTED, BDR_INNER, BDR_NOBORDER, BDR_OUTER, BDR_OUTLINE, BDR_RAISEDINNER, BDR_RAISEDOUTER, BDR_SUNKENINNER, BDR_SUNKENOUTER, BF_ABUT_ANY, BF_ABUT_BOTTOM, BF_ABUT_LEFT, BF_ABUT_RIGHT, BF_ABUT_TOP, 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
ALWAYS_STRETCHABLE, BOTTOM, CELLFLAG, CELLMASK, CENTER, CONTROLMASK, DONTCHANGE, DONTFILL, DONTSTRETCH, EAST, FILL, GROW, HCENTER, HCONTRACT, HEXPAND, HFILL, HGROW, HSHRINK, HSTRETCH, INITIALLY_CLOSED, INITIALLY_HIDDEN, INITIALLY_MINIMIZED, INITIALLY_PREFERRED_SIZE, INSETS, LEFT, MAXIMUMSIZE, MINIMUMSIZE, NORTH, NORTHEAST, NORTHWEST, PREFERREDSIZE, RECT, RIGHT, SHRINK, SOUTH, SOUTHEAST, SOUTHWEST, SPAN, STRETCH, TAG_BACKGROUND_IMAGE, TAG_BUSY_DISPLAY, TAG_COLORS, TAG_CONTROL_PAINTER, TAG_EXPOSE_GROUP, TAG_FIXEDSIZE, TAG_GRAY_BACKGROUND, TAG_HIDE_CONTROL_OBJECT, TAG_HIDE_PARENT, TAG_INNER_TEXT_INSETS, TAG_INPUT_STACK_PARENT, TAG_INSETS, TAG_MAKE_VISIBLE, TAG_MAXIMUMSIZE, TAG_MINIMUMSIZE, TAG_PAINT_CONTROL_LIST, TAG_PREFERRED_TEXT_SIZE, TAG_PREFERRED_TEXT_SIZE_HEIGHT, TAG_PREFERRED_TEXT_SIZE_WIDTH, TAG_PREFERREDSIZE, TAG_RECT, TAG_SHADOW_INSETS, TAG_SPAN, TAG_SWIPER, TAG_TEMPORARY_ERROR, TAG_TEXT_INSETS, TAG_TEXTSIZE, TEXTSIZE, TOP, VCENTER, VCONTRACT, VEXPAND, VFILL, VGROW, VSHRINK, VSTRETCH, WEST
All, AlwaysEnabled, AlwaysRecalculateSizes, ByDeferredMouse, ByDeferredPen, ByFrameChange, ByKeyboard, ByMouse, ByPen, ByRequest, CalculatedSizes, ContainerDontPaintChildren, Disabled, DisablePopupMenu, DisplayOnly, DontBuffer, Down, DrawFlat, Flag, ForceResize, HasData, Invisible, KeepImage, KeepSIP, Left, MakeMenuAtLeastAsWide, Maximize, Minimize, ModifiersInheritedFromWindow, MouseSensitive, NoFocus, NotAnEditor, NotEditable, PaintDataOnly, PaintOutsideOnly, PenTransparent, PreferredSizeOnly, Right, SendUpUIEvents, ShowSIP, ShrinkToNothing, SmallControl, TakeChildUIEvents, TakeControlEvents, TakesKeyFocus, Transparent, Up, WantDrag, WantHoldDown
Constructor and Description |
---|
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.
|
Modifier and Type | Method and Description |
---|---|
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 |
getAllFieldData()
This returns the Vector of all the FieldData objects that can be used with this FieldTableModel
|
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.
|
boolean |
getCellText(int row,
int col,
StringList dest)
Override this to provide text data to display in a cell.
|
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.
|
FieldData |
getFieldData(String fieldName) |
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) |
Form |
getTableForm(Form f,
Panel tableDestination,
Panel 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() |
protected TableModel.CellControl |
madeCellControlFor(FieldData fd,
TableModel.CellControl cc)
This is called after a CellControl is made for editing.
|
static void |
main(String[] args)
This allows you to execute the following command line:
ewe ewe.data.FieldTableModel
|
FieldTableModel |
modifyFields(Object objectOrReflect,
String headersAndFields)
This can be used to modify any of the fields.
|
void |
onEvent(Event ev) |
void |
recalculateHeaderRow() |
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(Object dataOrClass,
String headersAndFields,
String initialFields,
String excludeFields) |
void |
setFields(Object dataOrClass,
Vector fieldData,
String initialFields,
String excludeFields) |
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.
|
static MultiListSelect.SingleListSelect |
toListSelect(Vector allFields,
int[] initial) |
acceptColumnMoved, calculatePreferredColWidth, calculatePreferredRowHeight, calculatePreferredSize, calculateSizes, calculateTextLinesInRow, canScreenScroll, canSelect, checkControlFor, clearCellAdjustments, clearColumnWidthAdjustments, clearSelectionOnClick, closeActiveControl, columnMoved, deferPaintTableCell, editNow, editNow, endEditing, findCellsInArea, fixBorder, freezeUpdate, getCellData, getCellInsets, getCellPreferredSize, getCellRect, getCellText, getColWidth, getColXPointInTable, getControlFor, getLock, getMaxRowHeight, getMenuFor, getMenuOutsideCells, getMinRowHeight, getPreferredSize, getRowHeight, getRowYPointInTable, getTable, getToolTip, handleEvent, hasActiveControls, hasCellControlFor, inset, isActiveCellControl, makeActiveControlVisible, mouseMoving, mouseOverChanged, notifyDataChange, onKeyEvent, paintTableCell, paintTableCell, paintTableCellData, paintTableCellText, penClicked, penPressed, popupMenuEvent, positionCellControl, remapColumns, resized, restoreColumnWidthAdjustments, saveColumnWidthAdjustments, scrolled, scrollTo, select, setColAdjust, setColWidth, show, showingMenuFor, sizeColumnToFitData, startedEditing, updateControls
public Vector displayFields
public Vector objects
public MultiListSelect.SingleListSelect allColumns
public Class objectClass
public Object objectData
public boolean readOnly
public boolean dontSplitHeaders
public Locale displayLocale
protected int headerRowHeight
protected Gate getLock
public boolean dontCacheObjects
public int cacheSize
protected int rowHeight
protected int charWidth
protected int rowLines
public FieldTableModel()
public FieldTableModel(Object anObject, Vector objects)
anObject
- An instance of the object to be displayed.objects
- A list of objects to display.public FieldTableModel setFields(Object objectOrReflect, String headersAndFields, int[] initial)
[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
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.public static MultiListSelect.SingleListSelect toListSelect(Vector allFields, int[] initial)
public FieldTableModel modifyFields(Object objectOrReflect, String headersAndFields)
[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
objectOrReflect
- The object being edited or the class of the object.headersAndFields
- The list of headers and fields with optional formatting info.public FieldTableModel setFields(Object objectOrReflect, int[] initial)
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 casepublic FieldTableModel setFields(Object objectOrReflect)
objectOrReflect
- The object being edited or the class of the object.public void setFields(Vector allFields, int[] initialChoices)
allFields
- The fields stored in a Vector.initialChoices
- the indexes of the field that will be displayed initially. This can be null.public void setFields(Object dataOrClass, String headersAndFields, String initialFields, String excludeFields)
public void setFields(Object dataOrClass, Vector fieldData, String initialFields, String excludeFields)
public void setFields(Object objectOrReflect, String[] fieldProperties, int[] initialChoices)
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.public void setFields(MultiListSelect.SingleListSelect fields)
public FieldTableModel setObjects(Vector objs)
public Object getNew()
public Form getTableForm(Form f, Panel tableDestination, Panel putExtraControls)
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.public Form getTableForm(Form f)
f
- A destination form to add to, which can be null.public Editor getColumnSelector(MultiListSelect.SingleListSelect columns)
protected int getMinColWidth(int col)
getMinColWidth
in class TableModel
protected int getMaxColWidth(int col)
TableModel
getMaxColWidth
in class TableModel
public Vector getAllFields()
public Editor getTableExporter()
public Task getExportTask(FieldTableExportSpecs specs)
public Control getTableExportButton(boolean textLabel)
public void recalculateHeaderRow()
public void doColumnSelection()
public Control getColumnSelectorButton(boolean textLabel)
protected Object loadObjectAtRow(int row) throws Exception
Exception
protected void cacheObject(int row, Object obj)
protected Object getCachedObject(int row)
public void invalidateCachedObject(int row)
public void rowChanged(int row)
public void invalidateCachedObject()
public void invalidateCache()
protected Object getObjectAtRow(int row)
public FieldData getFieldData(int col)
public Vector getAllFieldData()
public TableCellAttributes getCellAttributes(int row, int col, boolean sel, TableCellAttributes tca)
TableModel
getCellAttributes
in class TableModel
public Object getFieldValue(FieldData fd, int row)
fd
- the FieldData.row
- the row of the data.public boolean getCellText(int row, int col, StringList dest)
TableModel
getCellText
in class TableModel
row
- the table row.col
- the table column.dest
- a non-null StringList - use one of the add() methods
to add your text.public int calculateRowHeight(int row)
TableModel
calculateRowHeight
in class TableModel
public int calculateColWidth(int col)
TableModel
calculateColWidth
in class TableModel
public void made()
made
in class TableModel
protected void dataChanged(FieldTransfer ft, Point cell)
public void onEvent(Event ev)
onEvent
in class TableModel
protected TableModel.CellControl madeCellControlFor(FieldData fd, TableModel.CellControl cc)
fd
- the FieldData the control was made for.cc
- the created CellControl.protected TableModel.CellControl getCellControlFor(Point p)
TableModel
getCellControlFor
in class TableModel
p
- the cell the CellControl is for.protected int calculateNumRows()
public void entriesChanged()
protected int calculateTextCharsInColumn(int col)
TableModel
calculateTextCharsInColumn
in class TableModel
public void entriesChanged(int selectIndex)
selectIndex
- the row to select, or -1 to clear the selection.public int getSelectedEntry()
public void selectEntry(int index)
public int countEntries()
public boolean doHotKey(KeyEvent ev)
doHotKey
in class TableModel
public static void main(String[] args) throws Exception
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
Exception