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

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

Introduction

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

Prototype

public static ImageDescriptor getMissingImageDescriptor() 

Source Link

Document

Returns the shared image descriptor for a missing image.

Usage

From source file:org.eclipse.emf.compare.examples.export.xslt.action.ExportAsHTMLAction.java

License:Open Source License

/**
 * Default constructor. Instantiates this action by setting its text, tooltip and image.
 *//* w  ww. j ava 2  s.  c  o m*/
public ExportAsHTMLAction() {
    text = Messages.getString("ExportAsHTMLAction.action.label"); //$NON-NLS-1$
    toolTipText = Messages.getString("ExportAsHTMLAction.action.tooltip"); //$NON-NLS-1$

    final String imagePath = Messages.getString("ExportAsHTMLAction.action.image"); //$NON-NLS-1$

    ImageDescriptor disabledImageDescriptor = null;
    ImageDescriptor enabledImageDescriptor = null;
    final URL imageURL = XSLTExportPlugin.getDefault().getBundle().getEntry("icons/full/" + imagePath); //$NON-NLS-1$
    try {
        disabledImageDescriptor = ImageDescriptor.createFromURL(FileLocator.toFileURL(imageURL));
        enabledImageDescriptor = ImageDescriptor.createFromURL(FileLocator.toFileURL(imageURL));
    } catch (final IOException e) {
        EMFComparePlugin.log(e.getMessage(), false);
    }

    if (disabledImageDescriptor != null) {
        disabledImage = disabledImageDescriptor.createImage();
    } else {
        disabledImage = ImageDescriptor.getMissingImageDescriptor().createImage();
    }
    if (enabledImageDescriptor != null) {
        enabledImage = enabledImageDescriptor.createImage();
    } else {
        enabledImage = ImageDescriptor.getMissingImageDescriptor().createImage();
    }
}

From source file:org.eclipse.emf.compare.ui.AbstractCompareAction.java

License:Open Source License

/**
 * Creates and initializes an action given its {@link ResourceBundle} and its keys prefix.
 * <p>//from  www  . java  2  s.  co m
 * Expects keys are of the form
 * <ul>
 * <li>displayed label : <code>keyPrefix</code>label (ex: compare.label)</li>
 * <li>action tooltip : <code>keyPrefix</code>tooltip (ex: compare.tooltip)</li>
 * <li>action icon : <code>keyPrefix</code>image (ex: compare.image)</li>
 * </ul>
 * </p>
 * 
 * @param bundle
 *            The bundle from which to read the keys.
 * @param keyPrefix
 *            Prefix for this action's keys.
 */
public AbstractCompareAction(ResourceBundle bundle, String keyPrefix) {
    if (keyPrefix == null || keyPrefix.length() <= 0) {
        throw new IllegalArgumentException(EMFCompareUIMessages.getString("AbstractCompareAction.IllegalKey")); //$NON-NLS-1$
    } else if (bundle == null) {
        throw new IllegalArgumentException(
                EMFCompareUIMessages.getString("AbstractCompareAction.IllegalBundle")); //$NON-NLS-1$
    }
    final String labelKey = keyPrefix + "label"; //$NON-NLS-1$
    final String tooltipKey = keyPrefix + "tooltip"; //$NON-NLS-1$
    final String imageKey = keyPrefix + "image"; //$NON-NLS-1$

    setText(bundle.getString(labelKey));
    setToolTipText(bundle.getString(tooltipKey));

    final String imagePath = bundle.getString(imageKey);
    if (imagePath != null && imagePath.trim().length() > 0) {
        String disabledImagePath;
        String enabledImagePath;

        if (imagePath.indexOf("/") >= 0) { //$NON-NLS-1$
            final String path = imagePath.substring(1);
            disabledImagePath = 'd' + path;
            enabledImagePath = 'e' + path;
        } else {
            disabledImagePath = "dlcl16/" + imagePath; //$NON-NLS-1$
            enabledImagePath = "elcl16/" + imagePath; //$NON-NLS-1$
        }

        ImageDescriptor disabledImageDescriptor = ImageDescriptor.createFromURL(FileLocator
                .find(Platform.getBundle(CompareUI.PLUGIN_ID), ICONS_PATH.append(disabledImagePath), null));
        ImageDescriptor enabledImageDescriptor = ImageDescriptor.createFromURL(FileLocator
                .find(Platform.getBundle(CompareUI.PLUGIN_ID), ICONS_PATH.append(enabledImagePath), null));

        // if the image cannot be found in CompareUIPlugin's icon path, we seek in ours.
        if (disabledImageDescriptor.equals(ImageDescriptor.getMissingImageDescriptor())) {
            try {
                disabledImageDescriptor = ImageDescriptor.createFromURL(FileLocator.toFileURL(
                        Platform.getBundle(EMFCompareUIPlugin.PLUGIN_ID).getEntry("icons/full/" + imagePath))); //$NON-NLS-1$
                enabledImageDescriptor = ImageDescriptor.createFromURL(FileLocator.toFileURL(
                        Platform.getBundle(EMFCompareUIPlugin.PLUGIN_ID).getEntry("icons/full/" + imagePath))); //$NON-NLS-1$
            } catch (IOException e) {
                EMFComparePlugin.log(e.getMessage(), false);
            }
        }

        // Sets the images.
        if (disabledImageDescriptor != null) {
            setDisabledImageDescriptor(disabledImageDescriptor);
        }
        if (enabledImageDescriptor != null) {
            setImageDescriptor(enabledImageDescriptor);
            setHoverImageDescriptor(enabledImageDescriptor);
        }
    }
}

