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:org.eclipse.linuxtools.internal.docker.ui.launch.RunImageEnvironmentTab.java

License:Open Source License

private TableViewer createEnvironmentVariablesTable(Composite container) {
    final Table table = new Table(container, SWT.BORDER | SWT.FULL_SELECTION | SWT.V_SCROLL | SWT.H_SCROLL);
    final TableViewer tableViewer = new TableViewer(table);
    table.setHeaderVisible(true);// ww w .  ja  v a  2 s .  c o m
    table.setLinesVisible(true);
    addTableViewerColumn(tableViewer, WizardMessages.getString("ImageRunResourceVolVarPage.nameColumn"), //$NON-NLS-1$
            200);
    addTableViewerColumn(tableViewer, WizardMessages.getString("ImageRunResourceVolVarPage.valueColumn"), //$NON-NLS-1$
            200);
    tableViewer.setContentProvider(new ObservableListContentProvider());
    return tableViewer;
}

From source file:org.eclipse.linuxtools.internal.docker.ui.launch.RunImageLabelsTab.java

License:Open Source License

private TableViewer createLabelVariablesTable(Composite container) {
    final Table table = new Table(container, SWT.BORDER | SWT.FULL_SELECTION | SWT.V_SCROLL | SWT.H_SCROLL);
    final TableViewer tableViewer = new TableViewer(table);
    table.setHeaderVisible(true);//  w ww  .  j  av  a  2  s .c  o  m
    table.setLinesVisible(true);
    addTableViewerColumn(tableViewer, WizardMessages.getString("ImageRunResourceVolVarPage.nameColumn"), //$NON-NLS-1$
            200);
    addTableViewerColumn(tableViewer, WizardMessages.getString("ImageRunResourceVolVarPage.valueColumn"), //$NON-NLS-1$
            200);
    tableViewer.setContentProvider(new ObservableListContentProvider());
    return tableViewer;
}

From source file:org.eclipse.linuxtools.internal.docker.ui.launch.RunImageLinksTab.java

License:Open Source License

private TableViewer createLinksTable(final Composite container) {
    final Table table = new Table(container, SWT.BORDER | SWT.FULL_SELECTION | SWT.V_SCROLL | SWT.H_SCROLL);
    final TableViewer tableViewer = new TableViewer(table);
    table.setHeaderVisible(true);//from  w  w  w.j  a  va  2 s.  c om
    table.setLinesVisible(true);
    createTableViewerColumn(tableViewer, WizardMessages.getString("ImageRunSelectionPage.containerNameColumn"), //$NON-NLS-1$
            200);
    createTableViewerColumn(tableViewer, WizardMessages.getString("ImageRunSelectionPage.aliasColumn"), //$NON-NLS-1$
            150);
    tableViewer.setContentProvider(new ObservableListContentProvider());
    return tableViewer;
}

From source file:org.eclipse.linuxtools.internal.docker.ui.wizards.ImageSearchPage.java

License:Open Source License

