Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 151377 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/jface/viewers/TableViewer.java (+70 lines)
Lines 15-21 Link Here
15
import java.util.HashSet;
15
import java.util.HashSet;
16
import java.util.List;
16
import java.util.List;
17
17
18
import org.eclipse.core.runtime.ListenerList;
18
import org.eclipse.jface.util.Assert;
19
import org.eclipse.jface.util.Assert;
20
import org.eclipse.jface.util.SafeRunnable;
19
import org.eclipse.swt.SWT;
21
import org.eclipse.swt.SWT;
20
import org.eclipse.swt.custom.TableEditor;
22
import org.eclipse.swt.custom.TableEditor;
21
import org.eclipse.swt.events.MouseAdapter;
23
import org.eclipse.swt.events.MouseAdapter;
Lines 256-261 Link Here
256
	private TableColorAndFontNoOp tableColorAndFont = new TableColorAndFontNoOp();
258
	private TableColorAndFontNoOp tableColorAndFont = new TableColorAndFontNoOp();
257
	
259
	
258
	/**
260
	/**
261
	 * Listeners for cell-selections
262
	 */
263
	private ListenerList cellSelectionListeners = new ListenerList();
264
	
265
	/**
259
	 * Creates a table viewer on a newly-created table control under the given
266
	 * Creates a table viewer on a newly-created table control under the given
260
	 * parent. The table control is created using the SWT style bits
267
	 * parent. The table control is created using the SWT style bits
261
	 * <code>MULTI, H_SCROLL, V_SCROLL,</code> and <code>BORDER</code>. The
268
	 * <code>MULTI, H_SCROLL, V_SCROLL,</code> and <code>BORDER</code>. The
Lines 285-290 Link Here
285
	}
292
	}
286
293
287
	/**
294
	/**
295
	 * Adding a cell selection listener
296
	 * @param listener listener for cell selections
297
	 */
298
	public void addCellSelectionListener(ICellSelectionListener listener) {
299
		this.cellSelectionListeners.add(listener);
300
	}
301
	
302
	/**
303
	 * Remove the cell selection listener
304
	 * @param listener listener for cell selections
305
	 */
306
	public void removeCellSelectionListener(ICellSelectionListener listener) {
307
		this.cellSelectionListeners.remove(listener);
308
	}
309
	
310
	/**
311
	 * Create the event used to select a cell
312
	 * 
313
	 * @param event the mouse event
314
	 * @return the cell selection event
315
	 */
316
	private CellSelectionEvent createCellSelectionEvent(MouseEvent event) {
317
		CellSelectionEvent selectionEvent = null;
318
		TableItem[] items = table.getSelection();
319
		int columnIndex = -1;
320
		TableItem item = null;
321
		
322
		for( int i = 0; i < items.length; i++ ) {
323
			for( int j = 0; j < table.getColumnCount(); j++ ) {
324
				Rectangle bounds = items[i].getBounds(j);
325
				System.err.println(bounds);
326
	            if (bounds.contains(event.x, event.y)) {
327
	            	columnIndex = j;
328
	            	item = items[i];
329
	                break;
330
	            }
331
			}
332
		}
333
		
334
		if( columnIndex != -1 ) {
335
			selectionEvent = new CellSelectionEvent(this,item,columnIndex);
336
		}
337
		
338
		return selectionEvent;
339
	}
340
	
341
	/**
288
	 * Creates a table viewer on the given table control. The viewer has no
342
	 * Creates a table viewer on the given table control. The viewer has no
289
	 * input, no content provider, a default label provider, no sorter, and no
343
	 * input, no content provider, a default label provider, no sorter, and no
290
	 * filters.
344
	 * filters.
Lines 672-677 Link Here
672
		Table tableControl = (Table) control;
726
		Table tableControl = (Table) control;
673
		tableControl.addMouseListener(new MouseAdapter() {
727
		tableControl.addMouseListener(new MouseAdapter() {
674
			public void mouseDown(MouseEvent e) {
728
			public void mouseDown(MouseEvent e) {
729
				
730
				if( ! cellSelectionListeners.isEmpty() ) {
731
					final CellSelectionEvent event = createCellSelectionEvent(e);
732
					if( event != null ) {
733
						Object[] listeners = cellSelectionListeners.getListeners();
734
						for( int i = 0; i < listeners.length; i++ ) {
735
							final ICellSelectionListener listener = (ICellSelectionListener)listeners[i];
736
							SafeRunnable.run(new SafeRunnable() {
737
								public void run() {
738
									listener.cellSelected(event);
739
				                }
740
							});
741
						}
742
					}
743
				}
744
				
675
				tableViewerImpl.handleMouseDown(e);
745
				tableViewerImpl.handleMouseDown(e);
676
			}
746
			}
677
		});
747
		});
(-)src/org/eclipse/jface/viewers/TreeViewer.java (+70 lines)
Lines 14-20 Link Here
14
import java.util.Iterator;
14
import java.util.Iterator;
15
import java.util.List;
15
import java.util.List;
16
16
17
import org.eclipse.core.runtime.ListenerList;
17
import org.eclipse.jface.util.Assert;
18
import org.eclipse.jface.util.Assert;
19
import org.eclipse.jface.util.SafeRunnable;
18
import org.eclipse.swt.SWT;
20
import org.eclipse.swt.SWT;
19
import org.eclipse.swt.custom.TreeEditor;
21
import org.eclipse.swt.custom.TreeEditor;
20
import org.eclipse.swt.events.DisposeEvent;
22
import org.eclipse.swt.events.DisposeEvent;
Lines 143-148 Link Here
143
	private boolean treeIsDisposed = false;
145
	private boolean treeIsDisposed = false;
144
146
145
	/**
147
	/**
148
	 * Listeners for cell-selections
149
	 */
