net.sourceforge.java.util.gui.jface.preference
Class TableFieldEditor

java.lang.Object
  extended byorg.eclipse.jface.preference.FieldEditor
      extended bynet.sourceforge.java.util.gui.jface.preference.TableFieldEditor

public class TableFieldEditor
extends FieldEditor

A FieldEditor implementation that supports the selection of tabular data.

Author:
Sebastian Machhausen

Field Summary
private  String[] columnHeaders
           The column headers to display in the Table
private  IStructuredContentProvider contentProvider
           The content provider used to query the table data
private  Object input
           The input or model object that holds the data of the TableViewer
private  ITableLabelProvider labelProvider
           The label provider used to convert domain objects to ui specific textual representations.
private  Object oldValue
           The last selected value of the Table
private  int selectionColumn
           The index of the column to store/retrieve the value for.
private  TableViewerSorter sorter
           The Table sorter
private  TableViewerSorterHandler sorterHandler
           The handler used to sort the underlying IStructuredContentProvider
private  Table table
           The Table used to present the selectable tabular data
private  TableViewer viewer
           The TableViewer used as controller
 
Fields inherited from class org.eclipse.jface.preference.FieldEditor
HORIZONTAL_GAP, IS_VALID, VALUE
 
Constructor Summary
TableFieldEditor(String name, String labelText, Composite parent, IStructuredContentProvider contentProvider, ITableLabelProvider labelProvider, String[] columnHeaders, Object input)
           Creates a new TableFieldEditor instance.
 
Method Summary
protected  void adjustForNumColumns(int numColumns)
           Adjusts the horizontal span of this TableFieldEditor's basic controls.
protected  void doFillIntoGrid(Composite parent, int numColumns)
           Fills this TableFieldEditor's basic controls into the given parent.
protected  void doLoad()
           Initializes this TableFieldEditor with the preference value from the preference store.
protected  void doLoadDefault()
           Initializes this TableFieldEditor with the default preference value from the preference store.
protected  void doStore()
           Stores the preference value from this TableFieldEditor into the preference store.
 int getColumnWidth(int columnIndex)
           Gets the width in pixel of the column at the specified columnIndex.
 int getNumberOfControls()
           Returns the number of controls in this TableFieldEditor.
 String getSelection()
           Gets the currently selected value of this TableFieldEditor.
 int getSelectionColumn()
           Gets the selection column which represents the index of the column whose value is stored/retrieved in this TableFieldEditor.
 int getSortingColumn()
           Gets the index of the column by which sorting is done.
private  void initializeColumns()
           Initializes the table columnHeaders by setting their widths and adjusting their settings.
private  void initializeViewer()
           Initializes this TableFieldEditor's TableViewer.
 boolean isSortAscending()
           Returns true if sorting is done in ascending order; false if done in descending order or sorting is disabled;
 boolean isSortingEnabled()
           Returns true if Table sorting is enabled; false otherwise.
 void setColumnWidth(int columnIndex, int width)
           Sets the width of the column at the specified columnIndex to the given width.
private  void setSelection(String selectionStr)
           Sets the selection of this TableFieldEditor to the row or element matching the specified selectionStr.
 void setSelectionColumn(int columnIndex)
           Sets the selection column to the specified columnIndex.
 void setSortingEnabled(boolean enabled)
           Enables or disables the sorting of the Table depending on the specified enabled status.
 void sort(int columnIndex, boolean ascending)
           Sorts the Table by the specified columnIndex in the specified sort order.
protected  void valueChanged()
           Informs this field editor's listener, if it has one, about a change to the value (VALUE property) provided that the old and new values are different.
 
Methods inherited from class org.eclipse.jface.preference.FieldEditor
applyFont, checkParent, clearErrorMessage, clearMessage, convertHorizontalDLUsToPixels, convertVerticalDLUsToPixels, createControl, dispose, fillIntoGrid, fireStateChanged, fireValueChanged, getFieldEditorFontName, getLabelControl, getLabelControl, getLabelText, getPage, getPreferenceName, getPreferencePage, getPreferenceStore, init, isValid, load, loadDefault, presentsDefaultValue, refreshValidState, setButtonLayoutData, setEnabled, setFocus, setLabelText, setPage, setPreferenceName, setPreferencePage, setPreferenceStore, setPresentsDefaultValue, setPropertyChangeListener, showErrorMessage, showMessage, store
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

table

private Table table

The Table used to present the selectable tabular data


viewer

private TableViewer viewer

The TableViewer used as controller


contentProvider

private IStructuredContentProvider contentProvider

The content provider used to query the table data


labelProvider

private ITableLabelProvider labelProvider

The label provider used to convert domain objects to ui specific textual representations.


input

private Object input

The input or model object that holds the data of the TableViewer


columnHeaders

private String[] columnHeaders

The column headers to display in the Table


sorter

private TableViewerSorter sorter
The Table sorter


sorterHandler

private TableViewerSorterHandler sorterHandler

The handler used to sort the underlying IStructuredContentProvider


selectionColumn

private int selectionColumn

The index of the column to store/retrieve the value for. If set to -1 the complete row represented as domain object is stored/retrieved. This is done by calling toString() on the respective domain object.


oldValue

private Object oldValue

The last selected value of the Table

Constructor Detail

TableFieldEditor

public TableFieldEditor(String name,
                        String labelText,
                        Composite parent,
                        IStructuredContentProvider contentProvider,
                        ITableLabelProvider labelProvider,
                        String[] columnHeaders,
                        Object input)

Creates a new TableFieldEditor instance.

