Example usage for org.eclipse.jface.viewers TableViewer setContentProvider

List of usage examples for org.eclipse.jface.viewers TableViewer setContentProvider

Introduction

In this page you can find the example usage for org.eclipse.jface.viewers TableViewer setContentProvider.

Prototype

@Override
public void setContentProvider(IContentProvider provider) 

Source Link

Document

Sets the content provider used by this AbstractTableViewer.

Usage

From source file:com.trivadis.loganalysis.ui.ChartCustomizationPanel.java

License:Open Source License

private TableViewer tableSeries(final Composite section, final FormToolkit toolkit) {
    final Table table = toolkit.createTable(section, SWT.NONE);
    table.setLayoutData(new GridDataBuilder().fill().build());
    final TableViewer tableViewer = new TableViewer(table);
    final TableViewerColumn viewerNameColumn = new TableViewerColumn(tableViewer, SWT.NONE);
    viewerNameColumn.getColumn().setWidth(300);

    viewerNameColumn.setLabelProvider(new CellLabelProvider() {
        @Override//from  w w w . j av a 2s  .c  o m
        public void update(final ViewerCell cell) {
            cell.setText(calculateLabel((Serie) cell.getElement()));
        }

        private String calculateLabel(final Serie serie) {
            return serie.getLabel() + " (" + serie.getXaxis().getValueProvider().getLabel() + " / "
                    + serie.getYaxis().getValueProvider().getLabel() + ")";
        }
    });
    tableViewer.setContentProvider(new ObservableListContentProvider());
    tableViewer.setInput(series);
    return tableViewer;
}

From source file:com.vectrace.MercurialEclipse.search.MercurialTextSearchResultPage.java

License:Open Source License

@Override
protected void configureTableViewer(TableViewer viewer) {
    viewer.setUseHashlookup(true);//www  . j av  a 2  s .c  om
    contentProvider = new MercurialTextSearchTableContentProvider(this);
    viewer.setContentProvider(contentProvider);
    MercurialTextSearchTableLabelProvider innerLabelProvider = new MercurialTextSearchTableLabelProvider(this,
            MercurialTextSearchTreeLabelProvider.SHOW_LABEL);
    viewer.setLabelProvider(new DecoratingMercurialTextSearchLabelProvider(innerLabelProvider));
}

From source file:com.windowtester.test.locator.swt.shells.TableCellTestShell.java

License:Open Source License

private void attachContentProvider(TableViewer viewer) {
    viewer.setContentProvider(new IStructuredContentProvider() {
        public Object[] getElements(Object inputElement) {
            return (Object[]) inputElement;
        }/*from ww  w.j a v  a 2 s. c  o m*/

        public void dispose() {
        }

        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
        }
    });
}

From source file:cz.kpartl.Snippet031TableViewerCustomTooltipsMultiSelection.java

License:Open Source License

