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 41404 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]
This is very flexible implementation to add tab support to TableViewer
patch.txt (text/plain), 9.15 KB, created by
Thomas Schindl
on 2006-05-13 12:40:10 EDT
(
hide
)
Description:
This is very flexible implementation to add tab support to TableViewer
Filename:
MIME Type:
Creator:
Thomas Schindl
Created:
2006-05-13 12:40:10 EDT
Size:
9.15 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 16:36:48 -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; >@@ -64,7 +66,12 @@ > * @see #internalRefresh(Object, boolean) > */ > public class TableViewer extends StructuredViewer { >- >+ 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,64 @@ > 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 { >+ public void keyTraversed(TraverseEvent e) { >+ TableViewer.this.tabeditingDelgate.focusNewEditor(e, TableViewer.this.tableEditor, TableViewer.this, table); >+ } >+ } > } > >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,186 @@ >+/******************************************************************************* >+ * 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.custom.TableEditor; >+import org.eclipse.swt.events.TraverseEvent; >+import org.eclipse.swt.widgets.Table; >+ >+/** >+ * 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 tableEditor >+ * the editor >+ * @param tableViewer >+ * the table viewer the column belongs to >+ * @param table >+ * the physical SWT-table >+ * @return true if a new column is activated >+ */ >+ public boolean focusNewEditor(TraverseEvent e, TableEditor tableEditor, >+ TableViewer tableViewer, Table table) { >+ // FIXME WHAT TO DO WHEN THE NEXT COLUMN IS NOT EDITABLE/HAS NO FOCUS >+ int activeColumn = tableEditor.getColumn(); >+ int editColumn = -1; >+ >+ if (e.detail == SWT.TRAVERSE_TAB_PREVIOUS) { >+ e.doit = false; >+ >+ if ((e.stateMask & SWT.CTRL) == SWT.CTRL && rowTabing) { >+ int row = table.getSelectionIndex(); >+ if (row > 0) { >+ table.setSelection(--row); >+ editColumn = activeColumn; >+ } >+ } else if (columnTabing) { >+ if (activeColumn > 0) { >+ editColumn = --activeColumn; >+ } else if (cycleInRow) { >+ editColumn = table.getColumnCount() - 1; >+ } else if (!moveToRowNeighbor) { >+ int row = table.getSelectionIndex(); >+ if (row > 0) { >+ table.setSelection(--row); >+ editColumn = table.getColumnCount() - 1; >+ } >+ } >+ } >+ } else if (e.detail == SWT.TRAVERSE_TAB_NEXT) { >+ e.doit = false; >+ >+ if ((e.stateMask & SWT.CTRL) == SWT.CTRL && rowTabing) { >+ int row = table.getSelectionIndex(); >+ if (row < table.getItemCount() - 1) { >+ table.setSelection(++row); >+ editColumn = activeColumn; >+ } >+ } else if (columnTabing) { >+ if (activeColumn < table.getColumnCount() - 1) { >+ editColumn = ++activeColumn; >+ } else if (cycleInRow) { >+ editColumn = 0; >+ } else if (!moveToRowNeighbor) { >+ int row = table.getSelectionIndex(); >+ if (row < table.getItemCount() - 1) { >+ table.setSelection(++row); >+ editColumn = 0; >+ } >+ } >+ } >+ } >+ >+ if (editColumn >= 0) { >+ tableViewer.editElement(((IStructuredSelection) tableViewer >+ .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; >+ } >+}
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