Example usage for org.eclipse.jface.resource ImageDescriptor createImage

List of usage examples for org.eclipse.jface.resource ImageDescriptor createImage

Introduction

In this page you can find the example usage for org.eclipse.jface.resource ImageDescriptor createImage.

Prototype

public Image createImage() 

Source Link

Document

Creates and returns a new SWT image for this image descriptor.

Usage

From source file:com.ebmwebsourcing.petals.services.filetransfer.FileTransferPlugin.java

License:Open Source License

/**
 * Loads the image located by this path in the current plug-in.
 * <p>//from  ww w.ja v a 2s. c  o  m
 * If the path is invalid or if the image could not be loaded, a log entry is created.
 * </p>
 *
 * @param path the relative image path in the plug-in
 * @return the image or null if it could not be loaded
 */
public static Image loadImage(String path) {

    Image img = null;
    try {
        ImageDescriptor desc = getImageDescriptor(path);
        if (desc != null)
            img = desc.createImage();

    } catch (Exception e) {
        log(e, IStatus.WARNING);
    }

    return img;
}

From source file:com.ebmwebsourcing.petals.services.su.export.SuBulkExportWizardPage.java

License:Open Source License

/**
 * Constructor.//from ww w .  j av a  2  s  .c o m
 * @param selection
 */
public SuBulkExportWizardPage(IStructuredSelection selection) {

    super("SU Bulk Export Page");
    setTitle("Bulk Services Export"); //NON-NLS-1
    setDescription("Create n Petals services from one Service Unit project."); //NON-NLS-1

    if (!selection.isEmpty()) {
        IProject project = PlatformUtils.getAdaptedProject(selection.getFirstElement());
        if (project != null && ServiceProjectRelationUtils.isSuProject(project))
            this.suProject = project;
    }

    try {
        ImageDescriptor desc = PlatformUI.getWorkbench().getSharedImages()
                .getImageDescriptor(ISharedImages.IMG_OBJ_FOLDER);
        if (desc != null)
            this.folderImg = desc.createImage();

    } catch (Exception e) {
        PetalsServicesPlugin.log(e, IStatus.WARNING);
    }

    try {
        ImageDescriptor desc = PlatformUI.getWorkbench().getSharedImages()
                .getImageDescriptor(org.eclipse.ui.ide.IDE.SharedImages.IMG_OBJ_PROJECT);
        if (desc != null)
            this.projectImg = desc.createImage();

    } catch (Exception e) {
        PetalsServicesPlugin.log(e, IStatus.WARNING);
    }

    try {
        ImageDescriptor desc = PetalsServicesPlugin.getImageDescriptor("icons/obj16/properties.gif");
        if (desc != null)
            this.propertiesImg = desc.createImage();

    } catch (Exception e) {
        PetalsServicesPlugin.log(e, IStatus.WARNING);
    }
}

From source file:com.ebmwebsourcing.petals.services.su.wizards.pages.ChoicePage.java

License:Open Source License

