org.eclipse.datatools.sqltools.common.ui.tableviewer
Class AccessibleTableViewer

java.lang.Object
  extended by org.eclipse.jface.viewers.Viewer
      extended by org.eclipse.jface.viewers.ContentViewer
          extended by org.eclipse.jface.viewers.StructuredViewer
              extended by org.eclipse.datatools.sqltools.common.ui.tableviewer.AccessibleTableViewer
All Implemented Interfaces:
org.eclipse.jface.viewers.IInputProvider, org.eclipse.jface.viewers.IInputSelectionProvider, org.eclipse.jface.viewers.IPostSelectionProvider, org.eclipse.jface.viewers.ISelectionProvider
Direct Known Subclasses:
ContextAccessibleTableViewer

public class AccessibleTableViewer
extends org.eclipse.jface.viewers.StructuredViewer

A concrete viewer to support tab function.

It is designed to be instantiated with a pre-existing SWT table control and configured with a domain-specific content provider ( TableDataContentProvider ), table label provider ( TableDataLabelProvider) , element filter (optional), and element sorter (optional).

Version:
1.0, 11/04/2005
Author:
lihuang

Field Summary
static java.lang.String GROUP_COPY
          Context menu group for cut/copy/paste related actions.
 
Constructor Summary
AccessibleTableViewer(org.eclipse.swt.widgets.Composite parent)
          Creates a accessible table viewer on a newly-created table control under the given parent.
AccessibleTableViewer(org.eclipse.swt.widgets.Composite parent, int style)
          Creates a table viewer on a newly-created table control under the given parent.
AccessibleTableViewer(org.eclipse.swt.widgets.Table table)
          Creates a table viewer on the given table control.
 
Method Summary
 void add(java.lang.Object element)
          Adds the given element to this table viewer.
 void add(java.lang.Object[] elements)
          Adds the given elements to this table viewer.
 void cancelEditing()
          Cancels a currently active cell editor.
 void clear(int index)
          Clear the table item at the specified index
 void doDelete()
          Delete a row which is positioned by cursor.
 void doDeleteAll(boolean confirm)
          Delete all rows in this table viewer.
 void doInsertRow()
          Insert a empty row into table.
 void doRefresh(boolean confirm)
          Refreshes the contents of the table if dirty.
 void doRevert()
          This method will revert the added, deleted and changes rows in the table on the currently displayed table data to the original table data.
 boolean doSave()
          This method is used to save table data.
 void doSetNull()
           
 void doUpdateValue()
          To make the selected cell editable.
 void editElement(java.lang.Object element, int column)
          Starts editing the given element.
 org.eclipse.jface.viewers.CellEditor[] getCellEditors()
          Returns the cell editors of this table viewer.
 org.eclipse.jface.viewers.ICellModifier getCellModifier()
          Returns the cell modifier of this table viewer.
 java.lang.Object[] getColumnProperties()
          Returns the column properties of this table viewer.
 org.eclipse.swt.widgets.Control getControl()
           
 TableDataTableCursor getCursor()
          Returns the table viewer's cursor.
 java.lang.Object getElementAt(int index)
          Returns the element with the given index from this table viewer.
 org.eclipse.jface.viewers.IBaseLabelProvider getLabelProvider()
          The table viewer implementation of this Viewer framework method returns the label provider, which in the case of table viewers will be an instance of either ITableLabelProvider or ILabelProvider.
 org.eclipse.datatools.sqltools.common.core.tableviewer.IRowData getOrCreateRow()
           
 org.eclipse.datatools.sqltools.common.core.tableviewer.IRowData getRow()
          Returns the IRowData over which the TableCursor is positioned.
 org.eclipse.swt.widgets.Table getTable()
          Returns this table viewer's table control.
 void insert(java.lang.Object element, int position)
          Inserts the given element into this table viewer at the given position.
 boolean isCellEditorActive()
          Returns whether there is an active cell editor.
 boolean isDirty()
          Returns whether the table data of this viewer have changed since the last save operation.
 boolean isReadonly()
          Returns whether the viewer input is read-only.
 void movedownRow()
          Move the select row down.
 void moveupRow()
          Move the selected row up.
 void refresh()
           
 void refreshViewer(java.lang.Object element)
          Refreshes this viewer starting with the given element.
 void remove(java.lang.Object element)
          Removes the given element from this table viewer.
 void remove(java.lang.Object[] elements)
          Removes the given elements from this table viewer.
 void replace(java.lang.Object element, int index)
          Replace the entries starting at index with elements.
 void reveal(java.lang.Object element)
           
 void setCellEditors(org.eclipse.jface.viewers.CellEditor[] editors)
          Sets the cell editors of this table viewer.
 void setCellModifier(org.eclipse.jface.viewers.ICellModifier modifier)
          Sets the cell modifier of this table viewer.
 void setColumnProperties(java.lang.String[] columnProperties)
          Sets the column properties of this table viewer.
 void setCursor(TableDataTableCursor cursor)
          Set cursor for the table viewer.
 void setDirty(boolean value)
           
 boolean setFocus()
          Causes the receiver to have the keyboard focus, such that all keyboard events will be delivered to it.
 void setItemCount(int count)
          Set the item count of the receiver.
 void setLabelProvider(org.eclipse.jface.viewers.IBaseLabelProvider labelProvider)
          The table viewer implementation of this Viewer framework method ensures that the given label provider is an instance of either ITableLabelProvider or ILabelProvider.
 void setSortable(boolean sort)
          Sets the table's column as sortable if the argument is true, and sets it non-sortable otherwise.
 
