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.ge.research.sadl.ui.editor.SadlEditorCallback.java

License:Open Source License

private void handleNatureAdding(XtextEditor editor) {
    IResource resource = editor.getResource();
    if (resource != null && !toggleNature.hasNature(resource.getProject())
            && resource.getProject().isAccessible() && !resource.getProject().isHidden()) {
        String title = Messages.NatureAddingEditorCallback_MessageDialog_Title;
        String message = Messages.NatureAddingEditorCallback_MessageDialog_Msg0
                + resource.getProject().getName() + Messages.NatureAddingEditorCallback_MessageDialog_Msg1;
        MessageDialog dialog = new MessageDialog(
                editor.getEditorSite().getShell(), title, null, message, MessageDialog.QUESTION, new String[] {
                        IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL },
                0);//from ww w. java 2s. com
        int open = dialog.open();
        if (open == 0) {
            toggleNature.toggleNature(resource.getProject());
        }
    }
}

From source file:com.generalrobotix.ui.item.GrxModelItem.java

License:Open Source License

public int checkModifiedModel(boolean reload) {
    if (bModified_) {
        String mes = MessageBundle.get("GrxProjectItem.dialog.message.changeModel.mes"); //$NON-NLS-1$
        mes = NLS.bind(mes, new String[] { getName() });

        MessageDialog msgDlg = new MessageDialog(GrxUIPerspectiveFactory.getCurrentShell(),
                MessageBundle.get("GrxProjectItem.dialog.message.changeModel.title"), null, mes,
                MessageDialog.INFORMATION,
                new String[] { MessageBundle.get("GrxProjectItem.dialog.message.changeModel.btn.save"),
                        MessageBundle.get("GrxProjectItem.dialog.message.changeModel.btn.reverse"),
                        MessageBundle.get("GrxProjectItem.dialog.message.changeModel.btn.cancel") },
                2);//from  ww w  .j  a  v a 2  s  .co  m

        switch (msgDlg.open()) {
        case 0:
            if (reload) {
                if (!saveAndLoad())
                    return MODIFIED_NG;
                else
                    return MODIFIED_OK;
            } else {
                if (!_saveAs())
                    return MODIFIED_NG;
                cancelModified();
                return MODIFIED_OK;
            }
        case 1:
            if (reload) {
                if (!reload())
                    return MODIFIED_NG;
                else
                    return MODIFIED_OK;
            } else {
                cancelModified();
                return MODIFIED_OK;
            }
        case 2:
        default:
            return MODIFIED_NG;
        }
    }
    return MODIFIED_NOT;
}

From source file:com.generalrobotix.ui.item.GrxSimulationItem.java

License:Open Source License

