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 46627 Details for
Bug 151377
[CellEditors] Listeners for CellSelections
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]
Adds new Listener API to Listen for CellSelections
patch.txt (text/plain), 9.66 KB, created by
Thomas Schindl
on 2006-07-21 04:49:40 EDT
(
hide
)
Description:
Adds new Listener API to Listen for CellSelections
Filename:
MIME Type:
Creator:
Thomas Schindl
Created:
2006-07-21 04:49:40 EDT
Size:
9.66 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 21 Jul 2006 08:50:18 -0000 >@@ -15,7 +15,9 @@ > import java.util.HashSet; > import java.util.List; > >+import org.eclipse.core.runtime.ListenerList; > import org.eclipse.jface.util.Assert; >+import org.eclipse.jface.util.SafeRunnable; > import org.eclipse.swt.SWT; > import org.eclipse.swt.custom.TableEditor; > import org.eclipse.swt.events.MouseAdapter; >@@ -256,6 +258,11 @@ > private TableColorAndFontNoOp tableColorAndFont = new TableColorAndFontNoOp(); > > /** >+ * Listeners for cell-selections >+ */ >+ private ListenerList cellSelectionListeners = new ListenerList(); >+ >+ /** > * 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 >@@ -285,6 +292,53 @@ > } > > /** >+ * Adding a cell selection listener >+ * @param listener listener for cell selections >+ */ >+ public void addCellSelectionListener(ICellSelectionListener listener) { >+ this.cellSelectionListeners.add(listener); >+ } >+ >+ /** >+ * Remove the cell selection listener >+ * @param listener listener for cell selections >+ */ >+ public void removeCellSelectionListener(ICellSelectionListener listener) { >+ this.cellSelectionListeners.remove(listener); >+ } >+ >+ /** >+ * Create the event used to select a cell >+ * >+ * @param event the mouse event >+ * @return the cell selection event >+ */ >+ private CellSelectionEvent createCellSelectionEvent(MouseEvent event) { >+ CellSelectionEvent selectionEvent = null; >+ TableItem[] items = table.getSelection(); >+ int columnIndex = -1; >+ TableItem item = null; >+ >+ for( int i = 0; i < items.length; i++ ) { >+ for( int j = 0; j < table.getColumnCount(); j++ ) { >+ Rectangle bounds = items[i].getBounds(j); >+ System.err.println(bounds); >+ if (bounds.contains(event.x, event.y)) { >+ columnIndex = j; >+ item = items[i]; >+ break; >+ } >+ } >+ } >+ >+ if( columnIndex != -1 ) { >+ selectionEvent = new CellSelectionEvent(this,item,columnIndex); >+ } >+ >+ return selectionEvent; >+ } >+ >+ /** > * Creates a table viewer on the given table control. The viewer has no > * input, no content provider, a default label provider, no sorter, and no > * filters. >@@ -672,6 +726,22 @@ > Table tableControl = (Table) control; > tableControl.addMouseListener(new MouseAdapter() { > public void mouseDown(MouseEvent e) { >+ >+ if( ! cellSelectionListeners.isEmpty() ) { >+ final CellSelectionEvent event = createCellSelectionEvent(e); >+ if( event != null ) { >+ Object[] listeners = cellSelectionListeners.getListeners(); >+ for( int i = 0; i < listeners.length; i++ ) { >+ final ICellSelectionListener listener = (ICellSelectionListener)listeners[i]; >+ SafeRunnable.run(new SafeRunnable() { >+ public void run() { >+ listener.cellSelected(event); >+ } >+ }); >+ } >+ } >+ } >+ > tableViewerImpl.handleMouseDown(e); > } > }); >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 21 Jul 2006 08:50:18 -0000 >@@ -14,7 +14,9 @@ > import java.util.Iterator; > import java.util.List; > >+import org.eclipse.core.runtime.ListenerList; > import org.eclipse.jface.util.Assert; >+import org.eclipse.jface.util.SafeRunnable; > import org.eclipse.swt.SWT; > import org.eclipse.swt.custom.TreeEditor; > import org.eclipse.swt.events.DisposeEvent; >@@ -143,6 +145,11 @@ > private boolean treeIsDisposed = false; > > /** >+ * Listeners for cell-selections >+ */ >+ private ListenerList cellSelectionListeners = new ListenerList(); >+ >+ /** > * 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 >@@ -186,6 +193,53 @@ > initTreeViewerImpl(); > } > >+ /** >+ * Adding a cell selection listener >+ * @param listener listener for cell selections >+ */ >+ public void addCellSelectionListener(ICellSelectionListener listener) { >+ this.cellSelectionListeners.add(listener); >+ } >+ >+ /** >+ * Remove the cell selection listener >+ * @param listener listener for cell selections >+ */ >+ public void removeCellSelectionListener(ICellSelectionListener listener) { >+ this.cellSelectionListeners.remove(listener); >+ } >+ >+ /** >+ * Create the event used to select a cell >+ * >+ * @param event the mouse event >+ * @return the cell selection event >+ */ >+ private CellSelectionEvent createCellSelectionEvent(MouseEvent event) { >+ CellSelectionEvent selectionEvent = null; >+ TreeItem[] items = tree.getSelection(); >+ int columnIndex = -1; >+ TreeItem item = null; >+ >+ for( int i = 0; i < items.length; i++ ) { >+ for( int j = 0; j < tree.getColumnCount(); j++ ) { >+ Rectangle bounds = items[i].getBounds(j); >+ System.err.println(bounds); >+ if (bounds.contains(event.x, event.y)) { >+ columnIndex = j; >+ item = items[i]; >+ break; >+ } >+ } >+ } >+ >+ if( columnIndex != -1 ) { >+ selectionEvent = new CellSelectionEvent(this,item,columnIndex); >+ } >+ >+ return selectionEvent; >+ } >+ > /* > * (non-Javadoc) Method declared in AbstractTreeViewer. > */ >@@ -490,6 +544,22 @@ > Tree treeControl = (Tree) control; > treeControl.addMouseListener(new MouseAdapter() { > public void mouseDown(MouseEvent e) { >+ >+ if( ! cellSelectionListeners.isEmpty() ) { >+ final CellSelectionEvent event = createCellSelectionEvent(e); >+ if( event != null ) { >+ Object[] listeners = cellSelectionListeners.getListeners(); >+ for( int i = 0; i < listeners.length; i++ ) { >+ final ICellSelectionListener listener = (ICellSelectionListener)listeners[i]; >+ SafeRunnable.run(new SafeRunnable() { >+ public void run() { >+ listener.cellSelected(event); >+ } >+ }); >+ } >+ } >+ } >+ > treeViewerImpl.handleMouseDown(e); > } > }); >Index: src/org/eclipse/jface/viewers/CellSelectionEvent.java >=================================================================== >RCS file: src/org/eclipse/jface/viewers/CellSelectionEvent.java >diff -N src/org/eclipse/jface/viewers/CellSelectionEvent.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/viewers/CellSelectionEvent.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,62 @@ >+/******************************************************************************* >+ * 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 java.util.EventObject; >+ >+import org.eclipse.swt.widgets.Item; >+ >+/** >+ * @since 3.3 >+ * >+ */ >+public class CellSelectionEvent extends EventObject { >+ >+ /** >+ * >+ */ >+ private static final long serialVersionUID = 7108743376612858108L; >+ >+ private Item item; >+ >+ private int column; >+ >+ /** >+ * Create new CellSelectionEvent >+ * >+ * @param viewer >+ * the source of the viewer >+ * @param item >+ * the item representing the row >+ * @param column >+ * the column >+ */ >+ public CellSelectionEvent(Viewer viewer, Item item, int column) { >+ super(viewer); >+ this.item = item; >+ this.column = column; >+ } >+ >+ /** >+ * @return the item representing the row >+ */ >+ public Item getItem() { >+ return item; >+ } >+ >+ /** >+ * @return the column number >+ */ >+ public int getColumn() { >+ return column; >+ } >+} >Index: src/org/eclipse/jface/viewers/ICellSelectionListener.java >=================================================================== >RCS file: src/org/eclipse/jface/viewers/ICellSelectionListener.java >diff -N src/org/eclipse/jface/viewers/ICellSelectionListener.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/viewers/ICellSelectionListener.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,26 @@ >+/******************************************************************************* >+ * 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; >+ >+/** >+ * @since 3.3 >+ * >+ */ >+public interface ICellSelectionListener { >+ /** >+ * Called when a cell is selected >+ * >+ * @param event >+ * the selection event >+ */ >+ public void cellSelected(CellSelectionEvent event); >+}
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 151377
:
46627
|
54784
|
54904
|
55407
|
55408
|
55412