Mercurial > projects > dwt2
comparison org.eclipse.jface.snippets/EclipseJfaceSnippets/org/eclipse/jface/snippets/viewers/Snippet031TableViewerCustomTooltipsMultiSelection.d @ 32:c4b36186a9bc
Renamings
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Mon, 23 Mar 2009 11:25:49 +0100 |
parents | 5d87d4191adf |
children | a8a838017920 |
comparison
equal
deleted
inserted
replaced
31:5d87d4191adf | 32:c4b36186a9bc |
---|---|
9 * Adam Neal - initial API and implementation | 9 * Adam Neal - initial API and implementation |
10 * Port to the D programming language: | 10 * Port to the D programming language: |
11 * yidabu at gmail dot com ( D China http://www.d-programming-language-china.org/ ) | 11 * yidabu at gmail dot com ( D China http://www.d-programming-language-china.org/ ) |
12 *******************************************************************************/ | 12 *******************************************************************************/ |
13 | 13 |
14 module snippets.viewers.Snippet031TableViewerCustomTooltipsMultiSelection; | 14 module org.eclipse.jface.snippets.viewers.Snippet031TableViewerCustomTooltipsMultiSelection; |
15 | 15 |
16 // http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.jface.snippets/Eclipse%20JFace%20Snippets/org/eclipse/jface/snippets/viewers/Snippet031TableViewerCustomTooltipsMultiSelection.java?view=markup | 16 // http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.jface.snippets/Eclipse%20JFace%20Snippets/org/eclipse/jface/snippets/viewers/Snippet031TableViewerCustomTooltipsMultiSelection.java?view=markup |
17 | 17 |
18 import dwtx.dwtxhelper.Collection; | |
19 import tango.util.Convert; | 18 import tango.util.Convert; |
20 | 19 import java.util.ArrayList; |
21 import dwtx.jface.viewers.ArrayContentProvider; | 20 |
22 import dwtx.jface.viewers.ILabelProviderListener; | 21 import org.eclipse.jface.viewers.ArrayContentProvider; |
23 import dwtx.jface.viewers.ITableLabelProvider; | 22 import org.eclipse.jface.viewers.ILabelProviderListener; |
24 import dwtx.jface.viewers.TableViewer; | 23 import org.eclipse.jface.viewers.ITableLabelProvider; |
25 import dwt.DWT; | 24 import org.eclipse.jface.viewers.TableViewer; |
26 import dwt.graphics.Image; | 25 import org.eclipse.swt.SWT; |
27 import dwt.graphics.Point; | 26 import org.eclipse.swt.graphics.Image; |
28 import dwt.graphics.Rectangle; | 27 import org.eclipse.swt.graphics.Point; |
29 import dwt.layout.FillLayout; | 28 import org.eclipse.swt.graphics.Rectangle; |
30 import dwt.widgets.Display; | 29 import org.eclipse.swt.layout.FillLayout; |
31 import dwt.widgets.Event; | 30 import org.eclipse.swt.widgets.Display; |
32 import dwt.widgets.Label; | 31 import org.eclipse.swt.widgets.Event; |
33 import dwt.widgets.Listener; | 32 import org.eclipse.swt.widgets.Label; |
34 import dwt.widgets.Shell; | 33 import org.eclipse.swt.widgets.Listener; |
35 import dwt.widgets.Table; | 34 import org.eclipse.swt.widgets.Shell; |
36 import dwt.widgets.TableColumn; | 35 import org.eclipse.swt.widgets.Table; |
37 import dwt.widgets.TableItem; | 36 import org.eclipse.swt.widgets.TableColumn; |
38 import dwt.dwthelper.System; | 37 import org.eclipse.swt.widgets.TableItem; |
39 import dwt.widgets.Listener; | 38 import org.eclipse.swt.widgets.Listener; |
40 | 39 |
41 alias char[] String; | 40 alias char[] String; |
42 void main(String[] args) | 41 void main(String[] args) |
43 { | 42 { |
44 Snippet031TableViewerCustomTooltipsMultiSelection.main(args); | 43 Snippet031TableViewerCustomTooltipsMultiSelection.main(args); |
93 | 92 |
94 | 93 |
95 public this(Shell shell) { | 94 public this(Shell shell) { |
96 | 95 |
97 | 96 |
98 final Table table = new Table(shell, DWT.H_SCROLL | DWT.V_SCROLL | DWT.MULTI | DWT.FULL_SELECTION); | 97 final Table table = new Table(shell, SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI | SWT.FULL_SELECTION); |
99 table.setHeaderVisible(true); | 98 table.setHeaderVisible(true); |
100 table.setLinesVisible(true); | 99 table.setLinesVisible(true); |
101 | 100 |
102 final TableViewer v = new TableViewer(table); | 101 final TableViewer v = new TableViewer(table); |
103 TableColumn tableColumn1 = new TableColumn(table, DWT.NONE); | 102 TableColumn tableColumn1 = new TableColumn(table, SWT.NONE); |
104 TableColumn tableColumn2 = new TableColumn(table, DWT.NONE); | 103 TableColumn tableColumn2 = new TableColumn(table, SWT.NONE); |
105 | 104 |
106 String column1 = "Column 1", column2 = "Column 2"; | 105 String column1 = "Column 1", column2 = "Column 2"; |
107 /* Setup the table columns */ | 106 /* Setup the table columns */ |
108 tableColumn1.setText(column1); | 107 tableColumn1.setText(column1); |
109 tableColumn2.setText(column2); | 108 tableColumn2.setText(column2); |
118 tooltipLabelListener = new TooltipLabelListener(); | 117 tooltipLabelListener = new TooltipLabelListener(); |
119 | 118 |
120 /** | 119 /** |
121 * The listener that gets added to the table. This listener is responsible for creating the tooltips | 120 * The listener that gets added to the table. This listener is responsible for creating the tooltips |
122 * when hovering over a cell item. This listener will listen for the following events: | 121 * when hovering over a cell item. This listener will listen for the following events: |
123 * <li>DWT.KeyDown - to remove the tooltip</li> | 122 * <li>SWT.KeyDown - to remove the tooltip</li> |
124 * <li>DWT.Dispose - to remove the tooltip</li> | 123 * <li>SWT.Dispose - to remove the tooltip</li> |
125 * <li>DWT.MouseMove - to remove the tooltip</li> | 124 * <li>SWT.MouseMove - to remove the tooltip</li> |
126 * <li>DWT.MouseHover - to set the tooltip</li> | 125 * <li>SWT.MouseHover - to set the tooltip</li> |
127 */ | 126 */ |
128 | 127 |
129 Listener tableListener = dgListener(&handleTableListener, table); | 128 Listener tableListener = dgListener(&handleTableListener, table); |
130 | 129 |
131 table.addListener (DWT.Dispose, tableListener); | 130 table.addListener (SWT.Dispose, tableListener); |
132 table.addListener (DWT.KeyDown, tableListener); | 131 table.addListener (SWT.KeyDown, tableListener); |
133 table.addListener (DWT.MouseMove, tableListener); | 132 table.addListener (SWT.MouseMove, tableListener); |
134 table.addListener (DWT.MouseHover, tableListener); | 133 table.addListener (SWT.MouseHover, tableListener); |
135 } | 134 } |
136 | 135 |
137 void handleTableListener(Event event, Table table) | 136 void handleTableListener(Event event, Table table) |
138 { | 137 { |
139 Shell tooltip = null; | 138 Shell tooltip = null; |
140 Label label = null; | 139 Label label = null; |
141 | 140 |
142 /* | 141 /* |
143 * (non-Javadoc) | 142 * (non-Javadoc) |
144 * @see dwt.widgets.Listener#handleEvent(dwt.widgets.Event) | 143 * @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Event) |
145 */ | 144 */ |
146 switch (event.type) { | 145 switch (event.type) { |
147 case DWT.KeyDown: | 146 case SWT.KeyDown: |
148 case DWT.Dispose: | 147 case SWT.Dispose: |
149 case DWT.MouseMove: { | 148 case SWT.MouseMove: { |
150 if (tooltip is null) break; | 149 if (tooltip is null) break; |
151 tooltip.dispose (); | 150 tooltip.dispose (); |
152 tooltip = null; | 151 tooltip = null; |
153 label = null; | 152 label = null; |
154 break; | 153 break; |
155 } | 154 } |
156 case DWT.MouseHover: { | 155 case SWT.MouseHover: { |
157 Point coords = new Point(event.x, event.y); | 156 Point coords = new Point(event.x, event.y); |
158 TableItem item = table.getItem(coords); | 157 TableItem item = table.getItem(coords); |
159 if (item !is null) { | 158 if (item !is null) { |
160 int columnCount = table.getColumnCount(); | 159 int columnCount = table.getColumnCount(); |
161 for (int columnIndex = 0; columnIndex < columnCount; columnIndex++) { | 160 for (int columnIndex = 0; columnIndex < columnCount; columnIndex++) { |
162 if (item.getBounds(columnIndex).contains(coords)) { | 161 if (item.getBounds(columnIndex).contains(coords)) { |
163 /* Dispose of the old tooltip (if one exists */ | 162 /* Dispose of the old tooltip (if one exists */ |
164 if (tooltip !is null && !tooltip.isDisposed ()) tooltip.dispose (); | 163 if (tooltip !is null && !tooltip.isDisposed ()) tooltip.dispose (); |
165 | 164 |
166 /* Create a new Tooltip */ | 165 /* Create a new Tooltip */ |
167 tooltip = new Shell (table.getShell(), DWT.ON_TOP | DWT.NO_FOCUS | DWT.TOOL); | 166 tooltip = new Shell (table.getShell(), SWT.ON_TOP | SWT.NO_FOCUS | SWT.TOOL); |
168 tooltip.setBackground (table.getDisplay().getSystemColor (DWT.COLOR_INFO_BACKGROUND)); | 167 tooltip.setBackground (table.getDisplay().getSystemColor (SWT.COLOR_INFO_BACKGROUND)); |
169 FillLayout layout = new FillLayout (); | 168 FillLayout layout = new FillLayout (); |
170 layout.marginWidth = 2; | 169 layout.marginWidth = 2; |
171 tooltip.setLayout (layout); | 170 tooltip.setLayout (layout); |
172 label = new Label (tooltip, DWT.NONE); | 171 label = new Label (tooltip, SWT.NONE); |
173 label.setForeground (table.getDisplay().getSystemColor (DWT.COLOR_INFO_FOREGROUND)); | 172 label.setForeground (table.getDisplay().getSystemColor (SWT.COLOR_INFO_FOREGROUND)); |
174 label.setBackground (table.getDisplay().getSystemColor (DWT.COLOR_INFO_BACKGROUND)); | 173 label.setBackground (table.getDisplay().getSystemColor (SWT.COLOR_INFO_BACKGROUND)); |
175 | 174 |
176 /* Store the TableItem with the label so we can pass the mouse event later */ | 175 /* Store the TableItem with the label so we can pass the mouse event later */ |
177 label.setData ("_TableItem_", item); | 176 label.setData ("_TableItem_", item); |
178 | 177 |
179 /* Set the tooltip text */ | 178 /* Set the tooltip text */ |
180 label.setText("Tooltip: " ~ to!(char[])(item.getData()) ~ " : " ~ to!(char[])(columnIndex)); | 179 label.setText("Tooltip: " ~ to!(char[])(item.getData()) ~ " : " ~ to!(char[])(columnIndex)); |
181 | 180 |
182 /* Setup Listeners to remove the tooltip and transfer the received mouse events */ | 181 /* Setup Listeners to remove the tooltip and transfer the received mouse events */ |
183 label.addListener (DWT.MouseExit, tooltipLabelListener); | 182 label.addListener (SWT.MouseExit, tooltipLabelListener); |
184 label.addListener (DWT.MouseDown, tooltipLabelListener); | 183 label.addListener (SWT.MouseDown, tooltipLabelListener); |
185 | 184 |
186 /* Set the size and position of the tooltip */ | 185 /* Set the size and position of the tooltip */ |
187 Point size = tooltip.computeSize (DWT.DEFAULT, DWT.DEFAULT); | 186 Point size = tooltip.computeSize (SWT.DEFAULT, SWT.DEFAULT); |
188 Rectangle rect = item.getBounds (columnIndex); | 187 Rectangle rect = item.getBounds (columnIndex); |
189 Point pt = table.toDisplay (rect.x, rect.y); | 188 Point pt = table.toDisplay (rect.x, rect.y); |
190 tooltip.setBounds (pt.x, pt.y, size.x, size.y); | 189 tooltip.setBounds (pt.x, pt.y, size.x, size.y); |
191 | 190 |
192 /* Show it */ | 191 /* Show it */ |
204 * exits the tooltip or so it can pass the selection event through to the table. | 203 * exits the tooltip or so it can pass the selection event through to the table. |
205 */ | 204 */ |
206 final TooltipLabelListener tooltipLabelListener; | 205 final TooltipLabelListener tooltipLabelListener; |
207 final class TooltipLabelListener : Listener { | 206 final class TooltipLabelListener : Listener { |
208 private bool isCTRLDown(Event e) { | 207 private bool isCTRLDown(Event e) { |
209 return (e.stateMask & DWT.CTRL) != 0; | 208 return (e.stateMask & SWT.CTRL) != 0; |
210 } | 209 } |
211 /* | 210 /* |
212 * (non-Javadoc) | 211 * (non-Javadoc) |
213 * @see dwt.widgets.Listener#handleEvent(dwt.widgets.Event) | 212 * @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Event) |
214 */ | 213 */ |
215 public void handleEvent (Event event) { | 214 public void handleEvent (Event event) { |
216 Label label = cast(Label)event.widget; | 215 Label label = cast(Label)event.widget; |
217 Shell shell = label.getShell (); | 216 Shell shell = label.getShell (); |
218 switch (event.type) { | 217 switch (event.type) { |
219 case DWT.MouseDown: /* Handle a user Click */ | 218 case SWT.MouseDown: /* Handle a user Click */ |
220 /* Extract our Data */ | 219 /* Extract our Data */ |
221 Event e = new Event (); | 220 Event e = new Event (); |
222 e.item = cast(TableItem) label.getData ("_TableItem_"); | 221 e.item = cast(TableItem) label.getData ("_TableItem_"); |
223 Table table = (cast(TableItem) e.item).getParent(); | 222 Table table = (cast(TableItem) e.item).getParent(); |
224 | 223 |
255 /* CTRL is not down, so we simply select the single element */ | 254 /* CTRL is not down, so we simply select the single element */ |
256 newSelection = [ cast(TableItem) e.item ]; | 255 newSelection = [ cast(TableItem) e.item ]; |
257 } | 256 } |
258 /* Set the new selection of the table and notify the listeners */ | 257 /* Set the new selection of the table and notify the listeners */ |
259 table.setSelection (newSelection); | 258 table.setSelection (newSelection); |
260 table.notifyListeners (DWT.Selection, e); | 259 table.notifyListeners (SWT.Selection, e); |
261 | 260 |
262 /* Remove the Tooltip */ | 261 /* Remove the Tooltip */ |
263 shell.dispose (); | 262 shell.dispose (); |
264 table.setFocus(); | 263 table.setFocus(); |
265 break; | 264 break; |
266 case DWT.MouseExit: | 265 case SWT.MouseExit: |
267 shell.dispose (); | 266 shell.dispose (); |
268 break; | 267 break; |
269 } | 268 } |
270 } | 269 } |
271 } | 270 } |