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

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

Introduction

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

Prototype

public int open() 

Source Link

Document

Opens this window, creating it first if it has not yet been created.

Usage

From source file:com.byterefinery.rmbench.dialogs.PrinterSetupDialog.java

License:Open Source License

protected void okPressed() {
    if (selectedPrinter != null) {

        // check margin value
        if (!validMargin((int) (margin * Display.getCurrent().getDPI().x))) {
            String[] buttons = { "Ok" };
            MessageDialog mDialog = new MessageDialog(parentShell, "Error", null,
                    Messages.PrintDialog_marginValueError, MessageDialog.ERROR, buttons, 0);
            mDialog.open();
            marginText.setFocus();//from   w w  w  .ja  va  2s  .  com
            return;
        }

        RMBenchPlugin.getPrintState().margin = margin;
        RMBenchPlugin.getPrintState().printer = selectedPrinter;
    }

    super.okPressed();
}

From source file:com.byterefinery.rmbench.util.ModelManager.java

License:Open Source License

/**
 * show a 3-option dialog asking the user whether the current model should be saved
 * /*from   ww w .j av a2  s  .c om*/
 * @return false if the dialog was cancelled, and thus the operation should not 
 * proceed
 */
private boolean querySaveModel(final Shell shell) {

    MessageDialog dialog = new MessageDialog(shell, RMBenchMessages.ModelView_SaveDlg_Title, null,
            RMBenchMessages.ModelView_SaveChanged_Message, MessageDialog.QUESTION, new String[] {
                    IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL },
            0);
    int result = dialog.open();
    if (result == 0) {
        IRunnableWithProgress runnable = new IRunnableWithProgress() {

            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {

                doSave(shell, monitor);
            }
        };
        try {
            new ProgressMonitorDialog(shell).run(false, true, runnable);
        } catch (InvocationTargetException e) {
            RMBenchPlugin.logError(e);
        } catch (InterruptedException e) {
            RMBenchPlugin.logError(e);
        }
    }

    return result != 2;
}

From source file:com.cea.papyrus.views.panels.CppAbstractPanel.java

License:Open Source License

/**
 * Action executed just before moving to the new element.
 *///from  w w w .j  av a  2s.co m
public void exitAction() {
    boolean modelChanged = false;

    // check if model was modified (read only action)
    modelChanged = checkModifications();

    // model has change, must go in a write transaction => save
    if (modelChanged) {
        MessageDialog dialog = new MessageDialog(Display.getCurrent().getActiveShell(),
                Activator.getResourceString("panel.property.dialog.saveorignore.title"),
                Activator.getImage(Activator.WARNING_IMAGE),
                Activator.getResourceString("panel.property.dialog.saveorignore"), 0,
                new String[] { Activator.getResourceString("panel.property.dialog.saveorignore.button.save"),
                        Activator.getResourceString("panel.property.dialog.saveorignore.button.ignore") },
                0);
        dialog.open();
        if (dialog.getReturnCode() == 0) { //saveButton pressed
            save();
        }
    }
}

From source file:com.centurylink.mdw.plugin.actions.WorkflowElementActionHandler.java

License:Apache License