public Snippet031TableViewerCustomTooltipsMultiSelection(Shell shell) {
    final Table table = new Table(shell, SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI | SWT.FULL_SELECTION);
    table.setHeaderVisible(true);/*w w w  .jav  a  2  s .c  om*/
    table.setLinesVisible(true);

    final TableViewer v = new TableViewer(table);
    TableColumn tableColumn1 = new TableColumn(table, SWT.NONE);
    TableColumn tableColumn2 = new TableColumn(table, SWT.NONE);

    String column1 = "Column 1", column2 = "Column 2";
    /* Setup the table  columns */
    tableColumn1.setText(column1);
    tableColumn2.setText(column2);
    tableColumn1.pack();
    tableColumn2.pack();

    v.setColumnProperties(new String[] { column1, column2 });
    v.setLabelProvider(new MyLableProvider());
    v.setContentProvider(new ArrayContentProvider());
    v.setInput(createModel());

    /**
      * The listener that gets added to the table.  This listener is responsible for creating the tooltips
      * when hovering over a cell item. This listener will listen for the following events:
      *  <li>SWT.KeyDown      - to remove the tooltip</li>
      *  <li>SWT.Dispose      - to remove the tooltip</li>
      *  <li>SWT.MouseMove   - to remove the tooltip</li>
      *  <li>SWT.MouseHover   - to set the tooltip</li>
      */
    Listener tableListener = new Listener() {
        Shell tooltip = null;
        Label label = null;

        /*
         * (non-Javadoc)
         * @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Event)
         */
        public void handleEvent(Event event) {
            switch (event.type) {
            case SWT.KeyDown:
            case SWT.Dispose:
            case SWT.MouseMove: {
                if (tooltip == null)
                    break;
                tooltip.dispose();
                tooltip = null;
                label = null;
                break;
            }
            case SWT.MouseHover: {
                Point coords = new Point(event.x, event.y);
                TableItem item = table.getItem(coords);
                if (item != null) {
                    int columnCount = table.getColumnCount();
                    for (int columnIndex = 0; columnIndex < columnCount; columnIndex++) {
                        if (item.getBounds(columnIndex).contains(coords)) {
                            /* Dispose of the old tooltip (if one exists */
                            if (tooltip != null && !tooltip.isDisposed())
                                tooltip.dispose();

                            /* Create a new Tooltip */
                            tooltip = new Shell(table.getShell(), SWT.ON_TOP | SWT.NO_FOCUS | SWT.TOOL);
                            tooltip.setBackground(table.getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND));
                            FillLayout layout = new FillLayout();
                            layout.marginWidth = 2;
                            tooltip.setLayout(layout);
                            label = new Label(tooltip, SWT.NONE);
                            label.setForeground(table.getDisplay().getSystemColor(SWT.COLOR_INFO_FOREGROUND));
                            label.setBackground(table.getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND));

                            /* Store the TableItem with the label so we can pass the mouse event later */
                            label.setData("_TableItem_", item);

                            /* Set the tooltip text */
                            label.setText("Tooltip: " + item.getData() + " : " + columnIndex);

                            /* Setup Listeners to remove the tooltip and transfer the received mouse events */
                            label.addListener(SWT.MouseExit, tooltipLabelListener);
                            label.addListener(SWT.MouseDown, tooltipLabelListener);

                            /* Set the size and position of the tooltip */
                            Point size = tooltip.computeSize(SWT.DEFAULT, SWT.DEFAULT);
                            Rectangle rect = item.getBounds(columnIndex);
                            Point pt = table.toDisplay(rect.x, rect.y);
                            tooltip.setBounds(pt.x, pt.y, size.x, size.y);

                            /* Show it */
                            tooltip.setVisible(true);
                            break;
                        }
                    }
                }
            }
            }
        }
    };

    table.addListener(SWT.Dispose, tableListener);
    table.addListener(SWT.KeyDown, tableListener);
    table.addListener(SWT.MouseMove, tableListener);
    table.addListener(SWT.MouseHover, tableListener);
}

From source file:de.blizzy.backup.ErrorsDialog.java

License:Open Source License