private boolean _setupController(GrxModelItem model, ControllerAttribute deactivatedController) {
    String controllerName = model.getProperty("controller"); //$NON-NLS-1$
    if (controllerName == null || controllerName.equals("")) //$NON-NLS-1$
        return true;

    double step = model.getDbl("controlTime", 0.005); //$NON-NLS-1$
    if (stepTime_ > step) {
        MessageDialog.openInformation(GrxUIPerspectiveFactory.getCurrentShell(), "", //$NON-NLS-1$
                MessageBundle.get("GrxOpenHRPView.dialog.message.errorControlTime")); //$NON-NLS-1$
        return false;
    }//from   www .j ava 2 s  .  c  o m

    String optionAdd = null;
    if (!isTrue("integrate", true))
        optionAdd = " -nosim"; //$NON-NLS-1$

    GrxDebugUtil.println("model name = " + model.getName() + " : controller = " + controllerName //$NON-NLS-1$//$NON-NLS-2$
            + " : cycle time[s] = " + step); //$NON-NLS-1$
    GrxProcessManager pManager = (GrxProcessManager) manager_.getItem("processManager");
    ;

    boolean doRestart = false;
    org.omg.CORBA.Object cobj = GrxCorbaUtil.getReference(controllerName);
    AProcess proc = pManager.get(controllerName);
    String dir = model.getStr("setupDirectory", ""); //$NON-NLS-1$ //$NON-NLS-2$
    String com = model.getStr("setupCommand", ""); //$NON-NLS-1$ //$NON-NLS-2$

    if (cobj != null) {
        try {
            cobj._non_existent();
            if (isInteractive_ && (!com.equals("") || proc != null)) { // ask only in case being abled to restart process //$NON-NLS-1$
                MessageDialog dialog = new MessageDialog(GrxUIPerspectiveFactory.getCurrentShell(),
                        MessageBundle.get("GrxOpenHRPView.dialog.title.restartController"), null, //$NON-NLS-1$
                        MessageBundle.get("GrxOpenHRPView.dialog.message.restartController0") + controllerName //$NON-NLS-1$
                                + MessageBundle.get("GrxOpenHRPView.dialog.message.restartController1") //$NON-NLS-1$
                                + MessageBundle.get("GrxOpenHRPView.dialog.message.restartController2"), //$NON-NLS-1$
                        MessageDialog.QUESTION,
                        new String[] { MessageBundle.get("GrxOpenHRPView.dialog.button.yes"), //$NON-NLS-1$
                                MessageBundle.get("GrxOpenHRPView.dialog.button.no"), //$NON-NLS-1$
                                MessageBundle.get("GrxOpenHRPView.dialog.button.cancel") }, //$NON-NLS-1$
                        2);
                switch (dialog.open()) {
                case 0: // 0 == "YES"
                    doRestart = true;
                    break;
                case 1: // 1 == "NO"
                    if (deactivatedController != null)
                        deactivatedController.active();
                    break;
                default:
                    return false;
                }
            } else {
                if ((!com.equals("") || proc != null) && deactivatedController != null)
                    deactivatedController.active();
            }

        } catch (Exception e) {
            cobj = null;
        }
    }

    if (cobj == null || doRestart) {
        if (proc != null)
            proc.stop();

        if (!com.equals("")) { //$NON-NLS-1$
            com = dir + java.io.File.separator + com;
            String osname = System.getProperty("os.name"); //$NON-NLS-1$
            if (osname.indexOf("Windows") >= 0) { //$NON-NLS-1$
                com = "\"" + com + "\""; //$NON-NLS-1$ //$NON-NLS-2$
            }
            ProcessInfo pi = new ProcessInfo();
            pi.id = controllerName;
            pi.dir = dir;
            pi.com.add(com);
            pi.waitCount = 2000;
            pi.isCorbaServer = true;
            pi.hasShutdown = true;
            pi.doKillall = false;
            pi.autoStart = false;
            pi.autoStop = true;
            if (proc != null)
                pManager.unregister(proc.pi_.id);
            pManager.register(pi);
            proc = pManager.get(controllerName);
        }

        if (proc != null) {
            GrxDebugUtil.println("Executing controller process ..."); //$NON-NLS-1$
            GrxDebugUtil.println("dir: " + dir); //$NON-NLS-1$
            GrxDebugUtil.println("command: " + com); //$NON-NLS-1$
            proc.start(optionAdd);
        }
    }

    Date before = new Date();
    for (int j = 0;; j++) {
        cobj = GrxCorbaUtil.getReference(controllerName);
        if (cobj != null) {
            try {
                Controller controller = ControllerHelper.narrow(cobj);
                controller.setModelName(model.getName());
                controller.setDynamicsSimulator(currentDynamics_);
                if (isTrue("viewsimulate")) {//simParamPane_.isSimulatingView()) {
                    cobj = GrxCorbaUtil.getReference("ViewSimulator"); //$NON-NLS-1$
                    ViewSimulator viewsim = ViewSimulatorHelper.narrow(cobj);
                    controller.setViewSimulator(viewsim);
                }
                ControllerAttribute refAttr = _getControllerFromControllerName(controllerName);
                if (refAttr == null) {
                    controllers_
                            .add(new ControllerAttribute(model.getName(), controllerName, controller, step));
                } else {
                    refAttr.reset(controller, step);
                }
                GrxDebugUtil.println(" connected to the Controller(" + controllerName + ")\n"); //$NON-NLS-1$ //$NON-NLS-2$
                controller.setTimeStep(step);
                controller.initialize();
                controller.start();
                break;
            } catch (ControllerException e) {
                System.out.println("setupController:" + e.description);
                MessageDialog.openInformation(GrxUIPerspectiveFactory.getCurrentShell(), e.description,
                        MessageBundle.get("GrxOpenHRPView.dialog.message.failedController"));
                if (proc != null)
                    proc.stop();
                return false;
            } catch (Exception e) {
                GrxDebugUtil.printErr("setupController:", e); //$NON-NLS-1$
            }
        }

        if (j > WAIT_COUNT_ || (new Date().getTime() - before.getTime() > WAIT_COUNT_ * 1000)) {
            GrxDebugUtil.println(" failed to setup controller:" + controllerName); //$NON-NLS-1$
            //??????????EE??E??????null????
            MessageDialog dialog = new MessageDialog(GrxUIPerspectiveFactory.getCurrentShell(),
                    MessageBundle.get("GrxOpenHRPView.dialog.title.setupController"), null, //$NON-NLS-1$
                    MessageBundle.get("GrxOpenHRPView.dialog.message.setupController0") + controllerName //$NON-NLS-1$
                            + ").\n" + MessageBundle.get("GrxOpenHRPView.dialog.message.setupController1"), //$NON-NLS-1$//$NON-NLS-2$
                    MessageDialog.QUESTION,
                    new String[] { MessageBundle.get("GrxOpenHRPView.dialog.button.yes"), //$NON-NLS-1$
                            MessageBundle.get("GrxOpenHRPView.dialog.button.no"), //$NON-NLS-1$
                            MessageBundle.get("GrxOpenHRPView.dialog.button.cancel") }, //$NON-NLS-1$
                    2);
            int ans = dialog.open();
            if (ans == 0) {
                before = new Date();
                j = 0;
            } else if (ans == 1) {
                MessageDialog.openInformation(GrxUIPerspectiveFactory.getCurrentShell(), "",
                        MessageBundle.get("GrxOpenHRPView.dialog.message.failedController"));
                return false;
            } else {
                MessageDialog.openInformation(GrxUIPerspectiveFactory.getCurrentShell(), "",
                        MessageBundle.get("GrxOpenHRPView.dialog.message.failedController"));
                return false;
            }
        } else {
            try {
                Thread.sleep(1000);
            } catch (Exception e) {
            }
        }
    }

    return true;
}