public void run(Object element) {
    if (element instanceof WorkflowProcess) {
        WorkflowProcess processVersion = (WorkflowProcess) element;
        IEditorPart editorPart = findOpenEditor(processVersion);
        if (editorPart != null && editorPart.isDirty()) {
            if (MessageDialog.openQuestion(getShell(), "Process Launch",
                    "Save process '" + processVersion.getLabel() + "' before launching?"))
                editorPart.doSave(new NullProgressMonitor());
        }/*from ww  w  . j  a  v  a 2 s  .  c om*/

        if (MdwPlugin.getDefault().getPreferenceStore()
                .getBoolean(PreferenceConstants.PREFS_WEB_BASED_PROCESS_LAUNCH)) {
            // web-based process launch
            try {
                IViewPart viewPart = getPage().showView("mdw.views.designer.process.launch");
                if (viewPart != null) {
                    ProcessLaunchView launchView = (ProcessLaunchView) viewPart;
                    launchView.setProcess(processVersion);
                }
            } catch (PartInitException ex) {
                PluginMessages.log(ex);
            }
        } else {
            if (editorPart == null) {
                // process must be open
                open((WorkflowElement) element);
            }
            ProcessLaunchShortcut launchShortcut = new ProcessLaunchShortcut();
            launchShortcut.launch(new StructuredSelection(processVersion), ILaunchManager.RUN_MODE);
        }
    } else if (element instanceof Activity) {
        Activity activity = (Activity) element;
        WorkflowProcess processVersion = activity.getProcess();

        IEditorPart editorPart = findOpenEditor(processVersion);
        if (editorPart != null && editorPart.isDirty()) {
            if (MessageDialog.openQuestion(getShell(), "Activity Launch",
                    "Save process '" + processVersion.getLabel() + "' before launching?"))
                editorPart.doSave(new NullProgressMonitor());
        }

        ActivityLaunchShortcut launchShortcut = new ActivityLaunchShortcut();
        launchShortcut.launch(new StructuredSelection(activity), ILaunchManager.RUN_MODE);
    } else if (element instanceof ExternalEvent) {
        ExternalEvent externalEvent = (ExternalEvent) element;
        ExternalEventLaunchShortcut launchShortcut = new ExternalEventLaunchShortcut();
        launchShortcut.launch(new StructuredSelection(externalEvent), ILaunchManager.RUN_MODE);
    } else if (element instanceof Template) {
        Template template = (Template) element;
        IEditorPart editorPart = template.getFileEditor();
        if (editorPart != null && editorPart.isDirty()) {
            if (MessageDialog.openQuestion(getShell(), "Run Template",
                    "Save template '" + template.getName() + "' before running?"))
                editorPart.doSave(new NullProgressMonitor());
        }

        template.openFile(new NullProgressMonitor());
        new TemplateRunDialog(getShell(), template).open();
    } else if (element instanceof Page) {
        Page page = (Page) element;
        IEditorPart editorPart = page.getFileEditor();
        if (editorPart != null) {
            if (editorPart.isDirty()) {
                if (MessageDialog.openQuestion(getShell(), "Run Page",
                        "Save page '" + page.getName() + "' before running?"))
                    editorPart.doSave(new NullProgressMonitor());
            }
        }
        page.run();
    } else if (element instanceof WorkflowProject || element instanceof ServerSettings) {
        ServerSettings serverSettings;
        if (element instanceof WorkflowProject) {
            WorkflowProject workflowProject = (WorkflowProject) element;
            if (workflowProject.isRemote())
                throw new IllegalArgumentException("Cannot run server for remote projects.");
            serverSettings = workflowProject.getServerSettings();
        } else {
            serverSettings = (ServerSettings) element;
        }

        if (ServerRunner.isServerRunning()) {
            String question = "A server may be running already.  Shut down the currently-running server?";
            MessageDialog dlg = new MessageDialog(getShell(), "Server Running", null, question,
                    MessageDialog.QUESTION_WITH_CANCEL, new String[] { "Shutdown", "Ignore", "Cancel" }, 0);
            int res = dlg.open();
            if (res == 0)
                new ServerRunner(serverSettings, getShell().getDisplay()).stop();
            else if (res == 2)
                return;
        }

        if (serverSettings.getHome() == null && element instanceof WorkflowProject) {
            final IProject project = serverSettings.getProject().isCloudProject()
                    ? serverSettings.getProject().getSourceProject()
                    : serverSettings.getProject().getEarProject();
            @SuppressWarnings("restriction")
            org.eclipse.ui.internal.dialogs.PropertyDialog dialog = org.eclipse.ui.internal.dialogs.PropertyDialog
                    .createDialogOn(getShell(), "mdw.workflow.mdwServerConnectionsPropertyPage", project);
            if (dialog != null)
                dialog.open();
        } else {
            IPreferenceStore prefStore = MdwPlugin.getDefault().getPreferenceStore();
            if (element instanceof WorkflowProject)
                prefStore.setValue(PreferenceConstants.PREFS_SERVER_WF_PROJECT,
                        ((WorkflowProject) element).getName());
            else
                prefStore.setValue(PreferenceConstants.PREFS_RUNNING_SERVER, serverSettings.getServerName());

            ServerRunner runner = new ServerRunner(serverSettings, getShell().getDisplay());
            if (serverSettings.getProject() != null)
                runner.setJavaProject(serverSettings.getProject().getJavaProject());
            runner.start();
        }
    }
}