@Override
protected Control createDialogArea(Composite parent) {
    Composite composite = (Composite) super.createDialogArea(parent);
    ((GridLayout) composite.getLayout()).numColumns = 1;

    TableViewer viewer = new TableViewer(composite,
            SWT.SINGLE | SWT.FULL_SELECTION | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
    viewer.setContentProvider(new ErrorsContentProvider());
    viewer.setLabelProvider(new ErrorsLabelProvider(parent.getDisplay()));

    Table table = viewer.getTable();/*from   ww w  . j  ava2 s.c  om*/
    TableLayout layout = new TableLayout();
    table.setLayout(layout);
    table.setHeaderVisible(true);
    table.setLinesVisible(true);
    GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
    gd.widthHint = convertWidthInCharsToPixels(80);
    gd.heightHint = convertHeightInCharsToPixels(15);
    table.setLayoutData(gd);

    TableColumn col = new TableColumn(table, SWT.LEFT);
    col.setText(Messages.Title_Date);
    layout.addColumnData(new ColumnPixelData(convertWidthInCharsToPixels(16) + 20, true));

    col = new TableColumn(table, SWT.LEFT);
    col.setText(Messages.Title_FileOrFolder);
    layout.addColumnData(new ColumnWeightData(40, true));

    col = new TableColumn(table, SWT.LEFT);
    col.setText(Messages.Title_Error);
    layout.addColumnData(new ColumnWeightData(40, true));

    viewer.setInput(errors);

    return composite;
}

From source file:de.defmacro.dandelion.internal.preferences.LispServerPreferencePage.java

License:Open Source License

private void setTableProvider(final TableViewer viewer, LispEvalServerLabelProvider labelProvider) {
    viewer.setContentProvider(new IStructuredContentProvider() {
        public Object[] getElements(final Object inputElement) {
            return getCurrentServerList().toArray();
        }//from   w ww  . j a  v  a  2 s.co  m

        public void inputChanged(final Viewer viewer, final Object oldInput, final Object newInput) {
            //no-op
        }

        public void dispose() {
            //no-op
        }
    });
    viewer.setInput(new Object());
    viewer.setLabelProvider(labelProvider);
}

From source file:de.fkoeberle.autocommit.message.ui.AdvancedPage.java

License:Open Source License

/**
 * Create contents of the editor part.//from w  w w.ja  va 2 s .c o  m
 * 
 * @param parent
 */
@Override
public void createFormContent(IManagedForm managedForm) {
    super.createFormContent(managedForm);
    FormToolkit toolkit = managedForm.getToolkit();
    ScrolledForm scrolledForm = managedForm.getForm();
    Composite body = scrolledForm.getBody();
    toolkit.decorateFormHeading(scrolledForm.getForm());
    toolkit.paintBordersFor(body);

    scrolledForm.setText("Advanced");
    Composite parent = scrolledForm.getBody();
    parent.setLayout(new FillLayout(SWT.HORIZONTAL));
    Composite container = toolkit.createComposite(parent);
    container.setLayout(new GridLayout(1, false));

    Composite header = toolkit.createComposite(container);
    header.setLayout(new GridLayout(2, false));

    Label generateLabel = toolkit.createLabel(header, "Generate:");
    generateLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));

    final ComboViewer comboViewer = new ComboViewer(header, SWT.READ_ONLY);
    final Combo combo = comboViewer.getCombo();
    toolkit.adapt(combo, true, true);

    GridData comboLayoutData = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
    comboLayoutData.widthHint = 315;
    combo.setLayoutData(comboLayoutData);
    comboViewer.addSelectionChangedListener(new ComboSelectionListener(combo, comboViewer));

    comboViewer.setContentProvider(new ObservableListContentProvider());
    comboViewer.setLabelProvider(new DefaultProfileLabelProvider());
    comboViewer.setInput(model.getProfiles());

    ProfileComboBoxUpdater profileComboBoxUpdater = new ProfileComboBoxUpdater(comboViewer);
    model.addCurrentProfileListener(new ProfileComboBoxUpdater(comboViewer));
    profileComboBoxUpdater.currentProfileChanged();

    SashForm sashForm = new SashForm(container, SWT.NONE);
    sashForm.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    toolkit.adapt(sashForm, false, false);

    Section leftSection = managedForm.getToolkit().createSection(sashForm, Section.TWISTIE | Section.TITLE_BAR);
    managedForm.getToolkit().paintBordersFor(leftSection);
    leftSection.setText("Used commit message factories:");

    Composite leftComposite = managedForm.getToolkit().createComposite(leftSection, SWT.NONE);
    managedForm.getToolkit().paintBordersFor(leftComposite);
    leftSection.setClient(leftComposite);
    leftComposite.setLayout(new GridLayout(1, false));

    final TableViewer usedFactoriesTableViewer = new TableViewer(leftComposite, SWT.BORDER | SWT.MULTI);
    usedFactoriesTable = usedFactoriesTableViewer.getTable();
    usedFactoriesTable.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    usedFactoriesTableViewer.setContentProvider(new ObservableListContentProvider());
    usedFactoriesTableViewer.setLabelProvider(new FactoryLabelProvider());
    usedFactoriesTableViewer.setInput(model.getFactoryDescriptions());

    Section middleSection = managedForm.getToolkit().createSection(sashForm,
            Section.TWISTIE | Section.TITLE_BAR);
    managedForm.getToolkit().paintBordersFor(middleSection);
    middleSection.setText("Unused commit message factories:");

    Composite middleComposite = managedForm.getToolkit().createComposite(middleSection, SWT.NONE);
    managedForm.getToolkit().paintBordersFor(middleComposite);
    middleSection.setClient(middleComposite);
    middleComposite.setLayout(new GridLayout(1, false));

    TableViewer unusedFactoriesTableViewer = new TableViewer(middleComposite, SWT.BORDER | SWT.MULTI);
    unusedFactoriesTable = unusedFactoriesTableViewer.getTable();
    unusedFactoriesTable.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    unusedFactoriesTableViewer.setContentProvider(new ObservableListContentProvider());
    unusedFactoriesTableViewer.setLabelProvider(new FactoryLabelProvider());
    unusedFactoriesTableViewer.setInput(model.getUnusedFactoryDescriptions());

    addDragAndDropSupport(usedFactoriesTableViewer, unusedFactoriesTableViewer);

    usedFactoriesTableViewer.addSelectionChangedListener(new FactoriesSelectionListener(CMFList.USED,
            usedFactoriesTableViewer, unusedFactoriesTableViewer, toolkit));
    unusedFactoriesTableViewer.addSelectionChangedListener(new FactoriesSelectionListener(CMFList.UNUSED,
            unusedFactoriesTableViewer, usedFactoriesTableViewer, toolkit));

    Section rightSection = managedForm.getToolkit().createSection(sashForm,
            Section.TWISTIE | Section.TITLE_BAR);
    managedForm.getToolkit().paintBordersFor(rightSection);
    rightSection.setText("Selected commit message factories:");

    Composite rightComposite = managedForm.getToolkit().createComposite(rightSection, SWT.NONE);
    managedForm.getToolkit().paintBordersFor(rightComposite);
    rightSection.setClient(rightComposite);
    rightComposite.setLayout(new GridLayout(1, false));

    final ScrolledComposite scrolledComposite = new ScrolledComposite(rightComposite,
            SWT.V_SCROLL | SWT.BORDER);
    scrolledComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    toolkit.adapt(scrolledComposite);
    factoriesComposite = new Composite(scrolledComposite, SWT.NONE);
    scrolledComposite.setContent(factoriesComposite);
    toolkit.adapt(factoriesComposite);
    GridLayout layout = new GridLayout();
    layout.numColumns = 1;
    factoriesComposite.setLayout(layout);
    scrolledComposite.addControlListener(new ControlAdapter() {
        @Override
        public void controlResized(ControlEvent e) {
            Rectangle r = scrolledComposite.getClientArea();
            factoriesComposite.setSize(factoriesComposite.computeSize(r.width, SWT.DEFAULT));
            factoriesComposite.layout();
        }
    });
    scrolledComposite.setAlwaysShowScrollBars(true);
    sashForm.setWeights(new int[] { 180, 180, 350 });
    /*
     * Expand after generating it's content so that content gets properly
     * shown:
     */
    leftSection.setExpanded(true);
    middleSection.setExpanded(true);
    rightSection.setExpanded(true);
}