From source file:com.genuitec.org.eclipse.egit.ui.internal.branch.BranchOperationUI.java

License:Open Source License

private String getTargetWithCheckoutRemoteTrackingDialog() {
    String[] buttons = new String[] { UIText.BranchOperationUI_CheckoutRemoteTrackingAsLocal,
            UIText.BranchOperationUI_CheckoutRemoteTrackingCommit, IDialogConstants.CANCEL_LABEL };
    MessageDialog questionDialog = new MessageDialog(getShell(),
            UIText.BranchOperationUI_CheckoutRemoteTrackingTitle, null,
            UIText.BranchOperationUI_CheckoutRemoteTrackingQuestion, MessageDialog.QUESTION, buttons, 0);
    int result = questionDialog.open();
    if (result == 0) {
        // Check out as new local branch
        CreateBranchWizard wizard = new CreateBranchWizard(repository, target);
        WizardDialog createBranchDialog = new WizardDialog(getShell(), wizard);
        createBranchDialog.open();/*from   w w w  . ja v  a 2 s  .  c  o m*/
        return null;
    } else if (result == 1) {
        // Check out commit
        return target;
    } else {
        // Cancel
        return null;
    }
}

From source file:com.google.appengine.eclipse.core.preferences.ui.GaePreferencePage.java

License:Open Source License

