~ubuntu-branches/ubuntu/trusty/eclipse-linuxtools/trusty

« back to all changes in this revision

Viewing changes to lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/virtualtable/TmfVirtualTable.java

  • Committer: Package Import Robot
  • Author(s): tony mancill
  • Date: 2013-05-13 21:43:22 UTC
  • mfrom: (1.2.1) (2.1.2 experimental)
  • Revision ID: package-import@ubuntu.com-20130513214322-6frgd9du1n0w2uo7
Tags: 1.2.1-1
* Team upload.
* New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*******************************************************************************
2
2
 * Copyright (c) 2010 Ericsson
3
 
 * 
 
3
 *
4
4
 * All rights reserved. This program and the accompanying materials are
5
5
 * made available under the terms of the Eclipse Public License v1.0 which
6
6
 * accompanies this distribution, and is available at
7
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 
 * 
 
8
 *
9
9
 * Contributors:
10
10
 *   Matthew Khouzam - Initial API and implementation
11
 
 *   Francois Chouinard - Refactoring, slider support, bug fixing 
 
11
 *   Francois Chouinard - Refactoring, slider support, bug fixing
12
12
 *   Patrick Tasse - Improvements and bug fixing
13
13
 *   Xavier Raynaud - Improvements
14
14
 ******************************************************************************/
52
52
 * <p>
53
53
 * TmfVirtualTable allows for the tabular display of arbitrarily large data sets
54
54
 * (well, up to Integer.MAX_VALUE or ~2G rows).
55
 
 * 
 
55
 *
56
56
 * It is essentially a Composite of Table and Slider, where the number of rows
57
57
 * in the table is set to fill the table display area. The slider is rank-based.
58
 
 * 
 
58
 *
59
59
 * It differs from Table with the VIRTUAL style flag where an empty entry is
60
60
 * created for each virtual row. This does not scale well for very large data sets.
61
 
 * 
 
61
 *
62
62
 * Styles:
63
63
 * H_SCROLL, V_SCROLL, SINGLE, CHECK, FULL_SELECTION, HIDE_SELECTION, NO_SCROLL
64
64
 * @author Matthew Khouzam, Francois Chouinard, Patrick Tasse, Xavier Raynaud
65
 
 * @version $Revision: 1.0 
 
65
 * @version $Revision: 1.0
66
66
 */
67
67
public class TmfVirtualTable extends Composite {
68
68
 
126
126
    // ------------------------------------------------------------------------
127
127
 
128
128
    /**
 
129
     * Standard constructor
 
130
     *
129
131
     * @param parent
 
132
     *            The parent composite object
130
133
     * @param style
 
134
     *            The style to use
131
135
     */
132
136
    public TmfVirtualTable(Composite parent, int style) {
133
137
        super(parent, style & (~SWT.H_SCROLL) & (~SWT.V_SCROLL) & (~SWT.SINGLE) & (~SWT.FULL_SELECTION) & (~SWT.HIDE_SELECTION) & (~SWT.CHECK));
215
219
                case SWT.MouseWheel:
216
220
                    shell.dispose ();
217
221
                    break;
 
222
                default:
 
223
                    break;
218
224
                }
219
225
            }
220
226
        };
247
253
                                }
248
254
                                if (tooltipProvider == null) {
249
255
                                    return;
250
 
                                } else {
251
 
                                    String tooltipText = tooltipProvider.getTooltip(i, item.getData());
252
 
                                    if (tooltipText == null) {
253
 
                                        return;
254
 
                                    }
255
 
                                    tip = new Shell(fTable.getShell(), SWT.ON_TOP | SWT.NO_FOCUS | SWT.TOOL);
256
 
                                    tip.setBackground(PlatformUI.getWorkbench().getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND));
257
 
                                    FillLayout layout = new FillLayout();
258
 
                                    layout.marginWidth = 2;
259
 
                                    tip.setLayout(layout);
260
 
                                    label = new Label(tip, SWT.WRAP);
261
 
                                    label.setForeground(PlatformUI.getWorkbench().getDisplay().getSystemColor(SWT.COLOR_INFO_FOREGROUND));
262
 
                                    label.setBackground(PlatformUI.getWorkbench().getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND));
263
 
                                    label.setData(TOOLTIP_DATA_KEY, item);
264
 
                                    label.setText(tooltipText);
 
256
                                }
 
257
                                String tooltipText = tooltipProvider.getTooltip(i, item.getData());
 
258
                                if (tooltipText == null) {
 
259
                                    return;
 
260
                                }
 
261
                                tip = new Shell(fTable.getShell(), SWT.ON_TOP | SWT.NO_FOCUS | SWT.TOOL);
 
262
                                tip.setBackground(PlatformUI.getWorkbench().getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND));
 
