Search in sources :

Example 91 with IStructuredContentProvider

use of org.eclipse.jface.viewers.IStructuredContentProvider in project xtext-eclipse by eclipse.

the class WizardSelectImportedEPackagePage method createControl.

@Override
public void createControl(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayout(new GridLayout(2, false));
    Label label = new Label(composite, SWT.NONE);
    label.setText(Messages.WizardSelectImportedEPackagePage_ListTitle);
    label.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false, 2, 1));
    importedEPackagesViewer = new TableViewer(composite, SWT.BORDER);
    importedEPackagesViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 3));
    importedEPackagesViewer.setContentProvider(new IStructuredContentProvider() {

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

        @Override
        public void dispose() {
        }

        @Override
        public Object[] getElements(Object inputElement) {
            return Iterables.toArray(ePackageInfos, EPackageInfo.class);
        }
    });
    importedEPackagesViewer.setLabelProvider(new LabelProvider() {

        @Override
        public String getText(Object element) {
            if (element instanceof EPackageInfo) {
                String label = ((EPackageInfo) element).getEPackageJavaFQN();
                if (element == getDefaultEPackageInfo()) {
                    return label + Messages.WizardSelectImportedEPackagePage_DefaultMarker;
                } else {
                    return label;
                }
            }
            return element.toString();
        }
    });
    Button addButton = new Button(composite, SWT.PUSH);
    addButton.setText(Messages.WizardSelectImportedEPackagePage_AddButtonText);
    addButton.setLayoutData(new GridData(SWT.FILL, SWT.BOTTOM, false, false, 1, 1));
    addButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            addEPackageInfos(new EPackageChooser(getShell(), jdtHelper).open());
        }
    });
    Button defaultButton = new Button(composite, SWT.PUSH);
    defaultButton.setText(Messages.WizardSelectImportedEPackagePage_SetDefault);
    defaultButton.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false, 1, 1));
    defaultButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            ISelection selection = importedEPackagesViewer.getSelection();
            if (selection instanceof IStructuredSelection) {
                IStructuredSelection structuredSelection = (IStructuredSelection) selection;
                if (structuredSelection.size() == 1) {
                    Object firstElement = structuredSelection.getFirstElement();
                    if (firstElement instanceof EPackageInfo) {
                        defaultEPackageInfo = (EPackageInfo) firstElement;
                    }
                }
            }
            updateUI();
        }
    });
    Button removeButton = new Button(composite, SWT.PUSH);
    removeButton.setText(Messages.WizardSelectImportedEPackagePage_RemoveButtonText);
    removeButton.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false, 1, 1));
    removeButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            ISelection selection = importedEPackagesViewer.getSelection();
            if (selection instanceof IStructuredSelection) {
                for (Iterator<?> i = ((IStructuredSelection) selection).iterator(); i.hasNext(); ) {
                    Object ePackageInfo = i.next();
                    ePackageInfos.remove(ePackageInfo);
                    if (defaultEPackageInfo == ePackageInfo) {
                        defaultEPackageInfo = null;
                    }
                }
            }
            updateUI();
        }
    });
    Label entryRuleLabel = new Label(composite, SWT.NONE);
    entryRuleLabel.setText(Messages.WizardSelectImportedEPackagePage_entryRuleLabelText);
    entryRuleLabel.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false, 2, 1));
    CCombo rootElementComboBoxCellEditor = new CCombo(composite, SWT.BORDER | SWT.DROP_DOWN | SWT.READ_ONLY);
    GridData layoutData = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
    layoutData.heightHint = 20;
    rootElementComboBoxCellEditor.setLayoutData(layoutData);
    rootElementComboBoxCellEditor.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            validatePage();
        }
    });
    rootElementComboViewer = new ComboViewer(rootElementComboBoxCellEditor);
    rootElementComboViewer.setLabelProvider(new LabelProvider() {

        @Override
        public String getText(Object element) {
            return (element instanceof EClass) ? ((EClass) element).getName() + " - " + ((EClass) element).getEPackage().getName() : super.getText(element);
        }
    });
    rootElementComboViewer.setContentProvider(new IStructuredContentProvider() {

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

        @Override
        public void dispose() {
        }

        @Override
        public Object[] getElements(Object inputElement) {
            Iterable<EClass> eClasses = Iterables.filter(Iterables.concat(Iterables.transform(ePackageInfos, new Function<EPackageInfo, List<EClassifier>>() {

                @Override
                public List<EClassifier> apply(EPackageInfo from) {
                    return from.getEPackage().getEClassifiers();
                }
            })), EClass.class);
            List<EClass> result = Lists.newArrayList(eClasses);
            Collections.sort(result, new Comparator<EClass>() {

                @Override
                public int compare(EClass o1, EClass o2) {
                    return o1.getName().compareTo(o2.getName());
                }
            });
            return Iterables.toArray(result, EClass.class);
        }
    });
    updateUI();
    setControl(composite);
    Dialog.applyDialogFont(getControl());
}
Also used : Label(org.eclipse.swt.widgets.Label) TableViewer(org.eclipse.jface.viewers.TableViewer) ComboViewer(org.eclipse.jface.viewers.ComboViewer) Viewer(org.eclipse.jface.viewers.Viewer) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Comparator(java.util.Comparator) Function(com.google.common.base.Function) GridLayout(org.eclipse.swt.layout.GridLayout) EClass(org.eclipse.emf.ecore.EClass) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ISelection(org.eclipse.jface.viewers.ISelection) Iterator(java.util.Iterator) List(java.util.List) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) EClassifier(org.eclipse.emf.ecore.EClassifier) CCombo(org.eclipse.swt.custom.CCombo) ComboViewer(org.eclipse.jface.viewers.ComboViewer) GridData(org.eclipse.swt.layout.GridData) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) EPackageInfo(org.eclipse.xtext.xtext.wizard.EPackageInfo) TableViewer(org.eclipse.jface.viewers.TableViewer) LabelProvider(org.eclipse.jface.viewers.LabelProvider)

