org.eclipse.xtext.ui.editor.tasks.dialogfields
Class ListDialogField

java.lang.Object
  extended by org.eclipse.xtext.ui.editor.tasks.dialogfields.DialogField
      extended by org.eclipse.xtext.ui.editor.tasks.dialogfields.ListDialogField

public class ListDialogField
extends DialogField

A list with a button bar. Typical buttons are 'Add', 'Remove', 'Up' and 'Down'. List model is independent of widget creation. DialogFields controls are: Label, List and Composite containing buttons.


Nested Class Summary
static class ListDialogField.ColumnsDescription
           
 
Field Summary
protected  java.lang.String[] fButtonLabels
           
protected  java.util.List fElements
           
protected  org.eclipse.jface.viewers.ILabelProvider fLabelProvider
           
protected  org.eclipse.xtext.ui.editor.tasks.dialogfields.ListDialogField.ListViewerAdapter fListViewerAdapter
           
protected  org.eclipse.jface.viewers.TableViewer fTable
           
protected  org.eclipse.swt.widgets.Control fTableControl
           
protected  org.eclipse.jface.viewers.ViewerComparator fViewerComparator
           
 
Fields inherited from class org.eclipse.xtext.ui.editor.tasks.dialogfields.DialogField
fLabelText
 
Constructor Summary
ListDialogField(IListAdapter adapter, java.lang.String[] buttonLabels, org.eclipse.jface.viewers.ILabelProvider lprovider)
          Creates the ListDialogField.
 
Method Summary
 boolean addElement(java.lang.Object element)
          Adds an element at the end of the list.
 boolean addElement(java.lang.Object element, int index)
          Adds an element at a position.
 boolean addElements(java.util.List elements)
          Adds elements at the end of the list.
 boolean addElements(java.util.List elements, int index)
          Adds elements at the given index
 boolean canMoveDown()
           
 boolean canMoveUp()
           
protected  org.eclipse.swt.widgets.Button createButton(org.eclipse.swt.widgets.Composite parent, java.lang.String label, org.eclipse.swt.events.SelectionListener listener)
           
protected  org.eclipse.jface.viewers.TableViewer createTableViewer(org.eclipse.swt.widgets.Composite parent)
           
 void dialogFieldChanged()
          Programatical invocation of a dialog field change.
protected  void doDoubleClick(org.eclipse.jface.viewers.DoubleClickEvent event)
           
 org.eclipse.swt.widgets.Control[] doFillIntoGrid(org.eclipse.swt.widgets.Composite parent, int nColumns)
          Creates all controls of the dialog field and fills it to a composite.
protected  void doListSelected(org.eclipse.jface.viewers.SelectionChangedEvent event)
           
 void editElement(java.lang.Object element)
           
 void elementChanged(java.lang.Object element)
          Notifies clients that the element has changed.
 void enableButton(int index, boolean enable)
          Sets a button enabled or disabled.
 org.eclipse.swt.widgets.Composite getButtonBox(org.eclipse.swt.widgets.Composite parent)
          Returns the composite containing the buttons.
 java.lang.Object getElement(int index)
          Gets the elements shown at the given index.
 java.util.List getElements()
          Gets the elements shown in the list.
 int getIndexOfElement(java.lang.Object elem)
          Gets the index of an element in the list or -1 if element is not in list.
 org.eclipse.swt.widgets.Control getListControl(org.eclipse.swt.widgets.Composite parent)
          Returns the list control.
protected  int getListStyle()
           
protected  boolean getManagedButtonState(org.eclipse.jface.viewers.ISelection sel, int index)
           
 int getNumberOfControls()
          Returns the number of columns of the dialog field.
 java.util.List getSelectedElements()
          Returns the selected elements.
 int getSize()
          Gets the number of elements
 org.eclipse.jface.viewers.TableViewer getTableViewer()
          Returns the internally used table viewer.
protected  void handleKeyPressed(org.eclipse.swt.events.KeyEvent event)
          Handles key events in the table viewer.
