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 | ||
dadf6e1a | 84 | private int fTableItemCount = 0; |
631d853f PT |
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$ | |
dadf6e1a | 176 | final Listener labelListener = new Listener() { |
631d853f | 177 | @Override |
f4c52cea | 178 | public void handleEvent (Event event) { |
dadf6e1a EB |
179 | Label label = (Label) event.widget; |
180 | Shell shell = label.getShell(); | |
631d853f PT |
181 | switch (event.type) { |
182 | case SWT.MouseDown: | |
dadf6e1a EB |
183 | Event e = new Event(); |
184 | e.item = (TableItem) label.getData(TOOLTIP_DATA_KEY); | |
631d853f PT |
185 | // Assuming table is single select, set the selection as if |
186 | // the mouse down event went through to the table | |
dadf6e1a EB |
187 | fTable.setSelection(new TableItem [] {(TableItem) e.item}); |
188 | fTable.notifyListeners(SWT.Selection, e); | |
189 | shell.dispose(); | |
631d853f PT |
190 | fTable.setFocus(); |
191 | break; | |
192 | case SWT.MouseExit: | |
193 | case SWT.MouseWheel: | |
dadf6e1a | 194 | shell.dispose(); |
631d853f | 195 | break; |
abbdd66a AM |
196 | default: |
197 | break; | |
631d853f PT |
198 | } |
199 | } | |
200 | }; | |
201 | ||
dadf6e1a | 202 | Listener tableListener = new Listener() { |
631d853f PT |
203 | Shell tip = null; |
204 | Label label = null; | |
205 | @Override | |
dadf6e1a | 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 | } | |
dadf6e1a | 214 | tip.dispose(); |
631d853f PT |
215 | tip = null; |
216 | label = null; | |
217 | break; | |
218 | } | |
219 | case SWT.MouseHover: { | |
dadf6e1a | 220 | TableItem item = fTable.getItem(new Point(event.x, event.y)); |
631d853f | 221 | if (item != null) { |
dadf6e1a | 222 | for (int i = 0; i < fTable.getColumnCount(); i++) { |
631d853f | 223 | Rectangle bounds = item.getBounds(i); |
dadf6e1a | 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); | |
dadf6e1a EB |
253 | |
254 | // Item found, leave loop. | |
255 | break; | |
631d853f PT |
256 | } |
257 | } | |
258 | } | |
abbdd66a | 259 | break; |
631d853f | 260 | } |
abbdd66a AM |
261 | default: |
262 | break; | |
631d853f PT |
263 | } |
264 | } | |
265 | }; | |
266 | fTable.addListener(SWT.Dispose, tableListener); | |
267 | fTable.addListener(SWT.KeyDown, tableListener); | |
268 | fTable.addListener(SWT.MouseMove, tableListener); | |
269 | fTable.addListener(SWT.MouseHover, tableListener); | |
270 | addControlListener(new ControlAdapter() { | |
271 | @Override | |
272 | public void controlResized(ControlEvent event) { | |
273 | resize(); | |
420bceb2 PT |
274 | if (fTableItemCount > 0) { |
275 | fSlider.setThumb(Math.max(1, Math.min(fTableRows, fFullyVisibleRows))); | |
276 | } | |
631d853f PT |
277 | } |
278 | }); | |
279 | ||
280 | // And display | |
281 | refresh(); | |
282 | } | |
283 | ||
284 | // ------------------------------------------------------------------------ | |
285 | // Table handling | |
286 | // ------------------------------------------------------------------------ | |
287 | ||
288 | /** | |
289 | * Create the table and add listeners | |
3f43dc48 | 290 | * @param style int can be H_SCROLL, SINGLE, MULTI, FULL_SELECTION, HIDE_SELECTION, CHECK |
631d853f PT |
291 | */ |
292 | private void createTable(int style) { | |
293 | fTable = new Table(this, style | SWT.NO_SCROLL); | |
294 | ||
295 | fTable.addSelectionListener(new SelectionAdapter() { | |
296 | @Override | |
297 | public void widgetSelected(SelectionEvent event) { | |
3f43dc48 PT |
298 | if (event.item == null) { |
299 | // Override table selection from Select All action | |
300 | refreshSelection(); | |
631d853f PT |
301 | } |
302 | } | |
303 | }); | |
9ccc6d01 | 304 | |
3f43dc48 | 305 | fTable.addMouseListener(new MouseAdapter() { |
631d853f | 306 | @Override |
3f43dc48 PT |
307 | public void mouseDown(MouseEvent e) { |
308 | handleTableMouseEvent(e); | |
631d853f | 309 | } |
3f43dc48 PT |
310 | }); |
311 | ||
312 | fTable.addKeyListener(new KeyAdapter() { | |
631d853f | 313 | @Override |
3f43dc48 PT |
314 | public void keyPressed(KeyEvent event) { |
315 | handleTableKeyEvent(event); | |
631d853f PT |
316 | } |
317 | }); | |
7800a42f XR |
318 | |
319 | fTable.addListener( | |
631d853f PT |
320 | SWT.MouseDoubleClick, new Listener() { |
321 | @Override | |
322 | public void handleEvent(Event event) { | |
323 | if (doubleClickListener != null) { | |
dadf6e1a | 324 | TableItem item = fTable.getItem(new Point (event.x, event.y)); |
631d853f | 325 | if (item != null) { |
dadf6e1a | 326 | for (int i = 0; i < fTable.getColumnCount(); i++){ |
631d853f | 327 | Rectangle bounds = item.getBounds(i); |
dadf6e1a | 328 | if (bounds.contains(event.x, event.y)){ |
631d853f PT |
329 | doubleClickListener.handleDoubleClick(TmfVirtualTable.this, item, i); |
330 | break; | |
331 | } | |
332 | } | |
333 | } | |
334 | } | |
335 | } | |
336 | } | |
337 | ); | |
dd03e2f1 PT |
338 | |
339 | /* | |
c9787691 PT |
340 | * Feature in Windows. When a partially visible table item is selected, |
341 | * after ~500 ms the top index is changed to ensure the selected item is | |
342 | * fully visible. This leaves a blank space at the bottom of the virtual | |
343 | * table. The workaround is to reset the top index to 0 if it is not 0. | |
344 | * Also reset the top index to 0 if indicated by the flag that was set | |
345 | * at table selection of a partially visible table item. | |
dd03e2f1 PT |
346 | */ |
347 | fTable.addPaintListener(new PaintListener() { | |
348 | @Override | |
349 | public void paintControl(PaintEvent e) { | |
c9787691 PT |
350 | if (fTable.getTopIndex() != 0 || fResetTopIndex) { |
351 | fTable.setTopIndex(0); | |
352 | } | |
353 | fResetTopIndex = false; | |
dd03e2f1 PT |
354 | } |
355 | }); | |
631d853f PT |
356 | } |
357 | ||
358 | /** | |
3f43dc48 PT |
359 | * Handle mouse-based selection in table. |
360 | * | |
361 | * @param event the mouse event | |
631d853f | 362 | */ |
3f43dc48 PT |
363 | private void handleTableMouseEvent(MouseEvent event) { |
364 | TableItem item = fTable.getItem(new Point(event.x, event.y)); | |
365 | if (item == null) { | |
366 | return; | |
367 | } | |
368 | int selectedRow = indexOf(item); | |
90328647 PT |
369 | if (event.button == 1 || (event.button == 3 && |
370 | (selectedRow < Math.min(fSelectedBeginRank, fSelectedEventRank) || | |
371 | selectedRow > Math.max(fSelectedBeginRank, fSelectedEventRank)))) { | |
3f43dc48 PT |
372 | if (selectedRow >= 0) { |
373 | fSelectedEventRank = selectedRow; | |
374 | } else { | |
375 | fSelectedEventRank = -1; | |
376 | } | |
377 | if ((event.stateMask & SWT.SHIFT) == 0 || (fTable.getStyle() & SWT.MULTI) == 0 || fSelectedBeginRank == -1) { | |
378 | fSelectedBeginRank = fSelectedEventRank; | |
379 | } | |
631d853f | 380 | } |
3f43dc48 | 381 | refreshSelection(); |
c9787691 PT |
382 | |
383 | /* | |
384 | * Feature in Linux. When a partially visible table item is selected, | |
385 | * the origin is changed to ensure the selected item is fully visible. | |
386 | * This makes the first row partially visible. The solution is to force | |
387 | * reset the origin by setting the top index to 0. This should happen | |
388 | * only once at the next redraw by the paint listener. | |
389 | */ | |
390 | if (selectedRow >= fFullyVisibleRows) { | |
391 | fResetTopIndex = true; | |
392 | } | |
631d853f PT |
393 | } |
394 | ||
395 | /** | |
396 | * Handle key-based navigation in table. | |
3934297e | 397 | * |
3f43dc48 | 398 | * @param event the key event |
631d853f PT |
399 | */ |
400 | private void handleTableKeyEvent(KeyEvent event) { | |
401 | ||
402 | int lastEventRank = fTableItemCount - 1; | |
403 | int lastPageTopEntryRank = Math.max(0, fTableItemCount - fFullyVisibleRows); | |
404 | ||
405 | int previousSelectedEventRank = fSelectedEventRank; | |
3f43dc48 | 406 | int previousSelectedBeginRank = fSelectedBeginRank; |
631d853f PT |
407 | boolean needsRefresh = false; |
408 | ||
409 | // In all case, perform the following steps: | |
410 | // - Update the selected entry rank (within valid range) | |
411 | // - Update the selected row | |
412 | // - Update the page's top entry if necessary (which also adjusts the selected row) | |
413 | // - If the top displayed entry was changed, table refresh is needed | |
414 | switch (event.keyCode) { | |
415 | ||
416 | case SWT.ARROW_DOWN: { | |
417 | event.doit = false; | |
418 | if (fSelectedEventRank < lastEventRank) { | |
419 | fSelectedEventRank++; | |
3f43dc48 | 420 | int selectedRow = fSelectedEventRank - fTableTopEventRank; |
75c271cf | 421 | if (selectedRow == fFullyVisibleRows) { |
631d853f PT |
422 | fTableTopEventRank++; |
423 | needsRefresh = true; | |
75c271cf PT |
424 | } else if (selectedRow < fFrozenRowCount || selectedRow > fFullyVisibleRows) { |
425 | fTableTopEventRank = Math.max(0, Math.min(fSelectedEventRank - fFrozenRowCount, lastPageTopEntryRank)); | |
426 | needsRefresh = true; | |
631d853f PT |
427 | } |
428 | } | |
429 | break; | |
430 | } | |
431 | ||
432 | case SWT.ARROW_UP: { | |
433 | event.doit = false; | |
434 | if (fSelectedEventRank > 0) { | |
435 | fSelectedEventRank--; | |
3f43dc48 | 436 | int selectedRow = fSelectedEventRank - fTableTopEventRank; |
75c271cf | 437 | if (selectedRow == fFrozenRowCount - 1 && fTableTopEventRank > 0) { |
631d853f PT |
438 | fTableTopEventRank--; |
439 | needsRefresh = true; | |
75c271cf PT |
440 | } else if (selectedRow < fFrozenRowCount || selectedRow > fFullyVisibleRows) { |
441 | fTableTopEventRank = Math.max(0, Math.min(fSelectedEventRank - fFrozenRowCount, lastPageTopEntryRank)); | |
442 | needsRefresh = true; | |
631d853f PT |
443 | } |
444 | } | |
445 | break; | |
446 | } | |
447 | ||
448 | case SWT.END: { | |
449 | event.doit = false; | |
450 | fTableTopEventRank = lastPageTopEntryRank; | |
451 | fSelectedEventRank = lastEventRank; | |
452 | needsRefresh = true; | |
453 | break; | |
454 | } | |
455 | ||
456 | case SWT.HOME: { | |
457 | event.doit = false; | |
458 | fSelectedEventRank = fFrozenRowCount; | |
459 | fTableTopEventRank = 0; | |
460 | needsRefresh = true; | |
461 | break; | |
462 | } | |
463 | ||
464 | case SWT.PAGE_DOWN: { | |
465 | event.doit = false; | |
466 | if (fSelectedEventRank < lastEventRank) { | |
467 | fSelectedEventRank += fFullyVisibleRows; | |
468 | if (fSelectedEventRank > lastEventRank) { | |
469 | fSelectedEventRank = lastEventRank; | |
470 | } | |
3f43dc48 | 471 | int selectedRow = fSelectedEventRank - fTableTopEventRank; |
75c271cf | 472 | if (selectedRow > fFullyVisibleRows + fFrozenRowCount - 1 && selectedRow < 2 * fFullyVisibleRows) { |
631d853f PT |
473 | fTableTopEventRank += fFullyVisibleRows; |
474 | if (fTableTopEventRank > lastPageTopEntryRank) { | |
475 | fTableTopEventRank = lastPageTopEntryRank; | |
476 | } | |
477 | needsRefresh = true; | |
75c271cf PT |
478 | } else if (selectedRow < fFrozenRowCount || selectedRow >= 2 * fFullyVisibleRows) { |
479 | fTableTopEventRank = Math.max(0, Math.min(fSelectedEventRank - fFrozenRowCount, lastPageTopEntryRank)); | |
480 | needsRefresh = true; | |
631d853f PT |
481 | } |
482 | } | |
483 | break; | |
484 | } | |
485 | ||
486 | case SWT.PAGE_UP: { | |
487 | event.doit = false; | |
488 | if (fSelectedEventRank > 0) { | |
489 | fSelectedEventRank -= fFullyVisibleRows; | |
490 | if (fSelectedEventRank < fFrozenRowCount) { | |
491 | fSelectedEventRank = fFrozenRowCount; | |
492 | } | |
3f43dc48 | 493 | int selectedRow = fSelectedEventRank - fTableTopEventRank; |
75c271cf | 494 | if (selectedRow < fFrozenRowCount && selectedRow > -fFullyVisibleRows) { |
631d853f PT |
495 | fTableTopEventRank -= fFullyVisibleRows; |
496 | if (fTableTopEventRank < 0) { | |
497 | fTableTopEventRank = 0; | |
498 | } | |
499 | needsRefresh = true; | |
75c271cf PT |
500 | } else if (selectedRow <= -fFullyVisibleRows || selectedRow >= fFullyVisibleRows) { |
501 | fTableTopEventRank = Math.max(0, Math.min(fSelectedEventRank - fFrozenRowCount, lastPageTopEntryRank)); | |
502 | needsRefresh = true; | |
631d853f PT |
503 | } |
504 | } | |
505 | break; | |
506 | } | |
507 | default: { | |
508 | return; | |
509 | } | |
510 | } | |
511 | ||
3f43dc48 PT |
512 | if ((event.stateMask & SWT.SHIFT) == 0 || (fTable.getStyle() & SWT.MULTI) == 0 || fSelectedBeginRank == -1) { |
513 | fSelectedBeginRank = fSelectedEventRank; | |
514 | } | |
515 | ||
631d853f PT |
516 | boolean done = true; |
517 | if (needsRefresh) { | |
518 | done = refreshTable(); // false if table items not updated yet in this thread | |
519 | } else { | |
3f43dc48 | 520 | refreshSelection(); |
631d853f PT |
521 | } |
522 | ||
523 | if (fFullyVisibleRows < fTableItemCount) { | |
524 | fSlider.setSelection(fTableTopEventRank); | |
525 | } | |
526 | ||
3f43dc48 | 527 | if (fSelectedEventRank != previousSelectedEventRank || fSelectedBeginRank != previousSelectedBeginRank) { |
631d853f PT |
528 | if (done) { |
529 | Event e = new Event(); | |
3f43dc48 | 530 | e.item = fTable.getItem(fSelectedEventRank - fTableTopEventRank); |
631d853f PT |
531 | fTable.notifyListeners(SWT.Selection, e); |
532 | } else { | |
533 | fPendingSelection = true; | |
534 | } | |
535 | } | |
536 | } | |
537 | ||
02023181 MK |
538 | /** |
539 | * Method setDataItem. | |
540 | * @param index int | |
541 | * @param item TableItem | |
542 | * @return boolean | |
543 | */ | |
631d853f PT |
544 | private boolean setDataItem(int index, TableItem item) { |
545 | if (index != -1) { | |
546 | Event event = new Event(); | |
547 | event.item = item; | |
548 | if (index < fFrozenRowCount) { | |
549 | event.index = index; | |
550 | } else { | |
551 | event.index = index + fTableTopEventRank; | |
552 | } | |
553 | event.doit = true; | |
554 | fTable.notifyListeners(SWT.SetData, event); | |
555 | return event.doit; // false if table item not updated yet in this thread | |
556 | } | |
557 | return true; | |
558 | } | |
559 | ||
560 | // ------------------------------------------------------------------------ | |
561 | // Slider handling | |
562 | // ------------------------------------------------------------------------ | |
563 | ||
02023181 MK |
564 | /** |
565 | * Method createSlider. | |
566 | * @param style int | |
567 | */ | |
631d853f PT |
568 | private void createSlider(int style) { |
569 | fSlider = new Slider(this, SWT.VERTICAL | SWT.NO_FOCUS); | |
570 | fSlider.setMinimum(0); | |
571 | fSlider.setMaximum(0); | |
572 | if ((style & SWT.V_SCROLL) == 0) { | |
573 | fSlider.setVisible(false); | |
574 | } | |
575 | ||
576 | fSlider.addListener(SWT.Selection, new Listener() { | |
577 | @Override | |
578 | public void handleEvent(Event event) { | |
579 | switch (event.detail) { | |
580 | case SWT.ARROW_DOWN: | |
581 | case SWT.ARROW_UP: | |
582 | case SWT.NONE: | |
583 | case SWT.END: | |
584 | case SWT.HOME: | |
585 | case SWT.PAGE_DOWN: | |
586 | case SWT.PAGE_UP: { | |
587 | fTableTopEventRank = fSlider.getSelection(); | |
588 | refreshTable(); | |
589 | break; | |
590 | } | |
abbdd66a AM |
591 | default: |
592 | break; | |
631d853f PT |
593 | } |
594 | } | |
595 | }); | |
596 | } | |
597 | ||
598 | // ------------------------------------------------------------------------ | |
599 | // Simulated Table API | |
600 | // ------------------------------------------------------------------------ | |
601 | ||
02023181 MK |
602 | /** |
603 | * Method setHeaderVisible. | |
604 | * @param b boolean | |
605 | */ | |
631d853f PT |
606 | public void setHeaderVisible(boolean b) { |
607 | fTable.setHeaderVisible(b); | |
608 | } | |
609 | ||
02023181 MK |
610 | /** |
611 | * Method setLinesVisible. | |
612 | * @param b boolean | |
613 | */ | |
631d853f PT |
614 | public void setLinesVisible(boolean b) { |
615 | fTable.setLinesVisible(b); | |
616 | } | |
617 | ||
02023181 | 618 | /** |
3f43dc48 PT |
619 | * Returns an array of <code>TableItem</code>s that are currently selected |
620 | * in the receiver. The order of the items is unspecified. An empty array | |
621 | * indicates that no items are selected. | |
622 | * <p> | |
623 | * Note: This array only contains the visible selected items in the virtual | |
624 | * table. To get information about the full selection range, use | |
625 | * {@link #getSelectionIndices()}. | |
626 | * </p> | |
627 | * | |
628 | * @return an array representing the selection | |
629 | * | |
630 | * @exception SWTException <ul> | |
631 | * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
632 | * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
633 | * </ul> | |
02023181 | 634 | */ |
631d853f PT |
635 | public TableItem[] getSelection() { |
636 | return fTable.getSelection(); | |
637 | } | |
638 | ||
02023181 MK |
639 | /** |
640 | * Method addListener. | |
641 | * @param eventType int | |
642 | * @param listener Listener | |
643 | */ | |
631d853f | 644 | @Override |
828e5592 PT |
645 | public void addListener(int eventType, Listener listener) { |
646 | fTable.addListener(eventType, listener); | |
647 | } | |
631d853f | 648 | |
02023181 MK |
649 | /** |
650 | * Method addKeyListener. | |
651 | * @param listener KeyListener | |
652 | */ | |
631d853f PT |
653 | @Override |
654 | public void addKeyListener(KeyListener listener) { | |
655 | fTable.addKeyListener(listener); | |
656 | } | |
b21305c2 | 657 | |
02023181 MK |
658 | /** |
659 | * Method addMouseListener. | |
660 | * @param listener MouseListener | |
661 | */ | |
828e5592 | 662 | @Override |
631d853f PT |
663 | public void addMouseListener(MouseListener listener) { |
664 | fTable.addMouseListener(listener); | |
665 | } | |
666 | ||
02023181 MK |
667 | /** |
668 | * Method addSelectionListener. | |
669 | * @param listener SelectionListener | |
670 | */ | |
631d853f PT |
671 | public void addSelectionListener(SelectionListener listener) { |
672 | fTable.addSelectionListener(listener); | |
673 | } | |
674 | ||
02023181 MK |
675 | /** |
676 | * Method setMenu sets the menu | |
677 | * @param menu Menu the menu | |
678 | */ | |
631d853f PT |
679 | @Override |
680 | public void setMenu(Menu menu) { | |
681 | fTable.setMenu(menu); | |
682 | } | |
683 | ||
48da630d XR |
684 | /** |
685 | * Gets the menu of this table | |
686 | * @return a Menu | |
687 | */ | |
688 | @Override | |
689 | public Menu getMenu() { | |
690 | return fTable.getMenu(); | |
691 | } | |
692 | ||
02023181 | 693 | /** |
3934297e | 694 | * Method clearAll empties a table. |
02023181 | 695 | */ |
631d853f PT |
696 | public void clearAll() { |
697 | setItemCount(0); | |
698 | } | |
699 | ||
02023181 MK |
700 | /** |
701 | * Method setItemCount | |
702 | * @param nbItems int the number of items in the table | |
3934297e | 703 | * |
02023181 | 704 | */ |
631d853f | 705 | public void setItemCount(int nbItems) { |
41b5c37f | 706 | final int nb = Math.max(0, nbItems); |
631d853f | 707 | |
41b5c37f AM |
708 | if (nb != fTableItemCount) { |
709 | fTableItemCount = nb; | |
631d853f | 710 | fTable.remove(fTableItemCount, fTable.getItemCount() - 1); |
41b5c37f | 711 | fSlider.setMaximum(nb); |
631d853f PT |
712 | resize(); |
713 | int tableHeight = Math.max(0, fTable.getClientArea().height - fTable.getHeaderHeight()); | |
714 | fFullyVisibleRows = tableHeight / getItemHeight(); | |
715 | if (fTableItemCount > 0) { | |
716 | fSlider.setThumb(Math.max(1, Math.min(fTableRows, fFullyVisibleRows))); | |
717 | } | |
718 | } | |
719 | } | |
720 | ||
02023181 MK |
721 | /** |
722 | * Method getItemCount. | |
723 | * @return int the number of items in the table | |
724 | */ | |
631d853f PT |
725 | public int getItemCount() { |
726 | return fTableItemCount; | |
727 | } | |
728 | ||
02023181 MK |
729 | /** |
730 | * Method getItemHeight. | |
731 | * @return int the height of a table item in pixels. (may vary from one os to another) | |
732 | */ | |
631d853f PT |
733 | public int getItemHeight() { |
734 | /* | |
735 | * Bug in Linux. The method getItemHeight doesn't always return the correct value. | |
736 | */ | |
737 | if (fLinuxItemHeight >= 0 && System.getProperty("os.name").contains("Linux")) { //$NON-NLS-1$ //$NON-NLS-2$ | |
738 | if (fLinuxItemHeight != 0) { | |
739 | return fLinuxItemHeight; | |
740 | } | |
741 | if (fTable.getItemCount() > 1) { | |
742 | int itemHeight = fTable.getItem(1).getBounds().y - fTable.getItem(0).getBounds().y; | |
743 | if (itemHeight > 0) { | |
744 | fLinuxItemHeight = itemHeight; | |
745 | return fLinuxItemHeight; | |
746 | } | |
747 | } | |
748 | } else { | |
749 | fLinuxItemHeight = -1; // Not Linux, don't perform os.name check anymore | |
750 | } | |
751 | return fTable.getItemHeight(); | |
752 | } | |
753 | ||
02023181 MK |
754 | /** |
755 | * Method getHeaderHeight. | |
756 | * @return int get the height of the header in pixels. | |
757 | */ | |
ea08e8ed PT |
758 | public int getHeaderHeight() { |
759 | return fTable.getHeaderHeight(); | |
760 | } | |
761 | ||
02023181 MK |
762 | /** |
763 | * Method getTopIndex. | |
764 | * @return int get the first data item index, if you have a header it is offset. | |
765 | */ | |
631d853f PT |
766 | public int getTopIndex() { |
767 | return fTableTopEventRank + fFrozenRowCount; | |
768 | } | |
769 | ||
02023181 MK |
770 | /** |
771 | * Method setTopIndex. | |
41b5c37f | 772 | * @param index int suggested top index for the table. |
02023181 | 773 | */ |
41b5c37f | 774 | public void setTopIndex(int index) { |
631d853f | 775 | if (fTableItemCount > 0) { |
41b5c37f | 776 | int i = Math.min(index, fTableItemCount - 1); |
631d853f PT |
777 | i = Math.max(i, fFrozenRowCount); |
778 | ||
779 | fTableTopEventRank = i - fFrozenRowCount; | |
780 | if (fFullyVisibleRows < fTableItemCount) { | |
781 | fSlider.setSelection(fTableTopEventRank); | |
782 | } | |
783 | ||
784 | refreshTable(); | |
785 | } | |
786 | } | |
787 | ||
02023181 MK |
788 | /** |
789 | * Method indexOf. Return the index of a table item | |
790 | * @param ti TableItem the table item to search for in the table | |
3934297e | 791 | * @return int the index of the first match. (there should only be one match) |
02023181 | 792 | */ |
631d853f PT |
793 | public int indexOf(TableItem ti) { |
794 | int index = fTable.indexOf(ti); | |
795 | if (index < fFrozenRowCount) { | |
796 | return index; | |
631d853f | 797 | } |
abbdd66a | 798 | return (index - fFrozenRowCount) + getTopIndex(); |
631d853f PT |
799 | } |
800 | ||
02023181 MK |
801 | /** |
802 | * Method getColumns. | |
3934297e | 803 | * @return TableColumn[] the table columns |
02023181 | 804 | */ |
631d853f PT |
805 | public TableColumn[] getColumns() { |
806 | return fTable.getColumns(); | |
807 | } | |
808 | ||
02023181 MK |
809 | /** |
810 | * Method getItem. | |
811 | * @param point Point the coordinates in the table | |
3934297e | 812 | * @return TableItem the corresponding table item |
02023181 | 813 | */ |
631d853f PT |
814 | public TableItem getItem(Point point) { |
815 | return fTable.getItem(point); | |
816 | } | |
817 | ||
02023181 MK |
818 | /** |
819 | * Method resize. | |
820 | */ | |
631d853f PT |
821 | private void resize() { |
822 | // Compute the numbers of rows that fit the new area | |
823 | int tableHeight = Math.max(0, getSize().y - fTable.getHeaderHeight()); | |
824 | int itemHeight = getItemHeight(); | |
825 | fTableRows = Math.min((tableHeight + itemHeight - 1) / itemHeight, fTableItemCount); | |
826 | ||
827 | if (fTableTopEventRank + fFullyVisibleRows > fTableItemCount) { | |
828 | // If we are at the end, get elements before to populate | |
829 | fTableTopEventRank = Math.max(0, fTableItemCount - fFullyVisibleRows); | |
830 | refreshTable(); | |
831 | } else if (fTableRows > fTable.getItemCount() || fTableItemCount < fTable.getItemCount()) { | |
832 | // Only refresh if new table items are needed or if table items need to be deleted | |
833 | refreshTable(); | |
834 | } | |
835 | ||
836 | } | |
837 | ||
838 | // ------------------------------------------------------------------------ | |
839 | // Controls interactions | |
840 | // ------------------------------------------------------------------------ | |
841 | ||
02023181 MK |
842 | /** |
843 | * Method setFocus. | |
844 | * @return boolean is this visible? | |
845 | */ | |
631d853f PT |
846 | @Override |
847 | public boolean setFocus() { | |
848 | boolean isVisible = isVisible(); | |
849 | if (isVisible) { | |
850 | fTable.setFocus(); | |
851 | } | |
852 | return isVisible; | |
853 | } | |
854 | ||
02023181 MK |
855 | /** |
856 | * Method refresh. | |
857 | */ | |
631d853f PT |
858 | public void refresh() { |
859 | boolean done = refreshTable(); | |
3f43dc48 PT |
860 | if (!done) { |
861 | return; | |
862 | } | |
dadf6e1a | 863 | if (fPendingSelection) { |
631d853f | 864 | fPendingSelection = false; |
3f43dc48 PT |
865 | TableItem item = null; |
866 | if (fSelectedEventRank >= 0 && fSelectedEventRank < fFrozenRowCount) { | |
867 | item = fTable.getItem(fSelectedEventRank); | |
868 | } else if (fSelectedEventRank >= fTableTopEventRank + fFrozenRowCount && fSelectedEventRank - fTableTopEventRank < fTable.getItemCount()) { | |
869 | item = fTable.getItem(fSelectedEventRank - fTableTopEventRank); | |
870 | } | |
871 | if (item != null) { | |
631d853f | 872 | Event e = new Event(); |
3f43dc48 | 873 | e.item = item; |
631d853f PT |
874 | fTable.notifyListeners(SWT.Selection, e); |
875 | } | |
876 | } | |
877 | } | |
878 | ||
02023181 MK |
879 | /** |
880 | * Method setColumnHeaders. | |
3934297e | 881 | * @param columnData ColumnData[] the columndata array. |
02023181 | 882 | */ |
631d853f PT |
883 | public void setColumnHeaders(ColumnData columnData[]) { |
884 | for (int i = 0; i < columnData.length; i++) { | |
885 | TableColumn column = new TableColumn(fTable, columnData[i].alignment, i); | |
886 | column.setText(columnData[i].header); | |
b06f64b7 PT |
887 | /* |
888 | * In Linux the table does not receive a control resized event when | |
889 | * a table column resize causes the horizontal scroll bar to become | |
890 | * visible or invisible, so a resize listener must be added to every | |
891 | * table column to properly update the number of fully visible rows. | |
892 | */ | |
893 | column.addControlListener(fResizeListener); | |
631d853f PT |
894 | if (columnData[i].width > 0) { |
895 | column.setWidth(columnData[i].width); | |
896 | } else { | |
897 | column.pack(); | |
898 | } | |
899 | } | |
900 | } | |
901 | ||
02023181 MK |
902 | /** |
903 | * Method removeAll. | |
904 | * @return int 0 the number of elements in the table | |
905 | */ | |
631d853f PT |
906 | public int removeAll() { |
907 | setItemCount(0); | |
908 | fSlider.setMaximum(0); | |
909 | fTable.removeAll(); | |
3f43dc48 PT |
910 | fSelectedEventRank = -1; |
911 | fSelectedBeginRank = fSelectedEventRank; | |
631d853f PT |
912 | return 0; |
913 | } | |
914 | ||
02023181 MK |
915 | /** |
916 | * Method refreshTable. | |
3f43dc48 | 917 | * @return true if all table items have been refreshed, false otherwise |
02023181 | 918 | */ |
631d853f PT |
919 | private boolean refreshTable() { |
920 | boolean done = true; | |
921 | for (int i = 0; i < fTableRows; i++) { | |
922 | if (i + fTableTopEventRank < fTableItemCount) { | |
923 | TableItem tableItem; | |
924 | if (i < fTable.getItemCount()) { | |
925 | tableItem = fTable.getItem(i); | |
926 | } else { | |
927 | tableItem = new TableItem(fTable, SWT.NONE); | |
928 | } | |
929 | done &= setDataItem(i, tableItem); // false if table item not updated yet in this thread | |
930 | } else { | |
931 | if (fTable.getItemCount() > fTableItemCount - fTableTopEventRank) { | |
932 | fTable.remove(fTableItemCount - fTableTopEventRank); | |
933 | } | |
934 | } | |
935 | } | |
3f43dc48 PT |
936 | if (done) { |
937 | refreshSelection(); | |
938 | } else { | |
939 | fTable.deselectAll(); | |
940 | } | |
941 | return done; | |
942 | } | |
631d853f | 943 | |
3f43dc48 | 944 | private void refreshSelection() { |
631d853f | 945 | int lastRowOffset = fTableTopEventRank + fTableRows - 1; |
3f43dc48 PT |
946 | int startRank = Math.min(fSelectedBeginRank, fSelectedEventRank); |
947 | int endRank = Math.max(fSelectedBeginRank, fSelectedEventRank); | |
948 | int start = Integer.MAX_VALUE; | |
949 | int end = Integer.MIN_VALUE; | |
950 | if (startRank < fFrozenRowCount) { | |
951 | start = startRank; | |
952 | } else if (startRank < fTableTopEventRank + fFrozenRowCount) { | |
953 | start = fFrozenRowCount; | |
954 | } else if (startRank <= lastRowOffset) { | |
955 | start = startRank - fTableTopEventRank; | |
956 | } | |
957 | if (endRank < fFrozenRowCount) { | |
958 | end = endRank; | |
959 | } else if (endRank < fTableTopEventRank + fFrozenRowCount) { | |
960 | end = fFrozenRowCount - 1; | |
961 | } else if (endRank <= lastRowOffset) { | |
962 | end = endRank - fTableTopEventRank; | |
963 | } else { | |
964 | end = fTableRows - 1; | |
965 | } | |
966 | if (start <= end) { | |
967 | fTable.setSelection(start, end); | |
968 | if (startRank == fSelectedEventRank) { | |
969 | fTable.select(start); | |
970 | } else { | |
971 | fTable.select(end); | |
972 | } | |
631d853f PT |
973 | } else { |
974 | fTable.deselectAll(); | |
975 | } | |
631d853f PT |
976 | } |
977 | ||
02023181 | 978 | /** |
3f43dc48 PT |
979 | * Selects the item at the given zero-relative index in the receiver. |
980 | * The current selection is first cleared, then the new item is selected, | |
981 | * and if necessary the receiver is scrolled to make the new selection visible. | |
982 | * | |
983 | * @param index the index of the item to select | |
984 | * | |
985 | * @exception SWTException <ul> | |
986 | * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
987 | * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
988 | * </ul> | |
02023181 | 989 | */ |
41b5c37f | 990 | public void setSelection(int index) { |
631d853f | 991 | if (fTableItemCount > 0) { |
41b5c37f | 992 | int i = Math.min(index, fTableItemCount - 1); |
631d853f PT |
993 | i = Math.max(i, 0); |
994 | ||
995 | fSelectedEventRank = i; | |
3f43dc48 | 996 | fSelectedBeginRank = fSelectedEventRank; |
631d853f PT |
997 | if ((i < fTableTopEventRank + fFrozenRowCount && i >= fFrozenRowCount) || |
998 | (i >= fTableTopEventRank + fFullyVisibleRows)) { | |
faa38350 PT |
999 | int lastPageTopEntryRank = Math.max(0, fTableItemCount - fFullyVisibleRows); |
1000 | fTableTopEventRank = Math.max(0, Math.min(lastPageTopEntryRank, i - fFrozenRowCount - fFullyVisibleRows / 2)); | |
631d853f PT |
1001 | } |
1002 | if (fFullyVisibleRows < fTableItemCount) { | |
1003 | fSlider.setSelection(fTableTopEventRank); | |
1004 | } | |
1005 | ||
1006 | refreshTable(); | |
631d853f PT |
1007 | } |
1008 | } | |
1009 | ||
02023181 | 1010 | /** |
3f43dc48 PT |
1011 | * Returns the zero-relative index of the item which is currently |
1012 | * selected in the receiver, or -1 if no item is selected. | |
1013 | * | |
1014 | * @return the index of the selected item | |
02023181 | 1015 | */ |
631d853f | 1016 | public int getSelectionIndex() { |
3f43dc48 PT |
1017 | return fSelectedEventRank; |
1018 | } | |
1019 | ||
1020 | /** | |
1021 | * Returns an index array representing the selection range. If there is a | |
1022 | * single item selected the array holds one index. If there is a selected | |
1023 | * range the first item in the array is the start index of the selection and | |
1024 | * the second item is the end index of the selection, which is the item most | |
1025 | * recently selected. The array is empty if no items are selected. | |
1026 | * <p> | |
1027 | * @return the array of indices of the selected items | |
4b121c48 | 1028 | * @since 2.1 |
3f43dc48 PT |
1029 | */ |
1030 | public int[] getSelectionIndices() { | |
1031 | if (fSelectedEventRank < 0 || fSelectedBeginRank < 0) { | |
1032 | return new int[] {}; | |
1033 | } else if (fSelectedEventRank == fSelectedBeginRank) { | |
1034 | return new int[] { fSelectedEventRank }; | |
631d853f | 1035 | } |
3f43dc48 | 1036 | return new int[] { fSelectedBeginRank, fSelectedEventRank }; |
631d853f PT |
1037 | } |
1038 | ||
02023181 MK |
1039 | /** |
1040 | * Method setFrozenRowCount. | |
1041 | * @param count int the number of rows to freeze from the top row | |
1042 | */ | |
631d853f PT |
1043 | public void setFrozenRowCount(int count) { |
1044 | fFrozenRowCount = count; | |
1045 | refreshTable(); | |
1046 | } | |
1047 | ||
02023181 MK |
1048 | /** |
1049 | * Method createTableEditor. | |
1050 | * @return a TableEditor of the table | |
1051 | */ | |
631d853f PT |
1052 | public TableEditor createTableEditor() { |
1053 | return new TableEditor(fTable); | |
1054 | } | |
1055 | ||
02023181 MK |
1056 | /** |
1057 | * Method createTableEditorControl. | |
1058 | * @param control Class<? extends Control> | |
1059 | * @return Control | |
1060 | */ | |
631d853f PT |
1061 | public Control createTableEditorControl(Class<? extends Control> control) { |
1062 | try { | |
420bceb2 | 1063 | return control.getConstructor(Composite.class, int.class).newInstance(new Object[] {fTable, SWT.NONE}); |
631d853f PT |
1064 | } catch (Exception e) { |
1065 | Activator.getDefault().logError("Error creating table editor control", e); //$NON-NLS-1$ | |
1066 | } | |
1067 | return null; | |
1068 | } | |
1069 | ||
1070 | /** | |
1071 | * @return the tooltipProvider | |
02023181 | 1072 | */ |
631d853f PT |
1073 | public TooltipProvider getTooltipProvider() { |
1074 | return tooltipProvider; | |
1075 | } | |
1076 | ||
1077 | /** | |
1078 | * @param tooltipProvider the tooltipProvider to set | |
1079 | */ | |
1080 | public void setTooltipProvider(TooltipProvider tooltipProvider) { | |
1081 | this.tooltipProvider = tooltipProvider; | |
1082 | } | |
1083 | ||
1084 | /** | |
1085 | * @return the doubleClickListener | |
02023181 | 1086 | */ |
631d853f PT |
1087 | public IDoubleClickListener getDoubleClickListener() { |
1088 | return doubleClickListener; | |
1089 | } | |
1090 | ||
1091 | /** | |
1092 | * @param doubleClickListener the doubleClickListener to set | |
1093 | */ | |
1094 | public void setDoubleClickListener(IDoubleClickListener doubleClickListener) { | |
1095 | this.doubleClickListener = doubleClickListener; | |
1096 | } | |
1097 | ||
9ccc6d01 | 1098 | } |