Methods inherited from class org.eclipse.jface.viewers.StructuredViewer
addDoubleClickListener, addDragSupport, addDropSupport, addFilter, addOpenListener, addPostSelectionChangedListener, getComparator, getComparer, getFilters, getSelection, getSorter, refresh, refresh, refresh, removeDoubleClickListener, removeFilter, removeOpenListener, removePostSelectionChangedListener, resetFilters, setComparator, setComparer, setContentProvider, setFilters, setInput, setSelection, setSorter, setUseHashlookup, testFindItem, testFindItems, update, update
 
Methods inherited from class org.eclipse.jface.viewers.ContentViewer
getContentProvider, getInput
 
Methods inherited from class org.eclipse.jface.viewers.Viewer
addHelpListener, addSelectionChangedListener, getData, removeHelpListener, removeSelectionChangedListener, scrollDown, scrollUp, setData, setSelection
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.eclipse.jface.viewers.ISelectionProvider
addSelectionChangedListener, removeSelectionChangedListener, setSelection
 

Field Detail

GROUP_COPY

public static final java.lang.String GROUP_COPY
Context menu group for cut/copy/paste related actions. Value: "group.copy"

See Also:
Constant Field Values
Constructor Detail

AccessibleTableViewer

public AccessibleTableViewer(org.eclipse.swt.widgets.Composite parent)
Creates a accessible table viewer on a newly-created table control under the given parent. The table control is created using the SWT style bits MULTI, H_SCROLL, V_SCROLL, and BORDER. The viewer has no input, no content provider, a default label provider, no sorter, and no filters. The table has no columns.

Parameters:
parent - the parent control

AccessibleTableViewer

public AccessibleTableViewer(org.eclipse.swt.widgets.Composite parent,
                             int style)
Creates a table viewer on a newly-created table control under the given parent. The table control is created using the given style bits. The viewer has no input, no content provider, a default label provider, no sorter, and no filters. The table has no columns.

Parameters:
parent - the parent control
style - SWT style bits

AccessibleTableViewer

public AccessibleTableViewer(org.eclipse.swt.widgets.Table table)
Creates a table viewer on the given table control. The viewer has no input, no content provider, a default label provider, no sorter, and no filters.

Parameters:
table - the table control
Method Detail

setCellEditors

public void setCellEditors(org.eclipse.jface.viewers.CellEditor[] editors)
Sets the cell editors of this table viewer.

Parameters:
editors - the list of cell editors

getCursor

public TableDataTableCursor getCursor()
Returns the table viewer's cursor.

Returns:
the table viewer's cursor.

setCursor

public void setCursor(TableDataTableCursor cursor)
Set cursor for the table viewer.

