|
Lines 18-23
Link Here
|
| 18 |
import org.eclipse.jface.util.Assert; |
18 |
import org.eclipse.jface.util.Assert; |
| 19 |
import org.eclipse.swt.SWT; |
19 |
import org.eclipse.swt.SWT; |
| 20 |
import org.eclipse.swt.custom.TableEditor; |
20 |
import org.eclipse.swt.custom.TableEditor; |
|
|
21 |
import org.eclipse.swt.events.KeyEvent; |
| 22 |
import org.eclipse.swt.events.KeyListener; |
| 21 |
import org.eclipse.swt.events.MouseAdapter; |
23 |
import org.eclipse.swt.events.MouseAdapter; |
| 22 |
import org.eclipse.swt.events.MouseEvent; |
24 |
import org.eclipse.swt.events.MouseEvent; |
| 23 |
import org.eclipse.swt.graphics.Image; |
25 |
import org.eclipse.swt.graphics.Image; |
|
Lines 256-261
Link Here
|
| 256 |
private TableColorAndFontNoOp tableColorAndFont = new TableColorAndFontNoOp(); |
258 |
private TableColorAndFontNoOp tableColorAndFont = new TableColorAndFontNoOp(); |
| 257 |
|
259 |
|
| 258 |
/** |
260 |
/** |
|
|
261 |
* Strategy to enable control activation of celleditors |
| 262 |
*/ |
| 263 |
private ICellEditorActivationStrategy cellEditorActivationStrategy; |
| 264 |
|
| 265 |
/** |
| 266 |
* The last mouse event has to be remembered because the double-click doesn't provide informations |
| 267 |
* about this |
| 268 |
*/ |
| 269 |
private MouseEvent lastMouseEvent; |
| 270 |
|
| 271 |
/** |
| 272 |
* Prevent from a possible endless-loop |
| 273 |
*/ |
| 274 |
private MouseEvent ddMouseEvent; |
| 275 |
|
| 276 |
/** |
| 259 |
* Creates a table viewer on a newly-created table control under the given |
277 |
* 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 |
278 |
* parent. The table control is created using the SWT style bits |
| 261 |
* <code>MULTI, H_SCROLL, V_SCROLL,</code> and <code>BORDER</code>. The |
279 |
* <code>MULTI, H_SCROLL, V_SCROLL,</code> and <code>BORDER</code>. The |
|
Lines 662-679
Link Here
|
| 662 |
public Table getTable() { |
680 |
public Table getTable() { |
| 663 |
return table; |
681 |
return table; |
| 664 |
} |
682 |
} |
| 665 |
|
683 |
|
| 666 |
/* |
684 |
/* |
| 667 |
* (non-Javadoc) |
685 |
* (non-Javadoc) |
| 668 |
* @see org.eclipse.jface.viewers.ContentViewer#hookControl(org.eclipse.swt.widgets.Control) |
686 |
* @see org.eclipse.jface.viewers.ContentViewer#hookControl(org.eclipse.swt.widgets.Control) |
| 669 |
*/ |
687 |
*/ |
| 670 |
protected void hookControl(Control control) { |
688 |
protected void hookControl(Control control) { |
| 671 |
super.hookControl(control); |
689 |
super.hookControl(control); |
| 672 |
Table tableControl = (Table) control; |
690 |
final Table tableControl = (Table) control; |
| 673 |
tableControl.addMouseListener(new MouseAdapter() { |
691 |
tableControl.addMouseListener(new MouseAdapter() { |
| 674 |
public void mouseDown(MouseEvent e) { |
692 |
public void mouseDown(MouseEvent e) { |
| 675 |
tableViewerImpl.handleMouseDown(e); |
693 |
// Avoid overhead when no editors defined |
|
|
694 |
if( getCellEditors() != null && getCellEditors().length > 0 ) { |
| 695 |
// Avoid overhead when no activation strategy |
| 696 |
if( cellEditorActivationStrategy == null ) { |
| 697 |
tableViewerImpl.handleMouseDown(e); |
| 698 |
} else { |
| 699 |
Item[] items = tableControl.getSelection(); |
| 700 |
// Do not edit if more than one row is selected. |
| 701 |
if (items.length != 1) { |
| 702 |
return; |
| 703 |
} |
| 704 |
|
| 705 |
|
| 706 |
if( cellEditorActivationStrategy == null || cellEditorActivationStrategy.shouldActivateCellEditor(e, items[0].getData(), false) ) { |
| 707 |
tableViewerImpl.handleMouseDown(e); |
| 708 |
} |
| 709 |
|
| 710 |
TableViewer.this.lastMouseEvent = e; |
| 711 |
} |
| 712 |
} |
| 713 |
} |
| 714 |
}); |
| 715 |
|
| 716 |
// We need to handle it this way because using after the double click a selection event |
| 717 |
// occurs and the cell-editor would loose focus |
| 718 |
addDoubleClickListener(new IDoubleClickListener() { |
| 719 |
public void doubleClick(DoubleClickEvent event) { |
| 720 |
/* |
| 721 |
* Avoid overhead when no activation strategy or no editors |
| 722 |
* The event check is needed because in some situations it is possible that a selection double click event |
| 723 |
* occurrs without any interaction maybe this is an SWT bug one has to look at |
| 724 |
*/ |
| 725 |
if( cellEditorActivationStrategy != null && getCellEditors() != null && getCellEditors().length > 0 && lastMouseEvent != ddMouseEvent ) { |
| 726 |
ddMouseEvent = lastMouseEvent; |
| 727 |
Item[] items = tableControl.getSelection(); |
| 728 |
// Do not edit if more than one row is selected. |
| 729 |
if (items.length != 1) { |
| 730 |
return; |
| 731 |
} |
| 732 |
|
| 733 |
if( cellEditorActivationStrategy != null && cellEditorActivationStrategy.shouldActivateCellEditor(lastMouseEvent, items[0].getData(), true) ) { |
| 734 |
tableViewerImpl.handleMouseDown(lastMouseEvent); |
| 735 |
} |
| 736 |
} |
| 737 |
} |
| 738 |
}); |
| 739 |
|
| 740 |
// Pressing return on a table control results in DoubleClick Event |
| 741 |
tableControl.addKeyListener(new KeyListener() { |
| 742 |
|
| 743 |
public void keyPressed(KeyEvent e) { |
| 744 |
if( cellEditorActivationStrategy != null && getCellEditors() != null && getCellEditors().length > 0 && e.keyCode == '\r' ) { |
| 745 |
Event event = new Event(); |
| 746 |
event.x = -1; |
| 747 |
event.y = -1; |
| 748 |
event.widget = tableControl; |
| 749 |
|
| 750 |
TableItem[] items = tableControl.getSelection(); |
| 751 |
// Do not edit if more than one row is selected. |
| 752 |
if (items.length != 1) { |
| 753 |
return; |
| 754 |
} |
| 755 |
|
| 756 |
event.x = items[0].getBounds().x; |
| 757 |
event.y = items[0].getBounds().y; |
| 758 |
event.button = 1; |
| 759 |
|
| 760 |
TableViewer.this.lastMouseEvent = new MouseEvent(event); |
| 761 |
} |
| 762 |
} |
| 763 |
|
| 764 |
public void keyReleased(KeyEvent e) { |
| 765 |
|
| 676 |
} |
766 |
} |
|
|
767 |
|
| 677 |
}); |
768 |
}); |
| 678 |
} |
769 |
} |
| 679 |
|
770 |
|
|
Lines 1287-1294
Link Here
|
| 1287 |
Assert.isTrue(provider instanceof IStructuredContentProvider || |
1378 |
Assert.isTrue(provider instanceof IStructuredContentProvider || |
| 1288 |
provider instanceof ILazyContentProvider); |
1379 |
provider instanceof ILazyContentProvider); |
| 1289 |
} |
1380 |
} |
| 1290 |
|
1381 |
|
| 1291 |
|
1382 |
public ICellEditorActivationStrategy getCellEditorActivationStrategy() { |
| 1292 |
|
1383 |
return cellEditorActivationStrategy; |
|
|
1384 |
} |
| 1385 |
|
| 1386 |
public void setCellEditorActivationStrategy( |
| 1387 |
ICellEditorActivationStrategy cellEditorActivationStrategy) { |
| 1388 |
this.cellEditorActivationStrategy = cellEditorActivationStrategy; |
| 1389 |
} |
| 1293 |
} |
1390 |
} |
| 1294 |
|
1391 |
|