Commit | Line | Data |
---|---|---|
9ccc6d01 | 1 | /******************************************************************************* |
c8422608 | 2 | * Copyright (c) 2010, 2013 Ericsson |
3934297e | 3 | * |
9ccc6d01 FC |
4 | * All rights reserved. This program and the accompanying materials are |
5 | * made available under the terms of the Eclipse Public License v1.0 which | |
6 | * accompanies this distribution, and is available at | |
7 | * http://www.eclipse.org/legal/epl-v10.html | |
3934297e | 8 | * |
9ccc6d01 FC |
9 | * Contributors: |
10 | * Matthew Khouzam - Initial API and implementation | |
3934297e | 11 | * Francois Chouinard - Refactoring, slider support, bug fixing |
b21305c2 | 12 | * Patrick Tasse - Improvements and bug fixing |
7cc11afa | 13 | * Xavier Raynaud - Improvements |
9ccc6d01 FC |
14 | ******************************************************************************/ |
15 | ||
fb5cad3d | 16 | package org.eclipse.linuxtools.tmf.ui.widgets.virtualtable; |
9ccc6d01 | 17 | |
8fd82db5 | 18 | import org.eclipse.linuxtools.internal.tmf.ui.Activator; |
9ccc6d01 | 19 | import org.eclipse.swt.SWT; |
3f43dc48 | 20 | import org.eclipse.swt.SWTException; |
b21305c2 | 21 | import org.eclipse.swt.custom.TableEditor; |
9ccc6d01 FC |
22 | import org.eclipse.swt.events.ControlAdapter; |
23 | import org.eclipse.swt.events.ControlEvent; | |
3f43dc48 | 24 | import org.eclipse.swt.events.KeyAdapter; |
9ccc6d01 FC |
25 | import org.eclipse.swt.events.KeyEvent; |
26 | import org.eclipse.swt.events.KeyListener; | |
3f43dc48 | 27 | import org.eclipse.swt.events.MouseAdapter; |
9ccc6d01 | 28 | import org.eclipse.swt.events.MouseEvent; |
b21305c2 | 29 | import org.eclipse.swt.events.MouseListener; |
9ccc6d01 | 30 | import org.eclipse.swt.events.MouseWheelListener; |
dd03e2f1 PT |
31 | import org.eclipse.swt.events.PaintEvent; |
32 | import org.eclipse.swt.events.PaintListener; | |
9ccc6d01 FC |
33 | import org.eclipse.swt.events.SelectionAdapter; |
34 | import org.eclipse.swt.events.SelectionEvent; | |
b21305c2 FC |
35 | import org.eclipse.swt.events.SelectionListener; |
36 | import org.eclipse.swt.graphics.Point; | |
7800a42f XR |
37 | import org.eclipse.swt.graphics.Rectangle; |
38 | import org.eclipse.swt.layout.FillLayout; | |
9ccc6d01 FC |
39 | import org.eclipse.swt.layout.GridData; |
40 | import org.eclipse.swt.layout.GridLayout; | |
41 | import org.eclipse.swt.widgets.Composite; | |
b21305c2 | 42 | import org.eclipse.swt.widgets.Control; |
9ccc6d01 | 43 | import org.eclipse.swt.widgets.Event; |
7800a42f | 44 | import org.eclipse.swt.widgets.Label; |
9ccc6d01 | 45 | import org.eclipse.swt.widgets.Listener; |
b21305c2 | 46 | import org.eclipse.swt.widgets.Menu; |
7800a42f | 47 | import org.eclipse.swt.widgets.Shell; |
9ccc6d01 FC |
48 | import org.eclipse.swt.widgets.Slider; |
49 | import org.eclipse.swt.widgets.Table; | |
50 | import org.eclipse.swt.widgets.TableColumn; | |
51 | import org.eclipse.swt.widgets.TableItem; | |
7800a42f | 52 | import org.eclipse.ui.PlatformUI; |
9ccc6d01 FC |
53 | |
54 | /** | |
55 | * <b><u>TmfVirtualTable</u></b> | |
56 | * <p> | |
57 | * TmfVirtualTable allows for the tabular display of arbitrarily large data sets | |
58 | * (well, up to Integer.MAX_VALUE or ~2G rows). | |
3934297e | 59 | * |
9ccc6d01 FC |
60 | * It is essentially a Composite of Table and Slider, where the number of rows |
61 | * in the table is set to fill the table display area. The slider is rank-based. | |
3934297e | 62 | * |
9ccc6d01 FC |
63 | * It differs from Table with the VIRTUAL style flag where an empty entry is |
64 | * created for each virtual row. This does not scale well for very large data sets. | |
3934297e | 65 | * |
b21305c2 | 66 | * Styles: |
3f43dc48 | 67 | * H_SCROLL, V_SCROLL, SINGLE, MULTI, CHECK, FULL_SELECTION, HIDE_SELECTION, NO_SCROLL |
02023181 | 68 | * @author Matthew Khouzam, Francois Chouinard, Patrick Tasse, Xavier Raynaud |
3934297e | 69 | * @version $Revision: 1.0 |
9ccc6d01 FC |
70 | */ |
71 | public class TmfVirtualTable extends Composite { | |
72 | ||
631d853f PT |
73 | // The table |
74 | private Table fTable; | |
75 | private int fTableRows = 0; // Number of table rows | |
76 | private int fFullyVisibleRows = 0; // Number of fully visible table rows | |
77 | private int fFrozenRowCount = 0; // Number of frozen table rows at top of table | |
78 | ||
79 | private int fTableTopEventRank = 0; // Global rank of the first entry displayed | |
3f43dc48 PT |
80 | private int fSelectedEventRank = -1; // Global rank of the selected event |
81 | private int fSelectedBeginRank = -1; // Global rank of the selected begin event | |
631d853f PT |
82 | private boolean fPendingSelection = false; // Pending selection update |
83 | ||
84 | private int fTableItemCount = 0; | |
85 | ||
86 | // The slider | |
87 | private Slider fSlider; | |
88 | ||
89 | private int fLinuxItemHeight = 0; // Calculated item height for Linux workaround | |
90 | private TooltipProvider tooltipProvider = null; | |
91 | private IDoubleClickListener doubleClickListener = null; | |
92 | ||
b06f64b7 PT |
93 | private boolean fResetTopIndex = false; // Flag to trigger reset of top index |
94 | private ControlAdapter fResizeListener; // Resize listener to update visible rows | |
c9787691 | 95 | |
631d853f PT |
96 | // ------------------------------------------------------------------------ |
97 | // Constructor | |
98 | // ------------------------------------------------------------------------ | |
99 | ||
100 | /** | |
3934297e AM |
101 | * Standard constructor |
102 | * | |
631d853f | 103 | * @param parent |
3934297e | 104 | * The parent composite object |
631d853f | 105 | * @param style |
3934297e | 106 | * The style to use |
631d853f PT |
107 | */ |
108 | public TmfVirtualTable(Composite parent, int style) { | |
3f43dc48 | 109 | super(parent, style & (~SWT.H_SCROLL) & (~SWT.V_SCROLL) & (~SWT.SINGLE) & (~SWT.MULTI) & (~SWT.FULL_SELECTION) & (~SWT.HIDE_SELECTION) & (~SWT.CHECK)); |
631d853f PT |
110 | |
111 | // Create the controls | |
3f43dc48 | 112 | createTable(style & (SWT.H_SCROLL | SWT.SINGLE | SWT.MULTI | SWT.FULL_SELECTION | SWT.HIDE_SELECTION | SWT.CHECK)); |
631d853f PT |
113 | createSlider(style & SWT.V_SCROLL); |
114 | ||
115 | // Prevent the slider from being traversed | |
116 | setTabList(new Control[] { fTable }); | |
117 | ||
118 | // Set the layout | |
119 | GridLayout gridLayout = new GridLayout(); | |
120 | gridLayout.numColumns = 2; | |
121 | gridLayout.horizontalSpacing = 0; | |
122 | gridLayout.verticalSpacing = 0; | |
123 | gridLayout.marginWidth = 0; | |
124 | gridLayout.marginHeight = 0; | |
125 | setLayout(gridLayout); | |
126 | ||
127 | GridData tableGridData = new GridData(SWT.FILL, SWT.FILL, true, true); | |
128 | fTable.setLayoutData(tableGridData); | |
129 | ||
130 | GridData sliderGridData = new GridData(SWT.FILL, SWT.FILL, false, true); | |
131 | fSlider.setLayoutData(sliderGridData); | |
132 | ||
133 | // Add the listeners | |
134 | fTable.addMouseWheelListener(new MouseWheelListener() { | |
135 | @Override | |
136 | public void mouseScrolled(MouseEvent event) { | |
137 | if (fTableItemCount <= fFullyVisibleRows) { | |
138 | return; | |
139 | } | |
140 | fTableTopEventRank -= event.count; | |
141 | if (fTableTopEventRank < 0) { | |
142 | fTableTopEventRank = 0; | |
143 | } | |
144 | int latestFirstRowOffset = fTableItemCount - fFullyVisibleRows; | |
145 | if (fTableTopEventRank > latestFirstRowOffset) { | |
146 | fTableTopEventRank = latestFirstRowOffset; | |
147 | } | |
148 | ||
149 | fSlider.setSelection(fTableTopEventRank); | |
150 | refreshTable(); | |
151 | } | |
152 | }); | |
153 | ||
154 | fTable.addListener(SWT.MouseWheel, new Listener() { | |
155 | // disable mouse scroll of horizontal scroll bar | |
156 | @Override | |
b21305c2 | 157 | public void handleEvent(Event event) { |
631d853f PT |
158 | event.doit = false; |
159 | } | |
160 | }); | |
161 | ||
b06f64b7 | 162 | fResizeListener = new ControlAdapter() { |
631d853f PT |
163 | @Override |
164 | public void controlResized(ControlEvent event) { | |
165 | int tableHeight = Math.max(0, fTable.getClientArea().height - fTable.getHeaderHeight()); | |
166 | fFullyVisibleRows = tableHeight / getItemHeight(); | |
167 | if (fTableItemCount > 0) { | |
168 | fSlider.setThumb(Math.max(1, Math.min(fTableRows, fFullyVisibleRows))); | |
169 | } | |
170 | } | |
b06f64b7 PT |
171 | }; |
172 | fTable.addControlListener(fResizeListener); | |
173 | ||
631d853f PT |
174 | // Implement a "fake" tooltip |
175 | final String TOOLTIP_DATA_KEY = "_TABLEITEM"; //$NON-NLS-1$ | |
176 | final Listener labelListener = new Listener () { | |
177 | @Override | |
f4c52cea | 178 | public void handleEvent (Event event) { |
631d853f PT |
179 | Label label = (Label)event.widget; |
180 | Shell shell = label.getShell (); | |
181 | switch (event.type) { | |
182 | case SWT.MouseDown: | |
183 | Event e = new Event (); | |
184 | e.item = (TableItem) label.getData (TOOLTIP_DATA_KEY); | |
185 | // Assuming table is single select, set the selection as if | |
186 | // the mouse down event went through to the table | |
187 | fTable.setSelection (new TableItem [] {(TableItem) e.item}); | |
188 | fTable.notifyListeners (SWT.Selection, e); | |
189 | shell.dispose (); | |
190 | fTable.setFocus(); | |
191 | break; | |
192 | case SWT.MouseExit: | |
193 | case SWT.MouseWheel: | |
194 | shell.dispose (); | |
195 | break; | |
abbdd66a AM |
196 | default: |
197 | break; | |
631d853f PT |
198 | } |
199 | } | |
200 | }; | |
201 | ||
202 | Listener tableListener = new Listener () { | |
203 | Shell tip = null; | |
204 | Label label = null; | |
205 | @Override | |
f4c52cea | 206 | public void handleEvent (Event event) { |
631d853f PT |
207 | switch (event.type) { |
208 | case SWT.Dispose: | |
209 | case SWT.KeyDown: | |
210 | case SWT.MouseMove: { | |
420bceb2 PT |
211 | if (tip == null) { |
212 | break; | |
213 | } | |
631d853f PT |
214 | tip.dispose (); |
215 | tip = null; | |
216 | label = null; | |
217 | break; | |
218 | } | |
219 | case SWT.MouseHover: { | |
220 | TableItem item = fTable.getItem (new Point(event.x, event.y)); | |
221 | if (item != null) { | |
420bceb2 | 222 | for (int i=0; i < fTable.getColumnCount(); i++) { |
631d853f PT |
223 | Rectangle bounds = item.getBounds(i); |
224 | if (bounds.contains(event.x,event.y)){ | |
420bceb2 PT |
225 | if (tip != null && !tip.isDisposed()) { |
226 | tip.dispose(); | |
227 | } | |
631d853f PT |
228 | if (tooltipProvider == null) { |
229 | return; | |
631d853f | 230 | } |
abbdd66a AM |
231 | String tooltipText = tooltipProvider.getTooltip(i, item.getData()); |
232 | if (tooltipText == null) { | |
233 | return; | |
234 | } | |
235 | tip = new Shell(fTable.getShell(), SWT.ON_TOP | SWT.NO_FOCUS | SWT.TOOL); | |
236 | tip.setBackground(PlatformUI.getWorkbench().getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND)); | |
237 | FillLayout layout = new FillLayout(); | |
238 | layout.marginWidth = 2; | |
239 | tip.setLayout(layout); | |
240 | label = new Label(tip, SWT.WRAP); | |
241 | label.setForeground(PlatformUI.getWorkbench().getDisplay().getSystemColor(SWT.COLOR_INFO_FOREGROUND)); | |
242 | label.setBackground(PlatformUI.getWorkbench().getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND)); | |
243 | label.setData(TOOLTIP_DATA_KEY, item); | |
244 | label.setText(tooltipText); | |
245 | ||
246 | label.addListener(SWT.MouseExit, labelListener); | |
247 | label.addListener(SWT.MouseDown, labelListener); | |
248 | label.addListener(SWT.MouseWheel, labelListener); | |
249 | Point size = tip.computeSize(SWT.DEFAULT, SWT.DEFAULT); | |
250 | Point pt = fTable.toDisplay(bounds.x, bounds.y); | |
251 | tip.setBounds(pt.x, pt.y, size.x, size.y); | |
252 | tip.setVisible(true); | |
631d853f PT |
253 | } |
254 | } | |
255 | } | |
abbdd66a | 256 | break; |
631d853f | 257 | } |
abbdd66a AM |
258 | default: |
259 | break; | |
631d853f PT |
260 | } |
261 | } | |
262 | }; | |
263 | fTable.addListener(SWT.Dispose, tableListener); | |
264 | fTable.addListener(SWT.KeyDown, tableListener); | |
265 | fTable.addListener(SWT.MouseMove, tableListener); | |
266 | fTable.addListener(SWT.MouseHover, tableListener); | |
267 | addControlListener(new ControlAdapter() { | |
268 | @Override | |
269 | public void controlResized(ControlEvent event) { | |
270 | resize(); | |
420bceb2 PT |
271 | if (fTableItemCount > 0) { |
272 | fSlider.setThumb(Math.max(1, Math.min(fTableRows, fFullyVisibleRows))); | |
273 | } | |
631d853f PT |
274 | } |
275 | }); | |
276 | ||
277 | // And display | |
278 | refresh(); | |
279 | } | |
280 | ||
281 | // ------------------------------------------------------------------------ | |
282 | // Table handling | |
283 | // ------------------------------------------------------------------------ | |
284 | ||
285 | /** | |
286 | * Create the table and add listeners | |
3f43dc48 | 287 | * @param style int can be H_SCROLL, SINGLE, MULTI, FULL_SELECTION, HIDE_SELECTION, CHECK |
631d853f PT |
288 | */ |
289 | private void createTable(int style) { | |
290 | fTable = new Table(this, style | SWT.NO_SCROLL); | |
291 | ||
292 | fTable.addSelectionListener(new SelectionAdapter() { | |
293 | @Override | |
294 | public void widgetSelected(SelectionEvent event) { | |
3f43dc48 PT |
295 | if (event.item == null) { |
296 | // Override table selection from Select All action | |
297 | refreshSelection(); | |
631d853f PT |
298 | } |
299 | } | |
300 | }); | |
9ccc6d01 | 301 | |
3f43dc48 | 302 | fTable.addMouseListener(new MouseAdapter() { |
631d853f | 303 | @Override |
3f43dc48 PT |
304 | public void mouseDown(MouseEvent e) { |
305 | handleTableMouseEvent(e); | |
631d853f | 306 | } |
3f43dc48 PT |
307 | }); |
308 | ||
309 | fTable.addKeyListener(new KeyAdapter() { | |
631d853f | 310 | @Override |
3f43dc48 PT |
311 | public void keyPressed(KeyEvent event) { |
312 | handleTableKeyEvent(event); | |
631d853f PT |
313 | } |
314 | }); | |
7800a42f XR |
315 | |
316 | fTable.addListener( | |
631d853f PT |
317 | SWT.MouseDoubleClick, new Listener() { |
318 | @Override | |
319 | public void handleEvent(Event event) { | |
320 | if (doubleClickListener != null) { | |
321 | TableItem item = fTable.getItem (new Point (event.x, event.y)); | |
322 | if (item != null) { | |
323 | for(int i=0;i<fTable.getColumnCount();i++){ | |
324 | Rectangle bounds = item.getBounds(i); | |
325 | if (bounds.contains(event.x,event.y)){ | |
326 | doubleClickListener.handleDoubleClick(TmfVirtualTable.this, item, i); | |
327 | break; | |
328 | } | |
329 | } | |
330 | } | |
331 | } | |
332 | } | |
333 | } | |
334 | ); | |
dd03e2f1 PT |
335 | |
336 | /* | |
c9787691 PT |
337 | * Feature in Windows. When a partially visible table item is selected, |
338 | * after ~500 ms the top index is changed to ensure the selected item is | |
339 | * fully visible. This leaves a blank space at the bottom of the virtual | |
340 | * table. The workaround is to reset the top index to 0 if it is not 0. | |
341 | * Also reset the top index to 0 if indicated by the flag that was set | |
342 | * at table selection of a partially visible table item. | |
dd03e2f1 PT |
343 | */ |
344 | fTable.addPaintListener(new PaintListener() { | |
345 | @Override | |
346 | public void paintControl(PaintEvent e) { | |
c9787691 PT |
347 | if (fTable.getTopIndex() != 0 || fResetTopIndex) { |
348 | fTable.setTopIndex(0); | |
349 | } | |
350 | fResetTopIndex = false; | |
dd03e2f1 PT |
351 | } |
352 | }); | |
631d853f PT |
353 | } |
354 | ||
355 | /** | |
3f43dc48 PT |
356 | * Handle mouse-based selection in table. |
357 | * | |
358 | * @param event the mouse event | |
631d853f | 359 | */ |
3f43dc48 PT |
360 | private void handleTableMouseEvent(MouseEvent event) { |
361 | TableItem item = fTable.getItem(new Point(event.x, event.y)); | |
362 | if (item == null) { | |
363 | return; | |
364 | } | |
365 | int selectedRow = indexOf(item); | |
366 | if (event.button != 2) { | |
367 | if (selectedRow >= 0) { | |
368 | fSelectedEventRank = selectedRow; | |
369 | } else { | |
370 | fSelectedEventRank = -1; | |
371 | } | |
372 | if ((event.stateMask & SWT.SHIFT) == 0 || (fTable.getStyle() & SWT.MULTI) == 0 || fSelectedBeginRank == -1) { | |
373 | fSelectedBeginRank = fSelectedEventRank; | |
374 | } | |
631d853f | 375 | } |
3f43dc48 | 376 | refreshSelection(); |
c9787691 PT |
377 | |
378 | /* | |
379 | * Feature in Linux. When a partially visible table item is selected, | |
380 | * the origin is changed to ensure the selected item is fully visible. | |
381 | * This makes the first row partially visible. The solution is to force | |
382 | * reset the origin by setting the top index to 0. This should happen | |
383 | * only once at the next redraw by the paint listener. | |
384 | */ | |
385 | if (selectedRow >= fFullyVisibleRows) { | |
386 | fResetTopIndex = true; | |
387 | } | |
631d853f PT |
388 | } |
389 | ||
390 | /** | |
391 | * Handle key-based navigation in table. | |
3934297e | 392 | * |
3f43dc48 | 393 | * @param event the key event |
631d853f PT |
394 | */ |
395 | private void handleTableKeyEvent(KeyEvent event) { | |
396 | ||
397 | int lastEventRank = fTableItemCount - 1; | |
398 | int lastPageTopEntryRank = Math.max(0, fTableItemCount - fFullyVisibleRows); | |
399 | ||
400 | int previousSelectedEventRank = fSelectedEventRank; | |
3f43dc48 | 401 | int previousSelectedBeginRank = fSelectedBeginRank; |
631d853f PT |
402 | boolean needsRefresh = false; |
403 | ||
404 | // In all case, perform the following steps: | |
405 | // - Update the selected entry rank (within valid range) | |
406 | // - Update the selected row | |
407 | // - Update the page's top entry if necessary (which also adjusts the selected row) | |
408 | // - If the top displayed entry was changed, table refresh is needed | |
409 | switch (event.keyCode) { | |
410 | ||
411 | case SWT.ARROW_DOWN: { | |
412 | event.doit = false; | |
413 | if (fSelectedEventRank < lastEventRank) { | |
414 | fSelectedEventRank++; | |
3f43dc48 | 415 | int selectedRow = fSelectedEventRank - fTableTopEventRank; |
75c271cf | 416 | if (selectedRow == fFullyVisibleRows) { |
631d853f PT |
417 | fTableTopEventRank++; |
418 | needsRefresh = true; | |
75c271cf PT |
419 | } else if (selectedRow < fFrozenRowCount || selectedRow > fFullyVisibleRows) { |
420 | fTableTopEventRank = Math.max(0, Math.min(fSelectedEventRank - fFrozenRowCount, lastPageTopEntryRank)); | |
421 | needsRefresh = true; | |
631d853f PT |
422 | } |
423 | } | |
424 | break; | |
425 | } | |
426 | ||
427 | case SWT.ARROW_UP: { | |
428 | event.doit = false; | |
429 | if (fSelectedEventRank > 0) { | |
430 | fSelectedEventRank--; | |
3f43dc48 | 431 | int selectedRow = fSelectedEventRank - fTableTopEventRank; |
75c271cf | 432 | if (selectedRow == fFrozenRowCount - 1 && fTableTopEventRank > 0) { |
631d853f PT |
433 | fTableTopEventRank--; |
434 | needsRefresh = true; | |
75c271cf PT |
435 | } else if (selectedRow < fFrozenRowCount || selectedRow > fFullyVisibleRows) { |
436 | fTableTopEventRank = Math.max(0, Math.min(fSelectedEventRank - fFrozenRowCount, lastPageTopEntryRank)); | |
437 | needsRefresh = true; | |
631d853f PT |
438 | } |
439 | } | |
440 | break; | |
441 | } | |
442 | ||
443 | case SWT.END: { | |
444 | event.doit = false; | |
445 | fTableTopEventRank = lastPageTopEntryRank; | |
446 | fSelectedEventRank = lastEventRank; | |
447 | needsRefresh = true; | |
448 | break; | |
449 | } | |
450 | ||
451 | case SWT.HOME: { | |
452 | event.doit = false; | |
453 | fSelectedEventRank = fFrozenRowCount; | |
454 | fTableTopEventRank = 0; | |
455 | needsRefresh = true; | |
456 | break; | |
457 | } | |
458 | ||
459 | case SWT.PAGE_DOWN: { | |
460 | event.doit = false; | |
461 | if (fSelectedEventRank < lastEventRank) { | |
462 | fSelectedEventRank += fFullyVisibleRows; | |
463 | if (fSelectedEventRank > lastEventRank) { | |
464 | fSelectedEventRank = lastEventRank; | |
465 | } | |
3f43dc48 | 466 | int selectedRow = fSelectedEventRank - fTableTopEventRank; |
75c271cf | 467 | if (selectedRow > fFullyVisibleRows + fFrozenRowCount - 1 && selectedRow < 2 * fFullyVisibleRows) { |
631d853f PT |
468 | fTableTopEventRank += fFullyVisibleRows; |
469 | if (fTableTopEventRank > lastPageTopEntryRank) { | |
470 | fTableTopEventRank = lastPageTopEntryRank; | |
471 | } | |
472 | needsRefresh = true; | |
75c271cf PT |
473 | } else if (selectedRow < fFrozenRowCount || selectedRow >= 2 * fFullyVisibleRows) { |
474 | fTableTopEventRank = Math.max(0, Math.min(fSelectedEventRank - fFrozenRowCount, lastPageTopEntryRank)); | |
475 | needsRefresh = true; | |
631d853f PT |
476 | } |
477 | } | |
478 | break; | |
479 | } | |
480 | ||
481 | case SWT.PAGE_UP: { | |
482 | event.doit = false; | |
483 | if (fSelectedEventRank > 0) { | |
484 | fSelectedEventRank -= fFullyVisibleRows; | |
485 | if (fSelectedEventRank < fFrozenRowCount) { | |
486 | fSelectedEventRank = fFrozenRowCount; | |
487 | } | |
3f43dc48 | 488 | int selectedRow = fSelectedEventRank - fTableTopEventRank; |
75c271cf | 489 | if (selectedRow < fFrozenRowCount && selectedRow > -fFullyVisibleRows) { |
631d853f PT |
490 | fTableTopEventRank -= fFullyVisibleRows; |
491 | if (fTableTopEventRank < 0) { | |
492 | fTableTopEventRank = 0; | |
493 | } | |
494 | needsRefresh = true; | |
75c271cf PT |
495 | } else if (selectedRow <= -fFullyVisibleRows || selectedRow >= fFullyVisibleRows) { |
496 | fTableTopEventRank = Math.max(0, Math.min(fSelectedEventRank - fFrozenRowCount, lastPageTopEntryRank)); | |
497 | needsRefresh = true; | |
631d853f PT |
498 | } |
499 | } | |
500 | break; | |
501 | } | |
502 | default: { | |
503 | return; | |
504 | } | |
505 | } | |
506 | ||
3f43dc48 PT |
507 | if ((event.stateMask & SWT.SHIFT) == 0 || (fTable.getStyle() & SWT.MULTI) == 0 || fSelectedBeginRank == -1) { |
508 | fSelectedBeginRank = fSelectedEventRank; | |
509 | } | |
510 | ||
631d853f PT |
511 | boolean done = true; |
512 | if (needsRefresh) { | |
513 | done = refreshTable(); // false if table items not updated yet in this thread | |
514 | } else { | |
3f43dc48 | 515 | refreshSelection(); |
631d853f PT |
516 | } |
517 | ||
518 | if (fFullyVisibleRows < fTableItemCount) { | |
519 | fSlider.setSelection(fTableTopEventRank); | |
520 | } | |
521 | ||
3f43dc48 | 522 | if (fSelectedEventRank != previousSelectedEventRank || fSelectedBeginRank != previousSelectedBeginRank) { |
631d853f PT |
523 | if (done) { |
524 | Event e = new Event(); | |
3f43dc48 | 525 | e.item = fTable.getItem(fSelectedEventRank - fTableTopEventRank); |
631d853f PT |
526 | fTable.notifyListeners(SWT.Selection, e); |
527 | } else { | |
528 | fPendingSelection = true; | |
529 | } | |
530 | } | |
531 | } | |
532 | ||
02023181 MK |
533 | /** |
534 | * Method setDataItem. | |
535 | * @param index int | |
536 | * @param item TableItem | |
537 | * @return boolean | |
538 | */ | |
631d853f PT |
539 | private boolean setDataItem(int index, TableItem item) { |
540 | if (index != -1) { | |
541 | Event event = new Event(); | |
542 | event.item = item; | |
543 | if (index < fFrozenRowCount) { | |
544 | event.index = index; | |
545 | } else { | |
546 | event.index = index + fTableTopEventRank; | |
547 | } | |
548 | event.doit = true; | |
549 | fTable.notifyListeners(SWT.SetData, event); | |
550 | return event.doit; // false if table item not updated yet in this thread | |
551 | } | |
552 | return true; | |
553 | } | |
554 | ||
555 | // ------------------------------------------------------------------------ | |
556 | // Slider handling | |
557 | // ------------------------------------------------------------------------ | |
558 | ||
02023181 MK |
559 | /** |
560 | * Method createSlider. | |
561 | * @param style int | |
562 | */ | |
631d853f PT |
563 | private void createSlider(int style) { |
564 | fSlider = new Slider(this, SWT.VERTICAL | SWT.NO_FOCUS); | |
565 | fSlider.setMinimum(0); | |
566 | fSlider.setMaximum(0); | |
567 | if ((style & SWT.V_SCROLL) == 0) { | |
568 | fSlider.setVisible(false); | |
569 | } | |
570 | ||
571 | fSlider.addListener(SWT.Selection, new Listener() { | |
572 | @Override | |
573 | public void handleEvent(Event event) { | |
574 | switch (event.detail) { | |
575 | case SWT.ARROW_DOWN: | |
576 | case SWT.ARROW_UP: | |
577 | case SWT.NONE: | |
578 | case SWT.END: | |
579 | case SWT.HOME: | |
580 | case SWT.PAGE_DOWN: | |
581 | case SWT.PAGE_UP: { | |
582 | fTableTopEventRank = fSlider.getSelection(); | |
583 | refreshTable(); | |
584 | break; | |
585 | } | |
abbdd66a AM |
586 | default: |
587 | break; | |
631d853f PT |
588 | } |
589 | } | |
590 | }); | |
591 | } | |
592 | ||
593 | // ------------------------------------------------------------------------ | |
594 | // Simulated Table API | |
595 | // ------------------------------------------------------------------------ | |
596 | ||
02023181 MK |
597 | /** |
598 | * Method setHeaderVisible. | |
599 | * @param b boolean | |
600 | */ | |
631d853f PT |
601 | public void setHeaderVisible(boolean b) { |
602 | fTable.setHeaderVisible(b); | |
603 | } | |
604 | ||
02023181 MK |
605 | /** |
606 | * Method setLinesVisible. | |
607 | * @param b boolean | |
608 | */ | |
631d853f PT |
609 | public void setLinesVisible(boolean b) { |
610 | fTable.setLinesVisible(b); | |
611 | } | |
612 | ||
02023181 | 613 | /** |
3f43dc48 PT |
614 | * Returns an array of <code>TableItem</code>s that are currently selected |
615 | * in the receiver. The order of the items is unspecified. An empty array | |
616 | * indicates that no items are selected. | |
617 | * <p> | |
618 | * Note: This array only contains the visible selected items in the virtual | |
619 | * table. To get information about the full selection range, use | |
620 | * {@link #getSelectionIndices()}. | |
621 | * </p> | |
622 | * | |
623 | * @return an array representing the selection | |
624 | * | |
625 | * @exception SWTException <ul> | |
626 | * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
627 | * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
628 | * </ul> | |
02023181 | 629 | */ |
631d853f PT |
630 | public TableItem[] getSelection() { |
631 | return fTable.getSelection(); | |
632 | } | |
633 | ||
02023181 MK |
634 | /** |
635 | * Method addListener. | |
636 | * @param eventType int | |
637 | * @param listener Listener | |
638 | */ | |
631d853f | 639 | @Override |
828e5592 PT |
640 | public void addListener(int eventType, Listener listener) { |
641 | fTable.addListener(eventType, listener); | |
642 | } | |
631d853f | 643 | |
02023181 MK |
644 | /** |
645 | * Method addKeyListener. | |
646 | * @param listener KeyListener | |
647 | */ | |
631d853f PT |
648 | @Override |
649 | public void addKeyListener(KeyListener listener) { | |
650 | fTable.addKeyListener(listener); | |
651 | } | |
b21305c2 | 652 | |
828e5592 | 653 | |
02023181 MK |
654 | /** |
655 | * Method addMouseListener. | |
656 | * @param listener MouseListener | |
657 | */ | |
828e5592 | 658 | @Override |
631d853f PT |
659 | public void addMouseListener(MouseListener listener) { |
660 | fTable.addMouseListener(listener); | |
661 | } | |
662 | ||
02023181 MK |
663 | /** |
664 | * Method addSelectionListener. | |
665 | * @param listener SelectionListener | |
666 | */ | |
631d853f PT |
667 | public void addSelectionListener(SelectionListener listener) { |
668 | fTable.addSelectionListener(listener); | |
669 | } | |
670 | ||
02023181 MK |
671 | /** |
672 | * Method setMenu sets the menu | |
673 | * @param menu Menu the menu | |
674 | */ | |
631d853f PT |
675 | @Override |
676 | public void setMenu(Menu menu) { | |
677 | fTable.setMenu(menu); | |
678 | } | |
679 | ||
48da630d XR |
680 | /** |
681 | * Gets the menu of this table | |
682 | * @return a Menu | |
683 | */ | |
684 | @Override | |
685 | public Menu getMenu() { | |
686 | return fTable.getMenu(); | |
687 | } | |
688 | ||
02023181 | 689 | /** |
3934297e | 690 | * Method clearAll empties a table. |
02023181 | 691 | */ |
631d853f PT |
692 | public void clearAll() { |
693 | setItemCount(0); | |
694 | } | |
695 | ||
02023181 MK |
696 | /** |
697 | * Method setItemCount | |
698 | * @param nbItems int the number of items in the table | |
3934297e | 699 | * |
02023181 | 700 | */ |
631d853f | 701 | public void setItemCount(int nbItems) { |
41b5c37f | 702 | final int nb = Math.max(0, nbItems); |
631d853f | 703 | |
41b5c37f AM |
704 | if (nb != fTableItemCount) { |
705 | fTableItemCount = nb; | |
631d853f | 706 | fTable.remove(fTableItemCount, fTable.getItemCount() - 1); |
41b5c37f | 707 | fSlider.setMaximum(nb); |
631d853f PT |
708 | resize(); |
709 | int tableHeight = Math.max(0, fTable.getClientArea().height - fTable.getHeaderHeight()); | |
710 | fFullyVisibleRows = tableHeight / getItemHeight(); | |
711 | if (fTableItemCount > 0) { | |
712 | fSlider.setThumb(Math.max(1, Math.min(fTableRows, fFullyVisibleRows))); | |
713 | } | |
714 | } | |
715 | } | |
716 | ||
02023181 MK |
717 | /** |
718 | * Method getItemCount. | |
719 | * @return int the number of items in the table | |
720 | */ | |
631d853f PT |
721 | public int getItemCount() { |
722 | return fTableItemCount; | |
723 | } | |
724 | ||
02023181 MK |
725 | /** |
726 | * Method getItemHeight. | |
727 | * @return int the height of a table item in pixels. (may vary from one os to another) | |
728 | */ | |
631d853f PT |
729 | public int getItemHeight() { |
730 | /* | |
731 | * Bug in Linux. The method getItemHeight doesn't always return the correct value. | |
732 | */ | |
733 | if (fLinuxItemHeight >= 0 && System.getProperty("os.name").contains("Linux")) { //$NON-NLS-1$ //$NON-NLS-2$ | |
734 | if (fLinuxItemHeight != 0) { | |
735 | return fLinuxItemHeight; | |
736 | } | |
737 | if (fTable.getItemCount() > 1) { | |
738 | int itemHeight = fTable.getItem(1).getBounds().y - fTable.getItem(0).getBounds().y; | |
739 | if (itemHeight > 0) { | |
740 | fLinuxItemHeight = itemHeight; | |
741 | return fLinuxItemHeight; | |
742 | } | |
743 | } | |
744 | } else { | |
745 | fLinuxItemHeight = -1; // Not Linux, don't perform os.name check anymore | |
746 | } | |
747 | return fTable.getItemHeight(); | |
748 | } | |
749 | ||
02023181 MK |
750 | /** |
751 | * Method getHeaderHeight. | |
752 | * @return int get the height of the header in pixels. | |
753 | */ | |
ea08e8ed PT |
754 | public int getHeaderHeight() { |
755 | return fTable.getHeaderHeight(); | |
756 | } | |
757 | ||
02023181 MK |
758 | /** |
759 | * Method getTopIndex. | |
760 | * @return int get the first data item index, if you have a header it is offset. | |
761 | */ | |
631d853f PT |
762 | public int getTopIndex() { |
763 | return fTableTopEventRank + fFrozenRowCount; | |
764 | } | |
765 | ||
02023181 MK |
766 | /** |
767 | * Method setTopIndex. | |
41b5c37f | 768 | * @param index int suggested top index for the table. |
02023181 | 769 | */ |
41b5c37f | 770 | public void setTopIndex(int index) { |
631d853f | 771 | if (fTableItemCount > 0) { |
41b5c37f | 772 | int i = Math.min(index, fTableItemCount - 1); |
631d853f PT |
773 | i = Math.max(i, fFrozenRowCount); |
774 | ||
775 | fTableTopEventRank = i - fFrozenRowCount; | |
776 | if (fFullyVisibleRows < fTableItemCount) { | |
777 | fSlider.setSelection(fTableTopEventRank); | |
778 | } | |
779 | ||
780 | refreshTable(); | |
781 | } | |
782 | } | |
783 | ||
02023181 MK |
784 | /** |
785 | * Method indexOf. Return the index of a table item | |
786 | * @param ti TableItem the table item to search for in the table | |
3934297e | 787 | * @return int the index of the first match. (there should only be one match) |
02023181 | 788 | */ |
631d853f PT |
789 | public int indexOf(TableItem ti) { |
790 | int index = fTable.indexOf(ti); | |
791 | if (index < fFrozenRowCount) { | |
792 | return index; | |
631d853f | 793 | } |
abbdd66a | 794 | return (index - fFrozenRowCount) + getTopIndex(); |
631d853f PT |
795 | } |
796 | ||
02023181 MK |
797 | /** |
798 | * Method getColumns. | |
3934297e | 799 | * @return TableColumn[] the table columns |
02023181 | 800 | */ |
631d853f PT |
801 | public TableColumn[] getColumns() { |
802 | return fTable.getColumns(); | |
803 | } | |
804 | ||
02023181 MK |
805 | /** |
806 | * Method getItem. | |
807 | * @param point Point the coordinates in the table | |
3934297e | 808 | * @return TableItem the corresponding table item |
02023181 | 809 | */ |
631d853f PT |
810 | public TableItem getItem(Point point) { |
811 | return fTable.getItem(point); | |
812 | } | |
813 | ||
02023181 MK |
814 | /** |
815 | * Method resize. | |
816 | */ | |
631d853f PT |
817 | private void resize() { |
818 | // Compute the numbers of rows that fit the new area | |
819 | int tableHeight = Math.max(0, getSize().y - fTable.getHeaderHeight()); | |
820 | int itemHeight = getItemHeight(); | |
821 | fTableRows = Math.min((tableHeight + itemHeight - 1) / itemHeight, fTableItemCount); | |
822 | ||
823 | if (fTableTopEventRank + fFullyVisibleRows > fTableItemCount) { | |
824 | // If we are at the end, get elements before to populate | |
825 | fTableTopEventRank = Math.max(0, fTableItemCount - fFullyVisibleRows); | |
826 | refreshTable(); | |
827 | } else if (fTableRows > fTable.getItemCount() || fTableItemCount < fTable.getItemCount()) { | |
828 | // Only refresh if new table items are needed or if table items need to be deleted | |
829 | refreshTable(); | |
830 | } | |
831 | ||
832 | } | |
833 | ||
834 | // ------------------------------------------------------------------------ | |
835 | // Controls interactions | |
836 | // ------------------------------------------------------------------------ | |
837 | ||
02023181 MK |
838 | /** |
839 | * Method setFocus. | |
840 | * @return boolean is this visible? | |
841 | */ | |
631d853f PT |
842 | @Override |
843 | public boolean setFocus() { | |
844 | boolean isVisible = isVisible(); | |
845 | if (isVisible) { | |
846 | fTable.setFocus(); | |
847 | } | |
848 | return isVisible; | |
849 | } | |
850 | ||
02023181 MK |
851 | /** |
852 | * Method refresh. | |
853 | */ | |
631d853f PT |
854 | public void refresh() { |
855 | boolean done = refreshTable(); | |
3f43dc48 PT |
856 | if (!done) { |
857 | return; | |
858 | } | |
631d853f PT |
859 | if (fPendingSelection && done) { |
860 | fPendingSelection = false; | |
3f43dc48 PT |
861 | TableItem item = null; |
862 | if (fSelectedEventRank >= 0 && fSelectedEventRank < fFrozenRowCount) { | |
863 | item = fTable.getItem(fSelectedEventRank); | |
864 | } else if (fSelectedEventRank >= fTableTopEventRank + fFrozenRowCount && fSelectedEventRank - fTableTopEventRank < fTable.getItemCount()) { | |
865 | item = fTable.getItem(fSelectedEventRank - fTableTopEventRank); | |
866 | } | |
867 | if (item != null) { | |
631d853f | 868 | Event e = new Event(); |
3f43dc48 | 869 | e.item = item; |
631d853f PT |
870 | fTable.notifyListeners(SWT.Selection, e); |
871 | } | |
872 | } | |
873 | } | |
874 | ||
02023181 MK |
875 | /** |
876 | * Method setColumnHeaders. | |
3934297e | 877 | * @param columnData ColumnData[] the columndata array. |
02023181 | 878 | */ |
631d853f PT |
879 | public void setColumnHeaders(ColumnData columnData[]) { |
880 | for (int i = 0; i < columnData.length; i++) { | |
881 | TableColumn column = new TableColumn(fTable, columnData[i].alignment, i); | |
882 | column.setText(columnData[i].header); | |
b06f64b7 PT |
883 | /* |
884 | * In Linux the table does not receive a control resized event when | |
885 | * a table column resize causes the horizontal scroll bar to become | |
886 | * visible or invisible, so a resize listener must be added to every | |
887 | * table column to properly update the number of fully visible rows. | |
888 | */ | |
889 | column.addControlListener(fResizeListener); | |
631d853f PT |
890 | if (columnData[i].width > 0) { |
891 | column.setWidth(columnData[i].width); | |
892 | } else { | |
893 | column.pack(); | |
894 | } | |
895 | } | |
896 | } | |
897 | ||
02023181 MK |
898 | /** |
899 | * Method removeAll. | |
900 | * @return int 0 the number of elements in the table | |
901 | */ | |
631d853f PT |
902 | public int removeAll() { |
903 | setItemCount(0); | |
904 | fSlider.setMaximum(0); | |
905 | fTable.removeAll(); | |
3f43dc48 PT |
906 | fSelectedEventRank = -1; |
907 | fSelectedBeginRank = fSelectedEventRank; | |
631d853f PT |
908 | return 0; |
909 | } | |
910 | ||
02023181 MK |
911 | /** |
912 | * Method refreshTable. | |
3f43dc48 | 913 | * @return true if all table items have been refreshed, false otherwise |
02023181 | 914 | */ |
631d853f PT |
915 | private boolean refreshTable() { |
916 | boolean done = true; | |
917 | for (int i = 0; i < fTableRows; i++) { | |
918 | if (i + fTableTopEventRank < fTableItemCount) { | |
919 | TableItem tableItem; | |
920 | if (i < fTable.getItemCount()) { | |
921 | tableItem = fTable.getItem(i); | |
922 | } else { | |
923 | tableItem = new TableItem(fTable, SWT.NONE); | |
924 | } | |
925 | done &= setDataItem(i, tableItem); // false if table item not updated yet in this thread | |
926 | } else { | |
927 | if (fTable.getItemCount() > fTableItemCount - fTableTopEventRank) { | |
928 | fTable.remove(fTableItemCount - fTableTopEventRank); | |
929 | } | |
930 | } | |
931 | } | |
3f43dc48 PT |
932 | if (done) { |
933 | refreshSelection(); | |
934 | } else { | |
935 | fTable.deselectAll(); | |
936 | } | |
937 | return done; | |
938 | } | |
631d853f | 939 | |
3f43dc48 | 940 | private void refreshSelection() { |
631d853f | 941 | int lastRowOffset = fTableTopEventRank + fTableRows - 1; |
3f43dc48 PT |
942 | int startRank = Math.min(fSelectedBeginRank, fSelectedEventRank); |
943 | int endRank = Math.max(fSelectedBeginRank, fSelectedEventRank); | |
944 | int start = Integer.MAX_VALUE; | |
945 | int end = Integer.MIN_VALUE; | |
946 | if (startRank < fFrozenRowCount) { | |
947 | start = startRank; | |
948 | } else if (startRank < fTableTopEventRank + fFrozenRowCount) { | |
949 | start = fFrozenRowCount; | |
950 | } else if (startRank <= lastRowOffset) { | |
951 | start = startRank - fTableTopEventRank; | |
952 | } | |
953 | if (endRank < fFrozenRowCount) { | |
954 | end = endRank; | |
955 | } else if (endRank < fTableTopEventRank + fFrozenRowCount) { | |
956 | end = fFrozenRowCount - 1; | |
957 | } else if (endRank <= lastRowOffset) { | |
958 | end = endRank - fTableTopEventRank; | |
959 | } else { | |
960 | end = fTableRows - 1; | |
961 | } | |
962 | if (start <= end) { | |
963 | fTable.setSelection(start, end); | |
964 | if (startRank == fSelectedEventRank) { | |
965 | fTable.select(start); | |
966 | } else { | |
967 | fTable.select(end); | |
968 | } | |
631d853f PT |
969 | } else { |
970 | fTable.deselectAll(); | |
971 | } | |
631d853f PT |
972 | } |
973 | ||
02023181 | 974 | /** |
3f43dc48 PT |
975 | * Selects the item at the given zero-relative index in the receiver. |
976 | * The current selection is first cleared, then the new item is selected, | |
977 | * and if necessary the receiver is scrolled to make the new selection visible. | |
978 | * | |
979 | * @param index the index of the item to select | |
980 | * | |
981 | * @exception SWTException <ul> | |
982 | * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
983 | * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
984 | * </ul> | |
02023181 | 985 | */ |
41b5c37f | 986 | public void setSelection(int index) { |
631d853f | 987 | if (fTableItemCount > 0) { |
41b5c37f | 988 | int i = Math.min(index, fTableItemCount - 1); |
631d853f PT |
989 | i = Math.max(i, 0); |
990 | ||
991 | fSelectedEventRank = i; | |
3f43dc48 | 992 | fSelectedBeginRank = fSelectedEventRank; |
631d853f PT |
993 | if ((i < fTableTopEventRank + fFrozenRowCount && i >= fFrozenRowCount) || |
994 | (i >= fTableTopEventRank + fFullyVisibleRows)) { | |
faa38350 PT |
995 | int lastPageTopEntryRank = Math.max(0, fTableItemCount - fFullyVisibleRows); |
996 | fTableTopEventRank = Math.max(0, Math.min(lastPageTopEntryRank, i - fFrozenRowCount - fFullyVisibleRows / 2)); | |
631d853f PT |
997 | } |
998 | if (fFullyVisibleRows < fTableItemCount) { | |
999 | fSlider.setSelection(fTableTopEventRank); | |
1000 | } | |
1001 | ||
1002 | refreshTable(); | |
1003 | ||
1004 | } | |
1005 | } | |
1006 | ||
02023181 | 1007 | /** |
3f43dc48 PT |
1008 | * Returns the zero-relative index of the item which is currently |
1009 | * selected in the receiver, or -1 if no item is selected. | |
1010 | * | |
1011 | * @return the index of the selected item | |
02023181 | 1012 | */ |
631d853f | 1013 | public int getSelectionIndex() { |
3f43dc48 PT |
1014 | return fSelectedEventRank; |
1015 | } | |
1016 | ||
1017 | /** | |
1018 | * Returns an index array representing the selection range. If there is a | |
1019 | * single item selected the array holds one index. If there is a selected | |
1020 | * range the first item in the array is the start index of the selection and | |
1021 | * the second item is the end index of the selection, which is the item most | |
1022 | * recently selected. The array is empty if no items are selected. | |
1023 | * <p> | |
1024 | * @return the array of indices of the selected items | |
1025 | * @since 2.1 | |
1026 | */ | |
1027 | public int[] getSelectionIndices() { | |
1028 | if (fSelectedEventRank < 0 || fSelectedBeginRank < 0) { | |
1029 | return new int[] {}; | |
1030 | } else if (fSelectedEventRank == fSelectedBeginRank) { | |
1031 | return new int[] { fSelectedEventRank }; | |
631d853f | 1032 | } |
3f43dc48 | 1033 | return new int[] { fSelectedBeginRank, fSelectedEventRank }; |
631d853f PT |
1034 | } |
1035 | ||
02023181 MK |
1036 | /** |
1037 | * Method setFrozenRowCount. | |
1038 | * @param count int the number of rows to freeze from the top row | |
1039 | */ | |
631d853f PT |
1040 | public void setFrozenRowCount(int count) { |
1041 | fFrozenRowCount = count; | |
1042 | refreshTable(); | |
1043 | } | |
1044 | ||
02023181 MK |
1045 | /** |
1046 | * Method createTableEditor. | |
1047 | * @return a TableEditor of the table | |
1048 | */ | |
631d853f PT |
1049 | public TableEditor createTableEditor() { |
1050 | return new TableEditor(fTable); | |
1051 | } | |
1052 | ||
02023181 MK |
1053 | /** |
1054 | * Method createTableEditorControl. | |
1055 | * @param control Class<? extends Control> | |
1056 | * @return Control | |
1057 | */ | |
631d853f PT |
1058 | public Control createTableEditorControl(Class<? extends Control> control) { |
1059 | try { | |
420bceb2 | 1060 | return control.getConstructor(Composite.class, int.class).newInstance(new Object[] {fTable, SWT.NONE}); |
631d853f PT |
1061 | } catch (Exception e) { |
1062 | Activator.getDefault().logError("Error creating table editor control", e); //$NON-NLS-1$ | |
1063 | } | |
1064 | return null; | |
1065 | } | |
1066 | ||
1067 | /** | |
1068 | * @return the tooltipProvider | |
02023181 | 1069 | */ |
631d853f PT |
1070 | public TooltipProvider getTooltipProvider() { |
1071 | return tooltipProvider; | |
1072 | } | |
1073 | ||
1074 | /** | |
1075 | * @param tooltipProvider the tooltipProvider to set | |
1076 | */ | |
1077 | public void setTooltipProvider(TooltipProvider tooltipProvider) { | |
1078 | this.tooltipProvider = tooltipProvider; | |
1079 | } | |
1080 | ||
1081 | /** | |
1082 | * @return the doubleClickListener | |
02023181 | 1083 | */ |
631d853f PT |
1084 | public IDoubleClickListener getDoubleClickListener() { |
1085 | return doubleClickListener; | |
1086 | } | |
1087 | ||
1088 | /** | |
1089 | * @param doubleClickListener the doubleClickListener to set | |
1090 | */ | |
1091 | public void setDoubleClickListener(IDoubleClickListener doubleClickListener) { | |
1092 | this.doubleClickListener = doubleClickListener; | |
1093 | } | |
1094 | ||
9ccc6d01 | 1095 | } |