10
|
1 /*******************************************************************************
|
|
2 * Copyright (c) 2006, 2007 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 * Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation
|
|
11 * - fix for bug 187817
|
|
12 * Port to the D programming language:
|
|
13 * Frank Benoit <benoit@tionex.de>
|
|
14 *******************************************************************************/
|
|
15
|
|
16 module dwtx.jface.viewers.ColumnViewerEditorActivationStrategy;
|
|
17
|
|
18 import dwtx.jface.viewers.ViewerCell;
|
|
19 import dwtx.jface.viewers.ColumnViewer;
|
|
20 import dwtx.jface.viewers.ColumnViewerEditorActivationEvent;
|
|
21 import dwtx.jface.viewers.IStructuredSelection;
|
|
22
|
|
23 import dwt.events.KeyEvent;
|
|
24 import dwt.events.KeyListener;
|
|
25 import dwt.events.MouseEvent;
|
|
26
|
|
27 import dwt.dwthelper.utils;
|
|
28
|
|
29 /**
|
|
30 * This class is responsible to determine if a cell selection event is triggers
|
|
31 * an editor activation. Implementors can extend and overwrite to implement
|
|
32 * custom editing behavior
|
|
33 *
|
|
34 * @since 3.3
|
|
35 */
|
|
36 public class ColumnViewerEditorActivationStrategy {
|
|
37 private ColumnViewer viewer;
|
|
38
|
|
39 private KeyListener keyboardActivationListener;
|
|
40
|
|
41 /**
|
|
42 * @param viewer
|
|
43 * the viewer the editor support is attached to
|
|
44 */
|
|
45 public this(ColumnViewer viewer) {
|
|
46 this.viewer = viewer;
|
|
47 }
|
|
48
|
|
49 /**
|
|
50 * @param event
|
|
51 * the event triggering the action
|
|
52 * @return <code>true</code> if this event should open the editor
|
|
53 */
|
|
54 protected bool isEditorActivationEvent(
|
|
55 ColumnViewerEditorActivationEvent event) {
|
|
56 bool singleSelect = (cast(IStructuredSelection)viewer.getSelection()).size() is 1;
|
|
57 bool isLeftMouseSelect = event.eventType is ColumnViewerEditorActivationEvent.MOUSE_CLICK_SELECTION && (cast(MouseEvent)event.sourceEvent).button is 1;
|
|
58
|
|
59 return singleSelect && (isLeftMouseSelect
|
|
60 || event.eventType is ColumnViewerEditorActivationEvent.PROGRAMMATIC
|
|
61 || event.eventType is ColumnViewerEditorActivationEvent.TRAVERSAL);
|
|
62 }
|
|
63 package bool isEditorActivationEvent_package(ColumnViewerEditorActivationEvent event){
|
|
64 return isEditorActivationEvent(event);
|
|
65 }
|
|
66
|
|
67 /**
|
|
68 * @return the cell holding the current focus
|
|
69 */
|
|
70 private ViewerCell getFocusCell() {
|
|
71 return viewer.getColumnViewerEditor().getFocusCell();
|
|
72 }
|
|
73
|
|
74 /**
|
|
75 * @return the viewer
|
|
76 */
|
|
77 public ColumnViewer getViewer() {
|
|
78 return viewer;
|
|
79 }
|
|
80
|
|
81 /**
|
|
82 * Enable activation of cell editors by keyboard
|
|
83 *
|
|
84 * @param enable
|
|
85 * <code>true</code> to enable
|
|
86 */
|
|
87 public void setEnableEditorActivationWithKeyboard(bool enable) {
|
|
88 if (enable) {
|
|
89 if (keyboardActivationListener is null) {
|
|
90 keyboardActivationListener = new class KeyListener {
|
|
91
|
|
92 public void keyPressed(KeyEvent e) {
|
|
93 ViewerCell cell = getFocusCell();
|
|
94
|
|
95 if (cell !is null) {
|
|
96 viewer
|
|
97 .triggerEditorActivationEvent_package(new ColumnViewerEditorActivationEvent(
|
|
98 cell, e));
|
|
99 }
|
|
100 }
|
|
101
|
|
102 public void keyReleased(KeyEvent e) {
|
|
103
|
|
104 }
|
|
105
|
|
106 };
|
|
107 viewer.getControl().addKeyListener(keyboardActivationListener);
|
|
108 }
|
|
109 } else {
|
|
110 if (keyboardActivationListener !is null) {
|
|
111 viewer.getControl().removeKeyListener(
|
|
112 keyboardActivationListener);
|
|
113 keyboardActivationListener = null;
|
|
114 }
|
|
115 }
|
|
116 }
|
|
117
|
|
118 }
|