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 45532 Details for
Bug 87733
[CellEditors] Double click behavior for tableviewer
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]
Implementation of editor activation strategy
patch.txt (text/plain), 12.30 KB, created by
Thomas Schindl
on 2006-06-29 09:41:34 EDT
(
hide
)
Description:
Implementation of editor activation strategy
Filename:
MIME Type:
Creator:
Thomas Schindl
Created:
2006-06-29 09:41:34 EDT
Size:
12.30 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jface >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.56 >diff -u -r1.56 TableViewer.java >--- src/org/eclipse/jface/viewers/TableViewer.java 15 Jun 2006 22:28:48 -0000 1.56 >+++ src/org/eclipse/jface/viewers/TableViewer.java 29 Jun 2006 13:42:01 -0000 >@@ -18,6 +18,8 @@ > import org.eclipse.jface.util.Assert; > import org.eclipse.swt.SWT; > import org.eclipse.swt.custom.TableEditor; >+import org.eclipse.swt.events.KeyEvent; >+import org.eclipse.swt.events.KeyListener; > import org.eclipse.swt.events.MouseAdapter; > import org.eclipse.swt.events.MouseEvent; > import org.eclipse.swt.graphics.Image; >@@ -256,6 +258,17 @@ > private TableColorAndFontNoOp tableColorAndFont = new TableColorAndFontNoOp(); > > /** >+ * Strategy to enable control activation of celleditors >+ */ >+ private ICellEditorActivationStrategy cellEditorActivationStrategy; >+ >+ /** >+ * The last mouse event has to be remembered because the double-click doesn't provide informations >+ * about this >+ */ >+ private MouseEvent lastMouseEvent; >+ >+ /** > * 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 >@@ -662,19 +675,87 @@ > public Table getTable() { > return table; > } >- >+ > /* > * (non-Javadoc) > * @see org.eclipse.jface.viewers.ContentViewer#hookControl(org.eclipse.swt.widgets.Control) > */ > protected void hookControl(Control control) { > super.hookControl(control); >- Table tableControl = (Table) control; >+ final Table tableControl = (Table) control; > tableControl.addMouseListener(new MouseAdapter() { > public void mouseDown(MouseEvent e) { >- tableViewerImpl.handleMouseDown(e); >+ // Avoid overhead when no editors defined >+ if( getCellEditors() != null && getCellEditors().length > 0 ) { >+ // Avoid overhead when no activation strategy >+ if( cellEditorActivationStrategy == null ) { >+ tableViewerImpl.handleMouseDown(e); >+ } else { >+ Item[] items = tableControl.getSelection(); >+ // Do not edit if more than one row is selected. >+ if (items.length != 1) { >+ return; >+ } >+ >+ >+ if( cellEditorActivationStrategy == null || cellEditorActivationStrategy.shouldActivateCellEditor(e, items[0].getData(), false) ) { >+ tableViewerImpl.handleMouseDown(e); >+ } >+ >+ TableViewer.this.lastMouseEvent = e; >+ } >+ } >+ } >+ }); >+ >+ // We need to handle it this way because using after the double click a selection event >+ // occurs and the cell-editor would loose focus >+ addDoubleClickListener(new IDoubleClickListener() { >+ public void doubleClick(DoubleClickEvent event) { >+ // Avoid overhead when no activation strategy or no editors >+ if( cellEditorActivationStrategy != null && getCellEditors() != null && getCellEditors().length > 0 ) { >+ Item[] items = tableControl.getSelection(); >+ // Do not edit if more than one row is selected. >+ if (items.length != 1) { >+ return; >+ } >+ >+ if( cellEditorActivationStrategy != null && cellEditorActivationStrategy.shouldActivateCellEditor(lastMouseEvent, items[0].getData(), true) ) { >+ tableViewerImpl.handleMouseDown(lastMouseEvent); >+ } >+ } > } > }); >+ >+ // Pressing return on a table control results in DoubleClick Event >+ tableControl.addKeyListener(new KeyListener() { >+ >+ public void keyPressed(KeyEvent e) { >+ if( cellEditorActivationStrategy != null && getCellEditors() != null && getCellEditors().length > 0 && e.keyCode == '\r' ) { >+ Event event = new Event(); >+ event.x = -1; >+ event.y = -1; >+ event.widget = tableControl; >+ >+ TableItem[] items = tableControl.getSelection(); >+ // Do not edit if more than one row is selected. >+ if (items.length != 1) { >+ return; >+ } >+ >+ event.x = items[0].getBounds().x; >+ event.y = items[0].getBounds().y; >+ event.button = 1; >+ >+ TableViewer.this.lastMouseEvent = new MouseEvent(event); >+ } >+ } >+ >+ public void keyReleased(KeyEvent e) { >+ >+ } >+ >+ }); > } > > /* >@@ -1287,8 +1368,14 @@ > Assert.isTrue(provider instanceof IStructuredContentProvider || > provider instanceof ILazyContentProvider); > } >- >- >- >+ >+ public ICellEditorActivationStrategy getCellEditorActivationStrategy() { >+ return cellEditorActivationStrategy; >+ } >+ >+ public void setCellEditorActivationStrategy( >+ ICellEditorActivationStrategy cellEditorActivationStrategy) { >+ this.cellEditorActivationStrategy = cellEditorActivationStrategy; >+ } > } > >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.50 >diff -u -r1.50 TreeViewer.java >--- src/org/eclipse/jface/viewers/TreeViewer.java 30 May 2006 20:15:06 -0000 1.50 >+++ src/org/eclipse/jface/viewers/TreeViewer.java 29 Jun 2006 13:42:01 -0000 >@@ -19,6 +19,8 @@ > import org.eclipse.swt.custom.TreeEditor; > import org.eclipse.swt.events.DisposeEvent; > import org.eclipse.swt.events.DisposeListener; >+import org.eclipse.swt.events.KeyAdapter; >+import org.eclipse.swt.events.KeyEvent; > import org.eclipse.swt.events.MouseAdapter; > import org.eclipse.swt.events.MouseEvent; > import org.eclipse.swt.events.TreeListener; >@@ -143,6 +145,17 @@ > private boolean treeIsDisposed = false; > > /** >+ * Strategy to enable control activation of celleditors >+ */ >+ private ICellEditorActivationStrategy cellEditorActivationStrategy; >+ >+ /** >+ * The last mouse event has to be remembered because the double-click doesn't provide informations >+ * about this >+ */ >+ private MouseEvent lastMouseEvent; >+ >+ /** > * Creates a tree viewer on a newly-created tree control under the given > * parent. The tree control is created using the SWT style bits > * <code>MULTI, H_SCROLL, V_SCROLL,</code> and <code>BORDER</code>. The >@@ -487,12 +500,8 @@ > */ > protected void hookControl(Control control) { > super.hookControl(control); >- Tree treeControl = (Tree) control; >- treeControl.addMouseListener(new MouseAdapter() { >- public void mouseDown(MouseEvent e) { >- treeViewerImpl.handleMouseDown(e); >- } >- }); >+ final Tree treeControl = (Tree) control; >+ > if ((treeControl.getStyle() & SWT.VIRTUAL) != 0) { > treeControl.addDisposeListener(new DisposeListener(){ > public void widgetDisposed(DisposeEvent e) { >@@ -520,6 +529,75 @@ > } > }); > } >+ >+ treeControl.addMouseListener(new MouseAdapter() { >+ public void mouseDown(MouseEvent e) { >+ // Avoid overhead when no editors defined >+ if( getCellEditors() != null && getCellEditors().length > 0 ) { >+ // Avoid overhead when no activation strategy >+ if( cellEditorActivationStrategy == null ) { >+ treeViewerImpl.handleMouseDown(e); >+ } else { >+ Item[] items = treeControl.getSelection(); >+ // Do not edit if more than one row is selected. >+ if (items.length != 1) { >+ return; >+ } >+ >+ if( cellEditorActivationStrategy == null || cellEditorActivationStrategy.shouldActivateCellEditor(e, items[0].getData(), false) ) { >+ treeViewerImpl.handleMouseDown(e); >+ } >+ >+ TreeViewer.this.lastMouseEvent = e; >+ } >+ } >+ } >+ }); >+ >+ // We need to handle it this way because using after the double click a selection event >+ // occurs and the cell-editor would loose focus >+ addDoubleClickListener(new IDoubleClickListener() { >+ public void doubleClick(DoubleClickEvent event) { >+ // Avoid overhead when no activation strategy or no editors >+ if( cellEditorActivationStrategy != null && getCellEditors() != null && getCellEditors().length > 0 ) { >+ Item[] items = treeControl.getSelection(); >+ // Do not edit if more than one row is selected. >+ if (items.length != 1) { >+ return; >+ } >+ >+ if( cellEditorActivationStrategy.shouldActivateCellEditor(lastMouseEvent, items[0].getData(), true) ) { >+ treeViewerImpl.handleMouseDown(lastMouseEvent); >+ } >+ } >+ } >+ }); >+ >+ // Pressing return on a table control results in DoubleClick Event >+ treeControl.addKeyListener(new KeyAdapter() { >+ >+ public void keyPressed(KeyEvent e) { >+ // Avoid overhead when no activation strategy or no editors >+ if( cellEditorActivationStrategy != null && getCellEditors() != null && getCellEditors().length > 0 && e.keyCode == '\r' ) { >+ Event event = new Event(); >+ event.x = -1; >+ event.y = -1; >+ event.widget = treeControl; >+ >+ TreeItem[] items = treeControl.getSelection(); >+ // Do not edit if more than one row is selected. >+ if (items.length != 1) { >+ return; >+ } >+ >+ event.x = items[0].getBounds().x; >+ event.y = items[0].getBounds().y; >+ event.button = 1; >+ >+ TreeViewer.this.lastMouseEvent = new MouseEvent(event); >+ } >+ } >+ }); > } > > /** >Index: src/org/eclipse/jface/viewers/DoubleClickEditorActivationStrategy.java >=================================================================== >RCS file: src/org/eclipse/jface/viewers/DoubleClickEditorActivationStrategy.java >diff -N src/org/eclipse/jface/viewers/DoubleClickEditorActivationStrategy.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/viewers/DoubleClickEditorActivationStrategy.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,30 @@ >+/******************************************************************************* >+ * 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.MouseEvent; >+ >+/** >+ * Activate CellEditors only on DoubleClick >+ * >+ * @since 3.3 >+ */ >+public class DoubleClickEditorActivationStrategy implements ICellEditorActivationStrategy { >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.jface.viewers.ICellEditorActivationStrategy#shouldActivateCellEditor(org.eclipse.swt.events.MouseEvent) >+ */ >+ public boolean shouldActivateCellEditor(MouseEvent event,Object element,boolean doubleClick) { >+ return doubleClick; >+ } >+ >+} >Index: src/org/eclipse/jface/viewers/ICellEditorActivationStrategy.java >=================================================================== >RCS file: src/org/eclipse/jface/viewers/ICellEditorActivationStrategy.java >diff -N src/org/eclipse/jface/viewers/ICellEditorActivationStrategy.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/viewers/ICellEditorActivationStrategy.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,37 @@ >+/******************************************************************************* >+ * 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.MouseEvent; >+ >+/** >+ * >+ * Interface for classes who want to provide specialized cell-editor activation >+ * >+ * @since 3.3 >+ * >+ */ >+public interface ICellEditorActivationStrategy { >+ /** >+ * Decide whether the actual event should tigger a activation event >+ * >+ * @param event >+ * the event >+ * @param element >+ * the model element >+ * @param doubleClick >+ * is it a double-click >+ * @return true if this event should trigger selection >+ */ >+ public boolean shouldActivateCellEditor(MouseEvent event, Object element, >+ boolean doubleClick); >+}
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 87733
:
45532
|
45533
|
46238