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: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();
        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);//from   w ww.  ja v a2 s .co m
            return true;
        } else
            return false;

    } else
        return true;
}

From source file:dk.itu.sdg.language.xwpf.resource.xwpf.ui.XwpfUIPlugin.java

License:Apache License

public static void showErrorDialog(final String title, final String message) {
    org.eclipse.swt.widgets.Display.getDefault().asyncExec(new Runnable() {
        public void run() {
            org.eclipse.swt.widgets.Shell parent = new org.eclipse.swt.widgets.Shell();
            org.eclipse.jface.dialogs.MessageDialog dialog = new org.eclipse.jface.dialogs.MessageDialog(parent,
                    title, null, message, org.eclipse.jface.dialogs.MessageDialog.ERROR,
                    new String[] { org.eclipse.jface.dialogs.IDialogConstants.OK_LABEL }, 0) {
            };/*from w  ww .  j a v  a  2 s .  co m*/
            dialog.open();
        }
    });
}

From source file:eclipse.spellchecker.preferences.OptionsConfigurationBlock.java

License:Open Source License

protected boolean processChanges(IWorkbenchPreferenceContainer container) {
    IScopeContext currContext = fLookupOrder[0];

    List<Key> changedOptions = new ArrayList<Key>();
    boolean needsBuild = getChanges(currContext, changedOptions);
    if (changedOptions.isEmpty()) {
        return true;
    }/*from   w w w .j  av a 2 s .  com*/
    if (needsBuild) {
        int count = getRebuildCount();
        if (count > fRebuildCount) {
            needsBuild = false; // build already requested
            fRebuildCount = count;
        }
    }

    boolean doBuild = false;
    if (needsBuild) {
        String[] strings = getFullBuildDialogStrings(fProject == null);
        if (strings != null) {
            if (ResourcesPlugin.getWorkspace().getRoot().getProjects().length == 0) {
                doBuild = true; // don't bother the user
            } else {
                MessageDialog dialog = new MessageDialog(getShell(), strings[0], null, strings[1],
                        MessageDialog.QUESTION, new String[] { IDialogConstants.YES_LABEL,
                                IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL },
                        2);
                int res = dialog.open();
                if (res == 0) {
                    doBuild = true;
                } else if (res != 1) {
                    return false; // cancel pressed
                }
            }
        }
    }
    if (container != null) {
        // no need to apply the changes to the original store: will be done by the page container
        if (doBuild) { // post build
            incrementRebuildCount();
            container.registerUpdateJob(CoreUtility.getBuildJob(fProject));
        }
    } else {
        // apply changes right away
        try {
            fManager.applyChanges();
        } catch (BackingStoreException e) {
            Activator.log(e);
            return false;
        }
        if (doBuild) {
            CoreUtility.getBuildJob(fProject).schedule();
        }

    }
    return true;
}

From source file:edu.toronto.cs.se.modelepedia.petrinet.operator.PetriNetSimulate.java

License:Open Source License

@Override
public EList<Model> execute(EList<Model> actualParameters) throws Exception {

    // simulate/*from w  w  w .  j a  v a2 s. co  m*/
    PetriNet petrinet = (PetriNet) actualParameters.get(0).getEMFInstanceRoot();
    boolean goodResult = !petrinet.getNodes().isEmpty();

    // show result
    Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
    int dialogType = (goodResult) ? MessageDialog.INFORMATION : MessageDialog.ERROR;
    String dialogMessage = (goodResult) ? "Good simulation result" : "Bad simulation result";
    MessageDialog dialog = new MessageDialog(shell, "Simulation results", null, dialogMessage, dialogType,
            new String[] { "Ok" }, 0);
    dialog.open();

    return null;
}

From source file:edu.tsinghua.lumaqq.ui.helper.ShellLauncher.java

License:Open Source License

/**
 * ??/*  www. j a  v  a 2  s. c om*/
 * 
  * @param url
  *       URL
  * @param title
  *       ?
  * @param errorString
  *       ?
  */