@Override
public void createControl(Composite parent) {

    // Create the composite container and define its layout
    final Composite container = SwtFactory.createComposite(parent);
    setControl(container);/*from w  w  w .  j av  a 2  s  . c om*/
    SwtFactory.applyNewGridLayout(container, 2, false, 15, 0, 0, 15);
    SwtFactory.applyHorizontalGridData(container);

    // Add a tool tip to display in case of problem
    this.helpTooltip = new FixedShellTooltip(getShell(), true, 90) {
        @Override
        public void populateTooltip(Composite parent) {

            GridLayout layout = new GridLayout();
            layout.verticalSpacing = 2;
            parent.setLayout(layout);
            parent.setLayoutData(new GridData(GridData.FILL_BOTH));
            parent.setBackground(getShell().getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND));

            try {
                ImageDescriptor desc = AbstractUIPlugin.imageDescriptorFromPlugin(
                        PetalsConstants.PETALS_COMMON_PLUGIN_ID, "icons/petals/thinking_hard.png");

                if (desc != null)
                    ChoicePage.this.helpImg = desc.createImage();

                parent.setBackgroundMode(SWT.INHERIT_DEFAULT);
                Label imgLabel = new Label(parent, SWT.NONE);
                imgLabel.setImage(ChoicePage.this.helpImg);
                imgLabel.setLayoutData(new GridData(SWT.CENTER, SWT.DEFAULT, true, true));

            } catch (Exception e) {
                PetalsServicesPlugin.log(e, IStatus.WARNING);
            }

            FontData[] fd = PlatformUtils.getModifiedFontData(getFont().getFontData(), SWT.BOLD);
            ChoicePage.this.boldFont = new Font(getShell().getDisplay(), fd);
            Label titleLabel = new Label(parent, SWT.NONE);
            titleLabel.setFont(ChoicePage.this.boldFont);
            GridData layoutData = new GridData(SWT.CENTER, SWT.DEFAULT, true, true);
            layoutData.verticalIndent = 5;
            titleLabel.setLayoutData(layoutData);
            titleLabel.setText("What does this error mean?");

            Label l = new Label(parent, SWT.WRAP);
            l.setText("This wizard will generate, among other things, Maven artifacts.");
            layoutData = new GridData();
            layoutData.verticalIndent = 8;
            l.setLayoutData(layoutData);

            RowLayout rowLayout = new RowLayout(SWT.HORIZONTAL);
            rowLayout.marginLeft = 0;
            rowLayout.marginTop = 0;
            rowLayout.marginRight = 0;
            rowLayout.marginBottom = 0;
            rowLayout.spacing = 0;

            Composite rowComposite = new Composite(parent, SWT.NONE);
            rowComposite.setLayout(rowLayout);
            rowComposite.setLayoutData(new GridData(SWT.CENTER, SWT.DEFAULT, true, true));

            new Label(rowComposite, SWT.WRAP).setText("Unfortunately, there is a problem with the ");
            Link link = new Link(rowComposite, SWT.WRAP | SWT.NO_FOCUS);
            link.setText("<A>the Petals Maven preferences</A>");
            new Label(rowComposite, SWT.WRAP).setText(".");
            new Label(parent, SWT.WRAP).setText("Please, make them correct.");

            link.addSelectionListener(new DefaultSelectionListener() {
                @Override
                public void widgetSelected(SelectionEvent e) {
                    try {
                        PreferencesUtil.createPreferenceDialogOn(new Shell(),
                                "com.ebmwebsourcing.petals.services.prefs.maven", null, null).open();

                    } catch (Exception e1) {
                        PetalsServicesPlugin.log(e1, IStatus.ERROR);
                    }
                }
            });
        }
    };

    // Prepare the input
    Comparator<AbstractServiceUnitWizard> comparator = new Comparator<AbstractServiceUnitWizard>() {
        @Override
        public int compare(AbstractServiceUnitWizard o1, AbstractServiceUnitWizard o2) {
            String v1 = o1.getComponentVersionDescription().getComponentVersion();
            String v2 = o2.getComponentVersionDescription().getComponentVersion();
            return -v1.compareTo(v2); // negative so that the most recent is first
        }
    };

    final Map<String, Collection<AbstractServiceUnitWizard>> componentNameToHandler = new TreeMap<String, Collection<AbstractServiceUnitWizard>>();
    final Map<PetalsKeyWords, Set<String>> keywordToComponentName = new TreeMap<PetalsKeyWords, Set<String>>();
    for (AbstractServiceUnitWizard handler : ExtensionManager.INSTANCE.findComponentWizards(this.petalsMode)) {
        for (PetalsKeyWords keyword : handler.getComponentVersionDescription().getKeyWords()) {
            Set<String> list = keywordToComponentName.get(keyword);
            if (list == null)
                list = new TreeSet<String>();

            String componentName = handler.getComponentVersionDescription().getComponentName();
            list.add(componentName);
            keywordToComponentName.put(keyword, list);

            Collection<AbstractServiceUnitWizard> handlers = componentNameToHandler.get(componentName);
            if (handlers == null)
                handlers = new TreeSet<AbstractServiceUnitWizard>(comparator);

            handlers.add(handler);
            componentNameToHandler.put(componentName, handlers);
        }
    }

    // Add the selection area
    final PhantomText searchText = new PhantomText(container, SWT.SINGLE | SWT.BORDER);
    searchText.setDefaultValue("Search...");
    GridDataFactory.swtDefaults().grab(true, false).align(SWT.FILL, SWT.TOP).span(2, 1).applyTo(searchText);

    final TreeViewer componentsViewer = new TreeViewer(container, SWT.BORDER | SWT.SINGLE | SWT.FULL_SELECTION);
    GridDataFactory.fillDefaults().span(2, 1).hint(380, 300).applyTo(componentsViewer.getTree());
    componentsViewer.setLabelProvider(new LabelProvider() {
        @Override
        public String getText(Object element) {

            String result;
            if (element instanceof String) {
                IComponentDescription desc = componentNameToHandler.get(element).iterator().next()
                        .getComponentVersionDescription();
                String componentName = desc.getComponentName();
                String componentAlias = desc.getComponentAlias();
                String annotation = desc.getComponentAnnotation();

                StringBuilder sb = new StringBuilder();
                if (StringUtils.isEmpty(componentName))
                    sb.append(componentAlias); // Generic component
                else
                    sb.append(componentAlias + "    -  " + componentName);

                if (!StringUtils.isEmpty(annotation))
                    sb.append("    ( " + annotation + " )");

                result = sb.toString();

            } else {
                result = super.getText(element);
            }

            return result;
        }

        @Override
        public Image getImage(Object element) {

            Image result = null;
            if (element instanceof PetalsKeyWords) {
                result = ChoicePage.this.keywordToImage.get(element);
            } else {
                IComponentDescription desc = componentNameToHandler.get(element).iterator().next()
                        .getComponentVersionDescription();
                result = desc.isBc() ? ChoicePage.this.bcImg : ChoicePage.this.seImg;
            }

            return result;
        }
    });

    componentsViewer.setContentProvider(new DefaultTreeContentProvider() {
        @Override
        public Object[] getElements(Object inputElement) {
            return keywordToComponentName.keySet().toArray();
        }

        @Override
        public Object[] getChildren(Object parentElement) {

            Object[] result;
            if (parentElement instanceof PetalsKeyWords) {
                Collection<String> componentNames = keywordToComponentName.get(parentElement);
                result = componentNames == null ? new Object[0] : componentNames.toArray();

            } else {
                result = new Object[0];
            }

            return result;
        }

        @Override
        public boolean hasChildren(Object element) {
            return element instanceof PetalsKeyWords;
        }
    });

    componentsViewer.addFilter(new ViewerFilter() {
        @Override
        public boolean select(Viewer viewer, Object parentElement, Object element) {

            boolean result = false;
            String filter = searchText.getTextValue().trim().toLowerCase();
            if (filter.length() == 0)
                result = true;

            else if (element instanceof PetalsKeyWords) {
                Set<String> names = keywordToComponentName.get(element);
                if (names != null) {
                    for (String s : names) {
                        if (select(viewer, null, s)) {
                            result = true;
                            break;
                        }
                    }
                }
            }

            else if (element instanceof String)
                result = ((String) element).toLowerCase().contains(filter);

            return result;
        }
    });

    componentsViewer.setInput(new Object());
    if (keywordToComponentName.size() > 0)
        componentsViewer.expandToLevel(keywordToComponentName.keySet().iterator().next(), 1);

    // Display the available versions
    new Label(container, SWT.NONE).setText("Component Version:");
    final ComboViewer versionCombo = new ComboViewer(container, SWT.BORDER | SWT.DROP_DOWN | SWT.READ_ONLY);
    GridData layoutData = new GridData();
    layoutData.widthHint = 130;
    versionCombo.getCombo().setLayoutData(layoutData);
    versionCombo.setContentProvider(new ArrayContentProvider());
    versionCombo.setLabelProvider(new LabelProvider() {
        @Override
        public String getText(Object element) {
            return ((AbstractServiceUnitWizard) element).getComponentVersionDescription().getComponentVersion();
        }
    });

    final Label descriptionLabel = new Label(container, SWT.NONE);
    GridDataFactory.swtDefaults().span(2, 1).indent(0, 10).applyTo(descriptionLabel);

    // Selection listeners
    searchText.addModifyListener(new ModifyListener() {
        @Override
        public void modifyText(ModifyEvent e) {
            componentsViewer.refresh();
            if (searchText.getTextValue().trim().length() == 0)
                componentsViewer.collapseAll();
            else
                componentsViewer.expandAll();
        }
    });

    componentsViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        @Override
        public void selectionChanged(SelectionChangedEvent event) {

            // Get the selection
            Object o = ((IStructuredSelection) event.getSelection()).getFirstElement();
            Collection<?> input;
            if (o == null || o instanceof PetalsKeyWords)
                input = Collections.emptyList();
            else
                input = componentNameToHandler.get(o);

            // Default selection - there is always one
            versionCombo.setInput(input);
            versionCombo.getCombo().setVisibleItemCount(input.size() > 0 ? input.size() : 1);
            if (!input.isEmpty()) {
                versionCombo.setSelection(new StructuredSelection(input.iterator().next()));
                versionCombo.getCombo().notifyListeners(SWT.Selection, new Event());
            } else {
                setPageComplete(false);
                setSelectedNode(null);
                descriptionLabel.setText("");
                descriptionLabel.getParent().layout();
            }
        }
    });

    versionCombo.addSelectionChangedListener(new ISelectionChangedListener() {
        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            AbstractServiceUnitWizard suWizard = (AbstractServiceUnitWizard) ((IStructuredSelection) event
                    .getSelection()).getFirstElement();
            if (suWizard == null)
                return;

            setPageComplete(true);
            setSelectedNode(getWizardNode(suWizard));

            String desc = ChoicePage.this.petalsMode == PetalsMode.provides
                    ? suWizard.getComponentVersionDescription().getProvideDescription()
                    : suWizard.getComponentVersionDescription().getConsumeDescription();
            descriptionLabel.setText(desc);
            descriptionLabel.getParent().layout();
        }
    });

    // Initialize
    if (PreferencesManager.isMavenTemplateConfigurationValid())
        this.helpTooltip.hide();

    componentsViewer.getTree().setFocus();
}