From source file:com.centurylink.mdw.plugin.designer.editors.ProcessEditor.java

License:Apache License

private int promptToSaveOverrideAttributes() {
    String msg = getProcess().getName() + " has unsaved override attributes.  Save changes?";
    String[] buttons = new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL };
    MessageDialog attrsSaveDialog = new MessageDialog(getSite().getShell(), "Save Attributes", null, msg,
            MessageDialog.QUESTION, buttons, 0);
    return attrsSaveDialog.open();
}

From source file:com.codesourcery.internal.installer.ui.InstallWizard.java

License:Open Source License

/**
 * Shows a cancel confirmation dialog./*w w  w.  ja  v  a 2 s. co m*/
 * 
 * @return <code>true</code> to cancel
 */
public boolean showCancelConfirmation() {
    // Confirmation message
    String confirmationMessage;
    if (isInstall()) {
        confirmationMessage = MessageFormat.format(InstallMessages.CancelInstallConfirmation2,
                new Object[] {
                        Installer.getDefault().getInstallManager().getInstallDescription().getProductName(),
                        InstallMessages.Resume, InstallMessages.Quit });
    } else {
        confirmationMessage = MessageFormat.format(InstallMessages.CancelUninstallConfirmation1,
                new Object[] { InstallMessages.Resume, InstallMessages.Quit });
    }
    // Confirm dialog
    MessageDialog confirmationDialog = new MessageDialog(getContainer().getShell(),
            InstallMessages.CancelSetupTitle, null, confirmationMessage, MessageDialog.QUESTION,
            new String[] { InstallMessages.Resume, InstallMessages.Quit }, 0);

    return (confirmationDialog.open() != 0);
}

From source file:com.conwet.wirecloud.ide.wizards.WizardProjectsImportPage.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/* ww w  . java  2 s .c  o  m*/
 * @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 = 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) {
        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() {
        public void run() {
            dialog.open();
        }
    });
    return dialog.getReturnCode() < 0 ? CANCEL : response[dialog.getReturnCode()];
}

From source file:com.drgarbage.utils.Messages.java

License:Apache License

public static int info(Shell shell, String title, String message) {
    MessageDialog dlg = new MessageDialog(shell, title, CoreImg.aboutDrGarbageIcon_16x16.createImage(), message,
            MessageDialog.INFORMATION, new String[] { IDialogConstants.OK_LABEL }, 0);
    return dlg.open();
}

From source file:com.drgarbage.utils.Messages.java

License:Apache License

public static int warning(Shell shell, String title, String message) {
    MessageDialog dlg = new MessageDialog(shell, title, CoreImg.aboutDrGarbageIcon_16x16.createImage(), message,
            MessageDialog.WARNING, new String[] { IDialogConstants.OK_LABEL }, 0);
    return dlg.open();
}

From source file:com.drgarbage.utils.Messages.java

License:Apache License

public static int error(Shell shell, String title, String message) {
    MessageDialog dlg = new MessageDialog(shell, title, CoreImg.aboutDrGarbageIcon_16x16.createImage(), message,
            MessageDialog.ERROR, new String[] { IDialogConstants.OK_LABEL }, 0);
    return dlg.open();
}