Parameters:
cursor - TableDataTableCursor

getRow

public org.eclipse.datatools.sqltools.common.core.tableviewer.IRowData getRow()
Returns the IRowData over which the TableCursor is positioned.

Returns:
IRowData

getOrCreateRow

public org.eclipse.datatools.sqltools.common.core.tableviewer.IRowData getOrCreateRow()

setDirty

public void setDirty(boolean value)

isDirty

public boolean isDirty()
Returns whether the table data of this viewer have changed since the last save operation.

Returns:
true if the table data of this viewer have changed

isReadonly

public boolean isReadonly()
Returns whether the viewer input is read-only.

Returns:
true if the viewer input is read-only

doInsertRow

public void doInsertRow()
Insert a empty row into table.


doDelete

public void doDelete()
Delete a row which is positioned by cursor.


doDeleteAll

public void doDeleteAll(boolean confirm)
Delete all rows in this table viewer.

Parameters:
confirm - true to ask the user before deleting all rows, and false to delete all rows without asking

doUpdateValue

public void doUpdateValue()
To make the selected cell editable.


setFocus

public boolean setFocus()
Causes the receiver to have the keyboard focus, such that all keyboard events will be delivered to it. Focus reassignment will respect applicable platform constraints.

Returns:
true if the control got focus, and false if it was unable to.
Throws:
org.eclipse.swt.SWTException -
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver

doSave

public boolean doSave()
This method is used to save table data. It will invoke the save method.

Returns:
true if, and only if, save is successful.

doRefresh

public void doRefresh(boolean confirm)
Refreshes the contents of the table if dirty. If not, this method returns without effect.

If confirm is true the user is prompted to confirm the command. Otherwise, the refresh happens without prompt.

Parameters:
confirm - true to ask the user before saving unsaved changes (recommended), and false to save unsaved changes without asking

doRevert

public void doRevert()
This method will revert the added, deleted and changes rows in the table on the currently displayed table data to the original table data.


doSetNull

public void doSetNull()

moveupRow

public void moveupRow()
Move the selected row up.


movedownRow

public void movedownRow()
Move the select row down.


add

public void add(java.lang.Object[] elements)
Adds the given elements to this table viewer. If this viewer does not have a sorter, the elements are added at the end in the order given; otherwise the elements are inserted at appropriate positions.

This method should be called (by the content provider) when elements have been added to the model, in order to cause the viewer to accurately reflect the model. This method only affects the viewer, not the model.

Parameters:
elements - the elements to add

add

public void add(java.lang.Object element)
Adds the given element to this table viewer. If this viewer does not have a sorter, the element is added at the end; otherwise the element is inserted at the appropriate position.

This method should be called (by the content provider) when a single element has been added to the model, in order to cause the viewer to accurately reflect the model. This method only affects the viewer, not the model. Note that there is another method for efficiently processing the simultaneous addition of multiple elements.

Parameters:
element - the element to add

cancelEditing

public void cancelEditing()
Cancels a currently active cell editor. All changes already done in the cell editor are lost.


editElement

public void editElement(java.lang.Object element,
                        int column)
Starts editing the given element.

Parameters:
element - the element
column - the column number

getCellEditors

public org.eclipse.jface.viewers.CellEditor[] getCellEditors()
Returns the cell editors of this table viewer.

Returns:
the list of cell editors

getCellModifier

public org.eclipse.jface.viewers.ICellModifier getCellModifier()
Returns the cell modifier of this table viewer.

Returns:
the cell modifier

getColumnProperties

public java.lang.Object[] getColumnProperties()
Returns the column properties of this table viewer. The properties must correspond with the columns of the table control. They are used to identify the column in a cell modifier.

Returns:
the list of column properties

getControl

public org.eclipse.swt.widgets.Control getControl()
Specified by:
getControl in class org.eclipse.jface.viewers.Viewer

getElementAt

public java.lang.Object getElementAt(int index)
Returns the element with the given index from this table viewer. Returns null if the index is out of range.

This method is internal to the framework.

Parameters:
index - the zero-based index
Returns:
the element at the given index, or null if the index is out of range

