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:ca.mcgill.sable.soot.ui.SootConfigManagerDialog.java

License:Open Source License

private void deletePressed() {
    if (getSelected() == null)
        return;//from w w  w . j  a v  a  2  s  . c o  m

    String result = this.getSelected();

    // maybe ask if they are sure here first
    MessageDialog msgDialog = new MessageDialog(this.getShell(),
            Messages.getString("SootConfigManagerDialog.Soot_Configuration_Remove_Message"), null, //$NON-NLS-1$
            Messages.getString("SootConfigManagerDialog.Are_you_sure_you_want_to_remove_this_configuration"), 0, //$NON-NLS-1$
            new String[] { Messages.getString("SootConfigManagerDialog.Yes"), //$NON-NLS-1$
                    Messages.getString("SootConfigManagerDialog.No") }, //$NON-NLS-1$
            0);
    msgDialog.open();
    if (msgDialog.getReturnCode() == 0) {

        // do the delete
        ArrayList toRemove = new ArrayList();
        toRemove.add(result);
        SavedConfigManager scm = new SavedConfigManager();
        scm.setDeleteList(toRemove);
        scm.handleDeletes();

        // remove also from tree
        getTreeRoot().removeChild(result);
        refreshTree();
    }

}

From source file:ca.uwaterloo.gp.fmp.provider.action.XMLExport.java

License:Open Source License

public void run() {
    StringBuffer output = new StringBuffer();

    // run recursion
    exportNode(output, object, 0);/*from  ww  w .j a va2  s  .  c om*/

    final String text = output.toString();

    //System.out.println(text);

    Dialog dialog = new MessageDialog(shell, "XML Export", null, null, MessageDialog.NONE,
            new String[] { "OK" }, 0) {
        protected Control createDialogArea(Composite parent) {
            Color white = shell.getDisplay().getSystemColor(SWT.COLOR_WHITE);
            parent.setBackground(white);
            // Composite composite = (Composite) super.createDialogArea(parent);
            // composite.setBackground(white);
            // Text field            
            fText = new Text(parent, SWT.MULTI);
            fText.setEditable(false);
            fText.setText(text);
            fText.selectAll();
            fText.setBackground(white);
            return fText;
        }
    };
    /*
     * Michal: unfortunately this only works in Eclipse 3.2
    PopupDialog dialog = new PopupDialog(shell, PopupDialog.INFOPOPUPRESIZE_SHELLSTYLE, true, false, false, false, 
    "XML Export", "Use <CTRL>-C to copy to clipboard, <ESC> to dismiss.") {
       protected Control createDialogArea(Composite parent) {
    Composite composite = (Composite) super.createDialogArea(parent);
    // Text field            
    fText= new Text(composite, SWT.MULTI);
    fText.setEditable(false);
    fText.setText(text);
    fText.selectAll();
    return composite;
       }
    };*/
    dialog.open();
}

From source file:carisma.ui.eclipse.dialogs.parameters.ParameterDialogUtil.java

License:Open Source License

/**
 * Getter for a Boolean Parameter./*w w  w.  j av a 2 s  .c om*/
 * @param parameter Boolean Parameter
 * @return the new value of the Boolean Parameter
 */
public final boolean queryBooleanParameter(final BooleanParameter parameter) {
    int result = 0;
    if (!parameter.getValue()) { // defaultValue used for MessageDialog's
        result = 1;
    }
    MessageDialog md = new MessageDialog(super.getShell(), this.checkDescriptor.getName(), null,
            DIALOG_TEXT + "\"" + parameter.getDescriptor().getName() + "\" (BOOLEAN)", 0,
            new String[] { "True", "False" }, result);
    result = md.open();

    return result == 0;

}

From source file:carisma.ui.eclipse.editors.AdfEditorMasterDetailsBlock.java

License:Open Source License

/**
 * Creates the run-button and the corresponding listener.
 * /*www  . ja va2  s  .  com*/
 * @param toolkit
 *            The FormToolKit where the button is created
 * @param composite
 *            The corresponding composite
 */
