Example usage for org.eclipse.jface.dialogs Dialog DLG_IMG_QUESTION

List of usage examples for org.eclipse.jface.dialogs Dialog DLG_IMG_QUESTION

Introduction

In this page you can find the example usage for org.eclipse.jface.dialogs Dialog DLG_IMG_QUESTION.

Prototype

String DLG_IMG_QUESTION

To view the source code for org.eclipse.jface.dialogs Dialog DLG_IMG_QUESTION.

Click Source Link

Document

Image registry key for question image (value "dialog_question_image").

Usage

From source file:org.eclipse.emf.compare.mpatch.emfdiff2mpatch.actions.CompareAndTransformAction.java

License:Open Source License

/**
 * Call EMF Compare to create an emfdiff for the given models.
 * // w  w w .j a  v  a2 s  .co m
 * @param oldFile
 *            The unchanged version of a model.
 * @param newFile
 *            The changed version of the same model.
 * @param shell
 *            The shell for showing dialogs.
 * @return The emfdiff in case of successful differencing or <code>null</code> otherwise.
 */
private static ComparisonSnapshot createComparisonSnapshot(final IFile oldFile, final IFile newFile,
        Shell shell) {
    ComparisonResourceSnapshot emfdiff = null;
    try {
        // get resources
        final ResourceSet resourceSet = new ResourceSetImpl();
        final Resource oldResource = resourceSet
                .getResource(URI.createFileURI(oldFile.getFullPath().toString()), true);
        final Resource newResource = resourceSet
                .getResource(URI.createFileURI(newFile.getFullPath().toString()), true);
        if (oldResource.getContents().size() != 1)
            throw new IllegalArgumentException(
                    oldFile.getFullPath() + " is expected to contain exactly one root model element, but "
                            + oldResource.getContents().size() + " elements found!");
        if (newResource.getContents().size() != 1)
            throw new IllegalArgumentException(
                    newFile.getFullPath() + " is expected to contain exactly one root model element, but "
                            + newResource.getContents().size() + " elements found!");

        // ask user which is the modified version of the model
        @SuppressWarnings("deprecation")
        final MessageDialog dialog = new MessageDialog(shell, "Please select the modified model",
                MessageDialog.getImage(Dialog.DLG_IMG_QUESTION),
                "Please select the file which contains the MODIFIED version:", MessageDialog.QUESTION,
                new String[] { newFile.getName(), oldFile.getName() }, 0);
        final int dialogResult = dialog.open();
        if (dialogResult == SWT.DEFAULT)
            return null;

        // use emf compare to compute differences
        final EObject oldModel = (dialogResult == 0 ? oldResource : newResource).getContents().get(0);
        final EObject newModel = (dialogResult == 0 ? newResource : oldResource).getContents().get(0);
        emfdiff = CommonUtils.createEmfdiff(newModel, oldModel);
        if (emfdiff != null)
            return emfdiff;
        throw new IllegalArgumentException("EMF Compare failed to compute differences.");

    } catch (Exception e) {
        final String message = "Could not create differences with EMF Compare.";
        Emfdiff2mpatchActivator.getDefault().logError(message, e);
        MessageDialog.openError(shell, "Could not create differences with EMF Compare!",
                message + " See error log for details.\n" + "Error message: " + e.getMessage());
        return null;
    }
}

From source file:raptor.swt.RaptorImageRegistry.java

License:BSD License

/**
 * Returns the image associated with the given key in this registry, or
 * <code>null</code> if none.
 * /* www.jav a 2  s .c  o m*/
 * @param key
 *            the key
 * @return the image, or <code>null</code> if none
 */
@SuppressWarnings({ "deprecation" })
public Image get(String key) {

    // can be null
    if (key == null) {
        return null;
    }

    if (display != null) {
        /**
         * NOTE, for backwards compatibility the following images are
         * supported here, they should never be disposed, hence we
         * explicitly return them rather then registering images that SWT
         * will dispose.
         * 
         * Applications should go direclty to SWT for these icons.
         * 
         * @see Display.getSystemIcon(int ID)
         */
        int swtKey = -1;
        if (key.equals(Dialog.DLG_IMG_INFO)) {
            swtKey = SWT.ICON_INFORMATION;
        }
        if (key.equals(Dialog.DLG_IMG_QUESTION)) {
            swtKey = SWT.ICON_QUESTION;
        }
        if (key.equals(Dialog.DLG_IMG_WARNING)) {
            swtKey = SWT.ICON_WARNING;
        }
        if (key.equals(Dialog.DLG_IMG_ERROR)) {
            swtKey = SWT.ICON_ERROR;
        }
        // if we actually just want to return an SWT image do so without
        // looking in the registry
        if (swtKey != -1) {
            final Image[] image = new Image[1];
            final int id = swtKey;
            display.syncExec(new RaptorRunnable() {
                @Override
                public void execute() {
                    image[0] = display.getSystemImage(id);
                }
            });
            return image[0];
        }
    }

    Entry entry = getEntry(key);
    if (entry == null) {
        return null;
    }

    if (entry.image == null) {
        entry.image = manager.createImageWithDefault(entry.descriptor);
    }

    return entry.image;
}