Example usage for org.eclipse.jface.viewers ILabelDecorator decorateText

List of usage examples for org.eclipse.jface.viewers ILabelDecorator decorateText

Introduction

In this page you can find the example usage for org.eclipse.jface.viewers ILabelDecorator decorateText.

Prototype

public String decorateText(String text, Object element);

Source Link

Document

Returns a text label that is based on the given text label, but decorated with additional information relating to the state of the provided element.

Usage

From source file:org.eclipse.debug.internal.ui.views.memory.AddMemoryRenderingDialog.java

License:Open Source License

private String[] getLabels(IMemoryBlock[] memoryBlocks) {
    String[] labels = new String[memoryBlocks.length];
    for (int i = 0; i < memoryBlocks.length; i++) {
        String text = IInternalDebugCoreConstants.EMPTY_STRING;
        if (memoryBlocks[i] instanceof IMemoryBlockExtension) {
            try {
                text = ((IMemoryBlockExtension) memoryBlocks[i]).getExpression();

                if (text == null)
                    text = DebugUIMessages.AddMemoryRenderingDialog_Unknown;

                if (((IMemoryBlockExtension) memoryBlocks[i]).getBigBaseAddress() != null) {
                    text += " : 0x"; //$NON-NLS-1$
                    text += ((IMemoryBlockExtension) memoryBlocks[i]).getBigBaseAddress().toString(16);
                }/* w w  w . ja  va  2  s  .  c o  m*/
            } catch (DebugException e) {
                long address = memoryBlocks[i].getStartAddress();
                text = Long.toHexString(address);
            }
        } else {
            long address = memoryBlocks[i].getStartAddress();
            text = Long.toHexString(address);
        }

        // ask decorator to decorate to ensure consistent label
        ILabelDecorator decorator = (ILabelDecorator) fMemoryBlocks[i].getAdapter(ILabelDecorator.class);
        if (decorator != null)
            text = decorator.decorateText(text, fMemoryBlocks[i]);

        labels[i] = text;
    }
    return labels;
}

From source file:org.eclipse.debug.internal.ui.views.memory.SwitchMemoryBlockAction.java

License:Open Source License

/**
 * Decorate the label for the specified <code>IMemoryBlock</code>
 * @param memBlk//  w  w  w. java  2 s  . c  om
 * @param label
 * @return the decorated label for the specified <code>IMemoryBlock</code>
 */
private String decorateLabel(final IMemoryBlock memBlk, String label) {
    ILabelDecorator decorator = (ILabelDecorator) memBlk.getAdapter(ILabelDecorator.class);
    if (decorator != null) {
        label = decorator.decorateText(label, memBlk);
    }
    return label;
}

From source file:org.eclipse.equinox.jmx.internal.client.ui.contributionsview.ContributionLabelProvider.java

License:Open Source License

protected String decorateText(String text, Object element) {
    if (labelDecorators != null && text.length() > 0) {
        Iterator iter = labelDecorators.iterator();
        while (iter.hasNext()) {
            ILabelDecorator decorator = (ILabelDecorator) iter.next();
            text = decorator.decorateText(text, element);
        }/*  w w  w.  jav a  2 s .  com*/
    }
    return text;
}

From source file:org.eclipse.handly.ui.viewer.CompositeLabelDecorator.java

License:Open Source License

@Override
public String decorateText(String text, Object element) {
    for (ILabelDecorator decorator : decorators) {
        String newText = decorator.decorateText(text, element);
        if (newText != null)
            text = newText;//from w w  w .ja  va2 s  .c om
    }
    return text;
}

From source file:org.eclipse.oomph.internal.ui.FindAndReplaceTarget.java

License:Open Source License

/**
 * This sets up a special label provider in the viewer to be able to highlight the scope and show the selected match.
 *///ww  w.  j  av a  2  s .  co  m