From source file:de.loskutov.eclipseskins.ui.ClosedPartListControl.java

License:Open Source License

protected void configureTableViewer(TableViewer tableViewer) {
    tableViewer.setContentProvider(new BasicStackListContentProvider());
    tableViewer.setSorter(new BasicStackListViewerSorter());
    tableViewer.setLabelProvider(new BasicStackListLabelProvider());
}

From source file:de.marw.cdt.cmake.core.ui.DefinesViewer.java

License:Open Source License

private TableViewer createViewer(Composite parent) {
    TableViewer viewer = new TableViewer(parent,
            SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI | SWT.FULL_SELECTION);

    createColumns(parent, viewer);/*w  ww . j av a2  s. c  o  m*/

    final Table table = viewer.getTable();
    table.setHeaderVisible(true);
    table.setLinesVisible(true);

    viewer.setContentProvider(new CmakeDefineTableContentProvider());
    viewer.setLabelProvider(new CmakeVariableLabelProvider());

    // Layout the viewer
    GridData gridData = new GridData();
    gridData.verticalAlignment = GridData.FILL;
    //    gridData.horizontalSpan = 2;
    gridData.grabExcessHorizontalSpace = true;
    gridData.grabExcessVerticalSpace = true;
    gridData.horizontalAlignment = GridData.FILL;
    viewer.getControl().setLayoutData(gridData);
    return viewer;
}

From source file:de.marw.cdt.cmake.core.ui.UnDefinesViewer.java

License:Open Source License

private TableViewer createViewer(Composite parent) {
    TableViewer viewer = new TableViewer(parent,
            SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI | SWT.FULL_SELECTION);

    createColumns(parent, viewer);/*from   w  ww.ja v  a 2 s.c  om*/

    final Table table = viewer.getTable();
    table.setHeaderVisible(true);
    table.setLinesVisible(true);

    viewer.setContentProvider(new CmakeUnDefineTableContentProvider());
    viewer.setLabelProvider(new CmakeVariableLabelProvider());

    //    // make the selection available to other views
    //    getSite().setSelectionProvider(tableViewer);

    // Layout the viewer
    GridData gridData = new GridData();
    gridData.verticalAlignment = GridData.FILL;
    //    gridData.horizontalSpan = 2;
    gridData.grabExcessHorizontalSpace = true;
    gridData.grabExcessVerticalSpace = true;
    gridData.horizontalAlignment = GridData.FILL;
    viewer.getControl().setLayoutData(gridData);
    return viewer;
}