private void createRunButton(final FormToolkit toolkit, final Composite composite) {
    this.run = toolkit.createButton(composite, "RUN", SWT.PUSH);
    this.run.setEnabled(this.controller.isModelFileValid());
    //Bug #1518: Wie kann man die Position des Tooltips verndern?
    //http://stackoverflow.com/questions/11375250/set-tooltip-text-at-a-particular-location
    this.run.setToolTipText("Runs the analysis");

    this.run.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(final SelectionEvent e) {
            listSelectionChanged();
            if (AdfEditorMasterDetailsBlock.this.controller.isEditorDirty()) {
                MessageDialog messageDialog = new MessageDialog(composite.getShell(), "Save and Launch", null,
                        "Do you want to save the changes?", 0, new String[] { "OK", "Cancel" }, 0);
                messageDialog.open();
                if (messageDialog.getReturnCode() == 0) {
                    AdfEditorMasterDetailsBlock.this.controller.saveAnalysis();
                }
            }
            if (AdfEditorMasterDetailsBlock.this.controller.hasAnalysisInvalidParameters()
                    || !AdfEditorMasterDetailsBlock.this.controller.isModelFileValid()
                    || !isOneCheckEnabled()) {
                updateRunButtonEnable();
                showProblems();
            } else {
                AdfEditorMasterDetailsBlock.this.controller.runAnalysis();
            }
        }
    });

    this.problemLink = new Link(composite, SWT.NONE);
    this.problemLink.setText("<a>Show problems</a>");
    this.problemLink.setBackground(new Color(null, 255, 255, 255));
    this.problemLink.setVisible(false);
    this.problemLink.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(final SelectionEvent e) {
            showProblems();
        }
    });
}

From source file:carisma.ui.eclipse.editors.AdfEditorMasterDetailsBlock.java

License:Open Source License

/**
 * Displays a message box which contains a list of problems.
 *//*from  ww  w  .ja  va  2  s  .com*/
void showProblems() {
    StringBuffer message = new StringBuffer("");

    for (String line : this.controller.getProblems()) {
        message.append(line + System.getProperty("line.separator"));
    }
    MessageDialog messageDialog = new MessageDialog(this.sashForm.getShell(), "Analysis problems", null,
            message.toString(), MessageDialog.ERROR, new String[] { "OK" }, 0);
    messageDialog.open();
}

From source file:carisma.ui.eclipse.editors.AdfEditorMasterDetailsBlock.java

License:Open Source License

/**
 * This method activates or deactivates the editors combo box.
 * //from  w ww .  jav  a2s.  c o m
 * @param active
 *            True, if the combo box should be activated, false otherwise
 * @param message
 *            the message, which will be shown
 */
