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:fr.gouv.mindef.safran.database.ui.actions.AbstractScaffoldHandler.java

License:Open Source License

public Object execute(ExecutionEvent event) throws ExecutionException {
    ISelection selection = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage().getSelection();
    shell = HandlerUtil.getActiveShell(event);
    if (selection instanceof StructuredSelection) {
        StructuredSelection structuredSelection = (StructuredSelection) selection;
        if (structuredSelection.size() == 2) {
            ScaffoldInfo existingScaffoldInfo = getExistingScaffoldModel(structuredSelection);
            if (existingScaffoldInfo != null) {
                MessageDialog dlg = new MessageDialog(shell, "Existing scaffold model found", null,
                        "A scaffold model already exists for these objects in file "
                                + existingScaffoldInfo.eResource().getURI().toPlatformString(true)
                                + "\n\nWhat do you want to do ?",
                        MessageDialog.QUESTION_WITH_CANCEL,
                        new String[] { "Use existing scaffold", "Create a new scaffold", "Cancel" }, 0);
                int btn = dlg.open();
                if (btn == CANCEL) {
                    return null;
                } else if (btn == CREATE_NEW_SCAFFOLD) {
                    executeScaffoldingWizard(structuredSelection);
                } else if (btn == USE_EXISTING_SCAFFOLD) {
                    executeFromScaffoldModel(existingScaffoldInfo);
                }//from w  w  w  . ja  v a  2 s  .  c  o  m
            } else {
                executeScaffoldingWizard(structuredSelection);
            }

        } else if (structuredSelection.size() == 1) {
            executeFromScaffoldModel(structuredSelection);
        }
    }
    return null;
}

From source file:fr.inria.atlanmod.collaboro.ui.wizards.NewLocalCollaboroProjectWizard.java

License:Open Source License

