Example usage for org.eclipse.jface.dialogs MessageDialog getReturnCode

List of usage examples for org.eclipse.jface.dialogs MessageDialog getReturnCode

Introduction

In this page you can find the example usage for org.eclipse.jface.dialogs MessageDialog getReturnCode.

Prototype

public int getReturnCode() 

Source Link

Document

Returns this window's return code.

Usage

From source file:com.nokia.s60tools.analyzetool.global.Util.java

License:Open Source License

/**
 * Opens confirmation Dialog./* w w  w  . ja va2 s.c o m*/
 * 
 * @param text
 *            Dialog info text
 * @return int User selected index
 */
public static int openConfirmationDialogWithCancel(final String text) {

    Activator.getDefault().getWorkbench().getDisplay().syncExec(new Runnable() {
        public void run() {

            String[] labels = new String[3];
            labels[0] = "Yes";
            labels[1] = "No";
            labels[2] = "Cancel";
            MessageDialog mDialog = new MessageDialog(new Shell(), Constants.ANALYZE_TOOL_TITLE, null, text, 0,
                    labels, 0);
            mDialog.open();
            mDialog.create();
            retValue = mDialog.getReturnCode();
        }
    });
    return retValue;
}

From source file:com.nokia.s60tools.memspy.ui.UiUtils.java

License:Open Source License

/**
 * Advises used to install MemSpy launcher component and provides necessary action alternatives.
 * @param errorMessage error message/*  ww w .ja v a2s .  c  o  m*/
 */
private static void adviceUserToInstallLauncherComponent(final String errorMessage) {

    MessageDialog dialog = new MessageDialog(Display.getCurrent().getActiveShell(),
            IMemSpyTraceListener.ERROR_MEMSPY, null, errorMessage, MessageDialog.ERROR,
            new String[] { "Install RnD-signed MemSpy Launcher", "Open sis-file's directory in Explorer",
                    "Don't install" },
            1);
    dialog.open();

    String launcherFolder = MemSpyPlugin.getDefault().getMemspyLauncherBinDir();
    String launcherLocation = launcherFolder + File.separatorChar
            + MEM_SPY_LAUNCHER_S60_50_RN_D_SIGNED_SIS_FILE_NAME;

    // if user wants to install launcher:
    if (dialog.getReturnCode() == 0) {
        // find program for xls-filetype
        Program p = Program.findProgram(".sis");
        // if found, launch it.
        if (p != null) {
            // Check that found program was Nokia PC Suite.
            p.execute(launcherLocation);
        } else {
            Status status = new Status(IStatus.ERROR, MemSpyPlugin.PLUGIN_ID, 0,
                    "Unable to locate PC suite or other suitable software for installing .sis -file from computer. You can try installing MemSpy launcher manually from:\n"
                            + launcherLocation,
                    null);
            ErrorDialog.openError(Display.getCurrent().getActiveShell(), "MemSpy Error", null, status);
        }

    }

    // Open directory in explorer
    else if (dialog.getReturnCode() == 1) {
        try {
            String directory = Platform.getConfigurationLocation().getURL().getFile();
            directory = directory.substring(1);
            Runtime.getRuntime().exec("explorer " + launcherFolder);
        } catch (IOException e) {
            Status status = new Status(IStatus.ERROR, MemSpyPlugin.PLUGIN_ID, 0, "Unable to open Explorer",
                    null);
            ErrorDialog.openError(Display.getCurrent().getActiveShell(), IMemSpyTraceListener.ERROR_MEMSPY,
                    null, status);
            e.printStackTrace();
        }
    }

}

From source file:com.nokia.tools.screen.ui.actions.NewPackageAction.java

License:Open Source License

