public class CompositeTable
extends org.eclipse.swt.widgets.Canvas
CompositeTable is designed specifically to work nicely in the Eclipse Visual Editor, but it is equally easy to use in hand-coded layouts.
Synopsis:
In order to edit anything, one must:
This control is designed to work inside of the Eclipse Visual Editor. To use it, drop one on the design surface. (Even though it extends Canvas, it does not make sense to put a layout manager on it.)
Next create one or two new custom controls by using the Visual Editor to extend Composite. If you create one custom control, it will be used as the prototype for all rows that will be displayed in the table. If you create two, the first one will be used as a prototype for the header and the second one will be used as a prototype for the rows.
If these custom controls are not given layout managers (null layout), then CompositeTable will automatically detect this situation and will supply its own layout manager that will automatically lay out the children of these controls in columns to form a table. However, if you supply layout managers for your header prototype and row prototype objects, CompositeTable will respect your choice. If you use CompositeTable's built-in layout manager, then the weights property will be used to determine what percentage of the total width will be allocated to each column. If this property is not set or if the sum of their elements does not equal 100, the columns are created as equal sizes.
Once you have created your (optional) Header and Row custom controls, simply drop them onto your CompositeTable control in VE. The first of these two custom controls to be instantiated in your code will be interpreted by the CompositeTable as the header control and the second will be interpreted as the row control.
Now that you have defined the (optional) header and row, you can switch your CompositeTable into run mode and use it. This is done by switching the RunTime property to true.
Once in run mode, all of the CompositeTable's properties will be active. In order to use it, set the NumRowsInCollection property to the number of rows in the collection you want to display. And add a RefreshContentProvider, which will be called whenever CompositeTable needs to refresh a particular row.
Please refer to the remainder of the JavaDoc for information on the remaining properties and events.
Although this control extends Composite, it is not intended to be subclassed except within its own implementation and it makes no sense to set a layout manager on it (although as discussed above, the child controls may have layout managers).
Modifier and Type | Field and Description |
---|---|
(package private) java.util.LinkedList |
contentProviders |
(package private) boolean |
deleteEnabled |
(package private) java.util.LinkedList |
deleteHandlers |
(package private) java.util.LinkedList |
insertHandlers |
(package private) java.lang.String |
insertHint |
(package private) boolean |
linesVisible |
(package private) java.util.LinkedList |
rowConstructionListeners |
(package private) java.util.LinkedList |
rowFocusListeners |
(package private) java.util.LinkedList |
scrollListeners |
Constructor and Description |
---|
CompositeTable(org.eclipse.swt.widgets.Composite parent,
int style)
Constructor CompositeTable.
|
Modifier and Type | Method and Description |
---|---|
void |
addDeleteHandler(IDeleteHandler deleteHandler)
Method addDeleteHandler.
|
void |
addInsertHandler(IInsertHandler insertHandler)
Method addInsertHandler.
|
void |
addKeyListener(org.eclipse.swt.events.KeyListener listener) |
void |
addMouseListener(org.eclipse.swt.events.MouseListener listener) |
void |
addMouseMoveListener(org.eclipse.swt.events.MouseMoveListener listener) |
void |
addRowConstructionListener(RowConstructionListener rowConstructionListener)
Method addRowConstructionListener.
|
void |
addRowContentProvider(IRowContentProvider contentProvider)
Method addRowContentProvider.
|
void |
addRowFocusListener(IRowFocusListener rowListener)
Method addRowListener.
|
void |
addScrollListener(ScrollListener scrollListener)
Method addScrollListener.
|
void |
clearSelection()
Method clearSelection.
|
boolean |
doDeleteRow() |
void |
doFocusInitialRow()
Method doFocusInitialRow.
|
void |
doFocusLastRow()
Method doFocusLastRow.
|
boolean |
doInsertRow() |
boolean |
doMakeFocusedRowVisible()
Makes sure that the focused row is visible
|
void |
doPageDown()
Method doPageDown.
|
void |
doPageUp()
Method doPageUp.
|
void |
doRowDown()
Method doRowDown.
|
void |
doRowUp()
Method doRowUp.
|
(package private) void |
fireKeyPressed(org.eclipse.swt.events.KeyEvent e) |
(package private) void |
fireKeyReleased(org.eclipse.swt.events.KeyEvent e) |
(package private) void |
fireMouseDouble(org.eclipse.swt.events.MouseEvent e) |
(package private) void |
fireMouseDown(org.eclipse.swt.events.MouseEvent e) |
(package private) void |
fireMouseMove(org.eclipse.swt.events.MouseEvent e) |
(package private) void |
fireMouseUp(org.eclipse.swt.events.MouseEvent e) |
int |
getControlRow(org.eclipse.swt.widgets.Control rowControl)
Method getControlRow.
|
int |
getCurrentColumn()
Method getCurrentColumn.
|
int |
getCurrentRow()
Method getCurrentRow.
|
org.eclipse.swt.widgets.Control |
getCurrentRowControl()
Method getCurrentRowControl.
|
org.eclipse.swt.widgets.Control |
getHeader()
Returns the actual header control (not the prototype).
|
java.lang.reflect.Constructor |
getHeaderConstructor()
(non-API) Method getHeaderConstructor.
|
org.eclipse.swt.widgets.Control |
getHeaderControl()
(non-API) Method getHeaderControl.
|
java.lang.String |
getInsertHint()
Returns the hint string that will be displayed when there are no rows in
the table.
|
boolean |
getLinesVisible()
Method getLinesVisible.
|
int |
getMaxRowsVisible()
Method getMaxRowsVisible.
|
int |
getNumRowsInCollection()
Method getNumRowsInCollection.
|
int |
getNumRowsVisible()
Method getNumRowsVisible.
|
java.lang.reflect.Constructor |
getRowConstructor()
(non-API) Method getRowConstructor.
|
org.eclipse.swt.widgets.Control |
getRowControl()
(non-API) Method getRowControl.
|
org.eclipse.swt.widgets.Control[] |
getRowControls()
Method getRowControls.
|
org.eclipse.swt.graphics.Point |
getSelection()
Method getSelection.
|
int |
getTopRow()
Method getTopRow.
|
boolean |
isDeleteEnabled()
Method isDeleteEnabled.
|
boolean |
isRunTime()
Method isRunTime.
|
boolean |
isTraverseOnTabsEnabled()
Method isTraverseOnTabsEnabled.
|
void |
refreshAllRows()
Method refreshAllRows.
|
void |
refreshRow(int row)
Method refreshRow.
|
void |
removeDeleteHandler(IDeleteHandler deleteHandler)
Method removeDeleteHandler.
|
void |
removeInsertHandler(IInsertHandler insertHandler)
Method removeInsertHandler.
|
void |
removeKeyListener(org.eclipse.swt.events.KeyListener listener) |
void |
removeMouseListener(org.eclipse.swt.events.MouseListener listener) |
void |
removeMouseMoveListener(org.eclipse.swt.events.MouseMoveListener listener) |
void |
removeRowConstructionListener(RowConstructionListener rowConstructionListener)
Method removeRowConstructionListener.
|
void |
removeRowContentProvider(IRowContentProvider contentProvider)
Method removeRowContentProvider.
|
void |
removeRowFocusListener(IRowFocusListener listener)
Method removeRowListener.
|
void |
removeScrollListener(ScrollListener scrollListener)
Method removeScrollListener.
|
protected void |
resize()
(non-API) Method resize.
|
protected void |
resizeAndRecordPrototypeRows()
(non-API) Method resizeAndRecordPrototypeRows.
|
void |
setBackground(org.eclipse.swt.graphics.Color color) |
void |
setCurrentColumn(int column)
Method setCurrentColumn.
|
void |
setCurrentRow(int row)
Method setCurrentRow.
|
void |
setDeleteEnabled(boolean deleteEnabled)
Method setDeleteEnabled.
|
void |
setInsertHint(java.lang.String newHint)
Sets the hint string that will be displayed when there are no rows in the
table.
|
void |
setLinesVisible(boolean linesVisible)
Method setLinesVisible.
|
void |
setMaxRowsVisible(int maxRowsVisible)
Method setMaxRowsVisible.
|
void |
setMenu(org.eclipse.swt.widgets.Menu menu) |
void |
setNumRowsInCollection(int numRowsInCollection)
Method setNumRowsInCollection.
|
void |
setRunTime(boolean runTime)
Method setRunTime.
|
void |
setSelection(int column,
int row)
Method setSelection.
|
void |
setSelection(org.eclipse.swt.graphics.Point selection)
Method setSelection.
|
void |
setTopRow(int topRow)
Method setTopRow.
|
void |
setTraverseOnTabsEnabled(boolean enabled)
Method setTraverseOnTabsEnabled.
|
protected void |
updateVisibleRows()
(non-API) Method updateVisibleRows.
|
drawBackground, getCaret, getIME, scroll, setCaret, setFont, setIME
changed, checkSubclass, drawBackground, getBackgroundMode, getChildren, getLayout, getLayoutDeferred, getTabList, isLayoutDeferred, layout, layout, layout, layout, layout, setBackgroundMode, setFocus, setLayout, setLayoutDeferred, setTabList
computeTrim, getClientArea, getHorizontalBar, getScrollbarsMode, getVerticalBar
addControlListener, addDragDetectListener, addFocusListener, addGestureListener, addHelpListener, addMenuDetectListener, addMouseTrackListener, addMouseWheelListener, addPaintListener, addTouchListener, addTraverseListener, computeSize, computeSize, dragDetect, dragDetect, forceFocus, getAccessible, getBackground, getBackgroundImage, getBorderWidth, getBounds, getCursor, getDragDetect, getEnabled, getFont, getForeground, getLayoutData, getLocation, getMenu, getMonitor, getOrientation, getParent, getRegion, getShell, getSize, getTextDirection, getToolTipText, getTouchEnabled, getVisible, internal_dispose_GC, internal_new_GC, isEnabled, isFocusControl, isReparentable, isVisible, moveAbove, moveBelow, pack, pack, print, redraw, redraw, removeControlListener, removeDragDetectListener, removeFocusListener, removeGestureListener, removeHelpListener, removeMenuDetectListener, removeMouseTrackListener, removeMouseWheelListener, removePaintListener, removeTouchListener, removeTraverseListener, requestLayout, setBackgroundImage, setBounds, setBounds, setCapture, setCursor, setDragDetect, setEnabled, setForeground, setLayoutData, setLocation, setLocation, setOrientation, setParent, setRedraw, setRegion, setSize, setSize, setTextDirection, setToolTipText, setTouchEnabled, setVisible, toControl, toControl, toDisplay, toDisplay, traverse, traverse, traverse, update
addDisposeListener, addListener, checkWidget, dispose, getData, getData, getDisplay, getListeners, getStyle, isAutoDirection, isDisposed, isListening, notifyListeners, removeDisposeListener, removeListener, removeListener, reskin, setData, setData, toString
boolean linesVisible
java.lang.String insertHint
java.util.LinkedList contentProviders
java.util.LinkedList rowFocusListeners
java.util.LinkedList insertHandlers
java.util.LinkedList deleteHandlers
java.util.LinkedList rowConstructionListeners
boolean deleteEnabled
java.util.LinkedList scrollListeners
public CompositeTable(org.eclipse.swt.widgets.Composite parent, int style)
parent
- The SWT parent control.style
- Style bits. These are the same as Canvaspublic void setBackground(org.eclipse.swt.graphics.Color color)
setBackground
in class org.eclipse.swt.widgets.Control
protected final void resize()
protected void updateVisibleRows()
protected void resizeAndRecordPrototypeRows()
public boolean isRunTime()
public void setRunTime(boolean runTime)
runTime
- true if run-time mode should be enabled; false otherwise.public boolean getLinesVisible()
public void setLinesVisible(boolean linesVisible)
linesVisible
- true if the CompositeTable will draw grid lines; false
otherwise.public java.lang.String getInsertHint()
public void setInsertHint(java.lang.String newHint)
newHint
- public int getMaxRowsVisible()
public void setMaxRowsVisible(int maxRowsVisible)
maxRowsVisible
- the maximum number of rows that are permitted to be visible at
one time, regardless of the control's size.public int getNumRowsVisible()
public int getNumRowsInCollection()
public void setNumRowsInCollection(int numRowsInCollection)
numRowsInCollection
- the number of rows represented by the underlying data
structure.public int getTopRow()
public void setTopRow(int topRow)
topRow
- the line number of the new top row.public boolean doMakeFocusedRowVisible()
public void doFocusInitialRow()
public void doFocusLastRow()
public void doPageUp()
public void doPageDown()
public void doRowUp()
public void doRowDown()
public boolean doInsertRow()
public boolean doDeleteRow()
public void refreshAllRows()
public void refreshRow(int row)
public int getCurrentColumn()
public void setCurrentColumn(int column)
column
- The new column to focus.public int getCurrentRow()
public void setCurrentRow(int row)
row
- the current row number as an offset from the top of the table
window.public org.eclipse.swt.widgets.Control getCurrentRowControl()
public org.eclipse.swt.widgets.Control[] getRowControls()
public org.eclipse.swt.widgets.Control getHeader()
public void setMenu(org.eclipse.swt.widgets.Menu menu)
setMenu
in class org.eclipse.swt.widgets.Control
public int getControlRow(org.eclipse.swt.widgets.Control rowControl)
rowControl
- The row object to findjava.lang.IllegalArgumentException
- if rowControl is not currently visiblepublic org.eclipse.swt.graphics.Point getSelection()
public void setSelection(org.eclipse.swt.graphics.Point selection)
selection
- the (column, row) to selectpublic void setSelection(int column, int row)
column
- the column to selectrow
- the row to select as an offset from the top of the windowpublic void clearSelection()
public java.lang.reflect.Constructor getHeaderConstructor()
public java.lang.reflect.Constructor getRowConstructor()
public org.eclipse.swt.widgets.Control getHeaderControl()
public org.eclipse.swt.widgets.Control getRowControl()
public void addRowContentProvider(IRowContentProvider contentProvider)
contentProvider
- The content provider to add.public void removeRowContentProvider(IRowContentProvider contentProvider)
contentProvider
- The content provider to remove.public void addRowFocusListener(IRowFocusListener rowListener)
rowListener
- The listener to add.public void removeRowFocusListener(IRowFocusListener listener)
listener
- The listener to remove.public void addInsertHandler(IInsertHandler insertHandler)
insertHandler
- the insertHandler to add.public void removeInsertHandler(IInsertHandler insertHandler)
insertHandler
- the insertHandler to remove.public void addDeleteHandler(IDeleteHandler deleteHandler)
deleteHandler
- the deleteHandler to add.public void removeDeleteHandler(IDeleteHandler deleteHandler)
deleteHandler
- the deleteHandler to remove.public void addRowConstructionListener(RowConstructionListener rowConstructionListener)
rowConstructionListener
- the rowConstructionListener to add.public void removeRowConstructionListener(RowConstructionListener rowConstructionListener)
rowConstructionListener
- the rowConstructionListener to remove.public boolean isDeleteEnabled()
The default value is true.
public void setDeleteEnabled(boolean deleteEnabled)
The default value is true.
deleteEnabled
- true if delete should be enabled. false otherwise.public void addScrollListener(ScrollListener scrollListener)
scrollListener
- the ScrollListener to add.public void removeScrollListener(ScrollListener scrollListener)
scrollListener
- the ScrollListener to remove.public boolean isTraverseOnTabsEnabled()
This property defaults to true.
public void setTraverseOnTabsEnabled(boolean enabled)
This property defaults to true.
enabled
- true if CompositeTable is handling Tab, Shift-tab, and Enter
key behavior; false otherwise.public void addKeyListener(org.eclipse.swt.events.KeyListener listener)
addKeyListener
in class org.eclipse.swt.widgets.Control
public void removeKeyListener(org.eclipse.swt.events.KeyListener listener)
removeKeyListener
in class org.eclipse.swt.widgets.Control
void fireKeyPressed(org.eclipse.swt.events.KeyEvent e)
void fireKeyReleased(org.eclipse.swt.events.KeyEvent e)
public void addMouseListener(org.eclipse.swt.events.MouseListener listener)
addMouseListener
in class org.eclipse.swt.widgets.Control
public void removeMouseListener(org.eclipse.swt.events.MouseListener listener)
removeMouseListener
in class org.eclipse.swt.widgets.Control
void fireMouseDown(org.eclipse.swt.events.MouseEvent e)
void fireMouseUp(org.eclipse.swt.events.MouseEvent e)
void fireMouseDouble(org.eclipse.swt.events.MouseEvent e)
public void addMouseMoveListener(org.eclipse.swt.events.MouseMoveListener listener)
addMouseMoveListener
in class org.eclipse.swt.widgets.Control
public void removeMouseMoveListener(org.eclipse.swt.events.MouseMoveListener listener)
removeMouseMoveListener
in class org.eclipse.swt.widgets.Control
void fireMouseMove(org.eclipse.swt.events.MouseEvent e)