Search in sources :

Example 1 with IStyledLabelProvider

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

the class XtextEObjectSearchDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite container) {
    Composite parent = (Composite) super.createDialogArea(container);
    if (enableStyledLabels && labelProvider instanceof IStyledLabelProvider) {
        final Table table = getTableViewer().getTable();
        final IStyledLabelProvider styledLabelProvider = (IStyledLabelProvider) labelProvider;
        TableOwnerDrawSupport.install(table);
        Listener listener = new Listener() {

            @Override
            public void handleEvent(Event event) {
                handleSetData(event);
            }

            protected void handleSetData(Event event) {
                TableItem item = (TableItem) event.item;
                IEObjectDescription description = (IEObjectDescription) item.getData();
                if (description != null) {
                    StyledString styledString = styledLabelProvider.getStyledText(description);
                    String displayString = styledString.toString();
                    StyleRange[] styleRanges = styledString.getStyleRanges();
                    item.setText(displayString);
                    TableOwnerDrawSupport.storeStyleRanges(item, 0, styleRanges);
                }
            }
        };
        table.addListener(SWT.SetData, listener);
    }
    messageLabel = new Label(parent, SWT.NONE);
    setDefaultGridData(messageLabel);
    EObjectDescriptionContentProvider contentProvider = new EObjectDescriptionContentProvider();
    getTableViewer().setContentProvider(contentProvider);
    getTableViewer().addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            ISelection selection = event.getSelection();
            if (selection instanceof IStructuredSelection) {
                IStructuredSelection structuredSelection = (IStructuredSelection) selection;
                if (!structuredSelection.isEmpty()) {
                    Object firstElement = structuredSelection.getFirstElement();
                    if (firstElement instanceof IEObjectDescription) {
                        IEObjectDescription eObjectDescription = (IEObjectDescription) firstElement;
                        URI resourceURI = eObjectDescription.getEObjectURI().trimFragment();
                        if (resourceURI.isPlatform()) {
                            messageLabel.setText(resourceURI.toPlatformString(true));
                        } else if (resourceURI.isFile()) {
                            messageLabel.setText(resourceURI.toFileString());
                        } else {
                            messageLabel.setText(resourceURI.toString());
                        }
                        return;
                    }
                }
            }
            // $NON-NLS-1$
            messageLabel.setText("");
        }
    });
    applyFilter();
    return parent;
}
Also used : Table(org.eclipse.swt.widgets.Table) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Listener(org.eclipse.swt.widgets.Listener) ModifyListener(org.eclipse.swt.events.ModifyListener) Composite(org.eclipse.swt.widgets.Composite) TableItem(org.eclipse.swt.widgets.TableItem) StyleRange(org.eclipse.swt.custom.StyleRange) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Label(org.eclipse.swt.widgets.Label) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) StyledString(org.eclipse.jface.viewers.StyledString) StyledString(org.eclipse.jface.viewers.StyledString) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) URI(org.eclipse.emf.common.util.URI) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription) IStyledLabelProvider(org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider) ISelection(org.eclipse.jface.viewers.ISelection) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) Event(org.eclipse.swt.widgets.Event) KeyEvent(org.eclipse.swt.events.KeyEvent) ModifyEvent(org.eclipse.swt.events.ModifyEvent)

Example 2 with IStyledLabelProvider

use of org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider in project egit by eclipse.

the class RevertFailureDialog method createCustomArea.

@Override
protected Control createCustomArea(Composite parent) {
    if (reasons == null || reasons.isEmpty())
        return null;
    Composite fileArea = new Composite(parent, SWT.NONE);
    GridDataFactory.fillDefaults().grab(true, true).hint(SWT.DEFAULT, 80).applyTo(fileArea);
    GridLayoutFactory.fillDefaults().applyTo(fileArea);
    TreeViewer viewer = new TreeViewer(fileArea);
    viewer.setAutoExpandLevel(AbstractTreeViewer.ALL_LEVELS);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(viewer.getControl());
    viewer.setContentProvider(new WorkbenchContentProvider() {

        @Override
        public Object[] getElements(Object element) {
            return ((Collection) element).toArray();
        }
    });
    final IStyledLabelProvider styleProvider = new WorkbenchStyledLabelProvider() {

        @Override
        public StyledString getStyledText(Object element) {
            // supported
            if (element instanceof RevertFailure)
                return ((RevertFailure) element).getStyledText(element);
            if (element instanceof Path)
                return ((Path) element).getStyledText(element);
            return super.getStyledText(element);
        }
    };
    viewer.setLabelProvider(new DelegatingStyledCellLabelProvider(styleProvider));
    viewer.setComparator(new ViewerComparator());
    Map<MergeFailureReason, RevertFailure> failures = new HashMap<>();
    for (Entry<String, MergeFailureReason> reason : reasons.entrySet()) {
        RevertFailure failure = failures.get(reason.getValue());
        if (failure == null) {
            failure = new RevertFailure(reason.getValue());
            failures.put(reason.getValue(), failure);
        }
        failure.add(reason.getKey());
    }
    viewer.setInput(failures.values());
    return fileArea;
}
Also used : Composite(org.eclipse.swt.widgets.Composite) HashMap(java.util.HashMap) AbstractTreeViewer(org.eclipse.jface.viewers.AbstractTreeViewer) TreeViewer(org.eclipse.jface.viewers.TreeViewer) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) WorkbenchContentProvider(org.eclipse.ui.model.WorkbenchContentProvider) StyledString(org.eclipse.jface.viewers.StyledString) MergeFailureReason(org.eclipse.jgit.merge.ResolveMerger.MergeFailureReason) WorkbenchStyledLabelProvider(org.eclipse.egit.ui.internal.WorkbenchStyledLabelProvider) IStyledLabelProvider(org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider) DelegatingStyledCellLabelProvider(org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider)