263
                                FillLayout layout = new FillLayout();
 
264
                                layout.marginWidth = 2;
 
265
                                tip.setLayout(layout);
 
266
                                label = new Label(tip, SWT.WRAP);
 
267
                                label.setForeground(PlatformUI.getWorkbench().getDisplay().getSystemColor(SWT.COLOR_INFO_FOREGROUND));
 
268
                                label.setBackground(PlatformUI.getWorkbench().getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND));
 
269
                                label.setData(TOOLTIP_DATA_KEY, item);
 
270
                                label.setText(tooltipText);
265
271
 
266
 
                                    label.addListener(SWT.MouseExit, labelListener);
267
 
                                    label.addListener(SWT.MouseDown, labelListener);
268
 
                                    label.addListener(SWT.MouseWheel, labelListener);
269
 
                                    Point size = tip.computeSize(SWT.DEFAULT, SWT.DEFAULT);
270
 
                                    Point pt = fTable.toDisplay(bounds.x, bounds.y);
271
 
                                    tip.setBounds(pt.x, pt.y, size.x, size.y);
272
 
                                    tip.setVisible(true);
273
 
                                }
274
 
                                break;
 
272
                                label.addListener(SWT.MouseExit, labelListener);
 
273
                                label.addListener(SWT.MouseDown, labelListener);
 
274
                                label.addListener(SWT.MouseWheel, labelListener);
 
275
                                Point size = tip.computeSize(SWT.DEFAULT, SWT.DEFAULT);
 
276
                                Point pt = fTable.toDisplay(bounds.x, bounds.y);
 
277
                                tip.setBounds(pt.x, pt.y, size.x, size.y);
 
278
                                tip.setVisible(true);
275
279
                            }
276
280
                        }
277
281
                    }
 
282
                    break;
278
283
                }
 
284
                default:
 
285
                    break;
279
286
                }
280
287
            }
281
288
        };
398
405
 
399
406
    /**
400
407
     * Handle key-based navigation in table.
401
 
     * 
 
408
     *
402
409
     * @param event
403
410
     */
404
411
    private void handleTableKeyEvent(KeyEvent event) {
422
429
            if (fSelectedEventRank < lastEventRank) {
423
430
                fSelectedEventRank++;
424
431
                selectedRow = fSelectedEventRank - fTableTopEventRank;
425
 
                if (selectedRow >= fFullyVisibleRows) {
 
432
                if (selectedRow == fFullyVisibleRows) {
426
433
                    fTableTopEventRank++;
427
434
                    needsRefresh = true;
 
435
                } else if (selectedRow < fFrozenRowCount || selectedRow > fFullyVisibleRows) {
 
436
                    fTableTopEventRank = Math.max(0, Math.min(fSelectedEventRank - fFrozenRowCount, lastPageTopEntryRank));
 
437
                    needsRefresh = true;
428
438
                }
429
439
            }
430
440
            break;
435
445
            if (fSelectedEventRank > 0) {
436
446
                fSelectedEventRank--;
437
447
                selectedRow = fSelectedEventRank - fTableTopEventRank;
438
 
                if (selectedRow < fFrozenRowCount && fTableTopEventRank > 0) {
 
448
                if (selectedRow == fFrozenRowCount - 1 && fTableTopEventRank > 0) {
439
449
                    fTableTopEventRank--;
440
450
                    needsRefresh = true;
 
451
                } else if (selectedRow < fFrozenRowCount || selectedRow > fFullyVisibleRows) {
 
452
                    fTableTopEventRank = Math.max(0, Math.min(fSelectedEventRank - fFrozenRowCount, lastPageTopEntryRank));
 
453
                    needsRefresh = true;
441
454
                }
442
455
            }
443
456
            break;
467
480
                    fSelectedEventRank = lastEventRank;
468
481
                }
469
482
                selectedRow = fSelectedEventRank - fTableTopEventRank;
470
 
                if (selectedRow > fFullyVisibleRows - 1) {
 
483
                if (selectedRow > fFullyVisibleRows + fFrozenRowCount - 1 && selectedRow < 2 * fFullyVisibleRows) {
471
484
                    fTableTopEventRank += fFullyVisibleRows;
472
485
                    if (fTableTopEventRank > lastPageTopEntryRank) {
473
486
                        fTableTopEventRank = lastPageTopEntryRank;
474
487
                    }
475
488
                    needsRefresh = true;
 
489
                } else if (selectedRow < fFrozenRowCount || selectedRow >= 2 * fFullyVisibleRows) {
 
490
                    fTableTopEventRank = Math.max(0, Math.min(fSelectedEventRank - fFrozenRowCount, lastPageTopEntryRank));
 
491
                    needsRefresh = true;
476
492
                }
477
493
            }
478
494
            break;
486
502
                    fSelectedEventRank = fFrozenRowCount;
487
503
                }
488
504
                selectedRow = fSelectedEventRank - fTableTopEventRank;
489
 
                if (selectedRow < 0) {
 
505
                if (selectedRow < fFrozenRowCount && selectedRow > -fFullyVisibleRows) {
490
506
                    fTableTopEventRank -= fFullyVisibleRows;
491
507
                    if (fTableTopEventRank < 0) {
492
508
                        fTableTopEventRank = 0;
493
509
                    }
494
510
                    needsRefresh = true;
 
511
                } else if (selectedRow <= -fFullyVisibleRows || selectedRow >= fFullyVisibleRows) {
 
512
                    fTableTopEventRank = Math.max(0, Math.min(fSelectedEventRank - fFrozenRowCount, lastPageTopEntryRank));
 
513
                    needsRefresh = true;
495
514
                }
496
515
            }
497
516
            break;
576
595
                    refreshTable();
577
596
                    break;
578
597
                }
 