150
	private ListenerList cellSelectionListeners = new ListenerList();
151
	
152
	/**
146
	 * Creates a tree viewer on a newly-created tree control under the given
153
	 * Creates a tree viewer on a newly-created tree control under the given
147
	 * parent. The tree control is created using the SWT style bits
154
	 * parent. The tree control is created using the SWT style bits
148
	 * <code>MULTI, H_SCROLL, V_SCROLL,</code> and <code>BORDER</code>. The
155
	 * <code>MULTI, H_SCROLL, V_SCROLL,</code> and <code>BORDER</code>. The
Lines 186-191 Link Here
186
		initTreeViewerImpl();
193
		initTreeViewerImpl();
187
	}
194
	}
188
195
196
	/**
197
	 * Adding a cell selection listener
198
	 * @param listener listener for cell selections
199
	 */
200
	public void addCellSelectionListener(ICellSelectionListener listener) {
201
		this.cellSelectionListeners.add(listener);
202
	}
203
	
204
	/**
205
	 * Remove the cell selection listener
206
	 * @param listener listener for cell selections
207
	 */
208
	public void removeCellSelectionListener(ICellSelectionListener listener) {
209
		this.cellSelectionListeners.remove(listener);
210
	}
211
	
212
	/**
213
	 * Create the event used to select a cell
214
	 * 
215
	 * @param event the mouse event
216
	 * @return the cell selection event
217
	 */
218
	private CellSelectionEvent createCellSelectionEvent(MouseEvent event) {
219
		CellSelectionEvent selectionEvent = null;
220
		TreeItem[] items = tree.getSelection();
221
		int columnIndex = -1;
222
		TreeItem item = null;
223
		
224
		for( int i = 0; i < items.length; i++ ) {
225
			for( int j = 0; j < tree.getColumnCount(); j++ ) {
226
				Rectangle bounds = items[i].getBounds(j);
227
				System.err.println(bounds);
228
	            if (bounds.contains(event.x, event.y)) {
229
	            	columnIndex = j;
230
	            	item = items[i];
231
	                break;
232
	            }
233
			}
234
		}
235
		
236
		if( columnIndex != -1 ) {
237
			selectionEvent = new CellSelectionEvent(this,item,columnIndex);
238
		}
239
		
240
		return selectionEvent;
241
	}
242
	
189
	/*
243
	/*
190
	 * (non-Javadoc) Method declared in AbstractTreeViewer.
244
	 * (non-Javadoc) Method declared in AbstractTreeViewer.
191
	 */
245
	 */
Lines 490-495 Link Here
490
		Tree treeControl = (Tree) control;
544
		Tree treeControl = (Tree) control;
491
		treeControl.addMouseListener(new MouseAdapter() {
545
		treeControl.addMouseListener(new MouseAdapter() {
492
			public void mouseDown(MouseEvent e) {
546
			public void mouseDown(MouseEvent e) {
547
				
548
				if( ! cellSelectionListeners.isEmpty() ) {
549
					final CellSelectionEvent event = createCellSelectionEvent(e);
550
					if( event != null ) {
551
						Object[] listeners = cellSelectionListeners.getListeners();
552
						for( int i = 0; i < listeners.length; i++ ) {
553
							final ICellSelectionListener listener = (ICellSelectionListener)listeners[i];
554
							SafeRunnable.run(new SafeRunnable() {
555
								public void run() {
556
									listener.cellSelected(event);
557
				                }
558
							});
559
						}
560
					}
561
				}
562
493
				treeViewerImpl.handleMouseDown(e);
563
				treeViewerImpl.handleMouseDown(e);
494
			}
564
			}
495
		});
565
		});
(-)src/org/eclipse/jface/viewers/CellSelectionEvent.java (+62 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 ******************************************************************************/
11
12
package org.eclipse.jface.viewers;
13
14
import java.util.EventObject;
15
16
import org.eclipse.swt.widgets.Item;
17
18
/**
19
 * @since 3.3
20
 * 
21
 */
22
public class CellSelectionEvent extends EventObject {
23
24
	/**
25
	 * 
26
	 */
27
	private static final long serialVersionUID = 7108743376612858108L;
28
29
	private Item item;
30
31
	private int column;
32
33
	/**
34
	 * Create new CellSelectionEvent
35
	 * 
36
	 * @param viewer
37
	 *            the source of the viewer
38
	 * @param item
39
	 *            the item representing the row
40
	 * @param column
41
	 *            the column
42
	 */
43
	public CellSelectionEvent(Viewer viewer, Item item, int column) {
44
		super(viewer);
45
		this.item = item;
46
		this.column = column;
47
	}
48
49
	/**
50
	 * @return the item representing the row
51
	 */
52
	public Item getItem() {
53
		return item;
54
	}
55
56
	/**
57
	 * @return the column number
58
	 */
59
	public int getColumn() {
60
		return column;
61
	}
62
}
(-)src/org/eclipse/jface/viewers/ICellSelectionListener.java (+26 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 ******************************************************************************/
11
12
package org.eclipse.jface.viewers;
13
14
/**
15
 * @since 3.3
16
 * 
17
 */
18
public interface ICellSelectionListener {
19
	/**
20
	 * Called when a cell is selected
21
	 * 
22
	 * @param event
23
	 *            the selection event
24
	 */
25
	public void cellSelected(CellSelectionEvent event);
26
}

Return to bug 151377