protected void hookLabelProvider() {
    final StructuredViewer viewer = getViewer();

    // We use this special class so we can detect if the label provider is already hooked up.
    class DecoratingLabelProvider extends DelegatingStyledCellLabelProvider.FontAndColorProvider
            implements IStyledLabelProvider {
        public DecoratingLabelProvider(IStyledLabelProvider styledLabelProvider) {
            super(styledLabelProvider);
        }

        @Override
        public StyledString getStyledText(Object element) {
            return super.getStyledText(element);
        }
    }

    // If the label provider is already hooked up...
    final ILabelProvider labelProvider = (ILabelProvider) viewer.getLabelProvider();
    if (labelProvider instanceof DecoratingLabelProvider) {
        // Update the selection scope objects.
        if (selectionScopeObjects != null) {
            viewer.update(selectionScopeObjects.toArray(), null);
        }

        // Update the selected object if it's for a label.
        if (selectedItem != null && selectedItem.itemPropertyDescriptor == null) {
            viewer.update(selectedItem.data.object, null);
        }
    } else {
        // Create a styled label provider that can decorate the text.
        IStyledLabelProvider styledProvider = new DecoratingColumLabelProvider.StyledLabelProvider(
                labelProvider, new IStyledLabelDecorator() {
                    // Use the color from the theme that the editor uses to highlight the scope.
                    final Color color = workbenchPart.getSite().getWorkbenchWindow().getWorkbench()
                            .getThemeManager().getCurrentTheme().getColorRegistry()
                            .get("org.eclipse.ui.editors.findScope");

                    final Styler scopeStyler = new Styler() {
                        @Override
                        public void applyStyles(TextStyle textStyle) {
                            textStyle.background = color;
                        }
                    };

                    public void removeListener(ILabelProviderListener listener) {
                        labelProvider.removeListener(listener);
                    }

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

                    public void dispose() {
                        labelProvider.dispose();
                    }

                    public void addListener(ILabelProviderListener listener) {
                        labelProvider.addListener(listener);
                    }

                    public String decorateText(String text, Object element) {
                        if (labelProvider instanceof ILabelDecorator) {
                            ILabelDecorator labelDecorator = (ILabelDecorator) labelProvider;
                            return labelDecorator.decorateText(text, element);
                        }

                        return text;
                    }

                    public Image decorateImage(Image image, Object element) {
                        if (labelProvider instanceof ILabelDecorator) {
                            ILabelDecorator labelDecorator = (ILabelDecorator) labelProvider;
                            return labelDecorator.decorateImage(image, element);
                        }

                        return image;
                    }

                    public StyledString decorateStyledText(StyledString styledString, Object element) {
                        if (labelProvider instanceof IStyledLabelDecorator) {
                            IStyledLabelDecorator styledLabelDecorator = (IStyledLabelDecorator) labelProvider;
                            styledString = styledLabelDecorator.decorateStyledText(styledString, element);
                        }

                        // If we have a selected item, it's the item for the label, and this element is that selected element's object...
                        if (selectedItem != null && selectedItem.itemPropertyDescriptor == null
                                && element == selectedItem.data.object) {
                            // Convert the styled string to just a string.
                            String string = styledString.getString();

                            // Find the pattern match within that string.
                            Matcher matcher = selectedItemPattern.matcher(string);
                            if (matcher.find(selectedItemStart)) {
                                // Create a new styles string.
                                StyledString result = new StyledString();

                                // Recompose the string with the match styled to show a selection bod.
                                String group = matcher.group();
                                int start = matcher.start();
                                int end = matcher.end();
                                result.append(string.substring(0, start));
                                result.append(group, MATCH_STYLER);
                                result.append(string.substring(end));
                                return result;
                            }
                        }

                        // If we have scope objects and the element is one of those...
                        if (selectionScopeObjects != null && selectionScopeObjects.contains(element)) {
                            // Mark the entire string with the scope styling.
                            StyledString result = new StyledString();
                            result.append(styledString.getString(), scopeStyler);
                            return result;
                        }

                        // Otherwise just pass through the string.
                        return styledString;
                    }
                });

        // Hook up the label provider to be the one used by the view.
        ILabelProvider delegatingLabelProvider = new DecoratingLabelProvider(styledProvider);
        viewer.setLabelProvider(delegatingLabelProvider);
    }
}

From source file:org.eclipse.tcf.te.ui.views.editor.pages.AbstractTreeViewerExplorerEditorPage.java

License:Open Source License

/**
 * Update the page's ui including its toolbar and title text and image.
 *//*from ww  w.  j  a  va  2s. c om*/
