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 58739 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]
Fixed to apply to CVS-HEAD after M5
clipboard17061.txt (text/plain), 86.31 KB, created by
Thomas Schindl
on 2007-02-11 11:25:18 EST
(
hide
)
Description:
Fixed to apply to CVS-HEAD after M5
Filename:
MIME Type:
Creator:
Thomas Schindl
Created:
2007-02-11 11:25:18 EST
Size:
86.31 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.75 >diff -u -r1.75 TableViewer.java >--- src/org/eclipse/jface/viewers/TableViewer.java 5 Feb 2007 02:49:28 -0000 1.75 >+++ src/org/eclipse/jface/viewers/TableViewer.java 11 Feb 2007 16:21:25 -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(); >- } >- > }; > } > >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.77 >diff -u -r1.77 TreeViewer.java >--- src/org/eclipse/jface/viewers/TreeViewer.java 5 Feb 2007 02:49:28 -0000 1.77 >+++ src/org/eclipse/jface/viewers/TreeViewer.java 11 Feb 2007 16:21:25 -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(); >- } >- > }; > } > >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.6 >diff -u -r1.6 EditingSupport.java >--- src/org/eclipse/jface/viewers/EditingSupport.java 4 Feb 2007 22:00:23 -0000 1.6 >+++ src/org/eclipse/jface/viewers/EditingSupport.java 11 Feb 2007 16:21:24 -0000 >@@ -13,6 +13,8 @@ > > package org.eclipse.jface.viewers; > >+import java.util.List; >+ > import org.eclipse.core.runtime.Assert; > import org.eclipse.swt.SWT; > import org.eclipse.swt.events.TraverseEvent; >@@ -170,8 +172,18 @@ > } > > if (cell2edit != null) { >- viewer.editElement(cell2edit.getElement(), cell2edit >- .getColumnIndex()); >+ List l = viewer.getSelectionFromWidget(); >+ >+ viewer.getControl().setRedraw(false); >+ >+ //TODO Is this correct in terms of other controls e.g. grid >+ if( ! l.contains(cell2edit.getElement()) ) { >+ viewer.setSelection(new StructuredSelection(cell2edit.getElement())); >+ } >+ >+ EditorActivationEvent acEvent = new EditorActivationEvent(cell2edit,event); >+ viewer.triggerEditorActivationEvent(acEvent); >+ viewer.getControl().setRedraw(true); > } > } > >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.24 >diff -u -r1.24 ColumnViewer.java >--- src/org/eclipse/jface/viewers/ColumnViewer.java 5 Feb 2007 04:55:37 -0000 1.24 >+++ src/org/eclipse/jface/viewers/ColumnViewer.java 11 Feb 2007 16:21:24 -0000 >@@ -14,6 +14,8 @@ > > package org.eclipse.jface.viewers; > >+import java.util.List; >+ > import org.eclipse.core.runtime.Assert; > import org.eclipse.swt.events.MouseAdapter; > import org.eclipse.swt.events.MouseEvent; >@@ -49,7 +51,7 @@ > private ColumnViewerEditor viewerEditor; > > private int tabEditingStyle = EditingSupport.TABBING_NONE; >- >+ > /** > * Create a new instance of the receiver. > */ >@@ -76,16 +78,18 @@ > if (viewerEditor != null) { > control.addMouseListener(new MouseAdapter() { > public void mouseDown(MouseEvent e) { >- viewerEditor.handleMouseDown(e); >+ handleMouseDown(e); > } > }); > } > } > > /** >- * Creates the viewer editor used for editing cell contents. To be implemented by subclasses. >+ * Creates the viewer editor used for editing cell contents. To be >+ * implemented by subclasses. > * >- * @return the editor, or <code>null</code> if this viewer does not support editing cell contents. >+ * @return the editor, or <code>null</code> if this viewer does not >+ * support editing cell contents. > */ > protected abstract ColumnViewerEditor createViewerEditor(); > >@@ -95,7 +99,8 @@ > * > * @param point > * the widget-relative coordinates >- * @return the cell or <code>null</code> if no cell is found at the given point >+ * @return the cell or <code>null</code> if no cell is found at the given >+ * point > */ > ViewerCell getCell(Point point) { > ViewerRow row = getViewerRow(point); >@@ -127,7 +132,8 @@ > /** > * Returns the viewer row associated with the given row widget. > * >- * @param item the row widget >+ * @param item >+ * the row widget > * @return ViewerRow the associated viewer row > */ > protected ViewerRow getViewerRowFromItem(Widget item) { >@@ -137,7 +143,8 @@ > /** > * Returns the column widget at the given column index. > * >- * @param columnIndex the column index >+ * @param columnIndex >+ * the column index > * @return Widget the column widget > */ > protected abstract Widget getColumnViewerOwner(int columnIndex); >@@ -150,7 +157,7 @@ > * @return the viewer column at the given index, or <code>null</code> if > * there is none for the given index > */ >- /* package */ ViewerColumn getViewerColumn(final int columnIndex) { >+ /* package */ViewerColumn getViewerColumn(final int columnIndex) { > > ViewerColumn viewer; > Widget columnOwner = getColumnViewerOwner(columnIndex); >@@ -176,7 +183,8 @@ > } > > /** >- * Sets up editing support for the given column based on the "old" cell editor API. >+ * Sets up editing support for the given column based on the "old" cell >+ * editor API. > * > * @param columnIndex > * @param viewer >@@ -229,15 +237,19 @@ > } > > /** >- * Creates a generic viewer column for the given column widget, based on the given label provider. >+ * Creates a generic viewer column for the given column widget, based on the >+ * given label provider. > * >- * @param columnOwner the column widget >- * @param labelProvider the label provider to use for the column >+ * @param columnOwner >+ * the column widget >+ * @param labelProvider >+ * the label provider to use for the column > * @return ViewerColumn the viewer column > */ > private ViewerColumn createViewerColumn(Widget columnOwner, > CellLabelProvider labelProvider) { >- ViewerColumn column = new ViewerColumn(this,columnOwner) {}; >+ ViewerColumn column = new ViewerColumn(this, columnOwner) { >+ }; > column.setLabelProvider(labelProvider, false); > return column; > } >@@ -269,19 +281,19 @@ > * @param column > * @return ViewerCell > */ >- /* package */ ViewerCell updateCell(ViewerRow rowItem, int column) { >+ /* package */ViewerCell updateCell(ViewerRow rowItem, int column) { > cell.update(rowItem, column); > return cell; > } > > /** > * Returns the {@link Item} at the given widget-relative coordinates, or >- * <code>null</code> if there is no item at the given coordinates. >+ * <code>null</code> if there is no item at the given coordinates. > * > * @param point > * the widget-relative coordinates >- * @return the {@link Item} at the coordinates or <code>null</code> if there >- * is no item at the given coordinates >+ * @return the {@link Item} at the coordinates or <code>null</code> if >+ * there is no item at the given coordinates > */ > protected abstract Item getItemAt(Point point); > >@@ -339,7 +351,7 @@ > > /** > * Cancels a currently active cell editor if one is active. All changes >- * already done in the cell editor are lost. >+ * already done in the cell editor are lost. > * > * @since 3.1 (in subclasses, added in 3.3 to abstract class) > */ >@@ -371,17 +383,37 @@ > */ > 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())); >+ } >+ >+ triggerEditorActivationEvent(new EditorActivationEvent( >+ cell)); >+ getControl().setRedraw(true); >+ } >+ } >+ } > } > } > > /** > * Return the CellEditors for the receiver, or <code>null</code> if no >- * cell editors are set. >+ * cell editors are set. > * <p> > * Since 3.3, an alternative API is available, see >- * {@link ViewerColumn#setEditingSupport(EditingSupport)} for a more flexible >- * way of editing values in a column viewer. >+ * {@link ViewerColumn#setEditingSupport(EditingSupport)} for a more >+ * flexible way of editing values in a column viewer. > * </p> > * > * @return CellEditor[] >@@ -398,12 +430,12 @@ > > /** > * Returns the cell modifier of this viewer, or <code>null</code> if none >- * has been set. >+ * has been set. > * > * <p> > * Since 3.3, an alternative API is available, see >- * {@link ViewerColumn#setEditingSupport(EditingSupport)} for a more flexible >- * way of editing values in a column viewer. >+ * {@link ViewerColumn#setEditingSupport(EditingSupport)} for a more >+ * flexible way of editing values in a column viewer. > * </p> > * > * @return the cell modifier, or <code>null</code> >@@ -425,8 +457,8 @@ > * > * <p> > * Since 3.3, an alternative API is available, see >- * {@link ViewerColumn#setEditingSupport(EditingSupport)} for a more flexible >- * way of editing values in a column viewer. >+ * {@link ViewerColumn#setEditingSupport(EditingSupport)} for a more >+ * flexible way of editing values in a column viewer. > * </p> > * > * @return the list of column properties >@@ -446,8 +478,8 @@ > * > * <p> > * Since 3.3, an alternative API is available, see >- * {@link ViewerColumn#setEditingSupport(EditingSupport)} for a more flexible >- * way of editing values in a column viewer. >+ * {@link ViewerColumn#setEditingSupport(EditingSupport)} for a more >+ * flexible way of editing values in a column viewer. > * </p> > * > * @return <code>true</code> if there is an active cell editor, and >@@ -469,8 +501,8 @@ > * > * <p> > * Since 3.3, an alternative API is available, see >- * {@link ViewerColumn#setEditingSupport(EditingSupport)} for a more flexible >- * way of editing values in a column viewer. >+ * {@link ViewerColumn#setEditingSupport(EditingSupport)} for a more >+ * flexible way of editing values in a column viewer. > * </p> > * > * @param editors >@@ -486,13 +518,13 @@ > } > > /** >- * Sets the cell modifier for this column viewer. This method does nothing if editing >- * is not supported by this viewer. >+ * Sets the cell modifier for this column viewer. This method does nothing >+ * if editing is not supported by this viewer. > * > * <p> > * Since 3.3, an alternative API is available, see >- * {@link ViewerColumn#setEditingSupport(EditingSupport)} for a more flexible >- * way of editing values in a column viewer. >+ * {@link ViewerColumn#setEditingSupport(EditingSupport)} for a more >+ * flexible way of editing values in a column viewer. > * </p> > * > * @param modifier >@@ -515,8 +547,8 @@ > * > * <p> > * Since 3.3, an alternative API is available, see >- * {@link ViewerColumn#setEditingSupport(EditingSupport)} for a more flexible >- * way of editing values in a column viewer. >+ * {@link ViewerColumn#setEditingSupport(EditingSupport)} for a more >+ * flexible way of editing values in a column viewer. > * </p> > * > * @param columnProperties >@@ -530,7 +562,7 @@ > viewerEditor.setColumnProperties(columnProperties); > } > } >- >+ > /** > * The tab-editing style used if the default implementation is used > * >@@ -544,7 +576,7 @@ > int getTabEditingStyle() { > return this.tabEditingStyle; > } >- >+ > /** > * 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 >@@ -576,4 +608,43 @@ > } > return null; > } >-} >+ >+ private void handleMouseDown(MouseEvent e) { >+ ViewerCell cell = getCell(new Point(e.x, e.y)); >+ >+ if (cell != null) { >+ triggerEditorActivationEvent(new EditorActivationEvent(cell, e)); >+ } >+ } >+ >+ /** >+ * Invoking this method fires an editor activation event which tries to >+ * enable the editor but before this event is passed to >+ * {@link ColumnViewerKeyboardSupport} to see if this event should >+ * really trigger editor activation >+ * >+ * @param event >+ * the activation event >+ */ >+ protected void triggerEditorActivationEvent(EditorActivationEvent event) { >+ viewerEditor.handleEditorActivationEvent(event); >+ } >+ >+ /** >+ * 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 setEditorActivationSupport( >+ ColumnViewerKeyboardSupport editorActivationStrategy) { >+ if (viewerEditor != null) { >+ viewerEditor.setEditorActivationStrategy(editorActivationStrategy); >+ } else { >+ throw new IllegalStateException( >+ "This feature is not supported by the widget"); //$NON-NLS-1$ >+ } >+ } >+} >\ No newline at end of file >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 11 Feb 2007 16:21:24 -0000 >@@ -853,4 +853,14 @@ > dirty = true; > fireEditorValueChanged(oldValidState, newValidState); > } >+ >+ /** >+ * 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(); >+ } > } >Index: src/org/eclipse/jface/viewers/ColumnViewerEditor.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jface/src/org/eclipse/jface/viewers/ColumnViewerEditor.java,v >retrieving revision 1.1 >diff -u -r1.1 ColumnViewerEditor.java >--- src/org/eclipse/jface/viewers/ColumnViewerEditor.java 5 Feb 2007 02:49:28 -0000 1.1 >+++ src/org/eclipse/jface/viewers/ColumnViewerEditor.java 11 Feb 2007 16:21:24 -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,26 @@ > > 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 ColumnViewerKeyboardSupport editorActivationStrategy; >+ > /** > * Create a new editor implementation for the viewer > * >@@ -70,6 +75,19 @@ > */ > public ColumnViewerEditor(ColumnViewer viewer) { > this.viewer = viewer; >+ editorActivationStrategy = new ColumnViewerKeyboardSupport(viewer) { >+ protected boolean isEditorActivationEvent(EditorActivationEvent event) { >+ return event.eventType == EditorActivationEvent.MOUSE_CLICK_SELECTION >+ || event.eventType == EditorActivationEvent.PROGRAMATIC >+ || event.eventType == EditorActivationEvent.TRAVERSAL; >+ } >+ >+ protected ViewerCell getFocusCell() { >+ return null; >+ } >+ >+ }; >+ > initCellEditorListener(); > } > >@@ -92,13 +110,25 @@ > > 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++ ) { >+ >+ if( activationEvent.cancle ) { >+ return; >+ } >+ >+ ((ColumnViewerEditorActivationListener)ls[i]).beforeEditorActivated(activationEvent); >+ } >+ } >+ > cellEditor.addListener(cellEditorListener); > Object value = part.getEditingSupport().getValue(element); > cellEditor.setValue(value); >@@ -108,12 +138,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 +158,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 +173,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++ ) { >+ ((ColumnViewerEditorActivationListener)ls[i]).afterEditorActivated(activationEvent); >+ } > } > } >- if (columnToEdit == -1) { >- return; >- } > } >- >- columnNumber = columnToEdit; >- activateCellEditor(); > } > > /** >@@ -203,8 +206,22 @@ > // 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++ ) { >+ >+ if( tmp.cancle ) { >+ return; >+ } >+ >+ ((ColumnViewerEditorActivationListener)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 +244,13 @@ > } > } > c.deactivate(); >+ >+ if( editorActivationListener != null && ! editorActivationListener.isEmpty() ) { >+ Object[] ls = editorActivationListener.getListeners(); >+ for( int i = 0; i < ls.length; i++ ) { >+ ((ColumnViewerEditorActivationListener)ls[i]).afterEditorDeactivated(tmp); >+ } >+ } > } > } > >@@ -235,6 +259,18 @@ > */ > 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++ ) { >+ if( tmp.cancle ) { >+ return; >+ } >+ >+ ((ColumnViewerEditorActivationListener)ls[i]).beforeEditorDeactivated(tmp); >+ } >+ } >+ > setEditor(null, null, 0); > cellEditor.removeListener(cellEditorListener); > >@@ -256,70 +292,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++ ) { >+ ((ColumnViewerEditorActivationListener)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 +396,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(ColumnViewerEditorActivationListener listener) { >+ if( editorActivationListener == null ) { >+ editorActivationListener = new ListenerList(); >+ } >+ editorActivationListener.add(listener); >+ } >+ >+ void removeEditorActivationListener(ColumnViewerEditorActivationListener listener) { >+ if( editorActivationListener != null ) { >+ editorActivationListener.remove(listener); >+ } >+ } >+ >+ void setEditorActivationStrategy( >+ ColumnViewerKeyboardSupport editorActivationStrategy) { >+ this.editorActivationStrategy = editorActivationStrategy; >+ } >+ > /** > * Create a selection for this model element > * >@@ -429,14 +448,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(); >-} >+} >\ No newline at end of file >Index: src/org/eclipse/jface/viewers/ColumnViewerKeyboardSupport.java >=================================================================== >RCS file: src/org/eclipse/jface/viewers/ColumnViewerKeyboardSupport.java >diff -N src/org/eclipse/jface/viewers/ColumnViewerKeyboardSupport.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/viewers/ColumnViewerKeyboardSupport.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,85 @@ >+/******************************************************************************* >+ * 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; >+ >+import org.eclipse.swt.events.KeyEvent; >+import org.eclipse.swt.events.KeyListener; >+ >+/** >+ * This class is responsible to determin if a cell selection event is triggers >+ * an editor activation >+ * >+ * @since 3.3 >+ */ >+public abstract class ColumnViewerKeyboardSupport { >+ private ColumnViewer viewer; >+ >+ private KeyListener keyboardActivationListener; >+ >+ /** >+ * @param viewer the viewer the editor support is attached to >+ */ >+ public ColumnViewerKeyboardSupport(ColumnViewer viewer) { >+ this.viewer = viewer; >+ } >+ >+ /** >+ * @return the cell holding the current focus >+ */ >+ protected abstract ViewerCell getFocusCell(); >+ >+ /** >+ * @param event >+ * @return bla bl >+ */ >+ protected abstract boolean isEditorActivationEvent(EditorActivationEvent event); >+ >+ /** >+ * @return the viewer >+ */ >+ public ColumnViewer getViewer() { >+ return viewer; >+ } >+ >+ /** >+ * 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 ) { >+ viewer.triggerEditorActivationEvent(new EditorActivationEvent(cell,e)); >+ } >+ } >+ >+ public void keyReleased(KeyEvent e) { >+ >+ } >+ >+ }; >+ viewer.getControl().addKeyListener(keyboardActivationListener); >+ } >+ } else { >+ if( keyboardActivationListener != null ) { >+ viewer.getControl().removeKeyListener(keyboardActivationListener); >+ keyboardActivationListener = null; >+ } >+ } >+ } >+ >+} >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,41 @@ >+/******************************************************************************* >+ * 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; >+ >+ /** >+ * Cancle the event >+ */ >+ public boolean cancle = false; >+ >+ /** >+ * @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,164 @@ >+/******************************************************************************* >+ * 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; >+ >+ /** >+ * Cancle the event (=> editor is not activated) >+ */ >+ public boolean cancle = false; >+ >+ /** >+ * 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/ColumnViewerEditorActivationListener.java >=================================================================== >RCS file: src/org/eclipse/jface/viewers/ColumnViewerEditorActivationListener.java >diff -N src/org/eclipse/jface/viewers/ColumnViewerEditorActivationListener.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/viewers/ColumnViewerEditorActivationListener.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 ColumnViewerEditorActivationListener { >+ /** >+ * 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); >+} >#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 11 Feb 2007 16:21:30 -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,208 @@ >+/******************************************************************************* >+ * 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.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.GridViewerKeyboardSupport; >+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"}); >+ >+ GridViewerKeyboardSupport support = new GridViewerKeyboardSupport(v) { >+ protected boolean isEditorActivationEvent( >+ EditorActivationEvent event) { >+ return event.eventType == EditorActivationEvent.TRAVERSAL || event.eventType == EditorActivationEvent.MOUSE_DOUBLE_CLICK_SELECTION || ( event.eventType == EditorActivationEvent.KEY_PRESSED && event.keyCode == SWT.CR ) || event.eventType == EditorActivationEvent.PROGRAMATIC; >+ } >+ }; >+ support.setEnableEditorActivationWithKeyboard(true); >+ >+ v.setEditorActivationSupport(support); >+ v.setTabEditingStyle(EditingSupport.TABBING_HORIZONTAL|EditingSupport.TABBING_MOVE_TO_ROW_NEIGHBOR|EditingSupport.TABBING_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(); >+ >+ } >+ >+} >#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 11 Feb 2007 16:21:33 -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 11 Feb 2007 16:21:33 -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 11 Feb 2007 16:21:33 -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.AbstractViewerEditor; >-import org.eclipse.jface.viewers.BaseTableViewer; >+import org.eclipse.jface.viewers.AbstractTableViewer; >+import org.eclipse.jface.viewers.ColumnViewerEditor; > 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 ColumnViewerEditor createViewerEditor() >+ { >+ return new ColumnViewerEditor(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); >- } >+ 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 11 Feb 2007 16:21:34 -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 11 Feb 2007 16:21:33 -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/GridViewerKeyboardSupport.java >=================================================================== >RCS file: src/org/eclipse/swt/nebula/nebface/viewers/GridViewerKeyboardSupport.java >diff -N src/org/eclipse/swt/nebula/nebface/viewers/GridViewerKeyboardSupport.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/swt/nebula/nebface/viewers/GridViewerKeyboardSupport.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,20 @@ >+package org.eclipse.swt.nebula.nebface.viewers; >+ >+import org.eclipse.jface.viewers.ColumnViewerKeyboardSupport; >+import org.eclipse.jface.viewers.EditorActivationEvent; >+import org.eclipse.jface.viewers.ViewerCell; >+ >+public class GridViewerKeyboardSupport extends ColumnViewerKeyboardSupport { >+ public GridViewerKeyboardSupport(GridViewer viewer) { >+ super(viewer); >+ } >+ >+ protected ViewerCell getFocusCell() { >+ return ((GridViewer)getViewer()).getFocusCell(); >+ } >+ >+ protected boolean isEditorActivationEvent(EditorActivationEvent event) { >+ return event.eventType == EditorActivationEvent.TRAVERSAL || event.eventType == EditorActivationEvent.MOUSE_DOUBLE_CLICK_SELECTION || event.eventType == EditorActivationEvent.PROGRAMATIC; >+ } >+ >+} >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.ColumnViewerEditor; >+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 ColumnViewerEditor createViewerEditor() >+ { >+ return new ColumnViewerEditor(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 >+ >+ } >+}
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