Parameters:
name - the name of the preference this field editor works on
labelText - the label text of the field editor
parent - the parent of the field editor's control
contentProvider - the IStructuredContentProvider used to query the table data
labelProvider - the ITableLabelProvider used to convert domain objects to ui specific textual representations
columnHeaders - an array of String objects representing the column headers
input - the input or model object which holds the data for this TableFieldEditor
Method Detail

getNumberOfControls

public int getNumberOfControls()

Returns the number of controls in this TableFieldEditor. Returns 1 as the Table is the only control.

Returns:
1
See Also:
FieldEditor.getNumberOfControls()

setSelectionColumn

public void setSelectionColumn(int columnIndex)

Sets the selection column to the specified columnIndex. The index represents the column whose value is stored/retrieved in this TableFieldEditor. If set to -1 the complete row represented as domain object is stored/retrieved. This is done by calling Object.toString() on the respective domain object.

Parameters:
columnIndex - the column whose value is stored/retrieved in this TableFieldEditor
See Also:
getSelectionColumn()

getSelectionColumn

public int getSelectionColumn()

Gets the selection column which represents the index of the column whose value is stored/retrieved in this TableFieldEditor. A value of -1 means that the complete row represented as domain object is stored/retrieved. This is done by calling Object.toString() on the respective domain object.

Returns:
the column whose value is stored/retrieved in this TableFieldEditor
See Also:
setSelectionColumn(int)

getSelection

public String getSelection()

Gets the currently selected value of this TableFieldEditor. The value returned by this method depends on the selection column set up as returned by getSelectionColumn(). If the selection column is set to -1 the complete row represented as domain object is returned by calling Object.toString() on it. Otherwise the respective column value is queried and returned using the ITableLabelProvider bound to this TableFieldEditor.

Returns:
the currently selected value or an empty String if no selection
See Also:
setSelectionColumn(int), getSelectionColumn()

setSortingEnabled

public void setSortingEnabled(boolean enabled)

Enables or disables the sorting of the Table depending on the specified enabled status.
The IStructuredContentProvider used in this TableFieldEditor has to implement the ITableContentProvider interface to enable sorting.

Parameters:
enabled - true to enable sorting; false to disable
See Also:
isSortingEnabled()

isSortingEnabled

public boolean isSortingEnabled()

Returns true if Table sorting is enabled; false otherwise.

Returns:
true if sorting is enabled; false otherwise
See Also:
setSortingEnabled(boolean)

sort

public void sort(int columnIndex,
                 boolean ascending)

Sorts the Table by the specified columnIndex in the specified sort order. If sorting is disabled this method does nothing.

Parameters:
columnIndex - the index of the column to sort by
ascending - true to sort in ascending, false to sort in descending order
See Also:
setSortingEnabled(boolean), isSortingEnabled(), getSortingColumn(), isSortAscending()

getSortingColumn

public int getSortingColumn()

Gets the index of the column by which sorting is done. If sorting is disabled -1 is returned.

Returns:
the index of the column upon which sorting is done; -1 if sorting is disabled
See Also:
isSortAscending(), sort(int, boolean)

isSortAscending

public boolean isSortAscending()

Returns true if sorting is done in ascending order; false if done in descending order or sorting is disabled;

Returns:
true if sorting is done in ascending order; false if done in descending order or sorting is disabled;
See Also:
getSortingColumn(), sort(int, boolean)

setColumnWidth

public void setColumnWidth(int columnIndex,
                           int width)

Sets the width of the column at the specified columnIndex to the given width. If no TableColumn exists at the specified columnIndex the method does nothing.

Parameters:
columnIndex - the index of the column to set the width for
width - the width of the column in pixel
See Also:
getColumnWidth(int)

getColumnWidth

public int getColumnWidth(int columnIndex)

Gets the width in pixel of the column at the specified columnIndex. If no TableColumn exists at the specified columnIndex the method returns 0.

Parameters:
columnIndex - the index of the column to get the width for
Returns:
the column width
See Also:
setColumnWidth(int, int)

adjustForNumColumns

protected void adjustForNumColumns(int numColumns)

Adjusts the horizontal span of this TableFieldEditor's basic controls. The number of columnHeaders will always be equal to or greater than the value returned by this editor's getNumberOfControls method.

Parameters:
numColumns - the number of columnHeaders
See Also:
FieldEditor.adjustForNumColumns(int)

doFillIntoGrid

protected void doFillIntoGrid(Composite parent,
                              int numColumns)

Fills this TableFieldEditor's basic controls into the given parent.

Parameters:
parent - the composite used as a parent for the basic controls; the parent's layout must be a GridLayout
numColumns - the number of columnHeaders
See Also:
FieldEditor.doFillIntoGrid(org.eclipse.swt.widgets.Composite, int)

doLoad

protected void doLoad()

Initializes this TableFieldEditor with the preference value from the preference store.

See Also:
FieldEditor.doLoad()

doLoadDefault

protected void doLoadDefault()

Initializes this TableFieldEditor with the default preference value from the preference store.

See Also:
FieldEditor.doLoadDefault()

doStore

protected void doStore()

Stores the preference value from this TableFieldEditor into the preference store.

See Also:
FieldEditor.doStore()

valueChanged

protected void valueChanged()

Informs this field editor's listener, if it has one, about a change to the value (VALUE property) provided that the old and new values are different. This hook is not called when the value is initialized (or reset to the default value) from the preference store.


initializeViewer

private void initializeViewer()

Initializes this TableFieldEditor's TableViewer.


initializeColumns

private void initializeColumns()

Initializes the table columnHeaders by setting their widths and adjusting their settings.


setSelection

private void setSelection(String selectionStr)

Sets the selection of this TableFieldEditor to the row or element matching the specified selectionStr.

Parameters:
selectionStr - the String that identifies the row or element to select