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:de.plugins.eclipse.depclipse.handlers.SaveJDependOutput.java

License:Open Source License

/**
 * @param file//from w  w  w.j a  va2 s . c o  m
 *            non null
 * @return OVERRIDE if file not exists or exists and may be overriden,
 *         APPEND if it exists and should be reused, CANCEL if action should
 *         be cancelled
 */
private int checkForExisting(File file) {
    if (file.exists()) {
        MessageDialog md = new MessageDialog(getShell(), Messages.SaveJDependOutput_Warning_File_already_exists,
                null, Messages.SaveJDependOutput_Warning_File_already_exists, MessageDialog.WARNING,
                new String[] { Messages.SaveJDependOutput_Append, Messages.SaveJDependOutput_Override,
                        Messages.SaveJDependOutput_Cancel },
                0);
        int result = md.open();
        switch (result) {
        case APPEND: // Append btn index
            return APPEND;
        case OVERRIDE: // Override btn index
            return OVERRIDE;
        default:
            return CANCEL;
        }
    }
    return OVERRIDE;
}

From source file:de.quamoco.adaptation.todo.listener.TodoController.java

License:Apache License

/**
 * Upon initialization all FeatureRequiredActions are executed against the {@link QualityModel}s
 * that are contained in the editingDomain to provide a consistent state. 
 *///from  w w w.j  ava  2  s.com
protected void runActionsGlobally(Map<EClass, List<FeatureRequiredAction>> eClassToFeatureRequiredActionMap) {
    // Get the QualityModels of the ResourceSet
    List<QualityModel> qualityModels = new LinkedList<QualityModel>();
    ResourceSet resourceSet = editingDomain.getResourceSet();

    for (Resource resource : resourceSet.getResources()) {
        if (resource.getContents().size() > 0) {
            if (resource.getContents().get(0) instanceof QualityModel) {
                qualityModels.add((QualityModel) resource.getContents().get(0));
            }
        }
    }

    // Gather commands for each QualityModel and for each action
    final CompoundCommand commandToExecute = new CompoundCommand();
    for (QualityModel qualityModel : qualityModels) {
        if (runGlobalActionsForModel(qualityModel)) {
            for (List<FeatureRequiredAction> actionList : eClassToFeatureRequiredActionMap.values()) {
                for (FeatureRequiredAction action : actionList) {
                    Command command = action.getCommand(qualityModel, editingDomain);
                    if (command.canExecute()) {
                        commandToExecute.append(command);
                    }
                }
            }
        }
    }

    // Execute the command on the editing domain
    // Execute in Runnable to avoid SWT actions (probably caused by update)
    PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {
        public void run() {
            if (commandToExecute.canExecute()) {
                if (adaptationModel.getRunGlobalActionsOnEditorStartup()
                        .equals(TodoActionsOnStartup.ASK_USER)) {
                    MessageDialog dialog = new MessageDialog(null, "Add Todo Tasks", null,
                            "There are some todo tasks that should be added to your model. Do you want to add them now?",
                            MessageDialog.QUESTION, new String[] { "Yes", "No" }, 0);
                    int result = dialog.open();
                    if (result == 0) {
                        editingDomain.getCommandStack().execute(commandToExecute);
                    }
                } else {
                    editingDomain.getCommandStack().execute(commandToExecute);
                }

            }
        }
    });

}

From source file:de.quamoco.qm.properties.eval.section.AbstractAggregationSection.java

License:Apache License

private Evaluation showMessage(List<Evaluation> evals) {
    String[] evalsstring = new String[evals.size()];

    for (int i = 0; i < evalsstring.length; i++) {
        evalsstring[i] = evals.get(i).getQualifiedName();
    }/*  ww  w.j  a va  2s.c  o  m*/

    MessageDialog dialog = new MessageDialog(Display.getDefault().getActiveShell(),
            "Select the evaluation to copy from", null, "Which evaluation should be copied?",
            MessageDialog.QUESTION, evalsstring, 2);
    int answer = dialog.open();

    return evals.get(answer);
}

From source file:de.quamoco.qm.properties.eval.util.Util.java

License:Apache License

public static void showOkMessageDialog(String title, String message, int dialogImageType) {
    String[] dialogButtonLabels = { IDialogConstants.OK_LABEL };
    MessageDialog dialog = new MessageDialog(null, title, null, message, dialogImageType, dialogButtonLabels,
            0);//from   w  ww  . ja va  2  s  . c  om
    dialog.open();
}

From source file:de.sebastianbenz.task.ui.editor.ExtLinkedXtextEditor.java

