Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 58144 Details for
Bug 172646
[Viewers] Activate Editors using a specialized Event
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
Fully customized editor activation
clipboard41627.txt (text/plain), 132.09 KB, created by
Thomas Schindl
on 2007-02-02 14:25:12 EST
(
hide
)
Description:
Fully customized editor activation
Filename:
MIME Type:
Creator:
Thomas Schindl
Created:
2007-02-02 14:25:12 EST
Size:
132.09 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jface >Index: src/org/eclipse/jface/viewers/TableViewer.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jface/src/org/eclipse/jface/viewers/TableViewer.java,v >retrieving revision 1.74 >diff -u -r1.74 TableViewer.java >--- src/org/eclipse/jface/viewers/TableViewer.java 31 Jan 2007 19:32:23 -0000 1.74 >+++ src/org/eclipse/jface/viewers/TableViewer.java 2 Feb 2007 19:23:29 -0000 >@@ -134,10 +134,6 @@ > return new StructuredSelection(element); > } > >- protected Item[] getSelection() { >- return table.getSelection(); >- } >- > protected void setEditor(Control w, Item item, int fColumnNumber) { > tableEditor.setEditor(w, (TableItem) item, fColumnNumber); > } >@@ -148,10 +144,6 @@ > tableEditor.minimumWidth = layoutData.minimumWidth; > } > >- protected void showSelection() { >- table.showSelection(); >- } >- > }; > } > >@@ -303,4 +295,10 @@ > protected void doClear(int index) { > table.clear(index); > } >-} >+ >+ >+ protected ViewerCell getFocusCell() { >+ //TODO Focus tracking has to be implemented in M6 >+ return null; >+ } >+} >\ No newline at end of file >Index: src/org/eclipse/jface/viewers/TreeViewer.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jface/src/org/eclipse/jface/viewers/TreeViewer.java,v >retrieving revision 1.76 >diff -u -r1.76 TreeViewer.java >--- src/org/eclipse/jface/viewers/TreeViewer.java 17 Jan 2007 21:57:05 -0000 1.76 >+++ src/org/eclipse/jface/viewers/TreeViewer.java 2 Feb 2007 19:23:29 -0000 >@@ -284,10 +284,6 @@ > return new StructuredSelection(element); > } > >- protected Item[] getSelection() { >- return tree.getSelection(); >- } >- > protected void setEditor(Control w, Item item, int fColumnNumber) { > treeEditor.setEditor(w, (TreeItem) item, fColumnNumber); > } >@@ -298,10 +294,6 @@ > treeEditor.minimumWidth = layoutData.minimumWidth; > } > >- protected void showSelection() { >- getTree().showSelection(); >- } >- > }; > } > >@@ -913,4 +905,9 @@ > protected int doGetColumnCount() { > return tree.getColumnCount(); > } >+ >+ protected ViewerCell getFocusCell() { >+ //TODO Focus tracking has to be implemented in M6 >+ return null; >+ } > } >Index: src/org/eclipse/jface/viewers/AbstractTreeViewer.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jface/src/org/eclipse/jface/viewers/AbstractTreeViewer.java,v >retrieving revision 1.108 >diff -u -r1.108 AbstractTreeViewer.java >--- src/org/eclipse/jface/viewers/AbstractTreeViewer.java 25 Jan 2007 16:52:11 -0000 1.108 >+++ src/org/eclipse/jface/viewers/AbstractTreeViewer.java 2 Feb 2007 19:23:27 -0000 >@@ -2950,4 +2950,11 @@ > return false; > return ((TreePath) elementOrTreePath).getSegmentCount() == 0; > } >+ >+ // -------------------------------------------------- >+ // These methods should be overwritten by subclasses and are only here to provide backwards compatility >+ >+ protected ViewerCell getFocusCell() { >+ return null; >+ } > } >Index: src/org/eclipse/jface/viewers/EditingSupport.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jface/src/org/eclipse/jface/viewers/EditingSupport.java,v >retrieving revision 1.5 >diff -u -r1.5 EditingSupport.java >--- src/org/eclipse/jface/viewers/EditingSupport.java 20 Jan 2007 05:11:39 -0000 1.5 >+++ src/org/eclipse/jface/viewers/EditingSupport.java 2 Feb 2007 19:23:29 -0000 >@@ -170,8 +170,10 @@ > } > > if (cell2edit != null) { >- viewer.editElement(cell2edit.getElement(), cell2edit >- .getColumnIndex()); >+ EditorActivationEvent acEvent = new EditorActivationEvent(cell2edit,event); >+ viewer.fireEditorActivationEvent(acEvent); >+// viewer.editElement(cell2edit.getElement(), cell2edit >+// .getColumnIndex()); > } > } > >Index: src/org/eclipse/jface/viewers/ColumnViewer.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jface/src/org/eclipse/jface/viewers/ColumnViewer.java,v >retrieving revision 1.21 >diff -u -r1.21 ColumnViewer.java >--- src/org/eclipse/jface/viewers/ColumnViewer.java 17 Jan 2007 21:57:05 -0000 1.21 >+++ src/org/eclipse/jface/viewers/ColumnViewer.java 2 Feb 2007 19:23:28 -0000 >@@ -14,7 +14,12 @@ > > package org.eclipse.jface.viewers; > >+ >+import java.util.List; >+ > import org.eclipse.core.runtime.Assert; >+import org.eclipse.swt.events.KeyEvent; >+import org.eclipse.swt.events.KeyListener; > import org.eclipse.swt.events.MouseAdapter; > import org.eclipse.swt.events.MouseEvent; > import org.eclipse.swt.graphics.Point; >@@ -50,6 +55,8 @@ > > private int tabEditingStyle = EditingSupport.TABING_NONE; > >+ private KeyListener keyboardActivationListener; >+ > /** > * Create a new instance of the receiver. > */ >@@ -76,7 +83,7 @@ > if (viewerEditor != null) { > control.addMouseListener(new MouseAdapter() { > public void mouseDown(MouseEvent e) { >- viewerEditor.handleMouseDown(e); >+ handleMouseDown(e); > } > }); > } >@@ -371,10 +378,38 @@ > */ > public void editElement(Object element, int column) { > if (viewerEditor != null) { >- viewerEditor.editElement(element, column); >+ Widget item = findItem(element); >+ if( item != null ) { >+ ViewerRow row = getViewerRowFromItem(item); >+ if( row != null ) { >+ ViewerCell cell = row.getCell(column); >+ if( cell != null ) { >+ getControl().setRedraw(false); >+ >+ List l = getSelectionFromWidget(); >+ >+ if( l.size() > 1 || ! l.contains(cell.getElement()) ) { >+ setSelection(new StructuredSelection(cell.getElement())); >+ } >+ >+ fireEditorActivationEvent(new EditorActivationEvent(cell)); >+ getControl().setRedraw(true); >+ } >+ } >+ } > } > } >- >+ >+ /** >+ * Invoking this method fires an editor activation event which tries to enable the editor >+ * but before this event is passed to {@link EditorActivationStrategy} to see >+ * if this event should really trigger editor activation >+ * @param event the activation event >+ */ >+ protected void fireEditorActivationEvent(EditorActivationEvent event) { >+ viewerEditor.handleEditorActivationEvent(event); >+ } >+ > /** > * Return the CellEditors for the receiver, or <code>null</code> if no > * cell editors are set. >@@ -546,6 +581,82 @@ > } > > /** >+ * To fully control the strategy used to control on which cell-selection >+ * events the editor has to be activated you can pass your customized >+ * strategy using this method. >+ * >+ * @param editorActivationStrategy >+ * the strategy used to activate an editor >+ */ >+ public void setEditorActivationStrategy( >+ EditorActivationStrategy editorActivationStrategy) { >+ if( viewerEditor != null ) { >+ viewerEditor.setEditorActivationStrategy(editorActivationStrategy); >+ } else { >+ throw new IllegalStateException("This feature is not supported by the widget"); //$NON-NLS-1$ >+ } >+ } >+ >+ /** >+ * Enable activation of cell editors by keyboard >+ * @param enable <code>true</code> to enable >+ */ >+ public void setEnableEditorActivationWithKeyboard(boolean enable) { >+ if( enable ) { >+ if( keyboardActivationListener == null ) { >+ keyboardActivationListener = new KeyListener() { >+ >+ public void keyPressed(KeyEvent e) { >+ ViewerCell cell = getFocusCell(); >+ >+ if( cell != null ) { >+ fireEditorActivationEvent(new EditorActivationEvent(cell,e)); >+ } >+ } >+ >+ public void keyReleased(KeyEvent e) { >+ >+ } >+ >+ }; >+ getControl().addKeyListener(keyboardActivationListener); >+ } >+ } else { >+ if( keyboardActivationListener != null ) { >+ getControl().removeKeyListener(keyboardActivationListener); >+ keyboardActivationListener = null; >+ } >+ } >+ } >+ >+ /** >+ * @param listener >+ */ >+ public void addEditorActivationListner(AbstractViewerEditorActivationListener listener) { >+ this.viewerEditor.addEditorActivationListener(listener); >+ } >+ >+ /** >+ * @param listener >+ */ >+ public void removeEditorActivationListener(AbstractViewerEditorActivationListener listener) { >+ this.viewerEditor.removeEditorActivationListener(listener); >+ } >+ >+ private void handleMouseDown(MouseEvent e) { >+ ViewerCell cell = getCell(new Point(e.x,e.y)); >+ >+ if( cell != null ) { >+ fireEditorActivationEvent(new EditorActivationEvent(cell,e)); >+ } >+ } >+ >+ /** >+ * @return the cell currently focused or <code>null</code> >+ */ >+ protected abstract ViewerCell getFocusCell(); >+ >+ /** > * Returns the number of columns contained in the receiver. If no columns > * were created by the programmer, this value is zero, despite the fact that > * visually, one column of items may be visible. This occurs when the >Index: src/org/eclipse/jface/viewers/CellEditor.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jface/src/org/eclipse/jface/viewers/CellEditor.java,v >retrieving revision 1.25 >diff -u -r1.25 CellEditor.java >--- src/org/eclipse/jface/viewers/CellEditor.java 10 Nov 2006 17:42:08 -0000 1.25 >+++ src/org/eclipse/jface/viewers/CellEditor.java 2 Feb 2007 19:23:28 -0000 >@@ -22,835 +22,860 @@ > import org.eclipse.swt.widgets.Control; > > /** >- * Abstract base class for cell editors. Implements property change listener handling, >- * and SWT window management. >+ * Abstract base class for cell editors. Implements property change listener >+ * handling, and SWT window management. > * <p> >- * Subclasses implement particular kinds of cell editors. This package contains various >- * specialized cell editors: >+ * Subclasses implement particular kinds of cell editors. This package contains >+ * various specialized cell editors: > * <ul> >- * <li><code>TextCellEditor</code> - for simple text strings</li> >- * <li><code>ColorCellEditor</code> - for colors</li> >- * <li><code>ComboBoxCellEditor</code> - value selected from drop-down combo box</li> >- * <li><code>CheckboxCellEditor</code> - boolean valued checkbox</li> >- * <li><code>DialogCellEditor</code> - value from arbitrary dialog</li> >+ * <li><code>TextCellEditor</code> - for simple text strings</li> >+ * <li><code>ColorCellEditor</code> - for colors</li> >+ * <li><code>ComboBoxCellEditor</code> - value selected from drop-down combo >+ * box</li> >+ * <li><code>CheckboxCellEditor</code> - boolean valued checkbox</li> >+ * <li><code>DialogCellEditor</code> - value from arbitrary dialog</li> > * </ul> > * </p> > */ > public abstract class CellEditor { > >- /** >- * List of cell editor listeners (element type: <code>ICellEditorListener</code>). >- */ >- private ListenerList listeners = new ListenerList(); >- >- /** >- * List of cell editor property change listeners >- * (element type: <code>IPropertyChangeListener</code>). >- */ >- private ListenerList propertyChangeListeners = new ListenerList(); >- >- /** >- * Indicates whether this cell editor's current value is valid. >- */ >- private boolean valid = false; >- >- /** >- * Optional cell editor validator; <code>null</code> if none. >- */ >- private ICellEditorValidator validator = null; >- >- /** >- * The error message string to display for invalid values; >- * <code>null</code> if none (that is, the value is valid). >- */ >- private String errorMessage = null; >- >- /** >- * Indicates whether this cell editor has been changed recently. >- */ >- private boolean dirty = false; >- >- /** >- * This cell editor's control, or <code>null</code> >- * if not created yet. >- */ >- private Control control = null; >- >- /** >- * Default cell editor style >- */ >- private static final int defaultStyle = SWT.NONE; >- >- /** >- * This cell editor's style >- */ >- private int style = defaultStyle; >- >- /** >- * Struct-like layout data for cell editors, with reasonable defaults >- * for all fields. >- */ >- public static class LayoutData { >- /** >- * Horizontal alignment; <code>SWT.LEFT</code> by default. >- */ >- public int horizontalAlignment = SWT.LEFT; >- >- /** >- * Indicates control grabs additional space; <code>true</code> by default. >- */ >- public boolean grabHorizontal = true; >- >- /** >- * Minimum width in pixels; <code>50</code> pixels by default. >- */ >- public int minimumWidth = 50; >- } >- >- /** >- * Property name for the copy action >- */ >- public static final String COPY = "copy"; //$NON-NLS-1$ >- >- /** >- * Property name for the cut action >- */ >- public static final String CUT = "cut"; //$NON-NLS-1$ >- >- /** >- * Property name for the delete action >- */ >- public static final String DELETE = "delete"; //$NON-NLS-1$ >- >- /** >- * Property name for the find action >- */ >- public static final String FIND = "find"; //$NON-NLS-1$ >- >- /** >- * Property name for the paste action >- */ >- public static final String PASTE = "paste"; //$NON-NLS-1$ >- >- /** >- * Property name for the redo action >- */ >- public static final String REDO = "redo"; //$NON-NLS-1$ >- >- /** >- * Property name for the select all action >- */ >- public static final String SELECT_ALL = "selectall"; //$NON-NLS-1$ >- >- /** >- * Property name for the undo action >- */ >- public static final String UNDO = "undo"; //$NON-NLS-1$ >- >- /** >- * Creates a new cell editor with no control >- * The cell editor has no cell validator. >- * @since 2.1 >- */ >- protected CellEditor() { >- } >- >- /** >- * Creates a new cell editor under the given parent control. >- * The cell editor has no cell validator. >- * >- * @param parent the parent control >- */ >- protected CellEditor(Composite parent) { >- this(parent, defaultStyle); >- } >- >- /** >- * Creates a new cell editor under the given parent control. >- * The cell editor has no cell validator. >- * >- * @param parent the parent control >- * @param style the style bits >- * @since 2.1 >- */ >- protected CellEditor(Composite parent, int style) { >- this.style = style; >- create(parent); >- } >- >- /** >- * Activates this cell editor. >- * <p> >- * The default implementation of this framework method >- * does nothing. Subclasses may reimplement. >- * </p> >- */ >- public void activate() { >- } >- >- /** >- * Adds a listener to this cell editor. >- * Has no effect if an identical listener is already registered. >- * >- * @param listener a cell editor listener >- */ >- public void addListener(ICellEditorListener listener) { >- listeners.add(listener); >- } >- >- /** >- * Adds a property change listener to this cell editor. >- * Has no effect if an identical property change listener >- * is already registered. >- * >- * @param listener a property change listener >- */ >- public void addPropertyChangeListener(IPropertyChangeListener listener) { >- propertyChangeListeners.add(listener); >- } >- >- /** >- * Creates the control for this cell editor under the given parent control. >- * <p> >- * This framework method must be implemented by concrete >- * subclasses. >- * </p> >- * >- * @param parent the parent control >- * @return the new control, or <code>null</code> if this cell editor has no control >- */ >- protected abstract Control createControl(Composite parent); >- >- /** >- * Creates the control for this cell editor under the given parent control. >- * >- * @param parent the parent control >- * @since 2.1 >- */ >- public void create(Composite parent) { >- Assert.isTrue(control == null); >- control = createControl(parent); >- // See 1GD5CA6: ITPUI:ALL - TaskView.setSelection does not work >- // Control is created with getVisible()==true by default. >- // This causes composite.setFocus() to work incorrectly. >- // The cell editor's control grabs focus instead, even if it is not active. >- // Make the control invisible here by default. >- deactivate(); >- } >- >- /** >- * Hides this cell editor's control. Does nothing if this >- * cell editor is not visible. >- */ >- public void deactivate() { >- if (control != null && !control.isDisposed()) { >+ /** >+ * List of cell editor listeners (element type: >+ * <code>ICellEditorListener</code>). >+ */ >+ private ListenerList listeners = new ListenerList(); >+ >+ /** >+ * List of cell editor property change listeners (element type: >+ * <code>IPropertyChangeListener</code>). >+ */ >+ private ListenerList propertyChangeListeners = new ListenerList(); >+ >+ /** >+ * Indicates whether this cell editor's current value is valid. >+ */ >+ private boolean valid = false; >+ >+ /** >+ * Optional cell editor validator; <code>null</code> if none. >+ */ >+ private ICellEditorValidator validator = null; >+ >+ /** >+ * The error message string to display for invalid values; <code>null</code> >+ * if none (that is, the value is valid). >+ */ >+ private String errorMessage = null; >+ >+ /** >+ * Indicates whether this cell editor has been changed recently. >+ */ >+ private boolean dirty = false; >+ >+ /** >+ * This cell editor's control, or <code>null</code> if not created yet. >+ */ >+ private Control control = null; >+ >+ /** >+ * Default cell editor style >+ */ >+ private static final int defaultStyle = SWT.NONE; >+ >+ /** >+ * This cell editor's style >+ */ >+ private int style = defaultStyle; >+ >+ /** >+ * Struct-like layout data for cell editors, with reasonable defaults for >+ * all fields. >+ */ >+ public static class LayoutData { >+ /** >+ * Horizontal alignment; <code>SWT.LEFT</code> by default. >+ */ >+ public int horizontalAlignment = SWT.LEFT; >+ >+ /** >+ * Indicates control grabs additional space; <code>true</code> by >+ * default. >+ */ >+ public boolean grabHorizontal = true; >+ >+ /** >+ * Minimum width in pixels; <code>50</code> pixels by default. >+ */ >+ public int minimumWidth = 50; >+ } >+ >+ /** >+ * Property name for the copy action >+ */ >+ public static final String COPY = "copy"; //$NON-NLS-1$ >+ >+ /** >+ * Property name for the cut action >+ */ >+ public static final String CUT = "cut"; //$NON-NLS-1$ >+ >+ /** >+ * Property name for the delete action >+ */ >+ public static final String DELETE = "delete"; //$NON-NLS-1$ >+ >+ /** >+ * Property name for the find action >+ */ >+ public static final String FIND = "find"; //$NON-NLS-1$ >+ >+ /** >+ * Property name for the paste action >+ */ >+ public static final String PASTE = "paste"; //$NON-NLS-1$ >+ >+ /** >+ * Property name for the redo action >+ */ >+ public static final String REDO = "redo"; //$NON-NLS-1$ >+ >+ /** >+ * Property name for the select all action >+ */ >+ public static final String SELECT_ALL = "selectall"; //$NON-NLS-1$ >+ >+ /** >+ * Property name for the undo action >+ */ >+ public static final String UNDO = "undo"; //$NON-NLS-1$ >+ >+ /** >+ * Creates a new cell editor with no control The cell editor has no cell >+ * validator. >+ * >+ * @since 2.1 >+ */ >+ protected CellEditor() { >+ } >+ >+ /** >+ * Creates a new cell editor under the given parent control. The cell editor >+ * has no cell validator. >+ * >+ * @param parent >+ * the parent control >+ */ >+ protected CellEditor(Composite parent) { >+ this(parent, defaultStyle); >+ } >+ >+ /** >+ * Creates a new cell editor under the given parent control. The cell editor >+ * has no cell validator. >+ * >+ * @param parent >+ * the parent control >+ * @param style >+ * the style bits >+ * @since 2.1 >+ */ >+ protected CellEditor(Composite parent, int style) { >+ this.style = style; >+ create(parent); >+ } >+ >+ /** >+ * Activates this cell editor. >+ * <p> >+ * The default implementation of this framework method does nothing. >+ * Subclasses may reimplement. >+ * </p> >+ */ >+ public void activate() { >+ } >+ >+ /** >+ * Activate the editor but also inform the editor which event triggered its activation. >+ * <b>The default implementation simply calls {@link #activate()}</b> >+ * >+ * @param activationEvent the editor activation event >+ */ >+ public void activate(EditorActivationEvent activationEvent) { >+ activate(); >+ } >+ >+ /** >+ * Adds a listener to this cell editor. Has no effect if an identical >+ * listener is already registered. >+ * >+ * @param listener >+ * a cell editor listener >+ */ >+ public void addListener(ICellEditorListener listener) { >+ listeners.add(listener); >+ } >+ >+ /** >+ * Adds a property change listener to this cell editor. Has no effect if an >+ * identical property change listener is already registered. >+ * >+ * @param listener >+ * a property change listener >+ */ >+ public void addPropertyChangeListener(IPropertyChangeListener listener) { >+ propertyChangeListeners.add(listener); >+ } >+ >+ /** >+ * Creates the control for this cell editor under the given parent control. >+ * <p> >+ * This framework method must be implemented by concrete subclasses. >+ * </p> >+ * >+ * @param parent >+ * the parent control >+ * @return the new control, or <code>null</code> if this cell editor has >+ * no control >+ */ >+ protected abstract Control createControl(Composite parent); >+ >+ /** >+ * Creates the control for this cell editor under the given parent control. >+ * >+ * @param parent >+ * the parent control >+ * @since 2.1 >+ */ >+ public void create(Composite parent) { >+ Assert.isTrue(control == null); >+ control = createControl(parent); >+ // See 1GD5CA6: ITPUI:ALL - TaskView.setSelection does not work >+ // Control is created with getVisible()==true by default. >+ // This causes composite.setFocus() to work incorrectly. >+ // The cell editor's control grabs focus instead, even if it is not >+ // active. >+ // Make the control invisible here by default. >+ deactivate(); >+ } >+ >+ /** >+ * Hides this cell editor's control. Does nothing if this cell editor is not >+ * visible. >+ */ >+ public void deactivate() { >+ if (control != null && !control.isDisposed()) { > control.setVisible(false); > } >- } >+ } > >- /** >- * Disposes of this cell editor and frees any associated SWT resources. >- */ >- public void dispose() { >- if (control != null && !control.isDisposed()) { >- control.dispose(); >- } >- control = null; >- } >- >- /** >- * Returns this cell editor's value. >- * <p> >- * This framework method must be implemented by concrete subclasses. >- * </p> >- * >- * @return the value of this cell editor >- * @see #getValue >- */ >- protected abstract Object doGetValue(); >- >- /** >- * Sets the focus to the cell editor's control. >- * <p> >- * This framework method must be implemented by concrete subclasses. >- * </p> >- * >- * @see #setFocus >- */ >- protected abstract void doSetFocus(); >- >- /** >- * Sets this cell editor's value. >- * <p> >- * This framework method must be implemented by concrete subclasses. >- * </p> >- * >- * @param value the value of this cell editor >- * @see #setValue >- */ >- protected abstract void doSetValue(Object value); >- >- /** >- * Notifies all registered cell editor listeners of an apply event. >- * Only listeners registered at the time this method is called are notified. >- * >- * @see ICellEditorListener#applyEditorValue >- */ >- protected void fireApplyEditorValue() { >- Object[] array = listeners.getListeners(); >- for (int i = 0; i < array.length; i++) { >- final ICellEditorListener l = (ICellEditorListener) array[i]; >- SafeRunnable.run(new SafeRunnable() { >- public void run() { >- l.applyEditorValue(); >- } >- }); >- } >- } >- >- /** >- * Notifies all registered cell editor listeners that editing has been >- * canceled. >- * >- * @see ICellEditorListener#cancelEditor >- */ >- protected void fireCancelEditor() { >- Object[] array = listeners.getListeners(); >- for (int i = 0; i < array.length; i++) { >- final ICellEditorListener l = (ICellEditorListener) array[i]; >- SafeRunnable.run(new SafeRunnable() { >- public void run() { >- l.cancelEditor(); >- } >- }); >- } >- } >- >- /** >- * Notifies all registered cell editor listeners of a value change. >- * >- * @param oldValidState the valid state before the end user changed the value >- * @param newValidState the current valid state >- * @see ICellEditorListener#editorValueChanged >- */ >- protected void fireEditorValueChanged(final boolean oldValidState, >- final boolean newValidState) { >- Object[] array = listeners.getListeners(); >- for (int i = 0; i < array.length; i++) { >- final ICellEditorListener l = (ICellEditorListener) array[i]; >- SafeRunnable.run(new SafeRunnable() { >- public void run() { >- l.editorValueChanged(oldValidState, newValidState); >- } >- }); >- } >- } >- >- /** >- * Notifies all registered property listeners >- * of an enablement change. >- * >- * @param actionId the id indicating what action's enablement has changed. >- */ >- protected void fireEnablementChanged(final String actionId) { >- Object[] array = propertyChangeListeners.getListeners(); >- for (int i = 0; i < array.length; i++) { >- final IPropertyChangeListener l = (IPropertyChangeListener) array[i]; >- SafeRunnable.run(new SafeRunnable() { >- public void run() { >- l.propertyChange(new PropertyChangeEvent(this, actionId, >- null, null)); >- } >- }); >- } >- } >- >- /** >- * Sets the style bits for this cell editor. >- * >- * @param style the SWT style bits for this cell editor >- * @since 2.1 >- */ >- public void setStyle(int style) { >- this.style = style; >- } >- >- /** >- * Returns the style bits for this cell editor. >- * >- * @return the style for this cell editor >- * @since 2.1 >- */ >- public int getStyle() { >- return style; >- } >- >- /** >- * Returns the control used to implement this cell editor. >- * >- * @return the control, or <code>null</code> if this cell editor has no control >- */ >- public Control getControl() { >- return control; >- } >- >- /** >- * Returns the current error message for this cell editor. >- * >- * @return the error message if the cell editor is in an invalid state, >- * and <code>null</code> if the cell editor is valid >- */ >- public String getErrorMessage() { >- return errorMessage; >- } >- >- /** >- * Returns a layout data object for this cell editor. >- * This is called each time the cell editor is activated >- * and controls the layout of the SWT table editor. >- * <p> >- * The default implementation of this method sets the >- * minimum width to the control's preferred width. >- * Subclasses may extend or reimplement. >- * </p> >- * >- * @return the layout data object >- */ >- public LayoutData getLayoutData() { >- LayoutData result = new LayoutData(); >- Control control = getControl(); >- if (control != null) { >- result.minimumWidth = control.computeSize(SWT.DEFAULT, SWT.DEFAULT, >- true).x; >- } >- return result; >- } >- >- /** >- * Returns the input validator for this cell editor. >- * >- * @return the input validator, or <code>null</code> if none >- */ >- public ICellEditorValidator getValidator() { >- return validator; >- } >- >- /** >- * Returns this cell editor's value provided that it has a valid one. >- * >- * @return the value of this cell editor, or <code>null</code> >- * if the cell editor does not contain a valid value >- */ >- public final Object getValue() { >- if (!valid) { >+ /** >+ * Disposes of this cell editor and frees any associated SWT resources. >+ */ >+ public void dispose() { >+ if (control != null && !control.isDisposed()) { >+ control.dispose(); >+ } >+ control = null; >+ } >+ >+ /** >+ * Returns this cell editor's value. >+ * <p> >+ * This framework method must be implemented by concrete subclasses. >+ * </p> >+ * >+ * @return the value of this cell editor >+ * @see #getValue >+ */ >+ protected abstract Object doGetValue(); >+ >+ /** >+ * Sets the focus to the cell editor's control. >+ * <p> >+ * This framework method must be implemented by concrete subclasses. >+ * </p> >+ * >+ * @see #setFocus >+ */ >+ protected abstract void doSetFocus(); >+ >+ /** >+ * Sets this cell editor's value. >+ * <p> >+ * This framework method must be implemented by concrete subclasses. >+ * </p> >+ * >+ * @param value >+ * the value of this cell editor >+ * @see #setValue >+ */ >+ protected abstract void doSetValue(Object value); >+ >+ /** >+ * Notifies all registered cell editor listeners of an apply event. Only >+ * listeners registered at the time this method is called are notified. >+ * >+ * @see ICellEditorListener#applyEditorValue >+ */ >+ protected void fireApplyEditorValue() { >+ Object[] array = listeners.getListeners(); >+ for (int i = 0; i < array.length; i++) { >+ final ICellEditorListener l = (ICellEditorListener) array[i]; >+ SafeRunnable.run(new SafeRunnable() { >+ public void run() { >+ l.applyEditorValue(); >+ } >+ }); >+ } >+ } >+ >+ /** >+ * Notifies all registered cell editor listeners that editing has been >+ * canceled. >+ * >+ * @see ICellEditorListener#cancelEditor >+ */ >+ protected void fireCancelEditor() { >+ Object[] array = listeners.getListeners(); >+ for (int i = 0; i < array.length; i++) { >+ final ICellEditorListener l = (ICellEditorListener) array[i]; >+ SafeRunnable.run(new SafeRunnable() { >+ public void run() { >+ l.cancelEditor(); >+ } >+ }); >+ } >+ } >+ >+ /** >+ * Notifies all registered cell editor listeners of a value change. >+ * >+ * @param oldValidState >+ * the valid state before the end user changed the value >+ * @param newValidState >+ * the current valid state >+ * @see ICellEditorListener#editorValueChanged >+ */ >+ protected void fireEditorValueChanged(final boolean oldValidState, >+ final boolean newValidState) { >+ Object[] array = listeners.getListeners(); >+ for (int i = 0; i < array.length; i++) { >+ final ICellEditorListener l = (ICellEditorListener) array[i]; >+ SafeRunnable.run(new SafeRunnable() { >+ public void run() { >+ l.editorValueChanged(oldValidState, newValidState); >+ } >+ }); >+ } >+ } >+ >+ /** >+ * Notifies all registered property listeners of an enablement change. >+ * >+ * @param actionId >+ * the id indicating what action's enablement has changed. >+ */ >+ protected void fireEnablementChanged(final String actionId) { >+ Object[] array = propertyChangeListeners.getListeners(); >+ for (int i = 0; i < array.length; i++) { >+ final IPropertyChangeListener l = (IPropertyChangeListener) array[i]; >+ SafeRunnable.run(new SafeRunnable() { >+ public void run() { >+ l.propertyChange(new PropertyChangeEvent(this, actionId, >+ null, null)); >+ } >+ }); >+ } >+ } >+ >+ /** >+ * Sets the style bits for this cell editor. >+ * >+ * @param style >+ * the SWT style bits for this cell editor >+ * @since 2.1 >+ */ >+ public void setStyle(int style) { >+ this.style = style; >+ } >+ >+ /** >+ * Returns the style bits for this cell editor. >+ * >+ * @return the style for this cell editor >+ * @since 2.1 >+ */ >+ public int getStyle() { >+ return style; >+ } >+ >+ /** >+ * Returns the control used to implement this cell editor. >+ * >+ * @return the control, or <code>null</code> if this cell editor has no >+ * control >+ */ >+ public Control getControl() { >+ return control; >+ } >+ >+ /** >+ * Returns the current error message for this cell editor. >+ * >+ * @return the error message if the cell editor is in an invalid state, and >+ * <code>null</code> if the cell editor is valid >+ */ >+ public String getErrorMessage() { >+ return errorMessage; >+ } >+ >+ /** >+ * Returns a layout data object for this cell editor. This is called each >+ * time the cell editor is activated and controls the layout of the SWT >+ * table editor. >+ * <p> >+ * The default implementation of this method sets the minimum width to the >+ * control's preferred width. Subclasses may extend or reimplement. >+ * </p> >+ * >+ * @return the layout data object >+ */ >+ public LayoutData getLayoutData() { >+ LayoutData result = new LayoutData(); >+ Control control = getControl(); >+ if (control != null) { >+ result.minimumWidth = control.computeSize(SWT.DEFAULT, SWT.DEFAULT, >+ true).x; >+ } >+ return result; >+ } >+ >+ /** >+ * Returns the input validator for this cell editor. >+ * >+ * @return the input validator, or <code>null</code> if none >+ */ >+ public ICellEditorValidator getValidator() { >+ return validator; >+ } >+ >+ /** >+ * Returns this cell editor's value provided that it has a valid one. >+ * >+ * @return the value of this cell editor, or <code>null</code> if the cell >+ * editor does not contain a valid value >+ */ >+ public final Object getValue() { >+ if (!valid) { > return null; > } > >- return doGetValue(); >- } >+ return doGetValue(); >+ } > >- /** >- * Returns whether this cell editor is activated. >- * >- * @return <code>true</code> if this cell editor's control is >- * currently activated, and <code>false</code> if not activated >- */ >- public boolean isActivated() { >- // Use the state of the visible style bit (getVisible()) rather than the >- // window's actual visibility (isVisible()) to get correct handling when >- // an ancestor control goes invisible, see bug 85331. >- return control != null && control.getVisible(); >- } >- >- /** >- * Returns <code>true</code> if this cell editor is >- * able to perform the copy action. >- * <p> >- * This default implementation always returns >- * <code>false</code>. >- * </p> >- * <p> >- * Subclasses may override >- * </p> >- * @return <code>true</code> if copy is possible, >- * <code>false</code> otherwise >- */ >- public boolean isCopyEnabled() { >- return false; >- } >- >- /** >- * Returns whether the given value is valid for this cell editor. >- * This cell editor's validator (if any) makes the actual determination. >- * @param value the value to check for >- * >- * @return <code>true</code> if the value is valid, and <code>false</code> >- * if invalid >- */ >- protected boolean isCorrect(Object value) { >- errorMessage = null; >- if (validator == null) { >+ /** >+ * Returns whether this cell editor is activated. >+ * >+ * @return <code>true</code> if this cell editor's control is currently >+ * activated, and <code>false</code> if not activated >+ */ >+ public boolean isActivated() { >+ // Use the state of the visible style bit (getVisible()) rather than the >+ // window's actual visibility (isVisible()) to get correct handling when >+ // an ancestor control goes invisible, see bug 85331. >+ return control != null && control.getVisible(); >+ } >+ >+ /** >+ * Returns <code>true</code> if this cell editor is able to perform the >+ * copy action. >+ * <p> >+ * This default implementation always returns <code>false</code>. >+ * </p> >+ * <p> >+ * Subclasses may override >+ * </p> >+ * >+ * @return <code>true</code> if copy is possible, <code>false</code> >+ * otherwise >+ */ >+ public boolean isCopyEnabled() { >+ return false; >+ } >+ >+ /** >+ * Returns whether the given value is valid for this cell editor. This cell >+ * editor's validator (if any) makes the actual determination. >+ * >+ * @param value >+ * the value to check for >+ * >+ * @return <code>true</code> if the value is valid, and <code>false</code> >+ * if invalid >+ */ >+ protected boolean isCorrect(Object value) { >+ errorMessage = null; >+ if (validator == null) { > return true; > } > >- errorMessage = validator.isValid(value); >- return (errorMessage == null || errorMessage.equals(""));//$NON-NLS-1$ >- } >- >- /** >- * Returns <code>true</code> if this cell editor is >- * able to perform the cut action. >- * <p> >- * This default implementation always returns >- * <code>false</code>. >- * </p> >- * <p> >- * Subclasses may override >- * </p> >- * @return <code>true</code> if cut is possible, >- * <code>false</code> otherwise >- */ >- public boolean isCutEnabled() { >- return false; >- } >- >- /** >- * Returns <code>true</code> if this cell editor is >- * able to perform the delete action. >- * <p> >- * This default implementation always returns >- * <code>false</code>. >- * </p> >- * <p> >- * Subclasses may override >- * </p> >- * @return <code>true</code> if delete is possible, >- * <code>false</code> otherwise >- */ >- public boolean isDeleteEnabled() { >- return false; >- } >- >- /** >- * Returns whether the value of this cell editor has changed since the >- * last call to <code>setValue</code>. >- * >- * @return <code>true</code> if the value has changed, and <code>false</code> >- * if unchanged >- */ >- public boolean isDirty() { >- return dirty; >- } >- >- /** >- * Marks this cell editor as dirty. >- * @since 2.1 >- */ >- protected void markDirty() { >- dirty = true; >- } >- >- /** >- * Returns <code>true</code> if this cell editor is >- * able to perform the find action. >- * <p> >- * This default implementation always returns >- * <code>false</code>. >- * </p> >- * <p> >- * Subclasses may override >- * </p> >- * @return <code>true</code> if find is possible, >- * <code>false</code> otherwise >- */ >- public boolean isFindEnabled() { >- return false; >- } >- >- /** >- * Returns <code>true</code> if this cell editor is >- * able to perform the paste action. >- * <p> >- * This default implementation always returns >- * <code>false</code>. >- * </p> >- * <p> >- * Subclasses may override >- * </p> >- * @return <code>true</code> if paste is possible, >- * <code>false</code> otherwise >- */ >- public boolean isPasteEnabled() { >- return false; >- } >- >- /** >- * Returns <code>true</code> if this cell editor is >- * able to perform the redo action. >- * <p> >- * This default implementation always returns >- * <code>false</code>. >- * </p> >- * <p> >- * Subclasses may override >- * </p> >- * @return <code>true</code> if redo is possible, >- * <code>false</code> otherwise >- */ >- public boolean isRedoEnabled() { >- return false; >- } >- >- /** >- * Returns <code>true</code> if this cell editor is >- * able to perform the select all action. >- * <p> >- * This default implementation always returns >- * <code>false</code>. >- * </p> >- * <p> >- * Subclasses may override >- * </p> >- * @return <code>true</code> if select all is possible, >- * <code>false</code> otherwise >- */ >- public boolean isSelectAllEnabled() { >- return false; >- } >- >- /** >- * Returns <code>true</code> if this cell editor is >- * able to perform the undo action. >- * <p> >- * This default implementation always returns >- * <code>false</code>. >- * </p> >- * <p> >- * Subclasses may override >- * </p> >- * @return <code>true</code> if undo is possible, >- * <code>false</code> otherwise >- */ >- public boolean isUndoEnabled() { >- return false; >- } >- >- /** >- * Returns whether this cell editor has a valid value. >- * The default value is false. >- * >- * @return <code>true</code> if the value is valid, and <code>false</code> >- * if invalid >- * >- * @see #setValueValid(boolean) >- */ >- public boolean isValueValid() { >- return valid; >- } >- >- /** >- * Processes a key release event that occurred in this cell editor. >- * <p> >- * The default implementation of this framework method cancels editing >- * when the ESC key is pressed. When the RETURN key is pressed the current >- * value is applied and the cell editor deactivates. >- * Subclasses should call this method at appropriate times. >- * Subclasses may also extend or reimplement. >- * </p> >- * >- * @param keyEvent the key event >- */ >- protected void keyReleaseOccured(KeyEvent keyEvent) { >- if (keyEvent.character == '\u001b') { // Escape character >- fireCancelEditor(); >- } else if (keyEvent.character == '\r') { // Return key >- fireApplyEditorValue(); >- deactivate(); >- } >- } >- >- /** >- * Processes a focus lost event that occurred in this cell editor. >- * <p> >- * The default implementation of this framework method applies the current >- * value and deactivates the cell editor. >- * Subclasses should call this method at appropriate times. >- * Subclasses may also extend or reimplement. >- * </p> >- */ >- protected void focusLost() { >- if (isActivated()) { >- fireApplyEditorValue(); >- deactivate(); >- } >- } >- >- /** >- * Performs the copy action. >- * This default implementation does nothing. >- * <p> >- * Subclasses may override >- * </p> >- */ >- public void performCopy() { >- } >- >- /** >- * Performs the cut action. >- * This default implementation does nothing. >- * <p> >- * Subclasses may override >- * </p> >- */ >- public void performCut() { >- } >- >- /** >- * Performs the delete action. >- * This default implementation does nothing. >- * <p> >- * Subclasses may override >- * </p> >- */ >- public void performDelete() { >- } >- >- /** >- * Performs the find action. >- * This default implementation does nothing. >- * <p> >- * Subclasses may override >- * </p> >- */ >- public void performFind() { >- } >- >- /** >- * Performs the paste action. >- * This default implementation does nothing. >- * <p> >- * Subclasses may override >- * </p> >- */ >- public void performPaste() { >- } >- >- /** >- * Performs the redo action. >- * This default implementation does nothing. >- * <p> >- * Subclasses may override >- * </p> >- */ >- public void performRedo() { >- } >- >- /** >- * Performs the select all action. >- * This default implementation does nothing. >- * <p> >- * Subclasses may override >- * </p> >- */ >- public void performSelectAll() { >- } >- >- /** >- * Performs the undo action. >- * This default implementation does nothing. >- * <p> >- * Subclasses may override >- * </p> >- */ >- public void performUndo() { >- } >- >- /** >- * Removes the given listener from this cell editor. >- * Has no affect if an identical listener is not registered. >- * >- * @param listener a cell editor listener >- */ >- public void removeListener(ICellEditorListener listener) { >- listeners.remove(listener); >- } >- >- /** >- * Removes the given property change listener from this cell editor. >- * Has no affect if an identical property change listener is not >- * registered. >- * >- * @param listener a property change listener >- */ >- public void removePropertyChangeListener(IPropertyChangeListener listener) { >- propertyChangeListeners.remove(listener); >- } >- >- /** >- * Sets or clears the current error message for this cell editor. >- * <p> >- * No formatting is done here, the message to be set is expected to be fully formatted >- * before being passed in. >- * </p> >- * @param message the error message, or <code>null</code> to clear >- */ >- protected void setErrorMessage(String message) { >- errorMessage = message; >- } >- >- /** >- * Sets the focus to the cell editor's control. >- */ >- public void setFocus() { >- doSetFocus(); >- } >- >- /** >- * Sets the input validator for this cell editor. >- * >- * @param validator the input validator, or <code>null</code> if none >- */ >- public void setValidator(ICellEditorValidator validator) { >- this.validator = validator; >- } >- >- /** >- * Sets this cell editor's value. >- * >- * @param value the value of this cell editor >- */ >- public final void setValue(Object value) { >- valid = isCorrect(value); >- dirty = false; >- doSetValue(value); >- } >- >- /** >- * Sets the valid state of this cell editor. >- * The default value is false. >- * Subclasses should call this method on construction. >- * >- * @param valid <code>true</code> if the current valie is valid, >- * and <code>false</code> if invalid >- * >- * @see #isValueValid >- */ >- protected void setValueValid(boolean valid) { >- this.valid = valid; >- } >- >- /** >- * The value has changed. >- * Updates the valid state flag, marks this cell editor as dirty, >- * and notifies all registered cell editor listeners of a value change. >- * >- * @param oldValidState the valid state before the end user changed the value >- * @param newValidState the current valid state >- * @see ICellEditorListener#editorValueChanged >- */ >- protected void valueChanged(boolean oldValidState, boolean newValidState) { >- valid = newValidState; >- dirty = true; >- fireEditorValueChanged(oldValidState, newValidState); >- } >+ errorMessage = validator.isValid(value); >+ return (errorMessage == null || errorMessage.equals(""));//$NON-NLS-1$ >+ } >+ >+ /** >+ * Returns <code>true</code> if this cell editor is able to perform the >+ * cut action. >+ * <p> >+ * This default implementation always returns <code>false</code>. >+ * </p> >+ * <p> >+ * Subclasses may override >+ * </p> >+ * >+ * @return <code>true</code> if cut is possible, <code>false</code> >+ * otherwise >+ */ >+ public boolean isCutEnabled() { >+ return false; >+ } >+ >+ /** >+ * Returns <code>true</code> if this cell editor is able to perform the >+ * delete action. >+ * <p> >+ * This default implementation always returns <code>false</code>. >+ * </p> >+ * <p> >+ * Subclasses may override >+ * </p> >+ * >+ * @return <code>true</code> if delete is possible, <code>false</code> >+ * otherwise >+ */ >+ public boolean isDeleteEnabled() { >+ return false; >+ } >+ >+ /** >+ * Returns whether the value of this cell editor has changed since the last >+ * call to <code>setValue</code>. >+ * >+ * @return <code>true</code> if the value has changed, and >+ * <code>false</code> if unchanged >+ */ >+ public boolean isDirty() { >+ return dirty; >+ } >+ >+ /** >+ * Marks this cell editor as dirty. >+ * >+ * @since 2.1 >+ */ >+ protected void markDirty() { >+ dirty = true; >+ } >+ >+ /** >+ * Returns <code>true</code> if this cell editor is able to perform the >+ * find action. >+ * <p> >+ * This default implementation always returns <code>false</code>. >+ * </p> >+ * <p> >+ * Subclasses may override >+ * </p> >+ * >+ * @return <code>true</code> if find is possible, <code>false</code> >+ * otherwise >+ */ >+ public boolean isFindEnabled() { >+ return false; >+ } >+ >+ /** >+ * Returns <code>true</code> if this cell editor is able to perform the >+ * paste action. >+ * <p> >+ * This default implementation always returns <code>false</code>. >+ * </p> >+ * <p> >+ * Subclasses may override >+ * </p> >+ * >+ * @return <code>true</code> if paste is possible, <code>false</code> >+ * otherwise >+ */ >+ public boolean isPasteEnabled() { >+ return false; >+ } >+ >+ /** >+ * Returns <code>true</code> if this cell editor is able to perform the >+ * redo action. >+ * <p> >+ * This default implementation always returns <code>false</code>. >+ * </p> >+ * <p> >+ * Subclasses may override >+ * </p> >+ * >+ * @return <code>true</code> if redo is possible, <code>false</code> >+ * otherwise >+ */ >+ public boolean isRedoEnabled() { >+ return false; >+ } >+ >+ /** >+ * Returns <code>true</code> if this cell editor is able to perform the >+ * select all action. >+ * <p> >+ * This default implementation always returns <code>false</code>. >+ * </p> >+ * <p> >+ * Subclasses may override >+ * </p> >+ * >+ * @return <code>true</code> if select all is possible, <code>false</code> >+ * otherwise >+ */ >+ public boolean isSelectAllEnabled() { >+ return false; >+ } >+ >+ /** >+ * Returns <code>true</code> if this cell editor is able to perform the >+ * undo action. >+ * <p> >+ * This default implementation always returns <code>false</code>. >+ * </p> >+ * <p> >+ * Subclasses may override >+ * </p> >+ * >+ * @return <code>true</code> if undo is possible, <code>false</code> >+ * otherwise >+ */ >+ public boolean isUndoEnabled() { >+ return false; >+ } >+ >+ /** >+ * Returns whether this cell editor has a valid value. The default value is >+ * false. >+ * >+ * @return <code>true</code> if the value is valid, and <code>false</code> >+ * if invalid >+ * >+ * @see #setValueValid(boolean) >+ */ >+ public boolean isValueValid() { >+ return valid; >+ } >+ >+ /** >+ * Processes a key release event that occurred in this cell editor. >+ * <p> >+ * The default implementation of this framework method cancels editing when >+ * the ESC key is pressed. When the RETURN key is pressed the current value >+ * is applied and the cell editor deactivates. Subclasses should call this >+ * method at appropriate times. Subclasses may also extend or reimplement. >+ * </p> >+ * >+ * @param keyEvent >+ * the key event >+ */ >+ protected void keyReleaseOccured(KeyEvent keyEvent) { >+ if (keyEvent.character == '\u001b') { // Escape character >+ fireCancelEditor(); >+ } else if (keyEvent.character == '\r') { // Return key >+ fireApplyEditorValue(); >+ deactivate(); >+ } >+ } >+ >+ /** >+ * Processes a focus lost event that occurred in this cell editor. >+ * <p> >+ * The default implementation of this framework method applies the current >+ * value and deactivates the cell editor. Subclasses should call this method >+ * at appropriate times. Subclasses may also extend or reimplement. >+ * </p> >+ */ >+ protected void focusLost() { >+ if (isActivated()) { >+ fireApplyEditorValue(); >+ deactivate(); >+ } >+ } >+ >+ /** >+ * Performs the copy action. This default implementation does nothing. >+ * <p> >+ * Subclasses may override >+ * </p> >+ */ >+ public void performCopy() { >+ } >+ >+ /** >+ * Performs the cut action. This default implementation does nothing. >+ * <p> >+ * Subclasses may override >+ * </p> >+ */ >+ public void performCut() { >+ } >+ >+ /** >+ * Performs the delete action. This default implementation does nothing. >+ * <p> >+ * Subclasses may override >+ * </p> >+ */ >+ public void performDelete() { >+ } >+ >+ /** >+ * Performs the find action. This default implementation does nothing. >+ * <p> >+ * Subclasses may override >+ * </p> >+ */ >+ public void performFind() { >+ } >+ >+ /** >+ * Performs the paste action. This default implementation does nothing. >+ * <p> >+ * Subclasses may override >+ * </p> >+ */ >+ public void performPaste() { >+ } >+ >+ /** >+ * Performs the redo action. This default implementation does nothing. >+ * <p> >+ * Subclasses may override >+ * </p> >+ */ >+ public void performRedo() { >+ } >+ >+ /** >+ * Performs the select all action. This default implementation does nothing. >+ * <p> >+ * Subclasses may override >+ * </p> >+ */ >+ public void performSelectAll() { >+ } >+ >+ /** >+ * Performs the undo action. This default implementation does nothing. >+ * <p> >+ * Subclasses may override >+ * </p> >+ */ >+ public void performUndo() { >+ } >+ >+ /** >+ * Removes the given listener from this cell editor. Has no affect if an >+ * identical listener is not registered. >+ * >+ * @param listener >+ * a cell editor listener >+ */ >+ public void removeListener(ICellEditorListener listener) { >+ listeners.remove(listener); >+ } >+ >+ /** >+ * Removes the given property change listener from this cell editor. Has no >+ * affect if an identical property change listener is not registered. >+ * >+ * @param listener >+ * a property change listener >+ */ >+ public void removePropertyChangeListener(IPropertyChangeListener listener) { >+ propertyChangeListeners.remove(listener); >+ } >+ >+ /** >+ * Sets or clears the current error message for this cell editor. >+ * <p> >+ * No formatting is done here, the message to be set is expected to be fully >+ * formatted before being passed in. >+ * </p> >+ * >+ * @param message >+ * the error message, or <code>null</code> to clear >+ */ >+ protected void setErrorMessage(String message) { >+ errorMessage = message; >+ } >+ >+ /** >+ * Sets the focus to the cell editor's control. >+ */ >+ public void setFocus() { >+ doSetFocus(); >+ } >+ >+ /** >+ * Sets the input validator for this cell editor. >+ * >+ * @param validator >+ * the input validator, or <code>null</code> if none >+ */ >+ public void setValidator(ICellEditorValidator validator) { >+ this.validator = validator; >+ } >+ >+ /** >+ * Sets this cell editor's value. >+ * >+ * @param value >+ * the value of this cell editor >+ */ >+ public final void setValue(Object value) { >+ valid = isCorrect(value); >+ dirty = false; >+ doSetValue(value); >+ } >+ >+ /** >+ * Sets the valid state of this cell editor. The default value is false. >+ * Subclasses should call this method on construction. >+ * >+ * @param valid >+ * <code>true</code> if the current valie is valid, and >+ * <code>false</code> if invalid >+ * >+ * @see #isValueValid >+ */ >+ protected void setValueValid(boolean valid) { >+ this.valid = valid; >+ } >+ >+ /** >+ * The value has changed. Updates the valid state flag, marks this cell >+ * editor as dirty, and notifies all registered cell editor listeners of a >+ * value change. >+ * >+ * @param oldValidState >+ * the valid state before the end user changed the value >+ * @param newValidState >+ * the current valid state >+ * @see ICellEditorListener#editorValueChanged >+ */ >+ protected void valueChanged(boolean oldValidState, boolean newValidState) { >+ valid = newValidState; >+ dirty = true; >+ fireEditorValueChanged(oldValidState, newValidState); >+ } > } >Index: src/org/eclipse/jface/viewers/AbstractViewerEditor.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jface/src/org/eclipse/jface/viewers/AbstractViewerEditor.java,v >retrieving revision 1.3 >diff -u -r1.3 AbstractViewerEditor.java >--- src/org/eclipse/jface/viewers/AbstractViewerEditor.java 1 Dec 2006 16:30:31 -0000 1.3 >+++ src/org/eclipse/jface/viewers/AbstractViewerEditor.java 2 Feb 2007 19:23:28 -0000 >@@ -14,6 +14,8 @@ > > package org.eclipse.jface.viewers; > >+ >+import org.eclipse.core.runtime.ListenerList; > import org.eclipse.swt.events.FocusAdapter; > import org.eclipse.swt.events.FocusEvent; > import org.eclipse.swt.events.FocusListener; >@@ -22,7 +24,6 @@ > import org.eclipse.swt.events.MouseListener; > import org.eclipse.swt.events.TraverseEvent; > import org.eclipse.swt.events.TraverseListener; >-import org.eclipse.swt.graphics.Rectangle; > import org.eclipse.swt.widgets.Control; > import org.eclipse.swt.widgets.Display; > import org.eclipse.swt.widgets.Item; >@@ -46,22 +47,34 @@ > > private String[] columnProperties; > >- private int columnNumber; >- > private ICellEditorListener cellEditorListener; > > private FocusListener focusListener; > > private MouseListener mouseListener; > >- private int doubleClickExpirationTime; >- > private ColumnViewer viewer; > >- private Item item; >- > private TraverseListener tabeditingListener; > >+ private int activationTime; >+ >+ private ViewerCell cell; >+ >+ private EditorActivationEvent activationEvent; >+ >+ private ListenerList editorActivationListener; >+ >+ private static EditorActivationStrategy defaultStrategy = new EditorActivationStrategy() { >+ protected boolean isEditorActivationEvent(EditorActivationEvent event) { >+ return event.eventType == EditorActivationEvent.MOUSE_CLICK_SELECTION >+ || event.eventType == EditorActivationEvent.PROGRAMATIC >+ || event.eventType == EditorActivationEvent.TRAVERSAL; >+ } >+ }; >+ >+ private EditorActivationStrategy editorActivationStrategy = defaultStrategy; >+ > /** > * Create a new editor implementation for the viewer > * >@@ -92,13 +105,20 @@ > > void activateCellEditor() { > >- ViewerColumn part = viewer.getViewerColumn(columnNumber); >- Object element = item.getData(); >+ ViewerColumn part = viewer.getViewerColumn(cell.getColumnIndex()); >+ Object element = cell.getElement(); > > if (part != null && part.getEditingSupport() != null > && part.getEditingSupport().canEdit(element)) { > cellEditor = part.getEditingSupport().getCellEditor(element); > if (cellEditor != null) { >+ if( editorActivationListener != null && ! editorActivationListener.isEmpty() ) { >+ Object[] ls = editorActivationListener.getListeners(); >+ for( int i = 0; i < ls.length; i++ ) { >+ ((AbstractViewerEditorActivationListener)ls[i]).beforeEditorActivated(activationEvent); >+ } >+ } >+ > cellEditor.addListener(cellEditorListener); > Object value = part.getEditingSupport().getValue(element); > cellEditor.setValue(value); >@@ -108,12 +128,12 @@ > // so must get control first, but must still call activate() > // even if there is no control. > final Control control = cellEditor.getControl(); >- cellEditor.activate(); >+ cellEditor.activate(activationEvent); > if (control == null) { > return; > } > setLayoutData(cellEditor.getLayoutData()); >- setEditor(control, item, columnNumber); >+ setEditor(control, cell.getItem(), cell.getColumnIndex()); > cellEditor.setFocus(); > if (focusListener == null) { > focusListener = new FocusAdapter() { >@@ -128,7 +148,7 @@ > public void mouseDown(MouseEvent e) { > // time wrap? > // check for expiration of doubleClickTime >- if (e.time <= doubleClickExpirationTime) { >+ if (e.time <= activationTime) { > control.removeMouseListener(mouseListener); > cancelEditing(); > handleDoubleClickEvent(); >@@ -143,53 +163,26 @@ > tabeditingListener = new TraverseListener() { > > public void keyTraversed(TraverseEvent e) { >- ViewerColumn col = viewer.getViewerColumn(columnNumber); >+ ViewerColumn col = viewer.getViewerColumn(cell.getColumnIndex()); > if ( col != null && col.getEditingSupport().isTabingSupported() ) { > col.getEditingSupport().processTraversEvent( >- columnNumber, >- viewer.getViewerRowFromItem(item), e); >+ cell.getColumnIndex(), >+ viewer.getViewerRowFromItem(cell.getItem()), e); > } > } > }; > } > > control.addTraverseListener(tabeditingListener); >- >- } >- } >- } >- >- /** >- * Activate a cell editor for the given mouse position. >- */ >- private void activateCellEditor(MouseEvent event) { >- if (item == null || item.isDisposed()) { >- // item no longer exists >- return; >- } >- int columnToEdit; >- ViewerRow row = viewer.getViewerRowFromItem(item); >- int columns = row.getColumnCount(); >- if (columns == 0) { >- // If no TableColumn, Table acts as if it has a single column >- // which takes the whole width. >- columnToEdit = 0; >- } else { >- columnToEdit = -1; >- for (int i = 0; i < columns; i++) { >- Rectangle bounds = row.getBounds(i); >- if (bounds.contains(event.x, event.y)) { >- columnToEdit = i; >- break; >+ >+ if( editorActivationListener != null && ! editorActivationListener.isEmpty() ) { >+ Object[] ls = editorActivationListener.getListeners(); >+ for( int i = 0; i < ls.length; i++ ) { >+ ((AbstractViewerEditorActivationListener)ls[i]).afterEditorActivated(activationEvent); >+ } > } > } >- if (columnToEdit == -1) { >- return; >- } > } >- >- columnNumber = columnToEdit; >- activateCellEditor(); > } > > /** >@@ -203,8 +196,18 @@ > // in case save results in applyEditorValue being re-entered > // see 1GAHI8Z: ITPUI:ALL - How to code event notification when > // using cell editor ? >+ >+ EditorDeactivationEvent tmp = new EditorDeactivationEvent(cell); >+ if( editorActivationListener != null && ! editorActivationListener.isEmpty() ) { >+ Object[] ls = editorActivationListener.getListeners(); >+ for( int i = 0; i < ls.length; i++ ) { >+ ((AbstractViewerEditorActivationListener)ls[i]).beforeEditorDeactivated(tmp); >+ } >+ } >+ > this.cellEditor = null; >- Item t = this.item; >+ this.activationEvent = null; >+ Item t = this.cell.getItem(); > // don't null out table item -- same item is still selected > if (t != null && !t.isDisposed()) { > saveEditorValue(c, t); >@@ -227,6 +230,13 @@ > } > } > c.deactivate(); >+ >+ if( editorActivationListener != null && ! editorActivationListener.isEmpty() ) { >+ Object[] ls = editorActivationListener.getListeners(); >+ for( int i = 0; i < ls.length; i++ ) { >+ ((AbstractViewerEditorActivationListener)ls[i]).afterEditorDeactivated(tmp); >+ } >+ } > } > } > >@@ -235,6 +245,14 @@ > */ > void cancelEditing() { > if (cellEditor != null) { >+ EditorDeactivationEvent tmp = new EditorDeactivationEvent(cell); >+ if( editorActivationListener != null && ! editorActivationListener.isEmpty() ) { >+ Object[] ls = editorActivationListener.getListeners(); >+ for( int i = 0; i < ls.length; i++ ) { >+ ((AbstractViewerEditorActivationListener)ls[i]).beforeEditorDeactivated(tmp); >+ } >+ } >+ > setEditor(null, null, 0); > cellEditor.removeListener(cellEditorListener); > >@@ -256,70 +274,39 @@ > > CellEditor oldEditor = cellEditor; > cellEditor = null; >+ activationEvent=null; > oldEditor.deactivate(); >+ >+ if( editorActivationListener != null && ! editorActivationListener.isEmpty() ) { >+ Object[] ls = editorActivationListener.getListeners(); >+ for( int i = 0; i < ls.length; i++ ) { >+ ((AbstractViewerEditorActivationListener)ls[i]).afterEditorDeactivated(tmp); >+ } >+ } > } > } >- >+ > /** > * Enable the editor by mouse down > * > * @param event > */ >- void handleMouseDown(MouseEvent event) { >- if (event.button != 1) { >- return; >- } >- >- if (cellEditor != null) { >- applyEditorValue(); >- } >- >- // activate the cell editor immediately. If a second mouseDown >- // is received prior to the expiration of the doubleClick time then >- // the cell editor will be deactivated and a doubleClick event will >- // be processed. >- // >- doubleClickExpirationTime = event.time >- + Display.getCurrent().getDoubleClickTime(); >- >- Item[] items = getSelection(); >- // Do not edit if more than one row is selected. >- if (items.length != 1) { >- item = null; >- return; >- } >- item = items[0]; >- activateCellEditor(event); >- } >- >- /** >- * Start editing the given element. >- * >- * @param element >- * @param column >- */ >- void editElement(Object element, int column) { >- if (cellEditor != null) { >- applyEditorValue(); >- } >+ void handleEditorActivationEvent(EditorActivationEvent event) { >+ if( editorActivationStrategy.isEditorActivationEvent(event) ) { >+ if (cellEditor != null) { >+ applyEditorValue(); >+ } > >- setSelection(createSelection(element), true); >- Item[] selection = getSelection(); >- if (selection.length != 1) { >- return; >+ this.cell = (ViewerCell)event.getSource(); >+ activationEvent = event; >+ activationTime = event.time + Display.getCurrent().getDoubleClickTime(); >+ >+ activateCellEditor(); > } >- >- item = selection[0]; >- >- // Make sure selection is visible >- showSelection(); >- columnNumber = column; >- activateCellEditor(); >- > } > > private void saveEditorValue(CellEditor cellEditor, Item tableItem) { >- ViewerColumn part = viewer.getViewerColumn(columnNumber); >+ ViewerColumn part = viewer.getViewerColumn(cell.getColumnIndex()); > > if (part != null && part.getEditingSupport() != null) { > part.getEditingSupport().setValue(tableItem.getData(), >@@ -391,16 +378,30 @@ > return cellEditors; > } > >- void setSelection(StructuredSelection selection, boolean b) { >- viewer.setSelection(selection, b); >- } >- > void handleDoubleClickEvent() { > viewer.fireDoubleClick(new DoubleClickEvent(viewer, viewer > .getSelection())); > viewer.fireOpen(new OpenEvent(viewer, viewer.getSelection())); > } > >+ void addEditorActivationListener(AbstractViewerEditorActivationListener listener) { >+ if( editorActivationListener == null ) { >+ editorActivationListener = new ListenerList(); >+ } >+ editorActivationListener.add(listener); >+ } >+ >+ void removeEditorActivationListener(AbstractViewerEditorActivationListener listener) { >+ if( editorActivationListener != null ) { >+ editorActivationListener.remove(listener); >+ } >+ } >+ >+ void setEditorActivationStrategy( >+ EditorActivationStrategy editorActivationStrategy) { >+ this.editorActivationStrategy = editorActivationStrategy; >+ } >+ > /** > * Create a selection for this model element > * >@@ -429,14 +430,4 @@ > * the layout data used when editor is displayed > */ > protected abstract void setLayoutData(CellEditor.LayoutData layoutData); >- >- /** >- * Show up the current selection (scroll the selection into view) >- */ >- protected abstract void showSelection(); >- >- /** >- * @return the current selection >- */ >- protected abstract Item[] getSelection(); > } >Index: src/org/eclipse/jface/viewers/AbstractViewerEditorActivationListener.java >=================================================================== >RCS file: src/org/eclipse/jface/viewers/AbstractViewerEditorActivationListener.java >diff -N src/org/eclipse/jface/viewers/AbstractViewerEditorActivationListener.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/viewers/AbstractViewerEditorActivationListener.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,52 @@ >+/******************************************************************************* >+ * Copyright (c) 2007 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ ******************************************************************************/ >+ >+package org.eclipse.jface.viewers; >+ >+/** >+ * Parties interested in activation and deactivation of editors extend this >+ * class and implement any or all of the methods >+ * >+ * @since 3.3 >+ * >+ */ >+public abstract class AbstractViewerEditorActivationListener { >+ /** >+ * Called before an editor is activated >+ * >+ * @param event >+ * the event >+ */ >+ public abstract void beforeEditorActivated(EditorActivationEvent event); >+ >+ /** >+ * Called after an editor has been activated >+ * >+ * @param event the event >+ */ >+ public abstract void afterEditorActivated(EditorActivationEvent event); >+ >+ /** >+ * Called before an editor is deactivated >+ * >+ * @param event >+ * the event >+ */ >+ public abstract void beforeEditorDeactivated(EditorDeactivationEvent event); >+ >+ >+ /** >+ * Called after an editor is deactivated >+ * >+ * @param event the event >+ */ >+ public abstract void afterEditorDeactivated(EditorDeactivationEvent event); >+} >Index: src/org/eclipse/jface/viewers/EditorDeactivationEvent.java >=================================================================== >RCS file: src/org/eclipse/jface/viewers/EditorDeactivationEvent.java >diff -N src/org/eclipse/jface/viewers/EditorDeactivationEvent.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/viewers/EditorDeactivationEvent.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,36 @@ >+/******************************************************************************* >+ * Copyright (c) 2007 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ ******************************************************************************/ >+ >+package org.eclipse.jface.viewers; >+ >+import java.util.EventObject; >+ >+/** >+ * This event is fired when an editor deactivated >+ * >+ * @since 3.3 >+ * >+ */ >+public class EditorDeactivationEvent extends EventObject { >+ >+ /** >+ * >+ */ >+ private static final long serialVersionUID = 1L; >+ >+ /** >+ * @param source >+ */ >+ public EditorDeactivationEvent(Object source) { >+ super(source); >+ } >+ >+} >Index: src/org/eclipse/jface/viewers/EditorActivationEvent.java >=================================================================== >RCS file: src/org/eclipse/jface/viewers/EditorActivationEvent.java >diff -N src/org/eclipse/jface/viewers/EditorActivationEvent.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/viewers/EditorActivationEvent.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,159 @@ >+/******************************************************************************* >+ * Copyright (c) 2007 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ ******************************************************************************/ >+ >+package org.eclipse.jface.viewers; >+ >+import java.util.EventObject; >+ >+import org.eclipse.swt.events.KeyEvent; >+import org.eclipse.swt.events.MouseEvent; >+import org.eclipse.swt.events.TraverseEvent; >+ >+/** >+ * This event is passed on when a cell-editor is going to be activated >+ * >+ * @since 3.3 >+ * >+ */ >+public class EditorActivationEvent extends EventObject { >+ /** >+ * >+ */ >+ private static final long serialVersionUID = 1L; >+ >+ /** >+ * if a key is pressed on a selected cell >+ */ >+ public static final int KEY_PRESSED = 1; >+ >+ /** >+ * if a cell is selected using a single click of the mouse >+ */ >+ public static final int MOUSE_CLICK_SELECTION = 2; >+ >+ /** >+ * if a cell is selected using double clicking of the mouse >+ */ >+ public static final int MOUSE_DOUBLE_CLICK_SELECTION = 3; >+ >+ /** >+ * if a cell is activated using code like e.g >+ * {@link ColumnViewer#editElement(Object, int)} >+ */ >+ public static final int PROGRAMATIC = 4; >+ >+ /** >+ * is a cell is activated by traversing >+ */ >+ public static final int TRAVERSAL = 5; >+ >+ /** >+ * the original event triggered >+ */ >+ public EventObject sourceEvent; >+ >+ /** >+ * The time the event is triggered >+ */ >+ public int time; >+ >+ /** >+ * The event type triggered: >+ * <ul> >+ * <li>{@link #KEY_PRESSED} if a key is pressed on a selected cell</li> >+ * <li>{@link #MOUSE_CLICK_SELECTION} if a cell is selected using a single >+ * click of the mouse</li> >+ * <li>{@link #MOUSE_DOUBLE_CLICK_SELECTION} if a cell is selected using >+ * double clicking of the mouse</li> >+ * </ul> >+ */ >+ public int eventType; >+ >+ /** >+ * <b>Only set for {@link #KEY_PRESSED}</b> >+ */ >+ public int keyCode; >+ >+ /** >+ * <b>Only set for {@link #KEY_PRESSED}</b> >+ */ >+ public char character; >+ >+ /** >+ * The statemask >+ */ >+ public int stateMask; >+ >+ /** >+ * This constructor can be used when no event exists. The type set is >+ * {@link #PROGRAMATIC} >+ * >+ * @param cell >+ * the cell >+ */ >+ public EditorActivationEvent(ViewerCell cell) { >+ super(cell); >+ eventType = PROGRAMATIC; >+ } >+ >+ /** >+ * This constructor is used for all types of mouse events. Currently the >+ * type is can be {@link #MOUSE_CLICK_SELECTION} and >+ * {@link #MOUSE_DOUBLE_CLICK_SELECTION} >+ * >+ * @param cell >+ * the cell source of the event >+ * @param event >+ * the event >+ */ >+ public EditorActivationEvent(ViewerCell cell, MouseEvent event) { >+ super(cell); >+ >+ if (event.count >= 2) { >+ eventType = MOUSE_DOUBLE_CLICK_SELECTION; >+ } else { >+ eventType = MOUSE_CLICK_SELECTION; >+ } >+ >+ this.sourceEvent = event; >+ this.time = event.time; >+ } >+ >+ /** >+ * @param cell >+ * the cell source of the event >+ * @param event >+ * the event >+ */ >+ public EditorActivationEvent(ViewerCell cell, KeyEvent event) { >+ super(cell); >+ this.eventType = KEY_PRESSED; >+ this.sourceEvent = event; >+ this.time = 0; >+ this.keyCode = event.keyCode; >+ this.character = event.character; >+ this.stateMask = event.stateMask; >+ } >+ >+ /** >+ * This constructur is used to mark the activation triggered by a traversal >+ * >+ * @param cell >+ * the cell source of the event >+ * @param event >+ * the event >+ */ >+ public EditorActivationEvent(ViewerCell cell, TraverseEvent event) { >+ super(cell); >+ this.eventType = TRAVERSAL; >+ this.sourceEvent = event; >+ } >+} >Index: src/org/eclipse/jface/viewers/EditorActivationStrategy.java >=================================================================== >RCS file: src/org/eclipse/jface/viewers/EditorActivationStrategy.java >diff -N src/org/eclipse/jface/viewers/EditorActivationStrategy.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/viewers/EditorActivationStrategy.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,26 @@ >+/******************************************************************************* >+ * Copyright (c) 2006 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ ******************************************************************************/ >+ >+package org.eclipse.jface.viewers; >+ >+/** >+ * This class is responsible to determin if a cell selection event is triggers >+ * an editor activation >+ * >+ * @since 3.3 >+ */ >+public abstract class EditorActivationStrategy { >+ /** >+ * @param event >+ * @return bla bl >+ */ >+ protected abstract boolean isEditorActivationEvent(EditorActivationEvent event); >+} >#P org.eclipse.swt.nebula.nebface >Index: META-INF/MANIFEST.MF >=================================================================== >RCS file: /cvsroot/technology/org.eclipse.swt.nebula/org.eclipse.swt.nebula.nebface/META-INF/MANIFEST.MF,v >retrieving revision 1.5 >diff -u -r1.5 MANIFEST.MF >--- META-INF/MANIFEST.MF 12 Jan 2007 03:49:24 -0000 1.5 >+++ META-INF/MANIFEST.MF 2 Feb 2007 19:23:31 -0000 >@@ -4,7 +4,7 @@ > Bundle-SymbolicName: org.eclipse.swt.nebula.nebface > Bundle-Version: 1.0.0 > Bundle-Localization: plugin >-Require-Bundle: org.eclipse.jface, >+Require-Bundle: org.eclipse.jface;visibility:=reexport, > org.eclipse.swt.nebula;visibility:=reexport, > org.eclipse.equinox.common;visibility:=reexport > Bundle-RequiredExecutionEnvironment: J2SE-1.4 >Index: src/org/eclipse/swt/nebula/nebface/viewers/CheckEditingSupport.java >=================================================================== >RCS file: /cvsroot/technology/org.eclipse.swt.nebula/org.eclipse.swt.nebula.nebface/src/org/eclipse/swt/nebula/nebface/viewers/CheckEditingSupport.java,v >retrieving revision 1.1 >diff -u -r1.1 CheckEditingSupport.java >--- src/org/eclipse/swt/nebula/nebface/viewers/CheckEditingSupport.java 20 Dec 2006 15:00:38 -0000 1.1 >+++ src/org/eclipse/swt/nebula/nebface/viewers/CheckEditingSupport.java 2 Feb 2007 19:23:31 -0000 >@@ -1,29 +1,56 @@ >+/******************************************************************************* >+ * Copyright (c) 2007 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * chris.gross@us.ibm.com - initial API and implementation >+ *******************************************************************************/ >+ > package org.eclipse.swt.nebula.nebface.viewers; > > import org.eclipse.jface.viewers.CellEditor; >+import org.eclipse.jface.viewers.ColumnViewer; > import org.eclipse.jface.viewers.EditingSupport; > >+/** >+ * . >+ * >+ * @author chris.gross@us.ibm.com >+ * @since 3.3 >+ */ > public abstract class CheckEditingSupport extends EditingSupport > { >+ /** >+ * Checkbox editing support. >+ * >+ * @param viewer column to add check box support for. >+ */ >+ public CheckEditingSupport(ColumnViewer viewer) >+ { >+ super(viewer); >+ } > >+ /** {@inheritDoc} */ > protected boolean canEdit(Object element) > { >- // TODO Auto-generated method stub > return false; > } > >+ /** {@inheritDoc} */ > protected CellEditor getCellEditor(Object element) > { >- // TODO Auto-generated method stub > return null; > } > >+ /** {@inheritDoc} */ > protected Object getValue(Object element) > { >- // TODO Auto-generated method stub > return null; > } > >- protected abstract void setValue(Object element, Object value); >- >+ /** {@inheritDoc} */ >+ public abstract void setValue(Object element, Object value); > } >Index: src/org/eclipse/swt/nebula/nebface/viewers/GridViewer.java >=================================================================== >RCS file: /cvsroot/technology/org.eclipse.swt.nebula/org.eclipse.swt.nebula.nebface/src/org/eclipse/swt/nebula/nebface/viewers/GridViewer.java,v >retrieving revision 1.1 >diff -u -r1.1 GridViewer.java >--- src/org/eclipse/swt/nebula/nebface/viewers/GridViewer.java 20 Dec 2006 15:00:38 -0000 1.1 >+++ src/org/eclipse/swt/nebula/nebface/viewers/GridViewer.java 2 Feb 2007 19:23:32 -0000 >@@ -1,22 +1,24 @@ > /******************************************************************************* >- * Copyright (c) 2006 Tom Schindl and others. >+ * Copyright (c) 2007 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at > * http://www.eclipse.org/legal/epl-v10.html > * > * Contributors: >- * Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation >- * IBM Corporation >- *******************************************************************************/ >+ * rmcamara@us.ibm.com - initial API and implementation >+ *******************************************************************************/ >+ > package org.eclipse.swt.nebula.nebface.viewers; > >+import org.eclipse.jface.viewers.AbstractTableViewer; > import org.eclipse.jface.viewers.AbstractViewerEditor; >-import org.eclipse.jface.viewers.BaseTableViewer; > import org.eclipse.jface.viewers.StructuredSelection; >+import org.eclipse.jface.viewers.ViewerCell; > import org.eclipse.jface.viewers.ViewerRow; > import org.eclipse.jface.viewers.CellEditor.LayoutData; > import org.eclipse.swt.SWT; >+import org.eclipse.swt.graphics.Image; > import org.eclipse.swt.graphics.Point; > import org.eclipse.swt.nebula.widgets.grid.Grid; > import org.eclipse.swt.nebula.widgets.grid.GridEditor; >@@ -24,187 +26,294 @@ > import org.eclipse.swt.widgets.Composite; > import org.eclipse.swt.widgets.Control; > import org.eclipse.swt.widgets.Item; >+import org.eclipse.swt.widgets.TableItem; > import org.eclipse.swt.widgets.Widget; > >-public class GridViewer extends BaseTableViewer { >- private static final int DEFAULT_STYLE = SWT.MULTI | SWT.H_SCROLL >- | SWT.V_SCROLL | SWT.BORDER; >- >- private Grid grid; >- >- private GridEditor gridEditor; >- >- public GridViewer(Composite parent) { >- this(parent, DEFAULT_STYLE); >- } >+/** >+ * A concrete viewer based on an Grid control. >+ * <p> >+ * This class is not intended to be subclassed outside the viewer framework. It >+ * is designed to be instantiated with a pre-existing Grid control and >+ * configured with a domain-specific content provider, label provider, element >+ * filter (optional), and element sorter (optional). >+ * <p> >+ * Content providers for grid viewers must not implement the >+ * {@code ITreeContentProvider} interface. >+ * <p> >+ * >+ * @author rmcamara@us.ibm.com >+ * @since >+ * @3.3 >+ */ >+public class GridViewer extends AbstractTableViewer >+{ >+ /** This viewer's grid control. */ >+ private Grid grid; >+ >+ /** Editor support for tables. */ >+ private GridEditor gridEditor; >+ >+ /** >+ * Creates a grid viewer on a newly-created grid control under the given >+ * parent. The grid control is created using the SWT style bits >+ * <code>MULTI, H_SCROLL, V_SCROLL,</code> and <code>BORDER</code>. The >+ * viewer has no input, no content provider, a default label provider, no >+ * sorter, and no filters. >+ * >+ * @param parent the parent control >+ */ >+ public GridViewer(Composite parent) >+ { >+ this(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER); >+ } > >- public GridViewer(Composite parent, int style) { >- this(new Grid(parent, style)); >- } >+ /** >+ * Creates a grid viewer on a newly-created grid control under the given >+ * parent. The grid control is created using the given SWT style bits. The >+ * viewer has no input, no content provider, a default label provider, no >+ * sorter, and no filters. >+ * >+ * @param parent the parent control >+ * @param style the SWT style bits used to create the grid. >+ */ >+ public GridViewer(Composite parent, int style) >+ { >+ this(new Grid(parent, style)); >+ } > >- public GridViewer(Grid gridControl) { >- super(); >- grid = gridControl; >- gridEditor = new GridEditor(gridControl); >+ /** >+ * Creates a grid viewer on the given grid control. The viewer has no >+ * input, no content provider, a default label provider, no sorter, and no >+ * filters. >+ * >+ * @param grid the grid control >+ */ >+ public GridViewer(Grid grid) >+ { >+ this.grid = grid; >+ gridEditor = new GridEditor(grid); > hookControl(grid); >- } >- >- public Grid getGrid() { >- return grid; >- } >- >- protected ViewerRow createNewRowPart(int style, int rowIndex) { >- GridItem item; >- >- if (rowIndex >= 0) { >- item = new GridItem(grid, style, rowIndex); >- } else { >- item = new GridItem(grid, style); >- } >- >- return getViewerRowFromItem(item); >- } >+ } >+ >+ /** >+ * Returns the underlying Grid Control. >+ * >+ * @return grid control. >+ */ >+ public Grid getGrid() >+ { >+ return grid; >+ } > >- protected ViewerRow getViewerRowFromItem(Widget item) { >- ViewerRow part = (ViewerRow) item.getData(ViewerRow.ROWPART_KEY); >+ /** {@inheritDoc} */ >+ protected ViewerRow internalCreateNewRowPart(int style, int rowIndex) >+ { >+ GridItem item; > >- if (part == null) { >- part = new GridViewerRow(((GridItem) item)); >+ if (rowIndex >= 0) >+ { >+ item = new GridItem(grid, style, rowIndex); >+ } >+ else >+ { >+ item = new GridItem(grid, style); > } > >- return part; >+ return getViewerRowFromItem(item); > } > >- protected AbstractViewerEditor createViewerEditor() { >- return new AbstractViewerEditor(this) { >- >- protected StructuredSelection createSelection(Object element) { >+ /** {@inheritDoc} */ >+ protected AbstractViewerEditor createViewerEditor() >+ { >+ return new AbstractViewerEditor(this) >+ { >+ protected StructuredSelection createSelection(Object element) >+ { > return new StructuredSelection(element); > } > >- protected Item[] getSelection() { >- return getGrid().getSelection(); >- } >- >- protected void setEditor(Control w, Item item, int fColumnNumber) { >+ protected void setEditor(Control w, Item item, int fColumnNumber) >+ { > gridEditor.setEditor(w, (GridItem) item, fColumnNumber); > } > >- protected void setLayoutData(LayoutData layoutData) { >+ protected void setLayoutData(LayoutData layoutData) >+ { > gridEditor.grabHorizontal = layoutData.grabHorizontal; > gridEditor.horizontalAlignment = layoutData.horizontalAlignment; > gridEditor.minimumWidth = layoutData.minimumWidth; > } >- >- protected void showSelection() { >- getGrid().showSelection(); >- } >- > }; >- } >- >- protected void internalClear(int index) { >- // TODO NEEDS IMP >- } >+ } > >- protected void internalClearAll() { >- // TODO NEEDS IMP >- } >+ /** {@inheritDoc} */ >+ protected void doClear(int index) >+ { >+ // TODO Fix when grid supports virtual >+ } > >- protected void internalDeselectAll() { >- grid.deselectAll(); >- } >+ /** {@inheritDoc} */ >+ protected void doClearAll() >+ { >+ //TODO Fix when grid supports virtual >+ } >+ >+ /** {@inheritDoc} */ >+ protected void doSetItemCount(int count) >+ { >+ //TODO Once grid supports virtual >+ } > >- protected Widget internalGetColumn(int index) { >- return grid.getColumn(index); >- } >+ /** {@inheritDoc} */ >+ protected void doDeselectAll() >+ { >+ grid.deselectAll(); >+ } > >- protected int internalGetColumnCount() { >- return grid.getColumnCount(); >- } >+ /** {@inheritDoc} */ >+ protected Widget doGetColumn(int index) >+ { >+ return grid.getColumn(index); >+ } > >- protected Widget[] internalGetColumns() { >- return grid.getColumns(); >- } >+ /** {@inheritDoc} */ >+ protected int doGetColumnCount() >+ { >+ return grid.getColumnCount(); >+ } > >- protected Item internalGetItem(int index) { >- return grid.getItem(index); >- } >+ /** {@inheritDoc} */ >+ protected Item doGetItem(int index) >+ { >+ return grid.getItem(index); >+ } > >- protected Item internalGetItem(Point point) { >- return grid.getItem(point); >- } >+ /** {@inheritDoc} */ >+ protected int doGetItemCount() >+ { >+ return grid.getItemCount(); >+ } > >- protected int internalGetItemCount() { >- return grid.getItemCount(); >- } >+ /** {@inheritDoc} */ >+ protected Item[] doGetItems() >+ { >+ return grid.getItems(); >+ } > >- protected Item[] internalGetItems() { >- return grid.getItems(); >- } >+ /** {@inheritDoc} */ >+ protected Item[] doGetSelection() >+ { >+ return grid.getSelection(); >+ } > >- protected Widget[] internalGetSelection() { >- return grid.getSelection(); >- } >+ /** {@inheritDoc} */ >+ protected int[] doGetSelectionIndices() >+ { >+ return grid.getSelectionIndices(); >+ } > >- protected int[] internalGetSelectionIndices() { >- return grid.getSelectionIndices(); >- } >+ /** {@inheritDoc} */ >+ protected int doIndexOf(Item item) >+ { >+ return grid.indexOf((GridItem) item); >+ } > >- protected int internalIndexOf(Item item) { >- return grid.indexOf((GridItem) item); >- } >+ /** {@inheritDoc} */ >+ protected void doRemove(int[] indices) >+ { >+ grid.remove(indices); >+ } > >- protected void internalRemove(int start, int end) { >- grid.remove(start, end); >- } >+ /** {@inheritDoc} */ >+ protected void doRemove(int start, int end) >+ { >+ grid.remove(start, end); >+ } > >- protected void internalRemove(int[] indices) { >- grid.remove(indices); >- } >+ /** {@inheritDoc} */ >+ protected void doRemoveAll() >+ { >+ grid.removeAll(); >+ } > >- protected void internalRemoveAll() { >- grid.removeAll(); >- } >+ /** {@inheritDoc} */ >+ protected void doSetSelection(Item[] items) >+ { >+ GridItem[] items2 = new GridItem[items.length]; >+ for (int i = 0; i < items.length; i++) >+ { >+ items2[i] = (GridItem) items[i]; >+ } >+ grid.setSelection(items2); >+ } > >- protected void internalSetItemCount(int count) { >- // TODO NEEDS IMP >- } >+ /** {@inheritDoc} */ >+ protected void doSetSelection(int[] indices) >+ { >+ grid.setSelection(indices); >+ } > >- protected void internalSetSelection(Item[] items) { >- if (items != null) { >- grid.setSelection(new GridItem[0]); >- } else { >- GridItem[] tmp = new GridItem[items.length]; >- System.arraycopy(items, 0, tmp, 0, items.length); >- grid.setSelection(tmp); >- } >+ /** {@inheritDoc} */ >+ protected void doShowItem(Item item) >+ { >+ grid.showItem((GridItem)item); >+ } > >- } >+ /** {@inheritDoc} */ >+ protected void doShowSelection() >+ { >+ grid.showSelection(); >+ } > >- protected void internalSetSelection(int[] indices) { >- grid.setSelection(indices); >- } >+ /** {@inheritDoc} */ >+ protected Item getItemAt(Point point) >+ { >+ return grid.getItem(point); >+ } > >- protected void internalShowItem(Item item) { >- grid.showItem((GridItem) item); >- } >+ /** {@inheritDoc} */ >+ public Control getControl() >+ { >+ return grid; >+ } >+ >+ /** {@inheritDoc} */ >+ protected ViewerRow getViewerRowFromItem(Widget item) >+ { >+ ViewerRow part = (ViewerRow) item.getData(ViewerRow.ROWPART_KEY); > >- protected void internalShowSelection() { >- grid.showSelection(); >- } >+ if (part == null) >+ { >+ part = new GridViewerRow(((GridItem) item)); >+ } > >- protected void internalSetControl(Control table) { >- grid = (Grid) table; >- } >+ return part; >+ } > >- public Control getControl() { >- return grid; >+ >+ >+ protected void doResetItem(Item item) { >+ GridItem gridItem = (GridItem) item; >+ int columnCount = Math.max(1, grid.getColumnCount()); >+ for (int i = 0; i < columnCount; i++) { >+ gridItem.setText(i, ""); //$NON-NLS-1$ >+ gridItem.setImage(null); >+ } > } > >- protected Item getItemAt(Point point) >- { >- return grid.getItem(point); >- } >+ protected ViewerCell getFocusCell() { >+ if( getGrid().getCellSelectionEnabled() ) { >+ Point p = getGrid().getFocusCell(); >+ >+ if( p.x >= 0 && p.y >= 0 ) { >+ GridItem item = getGrid().getItem(p.y); >+ if( item != null ) { >+ ViewerRow row = (ViewerRow) item.getData(ViewerRow.ROWPART_KEY); >+ return row.getCell(p.x); >+ } >+ } >+ } > >+ return null; >+ } > } >Index: src/org/eclipse/swt/nebula/nebface/viewers/GridViewerRow.java >=================================================================== >RCS file: /cvsroot/technology/org.eclipse.swt.nebula/org.eclipse.swt.nebula.nebface/src/org/eclipse/swt/nebula/nebface/viewers/GridViewerRow.java,v >retrieving revision 1.1 >diff -u -r1.1 GridViewerRow.java >--- src/org/eclipse/swt/nebula/nebface/viewers/GridViewerRow.java 20 Dec 2006 15:00:38 -0000 1.1 >+++ src/org/eclipse/swt/nebula/nebface/viewers/GridViewerRow.java 2 Feb 2007 19:23:32 -0000 >@@ -1,14 +1,14 @@ > /******************************************************************************* >- * Copyright (c) 2006 Tom Schindl and others. >+ * Copyright (c) 2007 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at > * http://www.eclipse.org/legal/epl-v10.html > * > * Contributors: >- * Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation >- * IBM Corporation >- *******************************************************************************/ >+ * rmcamara@us.ibm.com - initial API and implementation >+ *******************************************************************************/ >+ > package org.eclipse.swt.nebula.nebface.viewers; > > import org.eclipse.jface.viewers.ViewerRow; >@@ -20,82 +20,151 @@ > import org.eclipse.swt.widgets.Control; > import org.eclipse.swt.widgets.Item; > >-public class GridViewerRow extends ViewerRow { >- private GridItem item; >- >- public GridViewerRow(GridItem item) { >- super(item); >- this.item = item; >- } >- >- public void clear() { >- item.setText(""); >- if (getColumnCount() == 0) { >- item.setImage(null); >+/** >+ * GridViewerRow is the concrete implementation of the part that represents items in a >+ * Grid. >+ * >+ * @author rmcamara@us.ibm.com >+ * @since 3.3 >+ */ >+public class GridViewerRow extends ViewerRow >+{ >+ private GridItem item; >+ >+ /** >+ * Create a new instance of the receiver. >+ * >+ * @param item GridItem source. >+ */ >+ public GridViewerRow(Item item) >+ { >+ super(item); >+ this.item = (GridItem)item; >+ } >+ >+ /** {@inheritDoc} */ >+ public Rectangle getBounds(int columnIndex) >+ { >+ return item.getBounds(columnIndex); >+ } >+ >+ /** {@inheritDoc} */ >+ public Rectangle getBounds() >+ { >+ // TODO This is not correct. Update once item returns the correct information. >+ return item.getBounds(0); >+ } >+ >+ /** {@inheritDoc} */ >+ public Item getItem() >+ { >+ return item; >+ } >+ >+ /** {@inheritDoc} */ >+ public int getColumnCount() >+ { >+ return item.getParent().getColumnCount(); >+ } >+ >+ /** {@inheritDoc} */ >+ public Color getBackground(int columnIndex) >+ { >+ return item.getBackground(columnIndex); >+ } >+ >+ /** {@inheritDoc} */ >+ public Font getFont(int columnIndex) >+ { >+ return item.getFont(columnIndex); >+ } >+ >+ /** {@inheritDoc} */ >+ public Color getForeground(int columnIndex) >+ { >+ return item.getForeground(columnIndex); >+ } >+ >+ /** {@inheritDoc} */ >+ public Image getImage(int columnIndex) >+ { >+ return item.getImage(columnIndex); >+ } >+ >+ /** {@inheritDoc} */ >+ public String getText(int columnIndex) >+ { >+ return item.getText(columnIndex); >+ } >+ >+ /** {@inheritDoc} */ >+ public void setBackground(int columnIndex, Color color) >+ { >+ item.setBackground(columnIndex, color); >+ } >+ >+ /** {@inheritDoc} */ >+ public void setFont(int columnIndex, Font font) >+ { >+ item.setFont(columnIndex, font); >+ } >+ >+ /** {@inheritDoc} */ >+ public void setForeground(int columnIndex, Color color) >+ { >+ item.setForeground(columnIndex, color); >+ } >+ >+ /** {@inheritDoc} */ >+ public void setImage(int columnIndex, Image image) >+ { >+ item.setImage(columnIndex, image); >+ } >+ >+ /** {@inheritDoc} */ >+ public void setText(int columnIndex, String text) >+ { >+ item.setText(columnIndex, text == null ? "" : text); //$NON-NLS-1$ >+ } >+ >+ /** {@inheritDoc} */ >+ public Control getControl() >+ { >+ return item.getParent(); >+ } >+ >+ public ViewerRow getNeighbor(int direction, boolean sameLevel) { >+ if( direction == ViewerRow.ABOVE ) { >+ return getRowAbove(); >+ } else if( direction == ViewerRow.BELOW ) { >+ return getRowBelow(); > } else { >- for (int i = 0; i < getColumnCount(); i++) { >- item.setImage(i, null); >- } >+ throw new IllegalArgumentException("Illegal value of direction argument."); //$NON-NLS-1$ > } > } > >- public Color getBackground(int columnIndex) { >- return item.getBackground(columnIndex); >- } >- >- public Rectangle getBounds(int columnIndex) { >- return item.getBounds(columnIndex); >- } >- >- public Rectangle getBounds() { >- return item.getBounds(0); // TODO IS THIS CORRECT >- } >- >- public int getColumnCount() { >- return item.getParent().getColumnCount(); >- } >- >- public Font getFont(int columnIndex) { >- return item.getFont(columnIndex); >- } >- >- public Color getForeground(int columnIndex) { >- return item.getForeground(columnIndex); >- } >- >- public Image getImage(int columnIndex) { >- return item.getImage(columnIndex); >- } >- >- public Item getItem() { >- return item; >- } >- >- public String getText(int columnIndex) { >- return item.getText(columnIndex); >- } >- >- public void setBackground(int columnIndex, Color color) { >- item.setBackground(columnIndex, color); >- } >- >- public void setFont(int columnIndex, Font font) { >- item.setFont(columnIndex, font); >- } >- >- public void setForeground(int columnIndex, Color color) { >- item.setForeground(columnIndex, color); >- } >- >- public void setImage(int columnIndex, Image image) { >- item.setImage(columnIndex, image); >- } >- >- public void setText(int columnIndex, String text) { >- item.setText(columnIndex, text); >+ >+ private ViewerRow getRowAbove() { >+ int index = item.getParent().indexOf(item) - 1; >+ >+ if( index >= 0 ) { >+ return (ViewerRow)item.getParent().getItem(index).getData(ViewerRow.ROWPART_KEY); >+ } >+ >+ return null; > } > >- public Control getControl() { >- return item.getParent(); >+ private ViewerRow getRowBelow() { >+ int index = item.getParent().indexOf(item) + 1; >+ >+ if( index < item.getParent().getItemCount() ) { >+ GridItem tmp = item.getParent().getItem(index); >+ //TODO NULL can happen in case of VIRTUAL => How do we deal with that >+ if( tmp != null ) { >+ return (ViewerRow)tmp.getData(ViewerRow.ROWPART_KEY); >+ } >+ } >+ >+ return null; > } >-} >+} >\ No newline at end of file >Index: src/org/eclipse/swt/nebula/nebface/viewers/GridViewerColumn.java >=================================================================== >RCS file: /cvsroot/technology/org.eclipse.swt.nebula/org.eclipse.swt.nebula.nebface/src/org/eclipse/swt/nebula/nebface/viewers/GridViewerColumn.java,v >retrieving revision 1.1 >diff -u -r1.1 GridViewerColumn.java >--- src/org/eclipse/swt/nebula/nebface/viewers/GridViewerColumn.java 20 Dec 2006 15:00:38 -0000 1.1 >+++ src/org/eclipse/swt/nebula/nebface/viewers/GridViewerColumn.java 2 Feb 2007 19:23:32 -0000 >@@ -1,18 +1,17 @@ > /******************************************************************************* >- * Copyright (c) 2006 IBM Corporation and others. >+ * Copyright (c) 2007 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at > * http://www.eclipse.org/legal/epl-v10.html > * > * Contributors: >- * IBM Corporation - initial API and implementation >- ******************************************************************************/ >+ * rmcamara@us.ibm.com - initial API and implementation >+ *******************************************************************************/ > > package org.eclipse.swt.nebula.nebface.viewers; > > import org.eclipse.jface.viewers.EditingSupport; >-import org.eclipse.jface.viewers.TableViewer; > import org.eclipse.jface.viewers.ViewerColumn; > import org.eclipse.swt.SWT; > import org.eclipse.swt.nebula.widgets.grid.Grid; >@@ -20,49 +19,54 @@ > import org.eclipse.swt.nebula.widgets.grid.GridItem; > import org.eclipse.swt.widgets.Event; > import org.eclipse.swt.widgets.Listener; >-import org.eclipse.swt.widgets.Table; >-import org.eclipse.swt.widgets.TableColumn; > > /** >- * This is the JFace' implementation of SWT's {@link TableColumn} like >- * {@link TableViewer} is JFace' implementation of {@link Table} >- * >+ * The concrete implementation of the ColumnViewer for the grid. >+ * >+ * @author rmcamara@us.ibm.com > * @since 3.3 > */ >-public final class GridViewerColumn extends ViewerColumn { >- >+public final class GridViewerColumn extends ViewerColumn >+{ >+ /** The concrete grid column that is being represented by the {@code ViewerColumn}.*/ > private GridColumn column; >+ >+ /** Editor support for handling check events. */ > private CheckEditingSupport checkEditingSupport; >+ >+ /** The parent grid viewer. */ > private GridViewer viewer; > > /** >- * Create a new column in the {@link TableViewer} >+ * Create a new column in the {@link GridViewer} > * > * @param viewer > * the viewer the column belongs to > * @param style > * the style used to create the column for style bits see >- * {@link TableColumn} >- * @see TableColumn#TableColumn(Table, int) >+ * {@link GridColumn} >+ * @see GridColumn#GridColumn(Grid, int) > */ >- public GridViewerColumn(GridViewer viewer, int style) { >+ public GridViewerColumn(GridViewer viewer, int style) >+ { > this(viewer, style, -1); > this.viewer = viewer; > } > > /** >- * Create a new column in the {@link TableViewer} >+ * Create a new column in the {@link GridViewer} > * > * @param viewer > * the viewer the column belongs to > * @param style > * the style used to create the column for style bits see >- * {@link TableColumn} >+ * {@link GridColumn} > * @param index > * the index of the newly created column >- * @see TableColumn#TableColumn(Table, int, int) >+ * @see GridColumn#GridColumn(Grid, int, int) > */ >- public GridViewerColumn(GridViewer viewer, int style, int index) { >+ public GridViewerColumn(GridViewer viewer, int style, int index) >+ { > this(viewer, createColumn((Grid) viewer.getControl(), style, index)); > this.viewer = viewer; > } >@@ -74,27 +78,34 @@ > * @param column > * the column the viewer is attached to > */ >- public GridViewerColumn(GridViewer viewer, GridColumn column) { >+ public GridViewerColumn(GridViewer viewer, GridColumn column) >+ { > super(viewer, column); > this.column = column; > this.viewer = viewer; > } > >- private static GridColumn createColumn(Grid grid, int style, int index) { >- if (index >= 0) { >- return new GridColumn(grid, style, index); >+ private static GridColumn createColumn(Grid table, int style, int index) >+ { >+ if (index >= 0) >+ { >+ return new GridColumn(table, style, index); > } > >- return new GridColumn(grid, style); >+ return new GridColumn(table, style); > } > > /** >- * @return the underlying SWT column >+ * Returns the underlying column. >+ * >+ * @return the underlying Nebula column > */ >- public GridColumn getColumn() { >+ public GridColumn getColumn() >+ { > return column; > } > >+ /** {@inheritDoc} */ > public void setEditingSupport(EditingSupport editingSupport) > { > if (editingSupport instanceof CheckEditingSupport) >@@ -123,4 +134,4 @@ > super.setEditingSupport(editingSupport); > } > } >-} >+} >\ No newline at end of file >Index: src/org/eclipse/swt/nebula/nebface/viewers/GridTreeViewer.java >=================================================================== >RCS file: src/org/eclipse/swt/nebula/nebface/viewers/GridTreeViewer.java >diff -N src/org/eclipse/swt/nebula/nebface/viewers/GridTreeViewer.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/swt/nebula/nebface/viewers/GridTreeViewer.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,392 @@ >+/******************************************************************************* >+ * Copyright (c) 2007 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * rmcamara@us.ibm.com - initial API and implementation >+ *******************************************************************************/ >+ >+package org.eclipse.swt.nebula.nebface.viewers; >+ >+import org.eclipse.jface.viewers.AbstractTreeViewer; >+import org.eclipse.jface.viewers.AbstractViewerEditor; >+import org.eclipse.jface.viewers.StructuredSelection; >+import org.eclipse.jface.viewers.TreePath; >+import org.eclipse.jface.viewers.TreeSelection; >+import org.eclipse.jface.viewers.ViewerRow; >+import org.eclipse.jface.viewers.CellEditor.LayoutData; >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.events.TreeListener; >+import org.eclipse.swt.graphics.Point; >+import org.eclipse.swt.nebula.widgets.grid.Grid; >+import org.eclipse.swt.nebula.widgets.grid.GridEditor; >+import org.eclipse.swt.nebula.widgets.grid.GridItem; >+import org.eclipse.swt.widgets.Composite; >+import org.eclipse.swt.widgets.Control; >+import org.eclipse.swt.widgets.Item; >+import org.eclipse.swt.widgets.Widget; >+ >+import java.util.List; >+ >+ >+/** >+ * A concrete viewer based on an {@link Grid} control. This viewer is meant >+ * to provide grid like support for a grid. >+ * <p> >+ * This class is not intended to be subclassed outside the viewer framework. It >+ * is designed to be instantiated with a pre-existing grid control and >+ * configured with a domain-specific content provider, label provider, element >+ * filter (optional), and element sorter (optional). >+ * <p> >+ * Content providers for grid viewers must implement the >+ * {@code ITreeContentProvider} interface. >+ * >+ * @author rmcamara@us.ibm.com >+ * @since 3.3 >+ */ >+public class GridTreeViewer extends AbstractTreeViewer >+{ >+ /** This viewer's grid control. */ >+ private Grid grid; >+ >+ /** Table editor. */ >+ private GridEditor gridEditor; >+ >+ /** >+ * Creates a grid viewer on a newly-created grid control under the given >+ * parent. The grid control is created using the SWT style bits >+ * <code>MULTI, H_SCROLL, V_SCROLL,</code> and <code>BORDER</code>. The >+ * viewer has no input, no content provider, a default label provider, no >+ * sorter, and no filters. >+ * >+ * @param parent the parent control. >+ */ >+ public GridTreeViewer(Composite parent) >+ { >+ this(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER); >+ } >+ >+ /** >+ * Creates a grid viewer on a newly-created grid control under the given >+ * parent. The grid control is created using the given SWT style bits. The >+ * viewer has no input, no content provider, a default label provider, no >+ * sorter, and no filters. >+ * >+ * @param parent the parent control. >+ * @param style the SWT style bits used to create the grid. >+ */ >+ public GridTreeViewer(Composite parent, int style) >+ { >+ this(new Grid(parent, style)); >+ } >+ >+ /** >+ * Creates a grid viewer on the given grid control. The viewer has no >+ * input, no content provider, a default label provider, no sorter, and no >+ * filters. >+ * >+ * @param grid the grid control. >+ */ >+ public GridTreeViewer(Grid table) >+ { >+ this.grid = table; >+ gridEditor = new GridEditor(table); >+ hookControl(table); >+ } >+ >+ /** >+ * {@inheritDoc} >+ */ >+ public Control getControl() >+ { >+ return grid; >+ } >+ >+ /** >+ * Returns this grid viewer's grid control. >+ * >+ * @return the grid control >+ */ >+ public Grid getGrid() >+ { >+ return grid; >+ } >+ >+ /** {@inheritDoc} */ >+ protected void addTreeListener(Control c, TreeListener listener) >+ { >+ ((Grid)c).addTreeListener(listener); >+ } >+ >+ /** {@inheritDoc} */ >+ protected Widget doGetColumn(int index) >+ { >+ return grid.getColumn(index); >+ } >+ >+ /** {@inheritDoc} */ >+ protected int doGetColumnCount() >+ { >+ return grid.getColumnCount(); >+ } >+ >+ /** {@inheritDoc} */ >+ protected Item[] getChildren(Widget o) >+ { >+ if (o instanceof GridItem) >+ { >+ return ((GridItem)o).getItems(); >+ } >+ if (o instanceof Grid) >+ { >+ List rootlist = ((Grid)o).getRootItems(); >+ GridItem[] roots = new GridItem[rootlist.size()]; >+ >+ for (int i = 0; i < roots.length; i++) >+ { >+ roots[i] = (GridItem) rootlist.get(i); >+ } >+ >+ return roots; >+ } >+ return null; >+ } >+ >+ /** {@inheritDoc} */ >+ protected boolean getExpanded(Item item) >+ { >+ return ((GridItem)item).isExpanded(); >+ } >+ >+ /** {@inheritDoc} */ >+ protected Item getItemAt(Point p) >+ { >+ return grid.getItem(p); >+ } >+ >+ /** {@inheritDoc} */ >+ protected Item[] getItems(Item item) >+ { >+ return ((GridItem)item).getItems(); >+ } >+ >+ /** {@inheritDoc} */ >+ protected Item getParentItem(Item item) >+ { >+ return ((GridItem)item).getParentItem(); >+ } >+ >+ /** {@inheritDoc} */ >+ protected Item[] getSelection(Control widget) >+ { >+ return ((Grid)widget).getSelection(); >+ } >+ >+ /** {@inheritDoc} */ >+ protected Item doGetParentItem(Item item) >+ { >+ return ((GridItem)item).getParentItem(); >+ } >+ >+ /** {@inheritDoc} */ >+ protected int doIndexOf(Item parentItem, Item item) >+ { >+ return ((GridItem)parentItem).indexOf((GridItem)item); >+ } >+ >+ /** {@inheritDoc} */ >+ protected int doIndexOf(Item item) >+ { >+ return grid.indexOf((GridItem)item); >+ } >+ >+ /** {@inheritDoc} */ >+ protected AbstractViewerEditor createViewerEditor() >+ { >+ return new AbstractViewerEditor(this) >+ { >+ protected StructuredSelection createSelection(Object element) >+ { >+ if (element instanceof TreePath) >+ { >+ return new TreeSelection((TreePath)element, getComparer()); >+ } >+ >+ return new StructuredSelection(element); >+ } >+ >+ protected void setEditor(Control w, Item item, int fColumnNumber) >+ { >+ gridEditor.setEditor(w, (GridItem)item, fColumnNumber); >+ } >+ >+ protected void setLayoutData(LayoutData layoutData) >+ { >+ gridEditor.grabHorizontal = layoutData.grabHorizontal; >+ gridEditor.horizontalAlignment = layoutData.horizontalAlignment; >+ gridEditor.minimumWidth = layoutData.minimumWidth; >+ } >+ }; >+ } >+ >+ /** {@inheritDoc} */ >+ protected void removeAll(Control widget) >+ { >+ ((Grid)widget).removeAll(); >+ } >+ >+ /** {@inheritDoc} */ >+ protected void doSetExpanded(Item item, boolean expanded) >+ { >+ ((GridItem)item).setExpanded(expanded); >+ } >+ >+ /** {@inheritDoc} */ >+ protected void doSetSelection(List items) >+ { >+ GridItem[] newItems = new GridItem[items.size()]; >+ items.toArray(newItems); >+ getGrid().setSelection(newItems); >+ } >+ >+ /** {@inheritDoc} */ >+ protected void showItem(Item item) >+ { >+ getGrid().showItem((GridItem)item); >+ } >+ >+ /** {@inheritDoc} */ >+ protected Item getChild(Widget widget, int index) >+ { >+ if (widget instanceof GridItem) >+ { >+ return ((GridItem)widget).getItem(index); >+ } >+ if (widget instanceof Grid) >+ { >+ return (GridItem) ((Grid)widget).getRootItems().get(index); >+ } >+ return null; >+ } >+ >+ /** {@inheritDoc} */ >+ protected int doGetItemCount() >+ { >+ return grid.getItemCount(); >+ } >+ >+ /** {@inheritDoc} */ >+ protected Item doGetItem(int index) >+ { >+ return grid.getItem(index); >+ } >+ >+ /** {@inheritDoc} */ >+ protected Item doGetItem(Item item, int index) >+ { >+ return ((GridItem)item).getItem(index); >+ } >+ >+ /** {@inheritDoc} */ >+ protected int doGetItemCount(Item item) >+ { >+ return ((GridItem)item).getItemCount(); >+ } >+ >+ /** {@inheritDoc} */ >+ protected void doSetItemCount(int count) >+ { >+ // TODO Implement once grid supports virtual >+ } >+ >+ /** {@inheritDoc} */ >+ protected void doSetItemCount(Item item, int count) >+ { >+ // TODO Implement once grid supports virtual >+ } >+ >+ /** {@inheritDoc} */ >+ protected void doClear(Item item, boolean all) >+ { >+ // TODO Once grid implements virtual. >+ } >+ >+ /** {@inheritDoc} */ >+ protected void doClearAll(Item item, boolean all) >+ { >+ //TODO implement once grid supports virtual. >+ } >+ >+ /** {@inheritDoc} */ >+ protected void doClearAll(boolean all) >+ { >+ //TODO implement once grid supports virtual. >+ } >+ >+ /** {@inheritDoc} */ >+ protected ViewerRow getViewerRowFromItem(Widget item) >+ { >+ ViewerRow part = (ViewerRow)item.getData(ViewerRow.ROWPART_KEY); >+ >+ if (part == null) >+ { >+ part = new GridViewerRow(((GridItem)item)); >+ } >+ >+ return part; >+ } >+ >+ /** {@inheritDoc} */ >+ protected ViewerRow doCreateNewRowPart(ViewerRow parent, int style, int rowIndex) >+ { >+ if (parent == null) >+ { >+ if (rowIndex >= 0) >+ { >+ return getViewerRowFromItem(new GridItem(grid, style, rowIndex)); >+ } >+ return getViewerRowFromItem(new GridItem(grid, style)); >+ } >+ >+ if (rowIndex >= 0) >+ { >+ return getViewerRowFromItem(new GridItem((GridItem)parent.getItem(), >+ SWT.NONE, rowIndex)); >+ } >+ >+ return getViewerRowFromItem(new GridItem((GridItem)parent.getItem(), SWT.NONE)); >+ } >+ >+ protected int getItemCount(Control control) >+ { >+ // TODO Auto-generated method stub >+ return 0; >+ } >+ >+ protected int getItemCount(Item item) >+ { >+ // TODO Auto-generated method stub >+ return 0; >+ } >+ >+ protected Item newItem(Widget parent, int style, int index) >+ { >+ // TODO Auto-generated method stub >+ return null; >+ } >+ >+ protected void setExpanded(Item item, boolean expand) >+ { >+ // TODO Auto-generated method stub >+ >+ } >+ >+ protected void setSelection(List items) >+ { >+ // TODO Auto-generated method stub >+ >+ } >+} >#P org.eclipse.swt.nebula.widgets >Index: src/org/eclipse/swt/nebula/widgets/grid/Grid.java >=================================================================== >RCS file: /cvsroot/technology/org.eclipse.swt.nebula/org.eclipse.swt.nebula.widgets/src/org/eclipse/swt/nebula/widgets/grid/Grid.java,v >retrieving revision 1.23 >diff -u -r1.23 Grid.java >--- src/org/eclipse/swt/nebula/widgets/grid/Grid.java 29 Dec 2006 16:02:54 -0000 1.23 >+++ src/org/eclipse/swt/nebula/widgets/grid/Grid.java 2 Feb 2007 19:23:42 -0000 >@@ -6675,7 +6675,7 @@ > /** > * Returns the current cell in focus. If cell selection is disabled, this method returns null. > * >- * @return cell in focus or {@code null}. >+ * @return cell in focus or {@code null}. x represents the column and y the row the cell is in > * @throws org.eclipse.swt.SWTException > * <ul> > * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> >Index: .settings/org.eclipse.jdt.ui.prefs >=================================================================== >RCS file: /cvsroot/technology/org.eclipse.swt.nebula/org.eclipse.swt.nebula.widgets/.settings/org.eclipse.jdt.ui.prefs,v >retrieving revision 1.1 >diff -u -r1.1 org.eclipse.jdt.ui.prefs >--- .settings/org.eclipse.jdt.ui.prefs 2 Jun 2006 14:45:32 -0000 1.1 >+++ .settings/org.eclipse.jdt.ui.prefs 2 Feb 2007 19:23:36 -0000 >@@ -1,3 +1,3 @@ >-#Thu Jun 01 15:04:52 EDT 2006 >+#Thu Feb 01 11:43:25 CET 2007 > eclipse.preferences.version=1 > org.eclipse.jdt.ui.text.custom_code_templates=<?xml version\="1.0" encoding\="UTF-8"?><templates><template autoinsert\="true" context\="gettercomment_context" deleted\="false" description\="Comment for getter method" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.gettercomment" name\="gettercomment">/**\r\n * @return the ${bare_field_name}\r\n */</template><template autoinsert\="true" context\="settercomment_context" deleted\="false" description\="Comment for setter method" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.settercomment" name\="settercomment">/**\r\n * @param ${param} the ${bare_field_name} to set\r\n */</template><template autoinsert\="true" context\="constructorcomment_context" deleted\="false" description\="Comment for created constructors" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.constructorcomment" name\="constructorcomment">/**\r\n * ${tags}\r\n */</template><template autoinsert\="false" context\="filecomment_context" deleted\="false" description\="Comment for created Java files" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.filecomment" name\="filecomment">/*******************************************************************************\r\n * Copyright (c) ${year} ${todo}\r\n * All rights reserved. This program and the accompanying materials\r\n * are made available under the terms of the Eclipse Public License v1.0\r\n * which accompanies this distribution, and is available at\r\n * http\://www.eclipse.org/legal/epl-v10.html\r\n *\r\n * Contributors\:\r\n * ${user} - initial API and implementation\r\n *******************************************************************************/ \r\n</template><template autoinsert\="false" context\="typecomment_context" deleted\="false" description\="Comment for created types" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.typecomment" name\="typecomment">/**\r\n * \r\n *\r\n * @author ${user}\r\n */</template><template autoinsert\="true" context\="fieldcomment_context" deleted\="false" description\="Comment for fields" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.fieldcomment" name\="fieldcomment">/**\r\n * \r\n */</template><template autoinsert\="true" context\="methodcomment_context" deleted\="false" description\="Comment for non-overriding methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.methodcomment" name\="methodcomment">/**\r\n * ${tags}\r\n */</template><template autoinsert\="false" context\="overridecomment_context" deleted\="false" description\="Comment for overriding methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.overridecomment" name\="overridecomment">/** \r\n * {@inheritDoc}\r\n */</template><template autoinsert\="true" context\="newtype_context" deleted\="false" description\="Newly created files" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.newtype" name\="newtype">${filecomment}\r\n${package_declaration}\r\n\r\n${typecomment}\r\n${type_declaration}</template><template autoinsert\="true" context\="classbody_context" deleted\="false" description\="Code in new class type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.classbody" name\="classbody">\r\n</template><template autoinsert\="true" context\="interfacebody_context" deleted\="false" description\="Code in new interface type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.interfacebody" name\="interfacebody">\r\n</template><template autoinsert\="true" context\="enumbody_context" deleted\="false" description\="Code in new enum type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.enumbody" name\="enumbody">\r\n</template><template autoinsert\="true" context\="annotationbody_context" deleted\="false" description\="Code in new annotation type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.annotationbody" name\="annotationbody">\r\n</template><template autoinsert\="true" context\="catchblock_context" deleted\="false" description\="Code in new catch blocks" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.catchblock" name\="catchblock">// ${todo} Auto-generated catch block\r\n${exception_var}.printStackTrace();</template><template autoinsert\="true" context\="methodbody_context" deleted\="false" description\="Code in created method stubs" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.methodbody" name\="methodbody">// ${todo} Auto-generated method stub\r\n${body_statement}</template><template autoinsert\="true" context\="constructorbody_context" deleted\="false" description\="Code in created constructor stubs" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.constructorbody" name\="constructorbody">${body_statement}\r\n// ${todo} Auto-generated constructor stub</template><template autoinsert\="true" context\="getterbody_context" deleted\="false" description\="Code in created getters" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.getterbody" name\="getterbody">return ${field};</template><template autoinsert\="true" context\="setterbody_context" deleted\="false" description\="Code in created setters" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.setterbody" name\="setterbody">${field} \= ${param};</template></templates> >Index: .settings/org.eclipse.jdt.core.prefs >=================================================================== >RCS file: /cvsroot/technology/org.eclipse.swt.nebula/org.eclipse.swt.nebula.widgets/.settings/org.eclipse.jdt.core.prefs,v >retrieving revision 1.1 >diff -u -r1.1 org.eclipse.jdt.core.prefs >--- .settings/org.eclipse.jdt.core.prefs 2 Jun 2006 14:45:32 -0000 1.1 >+++ .settings/org.eclipse.jdt.core.prefs 2 Feb 2007 19:23:36 -0000 >@@ -1,4 +1,4 @@ >-#Thu Jun 01 12:46:14 EDT 2006 >+#Thu Feb 01 16:16:19 CET 2007 > eclipse.preferences.version=1 > org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled > org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.1 >@@ -7,6 +7,18 @@ > org.eclipse.jdt.core.compiler.debug.lineNumber=generate > org.eclipse.jdt.core.compiler.debug.localVariable=generate > org.eclipse.jdt.core.compiler.debug.sourceFile=generate >+org.eclipse.jdt.core.compiler.doc.comment.support=enabled > org.eclipse.jdt.core.compiler.problem.assertIdentifier=ignore > org.eclipse.jdt.core.compiler.problem.enumIdentifier=ignore >+org.eclipse.jdt.core.compiler.problem.invalidJavadoc=warning >+org.eclipse.jdt.core.compiler.problem.invalidJavadocTags=enabled >+org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsDeprecatedRef=enabled >+org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsNotVisibleRef=enabled >+org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsVisibility=protected >+org.eclipse.jdt.core.compiler.problem.missingJavadocComments=warning >+org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsOverriding=disabled >+org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsVisibility=protected >+org.eclipse.jdt.core.compiler.problem.missingJavadocTags=warning >+org.eclipse.jdt.core.compiler.problem.missingJavadocTagsOverriding=disabled >+org.eclipse.jdt.core.compiler.problem.missingJavadocTagsVisibility=protected > org.eclipse.jdt.core.compiler.source=1.3 >#P org.eclipse.swt.nebula.snippets >Index: META-INF/MANIFEST.MF >=================================================================== >RCS file: /cvsroot/technology/org.eclipse.swt.nebula/org.eclipse.swt.nebula.snippets/META-INF/MANIFEST.MF,v >retrieving revision 1.3 >diff -u -r1.3 MANIFEST.MF >--- META-INF/MANIFEST.MF 12 Jan 2007 03:47:52 -0000 1.3 >+++ META-INF/MANIFEST.MF 2 Feb 2007 19:23:44 -0000 >@@ -5,6 +5,6 @@ > Bundle-Version: 1.0.0 > Bundle-Localization: plugin > Require-Bundle: org.eclipse.swt, >- org.eclipse.swt.nebula >-Export-Package: org.eclipse.swt.nebula.snippets.ctree, >- org.eclipse.swt.nebula.snippets.grid >+ org.eclipse.swt.nebula, >+ org.eclipse.swt.nebula.nebface >+Export-Package: org.eclipse.swt.nebula.snippets.grid >Index: src/org/eclipse/swt/nebface/snippets/viewers/GridViewerSnippet1.java >=================================================================== >RCS file: src/org/eclipse/swt/nebface/snippets/viewers/GridViewerSnippet1.java >diff -N src/org/eclipse/swt/nebface/snippets/viewers/GridViewerSnippet1.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/swt/nebface/snippets/viewers/GridViewerSnippet1.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,206 @@ >+/******************************************************************************* >+ * Copyright (c) 2006 Tom Schindl and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Tom Schindl - initial API and implementation >+ *******************************************************************************/ >+ >+package org.eclipse.swt.nebface.snippets.viewers; >+ >+import org.eclipse.jface.resource.FontRegistry; >+import org.eclipse.jface.viewers.CellEditor; >+import org.eclipse.jface.viewers.EditingSupport; >+import org.eclipse.jface.viewers.EditorActivationEvent; >+import org.eclipse.jface.viewers.EditorActivationStrategy; >+import org.eclipse.jface.viewers.ICellModifier; >+import org.eclipse.jface.viewers.IStructuredContentProvider; >+import org.eclipse.jface.viewers.ITableColorProvider; >+import org.eclipse.jface.viewers.ITableFontProvider; >+import org.eclipse.jface.viewers.ITableLabelProvider; >+import org.eclipse.jface.viewers.LabelProvider; >+import org.eclipse.jface.viewers.TextCellEditor; >+import org.eclipse.jface.viewers.Viewer; >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.graphics.Color; >+import org.eclipse.swt.graphics.Font; >+import org.eclipse.swt.graphics.Image; >+import org.eclipse.swt.layout.FillLayout; >+import org.eclipse.swt.nebula.nebface.viewers.GridViewer; >+import org.eclipse.swt.nebula.widgets.grid.GridColumn; >+import org.eclipse.swt.widgets.Display; >+import org.eclipse.swt.widgets.Shell; >+ >+/** >+ * Example usage of none mandatory interfaces of ITableFontProvider and >+ * ITableColorProvider >+ * >+ * @author Tom Schindl <tom.schindl@bestsolution.at> >+ * >+ */ >+public class GridViewerSnippet1 { >+ >+ private class MyContentProvider implements IStructuredContentProvider { >+ >+ /* >+ * (non-Javadoc) >+ * >+ * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object) >+ */ >+ public Object[] getElements(Object inputElement) { >+ return (MyModel[]) inputElement; >+ } >+ >+ /* >+ * (non-Javadoc) >+ * >+ * @see org.eclipse.jface.viewers.IContentProvider#dispose() >+ */ >+ public void dispose() { >+ >+ } >+ >+ /* >+ * (non-Javadoc) >+ * >+ * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, >+ * java.lang.Object, java.lang.Object) >+ */ >+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { >+ >+ } >+ >+ } >+ >+ public static boolean flag = true; >+ >+ public class MyModel { >+ public int counter; >+ >+ public MyModel(int counter) { >+ this.counter = counter; >+ } >+ >+ public String toString() { >+ return "Item " + this.counter; >+ } >+ } >+ >+ public class MyLabelProvider extends LabelProvider implements >+ ITableLabelProvider, ITableFontProvider, ITableColorProvider { >+ FontRegistry registry = new FontRegistry(); >+ >+ public Image getColumnImage(Object element, int columnIndex) { >+ return null; >+ } >+ >+ public String getColumnText(Object element, int columnIndex) { >+ return "Column " + columnIndex + " => " + element.toString(); >+ } >+ >+ public Font getFont(Object element, int columnIndex) { >+ if (((MyModel) element).counter % 2 == 0) { >+ return registry.getBold(Display.getCurrent().getSystemFont() >+ .getFontData()[0].getName()); >+ } >+ return null; >+ } >+ >+ public Color getBackground(Object element, int columnIndex) { >+ if (((MyModel) element).counter % 2 == 0) { >+ return Display.getCurrent().getSystemColor(SWT.COLOR_RED); >+ } >+ return null; >+ } >+ >+ public Color getForeground(Object element, int columnIndex) { >+ if (((MyModel) element).counter % 2 == 1) { >+ return Display.getCurrent().getSystemColor(SWT.COLOR_RED); >+ } >+ return null; >+ } >+ >+ } >+ >+ public GridViewerSnippet1(Shell shell) { >+ final GridViewer v = new GridViewer(shell, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL); >+ v.setLabelProvider(new MyLabelProvider()); >+ v.setContentProvider(new MyContentProvider()); >+ v.getGrid().setCellSelectionEnabled(true); >+ >+ v.setCellEditors(new CellEditor[] { new TextCellEditor(v.getGrid()), new TextCellEditor(v.getGrid()) }); >+ v.setCellModifier(new ICellModifier() { >+ >+ public boolean canModify(Object element, String property) { >+ return true; >+ } >+ >+ public Object getValue(Object element, String property) { >+ return "Column " + property + " => " + element.toString(); >+ } >+ >+ public void modify(Object element, String property, Object value) { >+ >+ } >+ >+ }); >+ >+ v.setColumnProperties(new String[] {"1","2"}); >+ >+ v.setEditorActivationStrategy(new EditorActivationStrategy() { >+ protected boolean isEditorActivationEvent( >+ EditorActivationEvent event) { >+ return event.eventType == EditorActivationEvent.MOUSE_DOUBLE_CLICK_SELECTION || ( event.eventType == EditorActivationEvent.KEY_PRESSED && event.keyCode == SWT.CR ) || event.eventType == EditorActivationEvent.PROGRAMATIC; >+ } >+ }); >+ v.setEnableEditorActivationWithKeyboard(true); >+ v.setTabEditingStyle(EditingSupport.TABING_HORIZONTAL|EditingSupport.TABING_MOVE_TO_ROW_NEIGHBOR|EditingSupport.TABING_VERTICAL); >+ >+ GridColumn column = new GridColumn(v.getGrid(), SWT.NONE); >+ column.setWidth(200); >+ column.setText("Column 1"); >+ >+ column = new GridColumn(v.getGrid(), SWT.NONE); >+ column.setWidth(200); >+ column.setText("Column 2"); >+ >+ MyModel[] model = createModel(); >+ v.setInput(model); >+ v.getGrid().setLinesVisible(true); >+ v.getGrid().setHeaderVisible(true); >+ } >+ >+ private MyModel[] createModel() { >+ MyModel[] elements = new MyModel[10]; >+ >+ for (int i = 0; i < 10; i++) { >+ elements[i] = new MyModel(i); >+ } >+ >+ return elements; >+ } >+ >+ /** >+ * @param args >+ */ >+ public static void main(String[] args) { >+ Display display = new Display(); >+ >+ Shell shell = new Shell(display); >+ shell.setLayout(new FillLayout()); >+ new GridViewerSnippet1(shell); >+ shell.open(); >+ >+ while (!shell.isDisposed()) { >+ if (!display.readAndDispatch()) >+ display.sleep(); >+ } >+ >+ display.dispose(); >+ >+ } >+ >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 172646
:
58144
|
58157
|
58201
|
58739
|
58764
|
59015
|
59270
|
59808
|
59921
|
59931
|
60115
|
60666
|
61074
|
61075