protected void updateUI() {
    toolbarMgr.update(true);
    IManagedForm managedForm = getManagedForm();
    Form form = managedForm.getForm().getForm();
    Object element = getTreeViewerInput();
    boolean filterEnabled = false;
    IFilterable filterDecorator = adaptFilterable();
    if (filterDecorator != null) {
        TreeViewer viewer = (TreeViewer) treeControl.getViewer();
        filterEnabled = TreeViewerUtil.isFiltering(viewer, TreePath.EMPTY);
    }
    ILabelDecorator titleDecorator = getTitleBarDecorator();
    String text = getFormTitle();
    if (text != null) {
        if (titleDecorator != null) {
            text = titleDecorator.decorateText(text, element);
        }
        if (filterEnabled) {
            TreeViewer viewer = (TreeViewer) treeControl.getViewer();
            text = TreeViewerUtil.getDecoratedText(text, viewer, TreePath.EMPTY);
        }
    }
    Image image = getFormImage();
    if (image != null) {
        if (titleDecorator != null) {
            image = titleDecorator.decorateImage(image, element);
        }
        if (filterEnabled) {
            TreeViewer viewer = (TreeViewer) treeControl.getViewer();
            image = TreeViewerUtil.getDecoratedImage(image, viewer, TreePath.EMPTY);
        }
    }
    if (text != null) {
        try {
            form.setText(text);
        } catch (Exception e) {
            // Ignore any disposed exception
        }
    }
    if (image != null) {
        try {
            form.setImage(image);
        } catch (Exception e) {
            // Ignore any disposed exception
        }
    }
}

From source file:org.eclipse.ui.dialogs.EditorSelectionDialog.java

License:Open Source License

/**
 * Creates and returns the contents of the upper part of the dialog (above
 * the button bar).//from  ww  w .  j  av  a 2 s. co  m
 * 
 * Subclasses should overide.
 * 
 * @param parent
 *            the parent composite to contain the dialog area
 * @return the dialog area control
 */
protected Control createDialogArea(Composite parent) {
    Font font = parent.getFont();
    // create main group
    Composite contents = (Composite) super.createDialogArea(parent);
    ((GridLayout) contents.getLayout()).numColumns = 2;

    // begin the layout
    Label textLabel = new Label(contents, SWT.NONE);
    textLabel.setText(message);
    GridData data = new GridData();
    data.horizontalSpan = 2;
    textLabel.setLayoutData(data);
    textLabel.setFont(font);

    internalButton = new Button(contents, SWT.RADIO | SWT.LEFT);
    internalButton.setText(WorkbenchMessages.EditorSelection_internal);
    internalButton.addListener(SWT.Selection, listener);
    data = new GridData();
    data.horizontalSpan = 1;
    internalButton.setLayoutData(data);
    internalButton.setFont(font);

    externalButton = new Button(contents, SWT.RADIO | SWT.LEFT);
    externalButton.setText(WorkbenchMessages.EditorSelection_external);
    externalButton.addListener(SWT.Selection, listener);
    data = new GridData();
    data.horizontalSpan = 1;
    externalButton.setLayoutData(data);
    externalButton.setFont(font);

    editorTable = new Table(contents, SWT.SINGLE | SWT.BORDER);
    editorTable.addListener(SWT.Selection, listener);
    editorTable.addListener(SWT.DefaultSelection, listener);
    editorTable.addListener(SWT.MouseDoubleClick, listener);
    data = new GridData();
    data.widthHint = convertHorizontalDLUsToPixels(TABLE_WIDTH);
    data.horizontalAlignment = GridData.FILL;
    data.grabExcessHorizontalSpace = true;
    data.verticalAlignment = GridData.FILL;
    data.grabExcessVerticalSpace = true;
    data.horizontalSpan = 2;
    editorTable.setLayoutData(data);
    editorTable.setFont(font);
    data.heightHint = editorTable.getItemHeight() * 12;
    editorTableViewer = new TableViewer(editorTable);
    editorTableViewer.setContentProvider(ArrayContentProvider.getInstance());
    final ILabelDecorator decorator = PlatformUI.getWorkbench().getDecoratorManager()
            .getLabelDecorator(ContributingPluginDecorator.ID);
    editorTableViewer.setLabelProvider(new ColumnLabelProvider() {
        public String getText(Object element) {
            IEditorDescriptor d = (IEditorDescriptor) element;
            return TextProcessor.process(d.getLabel(), "."); //$NON-NLS-1$
        }

        public Image getImage(Object element) {
            IEditorDescriptor d = (IEditorDescriptor) element;
            return (Image) resourceManager.get(d.getImageDescriptor());
        }

        public String getToolTipText(Object element) {
            if (decorator == null || !(element instanceof EditorDescriptor)) {
                return null;
            }
            EditorDescriptor d = (EditorDescriptor) element;
            return decorator.decorateText(getText(element), d.getConfigurationElement());
        }
    });
    if (decorator != null) {
        ColumnViewerToolTipSupport.enableFor(editorTableViewer);
    }

    browseExternalEditorsButton = new Button(contents, SWT.PUSH);
    browseExternalEditorsButton.setText(WorkbenchMessages.EditorSelection_browse);
    browseExternalEditorsButton.addListener(SWT.Selection, listener);
    data = new GridData();
    int widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH);
    data.widthHint = Math.max(widthHint,
            browseExternalEditorsButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x);
    browseExternalEditorsButton.setLayoutData(data);
    browseExternalEditorsButton.setFont(font);

    restoreWidgetValues(); // Place buttons to the appropriate state

    fillEditorTable();

    updateEnableState();

    return contents;
}