public void run() {
    final IEditorPart currentEditor = EclipseUtils.getActiveSafeEditor();

    if (currentEditor == null)
        return;//from w  w  w.  ja  v  a 2  s. co m

    if (currentEditor.isDirty()) {
        boolean saveWithoutConfirm = false;
        IPreferenceStore store = UiPlugin.getDefault().getPreferenceStore();
        saveWithoutConfirm = store.getBoolean(IScreenConstants.PREF_SAVE_BEFORE_PACKAGING_ASK);
        if (!saveWithoutConfirm) {
            IBrandingManager branding = BrandingExtensionManager.getBrandingManager();
            Image image = null;
            if (branding != null) {
                image = branding.getIconImageDescriptor().createImage();
            }
            MessageDialog messageDialog = new MessageDialogWithCheckBox(
                    PlatformUI.getWorkbench().getDisplay().getActiveShell(),
                    Messages.NewPackageAction_Save_MsgBox_Title, image,
                    Messages.NewPackageAction_Save_MsgBox_Message,
                    Messages.NewPackageAction_Save_MsgBox_Confirmation_text, saveWithoutConfirm, null, null,
                    null, 3, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 0);
            messageDialog.open();
            if (image != null) {
                image.dispose();
            }
            store.setValue(IScreenConstants.PREF_SAVE_BEFORE_PACKAGING_ASK,
                    ((MessageDialogWithCheckBox) messageDialog).getCheckBoxValue());

            if (messageDialog.getReturnCode() != 0)
                return;
        }
        try {
            new ProgressMonitorDialog(PlatformUI.getWorkbench().getDisplay().getActiveShell()).run(false, false,
                    new IRunnableWithProgress() {

                        /*
                         * (non-Javadoc)
                         * 
                         * @see org.eclipse.jface.operation.IRunnableWithProgress#run(org.eclipse.core.runtime.IProgressMonitor)
                         */
                        public void run(IProgressMonitor monitor)
                                throws InvocationTargetException, InterruptedException {
                            currentEditor.doSave(monitor);
                        }
                    });
        } catch (Exception e) {
            UiPlugin.error(e);
        }
        performPackaging();

    } else
        performPackaging();
}

From source file:com.twinsoft.convertigo.eclipse.dialogs.MultipleDeletionDialog.java

License:Open Source License

private boolean confirmOverwrite(String msg) {
    if (shell == null)
        return false;
    final MessageDialog dialog = new MessageDialog(shell, title, null, msg, MessageDialog.QUESTION, buttons, 0);

    shell.getDisplay().syncExec(new Runnable() {
        public void run() {
            dialog.open();/* w  w  w.  j a v a2 s  .com*/
        }
    });
    if (hasMultiple) {
        switch (dialog.getReturnCode()) {
        case 0:
            return true;
        case 1:
            confirmation = YES_TO_ALL;
            return true;
        case 2:
            return false;
        case 3:
            confirmation = NO_TO_ALL;
        default:
            return false;
        }
    } else {
        switch (dialog.getReturnCode()) {
        case 0:
            return true;
        case 1:
            return false;
        case 2:
        default:
            return false;
        }
    }
}

From source file:com.ultimatetech.cim.views.CIMInstanceView.java

License:Open Source License

