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.ebmwebsourcing.petals.services.su.export.SuExportWizardPage.java

License:Open Source License

public void createControl(Composite parent) {

    Composite container = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout(2, false);
    layout.marginHeight = 10;//w ww .ja  va  2  s . com
    layout.marginWidth = 10;
    container.setLayout(layout);
    container.setLayoutData(new GridData(GridData.FILL_BOTH));

    // Project viewer
    Label l = new Label(container, SWT.NONE);
    l.setText("Select the Service Unit project(s) to export:");

    GridData layoutData = new GridData();
    layoutData.horizontalSpan = 2;
    l.setLayoutData(layoutData);

    final TableViewer viewer = new TableViewer(container, SWT.BORDER | SWT.CHECK);
    layoutData = new GridData(GridData.FILL_BOTH);
    layoutData.heightHint = 140;
    layoutData.widthHint = 440;
    layoutData.horizontalSpan = 2;

    viewer.getTable().setLayoutData(layoutData);
    viewer.setLabelProvider(new WorkbenchLabelProvider());
    viewer.setContentProvider(new ArrayContentProvider());
    viewer.setInput(this.suProjects.keySet());

    for (TableItem item : viewer.getTable().getItems()) {
        IProject p = (IProject) item.getData();
        if (this.suProjects.get(p))
            item.setChecked(true);
    }

    viewer.getTable().addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event event) {

            boolean checked = ((TableItem) event.item).getChecked();
            IProject p = (IProject) ((TableItem) event.item).getData();
            SuExportWizardPage.this.suProjects.put(p, checked);
            validate();
        }
    });

    // Export options
    final Composite exportComposite = new Composite(container, SWT.SHADOW_ETCHED_OUT);
    layout = new GridLayout(2, false);
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    exportComposite.setLayout(layout);

    layoutData = new GridData(GridData.FILL_HORIZONTAL);
    layoutData.verticalIndent = 17;
    layoutData.horizontalSpan = 2;
    exportComposite.setLayoutData(layoutData);

    l = new Label(exportComposite, SWT.NONE);
    l.setText("Export mode:");

    final Combo exportCombo = new Combo(exportComposite, SWT.SINGLE | SWT.BORDER | SWT.READ_ONLY);
    exportCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    exportCombo.setItems(new String[] { "Distinct export, in a same directory",
            "Distinct export, in the project directories", "All-in-one export, in a same service assembly" });

    this.lastLabel = new Label(exportComposite, SWT.NONE);
    exportCombo.addSelectionListener(new SelectionListener() {
        public void widgetSelected(SelectionEvent e) {
            widgetDefaultSelected(e);
        }

        public void widgetDefaultSelected(SelectionEvent e) {

            // Get the export type
            int selectionIndex = exportCombo.getSelectionIndex();

            // Delete the last two widgets
            boolean found = false;
            if (SuExportWizardPage.this.lastLabel != null) {
                for (Control control : exportComposite.getChildren()) {
                    if (found)
                        control.dispose();
                    else
                        found = control.equals(SuExportWizardPage.this.lastLabel);
                }
            }

            // Add new widgets - separate, external directory
            if (selectionIndex == 0) {
                SuExportWizardPage.this.exportMode = SuExportMode.SEPARATE_IN_DIRECTORY;
                SuExportWizardPage.this.lastLabel.setVisible(true);
                SuExportWizardPage.this.lastLabel.setText("Output directory:");

                Composite subContainer = new Composite(exportComposite, SWT.NONE);
                GridLayout layout = new GridLayout(2, false);
                layout.marginWidth = 0;
                layout.marginHeight = 0;
                subContainer.setLayout(layout);
                subContainer.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

                final Text dirText = new Text(subContainer, SWT.SINGLE | SWT.BORDER | SWT.READ_ONLY);
                dirText.setBackground(dirText.getDisplay().getSystemColor(SWT.COLOR_WHITE));
                dirText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
                String loc = PetalsServicesPlugin.getDefault().getPreferenceStore()
                        .getString(PREF_DIRECTORY_LOC);
                if (loc.length() != 0) {
                    dirText.setText(loc);
                    SuExportWizardPage.this.outputFile = new File(loc);
                }

                dirText.addModifyListener(new ModifyListener() {
                    public void modifyText(ModifyEvent e) {
                        SuExportWizardPage.this.outputFile = new File(dirText.getText());
                        validate();
                    }
                });

                final Button browseDirButton = new Button(subContainer, SWT.PUSH);
                browseDirButton.setText("Browse...");
                browseDirButton.addSelectionListener(new SelectionListener() {
                    public void widgetSelected(SelectionEvent e) {
                        widgetDefaultSelected(e);
                    }

                    public void widgetDefaultSelected(SelectionEvent e) {
                        DirectoryDialog dlg = new DirectoryDialog(dirText.getShell());
                        dlg.setText("Output Directory");
                        dlg.setMessage("Select the output directory.");
                        if (SuExportWizardPage.this.outputFile != null
                                && SuExportWizardPage.this.outputFile.exists())
                            dlg.setFilterPath(SuExportWizardPage.this.outputFile.getAbsolutePath());

                        String loc = dlg.open();
                        if (loc != null) {
                            dirText.setText(loc);
                            PetalsServicesPlugin.getDefault().getPreferenceStore().setValue(PREF_DIRECTORY_LOC,
                                    loc);
                        }
                    }
                });
            }

            // Separate, project directories
            else if (selectionIndex == 1) {
                SuExportWizardPage.this.exportMode = SuExportMode.SEPARATE_IN_PROJECT;
                SuExportWizardPage.this.lastLabel.setVisible(false);
            }

            // Same SA
            else if (selectionIndex == 2) {
                SuExportWizardPage.this.exportMode = SuExportMode.ALL_IN_ONE;
                SuExportWizardPage.this.lastLabel.setVisible(true);
                SuExportWizardPage.this.lastLabel.setText("Output file:");

                Composite subContainer = new Composite(exportComposite, SWT.NONE);
                GridLayout layout = new GridLayout(2, false);
                layout.marginWidth = 0;
                layout.marginHeight = 0;
                subContainer.setLayout(layout);
                subContainer.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

                final Text fileText = new Text(subContainer, SWT.SINGLE | SWT.BORDER);
                fileText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
                String loc = PetalsServicesPlugin.getDefault().getPreferenceStore().getString(PREF_FILE_LOC);
                if (loc.length() != 0) {
                    fileText.setText(loc);
                    SuExportWizardPage.this.outputFile = new File(loc);
                }

                fileText.addModifyListener(new ModifyListener() {
                    public void modifyText(ModifyEvent e) {
                        SuExportWizardPage.this.outputFile = new File(fileText.getText());
                        validate();
                    }
                });

                final Button browseFileButton = new Button(subContainer, SWT.PUSH);
                browseFileButton.setText("Browse...");
                browseFileButton.addSelectionListener(new SelectionListener() {
                    public void widgetSelected(SelectionEvent e) {
                        widgetDefaultSelected(e);
                    }

                    public void widgetDefaultSelected(SelectionEvent e) {
                        FileDialog dlg = new FileDialog(fileText.getShell());
                        dlg.setText("Target Service Assembly");
                        dlg.setFilterExtensions(new String[] { "*.zip" });
                        dlg.setOverwrite(true);

                        if (SuExportWizardPage.this.outputFile != null) {
                            dlg.setFileName(SuExportWizardPage.this.outputFile.getName());
                            File parentFile = SuExportWizardPage.this.outputFile.getParentFile();
                            if (parentFile != null)
                                dlg.setFilterPath(parentFile.getAbsolutePath());
                        }

                        String loc = dlg.open();
                        if (loc != null) {
                            if (!loc.endsWith(".zip"))
                                loc += ".zip";

                            fileText.setText(loc);
                            PetalsServicesPlugin.getDefault().getPreferenceStore().setValue(PREF_FILE_LOC, loc);
                        }
                    }
                });
            }

            // Refresh the container
            exportComposite.layout();
            validate();
        }
    });

    // Last UI details
    setControl(container);
    viewer.getTable().setFocus();
    exportCombo.select(0);
    exportCombo.notifyListeners(SWT.Selection, new Event());

    String msg = getErrorMessage();
    if (msg != null) {
        setErrorMessage(null);
        setMessage(msg, IMessageProvider.INFORMATION);
    }
}