@Override
public boolean performFinish() {
    final String projectName = newProjectPage.getProjectName();

    WorkspaceModifyOperation operation = new WorkspaceModifyOperation() {
        @Override//  ww  w . j a v a 2  s  .c  o  m
        protected void execute(IProgressMonitor progressMonitor) {
            progressMonitor.beginTask("Creating Collaboro Project", 10);

            progressMonitor.subTask("Registering packages");
            ResourceSet rset = new ResourceSetImpl();
            rset.getResourceFactoryRegistry().getExtensionToFactoryMap().put(Controller.HISTORY_EXTENSION,
                    new EcoreResourceFactoryImpl());
            rset.getPackageRegistry().put(HistoryPackage.eNS_URI, HistoryPackage.eINSTANCE);
            rset.getPackageRegistry().put(NotationPackage.eNS_URI, NotationPackage.eINSTANCE);

            rset.getResourceFactoryRegistry().getExtensionToFactoryMap().put(Controller.MODEL_EXTENSION,
                    new EcoreResourceFactoryImpl());
            rset.getResourceFactoryRegistry().getExtensionToFactoryMap().put(Controller.NOTATION_EXTENSION,
                    new EcoreResourceFactoryImpl());
            rset.getResourceFactoryRegistry().getExtensionToFactoryMap().put(Controller.ECORE_EXTENSION,
                    new EcoreResourceFactoryImpl());

            progressMonitor.worked(1);
            progressMonitor.subTask("Creating the project");
            IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
            IProject project = root.getProject(projectName);
            try {
                project.create(progressMonitor);
                project.open(progressMonitor);
            } catch (Exception e) {
                e.printStackTrace();
                MessageDialog dialog = new MessageDialog(getShell(), "Error", null,
                        "Error when creating the project in the workspace", MessageDialog.ERROR,
                        new String[] { "OK" }, 0);
                dialog.open();
                progressMonitor.done();
                return;
            }

            IFolder modelsFolder = project.getFolder("models");
            try {
                modelsFolder.create(true, true, progressMonitor);
            } catch (Exception e) {
                e.printStackTrace();
                MessageDialog dialog = new MessageDialog(getShell(), "Error", null,
                        "Error when creating the folder 'models' in the project", MessageDialog.ERROR,
                        new String[] { "OK" }, 0);
                dialog.open();
                progressMonitor.done();
                return;
            }

            IFolder examplesFolder = project.getFolder("examples");
            try {
                examplesFolder.create(true, true, progressMonitor);
            } catch (Exception e) {
                e.printStackTrace();
                MessageDialog dialog = new MessageDialog(getShell(), "Error", null,
                        "Error when creating the folder 'examples' in the project", MessageDialog.ERROR,
                        new String[] { "OK" }, 0);
                dialog.open();
                progressMonitor.done();
                return;
            }

            progressMonitor.worked(1);
            progressMonitor.subTask("Creating initial Collaboro model");
            History historyModel = createInitialHistoryModel();

            List<User> users = newUsersPage.getUsers();
            if (users != null)
                historyModel.getUsers().addAll(users);

            URI collaboroFile = URI.createPlatformResourceURI(
                    modelsFolder.getFullPath().toString() + File.separator + projectName + ".history", true);
            Resource collaboroRes = rset.createResource(collaboroFile);
            collaboroRes.getContents().add(historyModel);
            try {
                collaboroRes.save(null);
            } catch (Exception exception) {
                exception.printStackTrace();
                MessageDialog dialog = new MessageDialog(getShell(), "Error", null,
                        "Error when creating initial Collaboro model", MessageDialog.ERROR,
                        new String[] { "OK" }, 0);
                dialog.open();
                progressMonitor.done();
                return;
            }

            progressMonitor.worked(1);
            progressMonitor.subTask("Creating initial Ecore model");
            EPackage ePackage = createInitiaEcorePackage(projectName);
            URI ePackageFile = URI.createPlatformResourceURI(
                    modelsFolder.getFullPath().toString() + File.separator + projectName + ".ecore", true);
            Resource ePackageRes = rset.createResource(ePackageFile);
            ePackageRes.getContents().add(ePackage);
            try {
                ePackageRes.save(null);
            } catch (Exception exception) {
                exception.printStackTrace();
                MessageDialog dialog = new MessageDialog(getShell(), "Error", null,
                        "Error when creating initial Ecore model", MessageDialog.ERROR, new String[] { "OK" },
                        0);
                dialog.open();
                progressMonitor.done();
                return;
            }

            progressMonitor.worked(1);
            progressMonitor.subTask("Creating initial Notation model");
            Definition notation = createInitiaNotationModel();
            URI notationFile = URI.createPlatformResourceURI(
                    modelsFolder.getFullPath().toString() + File.separator + projectName + ".notation", true);
            Resource notationRes = rset.createResource(notationFile);
            notationRes.getContents().add(notation);
            try {
                notationRes.save(null);
            } catch (Exception exception) {
                exception.printStackTrace();
                MessageDialog dialog = new MessageDialog(getShell(), "Error", null,
                        "Error when creating initial Notation model", MessageDialog.ERROR,
                        new String[] { "OK" }, 0);
                dialog.open();
                progressMonitor.done();
                return;
            }

            progressMonitor.worked(6);
            progressMonitor.done();
        }
    };

    try {
        getContainer().run(false, false, operation);
    } catch (InvocationTargetException e) {
        e.printStackTrace();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }

    return true;
}

From source file:fr.inria.linuxtools.internal.tmf.ui.project.wizards.tracepkg.importexport.ImportTracePackageWizardPage.java

License:Open Source License

private int promptForOverwrite(String traceName) {
    final MessageDialog dialog = new MessageDialog(getContainer().getShell(), null, null,
            MessageFormat.format(Messages.ImportTracePackageWizardPage_AlreadyExists, traceName),
            MessageDialog.QUESTION, new String[] { IDialogConstants.NO_TO_ALL_LABEL, IDialogConstants.NO_LABEL,
                    IDialogConstants.YES_TO_ALL_LABEL, IDialogConstants.YES_LABEL, },
            3) {/*from ww w .  j a  va  2  s.  c o m*/
        @Override
        protected int getShellStyle() {
            return super.getShellStyle() | SWT.SHEET;
        }
    };
    return dialog.open();
}

From source file:fr.inria.soctrace.tools.ocelotl.ui.views.OcelotlView.java

License:Open Source License

/**
 * Set the cache strategy depending on the selected policy TODO Take the
 * operator into account//from   w w  w .ja v a 2s.co m
 */