From source file:com.ebmwebsourcing.petals.services.wizards.AbstractPetalsServiceCreationWizardPage.java

License:Open Source License

/**
 * Constructor.//from  w  ww  .  j  av  a2  s  .c  om
 * @param title the page title
 * @param description the page description
 */
public AbstractPetalsServiceCreationWizardPage(String title, String description) {

    super(title);
    setTitle(title); //NON-NLS-1
    setDescription(description); //NON-NLS-1

    try {
        ImageDescriptor desc = PetalsServicesPlugin.getImageDescriptor("icons/obj16/service_unit.png");
        if (desc != null)
            this.suImg = desc.createImage();

        desc = PetalsServicesPlugin.getImageDescriptor("icons/obj16/service_assembly.png");
        if (desc != null)
            this.saImg = desc.createImage();

        desc = PetalsServicesPlugin.getImageDescriptor("icons/obj16/checked.gif");
        if (desc != null)
            this.checked = desc.createImage();

        desc = PetalsServicesPlugin.getImageDescriptor("icons/obj16/unchecked.gif");
        if (desc != null)
            this.unchecked = desc.createImage();

    } catch (Exception e) {
        PetalsServicesPlugin.log(e, IStatus.WARNING);
    }
}

From source file:com.ebmwebsourcing.petals.services.wizards.FileStructureImportWizardPage.java