private void makeActions() {
    setInstanceAct = new Action() {
        public void run() {
            //get client
            CIMClient client = null;//from  w w  w  .  java  2s.c om
            try {
                client = CIMConnect.connectUsingPreferences();
                try {
                    client.setInstance(cimInstance.getObjectPath(), cimInstance, false,
                            (String[]) changedProps.toArray(new String[] {}));
                    showMessage("Set instance successfull");
                    setInstanceAct.setEnabled(false);
                } catch (CIMException e) {
                    e.printStackTrace();
                    ErrorDialog ed = new ErrorDialog(
                            PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
                            "Set Instance Error", "Set Instance failed:" + e.getMessage(),
                            new Status(Status.ERROR, "CIMPlugin", e.getXmlCode(e.getID()), e.getMessage(), e),
                            IStatus.ERROR);
                    ed.open();
                }
            } finally {
                if (client != null) {
                    try {
                        client.close();
                    } catch (CIMException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }
            }

        }
    };
    setInstanceAct.setText("Set instance");
    setInstanceAct.setToolTipText("Set instance");
    setInstanceAct.setImageDescriptor(CIMPlugin.getImageDescriptor("icons/save.gif"));
    setInstanceAct.setDisabledImageDescriptor(CIMPlugin.getImageDescriptor("icons/save_disabled.gif"));
    setInstanceAct.setEnabled(false);
    deleteInstance = new Action() {
        public void run() {
            CIMClient client = CIMConnect.connectUsingPreferences();
            try {
                MessageDialog areYouSure = new MessageDialog(
                        PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Delete Instance?",
                        MessageDialog.getImage(MessageDialog.DLG_IMG_QUESTION), "Delete this instance?",
                        MessageDialog.QUESTION, new String[] { "OK", "Cancel" }, 0);
                areYouSure.open();
                if (areYouSure.getReturnCode() == MessageDialog.OK) {
                    client.deleteInstance(cimInstance.getObjectPath());
                    clearView();
                    CIMExplorerView cev = (CIMExplorerView) PlatformUI.getWorkbench().getActiveWorkbenchWindow()
                            .getActivePage().showView("com.ultimatetech.cim.views.CIMExplorerView");
                    cev.refreshAllTreeNodes();
                }
            } catch (CIMException e) {
                ErrorDialog ed = new ErrorDialog(
                        PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
                        "Delete Instance Error", "Delete instance failed:" + e.getMessage(),
                        new Status(Status.ERROR, "CIMPlugin", e.getXmlCode(e.getID()), e.getMessage(), e),
                        IStatus.ERROR);
                ed.open();
            } catch (Exception e) {
                ErrorDialog ed = new ErrorDialog(
                        PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
                        "Delete Instance Error", "Delete instance failed:" + e.getMessage(),
                        new Status(Status.ERROR, "CIMPlugin", 100, e.getMessage(), e), IStatus.ERROR);
                ed.open();
            } finally {
                if (client != null) {
                    try {
                        client.close();
                    } catch (CIMException e) {
                        e.printStackTrace();
                    }
                }
            }
            //showMessage("Delete instance not yet implemented");
        }
    };
    deleteInstance.setText("Delete instance");
    deleteInstance.setToolTipText("Delete instance");
    deleteInstance.setImageDescriptor(
            PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_OBJS_ERROR_TSK));

    /*doubleClickAction = new Action() {
       public void run() {
    ISelection selection = viewer.getSelection();
    Object obj = ((IStructuredSelection)selection).getFirstElement();
    showMessage("Double-click detected on "+obj.toString());
       }
    };*/

    refreshAction = new Action() {
        public void run() {
            CIMClient client = CIMConnect.connectUsingPreferences();
            try {
                cimInstance = client.getInstance(cimInstance.getObjectPath(), false, true, true, null);
                showMessage("Instance reloaded");
            } catch (CIMException e) {
                e.printStackTrace();
                ErrorDialog ed = new ErrorDialog(
                        PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
                        "Reload Instance Error", "Reload Instance failed:" + e.getMessage(),
                        new Status(Status.ERROR, "CIMPlugin", e.getXmlCode(e.getID()), e.getMessage(), e),
                        IStatus.ERROR);
                ed.open();
            } finally {
                if (client != null) {
                    try {
                        client.close();
                    } catch (CIMException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }
            }

            setInstanceAct.setEnabled(false);
        }
    };
    refreshAction.setText("Reload instance");
    refreshAction.setToolTipText("Reload instance");
    refreshAction.setImageDescriptor(
            PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_REDO));
}

From source file:com.vectrace.MercurialEclipse.wizards.ProjectsImportPage.java

License:Open Source License

/**
 * The <code>WizardDataTransfer</code> implementation of this
 * <code>IOverwriteQuery</code> method asks the user whether the existing
 * resource at the given path should be overwritten.
 *
 * @param pathString//w  w w .  j ava2  s .  c  om
 * @return the user's reply: one of <code>"YES"</code>, <code>"NO"</code>,
 *    <code>"ALL"</code>, or <code>"CANCEL"</code>
 */