getLabelProvider

public org.eclipse.jface.viewers.IBaseLabelProvider getLabelProvider()
The table viewer implementation of this Viewer framework method returns the label provider, which in the case of table viewers will be an instance of either ITableLabelProvider or ILabelProvider. If it is an ITableLabelProvider, then it provides a separate label text and image for each column. If it is an ILabelProvider, then it provides only the label text and image for the first column, and any remaining columns are blank.

Overrides:
getLabelProvider in class org.eclipse.jface.viewers.ContentViewer

getTable

public org.eclipse.swt.widgets.Table getTable()
Returns this table viewer's table control.

Returns:
the table control

insert

public void insert(java.lang.Object element,
                   int position)
Inserts the given element into this table viewer at the given position. If this viewer has a sorter, the position is ignored and the element is inserted at the correct position in the sort order.

This method should be called (by the content provider) when elements have been added to the model, in order to cause the viewer to accurately reflect the model. This method only affects the viewer, not the model.

Parameters:
element - the element
position - a 0-based position relative to the model, or -1 to indicate the last position

refreshViewer

public void refreshViewer(java.lang.Object element)
Refreshes this viewer starting with the given element. This method is to replace method refresh(final Object element) for avoiding the cursor is not correct to position the tableitem, when user scrolls table.

Parameters:
element - the element

isCellEditorActive

public boolean isCellEditorActive()
Returns whether there is an active cell editor.

Returns:
true if there is an active cell editor, and false otherwise

remove

public void remove(java.lang.Object[] elements)
Removes the given elements from this table viewer. The selection is updated if required.

This method should be called (by the content provider) when elements have been removed from the model, in order to cause the viewer to accurately reflect the model. This method only affects the viewer, not the model.

Parameters:
elements - the elements to remove

remove

public void remove(java.lang.Object element)
Removes the given element from this table viewer. The selection is updated if necessary.

This method should be called (by the content provider) when a single element has been removed from the model, in order to cause the viewer to accurately reflect the model. This method only affects the viewer, not the model. Note that there is another method for efficiently processing the simultaneous removal of multiple elements.

Parameters:
element - the element

reveal

public void reveal(java.lang.Object element)
Specified by:
reveal in class org.eclipse.jface.viewers.StructuredViewer

setCellModifier

public void setCellModifier(org.eclipse.jface.viewers.ICellModifier modifier)
Sets the cell modifier of this table viewer.

Parameters:
modifier - the cell modifier

setColumnProperties

public void setColumnProperties(java.lang.String[] columnProperties)
Sets the column properties of this table viewer. The properties must correspond with the columns of the table control. They are used to identify the column in a cell modifier.

Parameters:
columnProperties - the list of column properties

setLabelProvider

public void setLabelProvider(org.eclipse.jface.viewers.IBaseLabelProvider labelProvider)
The table viewer implementation of this Viewer framework method ensures that the given label provider is an instance of either ITableLabelProvider or ILabelProvider. If it is an ITableLabelProvider, then it provides a separate label text and image for each column. If it is an ILabelProvider, then it provides only the label text and image for the first column, and any remaining columns are blank.

Overrides:
setLabelProvider in class org.eclipse.jface.viewers.StructuredViewer

setItemCount

public void setItemCount(int count)
Set the item count of the receiver.

Parameters:
count - the new table size.
Since:
3.1

replace

public void replace(java.lang.Object element,
                    int index)
Replace the entries starting at index with elements. This method assumes all of these values are correct and will not call the content provider to verify. Note that this method will create a TableItem for all of the elements provided.

Parameters:
element -
index -
Since:
3.1
See Also:
ILazyContentProvider

clear

public void clear(int index)
Clear the table item at the specified index

Parameters:
index - the index of the table item to be cleared
Since:
3.1

refresh

public void refresh()
Overrides:
refresh in class org.eclipse.jface.viewers.StructuredViewer

setSortable

public void setSortable(boolean sort)
Sets the table's column as sortable if the argument is true, and sets it non-sortable otherwise.

Note: this method should be invoked after tableColumns are created.

Parameters:
sort - the sortable state