|
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 |
}); |