License:Open Source License

@Override
protected void performSaveAs(IProgressMonitor progressMonitor) {

    Shell shell = getSite().getShell();//from   w w w  . j  av  a2s.  co  m
    final IEditorInput input = getEditorInput();

    // Customize save as if the file is linked, and it is in the special external link project
    //
    if (input instanceof IFileEditorInput && ((IFileEditorInput) input).getFile().isLinked()
            && ((IFileEditorInput) input).getFile().getProject().getName()
                    .equals(ExtLinkedFileHelper.AUTOLINK_PROJECT_NAME)) {
        final IEditorInput newInput;
        IDocumentProvider provider = getDocumentProvider();

        // 1. If file is "untitled" suggest last save location
        // 2. ...otherwise use the file's location (i.e. likely to be a rename in same folder)
        // 3. If a "last save location" is unknown, use user's home
        //
        String suggestedName = null;
        String suggestedPath = null;
        {
            // is it "untitled"
            java.net.URI uri = ((IURIEditorInput) input).getURI();
            String tmpProperty = null;
            try {
                tmpProperty = ((IFileEditorInput) input).getFile()
                        .getPersistentProperty(TmpFileStoreEditorInput.UNTITLED_PROPERTY);
            } catch (CoreException e) {
                // ignore - tmpProperty will be null
            }
            boolean isUntitled = tmpProperty != null && "true".equals(tmpProperty);

            // suggested name
            IPath oldPath = URIUtil.toPath(uri);
            // TODO: input.getName() is probably always correct
            suggestedName = isUntitled ? input.getName() : oldPath.lastSegment();

            // suggested path
            try {
                suggestedPath = isUntitled
                        ? ((IFileEditorInput) input).getFile().getWorkspace().getRoot()
                                .getPersistentProperty(LAST_SAVEAS_LOCATION)
                        : oldPath.toOSString();
            } catch (CoreException e) {
                // ignore, suggestedPath will be null
            }

            if (suggestedPath == null) {
                // get user.home
                suggestedPath = System.getProperty("user.home");
            }
        }
        FileDialog dialog = new FileDialog(shell, SWT.SAVE);
        if (suggestedName != null)
            dialog.setFileName(suggestedName);
        if (suggestedPath != null)
            dialog.setFilterPath(suggestedPath);

        dialog.setFilterExtensions(new String[] { "*.todo", "*.taskpaper", "*.*" });
        String path = dialog.open();
        if (path == null) {
            if (progressMonitor != null)
                progressMonitor.setCanceled(true);
            return;
        }

        // Check whether file exists and if so, confirm overwrite
        final File localFile = new File(path);
        if (localFile.exists()) {
            MessageDialog overwriteDialog = new MessageDialog(shell, "Save As", null,
                    path + " already exists.\nDo you want to replace it?", MessageDialog.WARNING,
                    new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 1); // 'No' is the default
            if (overwriteDialog.open() != Window.OK) {
                if (progressMonitor != null) {
                    progressMonitor.setCanceled(true);
                    return;
                }
            }
        }

        IFileStore fileStore;
        try {
            fileStore = EFS.getStore(localFile.toURI());
        } catch (CoreException ex) {
            String title = "Problems During Save As...";
            String msg = "Save could not be completed. " + ex.getMessage();
            MessageDialog.openError(shell, title, msg);
            return;
        }

        IFile file = getWorkspaceFile(fileStore);
        if (file != null)
            newInput = new FileEditorInput(file);
        else {
            IURIEditorInput uriInput = new FileStoreEditorInput(fileStore);
            java.net.URI uri = uriInput.getURI();
            IFile linkedFile = linkedFileHelper.obtainLink(uri, false);

            newInput = new FileEditorInput(linkedFile);
        }

        if (provider == null) {
            // editor has been closed while the dialog was open
            return;
        }

        boolean success = false;
        try {

            provider.aboutToChange(newInput);
            provider.saveDocument(progressMonitor, newInput, provider.getDocument(input), true);
            success = true;

        } catch (CoreException x) {
            final IStatus status = x.getStatus();
            if (status == null || status.getSeverity() != IStatus.CANCEL) {
                String title = "Problems During Save As...";
                String msg = "Save could not be completed. " + x.getMessage();
                MessageDialog.openError(shell, title, msg);
            }
        } finally {
            provider.changed(newInput);
            if (success)
                setInput(newInput);
            // the linked file must be removed (esp. if it is an "untitled" link).
            linkedFileHelper.unlinkInput(((IFileEditorInput) input));
            // remember last saveAs location
            String lastLocation = URIUtil.toPath(((FileEditorInput) newInput).getURI()).toOSString();
            try {
                ((FileEditorInput) newInput).getFile().getWorkspace().getRoot()
                        .setPersistentProperty(LAST_SAVEAS_LOCATION, lastLocation);
            } catch (CoreException e) {
                // ignore
            }
        }

        if (progressMonitor != null)
            progressMonitor.setCanceled(!success);

        return;
    }

    super.performSaveAs(progressMonitor);
}