@Override
public void createControl(final Composite parent) {
    final int COLUMNS = 3;
    final Composite container = new Composite(parent, SWT.NONE);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).span(1, 1).grab(true, false).applyTo(container);
    GridLayoutFactory.fillDefaults().numColumns(COLUMNS).margins(6, 6).spacing(10, 2).applyTo(container);
    // search text
    final Label searchImageLabel = new Label(container, SWT.NONE);
    searchImageLabel.setText(WizardMessages.getString("ImageSearchPage.imageLabel")); //$NON-NLS-1$
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, false).applyTo(searchImageLabel);
    final Text searchImageText = new Text(container,
            SWT.BORDER | SWT.SEARCH | SWT.ICON_SEARCH | SWT.ICON_CANCEL);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(searchImageText);
    searchImageText.addKeyListener(onKeyPressed());
    searchImageText.addTraverseListener(onSearchImageTextTraverse());
    final Button searchImageButton = new Button(container, SWT.NONE);
    searchImageButton.setText(WizardMessages.getString("ImageSearchPage.search")); //$NON-NLS-1$
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, false).applyTo(searchImageButton);
    searchImageButton.addSelectionListener(onSearchImageButtonSelected());
    // result table
    final Label searchResultLabel = new Label(container, SWT.NONE);
    searchResultLabel.setText(WizardMessages.getString("ImageSearchPage.searchResultLabel")); //$NON-NLS-1$
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).span(COLUMNS, 1)
            .applyTo(searchResultLabel);
    final Table table = new Table(container, SWT.BORDER | SWT.FULL_SELECTION | SWT.V_SCROLL | SWT.H_SCROLL);
    final TableViewer searchResultTableViewer = new TableViewer(table);
    table.setHeaderVisible(true);//  w  ww . j ava  2  s. c  om
    table.setLinesVisible(true);
    addTableViewerColum(searchResultTableViewer, WizardMessages.getString("ImageSearchPage.nameColumn"), //$NON-NLS-1$
            SWT.NONE, SWT.RIGHT, 290, new ImageNameColumnLabelProvider());
    addTableViewerColum(searchResultTableViewer, WizardMessages.getString("ImageSearchPage.starsColumn"), //$NON-NLS-1$
            SWT.NONE, SWT.RIGHT, 70, new ImageStarsColumnLabelProvider());
    addTableViewerColum(searchResultTableViewer, WizardMessages.getString("ImageSearchPage.officialColumn"), //$NON-NLS-1$
            SWT.NONE, SWT.CENTER, 70, new ImageOfficialColumnLabelProvider());
    addTableViewerColum(searchResultTableViewer, WizardMessages.getString("ImageSearchPage.automatedColumn"), //$NON-NLS-1$
            SWT.NONE, SWT.CENTER, 70, new ImageAutomatedColumnLabelProvider());
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).span(COLUMNS, 1).hint(200, 100)
            .applyTo(table);
    // description text area
    final Group selectedImageDescriptionGroup = new Group(container, SWT.BORDER);
    selectedImageDescriptionGroup.setText(WizardMessages.getString("ImageSearchPage.descriptionGroup")); //$NON-NLS-1$
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, true).span(COLUMNS, 1)
            .applyTo(selectedImageDescriptionGroup);
    GridLayoutFactory.fillDefaults().margins(6, 6).spacing(10, 2).applyTo(selectedImageDescriptionGroup);
    final Label selectedImageDescription = new Label(selectedImageDescriptionGroup, SWT.WRAP);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, true).hint(200, 100)
            .applyTo(selectedImageDescription);
    // bind the search term
    final IObservableValue observableTermModel = BeanProperties
            .value(ImageSearchModel.class, ImageSearchModel.TERM).observe(model);
    final ISWTObservableValue imageSearchTextObservable = WidgetProperties.text(SWT.Modify)
            .observe(searchImageText);
    ctx.bindValue(imageSearchTextObservable, observableTermModel,
            new UpdateValueStrategy().setBeforeSetValidator(new SearchTermValidator(searchImageButton)), null);
    // observe the viewer content
    searchResultTableViewer.setContentProvider(new ObservableListContentProvider());
    // observe the viewer content
    final IObservableList observableSearchResultModel = BeanProperties
            .list(ImageSearchModel.class, ImageSearchModel.IMAGE_SEARCH_RESULT).observe(model);
    searchResultTableViewer.setInput(observableSearchResultModel);

    // observe the viewer selection
    ctx.bindValue(ViewerProperties.singleSelection().observe(searchResultTableViewer),
            BeanProperties.value(ImageSearchModel.SELECTED_IMAGE).observe(model));
    // observe the viewer selection to update the description label
    final IObservableValue observableSelectedImageDescription = PojoProperties
            .value("description", String.class) // $NON-NLS-1$
            .observeDetail(ViewerProperties.singleSelection().observe(searchResultTableViewer));
    ctx.bindValue(WidgetProperties.text().observe(selectedImageDescription),
            observableSelectedImageDescription);
    searchImageText.setFocus();
    // attach the Databinding context status to this wizard page.
    WizardPageSupport.create(this, this.ctx);
    setControl(container);
    // trigger a search if an image name was provided
    if (model.getTerm() != null && !model.getTerm().isEmpty()) {
        searchImages();
    }
}

From source file:org.eclipse.linuxtools.internal.docker.ui.wizards.ImageTagSelectionPage.java

License:Open Source License

