Example usage for org.eclipse.jface.dialogs MessageDialog getReturnCode

List of usage examples for org.eclipse.jface.dialogs MessageDialog getReturnCode

Introduction

In this page you can find the example usage for org.eclipse.jface.dialogs MessageDialog getReturnCode.

Prototype

public int getReturnCode() 

Source Link

Document

Returns this window's return code.

Usage

From source file:ca.mcgill.sable.soot.launching.DavaHandler.java

License:Open Source License

private boolean createSpecialDavaProject(IPath jreLibPath) {
    IWorkbenchWindow window = SootPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow();
    MessageDialog create = new MessageDialog(window.getShell(), Messages.getString("DavaHandler.Soot_Question"),
            null,/*  w w w. j  a  va 2 s.co m*/
            Messages.getString(
                    "DavaHandler.Would_you_like_to_create_a_new_Dava_Project_with_generated_Dava_src_files"),
            0, new String[] { Messages.getString("DavaHandler.OK"), Messages.getString("DavaHandler.Cancel") },
            0);
    create.open();
    if (create.getReturnCode() == Dialog.OK) {
        // create proj
        IProject proj = SootPlugin.getWorkspace().getRoot().getProject(getDavaProjName());
        if (!proj.exists()) {
            try {
                proj.create(null);
                proj.open(null);
                IProjectDescription pd = proj.getDescription();
                String[] natures = new String[] { Messages.getString("org.eclipse.jdt.core.javanature") };

                pd.setNatureIds(natures);
                proj.setDescription(pd, null);

                setDavaProj(JavaCore.create(proj));
                IFolder folder = proj.getFolder(Messages.getString("DavaHandler.src")); //$NON-NLS-1$
                if (!folder.exists()) {
                    folder.create(false, true, null);
                }
                setSrcFolder(folder);
                IFolder out = proj.getFolder(Messages.getString("DavaHandler.bin")); //$NON-NLS-1$
                if (!folder.exists()) {
                    folder.create(false, true, null);
                }
                getDavaProj().setOutputLocation(out.getFullPath(), null);
                IClasspathEntry[] entries = new IClasspathEntry[2];
                entries[0] = JavaCore.newSourceEntry(folder.getFullPath());
                if (jreLibPath != null) {
                    entries[1] = JavaCore.newContainerEntry(jreLibPath);
                }
                getDavaProj().setRawClasspath(entries, null);
                return true;
            } catch (CoreException e) {
                e.printStackTrace();
                return false;
            }
        }

    }
    return false;
}

From source file:ca.mcgill.sable.soot.launching.DavaHandler.java

License:Open Source License

private boolean shouldCopyFiles() {
    IWorkbenchWindow window = SootPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow();
    MessageDialog copy = new MessageDialog(window.getShell(), Messages.getString("DavaHandler.Soot_Question"), //$NON-NLS-1$
            null, Messages.getString("DavaHandler.Would_you_like_to_copy_Dava_src_files_to_the_Dava_Project"), //$NON-NLS-1$
            0, new String[] { Messages.getString("DavaHandler.OK"), Messages.getString("DavaHandler.Cancel") }, //$NON-NLS-1$//$NON-NLS-2$
            0);/* w  ww .  ja  v a2  s  .  c  om*/
    copy.open();
    if (copy.getReturnCode() == Dialog.OK)
        return true;
    return false;
}

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  2s.  c om*/

    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:carisma.ui.eclipse.editors.AdfEditorMasterDetailsBlock.java

License:Open Source License

