Example usage for org.eclipse.jface.viewers DecorationOverlayIcon DecorationOverlayIcon

List of usage examples for org.eclipse.jface.viewers DecorationOverlayIcon DecorationOverlayIcon

Introduction

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

Prototype

public DecorationOverlayIcon(Image baseImage, ImageDescriptor[] overlaysArray) 

Source Link

Document

Create the decoration overlay for the base image using the array of provided overlays.

Usage

From source file:org.eclipse.ui.ide.markers.compatibility.internal.MarkerColumnLabelProvider.java

License:Open Source License

public Image getImage(Object element) {

    // if (showAnnotations && element instanceof MarkerEntry) {
    // MarkerItem item = (MarkerItem) element;
    // IMarker marker = item.getMarker();
    // if (marker != null) {
    // String contextId = IDE.getMarkerHelpRegistry().getHelp(marker);
    ////from ww  w. j av a2  s  . c  o  m
    // if (contextId != null)
    // return JFaceResources.getImage(Dialog.DLG_IMG_HELP);
    // }
    // }

    MarkerItem item = (MarkerItem) element;
    Image image = field.getImage(item);
    ImageDescriptor[] descriptors = new ImageDescriptor[5];
    if (showAnnotations && item.isConcrete()) {
        IMarker marker = item.getMarker();
        // If there is no image get the full image rather than the decorated
        // one
        if (marker != null) {
            String contextId = IDE.getMarkerHelpRegistry().getHelp(marker);
            if (contextId != null) {
                if (image == null)
                    image = JFaceResources.getImage(Dialog.DLG_IMG_HELP);
                else
                    descriptors[IDecoration.TOP_RIGHT] = IDEWorkbenchPlugin.getIDEImageDescriptor(
                            MarkerSupportInternalUtilities.IMG_MARKERS_HELP_DECORATION_PATH);
            }
            if (IDE.getMarkerHelpRegistry().hasResolutions(marker)) {
                if (image == null)
                    image = imageManager.createImage(IDEInternalWorkbenchImages
                            .getImageDescriptor(IDEInternalWorkbenchImages.IMG_ELCL_QUICK_FIX_ENABLED));
                else
                    descriptors[IDecoration.BOTTOM_RIGHT] = IDEWorkbenchPlugin.getIDEImageDescriptor(
                            MarkerSupportInternalUtilities.IMG_MARKERS_QUICK_FIX_DECORATION_PATH);
            }

            if (descriptors[IDecoration.TOP_RIGHT] != null || descriptors[IDecoration.BOTTOM_RIGHT] != null)
                image = imageManager.createImage(new DecorationOverlayIcon(image, descriptors));
        }
    }
    return image;
}

From source file:org.eclipse.ui.views.markers.MarkerField.java

License:Open Source License

/**
 * Annotate the image with indicators for whether or not help or quick fix
 * are available./*from   w ww .  ja  v  a  2 s .  com*/
 * 
 * @param item
 *            the item being decorated
 * @param image
 *            the image being overlaid
 * @return Image
 */
public Image annotateImage(MarkerItem item, Image image) {
    ImageDescriptor[] descriptors = new ImageDescriptor[5];
    if (item.getMarker() != null) {
        IMarker marker = item.getMarker();
        // If there is no image get the full image rather than the decorated
        // one
        if (marker != null) {
            String contextId = IDE.getMarkerHelpRegistry().getHelp(marker);
            if (contextId != null) {
                if (image == null)
                    image = JFaceResources.getImage(Dialog.DLG_IMG_HELP);
                else {
                    descriptors[IDecoration.TOP_RIGHT] = getIDEImageDescriptor(
                            MarkerSupportInternalUtilities.IMG_MARKERS_HELP_DECORATION_PATH);
                }
            }
            if (IDE.getMarkerHelpRegistry().hasResolutions(marker)) {
                if (image == MarkerSupportInternalUtilities.getSeverityImage(IMarker.SEVERITY_WARNING)) {
                    image = WorkbenchPlugin.getDefault().getSharedImages()
                            .getImage(IDEInternalWorkbenchImages.IMG_OBJS_FIXABLE_WARNING);
                } else if (image == MarkerSupportInternalUtilities.getSeverityImage(IMarker.SEVERITY_ERROR)) {
                    image = WorkbenchPlugin.getDefault().getSharedImages()
                            .getImage(IDEInternalWorkbenchImages.IMG_OBJS_FIXABLE_ERROR);
                } else if (image != null) {
                    descriptors[IDecoration.BOTTOM_RIGHT] = getIDEImageDescriptor(
                            MarkerSupportInternalUtilities.IMG_MARKERS_QUICK_FIX_DECORATION_PATH);
                }
                if (image == null) {
                    image = WorkbenchPlugin.getDefault().getSharedImages()
                            .getImage(IDEInternalWorkbenchImages.IMG_ELCL_QUICK_FIX_ENABLED);
                }
            }

            if (descriptors[IDecoration.TOP_RIGHT] != null || descriptors[IDecoration.BOTTOM_RIGHT] != null)
                image = getImageManager().createImage(new DecorationOverlayIcon(image, descriptors));
        }
    }
    return image;

}