@Override
protected Control createContents(Composite parent) {
    noDefaultAndApplyButton();//from  w  w  w .  ja v  a 2s.  c  o m

    sdkSet = GaePreferences.getSdks();

    return new SdkTable<GaeSdk>(parent, SWT.NONE, sdkSet, null, this) {
        @Override
        protected IStatus doAddSdk() {
            AddSdkDialog<GaeSdk> addGaeSdkDialog = new AddSdkDialog<GaeSdk>(getShell(), sdkSet,
                    AppEngineCorePlugin.PLUGIN_ID, "Add App Engine SDK", GaeSdk.getFactory());
            if (addGaeSdkDialog.open() == Window.OK) {
                GaeSdk newSdk = addGaeSdkDialog.getSdk();
                if (newSdk != null) {
                    sdkSet.add(newSdk);
                }

                return Status.OK_STATUS;
            }

            return Status.CANCEL_STATUS;
        }

        @Override
        protected IStatus doDownloadSdk() {
            MessageDialog dialog = new MessageDialog(AppEngineCorePlugin.getActiveWorkbenchShell(),
                    "Google Eclipse Plugin", null,
                    "Would you like to open the Google App Engine download page in your "
                            + "web browser?\n\nFrom there, you can "
                            + "download the latest App Engine SDK and extract it to the"
                            + " location of your choice. Add it to Eclipse" + " with the \"Add...\" button.",
                    MessageDialog.QUESTION, new String[] { "Open Browser", IDialogConstants.CANCEL_LABEL }, 0);

            if (dialog.open() == Window.OK) {
                if (BrowserUtilities
                        .launchBrowserAndHandleExceptions(AppEngineCorePlugin.SDK_DOWNLOAD_URL) == null) {
                    return Status.CANCEL_STATUS;
                }
            } else {
                return Status.CANCEL_STATUS;
            }
            return Status.OK_STATUS;
        }
    };
}

From source file:com.google.appraise.eclipse.ui.editor.AppraiseReviewTaskActivationListener.java

License:Open Source License

/**
 * Asks the user if they want to switch to the review branch, and performs
 * the switch if so./*from  www .j  ava  2 s  . co m*/
 */
private void promptSwitchToReviewBranch(TaskRepository taskRepository, String reviewBranch) {
    MessageDialog dialog = new MessageDialog(null, "Appraise Review", null,
            "Do you want to switch to the review branch (" + reviewBranch + ")", MessageDialog.QUESTION,
            new String[] { "Yes", "No" }, 0);
    int result = dialog.open();
    if (result == 0) {
        Repository repo = AppraisePluginUtils.getGitRepoForRepository(taskRepository);
        try (Git git = new Git(repo)) {
            previousBranch = repo.getFullBranch();
            git.checkout().setName(reviewBranch).call();
        } catch (RefNotFoundException rnfe) {
            MessageDialog alert = new MessageDialog(null, "Oops", null, "Branch " + reviewBranch + " not found",
                    MessageDialog.INFORMATION, new String[] { "OK" }, 0);
            alert.open();
        } catch (Exception e) {
            AppraiseUiPlugin.logError("Unable to switch to review branch: " + reviewBranch, e);
        }
    }
}

From source file:com.google.appraise.eclipse.ui.editor.CommitAttributeEditor.java

License:Open Source License

@Override
public void createControl(final Composite parent, FormToolkit toolkit) {
    link = new Link(parent, SWT.BORDER);
    link.setText("<a>" + getValue() + "</a>");
    link.addListener(SWT.Selection, new Listener() {
        @Override//from  w  ww .  ja v a 2  s .  c  o  m
        public void handleEvent(Event event) {
            try {
                RepositoryCommit commit = getCommit();
                if (commit != null) {
                    CommitEditor.openQuiet(commit);
                } else {
                    MessageDialog alert = new MessageDialog(parent.getShell(), "Oops", null,
                            "Commit " + getValue() + " not found", MessageDialog.ERROR, new String[] { "OK" },
                            0);
                    alert.open();
                }
            } catch (IOException e) {
                AppraiseUiPlugin.logError("Error reading commit " + getValue(), e);
            }
        }
    });
    setControl(link);
}

