org.csstudio.swt.widgets.natives
Class SpreadSheetTable

java.lang.Object
  extended by org.eclipse.swt.widgets.Widget
      extended by org.eclipse.swt.widgets.Control
          extended by org.eclipse.swt.widgets.Scrollable
              extended by org.eclipse.swt.widgets.Composite
                  extended by org.csstudio.swt.widgets.natives.SpreadSheetTable
All Implemented Interfaces:
org.eclipse.swt.graphics.Drawable

public class SpreadSheetTable
extends org.eclipse.swt.widgets.Composite

Author:
Xihui Chen

Nested Class Summary
static interface SpreadSheetTable.ITableCellEditingListener
          Listener on table cell editing events.
static interface SpreadSheetTable.ITableModifiedListener
          Listener on table contents modified events.
static interface SpreadSheetTable.ITableSelectionChangedListener
          Listener on table selection changed events.
 
Field Summary
 
Fields inherited from class org.eclipse.swt.widgets.Control
handle
 
Constructor Summary
SpreadSheetTable(org.eclipse.swt.widgets.Composite parent)
          Create a spreadsheet table.
 
Method Summary
 void addCellEditingListener(SpreadSheetTable.ITableCellEditingListener listener)
          Add a table cell editing listener.
 void addModifiedListener(SpreadSheetTable.ITableModifiedListener listener)
          Add a table modified listener.
 void addSelectionChangedListener(SpreadSheetTable.ITableSelectionChangedListener listener)
          Add a selection changed listener.
 void autoSizeColumns()
          Auto size all columns.
 void deleteColumn(int index)
          Delete a column.
 void deleteRow(int index)
          Delete a row.
 java.lang.String getCellText(int row, int col)
          Get text of a cell.
 int getColumnCount()
          Get number of columns.
 java.lang.String[][] getContent()
          Get content of the table in a 2D string array.
 java.util.List<java.util.List<java.lang.String>> getInput()
          Get input of the table by which the table is backed.
 int[] getRowColumnIndex(org.eclipse.swt.graphics.Point point)
          Get row and column index under given point.
 int getRowCount()
           
 java.lang.String[][] getSelection()
          Get selected part.
 org.eclipse.jface.viewers.TableViewer getTableViewer()
           
 void insertColumn(int index)
          Insert a column.
 void insertRow(int index)
          Insert a row.
 boolean isEditable()
           
 boolean isEmpty()
           
 void pack()
           
 void refresh()
          Refresh the table to reflect its content.
 void setCellBackground(int row, int col, org.eclipse.swt.graphics.RGB rgbColor)
          Set background color of the cell.
 void setCellForeground(int row, int col, org.eclipse.swt.graphics.RGB rgbColor)
          Set forground color of the cell.
 void setCellText(int row, int col, java.lang.String text)
          Set the text of a cell.
 void setColumnHeader(int columnIndex, java.lang.String header)
          Set the header of a column.
 void setColumnHeaders(java.lang.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(java.lang.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 setFont(org.eclipse.swt.graphics.Font font)
           
 void setInput(java.util.List<java.util.List<java.lang.String>> input)
          Set input of the table.
 void setMenu(org.eclipse.swt.widgets.Menu menu)
           
 void setRowBackground(int row, org.eclipse.swt.graphics.RGB rgbColor)
          Set background color of the row.
 void setRowForeground(int row, org.eclipse.swt.graphics.RGB rgbColor)
          Set foreground color of the row.
 
Methods inherited from class org.eclipse.swt.widgets.Composite
changed, computeSize, drawBackground, getBackgroundMode, getChildren, getLayout, getLayoutDeferred, getTabList, isLayoutDeferred, layout, layout, layout, layout, layout, setBackgroundMode, setFocus, setLayout, setLayoutDeferred, setTabList
 
Methods inherited from class org.eclipse.swt.widgets.Scrollable
computeTrim, getClientArea, getHorizontalBar, getVerticalBar
 
Methods inherited from class org.eclipse.swt.widgets.Control
addControlListener, addDragDetectListener, addFocusListener, addGestureListener, addHelpListener, addKeyListener, addMenuDetectListener, addMouseListener, addMouseMoveListener, addMouseTrackListener, addMouseWheelListener, addPaintListener, addTouchListener, addTraverseListener, computeSize, dragDetect, dragDetect, forceFocus, getAccessible, getBackground, getBackgroundImage, getBorderWidth, getBounds, getCursor, getDragDetect, getEnabled, getFont, getForeground, getLayoutData, getLocation, getMenu, getMonitor, getOrientation, getParent, getRegion, getShell, getSize, getToolTipText, getTouchEnabled, getVisible, internal_dispose_GC, internal_new_GC, isEnabled, isFocusControl, isReparentable, isVisible, moveAbove, moveBelow, pack, print, redraw, redraw, removeControlListener, removeDragDetectListener, removeFocusListener, removeGestureListener, removeHelpListener, removeKeyListener, removeMenuDetectListener, removeMouseListener, removeMouseMoveListener, removeMouseTrackListener, removeMouseWheelListener, removePaintListener, removeTouchListener, removeTraverseListener, setBackground, setBackgroundImage, setBounds, setBounds, setCapture, setCursor, setDragDetect, setEnabled, setForeground, setLayoutData, setLocation, setLocation, setOrientation, setParent, setRedraw, setRegion, setSize, setSize, setToolTipText, setTouchEnabled, setVisible, toControl, toControl, toDisplay, toDisplay, traverse, traverse, traverse, update
 
Methods inherited from class org.eclipse.swt.widgets.Widget
addDisposeListener, addListener, dispose, getData, getData, getDisplay, getListeners, getStyle, isDisposed, isListening, notifyListeners, removeDisposeListener, removeListener, reskin, setData, setData, toString
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SpreadSheetTable

public SpreadSheetTable(org.eclipse.swt.widgets.Composite parent)
Create a spreadsheet table.

Parameters:
parent - parent composite.
style - the style of widget to construct
Method Detail

addCellEditingListener

public void addCellEditingListener(SpreadSheetTable.ITableCellEditingListener listener)
Add a table cell editing listener. Called whenever the value in a cell has been edited.

Parameters:
listener - the listener

addModifiedListener

public void addModifiedListener(SpreadSheetTable.ITableModifiedListener listener)
Add a table modified listener. Called whenever content of the table has been modified from the table.

Parameters:
listener - the listener

addSelectionChangedListener

public void addSelectionChangedListener(SpreadSheetTable.ITableSelectionChangedListener listener)
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.

getCellText

public java.lang.String getCellText(int row,
                                    int col)
Get text of a cell.

Parameters:
row - row index of the cell.
col - column index of the cell.
Returns:
the cell text.

getColumnCount

public int getColumnCount()
Get number of columns.

See Also:
Table#getColumnCount()}

getContent

public java.lang.String[][] getContent()
Get content of the table in a 2D string array.

Returns:
content of the table.

getInput

public java.util.List<java.util.List<java.lang.String>> getInput()
Get input of the table by which the table is backed. To keep the table's content synchronized with the table, client should call refresh() if the returned list has been modified outside.

Returns:
the input of the table.

getRowColumnIndex

public int[] getRowColumnIndex(org.eclipse.swt.graphics.Point point)
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

public java.lang.String[][] getSelection()
Get selected part.

Returns:
the 2D string array under selection.

getTableViewer

public org.eclipse.jface.viewers.TableViewer 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.

isEditable

public boolean isEditable()
Returns:
true if table is editable.

isEmpty

public boolean isEmpty()
Returns:
true if table content is empty.

pack

public void pack()
Overrides:
pack in class org.eclipse.swt.widgets.Control

refresh

public void refresh()
Refresh the table to reflect its content.


setCellBackground

public void setCellBackground(int row,
                              int col,
                              org.eclipse.swt.graphics.RGB rgbColor)
Set background color of the cell.

Parameters:
row - row index of the cell.
col - column index of the cell.
rgbColor - color in RGB.

setCellForeground

public void setCellForeground(int row,
                              int col,
                              org.eclipse.swt.graphics.RGB rgbColor)
Set forground color of the cell.

Parameters:
row - row index of the cell.
col - column index of the cell.
rgbColor - color in RGB.

setCellText

public void setCellText(int row,
                        int col,
                        java.lang.String text)
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.

setColumnHeader

public void setColumnHeader(int columnIndex,
                            java.lang.String header)
Set the header of a column.

Parameters:
columnIndex - index of the column.
header - header text.

setColumnHeaders

public void setColumnHeaders(java.lang.String[] headers)
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

public void setContent(java.lang.String[][] content)
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

public void setFont(org.eclipse.swt.graphics.Font font)
Overrides:
setFont in class org.eclipse.swt.widgets.Control

setInput

public void setInput(java.util.List<java.util.List<java.lang.String>> input)
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

public void setMenu(org.eclipse.swt.widgets.Menu menu)
Overrides:
setMenu in class org.eclipse.swt.widgets.Control

setRowBackground

public void setRowBackground(int row,
                             org.eclipse.swt.graphics.RGB rgbColor)
Set background color of the row.

Parameters:
row - row index of the cell.
rgbColor - color in RGB.

setRowForeground

public void setRowForeground(int row,
                             org.eclipse.swt.graphics.RGB rgbColor)
Set foreground color of the row.

Parameters:
row - row index of the cell.
rgbColor - color in RGB.