From source file:com.ebmwebsourcing.petals.services.su.ui.ServiceOperationDialog.java

License:Open Source License

@Override
protected Control createDialogArea(Composite parent) {

    // Create the parent
    Composite bigContainer = (Composite) super.createDialogArea(parent);
    GridLayout layout = new GridLayout();
    layout.marginHeight = 0;//from  w  w w.ja  va2  s.  c om
    bigContainer.setLayout(layout);
    bigContainer.setLayoutData(new GridData(GridData.FILL_BOTH));

    Composite container = new Composite(bigContainer, SWT.NONE);
    container.setLayout(new GridLayout(2, true));
    container.setLayoutData(new GridData(GridData.FILL_BOTH));

    // Put a viewer on the left
    final TableViewer viewer = new TableViewer(container, SWT.BORDER | SWT.SINGLE | SWT.FULL_SELECTION);
    viewer.getTable().setLayoutData(new GridData(GridData.FILL_BOTH));
    viewer.setContentProvider(new ArrayContentProvider());
    viewer.setLabelProvider(new DelegatingStyledCellLabelProvider(new OperationLabelProvider()));
    viewer.setInput(this.opNameToMep.keySet());

    // Add widgets on the right
    Composite rightPart = new Composite(container, SWT.NONE);
    layout = new GridLayout(2, false);
    layout.marginHeight = 0;
    rightPart.setLayout(layout);
    rightPart.setLayoutData(new GridData(GridData.FILL_BOTH));

    final Button customOpButton = new Button(rightPart, SWT.CHECK);
    customOpButton.setText("Define a custom operation");
    GridData layoutData = new GridData();
    layoutData.horizontalSpan = 2;
    customOpButton.setLayoutData(layoutData);

    Label l = new Label(rightPart, SWT.NONE);
    l.setText("Name space:");
    l.setToolTipText("The operation's name space");

    this.nsText = new Text(rightPart, SWT.BORDER | SWT.SINGLE);
    this.nsText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    l = new Label(rightPart, SWT.NONE);
    l.setText("Name:");
    l.setToolTipText("The operation's name");

    this.nameText = new Text(rightPart, SWT.BORDER | SWT.SINGLE);
    this.nameText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    l = new Label(rightPart, SWT.NONE);
    l.setText("MEP:");
    l.setToolTipText("The Message Exchange Pattern");

    this.mepViewer = new ComboViewer(rightPart, SWT.BORDER | SWT.DROP_DOWN | SWT.READ_ONLY);
    this.mepViewer.getCombo().setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    this.mepViewer.setContentProvider(new ArrayContentProvider());
    this.mepViewer.setLabelProvider(new LabelProvider());
    this.mepViewer.setInput(Mep.values());

    // Complete the dialog properties
    getShell().setText("Operation Viewer");
    setTitle("Operation Viewer");
    setMessage("View and edit service operations.");

    // Add the listeners
    customOpButton.addSelectionListener(new SelectionListener() {
        public void widgetSelected(SelectionEvent e) {
            widgetDefaultSelected(e);
        }

        public void widgetDefaultSelected(SelectionEvent e) {

            ServiceOperationDialog.this.useCustomOperation = customOpButton.getSelection();
            ServiceOperationDialog.this.nsText.setEditable(customOpButton.getSelection());
            ServiceOperationDialog.this.nameText.setEditable(customOpButton.getSelection());
            ServiceOperationDialog.this.mepViewer.getCombo().setEnabled(customOpButton.getSelection());
            validate();
        }
    });

    viewer.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            Object o = ((IStructuredSelection) viewer.getSelection()).getFirstElement();
            ServiceOperationDialog.this.nsText.setText(((QName) o).getNamespaceURI());
            ServiceOperationDialog.this.nameText.setText(((QName) o).getLocalPart());

            Mep mep = ServiceOperationDialog.this.opNameToMep.get(o);
            ServiceOperationDialog.this.mepViewer.setSelection(new StructuredSelection(mep));
        }
    });

    customOpButton.setSelection(false);
    customOpButton.notifyListeners(SWT.Selection, new Event());

    ModifyListener modifyListener = new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            if ((((Text) e.widget).getStyle() & SWT.READ_ONLY) == 0)
                validate();
        }
    };

    this.nameText.addModifyListener(modifyListener);
    this.nsText.addModifyListener(modifyListener);
    this.mepViewer.getCombo().addSelectionListener(new SelectionListener() {
        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }

        public void widgetSelected(SelectionEvent e) {
            if (((Combo) e.widget).isEnabled())
                validate();
        }
    });

    return bigContainer;
}