Example 3 with IStyledLabelProvider

use of org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider in project webtools.sourceediting by eclipse.

the class ConfigurableContentOutlinePage method setConfiguration.

/**
 * Configures (or reconfigures) the page according to the given
 * configuration.
 *
 * @param configuration
 */
public void setConfiguration(ContentOutlineConfiguration configuration) {
    // intentionally do not check to see if the new configuration != old
    // configuration
    unconfigure();
    fConfiguration = configuration;
    if (getTreeViewer() != null && getControl() != null && !getControl().isDisposed()) {
        // (re)set the providers
        ILabelProvider labelProvider = getConfiguration().getLabelProvider(getTreeViewer());
        if (labelProvider instanceof IStyledLabelProvider) {
            getTreeViewer().setLabelProvider(new DelegatingStyledCellLabelProvider((IStyledLabelProvider) labelProvider));
        } else {
            getTreeViewer().setLabelProvider(labelProvider);
        }
        getTreeViewer().setContentProvider(getConfiguration().getContentProvider(getTreeViewer()));
        // view toolbar
        IContributionManager toolbar = getSite().getActionBars().getToolBarManager();
        if (toolbar != null) {
            IContributionItem[] toolbarItems = getConfiguration().getToolbarContributions(getTreeViewer());
            if (toolbarItems != null) {
                for (int i = 0; i < toolbarItems.length; i++) {
                    toolbar.add(toolbarItems[i]);
                }
                toolbar.update(true);
            }
        }
        // view menu
        IContributionManager menu = getSite().getActionBars().getMenuManager();
        if (menu != null) {
            IContributionItem[] menuItems = getConfiguration().getMenuContributions(getTreeViewer());
            if (menuItems != null) {
                for (int i = 0; i < menuItems.length; i++) {
                    menuItems[i].setVisible(true);
                    menu.add(menuItems[i]);
                    menuItems[i].update();
                }
                menu.update(true);
            }
        }
        // add the allowed DnD listeners and types
        TransferDragSourceListener[] dragListeners = getConfiguration().getTransferDragSourceListeners(getTreeViewer());
        if (fDragAdapter != null && dragListeners.length > 0) {
            for (int i = 0; i < dragListeners.length; i++) {
                fDragAdapter.addDragSourceListener(dragListeners[i]);
            }
            fActiveDragListeners = dragListeners;
            fDragSource.addDragListener(fDragAdapter);
            fDragSource.setTransfer(fDragAdapter.getTransfers());
        }
        TransferDropTargetListener[] dropListeners = getConfiguration().getTransferDropTargetListeners(getTreeViewer());
        if (fDropAdapter != null && dropListeners.length > 0) {
            for (int i = 0; i < dropListeners.length; i++) {
                fDropAdapter.addDropTargetListener(dropListeners[i]);
            }
            fActiveDropListeners = dropListeners;
            fDropTarget.addDropListener(fDropAdapter);
            fDropTarget.setTransfer(fDropAdapter.getTransfers());
        }
        // add the key listeners
        KeyListener[] listeners = getConfiguration().getKeyListeners(getTreeViewer());
        if (listeners != null) {
            for (int i = 0; i < listeners.length; i++) {
                getControl().addKeyListener(listeners[i]);
            }
        }
    }
    if (fInput != null) {
        setInput(fInput);
    }
}
Also used : IContributionItem(org.eclipse.jface.action.IContributionItem) TransferDragSourceListener(org.eclipse.jface.util.TransferDragSourceListener) TransferDropTargetListener(org.eclipse.jface.util.TransferDropTargetListener) ILabelProvider(org.eclipse.jface.viewers.ILabelProvider) IStyledLabelProvider(org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider) KeyListener(org.eclipse.swt.events.KeyListener) DelegatingStyledCellLabelProvider(org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider) IContributionManager(org.eclipse.jface.action.IContributionManager)

Example 4 with IStyledLabelProvider

use of org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider 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

IStyledLabelProvider (org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider)4 DelegatingStyledCellLabelProvider (org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider)3 StyledString (org.eclipse.jface.viewers.StyledString)3 Composite (org.eclipse.swt.widgets.Composite)3 ISelection (org.eclipse.jface.viewers.ISelection)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 MergeFailureReason (org.eclipse.jgit.merge.ResolveMerger.MergeFailureReason)2 Label (org.eclipse.swt.widgets.Label)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 UIText (org.eclipse.egit.ui.internal.UIText)1 WorkbenchStyledLabelProvider (org.eclipse.egit.ui.internal.WorkbenchStyledLabelProvider)1 RepositoryCommit (org.eclipse.egit.ui.internal.commit.RepositoryCommit)1 URI (org.eclipse.emf.common.util.URI)1 IContributionItem (org.eclipse.jface.action.IContributionItem)1 IContributionManager (org.eclipse.jface.action.IContributionManager)1 TransferDragSourceListener (org.eclipse.jface.util.TransferDragSourceListener)1 TransferDropTargetListener (org.eclipse.jface.util.TransferDropTargetListener)1 AbstractTreeViewer (org.eclipse.jface.viewers.AbstractTreeViewer)1