License:Open Source License

/**
 * Constructor.//from w  w  w.  j a va 2  s  .  c om
 */
public FileStructureImportWizardPage() {
    super("FileStructureImportWizardPage");
    setTitle("Petals File Structure Import");
    setDescription("Create a Petals project from a Maven file structure for Petals.");

    try {
        ImageDescriptor desc = PetalsServicesPlugin.getImageDescriptor("icons/obj16/service_unit.png");
        if (desc != null)
            this.suImg = desc.createImage();

        desc = PetalsServicesPlugin.getImageDescriptor("icons/obj16/service_assembly.png");
        if (desc != null)
            this.saImg = desc.createImage();

        desc = AbstractUIPlugin.imageDescriptorFromPlugin("com.ebmwebsourcing.petals.component",
                "icons/component.png");
        if (desc != null)
            this.componentImg = desc.createImage();

        desc = AbstractUIPlugin.imageDescriptorFromPlugin("com.ebmwebsourcing.petals.component",
                "icons/shared_library_16x16.png");
        if (desc != null)
            this.slImg = desc.createImage();

    } catch (Exception e) {
        PetalsServicesPlugin.log(e, IStatus.WARNING);
    }
}

From source file:com.ebmwebsourcing.petals.studio.welcome.PetalsStudioWelcomePage.java