private void updateSelectedEditorEnableState(final boolean active, final String message) {
    boolean validEditor = false;
    if (this.selectedEditorCombo.getEnabled() != active) {
        this.selectedEditorCombo.removeAll();
        if (active) {
            this.selectedEditorCombo.setEnabled(true);
            // Get the editors
            final EditorRegistry editorRegistry = CarismaGUI.INSTANCE.getEditorRegistry();
            List<EditorDescriptor> editorDescriptorList = editorRegistry.getRegisteredEditors();
            this.selectedEditorCombo.add(DEFAULT_EDITOR);
            // Add all applicable editors to the combo box
            for (EditorDescriptor editorDesc : editorDescriptorList) {
                if (editorDesc.isAvailable() && editorDesc.isApplicable(this.controller.getModelIFile())) {
                    this.selectedEditorCombo.add(editorDesc.getName());
                }
            }
            // Select 'Default Eclipse Editor' by default or the editor,
            // which is saved in the adf file
            this.selectedEditorCombo.select(0);
            EditorDescriptor savedEditorDescriptor = editorRegistry
                    .getEditorDescriptorById(this.controller.getSelectedEditorId());
            if (savedEditorDescriptor != null) {
                int index = 0;
                for (String item : this.selectedEditorCombo.getItems()) {
                    if (item.equals(savedEditorDescriptor.getName())) {
                        this.selectedEditorCombo.select(index);
                        validEditor = true;
                        break;
                    }
                    index++;
                }
            } else {
                if ((this.controller.getSelectedEditorId().equals(""))
                        || (this.controller.getSelectedEditorId().equals("Default Eclipse Editor"))) {
                    validEditor = true;
                }
            }
            this.selectedEditorCombo.setToolTipText("Choose an editor to open the model.");
            this.selectedEditorDecoration.hide();
        } else {
            if (EditorPriorityList.getPriorityList(this.controller.getModelType()) != null
                    && EditorPriorityList.getPriorityList(this.controller.getModelType()).size() >= 1) {
                this.selectedEditorCombo
                        .add(EditorPriorityList.getPriorityList(this.controller.getModelType()).get(0));
            } else {
                this.selectedEditorCombo.add("Priority list is empty!");
            }
            this.selectedEditorCombo.select(0);
            this.selectedEditorCombo.setEnabled(false);
            this.selectedEditorDecoration.setDescriptionText(message);
            this.selectedEditorCombo.setToolTipText("");
            this.selectedEditorDecoration.show();
        }
        if (!validEditor) {
            //MessageBox if the stored editor is invalid
            MessageDialog messageDialog = new MessageDialog(this.selectedEditorCombo.getShell(),
                    "Invalid Model-Editor", null,
                    "The chosen editor for the modeltype of the CARiSMA analysis is invalid." + "\nThe ID is \""
                            + this.controller.getSelectedEditorId() + "\"."
                            + "\nThe default editor will be chosen."
                            + "\nClick \"OK && remove ID\" to change the editor to the default editor in the analysis file.",
                    MessageDialog.INFORMATION, new String[] { "OK", "OK && remove ID" }, 0);
            // && in strings results in &
            messageDialog.open();
            if (messageDialog.getReturnCode() == 1) {
                //set the stored Editor to the default Editor and saves the analysis file
                setEditorToDefault();
            }
        }
    }
}

From source file:carisma.ui.eclipse.editors.EditorTranslator.java

License:Open Source License

/**
 * Opens the editor, which is selected in the adf editor dropdown menu, or the
 * editors from the editor priority list.
 * @param defaultEditor Is true, when the Eclipse default editor for this file should be opened
 * @return An indicator for the success of the method
 */// w  w  w  .  j  a va  2 s  .  com
public final boolean openEditor(final boolean defaultEditor) {
    EditorRegistry editorRegistry = CarismaGUI.INSTANCE.getEditorRegistry();
    String editorSelectionArt = CarismaGUI.INSTANCE.getPreferenceStore()
            .getString(Constants.EDITOR_SELECTION_ART);
    // Priority list
    if (editorSelectionArt.equals(Constants.AUTO)) {
        List<String> editorPriorityList = EditorPriorityList.getPriorityList(this.analysis.getModelType());
        if (editorPriorityList == null || editorPriorityList.size() < 1) {
            MessageDialog mDialog = new MessageDialog(Display.getDefault().getActiveShell(), "Error", null,
                    "The editor priority list is empty\n"
                            + "Add editors to the list in the CARiSMA Preferences",
                    MessageDialog.ERROR, new String[] { "OK" }, 0);
            mDialog.open();
            return false;
        }
        for (String editorName : editorPriorityList) {
            EditorDescriptor editorDesc = editorRegistry.getEditorDescriptorByName(editorName);
            if (editorDesc.forceOpen(this.analysis.getIFile())) {
                return true;
            }
        }
        // Dropdown menu selection
    } else {
        EditorDescriptor editorDesc = null;
        if (defaultEditor) {
            // Find Eclipse default editor for this model type
            editorDesc = getDefaultEditor();
        } else {
            // Find selected editor in the editor registry
            String selectedEditorId = this.analysis.getSelectedEditorId();
            editorDesc = editorRegistry.getEditorDescriptorById(selectedEditorId);
        }
        if (editorDesc != null) {
            if (editorDesc.forceOpen(this.analysis.getIFile())) {
                return true;
            }
            MessageDialog mDialog = new MessageDialog(Display.getDefault().getActiveShell(), "Error", null,
                    "The selected editor cannot be opened", MessageDialog.ERROR, new String[] { "OK" }, 0);
            mDialog.open();
            return false;
        }
        MessageDialog mDialog = new MessageDialog(Display.getDefault().getActiveShell(), "Error", null,
                "The selected editor was not found", MessageDialog.ERROR, new String[] { "OK" }, 0);
        mDialog.open();
        return false;
    }
    return false;
}