From source file:org.l2x6.eircc.ui.misc.IrcImages.java

License:Open Source License

public ImageDescriptor getImageDescriptor(String key, ImageKey[] overlays, ImageSize size) {
    ImageDescriptor result = imageRegistry.getDescriptor(key);
    if (result == null) {
        switch (overlays.length) {
        case 1:/*from w w w  .  j  a  v a2 s.  c  om*/
            result = getImageDescriptor(overlays[0], size);
            break;
        case 6:
            result = new DecorationOverlayIcon(getImage(overlays[0]), toOverlayDescriptors(overlays, size));
            imageRegistry.put(key, result);
            break;
        default:
            throw new IllegalArgumentException("Unexpected overlays length.");
        }
    }
    return result;
}

From source file:org.marketcetera.photon.test.SWTBotConditions.java

public static ICondition itemImageIsReplaced(AbstractSWTBot<? extends Item> widget, Image base,
        ImageDescriptor decoration) {/*ww  w .  ja va2s  .  c o m*/
    return itemImageIs(widget, new DecorationOverlayIcon(base,
            new ImageDescriptor[] { null, null, null, null, null, decoration }));
}

From source file:org.springframework.ide.eclipse.wizard.template.TemplateSelectionPart.java

License:Open Source License

@Override
public Control createArea(Composite parent) {

    initialiseTemplatesFromContentManager();

    Composite container = new Composite(parent, SWT.NONE);
    GridLayoutFactory.fillDefaults().margins(0, 0).spacing(0, 0).applyTo(container);
    container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    Label label = new Label(container, SWT.NONE);
    label.setText("Templates:"); //$NON-NLS-1$
    label.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));

    Tree tree = new Tree(container, SWT.FULL_SELECTION | SWT.BORDER);
    tree.setLinesVisible(false);//from w ww  . java2s  .c  o  m
    tree.setHeaderVisible(false);
    tree.setEnabled(true);

    GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
    data.heightHint = 170;
    tree.setLayoutData(data);

    treeViewer = new TreeViewer(tree);

    treeViewer.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 ITemplateElement) {
                return ((ITemplateElement) element).getName();
            }
            return null;
        }

        public Image getImage(Object element) {
            if (element instanceof Template) {
                Template template = (Template) element;
                Image templateImage = WizardImages.getImage(WizardImages.TEMPLATE_ICON);

                // Simple Project templates are bundled in the plugin,
                // therefore do not require download icon, since they are
                // not downloaded
                if (template instanceof SimpleProject
                        || ((template.getItem().isLocal() || TemplateUtils.hasBeenDownloaded(template))
                                && !template.getItem().isNewerVersionAvailable())) {
                    return templateImage;
                }

                return WizardImages.getImage(new DecorationOverlayIcon(templateImage,
                        new ImageDescriptor[] { StsUiImages.DOWNLOAD_OVERLAY, null, null, null, null }));
            }

            if (element instanceof TemplateCategory) {
                return WizardImages.getImage(WizardImages.TEMPLATE_CATEGORY_ICON);
            }
            return null;
        }
    });

    treeViewer.setSorter(new ViewerSorter() {
        @Override
        public int compare(Viewer viewer, Object e1, Object e2) {
            if (e1 instanceof TemplateCategory && e2 instanceof Template) {
                return -1;
            }
            if (e1 instanceof Template && e2 instanceof TemplateCategory) {
                return 1;
            }

            if (e1 instanceof ITemplateElement && e2 instanceof ITemplateElement) {
                ITemplateElement t1 = (ITemplateElement) e1;
                ITemplateElement t2 = (ITemplateElement) e2;
                // Special Case, Simple Projects category is placed above
                // others
                if (t1.getName().equals(SIMPLE_PROJECTS_CATEGORY)) {
                    return -1;
                } else if (t2.getName().equals(SIMPLE_PROJECTS_CATEGORY)) {
                    return 1;
                } else {
                    return t1.getName().compareTo(t2.getName());
                }
            }
            return super.compare(viewer, e1, e2);
        }
    });

    treeViewer.setContentProvider(new TemplateContentProvider());

    treeViewer.setInput(templates);

    Composite legendContainer = new Composite(container, SWT.NONE);
    legendContainer.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
    GridLayout headerLayout = new GridLayout(3, false);
    headerLayout.marginWidth = 0;
    headerLayout.marginHeight = 0;
    legendContainer.setLayout(headerLayout);

    Composite legendComposite = new Composite(legendContainer, SWT.NONE);
    GridLayout legendLayout = new GridLayout(2, false);
    legendLayout.verticalSpacing = 0;
    legendLayout.marginHeight = 0;
    legendLayout.marginBottom = 0;

    int legendControlVerticalIndent = 5;

    legendComposite.setLayout(legendLayout);
    legendComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));

    legendImage = new Label(legendComposite, SWT.NONE);

    GridDataFactory.fillDefaults().grab(false, false).indent(0, legendControlVerticalIndent)
            .applyTo(legendImage);

    legendImage.setImage(WizardImages.getImage(StsUiImages.DOWNLOAD_OVERLAY));
    legendImage.setToolTipText("Templates with this icon will be downloaded after clicking the 'Next' button.");

    legendText = new Label(legendComposite, SWT.NONE);
    legendText.setText("requires downloading");

    GridDataFactory.fillDefaults().grab(false, false).indent(0, legendControlVerticalIndent)
            .applyTo(legendText);

    Hyperlink hyperlink = new Hyperlink(legendContainer, SWT.WRAP);
    GridDataFactory.fillDefaults().grab(false, false).indent(0, legendControlVerticalIndent).applyTo(hyperlink);
    hyperlink.setText(NLS.bind("Configure templates...", null));
    Color blue = new Color(null, 0, 0, 255);
    hyperlink.setForeground(blue);
    hyperlink.setUnderlined(true);
    blue.dispose();
    hyperlink.addHyperlinkListener(new HyperlinkAdapter() {
        @Override
        public void linkActivated(HyperlinkEvent event) {
            PreferenceDialog dialog = PreferencesUtil.createPreferenceDialogOn(null,
                    TemplatesPreferencePage.EXAMPLE_PREFERENCES_PAGE_ID, null, null);
            refreshButton.setEnabled(false);

            dialog.open();
            downloadDescriptors();

            refreshButton.setEnabled(!isRefreshing());

        }
    });

    refreshButton = new Button(legendContainer, SWT.PUSH);
    refreshButton.setLayoutData(new GridData(SWT.RIGHT, SWT.FILL, false, false));
    refreshButton.setText("Refresh");
    refreshButton.setEnabled(!isRefreshing());

    // refreshButton.setImage(WizardImages.getImage(WizardImages.REFRESH_ICON));

    refreshButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {

            // under most circumstances, we don't want to download templates
            // if there has not been any change. However, when the user
            // presses Refresh, they really do want to see something happen.
            ContentPlugin.getDefault().getManager().setDirty();

            downloadDescriptors();
        }

    });

    refreshButton.setToolTipText(
            "Refresh the list of templates. Note that the current template selection will be cleared.");

    Composite descriptionComposite = new Composite(container, SWT.NONE);
    descriptionComposite.setLayout(new GridLayout());
    descriptionComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));

    descriptionLabel = new Label(descriptionComposite, SWT.NONE);
    descriptionLabel.setText("Description:"); //$NON-NLS-1$
    descriptionLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));

    descriptionText = new StyledText(descriptionComposite, SWT.WRAP | SWT.READ_ONLY | SWT.V_SCROLL);
    // descriptionText.setAlwaysShowScrollBars(false);
    Display display = Display.getCurrent();
    if (display != null) {
        descriptionText.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
    }

    GridData descriptionData = new GridData(SWT.FILL, SWT.FILL, true, true);
    descriptionData.widthHint = 200;
    descriptionData.heightHint = 80;
    descriptionText.setLayoutData(descriptionData);

    treeViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            ISelection selection = treeViewer.getSelection();
            if (selection instanceof TreeSelection) {
                Object element = ((TreeSelection) selection).getFirstElement();
                if (element instanceof Template) {
                    setSeletectedTemplate((Template) element);
                } else if (element instanceof TemplateCategory) {
                    // Note: ONLY clear the selected template if the
                    // selection is a template category.
                    // Do not clear the template if there is an empty
                    // selection in the tree, as there
                    // are times when the viewer
                    // will set an empty selection in the tree due to a
                    // refresh operation, and if
                    // a template was already selected prior to that refresh
                    // request, it should not be
                    // overwritten with null as other operations will
                    // require that the selected template not be changed
                    setSeletectedTemplate(null);
                }
            }
        }

    });

    this.contentManagerListener = new PropertyChangeListener() {

        public void propertyChange(PropertyChangeEvent event) {

            ContentManager manager = event.getSource() instanceof ContentManager
                    ? (ContentManager) event.getSource()
                    : null;
            final boolean hasTemplateContentChanged = manager != null && manager.isDirty();
            if (hasTemplateContentChanged) {

                clearTemplateSelection();

                // Only reinitialise templates if the manager is marked as
                // dirty, as template contents may have changed, therefore
                // new templates
                // need to be created in the tree viewer
                initialiseTemplatesFromContentManager();

            }
            // switch to UI thread to refresh the UI controls
            PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {
                public void run() {
                    refreshPage(hasTemplateContentChanged);
                }
            });

        }

    };

    ContentManager manager = ContentPlugin.getDefault().getManager();
    manager.addListener(contentManagerListener);

    // This does not automatically add the templates to the tree viewer
    // input.
    // Rather it downloads templates asynchronously, and the content manager
    // will then notify the tree viewer when the content is available and at
    // that time
    // refresh the tree input
    downloadDescriptors();

    expandCategory(SIMPLE_PROJECTS_CATEGORY);

    return container;

}