From source file:de.snertlab.xdccBee.tools.MyMessageDialog.java

License:Open Source License

public static boolean openConfirm(Shell parent, String title, String message) {
    MessageDialog dialog = new MessageDialog(parent, title, null, message, QUESTION,
            new String[] { "Ja", "Nein" }, //$NON-NLS-1$ //$NON-NLS-2$
            0);//  w w  w . j a  va  2s  .  co  m
    // ok is the default
    return dialog.open() == 0;
}

From source file:de.snertlab.xdccBee.tools.MyMessageDialog.java

License:Open Source License

public static int openConfirm3Btn(Shell parent, String title, String message) {
    MessageDialog dialog = new MessageDialog(parent, title, null, message, QUESTION,
            new String[] { "Ja", "Nein", "Abbrechen" }, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            0);//www.j a v a 2s .com
    // ok is the default
    return dialog.open();
}

From source file:de.tub.tfs.henshin.editor.ui.dialog.resources.ResourcesDialog.java

License:Open Source License

@Override
protected void okPressed() {
    IPath path = resourceGroup.getResourceFullPath();
    IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(path);

    if (file.exists() && type == SWT.SAVE) {
        String[] buttons = new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL,
                IDialogConstants.CANCEL_LABEL };
        MessageDialog confirm = new MessageDialog(getShell(), "Overwrite Question", null,
                "The file" + file.getName() + " already exists. Do you want to replace the existing file?",
                MessageDialog.QUESTION, buttons, 0);

        int result = confirm.open();

        switch (result) {
        case 0:// w ww.j  av a  2  s  . co m
            break;
        case 1:
            return;
        default:
            cancelPressed();
            break;
        }
    }

    this.result = file.getRawLocation().toFile();
    super.okPressed();
}

From source file:de.tub.tfs.muvitor.actions.DNPTBAction.java

License:Open Source License

@Override
public void run() {
    // MessageBox dialog = new MessageBox(new Shell(), SWT.ICON_WARNING);
    // dialog.setText("You pushed the button!");
    // dialog.setMessage("Please don't push the button again!");

    final MessageDialog dialog = new MessageDialog(Display.getDefault().getActiveShell(),
            "You pushed the button!", null, "Please don't push the button again!", MessageDialog.WARNING,
            new String[] { "I promise..." }, 0);
    dialog.open();
}

From source file:de.uniluebeck.itm.spyglass.gui.configuration.PluginPreferenceDialog.java

License:Open Source License

/**
 * Displays an information dialog which reminds the user that there are still unsaved changes at
 * a preference page. In respect to the type of the preference page, the user will be offered
 * the opportunity to store the changes before leaving the page.
 * //from  w  ww  .j a  va  2  s .  c  o  m
 * @returns <ul>
 *          <li>0 if there were no unsaved changes or there were unsaved changes and the user
 *          decided to save them</li>
 *          <li>1 if there were unsaved changes and the user decided to discard them</li>
 *          <li>2 if there were unsaved changes and the user decided to cancel page change</li>
 *          </ul>
 */
private int askToSaveChanges() {

    if (hasUnsavedChanges()) {

        final AbstractDatabindingPreferencePage selectedPrefPage = (AbstractDatabindingPreferencePage) preferenceDialog
                .getSelectedPage();

        if ((selectedPrefPage != null) && (selectedPrefPage instanceof AbstractDatabindingPreferencePage)) {

            final String message = "The currently opened preference page contains unsaved changes. Do you want to save now?";
            final MessageDialog dialog = new MessageDialog(preferenceDialog.getShell(), "Unsaved changes", null,
                    message, SWT.ICON_QUESTION, new String[] { "Save", "Discard", "Cancel" }, 0);
            final int answer = dialog.open();

            if (answer == 0) {
                // save the changes
                selectedPrefPage.performApply();
            } else if (answer == 1) {
                // discard the changes
                selectedPrefPage.loadFromModel();
            }

            return answer;

        } else {
            // there are unsaved changes
            return 2;
        }

    }

    // there are no unsaved changes
    return 0;
}