protected  boolean managedButtonPressed(int index)
          Checks if the button pressed is handled internally
 void postSetSelection(org.eclipse.jface.viewers.ISelection selection)
           
 void refresh()
          Refreshes the table.
 void removeAllElements()
          Adds an element at a position.
 void removeElement(java.lang.Object element)
          Removes an element from the list.
 void removeElements(java.util.List elements)
          Removes elements from the list.
 void replaceElement(java.lang.Object oldElement, java.lang.Object newElement)
          Replaces an element.
 void selectElements(org.eclipse.jface.viewers.ISelection selection)
           
 void selectFirstElement()
           
 void setButtonsMinWidth(int minWidth)
          Sets the minimal width of the buttons.
 void setDownButtonIndex(int downButtonIndex)
          Sets the index of the 'down' button in the button label array passed in the constructor.
 void setElements(java.util.Collection elements)
          Sets the elements shown in the list.
 void setRemoveButtonIndex(int removeButtonIndex)
          Sets the index of the 'remove' button in the button label array passed in the constructor.
 void setTableColumns(ListDialogField.ColumnsDescription column)
           
 void setUpButtonIndex(int upButtonIndex)
          Sets the index of the 'up' button in the button label array passed in the constructor.
 void setViewerComparator(org.eclipse.jface.viewers.ViewerComparator viewerComparator)
          Sets the viewer comparator.
 void setViewerSorter(org.eclipse.jface.viewers.ViewerSorter sorter)
          Deprecated. Use setViewerComparator(ViewerComparator) instead}
protected  void updateButtonState()
           
protected  void updateEnableState()
          Called when the enable state changed.
 
Methods inherited from class org.eclipse.xtext.ui.editor.tasks.dialogfields.DialogField
assertCompositeNotNull, assertEnoughColumns, createEmptySpace, createEmptySpace, getLabelControl, gridDataForLabel, isEnabled, isOkToUse, postSetFocusOnDialogField, setDialogFieldListener, setEnabled, setFocus, setLabelText
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

fTable

protected org.eclipse.jface.viewers.TableViewer fTable

fTableControl

protected org.eclipse.swt.widgets.Control fTableControl

fLabelProvider

protected org.eclipse.jface.viewers.ILabelProvider fLabelProvider

fListViewerAdapter

protected org.eclipse.xtext.ui.editor.tasks.dialogfields.ListDialogField.ListViewerAdapter fListViewerAdapter

fElements

protected java.util.List fElements

fViewerComparator

protected org.eclipse.jface.viewers.ViewerComparator fViewerComparator

fButtonLabels

protected java.lang.String[] fButtonLabels
Constructor Detail

ListDialogField

public ListDialogField(IListAdapter adapter,
                       java.lang.String[] buttonLabels,
                       org.eclipse.jface.viewers.ILabelProvider lprovider)
Creates the ListDialogField.

Parameters:
adapter - A listener for button invocation, selection changes. Can be null.
buttonLabels - The labels of all buttons: null is a valid array entry and marks a separator.
lprovider - The label provider to render the table entries
Method Detail

setRemoveButtonIndex

public void setRemoveButtonIndex(int removeButtonIndex)
Sets the index of the 'remove' button in the button label array passed in the constructor. The behavior of the button marked as the 'remove' button will then be handled internally. (enable state, button invocation behavior)


setUpButtonIndex

public void setUpButtonIndex(int upButtonIndex)
Sets the index of the 'up' button in the button label array passed in the constructor. The behavior of the button marked as the 'up' button will then be handled internally. (enable state, button invocation behavior)


setDownButtonIndex

public void setDownButtonIndex(int downButtonIndex)
Sets the index of the 'down' button in the button label array passed in the constructor. The behavior of the button marked as the 'down' button will then be handled internally. (enable state, button invocation behavior)


setViewerComparator

public void setViewerComparator(org.eclipse.jface.viewers.ViewerComparator viewerComparator)
Sets the viewer comparator.

Parameters:
viewerComparator - The viewer comparator to set

setTableColumns

public void setTableColumns(ListDialogField.ColumnsDescription column)

managedButtonPressed

protected boolean managedButtonPressed(int index)
Checks if the button pressed is handled internally

Returns:
Returns true if button has been handled.

doFillIntoGrid

public org.eclipse.swt.widgets.Control[] doFillIntoGrid(org.eclipse.swt.widgets.Composite parent,
                                                        int nColumns)
Description copied from class: DialogField
Creates all controls of the dialog field and fills it to a composite. The composite is assumed to have MGridLayout as layout. The dialog field will adjust its controls' spans to the number of columns given. To be reimplemented by dialog field implementors.

Overrides:
doFillIntoGrid in class DialogField

getNumberOfControls

public int getNumberOfControls()
Description copied from class: DialogField
Returns the number of columns of the dialog field. To be reimplemented by dialog field implementors.

Overrides:
getNumberOfControls in class DialogField

setButtonsMinWidth