Example 92 with IStructuredContentProvider

use of org.eclipse.jface.viewers.IStructuredContentProvider in project archi-modelrepository-plugin by archi-contribs.

the class ConflictsDialog method createTableControl.

// ===========================================================
// Top Table Control
// ===========================================================
private void createTableControl(Composite parent) {
    Composite tableComp = new Composite(parent, SWT.BORDER);
    TableColumnLayout tableLayout = new TableColumnLayout();
    tableComp.setLayout(tableLayout);
    tableComp.setLayoutData(new GridData(GridData.FILL_BOTH));
    fTableViewer = new TableViewer(tableComp, SWT.FULL_SELECTION | SWT.MULTI);
    fTableViewer.getControl().setLayoutData(new GridData(GridData.FILL_BOTH));
    fTableViewer.getTable().setHeaderVisible(true);
    fTableViewer.getTable().setLinesVisible(true);
    fTableViewer.setComparator(new ViewerComparator() {

        @Override
        public int compare(Viewer viewer, Object object1, Object object2) {
            EObject eObject1 = ((MergeObjectInfo) object1).getDefaultEObject();
            EObject eObject2 = ((MergeObjectInfo) object2).getDefaultEObject();
            String s1 = ArchiLabelProvider.INSTANCE.getDefaultName(eObject1.eClass());
            String s2 = ArchiLabelProvider.INSTANCE.getDefaultName(eObject2.eClass());
            return s1.compareToIgnoreCase(s2);
        }
    });
    // Columns
    TableViewerColumn column1 = new TableViewerColumn(fTableViewer, SWT.NONE, 0);
    column1.getColumn().setText(Messages.ConflictsDialog_24);
    tableLayout.setColumnData(column1.getColumn(), new ColumnWeightData(30, true));
    TableViewerColumn column2 = new TableViewerColumn(fTableViewer, SWT.NONE, 1);
    column2.getColumn().setText(Messages.ConflictsDialog_25);
    tableLayout.setColumnData(column2.getColumn(), new ColumnWeightData(40, true));
    TableViewerColumn column3 = new TableViewerColumn(fTableViewer, SWT.NONE, 2);
    column3.getColumn().setText(Messages.ConflictsDialog_26);
    tableLayout.setColumnData(column3.getColumn(), new ColumnWeightData(15, true));
    TableViewerColumn column4 = new TableViewerColumn(fTableViewer, SWT.NONE, 3);
    column4.getColumn().setText(Messages.ConflictsDialog_27);
    tableLayout.setColumnData(column4.getColumn(), new ColumnWeightData(15, true));
    column4.setEditingSupport(new ComboChoiceEditingSupport(fTableViewer));
    // Content Provider
    fTableViewer.setContentProvider(new IStructuredContentProvider() {

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

        @Override
        public void dispose() {
        }

        @Override
        public Object[] getElements(Object inputElement) {
            return fHandler.getMergeObjectInfos().toArray();
        }
    });
    // Table Selection Listener
    fTableViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            MergeObjectInfo info = (MergeObjectInfo) ((StructuredSelection) event.getSelection()).getFirstElement();
            updateTabs(info);
        }
    });
    // Table Label Provider
    fTableViewer.setLabelProvider(new TableLabelProvider());
    // Start the table
    // anything will do //$NON-NLS-1$
    fTableViewer.setInput("");
}
Also used : ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) Composite(org.eclipse.swt.widgets.Composite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) TableViewer(org.eclipse.jface.viewers.TableViewer) ColumnViewer(org.eclipse.jface.viewers.ColumnViewer) Viewer(org.eclipse.jface.viewers.Viewer) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) ITableLabelProvider(org.eclipse.jface.viewers.ITableLabelProvider) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) EObject(org.eclipse.emf.ecore.EObject) GridData(org.eclipse.swt.layout.GridData) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) EObject(org.eclipse.emf.ecore.EObject) TableViewer(org.eclipse.jface.viewers.TableViewer) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn)