@Override
public void createControl(final Composite parent) {
    final int COLUMNS = 1;
    final Composite container = new Composite(parent, SWT.NONE);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).span(1, 1).grab(true, false).applyTo(container);
    GridLayoutFactory.fillDefaults().numColumns(COLUMNS).margins(6, 6).spacing(10, 2).applyTo(container);

    // tags/layers table
    final Table table = new Table(container, SWT.BORDER | SWT.FULL_SELECTION | SWT.V_SCROLL | SWT.H_SCROLL);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).span(COLUMNS, 1).hint(200, 200)
            .applyTo(table);//  w  w  w.ja  va2s .  co m
    final TableViewer tableViewer = new TableViewer(table);
    table.setHeaderVisible(true);
    table.setLinesVisible(true);
    addTableViewerColum(tableViewer, WizardMessages.getString("ImageTagSelectionPage.column.tag"), //$NON-NLS-1$
            SWT.NONE, SWT.LEFT, 200, new RepositoryTagColumnLabelProvider());
    addTableViewerColum(tableViewer, WizardMessages.getString("ImageTagSelectionPage.column.layer"), //$NON-NLS-1$
            SWT.NONE, SWT.LEFT, 200, new RepositoryLayerColumnLabelProvider());
    addTableViewerColum(tableViewer, WizardMessages.getString("ImageTagSelectionPage.column.localcopy"), //$NON-NLS-1$
            SWT.NONE, SWT.LEFT, 75, new ImagePulledColumnLabelProvider());
    tableViewer.setContentProvider(new ObservableListContentProvider());
    // observe the viewer content
    final IObservableList observableSearchResultModel = BeanProperties
            .list(ImageSearchModel.class, ImageSearchModel.IMAGE_TAG_SEARCH_RESULT).observe(model);
    tableViewer.setInput(observableSearchResultModel);
    // observe the viewer selection
    ctx.bindValue(ViewerProperties.singleSelection().observe(tableViewer),
            BeanProperties.value(ImageSearchModel.SELECTED_IMAGE_TAG).observe(model));
    setControl(container);
}

From source file:org.eclipse.linuxtools.internal.tmf.ui.project.wizards.tracepkg.importexport.ExportTracePackageSelectTraceWizardPage.java

License:Open Source License