public void setButtonsMinWidth(int minWidth)
Sets the minimal width of the buttons. Must be called after widget creation.


getListControl

public org.eclipse.swt.widgets.Control getListControl(org.eclipse.swt.widgets.Composite parent)
Returns the list control. When called the first time, the control will be created.

Parameters:
parent - The parent composite when called the first time, or null after.

getTableViewer

public org.eclipse.jface.viewers.TableViewer getTableViewer()
Returns the internally used table viewer.


getListStyle

protected int getListStyle()

createTableViewer

protected org.eclipse.jface.viewers.TableViewer createTableViewer(org.eclipse.swt.widgets.Composite parent)

createButton

protected org.eclipse.swt.widgets.Button createButton(org.eclipse.swt.widgets.Composite parent,
                                                      java.lang.String label,
                                                      org.eclipse.swt.events.SelectionListener listener)

getButtonBox

public org.eclipse.swt.widgets.Composite getButtonBox(org.eclipse.swt.widgets.Composite parent)
Returns the composite containing the buttons. When called the first time, the control will be created.

Parameters:
parent - The parent composite when called the first time, or null after.

handleKeyPressed

protected void handleKeyPressed(org.eclipse.swt.events.KeyEvent event)
Handles key events in the table viewer. Specifically when the delete key is pressed.


dialogFieldChanged

public void dialogFieldChanged()
Description copied from class: DialogField
Programatical invocation of a dialog field change.

Overrides:
dialogFieldChanged in class DialogField

updateButtonState

protected void updateButtonState()

getManagedButtonState

protected boolean getManagedButtonState(org.eclipse.jface.viewers.ISelection sel,
                                        int index)

updateEnableState

protected void updateEnableState()
Description copied from class: DialogField
Called when the enable state changed. To be extended by dialog field implementors.

Overrides:
updateEnableState in class DialogField

enableButton

public void enableButton(int index,
                         boolean enable)
Sets a button enabled or disabled.


setElements

public void setElements(java.util.Collection elements)
Sets the elements shown in the list.


getElements

public java.util.List getElements()
Gets the elements shown in the list. The list returned is a copy, so it can be modified by the user.


getElement

public java.lang.Object getElement(int index)
Gets the elements shown at the given index.


getIndexOfElement

public int getIndexOfElement(java.lang.Object elem)
Gets the index of an element in the list or -1 if element is not in list.


replaceElement

public void replaceElement(java.lang.Object oldElement,
                           java.lang.Object newElement)
                    throws java.lang.IllegalArgumentException
Replaces an element.

Throws:
java.lang.IllegalArgumentException

elementChanged

public void elementChanged(java.lang.Object element)
                    throws java.lang.IllegalArgumentException
Notifies clients that the element has changed.

Throws:
java.lang.IllegalArgumentException

addElement

public boolean addElement(java.lang.Object element)
Adds an element at the end of the list.


addElement

public boolean addElement(java.lang.Object element,
                          int index)
Adds an element at a position.


addElements

public boolean addElements(java.util.List elements,
                           int index)
Adds elements at the given index


addElements

public boolean addElements(java.util.List elements)
Adds elements at the end of the list.


removeAllElements

public void removeAllElements()
Adds an element at a position.


removeElement

public void removeElement(java.lang.Object element)
                   throws java.lang.IllegalArgumentException
Removes an element from the list.

Throws:
java.lang.IllegalArgumentException

removeElements

public void removeElements(java.util.List elements)
Removes elements from the list.


getSize

public int getSize()
Gets the number of elements


selectElements

public void selectElements(org.eclipse.jface.viewers.ISelection selection)

selectFirstElement

public void selectFirstElement()

editElement

public void editElement(java.lang.Object element)

postSetSelection

public void postSetSelection(org.eclipse.jface.viewers.ISelection selection)

refresh

public void refresh()
Refreshes the table.

Overrides:
refresh in class DialogField

canMoveUp

public boolean canMoveUp()

canMoveDown

public boolean canMoveDown()

getSelectedElements

public java.util.List getSelectedElements()
Returns the selected elements.


doListSelected

protected void doListSelected(org.eclipse.jface.viewers.SelectionChangedEvent event)

doDoubleClick

protected void doDoubleClick(org.eclipse.jface.viewers.DoubleClickEvent event)

setViewerSorter

@Deprecated
public void setViewerSorter(org.eclipse.jface.viewers.ViewerSorter sorter)
Deprecated. Use setViewerComparator(ViewerComparator) instead}