From source file:com.google.dart.tools.search.internal.ui.util.ExtendedDialogWindow.java

License:Open Source License

private MessageDialog createClosingDialog() {
    MessageDialog result = new MessageDialog(getShell(), SearchMessages.SearchDialogClosingDialog_title, null,
            SearchMessages.SearchDialogClosingDialog_message, MessageDialog.QUESTION,
            new String[] { IDialogConstants.OK_LABEL }, 0);
    return result;
}

From source file:com.google.dart.tools.ui.internal.text.dart.CompletionProposalComputerRegistry.java

License:Open Source License

private void informUserModal(CompletionProposalComputerDescriptor descriptor, IStatus status) {
    String title = DartTextMessages.CompletionProposalComputerRegistry_error_dialog_title;
    CompletionProposalCategory category = descriptor.getCategory();
    IContributor culprit = descriptor.getContributor();
    Set affectedPlugins = getAffectedContributors(category, culprit);

    final String avoidHint;
    final String culpritName = culprit == null ? null : culprit.getName();
    if (affectedPlugins.isEmpty()) {
        avoidHint = Messages.format(DartTextMessages.CompletionProposalComputerRegistry_messageAvoidanceHint,
                new Object[] { culpritName, category.getDisplayName() });
    } else {//from   ww  w. ja  v  a 2  s  .  c  o  m
        avoidHint = Messages.format(
                DartTextMessages.CompletionProposalComputerRegistry_messageAvoidanceHintWithWarning,
                new Object[] { culpritName, category.getDisplayName(), toString(affectedPlugins) });
    }

    String message = status.getMessage();
    // inlined from MessageDialog.openError
    MessageDialog dialog = new MessageDialog(DartToolsPlugin.getActiveWorkbenchShell(), title,
            null /* default image */, message, MessageDialog.ERROR, new String[] { IDialogConstants.OK_LABEL },
            0) {
        @Override
        protected Control createCustomArea(Composite parent) {
            Link link = new Link(parent, SWT.NONE);
            link.setText(avoidHint);
            link.addSelectionListener(new SelectionAdapter() {
                @Override
                public void widgetSelected(SelectionEvent e) {
                    PreferencesUtil.createPreferenceDialogOn(getShell(),
                            "com.google.dart.tools.ui.internal.preferences.CodeAssistPreferenceAdvanced", null, //$NON-NLS-1$
                            null).open();
                }
            });
            GridData gridData = new GridData(SWT.FILL, SWT.BEGINNING, true, false);
            gridData.widthHint = this.getMinimumMessageWidth();
            link.setLayoutData(gridData);
            return link;
        }
    };
    dialog.open();
}

From source file:com.google.gapid.widgets.Licenses.java

License:Apache License

public static void showLicensesDialog(Shell shell) {
    new MessageDialog(shell, Messages.LICENSES, null, Messages.LICENSES, MessageDialog.INFORMATION, 0,
            IDialogConstants.OK_LABEL) {
        @Override//from w  w  w  .ja v a2s. c om
        protected boolean isResizable() {
            return true;
        }

        @Override
        protected Control createCustomArea(Composite parent) {
            Browser browser;
            try {
                browser = new Browser(parent, SWT.NONE);
            } catch (SWTError e) {
                // Failed to initialize the browser. Show it as a plain text widget.
                Text text = new Text(parent,
                        SWT.MULTI | SWT.READ_ONLY | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
                text.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
                text.setText(readLicenses(false));
                return text;
            }

            GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
            data.widthHint = 600;
            data.heightHint = 400;
            browser.setLayoutData(data);
            browser.setText(readLicenses(true));
            browser.addLocationListener(new LocationAdapter() {
                @Override
                public void changing(LocationEvent event) {
                    if ("about:blank".equals(event.location)) {
                        browser.setText(readLicenses(true));
                    }
                }
            });
            return browser;
        }
    }.open();
}