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

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

Introduction

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

Prototype

public MessageDialog(Shell parentShell, String dialogTitle, Image dialogTitleImage, String dialogMessage,
        int dialogImageType, int defaultIndex, String... dialogButtonLabels) 

Source Link

Document

Create a message dialog.

Usage

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  a  va  2s.c  om
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());
        }/*  w w w. ja  va  2  s. c o  m*/

        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.//from   w  w w.ja  v a 2 s . c o  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.codesourcery.internal.installer.ui.WizardDialog.java

License:Open Source License

/**
 * Creates and return a new wizard closing dialog without opening it.
 * /*  w w  w .ja  va 2  s  .c  om*/
 * @return MessageDalog
 */
private MessageDialog createWizardClosingDialog() {
    MessageDialog result = new MessageDialog(getShell(), JFaceResources.getString("WizardClosingDialog.title"), //$NON-NLS-1$
            null, JFaceResources.getString("WizardClosingDialog.message"), //$NON-NLS-1$
            MessageDialog.QUESTION, new String[] { IDialogConstants.OK_LABEL }, 0) {
        protected int getShellStyle() {
            return super.getShellStyle() | SWT.SHEET;
        }
    };
    return result;
}

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// www  . j  a va2  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();
}

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

License:Apache License

/**
 * Convenient method to open a simple confirm (OK/Cancel) dialog.
 * // w w w .  j  ava  2 s  .c  o m
 * @param parent
 *            the parent shell of the dialog, or <code>null</code> if none
 * @param title
 *            the dialog's title, or <code>null</code> if none
 * @param message
 *            the message
 * @return <code>true</code> if the user presses the OK button,
 *         <code>false</code> otherwise
 */
public static boolean openConfirm(Shell parent, String title, String message, String[] buttons) {
    MessageDialog dialog = new MessageDialog(parent, title, CoreImg.aboutDrGarbageIcon_16x16.createImage(),
            message, MessageDialog.QUESTION, buttons, 0); /* OK is the default */
    return dialog.open() == 0;
}