@Override
public void createControl(Composite parent) {
    Composite projectSelectionGroup = new Composite(parent, SWT.NONE);
    projectSelectionGroup.setLayout(new GridLayout(2, true));
    projectSelectionGroup.setLayoutData(new GridData(GridData.FILL_BOTH));
    projectSelectionGroup.setFont(parent.getFont());

    Label projectLabel = new Label(projectSelectionGroup, SWT.NONE);
    projectLabel.setText(Messages.ExportTracePackageSelectTraceWizardPage_ProjectSelection);
    projectLabel.setLayoutData(new GridData());

    Label configLabel = new Label(projectSelectionGroup, SWT.NONE);
    configLabel.setText(Messages.ExportTracePackageSelectTraceWizardPage_TraceSelection);
    configLabel.setLayoutData(new GridData());

    final Table projectTable = new Table(projectSelectionGroup, SWT.SINGLE | SWT.BORDER);
    projectTable.setLayoutData(new GridData(GridData.FILL_BOTH));

    TableViewer projectViewer = new TableViewer(projectTable);
    projectViewer.setContentProvider(new TmfNavigatorContentProvider() {

        @Override// w w  w  .  j ava 2  s  .  c om
        public Object[] getElements(Object inputElement) {
            return (IProject[]) inputElement;
        }
    });
    projectViewer.setLabelProvider(new WorkbenchLabelProvider());
    projectViewer.setInput(TraceUtils.getOpenedTmfProjects().toArray(new IProject[] {}));

    fTraceTable = new Table(projectSelectionGroup, SWT.BORDER | SWT.CHECK);
    fTraceTable.setLayoutData(new GridData(GridData.FILL_BOTH));

    final TableViewer traceViewer = new TableViewer(fTraceTable);
    traceViewer.setContentProvider(new IStructuredContentProvider() {
        @Override
        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
        }

        @Override
        public void dispose() {
        }

        @Override
        public Object[] getElements(Object inputElement) {
            if (inputElement instanceof TmfTraceElement[]) {
                return (TmfTraceElement[]) inputElement;
            }
            return null;
        }
    });
    traceViewer.setLabelProvider(new ExportLabelProvider());
    fTraceTable.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            getWizard().getContainer().updateButtons();
            updateNextPageData();
        }
    });

    projectTable.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            TableItem[] items = projectTable.getSelection();
            fSelectedProject = (IProject) items[0].getData();

            TmfProjectElement project = TmfProjectRegistry.getProject(fSelectedProject, true);

            TmfTraceFolder tracesFolder = project.getTracesFolder();
            List<TmfTraceElement> traces = tracesFolder.getTraces();
            TmfTraceElement[] array = traces.toArray(new TmfTraceElement[] {});
            traceViewer.setInput(array);
            traceViewer.refresh();
            fTraceTable.select(0);
            fTraceTable.notifyListeners(SWT.Selection, new Event());
            getWizard().getContainer().updateButtons();
        }
    });

    Composite btComp = new Composite(projectSelectionGroup, SWT.NONE);
    btComp.setLayout(new GridLayout(2, true));
    GridData gd = new GridData();
    gd.horizontalSpan = 2;
    gd.horizontalAlignment = SWT.RIGHT;
    btComp.setLayoutData(gd);

    final Button selectAll = new Button(btComp, SWT.PUSH);
    selectAll.setText(org.eclipse.linuxtools.internal.tmf.ui.project.dialogs.Messages.Dialog_SelectAll);
    selectAll.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            TableItem[] items = fTraceTable.getItems();
            for (TableItem item : items) {
                item.setChecked(true);
            }

            getWizard().getContainer().updateButtons();
            updateNextPageData();
        }
    });

    final Button deselectAll = new Button(btComp, SWT.PUSH);
    deselectAll.setText(org.eclipse.linuxtools.internal.tmf.ui.project.dialogs.Messages.Dialog_DeselectAll);
    deselectAll.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            TableItem[] items = fTraceTable.getItems();
            for (TableItem item : items) {
                item.setChecked(false);
            }

            getWizard().getContainer().updateButtons();
            updateNextPageData();
        }
    });

    setControl(projectSelectionGroup);
    setTitle(Messages.ExportTracePackageWizardPage_Title);
    setMessage(Messages.ExportTracePackageSelectTraceWizardPage_ChooseTrace);
}

From source file:org.eclipse.m2e.editor.xml.internal.dialogs.SelectSPDXLicenseDialog.java

License:Open Source License