Example 93 with IStructuredContentProvider

use of org.eclipse.jface.viewers.IStructuredContentProvider in project egit by eclipse.

the class CommitFileDiffViewer method selectFirstInterestingElement.

void selectFirstInterestingElement() {
    IStructuredContentProvider contentProvider = ((IStructuredContentProvider) getContentProvider());
    Object[] elements = contentProvider.getElements(getInput());
    for (final Object element : elements) {
        if (element instanceof FileDiff) {
            FileDiff fileDiff = (FileDiff) element;
            boolean marked = fileDiff.isMarked(FileDiffContentProvider.INTERESTING_MARK_TREE_FILTER_INDEX);
            if (marked) {
                setSelection(new StructuredSelection(fileDiff));
                return;
            }
        }
    }
}
Also used : IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection)

Example 94 with IStructuredContentProvider

use of org.eclipse.jface.viewers.IStructuredContentProvider in project egit by eclipse.

the class CommitFileDiffViewer method revealFirstInterestingElement.

private void revealFirstInterestingElement() {
    IStructuredContentProvider contentProvider = ((IStructuredContentProvider) getContentProvider());
    Object[] elements = contentProvider.getElements(getInput());
    if (elements.length <= 1)
        return;
    for (final Object element : elements) {
        if (element instanceof FileDiff) {
            FileDiff fileDiff = (FileDiff) element;
            boolean marked = fileDiff.isMarked(FileDiffContentProvider.INTERESTING_MARK_TREE_FILTER_INDEX);
            if (marked) {
                // Does not yet work reliably, see comment on bug 393610.
                getTable().getDisplay().asyncExec(new Runnable() {

                    @Override
                    public void run() {
                        reveal(element);
                    }
                });
                // Only reveal first
                return;
            }
        }
    }
}
Also used : IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider)

