Package org.csstudio.swt.widgets.natives
Class SpreadSheetTable
java.lang.Object
org.eclipse.swt.widgets.Widget
org.eclipse.swt.widgets.Control
org.eclipse.swt.widgets.Scrollable
org.eclipse.swt.widgets.Composite
org.csstudio.swt.widgets.natives.SpreadSheetTable
- All Implemented Interfaces:
Drawable
A table allow displaying and editing 2D text array as in spreadsheet. The internal data operated by this table is a
nested string list.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
static interface
Listener on table cell editing events.static interface
Listener on table contents modified events.static interface
Listener on table selection changed events. -
Field Summary
Fields inherited from class org.eclipse.swt.widgets.Composite
embeddedHandle
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Add a table cell editing listener.void
Add a table modified listener.void
Add a selection changed listener.int
Appends a row to the bottom of the table.void
Auto size all columns.void
deleteColumn
(int index) Delete a column.void
deleteRow
(int index) Delete a row.protected void
getCellText
(int row, int col) Get text of a cell.int
Get number of columns.String[]
Get column headers.String[][]
Get content of the table in a 2D string array.getInput()
Get input of the table by which the table is backed.int[]
getRowColumnIndex
(Point point) Get row and column index under given point.int
String[][]
Get selected part.void
insertColumn
(int index) Insert a column.void
insertRow
(int index) Insert a row.boolean
isColumnEditable
(int columnIndex) boolean
boolean
isEmpty()
void
pack()
void
refresh()
Refresh the table to reflect its content.void
revealRow
(int index) void
setCellBackground
(int row, int col, RGB rgbColor) Set background color of the cell.void
setCellForeground
(int row, int col, RGB rgbColor) Set forground color of the cell.void
setCellText
(int row, int col, String text) Set the text of a cell.void
setColumnCellEditor
(int columnIndex, CellEditor cellEditor) Set a customized cell editor for a column.void
setColumnCellEditorData
(int columnIndex, Object data) Set the needed data for the cell editor.void
setColumnCellEditorStyle
(int columnIndex, int style) Set the cell editor style.void
setColumnCellEditorType
(int columnIndex, String cellEditorType) void
setColumnCellEditorType
(int columnIndex, SpreadSheetTable.CellEditorType cellEditorType) Set the cell editor type of a columnvoid
setColumnEditable
(int columnIndex, boolean editable) Set if a column is editable.void
setColumnHeader
(int columnIndex, String header) Set the header of a column.void
setColumnHeaders
(String[] headers) Set column headers.void
setColumnHeaderVisible
(boolean show) Show/hide table column headers.void
setColumnsCount
(int count) Set number of columns.void
setColumnWidth
(int col, int width) void
setColumnWidths
(int[] widthes) Set width of each column.void
setContent
(String[][] content) Set content of the table.Old content in table will be replaced by the new content.void
setEditable
(boolean editable) Set if the table is editable.void
void
Set input of the table.void
void
setRowBackground
(int row, RGB rgbColor) Set background color of the row.void
setRowForeground
(int row, RGB rgbColor) Set foreground color of the row.Methods inherited from class org.eclipse.swt.widgets.Composite
changed, checkSubclass, drawBackground, getBackgroundMode, getChildren, getLayout, getLayoutDeferred, getTabList, isLayoutDeferred, layout, layout, layout, layout, layout, setBackgroundMode, setFocus, setLayout, setLayoutDeferred, setTabList, toString
Methods inherited from class org.eclipse.swt.widgets.Scrollable
computeTrim, getClientArea, getHorizontalBar, getScrollbarsMode, getVerticalBar, setScrollbarsMode
Methods inherited from class org.eclipse.swt.widgets.Control
addControlListener, addDragDetectListener, addFocusListener, addGestureListener, addHelpListener, addKeyListener, addMenuDetectListener, addMouseListener, addMouseMoveListener, 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, isAutoScalable, isEnabled, isFocusControl, isReparentable, isVisible, moveAbove, moveBelow, pack, print, redraw, redraw, removeControlListener, removeDragDetectListener, removeFocusListener, removeGestureListener, removeHelpListener, removeKeyListener, removeMenuDetectListener, removeMouseListener, removeMouseMoveListener, removeMouseTrackListener, removeMouseWheelListener, removePaintListener, removeTouchListener, removeTraverseListener, requestLayout, setBackground, 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
Methods inherited from class org.eclipse.swt.widgets.Widget
addDisposeListener, addListener, addTypedListener, checkWidget, dispose, getData, getData, getDisplay, getListeners, getStyle, getTypedListeners, isAutoDirection, isDisposed, isListening, notifyListeners, removeDisposeListener, removeListener, removeListener, removeTypedListener, reskin, setData, setData
-
Constructor Details
-
SpreadSheetTable
Create a spreadsheet table.- Parameters:
parent
- parent composite.
-
-
Method Details
-
addCellEditingListener
Add a table cell editing listener. Called whenever the value in a cell has been edited.- Parameters:
listener
- the listener
-
addModifiedListener
Add a table modified listener. Called whenever content of the table has been modified from the table.- Parameters:
listener
- the listener
-
addSelectionChangedListener
Add a selection changed listener. Call whenever selection of the table changes.- Parameters:
listener
- the listener
-
autoSizeColumns
public void autoSizeColumns()Auto size all columns. -
deleteColumn
public void deleteColumn(int index) Delete a column.- Parameters:
index
- index of the column.
-
deleteRow
public void deleteRow(int index) Delete a row.- Parameters:
index
- index of the row.
-
fireTableModified
protected void fireTableModified() -
getCellText
Get text of a cell. -
getColumnCount
public int getColumnCount()Get number of columns. -
getColumnHeaders
Get column headers. -
getContent
Get content of the table in a 2D string array. -
getInput
Get input of the table by which the table is backed. To keep the table's content synchronized with the table, client should callrefresh()
if the returned list has been modified outside.- Returns:
- the input of the table.
-
getRowColumnIndex
Get row and column index under given point.- Parameters:
point
- the widget-relative coordinates- Returns:
- int[0] is row index, int[1] is column index. null if no cell was found under given point.
-
getRowCount
public int getRowCount() -
getSelection
Get selected part.- Returns:
- the 2D string array under selection.
-
getTableViewer
- Returns:
- the
TableViewer
wrapped by this widget.
-
insertColumn
public void insertColumn(int index) Insert a column. Default values for the new column are empty strings.- Parameters:
index
- index of the column.
-
insertRow
public void insertRow(int index) Insert a row. Shifts the element currently at that position (if any) and any subsequent elements to the below (adds one to their indices).Default values for the new row are empty strings.- Parameters:
index
- index of the row.
-
appendRow
public int appendRow()Appends a row to the bottom of the table.- Returns:
- row index
-
isEditable
public boolean isEditable()- Returns:
- true if table is editable.
-
isEmpty
public boolean isEmpty()- Returns:
- true if table content is empty.
-
revealRow
public void revealRow(int index) -
isColumnEditable
public boolean isColumnEditable(int columnIndex) - Parameters:
columnIndex
- index of the column.- Returns:
- true if the column is editable.
-
pack
public void pack() -
refresh
public void refresh()Refresh the table to reflect its content. -
setCellBackground
Set background color of the cell.- Parameters:
row
- row index of the cell.col
- column index of the cell.rgbColor
- color in RGB.
-
setCellForeground
Set forground color of the cell.- Parameters:
row
- row index of the cell.col
- column index of the cell.rgbColor
- color in RGB.
-
setCellText
Set the text of a cell. If the row index is larger than current content, it will extend the current content to have that row.- Parameters:
row
- row index of the cell. Start from 0.col
- column index of the cell. Start from 0.text
- text to be set.
-
setColumnCellEditorType
public void setColumnCellEditorType(int columnIndex, SpreadSheetTable.CellEditorType cellEditorType) Set the cell editor type of a column- Parameters:
columnIndex
- index of the column.cellEditorType
- the cell editor type.
-
setColumnCellEditorType
-
setColumnCellEditorData
Set the needed data for the cell editor. For example, a String[] for dropdown cell editor.- Parameters:
columnIndex
- index of the column.data
- data for the cell editor.
-
setColumnCellEditorStyle
public void setColumnCellEditorStyle(int columnIndex, int style) Set the cell editor style. For example,SWT.READ_ONLY
for dropdown cell editor.- Parameters:
columnIndex
- index of the column.style
- the style
-
setColumnCellEditor
Set a customized cell editor for a column. The cell editor must generate or accept String type value.- Parameters:
columnIndex
- index of the column.cellEditor
- the cell editor.
-
setColumnEditable
public void setColumnEditable(int columnIndex, boolean editable) Set if a column is editable.- Parameters:
columnIndex
- index of the column.editable
- editable if true.
-
setColumnHeader
Set the header of a column.- Parameters:
columnIndex
- index of the column.header
- header text.
-
setColumnHeaders
Set column headers. If the size of the headers array is larger than the existing columns count. It will increase the columns count automatically.- Parameters:
headers
- headers text.
-
setColumnHeaderVisible
public void setColumnHeaderVisible(boolean show) Show/hide table column headers.- Parameters:
show
- the new visibility state
-
setColumnsCount
public void setColumnsCount(int count) Set number of columns. If the new count is less than old count, columns from right will be deleted. If the new count is more than old count, new columns will be appended to the right.- Parameters:
count
- number of columns.
-
setColumnWidth
public void setColumnWidth(int col, int width) -
setColumnWidths
public void setColumnWidths(int[] widthes) Set width of each column. If length of the sizes array is larger than the existing columns count. It will increase the columns count automatically.- Parameters:
widthes
- column size in pixels.
-
setContent
Set content of the table.Old content in table will be replaced by the new content.- Parameters:
content
- the new content.
-
setEditable
public void setEditable(boolean editable) Set if the table is editable.- Parameters:
editable
- true if table is editable.
-
setFont
-
setInput
Set input of the table. The input is the back of the table, so content of the input is always synchronized with content of the table.- Parameters:
input
- input of the table.
-
setMenu
-
setRowBackground
Set background color of the row.- Parameters:
row
- row index of the cell.rgbColor
- color in RGB.
-
setRowForeground
Set foreground color of the row.- Parameters:
row
- row index of the cell.rgbColor
- color in RGB.
-