@Override
protected Control createDialogArea(Composite parent) {
    Composite container = (Composite) super.createDialogArea(parent);

    Label lblLicenseNameFilter = new Label(container, SWT.NONE);
    lblLicenseNameFilter.setText(Messages.SelectSPDXLicenseDialog_lblLicenseNameFilter_text);

    final Text licenseFilter = new Text(container, SWT.BORDER | SWT.SEARCH);
    licenseFilter.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

    Label lblLicenses = new Label(container, SWT.NONE);
    lblLicenses.setText(Messages.SelectSPDXLicenseDialog_lblLicenses_text);

    final TableViewer licensesViewer = new TableViewer(container, SWT.BORDER | SWT.FULL_SELECTION);
    Table licensesTable = licensesViewer.getTable();
    licensesTable.addMouseListener(new MouseAdapter() {
        @Override//from  w w  w .  j a va2  s. com
        public void mouseDoubleClick(MouseEvent e) {
            handleDoubleClick();
        }
    });
    licensesTable.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            ISelection selection = licensesViewer.getSelection();
            if (selection instanceof IStructuredSelection && !selection.isEmpty()) {
                license = (SPDXLicense) ((IStructuredSelection) selection).getFirstElement();
            } else {
                license = null;
            }
            updateStatus();
        }
    });
    GridData gd_licensesTable = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
    gd_licensesTable.heightHint = 400;
    licensesTable.setLayoutData(gd_licensesTable);
    licensesViewer.setContentProvider(new IStructuredContentProvider() {
        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
        }

        public void dispose() {
        }

        public Object[] getElements(Object inputElement) {
            if (inputElement instanceof Collection<?>) {
                return ((Collection<?>) inputElement).toArray();
            }
            return null;
        }
    });
    licensesViewer.setLabelProvider(new ILabelProvider() {
        public void removeListener(ILabelProviderListener listener) {
        }

        public boolean isLabelProperty(Object element, String property) {
            return false;
        }

        public void dispose() {
        }

        public void addListener(ILabelProviderListener listener) {
        }

        public String getText(Object element) {
            if (element instanceof SPDXLicense) {
                return ((SPDXLicense) element).getName();
            }
            return null;
        }

        public Image getImage(Object element) {
            return null;
        }
    });
    licensesViewer.setInput(SPDXLicense.getStandardLicenses());

    licenseFilter.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            String text = licenseFilter.getText();
            ViewerFilter[] filters;
            if (text != null && text.trim().length() > 0) {
                filters = new ViewerFilter[] { new LicenseFilter(text.trim()) };
            } else {
                filters = new ViewerFilter[] {};
            }
            licensesViewer.setFilters(filters);
        }
    });

    Label lblPomxml = new Label(container, SWT.NONE);
    lblPomxml.setText(Messages.SelectSPDXLicenseDialog_lblPomxml_text);

    final PomHierarchyComposite parentComposite = new PomHierarchyComposite(container, SWT.NONE);
    parentComposite.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseDoubleClick(MouseEvent e) {
            handleDoubleClick();
        }
    });
    parentComposite.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            ISelection selection = parentComposite.getSelection();
            if (selection instanceof IStructuredSelection && !selection.isEmpty()) {
                MavenProject mavenProject = (MavenProject) ((IStructuredSelection) selection).getFirstElement();
                targetProject = MavenPlugin.getMavenProjectRegistry().getMavenProject(mavenProject.getGroupId(),
                        mavenProject.getArtifactId(), mavenProject.getVersion());
                updateStatus();
            }
        }
    });
    parentComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    parentComposite.computeHeirarchy(project, null); // FIXME proper progress monitor
    parentComposite.setSelection(new StructuredSelection(parentComposite.getHierarchy().get(0)));

    return container;
}

From source file:org.eclipse.mat.ui.snapshot.views.inspector.InspectorView.java

License:Open Source License

private TableViewer createTable(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    TableColumnLayout columnLayout = new TableColumnLayout();
    composite.setLayout(columnLayout);/*from   w  w  w  . jav a  2 s .c o m*/
    GridDataFactory.fillDefaults().grab(true, true).align(SWT.FILL, SWT.FILL).applyTo(composite);

    final TableViewer viewer = new TableViewer(composite,
            SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.MULTI);
    Table table = viewer.getTable();
    AccessibleCompositeAdapter.access(table);
    viewer.setContentProvider(new FieldsContentProvider());
    viewer.setLabelProvider(new FieldsLabelProvider(this, table.getFont()));

    TableColumn tableColumn = new TableColumn(table, SWT.LEFT);
    tableColumn.setText(Messages.InspectorView_Type);
    tableColumn.setWidth(50);
    columnLayout.setColumnData(tableColumn, new ColumnWeightData(10, 50, false));

    tableColumn = new TableColumn(table, SWT.LEFT);
    tableColumn.setWidth(80);
    tableColumn.setText(Messages.InspectorView_Name);
    columnLayout.setColumnData(tableColumn, new ColumnWeightData(30, 80));

    tableColumn = new TableColumn(table, SWT.LEFT);
    tableColumn.setWidth(250);
    tableColumn.setText(Messages.InspectorView_Value);
    columnLayout.setColumnData(tableColumn, new ColumnWeightData(60, 250, true));

    table.setHeaderVisible(true);

    return viewer;
}

From source file:org.eclipse.mylyn.internal.gerrit.ui.editor.PatchSetSection.java

License:Open Source License