public void openBrowserShell(String url, String title, String errorString) {
    // ?????
    String browser = main.getOptionHelper().getBrowser();
    try {
        if (browser.equals("")) {
            MessageDialog dialog = new MessageDialog(main.getShell(), message_box_common_question_title, null,
                    message_box_browser_not_set, MessageDialog.QUESTION,
                    new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL,
                            IDialogConstants.CANCEL_LABEL },
                    0);

            switch (dialog.open()) {
            case 0:
                main.getShellLauncher().openSystemOptionWindow().setCurrentPage(SystemOptionWindow.OTHER);
                break;
            case 1:
                BrowserShell bs = ShellFactory.createBrowserShell(main);
                bs.setUrl(url);
                bs.setTitle(title);
                bs.open();
                break;
            }
        } else
            Runtime.getRuntime().exec(browser.replaceAll("\\[URL\\]", url));
    } catch (Throwable t) {
        MessageDialog.openWarning(main.getShell(), message_box_common_warning_title, errorString);
    }
}

From source file:edu.tsinghua.lumaqq.ui.MainShell.java

License:Open Source License

/**
 * //  www  .  j av  a 2s .c o  m
 * 
 * @param e
 */
public void onDiskDownload(IStructuredSelection s) {
    if (s.isEmpty())
        return;

    Object obj = s.getFirstElement();
    if (obj instanceof File) {
        File f = (File) obj;
        DirectoryDialog dialog = new DirectoryDialog(getShell());
        String dir = dialog.open();
        if (dir != null) {
            // ?
            if (!dir.endsWith(java.io.File.separator))
                dir += java.io.File.separatorChar;
            java.io.File diskfile = new java.io.File(dir + f.name);
            boolean resume = false;
            if (diskfile.exists()) {
                MessageDialog msg = new MessageDialog(getShell(), message_box_common_question_title, null,
                        NLS.bind(message_box_resume_file, diskfile.getAbsolutePath()), MessageDialog.QUESTION,
                        new String[] { button_resume, button_overwrite, button_cancel }, 0);
                switch (msg.open()) {
                case 0:
                    resume = true;
                    break;
                case 1:
                    resume = false;
                    break;
                default:
                    return;
                }
            }

            // 
            if (f.owner == 0)
                return;
            diskJobQueue.addJob(new DownloadFileJob(f, dir, resume));
        }
    }
}

From source file:edu.utexas.cs.orc.orceclipse.project.OrcPathEditor.java

License:Open Source License

@Override
protected String getNewInputObject() {
    // prompt dir or JAR
    final MessageDialog typeDialog = new MessageDialog(getShell(), Messages.OrcPathEditor_TypeDialogTitle, null,
            Messages.OrcPathEditor_TypeDialogMessage1 + pathDescriptionForDialogMessage
                    + Messages.OrcPathEditor_TypeDialogMessage2,
            MessageDialog.QUESTION, TYPE_DIALOG_BUTTON_LABELS, SWT.DEFAULT);
    switch (typeDialog.open()) {
    case 0: // workspace dir:
        return chooseWorkspaceFolder();
    case 1: // workspace JAR:
        return chooseWorkspaceJarFile();
    case 2: // external dir:
        final String selectedFolder = super.getNewInputObject();
        if (selectedFolder != null) {
            return Path.fromOSString(selectedFolder).addTrailingSeparator().toPortableString();
        } else {//  w w  w  .j a  v  a  2s  .  c o  m
            return null;
        }
    case 3: // external JAR:
        return chooseExternalJarFile();
    default: // canceled
        return null;
    }
}

From source file:era.foss.typeeditor.TypeDialog.java

License:Open Source License

/**
 * Ok pressed./*from ww  w  .j av  a 2s  .  c o  m*/
 * 
 * @see org.eclipse.jface.dialogs.Dialog#okPressed()
 * @since 03.03.2010
 */