From source file:org.eclipse.ui.internal.decorators.FullDecoratorDefinition.java

License:Open Source License

/**
 * Decorate the text provided for the element type.
 * This method should not be called unless a check for
 * isEnabled() has been done first./*from www. ja  va  2 s. co  m*/
 * Return null if there is no text or if there is an exception.
 */
String decorateText(String text, Object element) {
    try {
        //Internal decorator might be null so be prepared
        ILabelDecorator currentDecorator = internalGetDecorator();
        if (currentDecorator != null) {
            return currentDecorator.decorateText(text, element);
        }
    } catch (CoreException exception) {
        handleCoreException(exception);
    }
    return null;
}

From source file:org.eclipse.ui.internal.dialogs.StartupPreferencePage.java

License:Open Source License

protected void createEarlyStartupSelection(Composite parent) {
    Label label = new Label(parent, SWT.NONE);
    label.setText(WorkbenchMessages.StartupPreferencePage_label);
    label.setFont(parent.getFont());//w w w .  ja v a  2 s .co  m
    GridData data = new GridData(GridData.FILL_HORIZONTAL);
    label.setLayoutData(data);
    pluginsList = new Table(parent, SWT.BORDER | SWT.CHECK | SWT.H_SCROLL | SWT.V_SCROLL);
    data = new GridData(GridData.FILL_BOTH);
    pluginsList.setFont(parent.getFont());
    pluginsList.setLayoutData(data);
    TableViewer viewer = new TableViewer(pluginsList);
    String pluginIds[] = workbench.getEarlyActivatedPlugins();
    final ILabelDecorator decorator = workbench.getDecoratorManager()
            .getLabelDecorator(ContributingPluginDecorator.ID);
    viewer.setLabelProvider(new ColumnLabelProvider() {
        public String getText(Object element) {
            return (String) Platform.getBundle((String) element).getHeaders().get(Constants.BUNDLE_NAME);
        }

        public String getToolTipText(Object element) {
            if (decorator == null) {
                return null;
            }
            return decorator.decorateText(getText(element), element);
        }
    });
    if (decorator != null) {
        ColumnViewerToolTipSupport.enableFor(viewer);
    }
    viewer.setContentProvider(ArrayContentProvider.getInstance());
    viewer.setInput(pluginIds);
    updateCheckState();
}

From source file:org.eclipse.wst.jsdt.internal.ui.viewsupport.DecoratingJavaLabelProvider.java

License:Open Source License

public ColoredString getRichTextLabel(Object element) {
    ILabelProvider labelProvider = getLabelProvider();
    if (labelProvider instanceof IRichLabelProvider) {
        // get a rich label from the label decorator
        IRichLabelProvider richLabelProvider = (IRichLabelProvider) labelProvider;
        ColoredString richLabel = richLabelProvider.getRichTextLabel(element);
        if (richLabel != null) {
            String decorated = null;
            ILabelDecorator labelDecorator = getLabelDecorator();
            if (labelDecorator != null) {
                if (labelDecorator instanceof LabelDecorator) {
                    decorated = ((LabelDecorator) labelDecorator).decorateText(richLabel.getString(), element,
                            getDecorationContext());
                } else {
                    decorated = labelDecorator.decorateText(richLabel.getString(), element);
                }/*  w ww .  ja  v  a  2  s.co  m*/
            }
            if (decorated != null) {
                return ColoredJavaElementLabels.decorateColoredString(richLabel, decorated,
                        ColoredJavaElementLabels.DECORATIONS_STYLE);
            }
            return richLabel;
        }
    }
    return null;
}