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:es.cv.gvcase.mdt.common.util.MultiDiagramUtil.java

License:Open Source License

/**
 * Perform delete {@link Diagram}./*from ww w  .  j  av  a2s.  c om*/
 * 
 * @param diagram
 *            the diagram
 * @param confirm
 *            the confirm
 * 
 * @return the diagram
 */
public static Diagram performDeleteDiagram(Diagram diagram, boolean confirm) {
    if (diagram == null) {
        return null;
    }
    // Get upper diagram to open in case the one deleted is active.
    Diagram diagramToOpen = getUpperDiagram(diagram);
    if (diagramToOpen == null || diagramToOpen.equals(diagram)) {
        // This is the uppest diagram we'll look for a diagram at the same
        // level
        diagramToOpen = getOtherDiagram(diagram);
        if (diagramToOpen == null) {
            // no suitable diagram to open
            return null;
        }
    }

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

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

From source file:eu.aniketos.securebpmn.util.DialogUtil.java

License:Apache License

/**
 * Opens a dialog window that contains an image and a message.
 *
 * @param title//from  w ww .java  2s . c  o  m
 *            The title of the message window.
 * @param message
 *            The message to be displayed in the window.
 * @param image
 *            The image that should be displayed in the window.
 * @param buttons
 *            The labels of the Buttons the window should contain.
 * @param defaultButton
 *            The index of the Button that should be selected by default.
 * @return The index of the Button that was pressed.
 */
public static int openMessageDialog(String title, String message, int image, String[] buttons,
        int defaultButton) {
    MessageDialog dialog;
    switch (image) {
    case INFO:
        dialog = new MessageDialog(getShell(), title, null, message, MessageDialog.INFORMATION, buttons,
                defaultButton);
        break;
    case WARNING:
        dialog = new MessageDialog(getShell(), title, null, message, MessageDialog.WARNING, buttons,
                defaultButton);
        break;
    case ERROR:
        dialog = new MessageDialog(getShell(), title, null, message, MessageDialog.ERROR, buttons,
                defaultButton);
        break;
    default:
        dialog = new MessageDialog(getShell(), title, null, message, MessageDialog.NONE, buttons,
                defaultButton);
        break;
    }
    return dialog.open();
}

From source file:eu.cloudwave.wp5.feedback.eclipse.base.ui.dialogs.AbstractMessageDialog.java

License:Apache License

/**
 * Displays the current {@link MessageDialog}.
 * /*from ww w . ja v a 2 s.  c o  m*/
 * @param title
 *          the title of the {@link MessageDialog}
 * @param message
 *          the message of the {@link MessageDialog}
 * @param dialogImageType
 *          one of the following values:
 *          <ul>
 *          <li>MessageDialog.NONE for a dialog with no image</li>
 *          <li>MessageDialog.ERROR for a dialog with an error image</li>
 *          <li>MessageDialog.INFORMATION for a dialog with an information image</li>
 *          <li>MessageDialog.QUESTION for a dialog with a question image</li>
 *          <li>MessageDialog.WARNING for a dialog with a warning image</li>
 *          </ul>
 * @param buttonText
 *          the text of the button
 */
public final void display(final String title, final String message, final int dialogImageType,
        final String buttonText) {
    new AbstractUiTask() {
        @Override
        public void doWork() {
            final Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
            final String[] buttons = new String[] { "Cancel", buttonText };
            final MessageDialog messageDialog = new MessageDialog(shell, title, null, message,
                    MessageDialog.ERROR, buttons, 0);
            final int action = messageDialog.open();
            if (action == 1) {
                action(shell);
            }
        }
    }.run();
}

From source file:eu.esdihumboldt.hale.io.haleconnect.ui.projects.ShareProjectWizard.java

License:Open Source License

@Override
public boolean performFinish() {
    boolean result = super.performFinish();

    if (result) {
        try {//from w  w  w  .ja va  2s  .  co  m
            URI clientAccessUrl = this.getProvider().getClientAccessUrl();
            MessageDialog successDialog = new MessageDialog(getShell(), "Project upload successful", null,
                    "Project was successfully uploaded to hale connect.", MessageDialog.INFORMATION,
                    new String[] { IDialogConstants.OK_LABEL }, 0) {

                @Override
                protected Control createCustomArea(Composite parent) {
                    Link link = new Link(parent, SWT.WRAP);
                    link.setText(MessageFormat.format(
                            "To access this project online, please visit the following URL (login may be required):\n<a href=\"{0}\">{0}</a>.",
                            clientAccessUrl));
                    link.addSelectionListener(new SelectionAdapter() {

                        @Override
                        public void widgetSelected(SelectionEvent e) {
                            try {
                                // Open default external browser
                                PlatformUI.getWorkbench().getBrowserSupport().getExternalBrowser()
                                        .openURL(new URL(e.text));
                            } catch (Exception ex) {
                                log.error(MessageFormat.format("Error opening browser: {0}", ex.getMessage()),
                                        e);
                            }
                        }
                    });
                    return link;
                }

            };
            successDialog.open();

            log.info(MessageFormat.format(
                    "Project was successfully uploaded to hale connect and is available online at \"{0}\"",
                    clientAccessUrl));
        } catch (IllegalArgumentException e) {
            // bad base path?
            log.error(MessageFormat.format("Error creating client access URL: {0}", e.getMessage()), e);
            log.userInfo("Project was successfully uploaded to hale connect.");
        }
    }

    return result;
}

From source file:eu.geclipse.ui.internal.actions.DeleteGridElementAction.java

License:Open Source License

private void deleteWorkflowJobDescriptions(final List<IGridJobDescription> selectedJobDescriptions) {
    MessageDialog dialog = null;
    String dialogMessage = ""; //$NON-NLS-1$
    if (selectedJobDescriptions.size() == 1) {
        IGridJobDescription selectedJobDesc = selectedJobDescriptions.get(0);
        String jsdl = selectedJobDesc.getResource().getName();
        dialogMessage = String.format(Messages.getString("DeleteGridElementAction.confirmJobDescDeleteOne"), //$NON-NLS-1$
                jsdl);/* www  . java 2s. c  o  m*/
    } else {
        String jsdlList = ""; //$NON-NLS-1$
        for (Iterator<IGridJobDescription> i = selectedJobDescriptions.iterator(); i.hasNext();) {
            jsdlList = jsdlList + " " + i.next().getResource().getName(); //$NON-NLS-1$
        }
        dialogMessage = String.format(Messages.getString("DeleteGridElementAction.confirmJobDescDeleteMany"), //$NON-NLS-1$
                jsdlList);
    }
    dialog = new MessageDialog(DeleteGridElementAction.this.shell,
            Messages.getString("DeleteGridElementAction.confirmationTitle"), //$NON-NLS-1$
            null, dialogMessage, MessageDialog.WARNING,
            new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 0);

    if (dialog.open() == Window.OK) {
        try {
            for (Iterator<IGridJobDescription> i1 = selectedJobDescriptions.iterator(); i1.hasNext();) {
                IResource r = i1.next().getResource();
                r.delete(true, new NullProgressMonitor()); // TODO add a proper progress monitor to use           
            }

        } catch (CoreException e) {
            // TODO Auto-generated catch block, add proper problem reporting
            e.printStackTrace();
        }
    }
}

From source file:eu.geclipse.ui.internal.transfer.GridElementTransferOperation.java

License:Open Source License

private void askOverwrite(final TransferParams data, final IFileInfo targetInfo) {

    class Runner implements Runnable {
        int exitCode;
        private final Display display;

        Runner(final Display display) {
            this.display = display;
        }/*w w  w . j a  v  a2s  .  c  o  m*/

        public void run() {
            Shell shell = null;
            String[] labels = { Messages.getString("GridElementTransferOperation.buttonYes"), //$NON-NLS-1$
                    Messages.getString("GridElementTransferOperation.buttonYesAll"), //$NON-NLS-1$
                    Messages.getString("GridElementTransferOperation.buttonNo"), //$NON-NLS-1$
                    Messages.getString("GridElementTransferOperation.buttonNoAll"), //$NON-NLS-1$
                    Messages.getString("GridElementTransferOperation.buttonCancel") }; //$NON-NLS-1$

            if (this.display != null) {
                shell = this.display.getActiveShell();
            }

            String message = String.format(Messages.getString("GridElementTransferOperation.overwriteMsg"), //$NON-NLS-1$
                    data.targetFile.getName(), formatURI(data.targetFile.toURI()),
                    formatDate(targetInfo.getLastModified()), formatURI(data.sourceFile.toURI()), "" //$NON-NLS-1$
            );

            MessageDialog dialog = new MessageDialog(shell,
                    Messages.getString("GridElementTransferOperation.overwriteTitle"), //$NON-NLS-1$
                    null, message, MessageDialog.QUESTION, labels, 0);
            this.exitCode = dialog.open();
        }
    }

    Display display = PlatformUI.getWorkbench().getDisplay();
    Runner runner = new Runner(display);
    display.syncExec(runner);

    switch (runner.exitCode) {
    case 0:
        deleteTarget(data);
        break;

    case 1:
        this.overwriteMode = OverwriteMode.OVERWRITE_ALL;
        deleteTarget(data);
        break;

    case 2:
        ignoreTransfer(data);
        break;

    case 3:
        this.overwriteMode = OverwriteMode.IGNORE_ALL;
        ignoreTransfer(data);
        break;

    case 4:
        data.status = Status.CANCEL_STATUS;
        data.monitor.setCanceled(true);
        break;
    }
}

From source file:eu.geclipse.workflow.ui.edit.policies.WorkflowJobDragDropEditPolicy.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override/*w  w  w  .  j av  a 2s.  c  o m*/
public Command getDropObjectsCommand(DropObjectsRequest dropRequest) {
    List objects = dropRequest.getObjects();
    CompoundCommand cmd = new CompoundCommand();
    JSDLJobDescription jsdl = null;

    for (Object o : objects) {

        if (o instanceof JSDLJobDescription) {
            jsdl = (JSDLJobDescription) o;
            this.selectedElement = (WorkflowJobEditPart) getHost();
            IWorkflowJob selectedJob = (IWorkflowJob) this.selectedElement.resolveSemanticElement();

            CopyJobDescToWorkflowCommand copyCmd = new CopyJobDescToWorkflowCommand(
                    this.selectedElement.resolveSemanticElement(), jsdl);
            UpdateJobPortsCommand updatePortsCmd = new UpdateJobPortsCommand(this.selectedElement, jsdl);

            if (!(selectedJob.getName() == null && selectedJob.getJobDescription() == null)) {
                MessageDialog confirmDialog = new MessageDialog(null,
                        Messages.getString("WorkflowJobDragDropEditPolicy_confirmationTitle"), //$NON-NLS-1$
                        null, Messages.getString("WorkflowJobDragDropEditPolicy_userPrompt"), //$NON-NLS-1$
                        true ? MessageDialog.QUESTION : MessageDialog.WARNING,
                        new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 0);
                int result = confirmDialog.open();
                if (result == 0) {
                    cmd.add(new ICommandProxy(copyCmd));
                    cmd.add(new ICommandProxy(updatePortsCmd));
                }
            } else {
                cmd.add(new ICommandProxy(copyCmd));
                cmd.add(new ICommandProxy(updatePortsCmd));
            }
        }

        return cmd;
    }
    return super.getDropObjectsCommand(dropRequest);
}

From source file:eu.geclipse.workflow.ui.internal.actions.GetJobDescriptionFromFileAction.java

License:Open Source License

/**
 * Fires up a GridFileDialog and fetches the contents of a user-chosen JSDL
 * file.//w  ww .  ja  v  a  2  s  .  c om
 */
public void run(final IAction action) {
    FileDialog dialog = new FileDialog(this.myShell, SWT.OPEN);
    String[] exts = { "*.jsdl" }; //$NON-NLS-1$
    dialog.setFilterExtensions(exts);
    // this bit find the root directory of the workflow
    TransactionalEditingDomain domain = this.mySelectedElement.getEditingDomain();
    ResourceSet resourceSet = domain.getResourceSet();
    Resource res = resourceSet.getResources().get(0);
    URI wfRootUri = res.getURI();
    String wfRootPath = wfRootUri.path();
    this.dirs = wfRootPath.split("/"); //$NON-NLS-1$
    String projectName = this.dirs[2];
    this.wfRootFileStore = GridModel.getRoot().getFileStore().getChild(projectName);
    dialog.setFilterPath(this.wfRootFileStore.toString());
    if (dialog.open() != null) {
        String result = dialog.getFileName();
        if ((result != null) && (result.length() > 0)) {
            String filePath = dialog.getFilterPath() + "/" + result; //$NON-NLS-1$
            // filePath = filePath.replace(' ', '+');
            java.net.URI filePathUri = null;
            filePathUri = URIUtil.toURI(filePath);
            IFile jsdlFile = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocationURI(filePathUri)[0];
            IWorkflowJob selectedJob = (IWorkflowJob) this.mySelectedElement.resolveSemanticElement();
            if (!(selectedJob.getName() == null && selectedJob.getJobDescription() == null)) {
                MessageDialog confirmDialog = new MessageDialog(null,
                        Messages.getString("WorkflowJobDragDropEditPolicy_confirmationTitle"), //$NON-NLS-1$
                        null, Messages.getString("WorkflowJobDragDropEditPolicy_userPrompt"), //$NON-NLS-1$
                        true ? MessageDialog.QUESTION : MessageDialog.WARNING,
                        new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 0);
                int confirmResult = confirmDialog.open();
                if (confirmResult == 0) {
                    JSDLJobDescription jsdl = new JSDLJobDescription(jsdlFile);
                    AbstractTransactionalCommand copyCommand = new CopyJobDescToWorkflowCommand(
                            this.mySelectedElement.resolveSemanticElement(), jsdl);
                    AbstractTransactionalCommand updatePortsCommand = new UpdateJobPortsCommand(
                            GetJobDescriptionFromFileAction.this.mySelectedElement, jsdl);
                    try {
                        OperationHistoryFactory.getOperationHistory().execute(copyCommand,
                                new NullProgressMonitor(), null);
                        OperationHistoryFactory.getOperationHistory().execute(updatePortsCommand,
                                new NullProgressMonitor(), null);
                    } catch (ExecutionException eE) {
                        eE.printStackTrace();
                    }
                }
            }
        }
    }
}

From source file:eu.hydrologis.jgrass.console.editor.actions.ConsoleEditorActionCompile.java

License:Open Source License

public void run() {

    Display.getDefault().asyncExec(new Runnable() {

        public void run() {

            JGrass console = ConsolePlugin.console();
            if (null == console) {

                MessageDialog dialog = new MessageDialog(null, "Info", null, "Missing JGrass ConsoleEngine.",
                        MessageDialog.INFORMATION, new String[] { "Ok" }, 0);
                dialog.setBlockOnOpen(true);
                dialog.open();
            } else {

                // JavaEditor editor = (JavaEditor) getTextEditor();
                // ProjectOptions projectOptions = editor.projectOptions();
                // PreferencesInitializer.initialize(projectOptions);
                // projectOptions
                // .setOption(ProjectOptions.CONSOLE_COMPILE_ONLY, new Boolean(true));
                // IDocument doc = editor.getDocumentProvider().getDocument(
                // editor.getEditorInput());
                // editor.getTextConsole().clearConsole();
                // console.dispatch(projectOptions, doc.get());
                //                    
                String text = null;
                JavaEditor editor = (JavaEditor) getTextEditor();
                ISelection selection = editor.getSelectionProvider().getSelection();
                if (selection instanceof ITextSelection) {
                    ITextSelection textSelection = (ITextSelection) selection;
                    if (!textSelection.isEmpty()) {
                        text = textSelection.getText();
                    }//from  w w  w  . j a v  a2s  . co  m
                }

                ProjectOptions projectOptions = editor.projectOptions();
                PreferencesInitializer.initialize(projectOptions);

                // FIXME check how GRASS preferences are saved in the preferencespage
                // Object option = projectOptions.getOption(ProjectOptions.COMMON_GRASS_MAPSET);

                projectOptions.setOption(ProjectOptions.CONSOLE_COMPILE_ONLY, new Boolean(true));
                IDocument doc = editor.getDocumentProvider().getDocument(editor.getEditorInput());
                editor.getTextConsole().clearConsole();
                if (text == null || 0 >= text.length()) {
                    text = doc.get();
                }
                console.dispatch(projectOptions, text);
            }
        }
    });
}

From source file:eu.hydrologis.jgrass.console.editor.actions.ConsoleEditorActionRun.java

License:Open Source License

public void run() {

    Display.getDefault().asyncExec(new Runnable() {

        public void run() {

            JGrass console = ConsolePlugin.console();
            if (null == console) {

                MessageDialog dialog = new MessageDialog(null, "Info", null, "Missing JGrass ConsoleEngine.",
                        MessageDialog.INFORMATION, new String[] { "Ok" }, 0);
                dialog.setBlockOnOpen(true);
                dialog.open();
            } else {
                JavaEditor editor = (JavaEditor) getTextEditor();
                IDocument doc = editor.getDocumentProvider().getDocument(editor.getEditorInput());
                editor.getTextConsole().clearConsole();

                ProjectOptions projectOptions = editor.projectOptions();
                PreferencesInitializer.initialize(projectOptions);
                projectOptions.setOption(ProjectOptions.CONSOLE_COMPILE_ONLY, new Boolean(false));

                String text = null;
                ISelection selection = editor.getSelectionProvider().getSelection();
                if (selection instanceof ITextSelection) {
                    ITextSelection textSelection = (ITextSelection) selection;
                    if (!textSelection.isEmpty()) {
                        text = textSelection.getText();
                    }//from   w ww . j a  v  a2s  .  com
                }
                if (text == null || 0 >= text.length()) {
                    text = doc.get();
                }

                if (text != null) {
                    List<String> commandsOnly = new ArrayList<String>();
                    List<String> settingsOnly = new ArrayList<String>();

                    // extract only the commands
                    String[] scriptSplit = text.split("\n"); //$NON-NLS-1$
                    for (String string : scriptSplit) {
                        if (string.trim().startsWith("#")) {
                            continue;
                        }
                        commandsOnly.add(string);
                    }
                    // from the whole document extract the settings, even id not selected
                    String allText = doc.get();
                    String[] allSplit = allText.split("\n"); //$NON-NLS-1$
                    for (String string : allSplit) {
                        if (string.trim().startsWith("#")) {
                            settingsOnly.add(string);
                        }
                    }

                    StringBuffer sB = new StringBuffer();
                    for (String string : settingsOnly) {
                        sB.append(string).append("\n");
                    }
                    sB.append("\n\n");
                    for (String string : commandsOnly) {
                        sB.append(string).append("\n");
                    }

                    text = sB.toString();
                }

                console.dispatch(projectOptions, text);
            }
        }
    });
}