protected void okPressed() {
    // validate model
    BasicDiagnostic diagnostic = Diagnostician.INSTANCE.createDefaultDiagnostic(erfModel.getCoreContent());
    for (DatatypeDefinition dataType : erfModel.getCoreContent().getDataTypes()) {
        Diagnostician.INSTANCE.validate(dataType, diagnostic);
    }
    for (SpecType specType : erfModel.getCoreContent().getSpecTypes()) {
        Diagnostician.INSTANCE.validate(specType, diagnostic);
    }
    Diagnostician.INSTANCE.validate(toolExtension, diagnostic);

    if (!diagnostic.getChildren().isEmpty()) {
        MessageDialog dialog = new MessageDialog(this.getShell(),
                typeEditorActivator.getString("_UI_ValidationErrorDialog_title"), null,
                typeEditorActivator.getString("_UI_ValidationErrorDialog_text"), MessageDialog.ERROR,
                new String[] { "OK" }, 0);
        dialog.open();

        String errorMessage = "";
        for (Diagnostic diagnosticChildren : diagnostic.getChildren()) {
            errorMessage += diagnosticChildren.getMessage() + "\n";
        }
        this.setErrorMessage(errorMessage);
    } else {
        super.okPressed();
        // the performed commands should not be available for undo after OK.
        eraCommandStack.inhibitUndos();

        // redraw the SpecObject editor
        if (editor instanceof IViewerProvider) {
            Viewer viewer = ((IViewerProvider) editor).getViewer();
            if (viewer instanceof IAllowViewerSchemaChange) {
                ((IAllowViewerSchemaChange) viewer).recreateViewerSchema();
            }
        }
    }

}

From source file:es.cv.gvcase.mdt.common.commands.DeleteDiagramCommand.java

License:Open Source License

public void redo() {
    if (getDiagramToDelete() == null) {
        return;//w w  w .ja  v  a  2  s.  c o m
    }
    // Get upper diagram to open in case the one deleted is active.
    Diagram diagramToOpen = MultiDiagramUtil.getUpperDiagram(getDiagramToDelete());
    if (diagramToOpen == null || diagramToOpen.equals(getDiagramToDelete())) {
        // This is the uppest diagram we'll look for a diagram at the same
        // level
        diagramToOpen = MultiDiagramUtil.getOtherDiagram(getDiagramToDelete());
        if (diagramToOpen == null) {
            // no suitable diagram to open
            return;
        }
    }

    // The diagram is Ok to be deleted. Ask user confirmation.
    MessageDialog confirmDialog = new MessageDialog(Display.getCurrent().getActiveShell(), "Delete diagram?",
            null, "Are you sure you want to delete the selected diagram?", MessageDialog.WARNING,
            new String[] { "Yes", "No" }, 1);
    int result = confirmDialog.open();
    if (result == Window.CANCEL) {
        return;
    }

    // modify the parent diagram of the diagrams that has this deleted
    // diagram as parent
    boolean hasParent = getDiagramToDelete().getEAnnotation(MultiDiagramUtil.UpperDiagram) == null ? false
            : true;
    for (Resource r : diagramToOpen.eResource().getResourceSet().getResources()) {
        if (r instanceof GMFResource) {
            for (EObject eo : r.getContents()) {
                if (eo instanceof Diagram) {
                    Diagram son = (Diagram) eo;
                    EAnnotation eAnnotation = son.getEAnnotation(MultiDiagramUtil.UpperDiagram);
                    if (eAnnotation != null && eAnnotation.getReferences().size() > 0
                            && (eAnnotation.getReferences().get(0) instanceof Diagram)) {
                        Diagram parent = (Diagram) eAnnotation.getReferences().get(0);
                        if (parent.equals(getDiagramToDelete())) {
                            if (!hasParent) {
                                // remove the eAnnotation
                                son.getEAnnotations().remove(MultiDiagramUtil.UpperDiagram);
                                if (diagramToOpen != null)
                                    diagramToOpen = son;
                            } else {
                                // change the parent diagram
                                Diagram parentDiagram = (Diagram) getDiagramToDelete()
                                        .getEAnnotation(MultiDiagramUtil.UpperDiagram).getReferences().get(0);
                                eAnnotation.getReferences().clear();
                                eAnnotation.getReferences().add(parentDiagram);
                            }
                        }
                    }
                }
            }
        }
    }

    IEditorPart editorPart = MDTUtil.getActiveEditor();
    if (!isDiagramActive()) {
        // If the diagram to delete is not active it can be deleted without
        // problems.
        MultiDiagramUtil.deleteDiagramAndSave(getDiagramToDelete(),
                !(editorPart instanceof MOSKittMultiPageEditor));
    } else {
        // If the diagram to delete is active, a complex process must be
        // followed to delete it.
        // Close all diagram editors that have the diagram to be deleted
        // active.
        // EditingDomainRegistry.getInstance().setChangingCachedEditors(true);
        MultiDiagramUtil.closeEditorsThatShowDiagram(getDiagramToDelete());
        // Delete diagram
        MultiDiagramUtil.deleteDiagramAndSave(getDiagramToDelete(),
                !(editorPart instanceof MOSKittMultiPageEditor));
        // Open its upper diagram
        try {
            MultiDiagramUtil.openDiagram(diagramToOpen);
        } catch (ExecutionException ex) {
            IStatus status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Can't open diagram");
            Activator.getDefault().getLog().log(status);
        } finally {
            // EditingDomainRegistry.getInstance().setChangingCachedEditors(
            // false);
            return;
        }
    }
}