public String queryOverwrite(String pathString) {

    Path path = new Path(pathString);

    String messageString;
    // Break the message up if there is a file name and a directory
    // and there are at least 2 segments.
    if (path.getFileExtension() == null || path.segmentCount() < 2) {
        messageString = "'" + pathString + "' already exists.  Would you like to overwrite it?";
    } else {
        messageString = "Overwrite '" + path.lastSegment() + "' in folder '"
                + path.removeLastSegments(1).toOSString() + "'?";
    }

    final MessageDialog dialog = new MessageDialog(getContainer().getShell(), "Question", null, messageString,
            MessageDialog.QUESTION,
            new String[] { IDialogConstants.YES_LABEL, IDialogConstants.YES_TO_ALL_LABEL,
                    IDialogConstants.NO_LABEL, IDialogConstants.NO_TO_ALL_LABEL,
                    IDialogConstants.CANCEL_LABEL },
            0) {
        @Override
        protected int getShellStyle() {
            // TODO add  "| SWT.SHEET" flag as soon as we drop Eclipse 3.4 support
            return super.getShellStyle()/* | SWT.SHEET*/;
        }
    };
    String[] response = new String[] { YES, ALL, NO, NO_ALL, CANCEL };
    // run in syncExec because callback is from an operation,
    // which is probably not running in the UI thread.
    getControl().getDisplay().syncExec(new Runnable() {
        public void run() {
            dialog.open();
        }
    });
    return dialog.getReturnCode() < 0 ? CANCEL : response[dialog.getReturnCode()];
}

From source file:de.ovgu.featureide.examples.wizards.ExampleNewWizardPage.java

License:Open Source License

/**
 * The <code>WizardDataTransfer</code> implementation of this
 * <code>IOverwriteQuery</code> method asks the user whether the existing
 * resource at the given path should be overwritten.
 * //from  ww w.j  a va  2 s. c  o m
 * @param pathString
 * @return the user's reply: one of <code>"YES"</code>, <code>"NO"</code>,
 *         <code>"ALL"</code>, or <code>"CANCEL"</code>
 */
public String queryOverwrite(String pathString) {
    Path path = new Path(pathString);

    String messageString;
    // Break the message up if there is a file name and a directory
    // and there are at least 2 segments.
    if (path.getFileExtension() == null || path.segmentCount() < 2) {
        messageString = pathString + " already exists. Would you like to overwrite it?";
    } else {
        messageString = "Overwrite " + path.lastSegment() + " in folder "
                + path.removeLastSegments(1).toOSString() + " ?";
    }

    final MessageDialog dialog = new MessageDialog(getContainer().getShell(), "Question", null, messageString,
            MessageDialog.QUESTION,
            new String[] { IDialogConstants.YES_LABEL, IDialogConstants.YES_TO_ALL_LABEL,
                    IDialogConstants.NO_LABEL, IDialogConstants.NO_TO_ALL_LABEL,
                    IDialogConstants.CANCEL_LABEL },
            0);

    // run in syncExec because callback is from an operation,
    // which is probably not running in the UI thread.
    getControl().getDisplay().syncExec(new Runnable() {
        public void run() {
            dialog.open();
        }
    });
    return dialog.getReturnCode() < 0 ? CANCEL : response[dialog.getReturnCode()];
}

From source file:distributed.plugin.ui.actions.ProcessActions.java

License:Open Source License

boolean validateSavedGraph(GraphEditor editor) {
    if (editor.isDirty()) {
        MessageDialog messageBox;
        Shell parent = getWorkbenchPart().getSite().getShell();
        String[] btnText = { "No", "Cancel", "Yes" };
        messageBox = new MessageDialog(parent, "Save", null, "Graph has been modified. Do you want to save it?",
                MessageDialog.QUESTION, btnText, 2);
        messageBox.open();//from ww w.java  2  s. c o m
        int ans = messageBox.getReturnCode();
        if (ans == 0)
            return true;
        else if (ans == 1)
            return false;
        else if (ans == 2) {
            // TODO might need to put progress monitor
            IProgressMonitor monitor = null;
            editor.doSave(monitor);
            return true;
        } else
            return false;

    } else
        return true;
}

From source file:eu.numberfour.n4js.ui.export.AbstractExportToSingleFileWizardPage.java

License:Open Source License

/**
 * The default implementation of this <code>IOverwriteQuery</code> method asks the user whether the existing
 * resource at the given path should be overwritten.
 *
 * @param pathString//from  w w w.jav a  2 s  .co m
 *            the path of the archive
 * @return the user's reply: one of <code>"YES"</code>, <code>"NO"</code>, <code>"ALL"</code>, or
 *         <code>"CANCEL"</code>
 */
