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 60115 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 small outstanding bugs
clipboard51944.txt (text/plain), 148.52 KB, created by
Thomas Schindl
on 2007-03-01 17:04:06 EST
(
hide
)
Description:
Fixed small outstanding bugs
Filename:
MIME Type:
Creator:
Thomas Schindl
Created:
2007-03-01 17:04:06 EST
Size:
148.52 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#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 1 Mar 2007 21:52:49 -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 1 Mar 2007 21:52:49 -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 1 Mar 2007 21:52:50 -0000 >@@ -1,22 +1,25 @@ > /******************************************************************************* >- * 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.ColumnViewerEditorActivationStrategy; > 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 +27,256 @@ > 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; >+ >+ /** >+ * 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; > 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) { >- return new StructuredSelection(element); >- } >- >- protected Item[] getSelection() { >- return getGrid().getSelection(); >- } >- >- 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; >- } >- >- protected void showSelection() { >- getGrid().showSelection(); >- } >- >- }; >- } >- >- protected void internalClear(int index) { >- // TODO NEEDS IMP >- } >- >- protected void internalClearAll() { >- // TODO NEEDS IMP >- } >- >- protected void internalDeselectAll() { >- grid.deselectAll(); >- } >- >- protected Widget internalGetColumn(int index) { >- return grid.getColumn(index); >- } >- >- protected int internalGetColumnCount() { >- return grid.getColumnCount(); >- } >- >- protected Widget[] internalGetColumns() { >- return grid.getColumns(); >- } >+ /** {@inheritDoc} */ >+ protected ColumnViewerEditor createViewerEditor() >+ { >+ return new GridViewerEditor(this,new ColumnViewerEditorActivationStrategy(this),ColumnViewerEditor.DEFAULT); >+ } > >- protected Item internalGetItem(int index) { >- return grid.getItem(index); >- } >+ /** {@inheritDoc} */ >+ protected void doClear(int index) >+ { >+ // TODO Fix when grid supports virtual >+ } > >- protected Item internalGetItem(Point point) { >- return grid.getItem(point); >- } >+ /** {@inheritDoc} */ >+ protected void doClearAll() >+ { >+ //TODO Fix when grid supports virtual >+ } >+ >+ /** {@inheritDoc} */ >+ protected void doSetItemCount(int count) >+ { >+ //TODO Once grid supports virtual >+ } > >- protected int internalGetItemCount() { >- return grid.getItemCount(); >- } >+ /** {@inheritDoc} */ >+ protected void doDeselectAll() >+ { >+ grid.deselectAll(); >+ } > >- protected Item[] internalGetItems() { >- return grid.getItems(); >- } >+ /** {@inheritDoc} */ >+ protected Widget doGetColumn(int index) >+ { >+ return grid.getColumn(index); >+ } > >- protected Widget[] internalGetSelection() { >- return grid.getSelection(); >- } >+ /** {@inheritDoc} */ >+ protected int doGetColumnCount() >+ { >+ return grid.getColumnCount(); >+ } > >- protected int[] internalGetSelectionIndices() { >- return grid.getSelectionIndices(); >- } >+ /** {@inheritDoc} */ >+ protected Item doGetItem(int index) >+ { >+ return grid.getItem(index); >+ } > >- protected int internalIndexOf(Item item) { >- return grid.indexOf((GridItem) item); >- } >+ /** {@inheritDoc} */ >+ protected int doGetItemCount() >+ { >+ return grid.getItemCount(); >+ } > >- protected void internalRemove(int start, int end) { >- grid.remove(start, end); >- } >+ /** {@inheritDoc} */ >+ protected Item[] doGetItems() >+ { >+ return grid.getItems(); >+ } > >- protected void internalRemove(int[] indices) { >- grid.remove(indices); >- } >+ /** {@inheritDoc} */ >+ protected Item[] doGetSelection() >+ { >+ return grid.getSelection(); >+ } > >- protected void internalRemoveAll() { >- grid.removeAll(); >- } >+ /** {@inheritDoc} */ >+ protected int[] doGetSelectionIndices() >+ { >+ return grid.getSelectionIndices(); >+ } > >- protected void internalSetItemCount(int count) { >- // TODO NEEDS IMP >- } >+ /** {@inheritDoc} */ >+ protected int doIndexOf(Item item) >+ { >+ return grid.indexOf((GridItem) item); >+ } > >- 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 doRemove(int[] indices) >+ { >+ grid.remove(indices); >+ } > >- } >+ /** {@inheritDoc} */ >+ protected void doRemove(int start, int end) >+ { >+ grid.remove(start, end); >+ } > >- protected void internalSetSelection(int[] indices) { >- grid.setSelection(indices); >- } >+ /** {@inheritDoc} */ >+ protected void doRemoveAll() >+ { >+ grid.removeAll(); >+ } > >- protected void internalShowItem(Item item) { >- grid.showItem((GridItem) item); >- } >+ /** {@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 internalShowSelection() { >- grid.showSelection(); >- } >+ /** {@inheritDoc} */ >+ protected void doSetSelection(int[] indices) >+ { >+ grid.setSelection(indices); >+ } > >- protected void internalSetControl(Control table) { >- grid = (Grid) table; >- } >+ /** {@inheritDoc} */ >+ protected void doShowItem(Item item) >+ { >+ grid.showItem((GridItem)item); >+ } > >- public Control getControl() { >- return grid; >- } >+ /** {@inheritDoc} */ >+ protected void doShowSelection() >+ { >+ grid.showSelection(); >+ } > >+ /** {@inheritDoc} */ > protected Item getItemAt(Point point) > { > return grid.getItem(point); > } > >+ /** {@inheritDoc} */ >+ public Control getControl() >+ { >+ return grid; >+ } >+ >+ /** {@inheritDoc} */ >+ protected ViewerRow getViewerRowFromItem(Widget item) >+ { >+ ViewerRow part = (ViewerRow) item.getData(ViewerRow.ROWPART_KEY); >+ >+ if (part == null) >+ { >+ part = new GridViewerRow(((GridItem) item)); >+ } >+ >+ return part; >+ } >+ >+ >+ >+ 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); >+ } >+ } > } >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 1 Mar 2007 21:52:51 -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 1 Mar 2007 21:52:50 -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.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 >+ >+ } >+} >Index: src/org/eclipse/swt/nebula/nebface/viewers/GridViewerEditor.java >=================================================================== >RCS file: src/org/eclipse/swt/nebula/nebface/viewers/GridViewerEditor.java >diff -N src/org/eclipse/swt/nebula/nebface/viewers/GridViewerEditor.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/swt/nebula/nebface/viewers/GridViewerEditor.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,70 @@ >+package org.eclipse.swt.nebula.nebface.viewers; >+ >+import org.eclipse.jface.viewers.ColumnViewerEditor; >+import org.eclipse.jface.viewers.ColumnViewerEditorActivationStrategy; >+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.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.Control; >+import org.eclipse.swt.widgets.Item; >+ >+public class GridViewerEditor extends ColumnViewerEditor { >+ /** Editor support for tables. */ >+ private GridEditor gridEditor; >+ >+ public GridViewerEditor(GridViewer viewer, >+ ColumnViewerEditorActivationStrategy editorActivationStrategy, >+ int feature) { >+ super(viewer, editorActivationStrategy, feature); >+ this.gridEditor = new GridEditor(viewer.getGrid()); >+ } >+ >+ protected StructuredSelection createSelection(Object element) >+ { >+ 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; >+ } >+ >+ public ViewerCell getFocusCell() { >+ Grid grid = ((GridViewer)getViewer()).getGrid(); >+ >+ if( grid.getCellSelectionEnabled() ) { >+ Point p = grid.getFocusCell(); >+ >+ if( p.x >= 0 && p.y >= 0 ) { >+ GridItem item = grid.getItem(p.y); >+ if( item != null ) { >+ ViewerRow row = (ViewerRow) item.getData(ViewerRow.ROWPART_KEY); >+ return row.getCell(p.x); >+ } >+ } >+ } >+ >+ return null; >+ } >+ >+ protected void updateFocusCell(ViewerCell focusCell) { >+ Grid grid = ((GridViewer)getViewer()).getGrid(); >+ >+ if( grid.getCellSelectionEnabled() ) { >+ //TODO CHRIS WE NEED SOMETHING LIKE >+ // grid.setFocusCell(); >+ } >+ } >+} >#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.4 >diff -u -r1.4 MANIFEST.MF >--- META-INF/MANIFEST.MF 25 Feb 2007 16:03:35 -0000 1.4 >+++ META-INF/MANIFEST.MF 1 Mar 2007 21:52:52 -0000 >@@ -6,6 +6,7 @@ > Bundle-Localization: plugin > Require-Bundle: org.eclipse.swt, > org.eclipse.swt.nebula, >- org.eclipse.nebula.widgets.gallery >+ org.eclipse.nebula.widgets.gallery, >+ org.eclipse.swt.nebula.nebface > Export-Package: org.eclipse.swt.nebula.snippets.ctree, > 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,216 @@ >+/******************************************************************************* >+ * 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.ColumnViewerEditor; >+import org.eclipse.jface.viewers.ColumnViewerEditorActivationEvent; >+import org.eclipse.jface.viewers.ColumnViewerEditorActivationStrategy; >+import org.eclipse.jface.viewers.EditingSupport; >+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.TreeViewerEditor; >+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.GridViewerEditor; >+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"}); >+ >+ ColumnViewerEditorActivationStrategy actSupport = new ColumnViewerEditorActivationStrategy(v) { >+ protected boolean isEditorActivationEvent( >+ ColumnViewerEditorActivationEvent event) { >+ return event.eventType == ColumnViewerEditorActivationEvent.TRAVERSAL >+ || event.eventType == ColumnViewerEditorActivationEvent.MOUSE_DOUBLE_CLICK_SELECTION >+ || (event.eventType == ColumnViewerEditorActivationEvent.KEY_PRESSED && event.keyCode == SWT.CR) >+ || event.eventType == ColumnViewerEditorActivationEvent.PROGRAMATIC; >+ } >+ }; >+ >+ GridViewerEditor gridViewerEditor = new GridViewerEditor(v, actSupport, ColumnViewerEditor.TABBING_HORIZONTAL >+ | ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR >+ | ColumnViewerEditor.TABBING_VERTICAL | ColumnViewerEditor.KEYBOARD_ACTIVATION); >+ >+ v.setColumnViewerEditor(gridViewerEditor); >+ >+ 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.jface.snippets >Index: Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet025TabEditing.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet025TabEditing.java,v >retrieving revision 1.2 >diff -u -r1.2 Snippet025TabEditing.java >--- Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet025TabEditing.java 4 Feb 2007 22:00:22 -0000 1.2 >+++ Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet025TabEditing.java 1 Mar 2007 21:52:54 -0000 >@@ -12,10 +12,13 @@ > package org.eclipse.jface.snippets.viewers; > > import org.eclipse.jface.viewers.CellEditor; >+import org.eclipse.jface.viewers.ColumnViewerEditor; >+import org.eclipse.jface.viewers.ColumnViewerEditorActivationStrategy; > import org.eclipse.jface.viewers.EditingSupport; > import org.eclipse.jface.viewers.ICellModifier; > import org.eclipse.jface.viewers.IStructuredContentProvider; > import org.eclipse.jface.viewers.LabelProvider; >+import org.eclipse.jface.viewers.TableViewerEditor; > import org.eclipse.jface.viewers.TableViewer; > import org.eclipse.jface.viewers.TextCellEditor; > import org.eclipse.jface.viewers.Viewer; >@@ -111,8 +114,7 @@ > > v.setColumnProperties(new String[] { "column1", "column2" }); > v.setCellEditors(new CellEditor[] { new TextCellEditor(v.getTable()), new TextCellEditor(v.getTable()) }); >- v.setTabEditingStyle(EditingSupport.TABBING_HORIZONTAL|EditingSupport.TABBING_MOVE_TO_ROW_NEIGHBOR|EditingSupport.TABBING_VERTICAL); >- >+ TableViewerEditor.create(v,new ColumnViewerEditorActivationStrategy(v),ColumnViewerEditor.TABBING_HORIZONTAL|ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR|ColumnViewerEditor.TABBING_VERTICAL); > > MyModel[] model = createModel(); > v.setInput(model); >Index: Eclipse JFace Snippets/org/eclipse/jface/snippets/window/Snippet020CustomizedControlTooltips.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/window/Snippet020CustomizedControlTooltips.java,v >retrieving revision 1.2 >diff -u -r1.2 Snippet020CustomizedControlTooltips.java >--- Eclipse JFace Snippets/org/eclipse/jface/snippets/window/Snippet020CustomizedControlTooltips.java 12 Dec 2006 19:30:30 -0000 1.2 >+++ Eclipse JFace Snippets/org/eclipse/jface/snippets/window/Snippet020CustomizedControlTooltips.java 1 Mar 2007 21:52:55 -0000 >@@ -22,12 +22,14 @@ > import org.eclipse.swt.events.MouseEvent; > import org.eclipse.swt.events.SelectionAdapter; > import org.eclipse.swt.events.SelectionEvent; >+import org.eclipse.swt.events.SelectionListener; > import org.eclipse.swt.graphics.Point; > import org.eclipse.swt.graphics.RGB; > import org.eclipse.swt.layout.FillLayout; > import org.eclipse.swt.layout.GridData; > import org.eclipse.swt.layout.GridLayout; > import org.eclipse.swt.layout.RowLayout; >+import org.eclipse.swt.widgets.Button; > import org.eclipse.swt.widgets.Composite; > import org.eclipse.swt.widgets.Control; > import org.eclipse.swt.widgets.Display; >@@ -207,6 +209,22 @@ > DefaultToolTip toolTip = new DefaultToolTip(text); > toolTip.setText("Hello World\nHello World"); > toolTip.setBackgroundColor(parent.getDisplay().getSystemColor(SWT.COLOR_RED)); >+ >+ Button b = new Button(parent,SWT.PUSH); >+ b.setText("Popup on press"); >+ >+ final DefaultToolTip toolTipDelayed = new DefaultToolTip(b,true); >+ toolTipDelayed.setText("Hello World\nHello World"); >+ toolTipDelayed.setBackgroundColor(parent.getDisplay().getSystemColor(SWT.COLOR_RED)); >+ toolTipDelayed.setHideDelay(2000); >+ >+ b.addSelectionListener(new SelectionAdapter() { >+ public void widgetSelected(SelectionEvent e) { >+ toolTipDelayed.start(new Point(0,0)); >+ } >+ }); >+ >+ > } > > public static void main(String[] args) { >Index: Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet026TreeViewerTabEditing.java >=================================================================== >RCS file: Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet026TreeViewerTabEditing.java >diff -N Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet026TreeViewerTabEditing.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet026TreeViewerTabEditing.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,223 @@ >+/******************************************************************************* >+ * 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.jface.snippets.viewers; >+ >+import java.util.ArrayList; >+ >+import org.eclipse.jface.viewers.CellEditor; >+import org.eclipse.jface.viewers.CellNavigationStrategy; >+import org.eclipse.jface.viewers.ColumnLabelProvider; >+import org.eclipse.jface.viewers.ColumnViewerEditor; >+import org.eclipse.jface.viewers.ColumnViewerEditorActivationStrategy; >+import org.eclipse.jface.viewers.EditingSupport; >+import org.eclipse.jface.viewers.ColumnViewerEditorActivationEvent; >+import org.eclipse.jface.viewers.FocusCellOwnerDrawHighlighter; >+import org.eclipse.jface.viewers.ITreeContentProvider; >+import org.eclipse.jface.viewers.TextCellEditor; >+import org.eclipse.jface.viewers.TreeViewerFocusCellManager; >+import org.eclipse.jface.viewers.TreeViewerEditor; >+import org.eclipse.jface.viewers.TreeViewer; >+import org.eclipse.jface.viewers.TreeViewerColumn; >+import org.eclipse.jface.viewers.Viewer; >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.layout.FillLayout; >+import org.eclipse.swt.widgets.Button; >+import org.eclipse.swt.widgets.Display; >+import org.eclipse.swt.widgets.Shell; >+ >+/** >+ * A simple TreeViewer to demonstrate usage >+ * >+ * @author Tom Schindl <tom.schindl@bestsolution.at> >+ * >+ */ >+public class Snippet026TreeViewerTabEditing { >+ public Snippet026TreeViewerTabEditing(final Shell shell) { >+ Button b = new Button(shell,SWT.PUSH); >+ b.setText("BBB"); >+ final TreeViewer v = new TreeViewer(shell, SWT.BORDER >+ | SWT.FULL_SELECTION); >+ v.getTree().setLinesVisible(true); >+ v.getTree().setHeaderVisible(true); >+ >+ >+ TreeViewerFocusCellManager focusCellManager = new TreeViewerFocusCellManager(v,new FocusCellOwnerDrawHighlighter(v)); >+ ColumnViewerEditorActivationStrategy actSupport = new ColumnViewerEditorActivationStrategy(v) { >+ protected boolean isEditorActivationEvent( >+ ColumnViewerEditorActivationEvent event) { >+ return event.eventType == ColumnViewerEditorActivationEvent.TRAVERSAL >+ || event.eventType == ColumnViewerEditorActivationEvent.MOUSE_DOUBLE_CLICK_SELECTION >+ || (event.eventType == ColumnViewerEditorActivationEvent.KEY_PRESSED && event.keyCode == SWT.CR) >+ || event.eventType == ColumnViewerEditorActivationEvent.PROGRAMATIC; >+ } >+ }; >+ >+ TreeViewerEditor.create(v, focusCellManager, actSupport, ColumnViewerEditor.TABBING_HORIZONTAL >+ | ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR >+ | ColumnViewerEditor.TABBING_VERTICAL | ColumnViewerEditor.KEYBOARD_ACTIVATION); >+ >+ final TextCellEditor textCellEditor = new TextCellEditor(v.getTree()); >+ >+ TreeViewerColumn column = new TreeViewerColumn(v, SWT.NONE); >+ column.getColumn().setWidth(200); >+ column.getColumn().setText("Column 1"); >+ column.setLabelProvider(new ColumnLabelProvider() { >+ >+ public String getText(Object element) { >+ return "Column 1 => " + element.toString(); >+ } >+ >+ }); >+ column.setEditingSupport(new EditingSupport(v) { >+ protected boolean canEdit(Object element) { >+ return true; >+ } >+ >+ protected CellEditor getCellEditor(Object element) { >+ return textCellEditor; >+ } >+ >+ protected Object getValue(Object element) { >+ return ((MyModel) element).counter + ""; >+ } >+ >+ protected void setValue(Object element, Object value) { >+ ((MyModel) element).counter = Integer >+ .parseInt(value.toString()); >+ v.update(element, null); >+ } >+ }); >+ >+ column = new TreeViewerColumn(v, SWT.NONE); >+ column.getColumn().setWidth(200); >+ column.getColumn().setText("Column 2"); >+ column.setLabelProvider(new ColumnLabelProvider() { >+ >+ public String getText(Object element) { >+ return "Column 2 => " + element.toString(); >+ } >+ >+ }); >+ column.setEditingSupport(new EditingSupport(v) { >+ protected boolean canEdit(Object element) { >+ return true; >+ } >+ >+ protected CellEditor getCellEditor(Object element) { >+ return textCellEditor; >+ } >+ >+ protected Object getValue(Object element) { >+ return ((MyModel) element).counter + ""; >+ } >+ >+ protected void setValue(Object element, Object value) { >+ ((MyModel) element).counter = Integer >+ .parseInt(value.toString()); >+ v.update(element, null); >+ } >+ }); >+ >+ v.setContentProvider(new MyContentProvider()); >+ >+ v.setInput(createModel()); >+ } >+ >+ private MyModel createModel() { >+ >+ MyModel root = new MyModel(0, null); >+ root.counter = 0; >+ >+ MyModel tmp; >+ MyModel subItem; >+ for (int i = 1; i < 10; i++) { >+ tmp = new MyModel(i, root); >+ root.child.add(tmp); >+ for (int j = 1; j < i; j++) { >+ subItem = new MyModel(j, tmp); >+ subItem.child.add(new MyModel(j * 100, subItem)); >+ tmp.child.add(subItem); >+ } >+ } >+ >+ return root; >+ } >+ >+ public static void main(String[] args) { >+ Display display = new Display(); >+ Shell shell = new Shell(display); >+ shell.setLayout(new FillLayout()); >+ new Snippet026TreeViewerTabEditing(shell); >+ shell.open(); >+ >+ while (!shell.isDisposed()) { >+ if (!display.readAndDispatch()) >+ display.sleep(); >+ } >+ >+ display.dispose(); >+ } >+ >+ private class MyContentProvider implements ITreeContentProvider { >+ >+ public Object[] getElements(Object inputElement) { >+ return ((MyModel) inputElement).child.toArray(); >+ } >+ >+ public void dispose() { >+ } >+ >+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { >+ } >+ >+ public Object[] getChildren(Object parentElement) { >+ return getElements(parentElement); >+ } >+ >+ public Object getParent(Object element) { >+ if (element == null) { >+ return null; >+ } >+ return ((MyModel) element).parent; >+ } >+ >+ public boolean hasChildren(Object element) { >+ return ((MyModel) element).child.size() > 0; >+ } >+ >+ } >+ >+ public class MyModel { >+ public MyModel parent; >+ >+ public ArrayList child = new ArrayList(); >+ >+ public int counter; >+ >+ public MyModel(int counter, MyModel parent) { >+ this.parent = parent; >+ this.counter = counter; >+ } >+ >+ public String toString() { >+ String rv = "Item "; >+ if (parent != null) { >+ rv = parent.toString() + "."; >+ } >+ >+ rv += counter; >+ >+ return rv; >+ } >+ } >+ >+} >#P org.eclipse.jface >Index: src/org/eclipse/jface/window/DefaultToolTip.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jface/src/org/eclipse/jface/window/DefaultToolTip.java,v >retrieving revision 1.3 >diff -u -r1.3 DefaultToolTip.java >--- src/org/eclipse/jface/window/DefaultToolTip.java 17 Nov 2006 16:27:04 -0000 1.3 >+++ src/org/eclipse/jface/window/DefaultToolTip.java 1 Mar 2007 21:53:04 -0000 >@@ -52,6 +52,14 @@ > } > > /** >+ * @param control >+ * @param delayActivation >+ */ >+ public DefaultToolTip(Control control, boolean delayActivation) { >+ super(control, delayActivation); >+ } >+ >+ /** > * Creates the content are of the the tooltip. By default this creates a > * CLabel to display text. To customize the text Subclasses may override the > * following methods >Index: src/org/eclipse/jface/window/ToolTip.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jface/src/org/eclipse/jface/window/ToolTip.java,v >retrieving revision 1.4 >diff -u -r1.4 ToolTip.java >--- src/org/eclipse/jface/window/ToolTip.java 22 Dec 2006 17:38:32 -0000 1.4 >+++ src/org/eclipse/jface/window/ToolTip.java 1 Mar 2007 21:53:05 -0000 >@@ -67,6 +67,18 @@ > * the control on whose action the tooltip is shown > */ > public ToolTip(Control control) { >+ this(control, false); >+ } >+ >+ /** >+ * @param control >+ * the control to which the tooltip is bound >+ * @param delayActivation >+ * <code>true</code> if the activation be delayed. This can be >+ * used to programmatically start up the ToolTip using >+ * {@link #start(Point)} >+ */ >+ public ToolTip(Control control, boolean delayActivation) { > this.control = control; > this.control.addDisposeListener(new DisposeListener() { > >@@ -77,7 +89,10 @@ > }); > > this.listener = new ToolTipOwnerControlListener(); >- activate(); >+ >+ if (!delayActivation) { >+ activate(); >+ } > } > > /** >@@ -206,6 +221,20 @@ > return true; > } > >+ /** >+ * Start up the tooltip programmatically >+ * >+ * @param location >+ * the location relative to the control the tooltip is shown >+ */ >+ public void start(Point location) { >+ Event event = new Event(); >+ event.x = location.x; >+ event.y = location.y; >+ event.widget = control; >+ toolTipCreate(event); >+ } >+ > private Shell toolTipCreate(final Event event) { > if (shouldCreateToolTip(event)) { > Shell shell = new Shell(control.getShell(), SWT.ON_TOP | SWT.TOOL >@@ -241,24 +270,24 @@ > Rectangle bounds; > Point rightBounds = new Point(tipSize.x + location.x, tipSize.y > + location.y); >- >+ > Monitor[] ms = control.getDisplay().getMonitors(); >- >+ > if (respectMonitorBounds && ms.length > 1) { > // By default present in the monitor of the control > bounds = control.getMonitor().getBounds(); >- Point p = new Point(location.x,location.y); >- >+ Point p = new Point(location.x, location.y); >+ > // Search on which monitor the event occurred > Rectangle tmp; >- for( int i = 0; i < ms.length; i++ ) { >+ for (int i = 0; i < ms.length; i++) { > tmp = ms[i].getBounds(); >- if( tmp.contains(p) ) { >+ if (tmp.contains(p)) { > bounds = tmp; > break; > } > } >- >+ > } else { > bounds = control.getDisplay().getBounds(); > } >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 1 Mar 2007 21:53:02 -0000 >@@ -16,9 +16,7 @@ > > > import org.eclipse.core.runtime.Assert; >-import org.eclipse.jface.viewers.CellEditor.LayoutData; > import org.eclipse.swt.SWT; >-import org.eclipse.swt.custom.TableEditor; > import org.eclipse.swt.graphics.Image; > import org.eclipse.swt.graphics.Point; > import org.eclipse.swt.widgets.Composite; >@@ -67,11 +65,6 @@ > private Table table; > > /** >- * This viewer's table editor. >- */ >- private TableEditor tableEditor; >- >- /** > * Creates a table viewer on a newly-created table control under the given > * parent. The table control is created using the SWT style bits > * <code>MULTI, H_SCROLL, V_SCROLL,</code> and <code>BORDER</code>. The >@@ -110,7 +103,6 @@ > */ > public TableViewer(Table table) { > this.table = table; >- tableEditor = new TableEditor(table); > hookControl(table); > } > >@@ -128,31 +120,7 @@ > } > > protected ColumnViewerEditor createViewerEditor() { >- return new ColumnViewerEditor(this) { >- >- protected StructuredSelection createSelection(Object element) { >- 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); >- } >- >- protected void setLayoutData(LayoutData layoutData) { >- tableEditor.grabHorizontal = layoutData.grabHorizontal; >- tableEditor.horizontalAlignment = layoutData.horizontalAlignment; >- tableEditor.minimumWidth = layoutData.minimumWidth; >- } >- >- protected void showSelection() { >- table.showSelection(); >- } >- >- }; >+ return new TableViewerEditor(this,null,new ColumnViewerEditorActivationStrategy(this),ColumnViewerEditor.DEFAULT); > } > > /** >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 1 Mar 2007 21:53:04 -0000 >@@ -16,9 +16,7 @@ > import java.util.List; > > import org.eclipse.jface.util.Policy; >-import org.eclipse.jface.viewers.CellEditor.LayoutData; > import org.eclipse.swt.SWT; >-import org.eclipse.swt.custom.TreeEditor; > import org.eclipse.swt.events.DisposeEvent; > import org.eclipse.swt.events.DisposeListener; > import org.eclipse.swt.events.TreeEvent; >@@ -63,11 +61,6 @@ > private Tree tree; > > /** >- * This viewer's tree editor. >- */ >- private TreeEditor treeEditor; >- >- /** > * Flag for whether the tree has been disposed of. > */ > private boolean treeIsDisposed = false; >@@ -116,7 +109,6 @@ > super(); > this.tree = tree; > hookControl(tree); >- treeEditor = new TreeEditor(tree); > } > > /* >@@ -274,35 +266,7 @@ > } > > 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 Item[] getSelection() { >- return tree.getSelection(); >- } >- >- protected void setEditor(Control w, Item item, int fColumnNumber) { >- treeEditor.setEditor(w, (TreeItem) item, fColumnNumber); >- } >- >- protected void setLayoutData(LayoutData layoutData) { >- treeEditor.grabHorizontal = layoutData.grabHorizontal; >- treeEditor.horizontalAlignment = layoutData.horizontalAlignment; >- treeEditor.minimumWidth = layoutData.minimumWidth; >- } >- >- protected void showSelection() { >- getTree().showSelection(); >- } >- >- }; >+ return new TreeViewerEditor(this,null,new ColumnViewerEditorActivationStrategy(this),ColumnViewerEditor.DEFAULT); > } > > /* >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 1 Mar 2007 21:53:01 -0000 >@@ -14,8 +14,6 @@ > package org.eclipse.jface.viewers; > > import org.eclipse.core.runtime.Assert; >-import org.eclipse.swt.SWT; >-import org.eclipse.swt.events.TraverseEvent; > > /** > * EditingSupport is the abstract superclass of the support for cell editing. >@@ -27,32 +25,6 @@ > * > */ > public abstract class EditingSupport { >- /** >- * Tabing from cell to cell is turned off >- */ >- public static final int TABBING_NONE = 1; >- >- /** >- * Should if the end of the row is reach started from the start/end of the >- * row below/above >- */ >- public static final int TABBING_MOVE_TO_ROW_NEIGHBOR = 1 << 1; >- >- /** >- * Should if the end of the row is reach started from the beginning in the >- * same row >- */ >- public static final int TABBING_CYCLE_IN_ROW = 1 << 2; >- >- /** >- * Support tabing to Cell above/below the current cell >- */ >- public static final int TABBING_VERTICAL = 1 << 3; >- >- /** >- * Should tabing from column to column with in one row be supported >- */ >- public static final int TABBING_HORIZONTAL = 1 << 4; > > private ColumnViewer viewer; > >@@ -61,7 +33,7 @@ > * a new viewer > */ > public EditingSupport(ColumnViewer viewer) { >- Assert.isNotNull(viewer,"Viewer is not allowed to be null"); //$NON-NLS-1$ >+ Assert.isNotNull(viewer, "Viewer is not allowed to be null"); //$NON-NLS-1$ > this.viewer = viewer; > } > >@@ -95,7 +67,9 @@ > /** > * Restore the value from the CellEditor > * >- * <p><b>Subclasses should overwrite!</b></p> >+ * <p> >+ * <b>Subclasses should overwrite!</b> >+ * </p> > * > * @param element > * the model element >@@ -105,174 +79,28 @@ > protected abstract void setValue(Object element, Object value); > > /** >- * @return <code>true</code> if tabing supported >- */ >- protected boolean isTabingSupported() { >- return (TABBING_NONE & getTabingStyle()) != TABBING_NONE; >- } >- >- /** >- * @return the bit mask representing the tabing style >+ * @return the viewer this editing support works for > */ >- int getTabingStyle() { >- return viewer.getTabEditingStyle(); >+ public ColumnViewer getViewer() { >+ return viewer; > } > > /** >- * Process the travers event and opens the next available editor depending >- * of the implemented strategy. The default implementation uses the style >- * constants >- * <ul> >- * <li>{@link #TABBING_MOVE_TO_ROW_NEIGHBOR}</li> >- * <li>{@link #TABBING_CYCLE_IN_ROW}</li> >- * <li>{@link #TABBING_VERTICAL}</li> >- * <li>{@link #TABBING_HORIZONTAL}</li> >- * </ul> >- * >- * <p> >- * Subclasses may overwrite to implement their custom logic to edit the next >- * cell >- * </p> >- * >- * @param columnIndex >- * the index of the current column >- * @param row >- * the current row >- * @param event >- * the travers event >+ * @param cellEditor >+ * the cell editor >+ * @param value >+ * the value to set the editor to > */ >- protected void processTraversEvent(int columnIndex, >- ViewerRow row, TraverseEvent event) { >- >- ViewerCell cell2edit = null; >- >- if (event.detail == SWT.TRAVERSE_TAB_PREVIOUS) { >- event.doit = false; >- >- if ((event.stateMask & SWT.CTRL) == SWT.CTRL >- && (getTabingStyle() & TABBING_VERTICAL) == TABBING_VERTICAL) { >- cell2edit = searchCellAboveBelow(row, viewer, columnIndex, true); >- } else if ((getTabingStyle() & TABBING_HORIZONTAL) == TABBING_HORIZONTAL) { >- cell2edit = searchPreviousCell(row, viewer, columnIndex, >- columnIndex); >- } >- } else if (event.detail == SWT.TRAVERSE_TAB_NEXT) { >- event.doit = false; >- >- if ((event.stateMask & SWT.CTRL) == SWT.CTRL >- && (getTabingStyle() & TABBING_VERTICAL) == TABBING_VERTICAL) { >- cell2edit = searchCellAboveBelow(row, viewer, columnIndex, >- false); >- } else if ((getTabingStyle() & TABBING_HORIZONTAL) == TABBING_HORIZONTAL) { >- cell2edit = searchNextCell(row, viewer, columnIndex, >- columnIndex); >- } >- } >- >- if (cell2edit != null) { >- viewer.editElement(cell2edit.getElement(), cell2edit >- .getColumnIndex()); >- } >- } >- >- private ViewerCell searchCellAboveBelow(ViewerRow row, ColumnViewer viewer, >- int columnIndex, boolean above) { >- ViewerCell rv = null; >- >- ViewerRow newRow = null; >- >- if (above) { >- newRow = row.getNeighbor(ViewerRow.ABOVE, false); >- } else { >- newRow = row.getNeighbor(ViewerRow.BELOW,false); >- } >- >- if (newRow != null) { >- ViewerColumn column = viewer.getViewerColumn(columnIndex); >- if (column != null >- && column.getEditingSupport().canEdit( >- newRow.getItem().getData())) { >- rv = newRow.getCell(columnIndex); >- } else { >- rv = searchCellAboveBelow(newRow, viewer, columnIndex, above); >- } >- } >- >- return rv; >- } >- >- private ViewerCell searchPreviousCell(ViewerRow row, ColumnViewer viewer, >- int columnIndex, int startIndex) { >- ViewerCell rv = null; >- >- if (columnIndex - 1 >= 0) { >- ViewerColumn column = viewer.getViewerColumn(columnIndex - 1); >- if (column != null >- && column.getEditingSupport().canEdit( >- row.getItem().getData())) { >- rv = row.getCell(columnIndex - 1); >- } else { >- rv = searchPreviousCell(row, viewer, columnIndex - 1, >- startIndex); >- } >- } else { >- if ((getTabingStyle() & TABBING_CYCLE_IN_ROW) == TABBING_CYCLE_IN_ROW) { >- // Check that we don't get into endless loop >- if (columnIndex - 1 != startIndex) { >- // Don't subtract -1 from getColumnCount() we need to >- // start in the virtual column >- // next to it >- rv = searchPreviousCell(row, viewer, row.getColumnCount(), >- startIndex); >- } >- } else if ((getTabingStyle() & TABBING_MOVE_TO_ROW_NEIGHBOR) == TABBING_MOVE_TO_ROW_NEIGHBOR) { >- ViewerRow rowAbove = row.getNeighbor(ViewerRow.ABOVE,false); >- if (rowAbove != null) { >- rv = searchPreviousCell(rowAbove, viewer, rowAbove >- .getColumnCount(), startIndex); >- } >- } >- } >- >- return rv; >+ protected void setCellEditorValue(CellEditor cellEditor, Object value) { >+ cellEditor.setValue(value); > } > >- private ViewerCell searchNextCell(ViewerRow row, ColumnViewer viewer, >- int columnIndex, int startIndex) { >- ViewerCell rv = null; >- >- if (columnIndex + 1 < row.getColumnCount()) { >- ViewerColumn column = viewer.getViewerColumn(columnIndex + 1); >- if (column != null >- && column.getEditingSupport().canEdit( >- row.getItem().getData())) { >- rv = row.getCell(columnIndex + 1); >- } else { >- rv = searchNextCell(row, viewer, columnIndex + 1, startIndex); >- } >- } else { >- if ((getTabingStyle() & TABBING_CYCLE_IN_ROW) == TABBING_CYCLE_IN_ROW) { >- // Check that we don't get into endless loop >- if (columnIndex + 1 != startIndex) { >- // Start from -1 from the virtual column before the >- // first one >- rv = searchNextCell(row, viewer, -1, startIndex); >- } >- } else if ((getTabingStyle() & TABBING_MOVE_TO_ROW_NEIGHBOR) == TABBING_MOVE_TO_ROW_NEIGHBOR) { >- ViewerRow rowBelow = row.getNeighbor(ViewerRow.BELOW,false); >- if (rowBelow != null) { >- rv = searchNextCell(rowBelow, viewer, -1, startIndex); >- } >- } >- } >- >- return rv; >- } >- > /** >- * @return the viewer this editing support works for >+ * @param cellEditor >+ * the cell-editor >+ * @return the value retrieved from cell-editor > */ >- public ColumnViewer getViewer() { >- return viewer; >+ protected Object getCellEditorValue(CellEditor cellEditor) { >+ return cellEditor.getValue(); > } > } >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 1 Mar 2007 21:53:00 -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; >@@ -38,6 +40,11 @@ > * > */ > public abstract class ColumnViewer extends StructuredViewer { >+ private CellEditor[] cellEditors; >+ >+ private ICellModifier cellModifier; >+ >+ private String[] columnProperties; > > private ToolTipSupport tooltipSupport; > >@@ -48,17 +55,16 @@ > > private ColumnViewerEditor viewerEditor; > >- private int tabEditingStyle = EditingSupport.TABBING_NONE; >- > /** > * Create a new instance of the receiver. > */ > public ColumnViewer() { >- viewerEditor = createViewerEditor(); >+ > } > > protected void hookControl(Control control) { > super.hookControl(control); >+ viewerEditor = createViewerEditor(); > hookEditingSupport(control); > } > >@@ -76,16 +82,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 +103,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 +136,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 +147,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 +161,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 +187,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 +241,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 +285,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 +355,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 +387,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 ColumnViewerEditorActivationEvent( >+ 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[] >@@ -390,20 +426,17 @@ > * @see EditingSupport > */ > public CellEditor[] getCellEditors() { >- if (viewerEditor != null) { >- return viewerEditor.getCellEditors(); >- } >- return null; >+ return cellEditors; > } > > /** > * 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> >@@ -412,10 +445,7 @@ > * @see EditingSupport > */ > public ICellModifier getCellModifier() { >- if (viewerEditor != null) { >- return viewerEditor.getCellModifier(); >- } >- return null; >+ return cellModifier; > } > > /** >@@ -425,8 +455,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 >@@ -435,10 +465,7 @@ > * @see EditingSupport > */ > public Object[] getColumnProperties() { >- if (viewerEditor != null) { >- return viewerEditor.getColumnProperties(); >- } >- return null; >+ return columnProperties; > } > > /** >@@ -446,8 +473,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 +496,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 >@@ -480,19 +507,17 @@ > * @see EditingSupport > */ > public void setCellEditors(CellEditor[] editors) { >- if (viewerEditor != null) { >- viewerEditor.setCellEditors(editors); >- } >+ this.cellEditors = editors; > } > > /** >- * 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 >@@ -502,9 +527,7 @@ > * @see EditingSupport > */ > public void setCellModifier(ICellModifier modifier) { >- if (viewerEditor != null) { >- viewerEditor.setCellModifier(modifier); >- } >+ this.cellModifier = modifier; > } > > /** >@@ -515,8 +538,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 >@@ -526,25 +549,9 @@ > * @see EditingSupport > */ > public void setColumnProperties(String[] columnProperties) { >- if (viewerEditor != null) { >- viewerEditor.setColumnProperties(columnProperties); >- } >- } >- >- /** >- * The tab-editing style used if the default implementation is used >- * >- * @param tabEditingStyle >- * bit mask for the tab editing style >- */ >- public void setTabEditingStyle(int tabEditingStyle) { >- this.tabEditingStyle = tabEditingStyle; >+ this.columnProperties = columnProperties; > } > >- 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 +583,59 @@ > } > return null; > } >-} >+ >+ private void handleMouseDown(MouseEvent e) { >+ ViewerCell cell = getCell(new Point(e.x, e.y)); >+ >+ if (cell != null) { >+ triggerEditorActivationEvent(new ColumnViewerEditorActivationEvent(cell, e)); >+ } >+ } >+ >+ /** >+ * Invoking this method fires an editor activation event which tries to >+ * enable the editor but before this event is passed to >+ * {@link ColumnViewerEditorActivationStrategy} to see if this event should really >+ * trigger editor activation >+ * >+ * @param event >+ * the activation event >+ */ >+ protected void triggerEditorActivationEvent(ColumnViewerEditorActivationEvent 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( >+ ColumnViewerEditorActivationStrategy editorActivationStrategy) { >+ if (viewerEditor != null) { >+ viewerEditor.setEditorActivationStrategy(editorActivationStrategy); >+ } else { >+ throw new IllegalStateException( >+ "This feature is not supported by the widget"); //$NON-NLS-1$ >+ } >+ } >+ >+ /** >+ * @param columnViewerEditor >+ * the new column viewer editor >+ */ >+ public void setColumnViewerEditor(ColumnViewerEditor columnViewerEditor) { >+ Assert.isNotNull(viewerEditor); >+ this.viewerEditor = columnViewerEditor; >+ } >+ >+ /** >+ * @return the currently attached viewer editor >+ */ >+ public ColumnViewerEditor getColumnViewerEditor() { >+ return viewerEditor; >+ } >+} >\ 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 1 Mar 2007 21:52:58 -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(ColumnViewerEditorActivationEvent 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 1 Mar 2007 21:53:01 -0000 >@@ -14,6 +14,10 @@ > > package org.eclipse.jface.viewers; > >+import java.util.List; >+ >+import org.eclipse.core.runtime.ListenerList; >+import org.eclipse.swt.SWT; > import org.eclipse.swt.events.FocusAdapter; > import org.eclipse.swt.events.FocusEvent; > import org.eclipse.swt.events.FocusListener; >@@ -22,7 +26,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; >@@ -40,36 +43,73 @@ > public abstract class ColumnViewerEditor { > private CellEditor cellEditor; > >- private CellEditor[] cellEditors; >+ private ICellEditorListener cellEditorListener; > >- private ICellModifier cellModifier; >+ private FocusListener focusListener; > >- private String[] columnProperties; >+ private MouseListener mouseListener; > >- private int columnNumber; >+ private ColumnViewer viewer; > >- private ICellEditorListener cellEditorListener; >+ private TraverseListener tabeditingListener; > >- private FocusListener focusListener; >+ private int activationTime; > >- private MouseListener mouseListener; >+ private ViewerCell cell; > >- private int doubleClickExpirationTime; >+ private ColumnViewerEditorActivationEvent activationEvent; > >- private ColumnViewer viewer; >+ private ListenerList editorActivationListener; > >- private Item item; >+ private ColumnViewerEditorActivationStrategy editorActivationStrategy; > >- private TraverseListener tabeditingListener; >+ /** >+ * Tabing from cell to cell is turned off >+ */ >+ public static final int DEFAULT = 1; >+ >+ /** >+ * Should if the end of the row is reach started from the start/end of the >+ * row below/above >+ */ >+ public static final int TABBING_MOVE_TO_ROW_NEIGHBOR = 1 << 1; >+ >+ /** >+ * Should if the end of the row is reach started from the beginning in the >+ * same row >+ */ >+ public static final int TABBING_CYCLE_IN_ROW = 1 << 2; >+ >+ /** >+ * Support tabing to Cell above/below the current cell >+ */ >+ public static final int TABBING_VERTICAL = 1 << 3; >+ >+ /** >+ * Should tabing from column to column with in one row be supported >+ */ >+ public static final int TABBING_HORIZONTAL = 1 << 4; > > /** >- * Create a new editor implementation for the viewer > * >+ */ >+ public static final int KEYBOARD_ACTIVATION = 1 << 5; >+ >+ private int feature; >+ >+ /** > * @param viewer >- * the column viewer >+ * @param editorActivationStrategy >+ * @param feature > */ >- public ColumnViewerEditor(ColumnViewer viewer) { >+ protected ColumnViewerEditor(ColumnViewer viewer, >+ ColumnViewerEditorActivationStrategy editorActivationStrategy, int feature) { > this.viewer = viewer; >+ this.editorActivationStrategy = editorActivationStrategy; >+ if( (feature & KEYBOARD_ACTIVATION) == KEYBOARD_ACTIVATION ) { >+ this.editorActivationStrategy.setEnableEditorActivationWithKeyboard(true); >+ } >+ this.feature = feature; > initCellEditorListener(); > } > >@@ -92,28 +132,44 @@ > > 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); >+ part.getEditingSupport().setCellEditorValue(cellEditor, value); >+ > // Tricky flow of control here: > // activate() can trigger callback to cellEditorListener which > // will clear cellEditor > // 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 +184,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(); >@@ -139,57 +195,31 @@ > }; > control.addMouseListener(mouseListener); > >- if( tabeditingListener == null ) { >+ if (tabeditingListener == null) { > tabeditingListener = new TraverseListener() { > > public void keyTraversed(TraverseEvent e) { >- ViewerColumn col = viewer.getViewerColumn(columnNumber); >- if ( col != null && col.getEditingSupport().isTabingSupported() ) { >- col.getEditingSupport().processTraversEvent( >- columnNumber, >- viewer.getViewerRowFromItem(item), e); >+ if ((feature & DEFAULT) != DEFAULT) { >+ processTraversEvent(cell.getColumnIndex(), >+ viewer.getViewerRowFromItem(cell >+ .getItem()), e); > } > } > }; > } >- >- control.addTraverseListener(tabeditingListener); > >- } >- } >- } >+ 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 +233,20 @@ > // in case save results in applyEditorValue being re-entered > // see 1GAHI8Z: ITPUI:ALL - How to code event notification when > // using cell editor ? >+ ColumnViewerEditorDeactivationEvent tmp = new ColumnViewerEditorDeactivationEvent(cell); >+ if (editorActivationListener != null >+ && !editorActivationListener.isEmpty()) { >+ Object[] ls = editorActivationListener.getListeners(); >+ for (int i = 0; i < ls.length; i++) { >+ >+ ((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 +269,15 @@ > } > } > 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 +286,17 @@ > */ > void cancelEditing() { > if (cellEditor != null) { >+ ColumnViewerEditorDeactivationEvent tmp = new ColumnViewerEditorDeactivationEvent(cell); >+ if (editorActivationListener != null >+ && !editorActivationListener.isEmpty()) { >+ Object[] ls = editorActivationListener.getListeners(); >+ for (int i = 0; i < ls.length; i++) { >+ >+ ((ColumnViewerEditorActivationListener) ls[i]) >+ .beforeEditorDeactivated(tmp); >+ } >+ } >+ > setEditor(null, null, 0); > cellEditor.removeListener(cellEditorListener); > >@@ -256,7 +318,17 @@ > > 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); >+ } >+ } > } > } > >@@ -265,65 +337,27 @@ > * > * @param event > */ >- void handleMouseDown(MouseEvent event) { >- if (event.button != 1) { >- return; >- } >- >- if (cellEditor != null) { >- applyEditorValue(); >- } >+ void handleEditorActivationEvent(ColumnViewerEditorActivationEvent event) { >+ if (editorActivationStrategy.isEditorActivationEvent(event)) { >+ 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(); >+ this.cell = (ViewerCell) event.getSource(); >+ activationEvent = event; >+ activationTime = 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; >+ activateCellEditor(); > } >- item = items[0]; >- activateCellEditor(event); >- } >- >- /** >- * Start editing the given element. >- * >- * @param element >- * @param column >- */ >- void editElement(Object element, int column) { >- if (cellEditor != null) { >- applyEditorValue(); >- } >- >- setSelection(createSelection(element), true); >- Item[] selection = getSelection(); >- if (selection.length != 1) { >- return; >- } >- >- 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(), >- cellEditor.getValue()); >+ Object value = part.getEditingSupport().getCellEditorValue(cellEditor); >+ part.getEditingSupport().setValue(tableItem.getData(),value); > } > } > >@@ -337,68 +371,194 @@ > return cellEditor != null; > } > >- /** >- * Set the cell editors >- * >- * @param editors >- */ >- void setCellEditors(CellEditor[] editors) { >- this.cellEditors = editors; >+ void handleDoubleClickEvent() { >+ viewer.fireDoubleClick(new DoubleClickEvent(viewer, viewer >+ .getSelection())); >+ viewer.fireOpen(new OpenEvent(viewer, viewer.getSelection())); > } > >- /** >- * Set the cell modifier >- * >- * @param modifier >- */ >- void setCellModifier(ICellModifier modifier) { >- this.cellModifier = modifier; >+ void addEditorActivationListener( >+ ColumnViewerEditorActivationListener listener) { >+ if (editorActivationListener == null) { >+ editorActivationListener = new ListenerList(); >+ } >+ editorActivationListener.add(listener); > } > >- /** >- * Set the column properties >- * >- * @param columnProperties >- */ >- void setColumnProperties(String[] columnProperties) { >- this.columnProperties = columnProperties; >+ void removeEditorActivationListener( >+ ColumnViewerEditorActivationListener listener) { >+ if (editorActivationListener != null) { >+ editorActivationListener.remove(listener); >+ } > } > >- /** >- * Return the properties for the column >- * >- * @return the array of column properties >- */ >- Object[] getColumnProperties() { >- return columnProperties; >+ void setEditorActivationStrategy( >+ ColumnViewerEditorActivationStrategy editorActivationStrategy) { >+ this.editorActivationStrategy = editorActivationStrategy; > } > > /** >- * Get the cell modifier >+ * Process the travers event and opens the next available editor depending >+ * of the implemented strategy. The default implementation uses the style >+ * constants >+ * <ul> >+ * <li>{@link ColumnViewerEditor#TABBING_MOVE_TO_ROW_NEIGHBOR}</li> >+ * <li>{@link ColumnViewerEditor#TABBING_CYCLE_IN_ROW}</li> >+ * <li>{@link ColumnViewerEditor#TABBING_VERTICAL}</li> >+ * <li>{@link ColumnViewerEditor#TABBING_HORIZONTAL}</li> >+ * </ul> > * >- * @return the cell modifier >+ * <p> >+ * Subclasses may overwrite to implement their custom logic to edit the next >+ * cell >+ * </p> >+ * >+ * @param columnIndex >+ * the index of the current column >+ * @param row >+ * the current row >+ * @param event >+ * the travers event > */ >- ICellModifier getCellModifier() { >- return cellModifier; >+ protected void processTraversEvent(int columnIndex, ViewerRow row, >+ TraverseEvent event) { >+ >+ ViewerCell cell2edit = null; >+ >+ if (event.detail == SWT.TRAVERSE_TAB_PREVIOUS) { >+ event.doit = false; >+ >+ if ((event.stateMask & SWT.CTRL) == SWT.CTRL >+ && (feature & TABBING_VERTICAL) == TABBING_VERTICAL) { >+ cell2edit = searchCellAboveBelow(row, viewer, columnIndex, true); >+ } else if ((feature & TABBING_HORIZONTAL) == TABBING_HORIZONTAL) { >+ cell2edit = searchPreviousCell(row, viewer, columnIndex, >+ columnIndex); >+ } >+ } else if (event.detail == SWT.TRAVERSE_TAB_NEXT) { >+ event.doit = false; >+ >+ if ((event.stateMask & SWT.CTRL) == SWT.CTRL >+ && (feature & TABBING_VERTICAL) == TABBING_VERTICAL) { >+ cell2edit = searchCellAboveBelow(row, viewer, columnIndex, >+ false); >+ } else if ((feature & TABBING_HORIZONTAL) == TABBING_HORIZONTAL) { >+ cell2edit = searchNextCell(row, viewer, columnIndex, >+ columnIndex); >+ } >+ } >+ >+ if (cell2edit != null) { >+ List l = viewer.getSelectionFromWidget(); >+ >+ viewer.getControl().setRedraw(false); >+ >+ updateFocusCell(cell2edit); >+ >+ if (!l.contains(cell2edit.getElement())) { >+ viewer.setSelection(new StructuredSelection(cell2edit >+ .getElement())); >+ } >+ >+ ColumnViewerEditorActivationEvent acEvent = new ColumnViewerEditorActivationEvent( >+ cell2edit, event); >+ viewer.triggerEditorActivationEvent(acEvent); >+ viewer.getControl().setRedraw(true); >+ } > } > >- /** >- * Return the array of CellEditors used in the viewer >- * >- * @return the cell editors >- */ >- CellEditor[] getCellEditors() { >- return cellEditors; >+ private ViewerCell searchCellAboveBelow(ViewerRow row, ColumnViewer viewer, >+ int columnIndex, boolean above) { >+ ViewerCell rv = null; >+ >+ ViewerRow newRow = null; >+ >+ if (above) { >+ newRow = row.getNeighbor(ViewerRow.ABOVE, false); >+ } else { >+ newRow = row.getNeighbor(ViewerRow.BELOW, false); >+ } >+ >+ if (newRow != null) { >+ ViewerColumn column = viewer.getViewerColumn(columnIndex); >+ if (column != null && column.getEditingSupport() != null >+ && column.getEditingSupport().canEdit( >+ newRow.getItem().getData())) { >+ rv = newRow.getCell(columnIndex); >+ } else { >+ rv = searchCellAboveBelow(newRow, viewer, columnIndex, above); >+ } >+ } >+ >+ return rv; > } > >- void setSelection(StructuredSelection selection, boolean b) { >- viewer.setSelection(selection, b); >+ private ViewerCell searchPreviousCell(ViewerRow row, ColumnViewer viewer, >+ int columnIndex, int startIndex) { >+ ViewerCell rv = null; >+ >+ if (columnIndex - 1 >= 0) { >+ ViewerColumn column = viewer.getViewerColumn(columnIndex - 1); >+ if (column != null && column.getEditingSupport() != null >+ && column.getEditingSupport().canEdit( >+ row.getItem().getData())) { >+ rv = row.getCell(columnIndex - 1); >+ } else { >+ rv = searchPreviousCell(row, viewer, columnIndex - 1, >+ startIndex); >+ } >+ } else { >+ if ((feature & TABBING_CYCLE_IN_ROW) == TABBING_CYCLE_IN_ROW) { >+ // Check that we don't get into endless loop >+ if (columnIndex - 1 != startIndex) { >+ // Don't subtract -1 from getColumnCount() we need to >+ // start in the virtual column >+ // next to it >+ rv = searchPreviousCell(row, viewer, row.getColumnCount(), >+ startIndex); >+ } >+ } else if ((feature & TABBING_MOVE_TO_ROW_NEIGHBOR) == TABBING_MOVE_TO_ROW_NEIGHBOR) { >+ ViewerRow rowAbove = row.getNeighbor(ViewerRow.ABOVE, false); >+ if (rowAbove != null) { >+ rv = searchPreviousCell(rowAbove, viewer, rowAbove >+ .getColumnCount(), startIndex); >+ } >+ } >+ } >+ >+ return rv; > } > >- void handleDoubleClickEvent() { >- viewer.fireDoubleClick(new DoubleClickEvent(viewer, viewer >- .getSelection())); >- viewer.fireOpen(new OpenEvent(viewer, viewer.getSelection())); >+ private ViewerCell searchNextCell(ViewerRow row, ColumnViewer viewer, >+ int columnIndex, int startIndex) { >+ ViewerCell rv = null; >+ >+ if (columnIndex + 1 < row.getColumnCount()) { >+ ViewerColumn column = viewer.getViewerColumn(columnIndex + 1); >+ if (column != null && column.getEditingSupport() != null >+ && column.getEditingSupport().canEdit( >+ row.getItem().getData())) { >+ rv = row.getCell(columnIndex + 1); >+ } else { >+ rv = searchNextCell(row, viewer, columnIndex + 1, startIndex); >+ } >+ } else { >+ if ((feature & TABBING_CYCLE_IN_ROW) == TABBING_CYCLE_IN_ROW) { >+ // Check that we don't get into endless loop >+ if (columnIndex + 1 != startIndex) { >+ // Start from -1 from the virtual column before the >+ // first one >+ rv = searchNextCell(row, viewer, -1, startIndex); >+ } >+ } else if ((feature & TABBING_MOVE_TO_ROW_NEIGHBOR) == TABBING_MOVE_TO_ROW_NEIGHBOR) { >+ ViewerRow rowBelow = row.getNeighbor(ViewerRow.BELOW, false); >+ if (rowBelow != null) { >+ rv = searchNextCell(rowBelow, viewer, -1, startIndex); >+ } >+ } >+ } >+ >+ return rv; > } > > /** >@@ -431,12 +591,22 @@ > protected abstract void setLayoutData(CellEditor.LayoutData layoutData); > > /** >- * Show up the current selection (scroll the selection into view) >+ * @param focusCell updates the cell with the current input focus > */ >- protected abstract void showSelection(); >+ protected abstract void updateFocusCell(ViewerCell focusCell); >+ >+ /** >+ * @return the cell currently holding the focus >+ * >+ */ >+ public ViewerCell getFocusCell() { >+ return null; >+ } > > /** >- * @return the current selection >+ * @return the viewer working for > */ >- protected abstract Item[] getSelection(); >-} >+ protected ColumnViewer getViewer() { >+ return viewer; >+ } >+} >\ No newline at end of file >Index: src/org/eclipse/jface/viewers/TableViewerEditor.java >=================================================================== >RCS file: src/org/eclipse/jface/viewers/TableViewerEditor.java >diff -N src/org/eclipse/jface/viewers/TableViewerEditor.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/viewers/TableViewerEditor.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,85 @@ >+/******************************************************************************* >+ * 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 org.eclipse.jface.viewers.CellEditor.LayoutData; >+import org.eclipse.swt.custom.TableEditor; >+import org.eclipse.swt.widgets.Control; >+import org.eclipse.swt.widgets.Item; >+import org.eclipse.swt.widgets.TableItem; >+ >+/** >+ * @since 3.3 >+ * >+ */ >+public final class TableViewerEditor extends ColumnViewerEditor { >+ /** >+ * This viewer's table editor. >+ */ >+ private TableEditor tableEditor; >+ >+ private SWTFocusCellManager focusCellManager; >+ >+ TableViewerEditor(TableViewer viewer, SWTFocusCellManager focusCellManager, ColumnViewerEditorActivationStrategy editorActivationStrategy, int feature) { >+ super(viewer,editorActivationStrategy,feature); >+ tableEditor = new TableEditor(viewer.getTable()); >+ this.focusCellManager = focusCellManager; >+ } >+ >+ /** >+ * @param viewer >+ * @param focusCellManager >+ * @param editorActivationStrategy >+ * @param feature >+ */ >+ public static void create(TableViewer viewer, SWTFocusCellManager focusCellManager, ColumnViewerEditorActivationStrategy editorActivationStrategy, int feature) { >+ TableViewerEditor editor = new TableViewerEditor(viewer,focusCellManager,editorActivationStrategy,feature); >+ viewer.setColumnViewerEditor(editor); >+ } >+ >+ /** >+ * @param viewer >+ * @param editorActivationStrategy >+ * @param feature >+ */ >+ public static void create(TableViewer viewer, ColumnViewerEditorActivationStrategy editorActivationStrategy, int feature) { >+ create(viewer, null, editorActivationStrategy, feature); >+ } >+ >+ protected StructuredSelection createSelection(Object element) { >+ return new StructuredSelection(element); >+ } >+ >+ protected void setEditor(Control w, Item item, int columnNumber) { >+ tableEditor.setEditor(w, (TableItem) item, columnNumber); >+ } >+ >+ protected void setLayoutData(LayoutData layoutData) { >+ tableEditor.grabHorizontal = layoutData.grabHorizontal; >+ tableEditor.horizontalAlignment = layoutData.horizontalAlignment; >+ tableEditor.minimumWidth = layoutData.minimumWidth; >+ } >+ >+ public ViewerCell getFocusCell() { >+ if( focusCellManager != null ) { >+ return focusCellManager.getFocusCell(); >+ } >+ >+ return super.getFocusCell(); >+ } >+ >+ protected void updateFocusCell(ViewerCell focusCell) { >+ if( focusCellManager != null ) { >+ focusCellManager.setFocusCell(focusCell); >+ } >+ } >+} >Index: src/org/eclipse/jface/viewers/ColumnViewerEditorActivationEvent.java >=================================================================== >RCS file: src/org/eclipse/jface/viewers/ColumnViewerEditorActivationEvent.java >diff -N src/org/eclipse/jface/viewers/ColumnViewerEditorActivationEvent.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/viewers/ColumnViewerEditorActivationEvent.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 ColumnViewerEditorActivationEvent 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 ColumnViewerEditorActivationEvent(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 ColumnViewerEditorActivationEvent(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 ColumnViewerEditorActivationEvent(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 ColumnViewerEditorActivationEvent(ViewerCell cell, TraverseEvent event) { >+ super(cell); >+ this.eventType = TRAVERSAL; >+ this.sourceEvent = event; >+ } >+} >Index: src/org/eclipse/jface/viewers/ColumnViewerEditorDeactivationEvent.java >=================================================================== >RCS file: src/org/eclipse/jface/viewers/ColumnViewerEditorDeactivationEvent.java >diff -N src/org/eclipse/jface/viewers/ColumnViewerEditorDeactivationEvent.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/viewers/ColumnViewerEditorDeactivationEvent.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 ColumnViewerEditorDeactivationEvent extends EventObject { >+ >+ /** >+ * >+ */ >+ private static final long serialVersionUID = 1L; >+ >+ /** >+ * @param source >+ */ >+ public ColumnViewerEditorDeactivationEvent(Object source) { >+ super(source); >+ } >+ >+} >Index: src/org/eclipse/jface/viewers/SWTFocusCellManager.java >=================================================================== >RCS file: src/org/eclipse/jface/viewers/SWTFocusCellManager.java >diff -N src/org/eclipse/jface/viewers/SWTFocusCellManager.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/viewers/SWTFocusCellManager.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,144 @@ >+/******************************************************************************* >+ * 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 org.eclipse.core.runtime.Assert; >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.graphics.Point; >+import org.eclipse.swt.widgets.Event; >+import org.eclipse.swt.widgets.Listener; >+ >+/** >+ * @since 3.3 >+ * >+ */ >+abstract class SWTFocusCellManager { >+ >+ private CellNavigationStrategy navigationDelegate; >+ >+ private ColumnViewer viewer; >+ >+ private ViewerCell focusCell; >+ >+ /** >+ * @param viewer >+ * @param focusDrawingDelegate >+ * @param navigationDelegate >+ */ >+ public SWTFocusCellManager(ColumnViewer viewer, >+ FocusCellHighlighter focusDrawingDelegate, >+ CellNavigationStrategy navigationDelegate) { >+ this.viewer = viewer; >+ this.navigationDelegate = navigationDelegate; >+ hookListener(viewer); >+ } >+ >+ private void handleMouseDown(Event event) { >+ ViewerCell cell = viewer.getCell(new Point(event.x, event.y)); >+ if (cell != null) { >+ >+ if (!cell.equals(focusCell)) { >+ this.focusCell = cell; >+ viewer.getControl().redraw(); >+ } >+ } >+ } >+ >+ private void handleKeyDown(Event event) { >+ ViewerCell tmp = null; >+ >+ if (navigationDelegate.isCollapseEvent(viewer, focusCell, event)) { >+ navigationDelegate.collapse(viewer, focusCell, event); >+ } else if (navigationDelegate.isExpandEvent(viewer, focusCell, event)) { >+ navigationDelegate.expand(viewer, focusCell, event); >+ } else if (navigationDelegate.isNavigationEvent(viewer, event)) { >+ tmp = navigationDelegate.findSelectedCell(viewer, focusCell, event); >+ >+ if (tmp != null) { >+ if (!tmp.equals(focusCell)) { >+ this.focusCell = tmp; >+ viewer.getControl().redraw(); >+ } >+ } >+ } >+ >+ if (navigationDelegate.cancleEvent(viewer, event)) { >+ event.doit = false; >+ } >+ } >+ >+ private void handleSelection(Event event) { >+ if (focusCell != null && focusCell.getItem() != event.item >+ && event.item != null) { >+ ViewerRow row = viewer.getViewerRowFromItem(event.item); >+ Assert >+ .isNotNull(row, >+ "Internal Structure invalid. Row item has no row ViewerRow assigned"); //$NON-NLS-1$ >+ ViewerCell tmp = row.getCell(focusCell.getColumnIndex()); >+ if (!focusCell.equals(tmp)) { >+ this.focusCell = tmp; >+ viewer.getControl().redraw(); >+ } >+ } >+ } >+ >+ private void handleFocusIn(Event event) { >+ if( focusCell == null ) { >+ focusCell = getPrimaryFocusCell(); >+ } >+ } >+ >+ abstract ViewerCell getPrimaryFocusCell(); >+ >+ private void hookListener(ColumnViewer viewer) { >+ Listener listener = new Listener() { >+ >+ public void handleEvent(Event event) { >+ switch (event.type) { >+ case SWT.MouseDown: >+ handleMouseDown(event); >+ break; >+ case SWT.KeyDown: >+ handleKeyDown(event); >+ break; >+ case SWT.Selection: >+ handleSelection(event); >+ break; >+ case SWT.FocusIn: >+ handleFocusIn(event); >+ break; >+ } >+ } >+ }; >+ >+ viewer.getControl().addListener(SWT.MouseDown, listener); >+ viewer.getControl().addListener(SWT.KeyDown, listener); >+ viewer.getControl().addListener(SWT.Selection, listener); >+ viewer.getControl().addListener(SWT.FocusIn, listener); >+ } >+ >+ /** >+ * @return the cell with the focus >+ * >+ */ >+ public ViewerCell getFocusCell() { >+ return focusCell; >+ } >+ >+ void setFocusCell(ViewerCell focusCell) { >+ this.focusCell = focusCell; >+ } >+ >+ ColumnViewer getViewer() { >+ return viewer; >+ } >+} >Index: src/org/eclipse/jface/viewers/TreeViewerEditor.java >=================================================================== >RCS file: src/org/eclipse/jface/viewers/TreeViewerEditor.java >diff -N src/org/eclipse/jface/viewers/TreeViewerEditor.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/viewers/TreeViewerEditor.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,95 @@ >+/******************************************************************************* >+ * 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 org.eclipse.jface.viewers.CellEditor.LayoutData; >+import org.eclipse.swt.custom.TreeEditor; >+import org.eclipse.swt.widgets.Control; >+import org.eclipse.swt.widgets.Item; >+import org.eclipse.swt.widgets.TreeItem; >+ >+/** >+ * @since 3.3 >+ * >+ */ >+public class TreeViewerEditor extends ColumnViewerEditor { >+ /** >+ * This viewer's tree editor. >+ */ >+ private TreeEditor treeEditor; >+ >+ private SWTFocusCellManager focusCellManager; >+ >+ /** >+ * @param viewer >+ * @param focusCellManager >+ * @param editorActivationStrategy >+ * @param feature >+ */ >+ TreeViewerEditor(TreeViewer viewer, SWTFocusCellManager focusCellManager, ColumnViewerEditorActivationStrategy editorActivationStrategy, int feature) { >+ super(viewer,editorActivationStrategy,feature); >+ treeEditor = new TreeEditor(viewer.getTree()); >+ this.focusCellManager = focusCellManager; >+ } >+ >+ /** >+ * @param viewer >+ * @param focusCellManager >+ * @param editorActivationStrategy >+ * @param feature >+ */ >+ public static void create(TreeViewer viewer, SWTFocusCellManager focusCellManager, ColumnViewerEditorActivationStrategy editorActivationStrategy, int feature) { >+ TreeViewerEditor editor = new TreeViewerEditor(viewer,focusCellManager,editorActivationStrategy,feature); >+ viewer.setColumnViewerEditor(editor); >+ } >+ >+ /** >+ * @param viewer >+ * @param editorActivationStrategy >+ * @param feature >+ */ >+ public static void create(TreeViewer viewer, ColumnViewerEditorActivationStrategy editorActivationStrategy, int feature) { >+ create(viewer, null, editorActivationStrategy, feature); >+ } >+ >+ protected StructuredSelection createSelection(Object element) { >+ if (element instanceof TreePath) { >+ return new TreeSelection((TreePath) element, getViewer().getComparer()); >+ } >+ >+ return new StructuredSelection(element); >+ } >+ >+ protected void setEditor(Control w, Item item, int fColumnNumber) { >+ treeEditor.setEditor(w, (TreeItem) item, fColumnNumber); >+ } >+ >+ protected void setLayoutData(LayoutData layoutData) { >+ treeEditor.grabHorizontal = layoutData.grabHorizontal; >+ treeEditor.horizontalAlignment = layoutData.horizontalAlignment; >+ treeEditor.minimumWidth = layoutData.minimumWidth; >+ } >+ >+ public ViewerCell getFocusCell() { >+ if( focusCellManager != null ) { >+ return focusCellManager.getFocusCell(); >+ } >+ >+ return super.getFocusCell(); >+ } >+ >+ protected void updateFocusCell(ViewerCell focusCell) { >+ if( focusCellManager != null ) { >+ focusCellManager.setFocusCell(focusCell); >+ } >+ } >+} >Index: src/org/eclipse/jface/viewers/TableViewerFocusCellManager.java >=================================================================== >RCS file: src/org/eclipse/jface/viewers/TableViewerFocusCellManager.java >diff -N src/org/eclipse/jface/viewers/TableViewerFocusCellManager.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/viewers/TableViewerFocusCellManager.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,42 @@ >+/******************************************************************************* >+ * 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 org.eclipse.swt.widgets.Table; >+ >+/** >+ * @since 3.3 >+ * >+ */ >+public class TableViewerFocusCellManager extends SWTFocusCellManager { >+ private static final CellNavigationStrategy TABLE_NAVIGATE = new CellNavigationStrategy(); >+ >+ /** >+ * @param viewer >+ * @param focusDrawingDelegate >+ */ >+ public TableViewerFocusCellManager(TableViewer viewer, >+ FocusCellHighlighter focusDrawingDelegate) { >+ super(viewer, focusDrawingDelegate, TABLE_NAVIGATE); >+ } >+ >+ ViewerCell getPrimaryFocusCell() { >+ Table table = (Table) getViewer().getControl(); >+ >+ if( table.getItemCount() > 0 ) { >+ return getViewer().getViewerRowFromItem(table.getItem(0)).getCell(0); >+ } >+ >+ return null; >+ } >+ >+} >Index: src/org/eclipse/jface/viewers/FocusCellHighlighter.java >=================================================================== >RCS file: src/org/eclipse/jface/viewers/FocusCellHighlighter.java >diff -N src/org/eclipse/jface/viewers/FocusCellHighlighter.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/viewers/FocusCellHighlighter.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,34 @@ >+/******************************************************************************* >+ * 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; >+ >+/** >+ * @since 3.3 >+ * >+ */ >+public abstract class FocusCellHighlighter { >+ private ColumnViewer viewer; >+ >+ /** >+ * @param viewer >+ */ >+ public FocusCellHighlighter(ColumnViewer viewer) { >+ this.viewer = viewer; >+ } >+ >+ /** >+ * @return the focus cell >+ */ >+ public ViewerCell getFocusCell() { >+ return viewer.getColumnViewerEditor().getFocusCell(); >+ } >+} >Index: src/org/eclipse/jface/viewers/FocusCellOwnerDrawHighlighter.java >=================================================================== >RCS file: src/org/eclipse/jface/viewers/FocusCellOwnerDrawHighlighter.java >diff -N src/org/eclipse/jface/viewers/FocusCellOwnerDrawHighlighter.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/viewers/FocusCellOwnerDrawHighlighter.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,119 @@ >+/******************************************************************************* >+ * 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 org.eclipse.core.runtime.Assert; >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.graphics.Color; >+import org.eclipse.swt.graphics.GC; >+import org.eclipse.swt.widgets.Event; >+import org.eclipse.swt.widgets.Listener; >+ >+/** >+ * @since 3.3 >+ * >+ */ >+public class FocusCellOwnerDrawHighlighter extends FocusCellHighlighter { >+ >+ /** >+ * @param viewer >+ * the viewer >+ */ >+ public FocusCellOwnerDrawHighlighter(ColumnViewer viewer) { >+ super(viewer); >+ hookListener(viewer); >+ } >+ >+ private void markFocusedCell(Event event, ViewerCell cell) { >+ Color background = getSelectedCellBackgroundColor(cell); >+ Color foreground = getSelectedCellForegroundColor(cell); >+ >+ if (foreground != null || background != null) { >+ GC gc = event.gc; >+ >+ if (background == null) { >+ background = cell.getItem().getDisplay().getSystemColor( >+ SWT.COLOR_LIST_SELECTION); >+ } >+ >+ if (foreground == null) { >+ foreground = cell.getItem().getDisplay().getSystemColor( >+ SWT.COLOR_LIST_SELECTION_TEXT); >+ } >+ >+ gc.setBackground(background); >+ gc.setForeground(foreground); >+ gc.fillRectangle(event.getBounds()); >+ >+ // This is a workaround for an SWT-Bug on WinXP bug 169517 >+ gc.drawText(" ", cell.getBounds().x, cell.getBounds().y, false); //$NON-NLS-1$ >+ event.detail &= ~SWT.SELECTED; >+ } >+ } >+ >+ private void removeSelectionInformation(Event event, ViewerCell cell) { >+ GC gc = event.gc; >+ gc.setBackground(cell.getViewerRow().getBackground( >+ cell.getColumnIndex())); >+ gc.setForeground(cell.getViewerRow().getForeground( >+ cell.getColumnIndex())); >+ gc.fillRectangle(cell.getBounds()); >+ // This is a workaround for an SWT-Bug on WinXP bug 169517 >+ gc.drawText(" ", cell.getBounds().x, cell.getBounds().y, false); //$NON-NLS-1$ >+ event.detail &= ~SWT.SELECTED; >+ } >+ >+ private void hookListener(final ColumnViewer viewer) { >+ >+ Listener listener = new Listener() { >+ >+ public void handleEvent(Event event) { >+ if ((event.detail & SWT.SELECTED) > 0) { >+ ViewerCell focusCell = getFocusCell(); >+ ViewerRow row = viewer.getViewerRowFromItem(event.item); >+ >+ Assert >+ .isNotNull(row, >+ "Internal structure invalid. Item without associated row is not possible."); //$NON-NLS-1$ >+ >+ ViewerCell cell = row.getCell(event.index); >+ >+ if (focusCell == null || !cell.equals(focusCell)) { >+ removeSelectionInformation(event, cell); >+ } else { >+ markFocusedCell(event, cell); >+ } >+ } >+ } >+ >+ }; >+ viewer.getControl().addListener(SWT.EraseItem, listener); >+ } >+ >+ /** >+ * @param cell >+ * the cell which is colored >+ * @return the color >+ */ >+ protected Color getSelectedCellBackgroundColor(ViewerCell cell) { >+ return null; >+ } >+ >+ /** >+ * @param cell >+ * the cell which is colored >+ * @return the color >+ */ >+ protected Color getSelectedCellForegroundColor(ViewerCell cell) { >+ return null; >+ } >+} >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(ColumnViewerEditorActivationEvent event); >+ >+ /** >+ * Called after an editor has been activated >+ * >+ * @param event the event >+ */ >+ public abstract void afterEditorActivated(ColumnViewerEditorActivationEvent event); >+ >+ /** >+ * Called before an editor is deactivated >+ * >+ * @param event >+ * the event >+ */ >+ public abstract void beforeEditorDeactivated(ColumnViewerEditorDeactivationEvent event); >+ >+ >+ /** >+ * Called after an editor is deactivated >+ * >+ * @param event the event >+ */ >+ public abstract void afterEditorDeactivated(ColumnViewerEditorDeactivationEvent event); >+} >Index: src/org/eclipse/jface/viewers/TreeViewerFocusCellManager.java >=================================================================== >RCS file: src/org/eclipse/jface/viewers/TreeViewerFocusCellManager.java >diff -N src/org/eclipse/jface/viewers/TreeViewerFocusCellManager.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/viewers/TreeViewerFocusCellManager.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,77 @@ >+/******************************************************************************* >+ * 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 org.eclipse.swt.SWT; >+import org.eclipse.swt.widgets.Event; >+import org.eclipse.swt.widgets.Tree; >+import org.eclipse.swt.widgets.TreeItem; >+ >+/** >+ * @since 3.3 >+ * >+ */ >+public class TreeViewerFocusCellManager extends SWTFocusCellManager { >+ private static final CellNavigationStrategy TREE_NAVIGATE = new CellNavigationStrategy() { >+ public void collapse(ColumnViewer viewer, ViewerCell cellToCollapse, >+ Event event) { >+ if (cellToCollapse != null) { >+ ((TreeItem) cellToCollapse.getItem()).setExpanded(false); >+ } >+ } >+ >+ public void expand(ColumnViewer viewer, ViewerCell cellToExpand, >+ Event event) { >+ if (cellToExpand != null) { >+ TreeViewer v = (TreeViewer) viewer; >+ v.setExpandedState(v >+ .getTreePathFromItem(cellToExpand.getItem()), true); >+ } >+ } >+ >+ public boolean isCollapseEvent(ColumnViewer viewer, >+ ViewerCell cellToCollapse, Event event) { >+ return cellToCollapse != null >+ && ((TreeItem) cellToCollapse.getItem()).getExpanded() >+ && cellToCollapse.getColumnIndex() == 0 >+ && event.keyCode == SWT.ARROW_LEFT; >+ } >+ >+ public boolean isExpandEvent(ColumnViewer viewer, >+ ViewerCell cellToExpand, Event event) { >+ return cellToExpand != null >+ && ((TreeItem) cellToExpand.getItem()).getItemCount() > 0 >+ && !((TreeItem) cellToExpand.getItem()).getExpanded() >+ && cellToExpand.getColumnIndex() == 0 >+ && event.keyCode == SWT.ARROW_RIGHT; >+ } >+ }; >+ >+ /** >+ * @param viewer >+ * @param focusDrawingDelegate >+ */ >+ public TreeViewerFocusCellManager(TreeViewer viewer, >+ FocusCellHighlighter focusDrawingDelegate) { >+ super(viewer, focusDrawingDelegate,TREE_NAVIGATE); >+ } >+ >+ ViewerCell getPrimaryFocusCell() { >+ Tree tree = (Tree) getViewer().getControl(); >+ >+ if( tree.getItemCount() > 0 ) { >+ return getViewer().getViewerRowFromItem(tree.getItem(0)).getCell(0); >+ } >+ >+ return null; >+ } >+} >Index: src/org/eclipse/jface/viewers/CellNavigationStrategy.java >=================================================================== >RCS file: src/org/eclipse/jface/viewers/CellNavigationStrategy.java >diff -N src/org/eclipse/jface/viewers/CellNavigationStrategy.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/viewers/CellNavigationStrategy.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,151 @@ >+/******************************************************************************* >+ * 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 org.eclipse.swt.SWT; >+import org.eclipse.swt.widgets.Event; >+ >+/** >+ * @since 3.3 >+ * >+ */ >+public class CellNavigationStrategy { >+ /** >+ * is the given event an event which moves the selection to another cell >+ * >+ * @param viewer >+ * the viewer we are working for >+ * >+ * @param event >+ * the key event >+ * @return <code>true</code> if a new cell is searched >+ */ >+ public boolean isNavigationEvent(ColumnViewer viewer, Event event) { >+ switch (event.keyCode) { >+ case SWT.ARROW_UP: >+ case SWT.ARROW_DOWN: >+ case SWT.ARROW_LEFT: >+ case SWT.ARROW_RIGHT: >+ case SWT.HOME: >+ case SWT.PAGE_DOWN: >+ case SWT.PAGE_UP: >+ case SWT.END: >+ return true; >+ default: >+ return false; >+ } >+ } >+ >+ /** >+ * @param viewer >+ * the viewer we are working for >+ * @param cellToCollapse the cell to collapse >+ * @param event >+ * the key event >+ * @return <code>true</code> if this event triggers collapsing of a node >+ */ >+ public boolean isCollapseEvent(ColumnViewer viewer, ViewerCell cellToCollapse, Event event) { >+ return false; >+ } >+ >+ /** >+ * @param viewer >+ * the viewer we are working for >+ * @param cellToExpand the cell to expand >+ * @param event >+ * the key event >+ * @return <code>true</code> if this event triggers expanding of a node >+ */ >+ public boolean isExpandEvent(ColumnViewer viewer, ViewerCell cellToExpand, Event event) { >+ return false; >+ } >+ >+ /** >+ * @param viewer >+ * the viewer working for >+ * @param cellToExpand >+ * the cell the user wants to expand >+ * @param event >+ * the event triggering the exansion >+ */ >+ public void expand(ColumnViewer viewer, ViewerCell cellToExpand, Event event) { >+ >+ } >+ >+ /** >+ * @param viewer >+ * the viewer working for >+ * @param cellToCollapse >+ * the cell the user wants to collapse >+ * @param event >+ * the event triggering the exansion >+ */ >+ public void collapse(ColumnViewer viewer, ViewerCell cellToCollapse, >+ Event event) { >+ >+ } >+ >+ /** >+ * @param viewer >+ * the viewer we are working for >+ * @param currentSelectedCell >+ * the cell currently selected >+ * @param event >+ * the key event >+ * @return the cell which is highlighted next or <code>null</code> if the >+ * default implementation is taken. E.g. it's fairly impossible to >+ * react on PAGE_DOWN requests >+ */ >+ public ViewerCell findSelectedCell(ColumnViewer viewer, >+ ViewerCell currentSelectedCell, Event event) { >+ >+ switch (event.keyCode) { >+ case SWT.ARROW_UP: >+ if (currentSelectedCell != null) { >+ return currentSelectedCell.getNeighbor(ViewerCell.ABOVE, false); >+ } >+ break; >+ case SWT.ARROW_DOWN: >+ if (currentSelectedCell != null) { >+ return currentSelectedCell.getNeighbor(ViewerCell.BELOW, false); >+ } >+ break; >+ case SWT.ARROW_LEFT: >+ if (currentSelectedCell != null) { >+ return currentSelectedCell.getNeighbor(ViewerCell.LEFT, true); >+ } >+ break; >+ case SWT.ARROW_RIGHT: >+ if (currentSelectedCell != null) { >+ return currentSelectedCell.getNeighbor(ViewerCell.RIGHT, true); >+ } >+ break; >+ } >+ >+ return null; >+ } >+ >+ /** >+ * This method is consulted to decide whether an event has to be cancled or >+ * not. By default events who collapse/expand tree-nodes are cancled >+ * >+ * @param viewer >+ * the viewer working for >+ * @param event >+ * the event >+ * @return <code>true</code> if the event has to be cancled >+ */ >+ public boolean cancleEvent(ColumnViewer viewer, Event event) { >+ return event.keyCode == SWT.ARROW_LEFT >+ || event.keyCode == SWT.ARROW_RIGHT; >+ } >+} >Index: src/org/eclipse/jface/viewers/ColumnViewerEditorActivationStrategy.java >=================================================================== >RCS file: src/org/eclipse/jface/viewers/ColumnViewerEditorActivationStrategy.java >diff -N src/org/eclipse/jface/viewers/ColumnViewerEditorActivationStrategy.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/viewers/ColumnViewerEditorActivationStrategy.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,91 @@ >+/******************************************************************************* >+ * 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 class ColumnViewerEditorActivationStrategy { >+ private ColumnViewer viewer; >+ >+ private KeyListener keyboardActivationListener; >+ >+ /** >+ * @param viewer the viewer the editor support is attached to >+ */ >+ public ColumnViewerEditorActivationStrategy(ColumnViewer viewer) { >+ this.viewer = viewer; >+ } >+ >+ /** >+ * @param event >+ * @return bla bl >+ */ >+ protected boolean isEditorActivationEvent(ColumnViewerEditorActivationEvent event) { >+ return event.eventType == ColumnViewerEditorActivationEvent.MOUSE_CLICK_SELECTION >+ || event.eventType == ColumnViewerEditorActivationEvent.PROGRAMATIC >+ || event.eventType == ColumnViewerEditorActivationEvent.TRAVERSAL; >+ } >+ >+ /** >+ * @return the cell holding the current focus >+ */ >+ private ViewerCell getFocusCell() { >+ return viewer.getColumnViewerEditor().getFocusCell(); >+ } >+ >+ /** >+ * @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 ColumnViewerEditorActivationEvent(cell,e)); >+ } >+ } >+ >+ public void keyReleased(KeyEvent e) { >+ >+ } >+ >+ }; >+ viewer.getControl().addKeyListener(keyboardActivationListener); >+ } >+ } else { >+ if( keyboardActivationListener != null ) { >+ viewer.getControl().removeKeyListener(keyboardActivationListener); >+ keyboardActivationListener = null; >+ } >+ } >+ } >+ >+}
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