From source file:com.eclipsesource.rowtemplate.demo.RowTemplateDemo.java

License:Open Source License

private void createTable(Composite parent) {
    TableViewer tableViewer = new TableViewer(parent, getStyle());
    exampleControl = tableViewer.getTable();
    tableViewer.setContentProvider(new ArrayContentProvider());
    configColumnViewer(tableViewer);/*from   w w w . ja va  2 s .  c o  m*/
    tableViewer.getTable().setHeaderVisible(headerVisible.getSelection());
    tableViewer.getTable().setLinesVisible(headerVisible.getSelection());
    tableViewer.getTable().addSelectionListener(new SelectionListener(parent));
}

From source file:com.exmaple.e4.tableFunctionality.edit.Snippet027ComboBoxCellEditors.java

License:Open Source License

public Snippet027ComboBoxCellEditors(Shell shell) {
    final Table table = new Table(shell, SWT.BORDER | SWT.FULL_SELECTION);
    final TableViewer v = new TableViewer(table);
    final MyCellModifier modifier = new MyCellModifier(v);

    TableColumn column = new TableColumn(table, SWT.NONE);
    column.setWidth(200);/*from w  ww  .  j  a va  2 s. com*/

    v.setLabelProvider(new LabelProvider());
    v.setContentProvider(ArrayContentProvider.getInstance());
    v.setCellModifier(modifier);
    v.setColumnProperties(new String[] { "column1" });
    v.setCellEditors(new CellEditor[] { new ComboBoxCellEditor(v.getTable(), new String[] { "Zero", "Ten",
            "Twenty", "Thirty", "Fourty", "Fifty", "Sixty", "Seventy", "Eighty", "Ninety" }) });

    v.setInput(createModel());
    v.getTable().setLinesVisible(true);
}