From source file:es.cv.gvcase.mdt.common.part.MOSKittMultiPageEditor.java

License:Open Source License

/**
 * {@link ISaveablePart2} implementation. <br>
 * Will ask nested editors that implement ISaveablePart2 to perform their
 * prompt./*  w  w w  .j a va 2  s .c  o  m*/
 * 
 */
public int promptToSaveOnClose() {
    // clear the previous map
    mapEditorIndex2SaveOnClose.clear();
    int saveOption = ISaveablePart2.DEFAULT;
    boolean saveNeeded = false;
    ISaveablePart saveablePart1 = null;
    ISaveablePart2 saveablePart2 = null;
    String partsNamesToSave = ""; //$NON-NLS-1$
    for (int i = 0; i < getPageCount(); i++) {
        IEditorPart editor = getEditor(i);
        if (editor == null) {
            continue;
        }
        saveablePart1 = (ISaveablePart) Platform.getAdapterManager().getAdapter(editor, ISaveablePart.class);
        saveablePart2 = (ISaveablePart2) Platform.getAdapterManager().getAdapter(editor, ISaveablePart2.class);
        if (saveablePart2 != null) {
            saveOption = saveablePart2.promptToSaveOnClose();
        } else if (saveablePart1 != null) {
            saveOption = saveablePart1.isSaveOnCloseNeeded() ? ISaveablePart2.YES : ISaveablePart2.NO;
        } else {
            saveOption = ISaveablePart2.DEFAULT;
        }
        mapEditorIndex2SaveOnClose.put(i, saveOption);
        if (saveOption == ISaveablePart2.YES) {
            saveNeeded = true;
            partsNamesToSave += ((partsNamesToSave.length() == 0 ? "" //$NON-NLS-1$
                    : ", ") + getPageText(i)); //$NON-NLS-1$
        }
    }

    if (saveNeeded) {
        String message = Messages.MOSKittMultiPageEditor_15;
        String[] buttons = new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL,
                IDialogConstants.CANCEL_LABEL };
        MessageDialog dialog = new MessageDialog(
                PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
                Messages.MOSKittMultiPageEditor_16, null, message, MessageDialog.QUESTION, buttons, 0) {
            protected int getShellStyle() {
                return SWT.CLOSE | SWT.TITLE | SWT.BORDER | SWT.APPLICATION_MODAL | getDefaultOrientation();
            }
        };
        int choice = ISaveablePart2.NO;
        choice = dialog.open();
        // map value of choice back to ISaveablePart2 values
        switch (choice) {
        case 0: // Yes
            choice = ISaveablePart2.YES;
            break;
        case 1: // No
            choice = ISaveablePart2.NO;
            break;
        case 2: // Cancel
            choice = ISaveablePart2.CANCEL;
            break;
        default: // ??
            choice = ISaveablePart2.DEFAULT;
            break;
        }
        return choice;
    } else {
        return ISaveablePart2.NO;
    }
}