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 41408 Details for
Bug 75114
[Viewers] TableViewer-Enhancement for Editing
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]
A more generalized version which also includes "support" for TreeViewer
patch.txt (text/plain), 18.17 KB, created by
Thomas Schindl
on 2006-05-13 14:12:39 EDT
(
hide
)
Description:
A more generalized version which also includes "support" for TreeViewer
Filename:
MIME Type:
Creator:
Thomas Schindl
Created:
2006-05-13 14:12:39 EDT
Size:
18.17 KB
patch
obsolete
>Index: src/org/eclipse/jface/viewers/TableViewer.java >=================================================================== >RCS file: /home/eclipse/org.eclipse.jface/src/org/eclipse/jface/viewers/TableViewer.java,v >retrieving revision 1.53 >diff -u -r1.53 TableViewer.java >--- src/org/eclipse/jface/viewers/TableViewer.java 8 May 2006 20:56:56 -0000 1.53 >+++ src/org/eclipse/jface/viewers/TableViewer.java 13 May 2006 18:10:11 -0000 >@@ -20,6 +20,8 @@ > import org.eclipse.swt.custom.TableEditor; > import org.eclipse.swt.events.MouseAdapter; > import org.eclipse.swt.events.MouseEvent; >+import org.eclipse.swt.events.TraverseEvent; >+import org.eclipse.swt.events.TraverseListener; > import org.eclipse.swt.graphics.Image; > import org.eclipse.swt.graphics.Rectangle; > import org.eclipse.swt.widgets.Composite; >@@ -63,8 +65,13 @@ > * @see #doFindItem(Object) > * @see #internalRefresh(Object, boolean) > */ >-public class TableViewer extends StructuredViewer { >- >+public class TableViewer extends StructuredViewer implements ITabEditingSupport { >+ private boolean tabediting = false; >+ >+ private TabeditingListener tabeditingListener; >+ >+ private TabEditingDelegate tabeditingDelgate; >+ > private class VirtualManager{ > > /** >@@ -1037,6 +1044,10 @@ > */ > public void setCellEditors(CellEditor[] editors) { > tableViewerImpl.setCellEditors(editors); >+ >+ if( tabediting ) { >+ applyCellEditing(tabediting); >+ } > } > > /** >@@ -1278,7 +1289,90 @@ > provider instanceof ILazyContentProvider); > } > >+ private void applyCellEditing(boolean tabediting) { >+ CellEditor[] editors = getCellEditors(); >+ >+ // There's already a listener known we need remove it from the cell-editors because every >+ // cell-editor should only hold one reference >+ if( this.tabeditingListener != null ) { >+ addRemoveEditingListeners(editors,this.tabeditingListener,false); >+ } >+ >+ if( tabediting ) { >+ if( this.tabeditingListener == null ) { >+ if( this.tabeditingDelgate == null ) { >+ this.tabeditingDelgate = new TabEditingDelegate(); >+ } >+ this.tabeditingListener = new TabeditingListener(); >+ } >+ >+ addRemoveEditingListeners(editors,this.tabeditingListener,true); >+ } >+ } >+ >+ private void addRemoveEditingListeners(CellEditor[] editors, TraverseListener listener, boolean add) { >+ if( editors != null ) { >+ for( int i = 0; i < editors.length; i++ ) { >+ if( editors[i] != null ) { >+ if( add ) { >+ editors[i].getControl().addTraverseListener(listener); >+ } else { >+ editors[i].getControl().addTraverseListener(listener); >+ } >+ } >+ } >+ } >+ } > >+ /** >+ * @param tabediting The tabediting to set. >+ */ >+ public void setTabediting(boolean tabediting) { >+ this.tabediting = tabediting; >+ if( tabediting && getCellEditors() != null ) { >+ applyCellEditing(true); >+ } else if( ! tabediting && getCellEditors() != null ) { >+ applyCellEditing(false); >+ } >+ } >+ >+ /** >+ * @param tabeditingDelgate The tabeditingDelgate to set. >+ */ >+ public void setTabeditingDelgate(TabEditingDelegate tabeditingDelgate) { >+ this.tabeditingDelgate = tabeditingDelgate; >+ } > >+ private class TabeditingListener implements TraverseListener { >+ private TabEditingSupportWrapper wrapper = new TabEditingSupportWrapper() { >+ >+ public void setSelectedRow(int index) { >+ TableViewer.this.table.setSelection(index); >+ } >+ >+ public int getColumnCount() { >+ return TableViewer.this.table.getColumnCount(); >+ } >+ >+ public int getCurrentColumnIndex() { >+ return TableViewer.this.tableEditor.getColumn(); >+ } >+ >+ public int getCurrentRowIndex() { >+ return TableViewer.this.table.getSelectionIndex(); >+ } >+ >+ public int getRowCount() { >+ return TableViewer.this.table.getItemCount(); >+ } >+ >+ }; >+ >+ public void keyTraversed(TraverseEvent e) { >+ if( TableViewer.this.tabeditingDelgate != null ) { >+ TableViewer.this.tabeditingDelgate.focusNewEditor(e, TableViewer.this, wrapper); >+ } >+ } >+ } > } > >Index: src/org/eclipse/jface/viewers/TreeViewer.java >=================================================================== >RCS file: /home/eclipse/org.eclipse.jface/src/org/eclipse/jface/viewers/TreeViewer.java,v >retrieving revision 1.48 >diff -u -r1.48 TreeViewer.java >--- src/org/eclipse/jface/viewers/TreeViewer.java 8 May 2006 20:56:57 -0000 1.48 >+++ src/org/eclipse/jface/viewers/TreeViewer.java 13 May 2006 18:10:13 -0000 >@@ -21,6 +21,8 @@ > import org.eclipse.swt.events.DisposeListener; > import org.eclipse.swt.events.MouseAdapter; > import org.eclipse.swt.events.MouseEvent; >+import org.eclipse.swt.events.TraverseEvent; >+import org.eclipse.swt.events.TraverseListener; > import org.eclipse.swt.events.TreeListener; > import org.eclipse.swt.graphics.Image; > import org.eclipse.swt.graphics.Point; >@@ -47,8 +49,15 @@ > * <code>ITreeContentProvider</code> interface. > * </p> > */ >-public class TreeViewer extends AbstractTreeViewer { >+public class TreeViewer extends AbstractTreeViewer implements ITabEditingSupport { > >+ private boolean tabediting = false; >+ >+ private TabeditingListener tabeditingListener; >+ >+ private TabEditingDelegate tabeditingDelgate; >+ >+ > /** > * TreeColorAndFontCollector is an helper class for color and font support > * for trees that support the ITableFontProvider and the >@@ -609,6 +618,10 @@ > */ > public void setCellEditors(CellEditor[] editors) { > treeViewerImpl.setCellEditors(editors); >+ >+ if( tabediting ) { >+ applyCellEditing(tabediting); >+ } > } > > /** >@@ -985,4 +998,93 @@ > }}); > } > } >+ >+ private void applyCellEditing(boolean tabediting) { >+ CellEditor[] editors = getCellEditors(); >+ >+ // There's already a listener known we need remove it from the cell-editors because every >+ // cell-editor should only hold one reference >+ if( this.tabeditingListener != null ) { >+ addRemoveEditingListeners(editors,this.tabeditingListener,false); >+ } >+ >+ if( tabediting ) { >+ if( this.tabeditingListener == null ) { >+ if( this.tabeditingDelgate == null ) { >+ this.tabeditingDelgate = new TabEditingDelegate(); >+ } >+ this.tabeditingListener = new TabeditingListener(); >+ } >+ >+ addRemoveEditingListeners(editors,this.tabeditingListener,true); >+ } >+ } >+ >+ private void addRemoveEditingListeners(CellEditor[] editors, TraverseListener listener, boolean add) { >+ if( editors != null ) { >+ for( int i = 0; i < editors.length; i++ ) { >+ if( editors[i] != null ) { >+ if( add ) { >+ editors[i].getControl().addTraverseListener(listener); >+ } else { >+ editors[i].getControl().addTraverseListener(listener); >+ } >+ } >+ } >+ } >+ } >+ >+ /** >+ * @param tabediting The tabediting to set. >+ */ >+ public void setTabediting(boolean tabediting) { >+ this.tabediting = tabediting; >+ if( tabediting && getCellEditors() != null ) { >+ applyCellEditing(true); >+ } else if( ! tabediting && getCellEditors() != null ) { >+ applyCellEditing(false); >+ } >+ } >+ >+ /** >+ * @param tabeditingDelgate The tabeditingDelgate to set. >+ */ >+ public void setTabeditingDelgate(TabEditingDelegate tabeditingDelgate) { >+ this.tabeditingDelgate = tabeditingDelgate; >+ } >+ >+ private class TabeditingListener implements TraverseListener { >+ private TabEditingSupportWrapper wrapper = new TabEditingSupportWrapper() { >+ >+ public void setSelectedRow(int index) { >+ TreeItem item = TreeViewer.this.tree.getItem(index); >+ TreeViewer.this.tree.setSelection(item); >+ } >+ >+ public int getColumnCount() { >+ return TreeViewer.this.tree.getColumnCount(); >+ } >+ >+ public int getCurrentColumnIndex() { >+ return TreeViewer.this.treeEditor.getColumn(); >+ } >+ >+ public int getCurrentRowIndex() { >+ // FIXME TABING FROM ROW TO ROW >+ return 0; >+ } >+ >+ public int getRowCount() { >+ // FIXME TABING FROM ROW TO ROW >+ return 0; >+ } >+ >+ }; >+ >+ public void keyTraversed(TraverseEvent e) { >+ if( TreeViewer.this.tabeditingDelgate != null ) { >+ TreeViewer.this.tabeditingDelgate.focusNewEditor(e, TreeViewer.this, wrapper); >+ } >+ } >+ } > } >Index: src/org/eclipse/jface/viewers/ITabEditingSupport.java >=================================================================== >RCS file: src/org/eclipse/jface/viewers/ITabEditingSupport.java >diff -N src/org/eclipse/jface/viewers/ITabEditingSupport.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/viewers/ITabEditingSupport.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,59 @@ >+/******************************************************************************* >+ * 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; >+ >+/** >+ * Viewers who want to provide tabulator editing features have to implement this >+ * interface. >+ * >+ * @since 3.2 >+ * >+ */ >+public interface ITabEditingSupport { >+ >+ /** >+ * @param tabediting >+ * Turn on/off tab-editing support >+ */ >+ public void setTabediting(boolean tabediting); >+ >+ /** >+ * Set your own tab-editing delegate >+ * >+ * @param tabeditingDelgate the new delegate >+ */ >+ public void setTabeditingDelgate(TabEditingDelegate tabeditingDelgate); >+ >+ /** >+ * Starts editing the given element. >+ * >+ * @param element >+ * the element >+ * @param column >+ * the column number >+ * @see TableViewer#editElement(Object, int) >+ * @see TreeViewer#editElement(Object, int) >+ */ >+ public void editElement(Object element, int column); >+ >+ /** >+ * The <code>StructuredViewer</code> implementation of this method returns >+ * the result as an <code>IStructuredSelection</code>. >+ * <p> >+ * Subclasses do not typically override this method, but implement >+ * <code>getSelectionFromWidget(List)</code> instead. >+ * <p> >+ * @return ISelection >+ * @see ISelectionProvider#getSelection() >+ */ >+ public ISelection getSelection(); >+} >Index: src/org/eclipse/jface/viewers/TabEditingDelegate.java >=================================================================== >RCS file: src/org/eclipse/jface/viewers/TabEditingDelegate.java >diff -N src/org/eclipse/jface/viewers/TabEditingDelegate.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/viewers/TabEditingDelegate.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,192 @@ >+/******************************************************************************* >+ * 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.SWT; >+import org.eclipse.swt.events.TraverseEvent; >+ >+/** >+ * TableViewer delegates tabulator traversing to the class which implements how >+ * elements are the next column in the table is selected. You may sub-class this >+ * class and implement your own selection algorithm. >+ * >+ * @since 3.2 >+ * @see TableViewer#setTabeditingDelgate(TabEditingDelegate) >+ * @see TableViewer#setTabediting(boolean) >+ */ >+public class TabEditingDelegate { >+ private boolean moveToRowNeighbor = false; >+ >+ private boolean cycleInRow = false; >+ >+ private boolean rowTabing = true; >+ >+ private boolean columnTabing = true; >+ >+ /** >+ * This method is called when in the actually active cell-editor a traversal >+ * event is kicked of by the user. Subclasses may override this method to >+ * implement their own selection mechanism. >+ * >+ * @param e >+ * the traversal event >+ * >+ * @param activeColumn >+ * the currently active column >+ * @param totalColumns >+ * the totla number of columns >+ * @param activeRow >+ * the active row >+ * @param totalRows >+ * the total number of rows >+ * @param viewer >+ * the viewer which support tabing >+ * @param widgetWrapper >+ * the swt wigdet wrapped in a helper class >+ * @return true of a new column is activated >+ */ >+ public boolean focusNewEditor(TraverseEvent e, ITabEditingSupport viewer, >+ TabEditingSupportWrapper widgetWrapper) { >+ // FIXME WHAT TO DO WHEN THE NEXT COLUMN IS NOT EDITABLE/HAS NO FOCUS >+ >+ int activeColumn = widgetWrapper.getCurrentColumnIndex(); >+ int totalColumns = widgetWrapper.getColumnCount(); >+ int activeRow = widgetWrapper.getCurrentRowIndex(); >+ int totalRows = widgetWrapper.getRowCount(); >+ >+ int editColumn = -1; >+ >+ if (e.detail == SWT.TRAVERSE_TAB_PREVIOUS) { >+ e.doit = false; >+ >+ if ((e.stateMask & SWT.CTRL) == SWT.CTRL && rowTabing) { >+ if (activeRow > 0) { >+ widgetWrapper.setSelectedRow(--activeRow); >+ editColumn = activeColumn; >+ } >+ } else if (columnTabing) { >+ if (activeColumn > 0) { >+ editColumn = --activeColumn; >+ } else if (cycleInRow) { >+ editColumn = totalColumns - 1; >+ } else if (moveToRowNeighbor) { >+ if (activeRow > 0) { >+ widgetWrapper.setSelectedRow(--activeRow); >+ editColumn = totalColumns - 1; >+ } >+ } >+ } >+ } else if (e.detail == SWT.TRAVERSE_TAB_NEXT) { >+ e.doit = false; >+ >+ if ((e.stateMask & SWT.CTRL) == SWT.CTRL && rowTabing) { >+ if (activeRow < totalRows - 1) { >+ widgetWrapper.setSelectedRow(++activeRow); >+ editColumn = activeColumn; >+ } >+ } else if (columnTabing) { >+ if (activeColumn < totalColumns - 1) { >+ editColumn = ++activeColumn; >+ } else if (cycleInRow) { >+ editColumn = 0; >+ } else if (moveToRowNeighbor) { >+ if (activeRow < totalRows - 1) { >+ widgetWrapper.setSelectedRow(++activeRow); >+ editColumn = 0; >+ } >+ } >+ } >+ } >+ >+ if (editColumn >= 0) { >+ viewer.editElement(((IStructuredSelection) viewer.getSelection()) >+ .getFirstElement(), editColumn); >+ return true; >+ } >+ >+ return false; >+ } >+ >+ /** >+ * @return Returns the columnTabing. >+ */ >+ public boolean isColumnTabing() { >+ return columnTabing; >+ } >+ >+ /** >+ * Setting this to true the user can move from column to column pressing TAB >+ * and SHIFT+TAB. This is turned on by default. >+ * >+ * @param columnTabing >+ * The columnTabing to set. >+ */ >+ public void setColumnTabing(boolean columnTabing) { >+ this.columnTabing = columnTabing; >+ } >+ >+ /** >+ * @return Returns the cycleInRow. >+ */ >+ public boolean isCycleInRow() { >+ return cycleInRow; >+ } >+ >+ /** >+ * Setting this to true results in the fact that when the end of the row is >+ * reached the cursor is moved to the first column in the row. This is >+ * turned of by default. >+ * >+ * @param cycleInRow >+ * The cycleInRow to set. >+ */ >+ public void setCycleInRow(boolean cycleInRow) { >+ this.cycleInRow = cycleInRow; >+ } >+ >+ /** >+ * Setting this to true results in the fact that when the end of the current >+ * row is reached the cursor is moved to first/last column in the >+ * successor/predecessor. This is turned of by default. >+ * >+ * @return Returns the moveToRowNeighbor. >+ */ >+ public boolean isMoveToRowNeighbor() { >+ return moveToRowNeighbor; >+ } >+ >+ /** >+ * @param moveToRowNeighbor >+ * The moveToRowNeighbor to set. >+ */ >+ public void setMoveToRowNeighbor(boolean moveToRowNeighbor) { >+ this.moveToRowNeighbor = moveToRowNeighbor; >+ } >+ >+ /** >+ * @return Returns the rowTabing. >+ */ >+ public boolean isRowTabing() { >+ return rowTabing; >+ } >+ >+ /** >+ * Setting this to true results in the fact that you user can jump from row >+ * to row using CTRL+TAB/CTRL+SHIFT+TAB. This is turned on by default. >+ * >+ * @param rowTabing >+ * The rowTabing to set. >+ */ >+ public void setRowTabing(boolean rowTabing) { >+ this.rowTabing = rowTabing; >+ } >+} >Index: src/org/eclipse/jface/viewers/TabEditingSupportWrapper.java >=================================================================== >RCS file: src/org/eclipse/jface/viewers/TabEditingSupportWrapper.java >diff -N src/org/eclipse/jface/viewers/TabEditingSupportWrapper.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/viewers/TabEditingSupportWrapper.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,50 @@ >+/******************************************************************************* >+ * Copyright (c) 2006 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ ******************************************************************************/ >+ >+package org.eclipse.jface.viewers; >+ >+/** >+ * This class wraps calls to really objects because they are not accessible >+ * through an interface because they are done on the concrete SWT-Classes e.g. >+ * Tree/Table/... >+ * >+ * @since 3.2 >+ * >+ */ >+public abstract class TabEditingSupportWrapper { >+ /** >+ * Set the current selected row >+ * >+ * @param index >+ * the new row index >+ */ >+ public abstract void setSelectedRow(int index); >+ >+ /** >+ * @return the total number of columns >+ */ >+ public abstract int getColumnCount(); >+ >+ /** >+ * @return the total number of rows >+ */ >+ public abstract int getRowCount(); >+ >+ /** >+ * @return the current column indexF >+ */ >+ public abstract int getCurrentColumnIndex(); >+ >+ /** >+ * @return the current row index >+ */ >+ public abstract int getCurrentRowIndex(); >+}
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 75114
:
18352
|
18353
|
41404
| 41408