public void setCachePolicy() {
    if (hasChanged != HasChanged.ALL)
        return;

    switch (ocelotlParameters.getOcelotlSettings().getCachePolicy()) {
    case CACHEPOLICY_FAST:
        ocelotlParameters.getDataCache().setBuildingStrategy(DatacacheStrategy.DATACACHE_PROPORTIONAL);
        break;

    case CACHEPOLICY_SLOW:
        ocelotlParameters.getDataCache().setBuildingStrategy(DatacacheStrategy.DATACACHE_DATABASE);
        break;

    case CACHEPOLICY_ASK:
        String[] dialogButtonLabels = { "Precise", "Fast", "Automatic" };
        MessageDialog choosePolicy = new MessageDialog(getSite().getShell(), "Choose a cache policy", null,
                "Please choose one of the following methods for cache rebuilding:", MessageDialog.NONE,
                dialogButtonLabels, 0);
        int choice = choosePolicy.open();

        if (choice == 0) {
            ocelotlParameters.getDataCache().setBuildingStrategy(DatacacheStrategy.DATACACHE_DATABASE);
            break;
        } else if (choice == 1) {
            ocelotlParameters.getDataCache().setBuildingStrategy(DatacacheStrategy.DATACACHE_PROPORTIONAL);
            break;
        }

    case CACHEPOLICY_AUTO:
        // TODO implement auto (decision taken when computing ratio)
        ocelotlParameters.getDataCache().setBuildingStrategy(DatacacheStrategy.DATACACHE_PROPORTIONAL);
        break;

    default:
        break;
    }
}

From source file:gda.rcp.views.NudgePositionerComposite.java

License:Open Source License

private void move(double position) throws DeviceException {
    boolean batonHeld = JythonServerFacade.getInstance().isBatonHeld();
    if (!batonHeld) {
        MessageDialog dialog = new MessageDialog(Display.getDefault().getActiveShell(), "Baton not held", null,
                "You do not hold the baton, please take the baton using the baton manager.",
                MessageDialog.ERROR, new String[] { "Ok" }, 0);
        dialog.open();
    } else if (!limitsSet || (position >= lowerLimit && position <= upperLimit) && moveEnabled)
        NudgePositionerComposite.this.scannable.asynchronousMoveTo(position);
}

From source file:gov.nasa.arc.spife.europa.clientside.xmlrpc.ClientExceptionHandler.java

License:Open Source License

private static MessageDialog openErrorDialog(final Exception e, int dialogType, String[] buttons) {

    String exceptionMessage = "unknown";
    if (e != null)
        exceptionMessage = e.getMessage();
    String causeExceptionMessage = "unknown";
    if (e != null && e.getCause() != null)
        causeExceptionMessage = e.getCause().toString();

    MessageDialog dialog = new MessageDialog(Display.getDefault().getActiveShell(), "Europa2 Problem", null,
            "There is a problem connecting with Europa2.  It is possible that "
                    + "there is a network problem.\n\n" + "Reason:  "
                    + truncateExceptionString(exceptionMessage) + "\n\nCause:  "
                    + truncateExceptionString(causeExceptionMessage),
            dialogType, buttons, 0); // 0 to select first (and only) button by default
    dialog.open();
    return dialog;
}

From source file:gov.nasa.ensemble.common.ui.EnsembleComposite.java

License:Open Source License

private void nolayout() {
    MessageDialog dialog = new MessageDialog(Display.getDefault().getActiveShell(), "EnsembleComposite", null,
            "layout must be set for EnsembleComposite: " + this, MessageDialog.ERROR, new String[] { "OK" }, 1);
    dialog.open();
    setBackground(ColorConstants.red);//from w  w w  . j  a v  a 2  s.c  o m
}

From source file:gov.nasa.ensemble.common.ui.operations.EnsembleFileSystemExportOperation.java

License:Open Source License

protected boolean queryYesNoQuestion(String message) {
    MessageDialog dialog = new MessageDialog(getShellForMessageDialog(), "Question", (Image) null, message,
            MessageDialog.NONE, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 0) {
        @Override//from   w ww. ja v a 2  s .c o  m
        protected int getShellStyle() {
            return super.getShellStyle() | SWT.SHEET;
        }
    };
    // ensure yes is the default

    return dialog.open() == 0;
}

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;//from  w  w  w.  j av  a2  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()];
}

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

License:Open Source License

/**
 * This override is provided to provide an appropriate shell vs the standard
 * approach of just using the container.
 *//*from  w  w w.  ja  v a  2s.  com*/
@Override
protected boolean queryYesNoQuestion(String message) {
    MessageDialog dialog = new MessageDialog(getShellForMessageDialog(), IDEWorkbenchMessages.Question,
            (Image) null, message, MessageDialog.NONE,
            new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 0) {
        @Override
        protected int getShellStyle() {
            return super.getShellStyle() | SWT.SHEET;
        }
    };
    // ensure yes is the default

    return dialog.open() == 0;
}