Class SpreadSheetTable

All Implemented Interfaces:
Drawable

public class SpreadSheetTable extends Composite
A table allow displaying and editing 2D text array as in spreadsheet. The internal data operated by this table is a nested string list.
  • Constructor Details

    • SpreadSheetTable

      public SpreadSheetTable(Composite parent)
      Create a spreadsheet table.
      Parameters:
      parent - parent composite.
  • Method Details

    • 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.
    • fireTableModified

      protected void fireTableModified()
    • getCellText

      public String getCellText(int row, int col)
      Get text of a cell.
    • getColumnCount

      public int getColumnCount()
      Get number of columns.
    • getColumnHeaders

      public String[] getColumnHeaders()
      Get column headers.
    • getContent

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

      public List<List<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(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 String[][] getSelection()
      Get selected part.
      Returns:
      the 2D string array under selection.
    • getTableViewer

      public 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.
    • 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()
      Overrides:
      pack in class Control
    • refresh

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

      public void setCellBackground(int row, int col, 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, 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, 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.
    • 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

      public void setColumnCellEditorType(int columnIndex, String cellEditorType)
    • setColumnCellEditorData

      public void setColumnCellEditorData(int columnIndex, Object data)
      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

      public void setColumnCellEditor(int columnIndex, CellEditor cellEditor)
      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

      public void setColumnHeader(int columnIndex, String header)
      Set the header of a column.
      Parameters:
      columnIndex - index of the column.
      header - header text.
    • setColumnHeaders

      public void setColumnHeaders(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(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(Font font)
      Overrides:
      setFont in class Control
    • setInput

      public void setInput(List<List<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(Menu menu)
      Overrides:
      setMenu in class Control
    • setRowBackground

      public void setRowBackground(int row, 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, RGB rgbColor)
      Set foreground color of the row.
      Parameters:
      row - row index of the cell.
      rgbColor - color in RGB.