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:de.ovgu.featureide.ui.statistics.core.CsvExporter.java

License:Open Source License

/**
 * Puts the description of each selected node in the first row as header and
 * it's value in the second row.//from  ww w.j a  v a  2  s . c  o m
 * 
 */
private void actualExport() {
    Job job = new Job("Export statistics into csv") {

        private StringBuilder firstBuffer;
        private StringBuilder secondBuffer;

        @Override
        protected IStatus run(IProgressMonitor monitor) {

            List<String> descs = new LinkedList<String>();
            List<String> vals = new LinkedList<String>();
            getExportData(descs, vals);
            firstBuffer = new StringBuilder();
            secondBuffer = new StringBuilder();
            prepareDataForExport(descs, vals, firstBuffer, secondBuffer);
            return actualWriting();
        }

        /**
         * @param firstBuffer
         * @param secondBuffer
         * @return
         */
        private IStatus actualWriting() {
            BufferedWriter writer = null;

            if (!returnVal.endsWith(".csv")) {
                returnVal += ".csv";
            }
            File file = new File(returnVal);
            try {
                if (!file.exists()) {
                    file.createNewFile();
                }
                writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file)));
                writer.write(firstBuffer.toString());
                writer.newLine();
                writer.write(secondBuffer.toString());
            } catch (FileNotFoundException e) {
                giveUserFeedback(true);
                return Status.CANCEL_STATUS;
            } catch (IOException e) {
                UIPlugin.getDefault().logError(e);
            } finally {
                if (writer != null) {
                    try {
                        writer.close();
                    } catch (IOException e) {
                        UIPlugin.getDefault().logError(e);
                    }
                }
            }
            giveUserFeedback(false);
            return Status.OK_STATUS;
        }

        /**
         * 
         */
        private void giveUserFeedback(final boolean error) {
            UIJob errorJob = new UIJob(error ? "show errordialog" : "show dialog") {

                @Override
                public IStatus runInUIThread(IProgressMonitor monitor) {
                    Shell shell = Display.getDefault().getActiveShell();
                    if (error) {
                        MessageDialog dial = new MessageDialog(shell, "Error", GUIDefaults.FEATURE_SYMBOL,
                                "The file cannot be accessed!\nTry again?", MessageDialog.ERROR,
                                new String[] { "OK", "Cancel" }, 0);
                        if (dial.open() == 0) {
                            actualWriting();
                        }
                    } else {
                        // MessageDialog.openInformation(shell, ,
                        // "Data was successfully exported.");
                        new MessageDialog(shell, "Success", GUIDefaults.FEATURE_SYMBOL,
                                "Data was successfully exported", MessageDialog.INFORMATION,
                                new String[] { "OK" }, 0).open();
                    }

                    return Status.OK_STATUS;
                }
            };
            errorJob.setPriority(INTERACTIVE);
            errorJob.schedule();
        }

        /**
         * @param descs
         * @param vals
         * @param buffer
         * @param secBuf
         */
        private void prepareDataForExport(List<String> descs, List<String> vals, StringBuilder buffer,
                StringBuilder secBuf) {
            for (String desc : descs) {
                buffer.append(desc);
                buffer.append(SEPARATOR);
            }
            for (String val : vals) {
                secBuf.append(val);
                secBuf.append(SEPARATOR);
            }
        }

        /**
         * @param descs
         * @param vals
         */
        private void getExportData(List<String> descs, List<String> vals) {
            descs.add("Description: ");
            vals.add("Value: ");
            Parent last = null;
            for (Object o : visibleExpandedElements) {
                if (o instanceof Parent) {
                    Parent parent = ((Parent) o);
                    if (parent.getParent().equals(last)) {
                        int end = descs.size() - 1;
                        descs.set(end, descs.get(end) + ":");
                    }
                    descs.add(parent.getDescription());
                    vals.add(parent.getValue() != null ? parent.getValue().toString() : "");
                    last = parent;
                }
            }
        }
    };
    job.setPriority(Job.SHORT);
    job.schedule();
}

From source file:de.ovgu.featureide.ui.views.collaboration.action.DeleteAction.java

License:Open Source License

public void run() {
    MessageDialog messageDialog = new MessageDialog(null, "Delete Resources", null,
            "Are you sure you want to remove " + getDialogText(), MessageDialog.INFORMATION,
            new String[] { "OK", "Cancel" }, 0);
    if (messageDialog.open() != 0) {
        return;/*  w w w.jav a  2 s.co m*/
    }
    if (part instanceof RoleEditPart) {
        Role role = ((RoleEditPart) part).getRoleModel();
        try {
            role.getRoleFile().delete(true, null);
        } catch (CoreException e) {
            UIPlugin.getDefault().logError(e);
        }
    } else if (part instanceof ClassEditPart) {
        Class c = ((ClassEditPart) part).getClassModel();
        List<Role> roles = c.getRoles();
        for (Role role : roles) {
            //if (part != null)
            try {
                role.getRoleFile().delete(true, null);
            } catch (CoreException e) {
                UIPlugin.getDefault().logError(e);
            }
        }

    } else if (part instanceof CollaborationEditPart) {
        Collaboration coll = ((CollaborationEditPart) part).getCollaborationModel();
        for (Role role : coll.getRoles()) {
            try {
                role.getRoleFile().delete(true, null);
            } catch (CoreException e) {
                UIPlugin.getDefault().logError(e);
            }
        }
    }

}

From source file:de.plugins.eclipse.depclipse.handlers.SaveJDependOutput.java

License:Open Source License

/**
 * @param file/* w  w  w . j  a  v a  2  s . c  om*/
 *            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. 
 *//*ww  w  .  j  av  a 2  s . c  o m*/
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.adaptation.util.swt.SWTUtil.java

License:Apache License

/**
 * Create and opens simple error dialog with an OK button.
 * @param shell the shell of the dialog/*from   w  ww .jav a  2 s  .c  o  m*/
 * @param title the title of the dialog
 * @param message the message of the dialog
 * @param exeception the exception that was thrown (optional)
 */
public static void showErrorDialog(Shell shell, String title, String message, Exception exception) {
    String[] buttons = { IDialogConstants.OK_LABEL };
    if (exception != null) {
        message = message + "\n\nException: " + exception.getClass().getSimpleName() + "\nMessage: "
                + exception.getMessage();
    }
    new MessageDialog(shell, title, null, message, MessageDialog.ERROR, buttons, 0).open();
}

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();
    }//from ww  w  . j ava2 s  .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);/*ww w  .ja  v  a  2 s .co m*/
    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. ja  v  a 2  s.  c om*/
    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);//from www .  ja  v  a2  s .  c  o 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);/*  w w  w  . j av a 2 s. com*/
    // ok is the default
    return dialog.open();
}