From source file:com.genuitec.eclipse.gerrit.tools.internal.utils.dialogs.TagAndPushDialog.java

License:Open Source License

private void createRepositoriesList(Composite parent) {
    Label l = new Label(parent, SWT.NONE);
    l.setText("List of repositories:");
    l.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 2, 1));

    TableViewer list = new TableViewer(parent, SWT.V_SCROLL + SWT.H_SCROLL + SWT.BORDER);
    list.setLabelProvider(new LabelProvider() {
        private Image img = UIIcons.REPOSITORY.createImage();

        @Override/*from www  .  j  a  va  2s  .com*/
        public Image getImage(Object element) {
            return img;
        }

        @Override
        public void dispose() {
            img.dispose();
        }

        @Override
        public String getText(Object element) {
            return ((Repository) element).getDirectory().getParentFile().getName();
        }
    });
    list.setContentProvider(new ArrayContentProvider());
    list.setInput(repos);
    Table lst = list.getTable();
    GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1);
    gd.heightHint = 200;
    lst.setLayoutData(gd);
}

From source file:com.google.dart.tools.internal.search.ui.text.FileSearchPage.java

License:Open Source License

@Override
protected void configureTableViewer(TableViewer viewer) {
    super.configureTableViewer(viewer);
    viewer.setUseHashlookup(true);/* w w  w . ja va  2  s  .  c o m*/
    FileLabelProvider innerLabelProvider = new FileLabelProvider(this, fCurrentSortOrder);
    viewer.setLabelProvider(new DecoratingFileSearchLabelProvider(innerLabelProvider));
    viewer.setContentProvider(new FileTableContentProvider(this));
    viewer.setComparator(new DecoratorIgnoringViewerSorter(innerLabelProvider));
    fContentProvider = (IFileSearchContentProvider) viewer.getContentProvider();
    addDragAdapters(viewer);
}