From source file:org.eclipse.emf.search.ecore.common.ui.dialogs.AbstractModelSearchFilteredMetaElementsSelectionDialog.java

License:Open Source License

/**
  * Retrieves user contributed query image from the distant bundle.
  *///w  w  w .  jav a2  s  . c o  m
private Image getModelSearchResultImage(IModelSearchQuery query) {
    Bundle bundle = Platform.getBundle(query.getBundleSymbolicName());
    URL url = null;
    if (bundle != null) {
        url = FileLocator.find(bundle, new Path(query.getResultImagePath()), null);
        return ImageDescriptor.createFromURL(url).createImage();
    }
    return ImageDescriptor.getMissingImageDescriptor().createImage();
}

From source file:org.eclipse.emf.search.utils.ModelSearchImagesUtil.java

License:Open Source License

/**
 * Get an ImageDescriptor from a bundle ID and image relative path to the given bundle location
 * /*from w ww  .  jav a 2  s .c  o m*/
 * @param url Relative URL to the wanted image
 * 
 * @return ImageDescriptor built from the image file, Empty non null ImageDescriptor otherwise
 * 
 * @see ImageDescriptor
 */
public static ImageDescriptor getImageDescriptor(URL url) {
    ImageDescriptor desc = ImageDescriptor.getMissingImageDescriptor();
    if (imageDescriptorMap.containsKey(url)) {
        desc = imageDescriptorMap.get(url);
    } else {
        desc = ImageDescriptor.createFromURL(url);
        imageDescriptorMap.put(url, desc);
    }
    return desc;
}

From source file:org.eclipse.emf.validation.debug.ui.utils.PluginImages.java

License:Open Source License

protected PluginImages(URL baseUrl) {
    myBaseUrl = baseUrl;/*from www  .  j ava  2  s  .  c  o  m*/

    myImageRegistry = new ImageRegistry(getStandardDisplay());
    myImageDescriptors = new HashMap<String, ImageDescriptor>();

    myMissingImageDescriptor = ImageDescriptor.getMissingImageDescriptor();
    myMissingImage = null;

    declareImages();
}

From source file:org.eclipse.emf.validation.ui.internal.ValidationUIPlugin.java

License:Open Source License

/**
 * <p>// ww w.  jav  a  2s  .  co  m
 * Returns an {@link ImageDescriptor}whose path, relative to the plugin
 * directory's <tt>icons/</tt> directory, is <code>imageFile</code>. If
 * the image descriptor cannot be created, either because the file does not
 * exist or because of an internal error, then the result is the Eclipse
 * default "missing image" descriptor.
 * </p>
 * <p>
 * <b>Note </b> that the file specified must not have any leading "." or
 * path separators "/" or "\". It is strictly relative to the
 * <tt>icons/</tt> directory.
 * 
 * @param imageFile
 *            the name of the image file to retrieve
 * @return the corresponding image descriptor
 */
public static ImageDescriptor getImageDescriptor(String imageFile) {
    URL fullPath = FileLocator.find(getPlugin().getBundle(), new Path(ICONS + imageFile), null);
    if (fullPath != null) {
        return ImageDescriptor.createFromURL(fullPath);
    }

    return ImageDescriptor.getMissingImageDescriptor();
}