598
                default:
 
599
                    break;
579
600
                }
580
601
            }
581
602
        });
602
623
    }
603
624
 
604
625
    /**
605
 
     * Method getSelection. 
 
626
     * Method getSelection.
606
627
     * @return TableItem[] the items that are selected.
607
628
     */
608
629
    public TableItem[] getSelection() {
656
677
    }
657
678
 
658
679
    /**
659
 
     * Method clearAll empties a table. 
 
680
     * Method clearAll empties a table.
660
681
     */
661
682
    public void clearAll() {
662
683
        setItemCount(0);
665
686
    /**
666
687
     * Method setItemCount
667
688
     * @param nbItems int the number of items in the table
668
 
         * 
 
689
         *
669
690
     */
670
691
    public void setItemCount(int nbItems) {
671
692
        nbItems = Math.max(0, nbItems);
734
755
 
735
756
    /**
736
757
     * Method setTopIndex.
737
 
     * @param i int suggested top index for the table. 
 
758
     * @param i int suggested top index for the table.
738
759
     */
739
760
    public void setTopIndex(int i) {
740
761
        if (fTableItemCount > 0) {
753
774
    /**
754
775
     * Method indexOf. Return the index of a table item
755
776
     * @param ti TableItem the table item to search for in the table
756
 
     * @return int the index of the first match. (there should only be one match) 
 
777
     * @return int the index of the first match. (there should only be one match)
757
778
     */
758
779
    public int indexOf(TableItem ti) {
759
780
        int index = fTable.indexOf(ti);
760
781
        if (index < fFrozenRowCount) {
761
782
            return index;
762
 
        } else {
763
 
            return (index - fFrozenRowCount) + getTopIndex();
764
783
        }
 
784
        return (index - fFrozenRowCount) + getTopIndex();
765
785
    }
766
786
 
767
787
    /**
768
788
     * Method getColumns.
769
 
     * @return TableColumn[] the table columns 
 
789
     * @return TableColumn[] the table columns
770
790
     */
771
791
    public TableColumn[] getColumns() {
772
792
        return fTable.getColumns();
775
795
    /**
776
796
     * Method getItem.
777
797
     * @param point Point the coordinates in the table
778
 
     * @return TableItem the corresponding table item 
 
798
     * @return TableItem the corresponding table item
779
799
     */
780
800
    public TableItem getItem(Point point) {
781
801
        return fTable.getItem(point);
835
855
 
836
856
    /**
837
857
     * Method setColumnHeaders.
838
 
     * @param columnData ColumnData[] the columndata array. 
 
858
     * @param columnData ColumnData[] the columndata array.
839
859
     */
840
860
    public void setColumnHeaders(ColumnData columnData[]) {
841
861
        for (int i = 0; i < columnData.length; i++) {
863
883
 
864
884
    /**
865
885
     * Method refreshTable.
866
 
     * @return boolean did all the items regresh properly? 
 
886
     * @return boolean did all the items regresh properly?
867
887
     */
868
888
    private boolean refreshTable() {
869
889
        boolean done = true;
899
919
 
900
920
    /**
901
921
     * Method setSelection.
902
 
     * @param i int the item number to select in the table. 
 
922
     * @param i int the item number to select in the table.
903
923
     */
904
924
    public void setSelection(int i) {
905
925
        if (fTableItemCount > 0) {
931
951
        }
932
952
        if (index < fFrozenRowCount) {
933
953
            return index;
934
 
        } else {
935
 
            return (index - fFrozenRowCount) + getTopIndex();
936
954
        }
 
955
        return (index - fFrozenRowCount) + getTopIndex();
937
956
    }
938
957
 
939
958
    /**