void createSubSectionContents(final ChangeDetail changeDetail, final PatchSetDetail patchSetDetail,
        PatchSetPublishDetail publishDetail, Section subSection) {
    Composite composite = toolkit.createComposite(subSection);
    GridLayoutFactory.fillDefaults().numColumns(2).applyTo(composite);
    subSection.setClient(composite);//from w  w w  . ja va  2s  . c om

    Label authorLabel = new Label(composite, SWT.NONE);
    authorLabel.setForeground(toolkit.getColors().getColor(IFormColors.TITLE));
    authorLabel.setText("Author");

    Text authorText = new Text(composite, SWT.READ_ONLY);
    authorText.setText(GerritUtil.getUserLabel(patchSetDetail.getInfo().getAuthor()));

    Label committerLabel = new Label(composite, SWT.NONE);
    committerLabel.setForeground(toolkit.getColors().getColor(IFormColors.TITLE));
    committerLabel.setText("Committer");

    Text committerText = new Text(composite, SWT.READ_ONLY);
    committerText.setText(GerritUtil.getUserLabel(patchSetDetail.getInfo().getCommitter()));

    Label commitLabel = new Label(composite, SWT.NONE);
    commitLabel.setForeground(toolkit.getColors().getColor(IFormColors.TITLE));
    commitLabel.setText("Commit");

    Hyperlink commitLink = new Hyperlink(composite, SWT.READ_ONLY);
    commitLink.setText(patchSetDetail.getPatchSet().getRevision().get());
    commitLink.addHyperlinkListener(new HyperlinkAdapter() {
        @Override
        public void linkActivated(HyperlinkEvent event) {
            GerritToGitMapping mapping = getRepository(changeDetail);
            if (mapping != null) {
                final FetchPatchSetJob job = new FetchPatchSetJob("Opening Commit Viewer",
                        mapping.getRepository(), mapping.getRemote(), patchSetDetail.getPatchSet());
                job.schedule();
                job.addJobChangeListener(new JobChangeAdapter() {
                    @Override
                    public void done(IJobChangeEvent event) {
                        Display.getDefault().asyncExec(new Runnable() {
                            @Override
                            public void run() {
                                CommitEditor.openQuiet(job.getCommit());
                            }
                        });
                    }
                });
            }
        }
    });

    Label refLabel = new Label(composite, SWT.NONE);
    refLabel.setForeground(toolkit.getColors().getColor(IFormColors.TITLE));
    refLabel.setText("Ref");

    Text refText = new Text(composite, SWT.READ_ONLY);
    refText.setText(patchSetDetail.getPatchSet().getRefName());

    final TableViewer viewer = new TableViewer(composite, SWT.SINGLE | SWT.BORDER | SWT.V_SCROLL | SWT.VIRTUAL);
    GridDataFactory.fillDefaults().span(2, 1).grab(true, true).hint(500, SWT.DEFAULT)
            .applyTo(viewer.getControl());
    viewer.setContentProvider(new IStructuredContentProvider() {
        private EContentAdapter modelAdapter;

        public void dispose() {
            // ignore
        }

        public Object[] getElements(Object inputElement) {
            return getReviewItems(inputElement).toArray();
        }

        private List<IReviewItem> getReviewItems(Object inputElement) {
            if (inputElement instanceof IReviewItemSet) {
                return ((IReviewItemSet) inputElement).getItems();
            }
            return Collections.emptyList();
        }

        public void inputChanged(final Viewer viewer, Object oldInput, Object newInput) {
            if (modelAdapter != null) {
                for (IReviewItem item : getReviewItems(oldInput)) {
                    ((EObject) item).eAdapters().remove(modelAdapter);
                }
                addedDrafts = 0;
            }

            if (newInput instanceof IReviewItemSet) {
                // monitors any new topics that are added
                modelAdapter = new EContentAdapter() {
                    @Override
                    public void notifyChanged(Notification notification) {
                        super.notifyChanged(notification);
                        if (notification.getFeatureID(IReviewItem.class) == ReviewsPackage.REVIEW_ITEM__TOPICS
                                && notification.getEventType() == Notification.ADD) {
                            viewer.refresh();
                            addedDrafts++;
                        }
                    }
                };
                for (Object item : getReviewItems(newInput)) {
                    ((EObject) item).eAdapters().add(modelAdapter);
                }
            }
        }
    });
    viewer.setLabelProvider(new DelegatingStyledCellLabelProvider(new ReviewItemLabelProvider()));
    viewer.addOpenListener(new IOpenListener() {
        public void open(OpenEvent event) {
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            IFileItem item = (IFileItem) selection.getFirstElement();
            if (item != null) {
                doOpen((IReviewItemSet) viewer.getInput(), item);
            }
        }
    });

    IReviewItemSet itemSet = GerritUtil.createInput(changeDetail, new GerritPatchSetContent(patchSetDetail),
            cache);
    viewer.setInput(itemSet);

    Composite actionComposite = createActions(changeDetail, patchSetDetail, publishDetail, composite);
    GridDataFactory.fillDefaults().span(2, 1).applyTo(actionComposite);

    subSectionExpanded(changeDetail, patchSetDetail, subSection, viewer);
    EditorUtil.addScrollListener(viewer.getTable());

    getTaskEditorPage().reflow();
}