From source file:org.eclipse.epf.authoring.ui.internal.ImageDescriptorRegistry.java

License:Open Source License

/**
 * Returns the image associated with the given image descriptor.
 * //w w w  . j av  a2 s . co m
 * @param descriptor the image descriptor for which the registry manages an image
 * @return the image associated with the image descriptor or <code>null</code>
 *  if the image descriptor can't create the requested image.
 */
public Image get(ImageDescriptor descriptor) {
    if (descriptor == null)
        descriptor = ImageDescriptor.getMissingImageDescriptor();

    Image result = (Image) fRegistry.get(descriptor);
    if (result != null)
        return result;

    Assert.isTrue(fDisplay == AuthoringUIPlugin.getStandardDisplay(), "Allocating image for wrong display."); //$NON-NLS-1$
    result = descriptor.createImage();
    if (result != null)
        fRegistry.put(descriptor, result);
    return result;
}

From source file:org.eclipse.epf.common.plugin.AbstractPlugin.java

License:Open Source License

/**
 * Returns the image descriptor given the relative path.
 * /*  w  w w. j  ava  2  s  .c o  m*/
 * @param relativePath
 *            The image's path relative to the plug-in's root.
 * @return The image descriptor.
 */
public ImageDescriptor getImageDescriptor(String relativePath) {
    try {
        URL url = new URL(iconURL, relativePath);
        return ImageDescriptor.createFromURL(url);
    } catch (MalformedURLException e) {
        return ImageDescriptor.getMissingImageDescriptor();
    }
}

From source file:org.eclipse.epp.mpc.tests.ui.catalog.CatalogDescriptorTest.java

License:Open Source License

@Test
public void testCatalogDescriptor() throws Exception {
    URL dependenciesRepository = new URL("http://marketplace.eclipse.org/repo/");
    String description = "some description";
    ImageDescriptor icon = ImageDescriptor.getMissingImageDescriptor();
    boolean installFromAllRepositories = true;
    String label = "some label";
    URL url = new URL("http://marketplace.eclipse.org");

    CatalogDescriptor descriptor = new CatalogDescriptor();
    descriptor.setDependenciesRepository(dependenciesRepository);
    descriptor.setDescription(description);
    descriptor.setIcon(icon);//from  w  ww  .  ja va2  s.c om
    descriptor.setInstallFromAllRepositories(installFromAllRepositories);
    descriptor.setLabel(label);
    descriptor.setUrl(url);

    assertEquals(dependenciesRepository.toString(), descriptor.getDependenciesRepository().toString());
    assertEquals(description, descriptor.getDescription());
    assertEquals(icon, descriptor.getIcon());
    assertEquals(installFromAllRepositories, descriptor.isInstallFromAllRepositories());
    assertEquals(label, descriptor.getLabel());
    assertEquals(url.toString(), descriptor.getUrl().toString());

    CatalogDescriptor copyDescriptor = new CatalogDescriptor(descriptor);
    assertEquals(dependenciesRepository.toString(), copyDescriptor.getDependenciesRepository().toString());
    assertEquals(description, copyDescriptor.getDescription());
    assertEquals(icon, copyDescriptor.getIcon());
    assertEquals(installFromAllRepositories, copyDescriptor.isInstallFromAllRepositories());
    assertEquals(label, copyDescriptor.getLabel());
    assertEquals(url.toString(), copyDescriptor.getUrl().toString());

    assertTrue(descriptor.equals(copyDescriptor));
    assertEquals(descriptor.hashCode(), copyDescriptor.hashCode());

}

From source file:org.eclipse.gmf.examples.taipan.figures.ShipShape.java

License:Open Source License

protected Image getImageImage(String path) {
    Image image = JFaceResources.getImageRegistry().get(path);
    if (image == null) {
        ImageDescriptor descriptor = AbstractUIPlugin
                .imageDescriptorFromPlugin("org.eclipse.gmf.examples.taipan", path); //$NON-NLS-1$
        if (descriptor == null) {
            descriptor = ImageDescriptor.getMissingImageDescriptor();
        }//from w w  w  .j a  v  a2  s  .  c o m
        JFaceResources.getImageRegistry().put(path, image = descriptor.createImage());
    }
    return image;
}