From source file:com.google.dart.tools.search.internal.ui.text.FileSearchPage.java

License:Open Source License

@Override
protected void configureTableViewer(TableViewer viewer) {
    viewer.setUseHashlookup(true);/*from  w w w .  j  a  v  a  2 s.c o  m*/
    FileLabelProvider innerLabelProvider = new FileLabelProvider(this, fCurrentSortOrder);
    viewer.setLabelProvider(new DecoratingFileSearchLabelProvider(innerLabelProvider));
    viewer.setContentProvider(new FileTableContentProvider(this));
    viewer.setComparator(new DecoratorIgnoringViewerSorter(innerLabelProvider));
    fContentProvider = (IFileSearchContentProvider) viewer.getContentProvider();
    addDragAdapters(viewer);
}

From source file:com.google.dart.tools.ui.internal.search.DartSearchResultPage.java

License:Open Source License

@Override
protected void configureTableViewer(TableViewer viewer) {
    viewer.setUseHashlookup(true);/*from  ww  w.j av  a  2 s  . c  o m*/
    fSortingLabelProvider = new SortingLabelProvider(this);
    viewer.setLabelProvider(new DecoratingDartLabelProvider(fSortingLabelProvider, false));
    contentProvider = new DartSearchTableContentProvider(this);
    viewer.setContentProvider(contentProvider);
    viewer.setComparator(new DecoratorIgnoringViewerSorter(fSortingLabelProvider));
    setSortOrder(currentSortOrder);
    addDragAdapters(viewer);
}

From source file:com.google.gapid.views.TextureView.java

License:Apache License

private static void initTextureSelector(TableViewer viewer, ImageProvider imageProvider) {
    viewer.setContentProvider(ArrayContentProvider.getInstance());
    viewer.setLabelProvider(new ViewLabelProvider(imageProvider));

    sorting(viewer, createTableColumn(viewer, "Type", Data::getType, Comparator.comparing(Data::getType)),
            createTableColumn(viewer, "ID", Data::getId, d -> imageProvider.getImage(d),
                    (d1, d2) -> UnsignedLongs.compare(d1.getSortId(), d2.getSortId())),
            createTableColumn(viewer, "Name", Data::getLabel, Comparator.comparing(Data::getLabel)),
            createTableColumn(viewer, "Width", Data::getWidth, Comparator.comparingInt(Data::getSortWidth)),
            createTableColumn(viewer, "Height", Data::getHeight, Comparator.comparingInt(Data::getSortHeight)),
            createTableColumn(viewer, "Depth", Data::getDepth, Comparator.comparingInt(Data::getSortDepth)),
            createTableColumn(viewer, "Layers", Data::getLayers, Comparator.comparingInt(Data::getSortLayers)),
            createTableColumn(viewer, "Levels", Data::getLevels, Comparator.comparingInt(Data::getSortLevels)),
            createTableColumn(viewer, "Format", Data::getFormat, Comparator.comparing(Data::getFormat)));
}

From source file:com.hangum.tadpole.rdb.core.editors.main.parameter.ParameterDialog.java

License:Open Source License

/**
 * Create contents of the dialog.//w  ww.  ja  va2  s .  co  m
 * 
 * @param parent
 */
@Override
protected Control createDialogArea(Composite parent) {
    Composite container = (Composite) super.createDialogArea(parent);
    container.setLayout(new GridLayout(1, false));

    Composite composite = new Composite(container, SWT.NONE);
    composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    TableColumnLayout tcl_composite = new TableColumnLayout();
    composite.setLayout(tcl_composite);

    TableViewer tableViewer = new TableViewer(composite,
            SWT.SINGLE | SWT.BORDER | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
    table = tableViewer.getTable();
    table.setHeaderVisible(true);
    table.setLinesVisible(true);

    createTableColumn(tableViewer, tcl_composite);

    tableViewer.setContentProvider(new ArrayContentProvider());
    tableViewer.setLabelProvider(new ParamLabelProvider());
    tableViewer.setInput(parameters);

    tableViewer.refresh();

    //      table.select(0);
    table.setFocus();

    // google analytic
    AnalyticCaller.track(this.getClass().getName());

    return container;
}