Example 95 with IStructuredContentProvider

use of org.eclipse.jface.viewers.IStructuredContentProvider in project egit by eclipse.

the class MergeResultDialog method createDialogArea.

@Override
public Control createDialogArea(final Composite parent) {
    final Composite composite = (Composite) super.createDialogArea(parent);
    GridLayout gridLayout = new GridLayout();
    gridLayout.numColumns = 2;
    composite.setLayout(gridLayout);
    // result
    Label resultLabel = new Label(composite, SWT.NONE);
    resultLabel.setText(UIText.MergeResultDialog_result);
    resultLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
    Text resultText = new Text(composite, SWT.READ_ONLY);
    MergeStatus status = mergeResult.getMergeStatus();
    resultText.setText(status.toString());
    resultText.setSelection(resultText.getCaretPosition());
    resultText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
    if (status == MergeStatus.FAILED) {
        resultText.setForeground(parent.getDisplay().getSystemColor(SWT.COLOR_RED));
        StringBuilder paths = new StringBuilder();
        Label pathsLabel = new Label(composite, SWT.NONE);
        pathsLabel.setText(UIText.MergeResultDialog_failed);
        pathsLabel.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false));
        Text pathsText = new Text(composite, SWT.READ_ONLY);
        pathsText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
        Set<Entry<String, MergeFailureReason>> failedPaths = mergeResult.getFailingPaths().entrySet();
        int n = 0;
        for (Map.Entry<String, MergeFailureReason> e : failedPaths) {
            if (n > 0)
                paths.append(Text.DELIMITER);
            paths.append(e.getValue());
            // $NON-NLS-1$
            paths.append("\t");
            paths.append(e.getKey());
            n++;
            if (n > 10 && failedPaths.size() > 15)
                break;
        }
        if (n < failedPaths.size()) {
            paths.append(Text.DELIMITER);
            paths.append(MessageFormat.format(UIText.MergeResultDialog_nMore, Integer.valueOf(n - failedPaths.size())));
        }
        pathsText.setText(paths.toString());
    }
    if (status == MergeStatus.FAST_FORWARD || status == MergeStatus.FAST_FORWARD_SQUASHED || status == MergeStatus.MERGED) {
        // new head
        Label newHeadLabel = new Label(composite, SWT.NONE);
        newHeadLabel.setText(UIText.MergeResultDialog_newHead);
        newHeadLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
        Text newHeadText = new Text(composite, SWT.READ_ONLY);
        ObjectId newHead = mergeResult.getNewHead();
        if (newHead != null)
            newHeadText.setText(getCommitMessage(newHead) + SPACE + abbreviate(mergeResult.getNewHead(), true));
        newHeadText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
    }
    // Merge Input
    Label mergeInputLabel = new Label(composite, SWT.NONE);
    mergeInputLabel.setText(UIText.MergeResultDialog_mergeInput);
    GridDataFactory.fillDefaults().align(SWT.LEAD, SWT.CENTER).span(2, 1).applyTo(mergeInputLabel);
    TableViewer viewer = new TableViewer(composite);
    viewer.setContentProvider(new IStructuredContentProvider() {

        @Override
        public void dispose() {
        // empty
        }

        @Override
        public void inputChanged(Viewer theViewer, Object oldInput, Object newInput) {
        // empty
        }

        @Override
        public Object[] getElements(Object inputElement) {
            return getCommits(mergeResult.getMergedCommits());
        }
    });
    final IStyledLabelProvider styleProvider = new IStyledLabelProvider() {

        private final WorkbenchLabelProvider wrapped = new WorkbenchLabelProvider();

        @Override
        public void removeListener(ILabelProviderListener listener) {
        // Empty
        }

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

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

        @Override
        public void addListener(ILabelProviderListener listener) {
        // Empty
        }

        @Override
        public StyledString getStyledText(Object element) {
            // supported
            if (element instanceof RepositoryCommit)
                return ((RepositoryCommit) element).getStyledText(element);
            return new StyledString(wrapped.getText(element));
        }

        @Override
        public Image getImage(Object element) {
            return wrapped.getImage(element);
        }
    };
    viewer.setLabelProvider(new DelegatingStyledCellLabelProvider(styleProvider));
    applyDialogFont(composite);
    GridDataFactory.fillDefaults().grab(true, true).align(SWT.FILL, SWT.FILL).span(2, 1).applyTo(viewer.getControl());
    viewer.setInput(mergeResult);
    new OpenAndLinkWithEditorHelper(viewer) {

        @Override
        protected void linkToEditor(ISelection selection) {
        // Not supported
        }

        @Override
        protected void open(ISelection selection, boolean activate) {
            handleOpen(selection, OpenStrategy.activateOnOpen());
        }

        @Override
        protected void activate(ISelection selection) {
            handleOpen(selection, true);
        }

        private void handleOpen(ISelection selection, boolean activateOnOpen) {
            if (selection instanceof IStructuredSelection)
                for (Object element : ((IStructuredSelection) selection).toArray()) if (element instanceof RepositoryCommit)
                    CommitEditor.openQuiet((RepositoryCommit) element, activateOnOpen);
        }
    };
    return composite;
}
Also used : OpenAndLinkWithEditorHelper(org.eclipse.ui.OpenAndLinkWithEditorHelper) WorkbenchLabelProvider(org.eclipse.ui.model.WorkbenchLabelProvider) Label(org.eclipse.swt.widgets.Label) TableViewer(org.eclipse.jface.viewers.TableViewer) Viewer(org.eclipse.jface.viewers.Viewer) StyledString(org.eclipse.jface.viewers.StyledString) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) GridLayout(org.eclipse.swt.layout.GridLayout) Entry(java.util.Map.Entry) ISelection(org.eclipse.jface.viewers.ISelection) DelegatingStyledCellLabelProvider(org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider) Composite(org.eclipse.swt.widgets.Composite) ObjectId(org.eclipse.jgit.lib.ObjectId) Text(org.eclipse.swt.widgets.Text) UIText(org.eclipse.egit.ui.internal.UIText) StyledString(org.eclipse.jface.viewers.StyledString) MergeFailureReason(org.eclipse.jgit.merge.ResolveMerger.MergeFailureReason) RepositoryCommit(org.eclipse.egit.ui.internal.commit.RepositoryCommit) ILabelProviderListener(org.eclipse.jface.viewers.ILabelProviderListener) MergeStatus(org.eclipse.jgit.api.MergeResult.MergeStatus) IStyledLabelProvider(org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider) GridData(org.eclipse.swt.layout.GridData) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) Map(java.util.Map) TableViewer(org.eclipse.jface.viewers.TableViewer)

Aggregations

IStructuredContentProvider (org.eclipse.jface.viewers.IStructuredContentProvider)99 Viewer (org.eclipse.jface.viewers.Viewer)77 Composite (org.eclipse.swt.widgets.Composite)58 GridData (org.eclipse.swt.layout.GridData)54 TableViewer (org.eclipse.jface.viewers.TableViewer)45 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)43 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)42 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)40 GridLayout (org.eclipse.swt.layout.GridLayout)40 LabelProvider (org.eclipse.jface.viewers.LabelProvider)32 Image (org.eclipse.swt.graphics.Image)29 Button (org.eclipse.swt.widgets.Button)28 Label (org.eclipse.swt.widgets.Label)28 SelectionEvent (org.eclipse.swt.events.SelectionEvent)26 Table (org.eclipse.swt.widgets.Table)24 ArrayList (java.util.ArrayList)23 ComboViewer (org.eclipse.jface.viewers.ComboViewer)19 TableViewerColumn (org.eclipse.jface.viewers.TableViewerColumn)19 ILabelProviderListener (org.eclipse.jface.viewers.ILabelProviderListener)18 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)18