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