License:Open Source License

/**
 * Constructor./*w ww  .j  a  v  a 2 s .c o m*/
 */
public PetalsStudioWelcomePage() {
    try {
        ImageDescriptor desc = PetalsStudioPlugin.getImageDescriptor("icons/prod/background_theme.png");
        this.backgroundImage = desc.createImage();

        desc = PetalsStudioPlugin.getImageDescriptor("icons/prod/background_theme_logo.png");
        this.logoImage = desc.createImage();

        desc = PetalsStudioPlugin.getImageDescriptor("icons/prod/pstudio_16x16_2.png");
        this.iconImage = desc.createImage();

        desc = PetalsStudioPlugin.getImageDescriptor("icons/obj16/Warning.gif");
        this.warnedImg = desc.createImage();

        desc = PetalsStudioPlugin.getImageDescriptor("icons/obj16/Validated.gif");
        this.validImg = desc.createImage();

        desc = PetalsStudioPlugin.getImageDescriptor("icons/prod/bouton_eclipse_contact_ok.png");
        this.eOkButton = desc.createImage();

        desc = PetalsStudioPlugin.getImageDescriptor("icons/prod/bouton_eclipse_contact_finish.png");
        this.eFinishButton = desc.createImage();

        desc = PetalsStudioPlugin.getImageDescriptor("icons/prod/bouton_eclipse_contact_ok_gris.png");
        this.dOkButton = desc.createImage();

    } catch (Exception e) {
        PetalsStudioPlugin.log(e, IStatus.WARNING);
    }
}

From source file:com.feup.contribution.druid.view.SharedImages.java

License:Open Source License

public static Image getImage(String name) {
    ImageDescriptor descriptor = getImageDescriptor(name);
    Image image = (Image) imageCache.get(descriptor);
    if (image == null) {
        image = descriptor.createImage();
        imageCache.put(descriptor, image);
    }/*from w ww  .  j ava2s  . c o m*/
    return image;
}

From source file:com.foglyn.ui.FoglynImages.java

License:Open Source License

/**
 * Lazily initializes image map.//from w ww. j a v a 2s  .c om
 */
public static Image getImage(ImageDescriptor imageDescriptor) {
    ImageRegistry imageRegistry = getImageRegistry();

    Image image = imageRegistry.get("" + imageDescriptor.hashCode());
    if (image == null) {
        image = imageDescriptor.createImage();
        imageRegistry.put("" + imageDescriptor.hashCode(), image);
    }
    return image;
}

From source file:com.github.lbroudoux.dsl.eip.parser.core.ui.dialogs.RouteTreeLabelProvider.java

License:Apache License

@Override
public Image getImage(Object element) {
    if (element instanceof IProject) {
        return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_PROJECT);
    }/*  w  w w  .  j  a v  a  2  s  .c o  m*/
    if (element instanceof IResource) {
        return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_FILE);
    }
    if (element instanceof Route) {
        Bundle bundle = FrameworkUtil.getBundle(RouteTreeLabelProvider.class);
        URL url = FileLocator.find(bundle, new Path("icons/obj16/Route.gif"), null);
        ImageDescriptor imageDcr = ImageDescriptor.createFromURL(url);
        return imageDcr.createImage();
    }
    return null;
}

From source file:com.github.sdbg.debug.ui.internal.SDBGDebugUIPlugin.java

License:Open Source License

public static Image getImage(ImageDescriptor imageDescriptor) {
    Image image = imageCache.get(imageDescriptor);

    if (image == null) {
        image = imageDescriptor.createImage();

        imageCache.put(imageDescriptor, image);
    }/*w w  w  .  jav a  2  s  .  c  o  m*/

    return image;
}