/**
 * Creates the run-button and the corresponding listener.
 * //  w ww.  j  ava2 s. c om
 * @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

/**
 * This method activates or deactivates the editors combo box.
 * //from   w  w w. j  a v  a  2s  .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.rcp.ForgetEditorHandler.java

License:Open Source License

/**
 * save changes to resource.//from w  w w  .  j a v a2s  . c  o 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");

        }
    }
}

From source file:com.amalto.workbench.export.ImportItemsWizard.java

License:Open Source License

private boolean isSaveModifiedEditor(String editorName) {
    final MessageDialog dialog = new MessageDialog(getShell(), Messages.ImportItemsWizard_4, null,
            Messages.ImportItemsWizard_5 + editorName + Messages.ImportItemsWizard_6, MessageDialog.QUESTION,
            new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 0);
    dialog.open();//from   w  ww. j a  va2 s.c  o  m
    if (dialog.getReturnCode() == 0) {
        return true;
    }
    return false;
}

From source file:com.amalto.workbench.export.ImportItemsWizard.java

License:Open Source License

private int isOveride(String name, String obTypeName) {

    final MessageDialog dialog = new MessageDialog(getShell(), Messages.ImportItemsWizard_12, null,
            Messages.ImportItemsWizard_13 + obTypeName + Messages.ImportItemsWizard_14 + name
                    + Messages.ImportItemsWizard_15,
            MessageDialog.QUESTION,//from   ww  w. j a v  a  2 s.c  o  m
            new String[] { IDialogConstants.YES_LABEL, IDialogConstants.YES_TO_ALL_LABEL,
                    IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL },
            0);
    dialog.open();
    int result = dialog.getReturnCode();
    if (result == 0) {
        return IDialogConstants.YES_ID;
    }
    if (result == 1) {
        return IDialogConstants.YES_TO_ALL_ID;
    }
    if (result == 2) {
        return IDialogConstants.NO_ID;
    }
    return IDialogConstants.CANCEL_ID;

}

From source file:com.aptana.ide.core.ui.wizards.WizardFolderImportPage.java

License:Open Source License

/**
 * The <code>WizardDataTransfer</code> implementation of this <code>IOverwriteQuery</code> method asks the user
 * whether the existing resource at the given path should be overwritten.
 * /*from w ww.  ja  v a2 s  .co  m*/
 * @param pathString
 * @return the user's reply: one of <code>"YES"</code>, <code>"NO"</code>, <code>"ALL"</code>, or
 *         <code>"CANCEL"</code>
 */
public String queryOverwrite(String pathString) {

    Path path = new Path(pathString);

    String messageString;
    // Break the message up if there is a file name and a directory
    // and there are at least 2 segments.
    if (path.getFileExtension() == null || path.segmentCount() < 2) {
        messageString = NLS.bind(IDEWorkbenchMessages.WizardDataTransfer_existsQuestion, pathString);
    }

    else {
        messageString = NLS.bind(IDEWorkbenchMessages.WizardDataTransfer_overwriteNameAndPathQuestion,
                path.lastSegment(), path.removeLastSegments(1).toOSString());
    }

    final MessageDialog dialog = new MessageDialog(getContainer().getShell(), IDEWorkbenchMessages.Question,
            null, messageString, MessageDialog.QUESTION,
            new String[] { IDialogConstants.YES_LABEL, IDialogConstants.YES_TO_ALL_LABEL,
                    IDialogConstants.NO_LABEL, IDialogConstants.NO_TO_ALL_LABEL,
                    IDialogConstants.CANCEL_LABEL },
            0);
    String[] response = new String[] { YES, ALL, NO, NO_ALL, CANCEL };
    // run in syncExec because callback is from an operation,
    // which is probably not running in the UI thread.
    getControl().getDisplay().syncExec(new Runnable() {
        public void run() {
            dialog.open();
        }
    });
    return dialog.getReturnCode() < 0 ? CANCEL : response[dialog.getReturnCode()];
}

From source file:com.arm.cmsis.pack.installer.OverwriteQuery.java

License:Open Source License

@Override
public String queryOverwrite(String pathString) {
    Path path = new Path(pathString);

    String messageString;/* w ww  .j ava  2  s  .c  o  m*/
    //Break the message up if there is a file name and a directory
    //and there are at least 2 segments.
    if (path.getFileExtension() == null || path.segmentCount() < 2) {
        messageString = NLS.bind(Messages.OverwriteQuery_ExistsQuestion, pathString);
    } else {
        messageString = NLS.bind(Messages.OverwriteQuery_OverwriteNameAndPathQuestion, path.lastSegment(),
                path.removeLastSegments(1).toOSString());
    }

    final MessageDialog dialog = new MessageDialog(shell, Messages.OverwriteQuery_Question, null, messageString,
            MessageDialog.QUESTION,
            new String[] { IDialogConstants.YES_LABEL, IDialogConstants.YES_TO_ALL_LABEL,
                    IDialogConstants.NO_LABEL, IDialogConstants.NO_TO_ALL_LABEL,
                    IDialogConstants.CANCEL_LABEL },
            0) {
        @Override
        protected int getShellStyle() {
            return super.getShellStyle() | SWT.SHEET;
        }
    };
    String[] response = new String[] { YES, ALL, NO, NO_ALL, CANCEL };
    //run in syncExec because callback is from an operation,
    //which is probably not running in the UI thread.
    shell.getDisplay().syncExec(new Runnable() {
        @Override
        public void run() {
            dialog.open();
        }
    });
    return dialog.getReturnCode() < 0 ? CANCEL : response[dialog.getReturnCode()];
}