From source file:carisma.ui.eclipse.popup.actions.RunAnalysisAction.java

License:Open Source License

/**
 * Show a message with name of checks, where the required parameters are not
 * filled, used to stop Run process if necessary.
 * @param checksWithUnsetRequiredParameters A list of checks, for those required parameter are not filled
 *//*from ww w.jav  a 2 s . c o m*/
private static void showUnsetRequiredParameters(final List<CheckReference> checksWithUnsetRequiredParameters) {
    StringBuffer message = new StringBuffer("Required parameters not set in: \n");

    if (checksWithUnsetRequiredParameters.size() > 0) {
        for (CheckReference check : checksWithUnsetRequiredParameters) {
            message.append("\"");
            message.append(check.getCheckID());
            message.append("\"\n");
        }
        Display display = Display.getDefault();
        Shell shell = new Shell(display);
        MessageDialog mDialog = new MessageDialog(shell, "Unset required parameter error", null,
                message.toString(), MessageDialog.ERROR, new String[] { "OK" }, 0);
        mDialog.open();
    }
}

From source file:carisma.ui.eclipse.rcp.ForgetEditorHandler.java

License:Open Source License

@Override
public final Object execute(final ExecutionEvent event) throws ExecutionException {

    this.analysis = AnalysisUtil.readAnalysis(this.selectedFile.getLocation().toOSString());

    if (this.analysis == null) {
        return null;
    } else if (this.analysis.getSelectedEditorId() == null || this.analysis.getSelectedEditorId().equals("")) {

        Display display = Display.getDefault();
        Shell shell = new Shell(display);
        MessageDialog mDialog = new MessageDialog(shell, "Editor not set", null,
                "No editor set for this analysis", MessageDialog.ERROR, new String[] { "OK" }, 0);
        mDialog.open();/*from w  w w .  j a v  a2 s. c  o  m*/
        return null;
    }
    this.analysis.setSelectedEditorId(null);
    fireHandlerChanged(new HandlerEvent(getHandler(), true, false));
    saveChanges();

    IWorkbenchPage[] pages = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getPages();

    for (IWorkbenchPage page : pages) {
        for (IEditorReference editorRef : page.getEditorReferences()) {
            if (editorRef != null && this.selectedFile.getName().equals(editorRef.getName())
                    && editorRef.getEditor(false) instanceof AdfEditor) {
                IEditorInput editInput = ((AdfEditor) editorRef.getEditor(false)).getEditorInput();
                if (editInput.getAdapter(IFile.class) != null) {
                    IFile file = editInput.getAdapter(IFile.class);
                    this.analysis = AnalysisUtil.readAnalysis(file.getLocation().toOSString());
                }
            }
        }
    }

    return null;

}

From source file:carisma.ui.eclipse.rcp.ForgetEditorHandler.java

License:Open Source License

/**
 * save changes to resource.//from   www. j  av  a  2  s  .  co m
 */
private void saveChanges() {
    if (this.selectedFile == null) {
        // TODO
        return;
    }
    Display display = Display.getDefault();
    Shell shell = new Shell(display);
    MessageDialog mDialog = new MessageDialog(shell, "Save and Launch", null,
            "Do you want to save the changes in" + this.selectedFile.getLocation().toOSString() + "?", 0,
            new String[] { "OK", "Cancel" }, 0);
    mDialog.open();

    if (mDialog.getReturnCode() == 0) { // save analysis
        AnalysisUtil.storeAnalysis(this.analysis, this.selectedFile.getLocation().toOSString());
        // refresh resource

        try {
            this.selectedFile.refreshLocal(IResource.DEPTH_ZERO, null);
        } catch (CoreException e) {
            Logger.log(LogLevel.INFO, "Could not refresh resource");

        }
    }
}