@Override
public String queryOverwrite(String pathString) {

    IPath path = Path.fromOSString(pathString);

    String messageString;
    // Break the message up if there is a file name and a directory
    // and there are at least 2 segments.
    if (path.getFileExtension() == null || path.segmentCount() < 2) {
        messageString = NLS.bind(IDEWorkbenchMessages.WizardDataTransfer_existsQuestion, pathString);
    } else {
        messageString = NLS.bind(IDEWorkbenchMessages.WizardDataTransfer_overwriteNameAndPathQuestion,
                path.lastSegment(), path.removeLastSegments(1).toOSString());
    }

    final MessageDialog dialog = new MessageDialog(getContainer().getShell(), IDEWorkbenchMessages.Question,
            null, messageString, MessageDialog.QUESTION,
            new String[] { IDialogConstants.YES_LABEL, IDialogConstants.YES_TO_ALL_LABEL,
                    IDialogConstants.NO_LABEL, IDialogConstants.NO_TO_ALL_LABEL,
                    IDialogConstants.CANCEL_LABEL },
            0) {
        @Override
        protected int getShellStyle() {
            return super.getShellStyle() | SWT.SHEET;
        }
    };
    String[] response = new String[] { YES, ALL, NO, NO_ALL, CANCEL };
    // run in syncExec because callback is from an operation,
    // which is probably not running in the UI thread.
    getControl().getDisplay().syncExec(new Runnable() {
        @Override
        public void run() {
            dialog.open();
        }
    });
    return dialog.getReturnCode() < 0 ? CANCEL : response[dialog.getReturnCode()];
}

From source file:gov.nasa.ensemble.common.ui.wizard.AbstractEnsembleProjectExportWizardPage.java

License:Open Source License

@Override
public String queryOverwrite(String pathString) {

    Path path = new Path(pathString);
    String messageString;//  w w  w . jav a  2 s.  c o  m
    //Break the message up if there is a file name and a directory
    //and there are at least 2 segments.
    if (path.getFileExtension() == null || path.segmentCount() < 2) {
        // PATH_TO_FILE already exists.  Would you like to overwrite it?
        //messageString = NLS.bind(IDEWorkbenchMessages.WizardDataTransfer_existsQuestion, pathString);

        IFolder folder = ResourcesPlugin.getWorkspace().getRoot().getFolder(path);
        IPath location = folder.getLocation();
        File file = null;
        if (location == null) {
            file = new File(pathString);
        }

        else {
            file = location.toFile();
        }

        messageString = getDialogQuestionText(file);

    } else {
        messageString = NLS.bind(IDEWorkbenchMessages.WizardDataTransfer_overwriteNameAndPathQuestion,
                path.lastSegment(), path.removeLastSegments(1).toOSString());
        String osString = path.toOSString();
        Date date = new Date(new File(osString).lastModified());
        messageString += System.getProperty("line.separator") + System.getProperty("line.separator") + "'"
                + path.lastSegment() + "' was last modified on: " + date;
    }

    final MessageDialog dialog = new MessageDialog(getShellForMessageDialog(), IDEWorkbenchMessages.Question,
            null, messageString, MessageDialog.QUESTION,
            new String[] { IDialogConstants.YES_LABEL, IDialogConstants.YES_TO_ALL_LABEL,
                    IDialogConstants.NO_LABEL, IDialogConstants.NO_TO_ALL_LABEL,
                    IDialogConstants.CANCEL_LABEL },
            0) {
        @Override
        protected int getShellStyle() {
            return super.getShellStyle() | SWT.SHEET;
        }
    };
    String[] response = new String[] { YES, ALL, NO, NO_ALL, CANCEL };
    //run in syncExec because callback is from an operation,
    //which is probably not running in the UI thread.
    WidgetUtils.runInDisplayThread(getShell(), new Runnable() {
        @Override
        public void run() {
            dialog.open();
        }
    });
    return dialog.getReturnCode() < 0 ? CANCEL : response[dialog.getReturnCode()];
}