From source file:org.eclipse.mylyn.internal.github.ui.gist.GistAttachmentPart.java

License:Open Source License

private void createAttachmentTable(FormToolkit toolkit, final Composite attachmentsComposite) {
    attachmentsTable = toolkit.createTable(attachmentsComposite, SWT.MULTI | SWT.FULL_SELECTION);
    attachmentsTable.setLinesVisible(true);
    attachmentsTable.setHeaderVisible(true);
    attachmentsTable.setLayout(new GridLayout());
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, false).hint(500, SWT.DEFAULT)
            .applyTo(attachmentsTable);/*from  ww w  .  java2s  . c om*/
    attachmentsTable.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TREE_BORDER);

    for (int i = 0; i < attachmentsColumns.length; i++) {
        TableColumn column = new TableColumn(attachmentsTable, SWT.LEFT, i);
        column.setText(attachmentsColumns[i]);
        column.setWidth(attachmentsColumnWidths[i]);
        column.setMoveable(true);
        if (i == 0) {
            attachmentsTable.setSortColumn(column);
            attachmentsTable.setSortDirection(SWT.DOWN);
        }
    }
    // size column
    attachmentsTable.getColumn(1).setAlignment(SWT.RIGHT);

    TableViewer attachmentsViewer = new TableViewer(attachmentsTable);
    attachmentsViewer.setUseHashlookup(true);
    attachmentsViewer.setColumnProperties(attachmentsColumns);
    ColumnViewerToolTipSupport.enableFor(attachmentsViewer, ToolTip.NO_RECREATE);

    attachmentsViewer.setSorter(new GistAttachmentSorter());

    List<ITaskAttachment> attachmentList = new ArrayList<ITaskAttachment>(attachments.size());
    for (TaskAttribute attribute : attachments) {
        ITaskAttachment taskAttachment = new TaskAttachment(getModel().getTaskRepository(),
                getModel().getTask(), attribute);
        getTaskData().getAttributeMapper().updateTaskAttachment(taskAttachment, attribute);
        attachmentList.add(taskAttachment);
    }
    attachmentsViewer.setContentProvider(new ArrayContentProvider());
    attachmentsViewer.setLabelProvider(
            new AttachmentTableLabelProvider(getModel(), getTaskEditorPage().getAttributeEditorToolkit()) {

                public String getColumnText(Object element, int columnIndex) {
                    if (columnIndex > 0)
                        columnIndex++;
                    return super.getColumnText(element, columnIndex);
                }

                public Image getColumnImage(Object element, int columnIndex) {
                    if (columnIndex > 0)
                        columnIndex++;
                    return super.getColumnImage(element, columnIndex);
                }

            });
    attachmentsViewer.addOpenListener(new IOpenListener() {
        public void open(OpenEvent event) {
            openAttachments(event);
        }
    });
    attachmentsViewer.addSelectionChangedListener(getTaskEditorPage());
    attachmentsViewer.setInput(attachmentList.toArray());

    menuManager = new MenuManager();
    menuManager.setRemoveAllWhenShown(true);
    menuManager.addMenuListener(new IMenuListener() {
        public void menuAboutToShow(IMenuManager manager) {
            TasksUiMenus.fillTaskAttachmentMenu(manager);
        }
    });
    getTaskEditorPage().getEditorSite().registerContextMenu(ID_POPUP_MENU, menuManager, attachmentsViewer,
            true);
    Menu menu = menuManager.createContextMenu(attachmentsTable);
    attachmentsTable.setMenu(menu);

    new TableViewerSupport(attachmentsViewer, getStateFile());
}