10
|
1 /*******************************************************************************
|
|
2 * Copyright (c) 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 * Port to the D programming language:
|
|
11 * Frank Benoit <benoit@tionex.de>
|
|
12 ******************************************************************************/
|
|
13
|
|
14 module dwtx.jface.viewers.CellNavigationStrategy;
|
|
15
|
|
16 import dwtx.jface.viewers.ColumnViewer;
|
|
17 import dwtx.jface.viewers.ViewerCell;
|
|
18
|
|
19 import dwt.DWT;
|
|
20 import dwt.widgets.Event;
|
|
21
|
|
22 /**
|
|
23 * This class implementation the strategy how the table is navigated using the
|
|
24 * keyboard.
|
|
25 *
|
|
26 * <p>
|
|
27 * <b>Subclasses can implement their custom navigation algorithms</b>
|
|
28 * </p>
|
|
29 *
|
|
30 * @since 3.3
|
|
31 *
|
|
32 */
|
|
33 public class CellNavigationStrategy {
|
|
34 /**
|
|
35 * is the given event an event which moves the selection to another cell
|
|
36 *
|
|
37 * @param viewer
|
|
38 * the viewer we are working for
|
|
39 * @param event
|
|
40 * the key event
|
|
41 * @return <code>true</code> if a new cell is searched
|
|
42 */
|
|
43 public bool isNavigationEvent(ColumnViewer viewer, Event event) {
|
|
44 switch (event.keyCode) {
|
|
45 case DWT.ARROW_UP:
|
|
46 case DWT.ARROW_DOWN:
|
|
47 case DWT.ARROW_LEFT:
|
|
48 case DWT.ARROW_RIGHT:
|
|
49 case DWT.HOME:
|
|
50 case DWT.PAGE_DOWN:
|
|
51 case DWT.PAGE_UP:
|
|
52 case DWT.END:
|
|
53 return true;
|
|
54 default:
|
|
55 return false;
|
|
56 }
|
|
57 }
|
|
58
|
|
59 /**
|
|
60 * @param viewer
|
|
61 * the viewer we are working for
|
|
62 * @param cellToCollapse
|
|
63 * the cell to collapse
|
|
64 * @param event
|
|
65 * the key event
|
|
66 * @return <code>true</code> if this event triggers collapsing of a node
|
|
67 */
|
|
68 public bool isCollapseEvent(ColumnViewer viewer,
|
|
69 ViewerCell cellToCollapse, Event event) {
|
|
70 return false;
|
|
71 }
|
|
72
|
|
73 /**
|
|
74 * @param viewer
|
|
75 * the viewer we are working for
|
|
76 * @param cellToExpand
|
|
77 * the cell to expand
|
|
78 * @param event
|
|
79 * the key event
|
|
80 * @return <code>true</code> if this event triggers expanding of a node
|
|
81 */
|
|
82 public bool isExpandEvent(ColumnViewer viewer, ViewerCell cellToExpand,
|
|
83 Event event) {
|
|
84 return false;
|
|
85 }
|
|
86
|
|
87 /**
|
|
88 * @param viewer
|
|
89 * the viewer working for
|
|
90 * @param cellToExpand
|
|
91 * the cell the user wants to expand
|
|
92 * @param event
|
|
93 * the event triggering the expansion
|
|
94 */
|
|
95 public void expand(ColumnViewer viewer, ViewerCell cellToExpand, Event event) {
|
|
96
|
|
97 }
|
|
98
|
|
99 /**
|
|
100 * @param viewer
|
|
101 * the viewer working for
|
|
102 * @param cellToCollapse
|
|
103 * the cell the user wants to collapse
|
|
104 * @param event
|
|
105 * the event triggering the expansion
|
|
106 */
|
|
107 public void collapse(ColumnViewer viewer, ViewerCell cellToCollapse,
|
|
108 Event event) {
|
|
109
|
|
110 }
|
|
111
|
|
112 /**
|
|
113 * @param viewer
|
|
114 * the viewer we are working for
|
|
115 * @param currentSelectedCell
|
|
116 * the cell currently selected
|
|
117 * @param event
|
|
118 * the key event
|
|
119 * @return the cell which is highlighted next or <code>null</code> if the
|
|
120 * default implementation is taken. E.g. it's fairly impossible to
|
|
121 * react on PAGE_DOWN requests
|
|
122 */
|
|
123 public ViewerCell findSelectedCell(ColumnViewer viewer,
|
|
124 ViewerCell currentSelectedCell, Event event) {
|
|
125
|
|
126 switch (event.keyCode) {
|
|
127 case DWT.ARROW_UP:
|
|
128 if (currentSelectedCell !is null) {
|
|
129 return currentSelectedCell.getNeighbor(ViewerCell.ABOVE, false);
|
|
130 }
|
|
131 break;
|
|
132 case DWT.ARROW_DOWN:
|
|
133 if (currentSelectedCell !is null) {
|
|
134 return currentSelectedCell.getNeighbor(ViewerCell.BELOW, false);
|
|
135 }
|
|
136 break;
|
|
137 case DWT.ARROW_LEFT:
|
|
138 if (currentSelectedCell !is null) {
|
|
139 return currentSelectedCell.getNeighbor(ViewerCell.LEFT, true);
|
|
140 }
|
|
141 break;
|
|
142 case DWT.ARROW_RIGHT:
|
|
143 if (currentSelectedCell !is null) {
|
|
144 return currentSelectedCell.getNeighbor(ViewerCell.RIGHT, true);
|
|
145 }
|
|
146 break;
|
|
147 }
|
|
148
|
|
149 return null;
|
|
150 }
|
|
151
|
|
152 /**
|
|
153 * This method is consulted to decide whether an event has to be canceled or
|
|
154 * not. By default events who collapse/expand tree-nodes are canceled
|
|
155 *
|
|
156 * @param viewer
|
|
157 * the viewer working for
|
|
158 * @param event
|
|
159 * the event
|
|
160 * @return <code>true</code> if the event has to be canceled
|
|
161 */
|
|
162 public bool shouldCancelEvent(ColumnViewer viewer, Event event) {
|
|
163 return event.keyCode is DWT.ARROW_LEFT
|
|
164 || event.keyCode is DWT.ARROW_RIGHT;
|
|
165 }
|
|
166
|
|
167 /**
|
|
168 * This method is called by the framework to initialize this navigation
|
|
169 * strategy object. Subclasses may extend.
|
|
170 */
|
|
171 protected void init() {
|
|
172 }
|
|
173 package void init_package() {
|
|
174 init();
|
|
175 }
|
|
176 }
|