From source file:org.springframework.ide.eclipse.wizard.template.TemplateSelectionWizardPage.java

License:Open Source License

public void createControl(Composite parent) {
    initializeTemplates();// ww w  . java  2s.c om
    Composite container = new Composite(parent, SWT.NONE);
    container.setLayout(new GridLayout());
    container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    Label label = new Label(container, SWT.NONE);
    label.setText("Templates:"); //$NON-NLS-1$
    label.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));

    String[] names = new String[templates.size()];
    for (int i = 0; i < templates.size(); i++) {
        names[i] = templates.get(i).getName();
    }

    Tree tree = new Tree(container, SWT.FULL_SELECTION | SWT.BORDER);
    tree.setLinesVisible(false);
    tree.setHeaderVisible(false);
    tree.setEnabled(true);
    tree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    treeViewer = new TreeViewer(tree);

    treeViewer.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 ITemplateElement) {
                return ((ITemplateElement) element).getName();
            }
            return null;
        }

        public Image getImage(Object element) {
            if (element instanceof Template) {
                Template template = (Template) element;
                Image templateImage = WizardImages.getImage(WizardImages.TEMPLATE_ICON);
                if (template.getItem().isLocal() && !template.getItem().isNewerVersionAvailable()) {
                    return templateImage;
                }
                return WizardImages.getImage(new DecorationOverlayIcon(templateImage,
                        new ImageDescriptor[] { StsUiImages.DOWNLOAD_OVERLAY, null, null, null, null }));
            }

            if (element instanceof TemplateCategory) {
                return WizardImages.getImage(WizardImages.TEMPLATE_CATEGORY_ICON);
            }
            return null;
        }
    });

    treeViewer.setSorter(new ViewerSorter() {
        @Override
        public int compare(Viewer viewer, Object e1, Object e2) {
            if (e1 instanceof TemplateCategory && e2 instanceof Template) {
                return -1;
            }
            if (e1 instanceof Template && e2 instanceof TemplateCategory) {
                return 1;
            }

            if (e1 instanceof ITemplateElement && e2 instanceof ITemplateElement) {
                ITemplateElement t1 = (ITemplateElement) e1;
                ITemplateElement t2 = (ITemplateElement) e2;
                return t1.getName().compareTo(t2.getName());
            }
            return super.compare(viewer, e1, e2);
        }
    });

    treeViewer.setContentProvider(new TemplateContentProvider());

    treeViewer.setInput(templates);

    Composite legendContainer = new Composite(container, SWT.NONE);
    legendContainer.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
    GridLayout headerLayout = new GridLayout(2, false);
    headerLayout.marginWidth = 0;
    headerLayout.marginHeight = 0;
    legendContainer.setLayout(headerLayout);

    Composite legendComposite = new Composite(legendContainer, SWT.NONE);
    GridLayout legendLayout = new GridLayout(2, false);
    legendLayout.verticalSpacing = 0;
    legendLayout.marginHeight = 0;
    legendLayout.marginBottom = 5;

    legendComposite.setLayout(legendLayout);
    legendComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));

    legendImage = new Label(legendComposite, SWT.NONE);
    legendImage.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
    legendImage.setImage(WizardImages.getImage(StsUiImages.DOWNLOAD_OVERLAY));

    legendText = new Label(legendComposite, SWT.NONE);
    legendText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    legendText.setText("requires downloading");

    Hyperlink hyperlink = new Hyperlink(container, SWT.WRAP | SWT.TRAIL | SWT.TOP);
    GridDataFactory.fillDefaults().grab(false, true).align(SWT.END, SWT.BEGINNING).indent(5, 0)
            .applyTo(hyperlink);
    hyperlink.setText(NLS.bind("Configure templates...", null));
    Color blue = new Color(null, 0, 0, 255);
    hyperlink.setForeground(blue);
    hyperlink.setUnderlined(true);
    blue.dispose();
    hyperlink.addHyperlinkListener(new HyperlinkAdapter() {
        @Override
        public void linkActivated(HyperlinkEvent event) {
            PreferenceDialog dialog = PreferencesUtil.createPreferenceDialogOn(null,
                    TemplatesPreferencePage.EXAMPLE_PREFERENCES_PAGE_ID, null, null);
            refreshButton.setEnabled(false);
            setErrorMessage(null);

            dialog.open();
            if (ContentPlugin.getDefault().getManager().isDirty()) {
                downloadDescriptors();
            }

            refreshButton.setEnabled(!isRefreshing());

        }
    });

    refreshButton = new Button(legendContainer, SWT.PUSH);
    refreshButton.setLayoutData(new GridData(SWT.RIGHT, SWT.FILL, false, false));
    refreshButton.setText("Refresh");
    refreshButton.setEnabled(!isRefreshing());

    // refreshButton.setImage(WizardImages.getImage(WizardImages.REFRESH_ICON));

    refreshButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            setErrorMessage(null);
            // under most circumstances, we don't want to download templates
            // if there has not been any change. However, when the user
            // presses Refresh, they really do want to see something happen.
            ContentPlugin.getDefault().getManager().setDirty();

            downloadDescriptors();
        }

    });

    Composite descriptionComposite = new Composite(container, SWT.NONE);
    descriptionComposite.setLayout(new GridLayout());
    descriptionComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));

    descriptionLabel = new Label(descriptionComposite, SWT.NONE);
    descriptionLabel.setText("Description:"); //$NON-NLS-1$
    descriptionLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
    descriptionLabel.setVisible(false);

    descriptionText = new Text(descriptionComposite, SWT.WRAP | SWT.READ_ONLY | SWT.V_SCROLL);
    GridData descriptionData = new GridData(SWT.FILL, SWT.FILL, true, true);
    descriptionData.widthHint = 200;
    descriptionData.heightHint = 80;
    descriptionText.setLayoutData(descriptionData);

    treeViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            ISelection selection = treeViewer.getSelection();

            if (selection instanceof TreeSelection) {
                Object element = ((TreeSelection) selection).getFirstElement();
                if (element instanceof Template) {
                    if (element != null) {
                        selectedTemplate = ((Template) element);
                    }
                }
            }
            firstPage = null;

            if (selectedTemplate != null) {
                setDescription(selectedTemplate);
                if (TemplateSelectionWizardPage.this.equals(wizard.getContainer().getCurrentPage())) {
                    wizard.getContainer().updateButtons();
                }
            }
        }

    });

    this.contentManagerListener = new PropertyChangeListener() {

        public void propertyChange(PropertyChangeEvent arg0) {
            initializeTemplates();
            // switch to UI thread
            PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {
                public void run() {
                    refreshPage();
                }
            });
        }

    };

    ContentManager manager = ContentPlugin.getDefault().getManager();
    manager.addListener(contentManagerListener);

    if (manager.isDirty()) {
        downloadDescriptors();
    }

    setControl(container);

}

From source file:ts.eclipse.ide.jsdt.internal.ui.JSDTTypeScriptUIImages.java

License:Open Source License

private JSDTTypeScriptUIImages(JSDTTypeScriptUIImages base, ImageDescriptor tlOverlay,
        ImageDescriptor trOverlay, ImageDescriptor blOverlay, ImageDescriptor brOverlay) {
    ImageDescriptor descr = new DecorationOverlayIcon(base.get(),
            new ImageDescriptor[] { tlOverlay, trOverlay, blOverlay, brOverlay });
    JFaceResources.getImageRegistry().put(key(), descr);
}