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:gov.nasa.ensemble.common.ui.wizard.DefaultOverwriteQueryImpl.java

License:Open Source License

@Override
public String queryOverwrite(String pathString) {
    if (alwaysOverwrite) {
        return ALL;
    }/*from   ww  w.  j a  v  a  2  s. c o m*/
    final String returnCode[] = { CANCEL };
    final String msg = NLS.bind(IDEWorkbenchMessages.CopyFilesAndFoldersOperation_overwriteQuestion,
            pathString);
    final String[] options = { IDialogConstants.YES_LABEL, IDialogConstants.YES_TO_ALL_LABEL,
            IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL };
    shell.getDisplay().syncExec(new Runnable() {
        @Override
        public void run() {
            MessageDialog dialog = new MessageDialog(shell,
                    IDEWorkbenchMessages.CopyFilesAndFoldersOperation_question, null, msg,
                    MessageDialog.QUESTION, options, 0) {
                @Override
                protected int getShellStyle() {
                    return super.getShellStyle() | SWT.SHEET;
                }
            };
            dialog.open();
            int returnVal = dialog.getReturnCode();
            String[] returnCodes = { YES, ALL, NO, CANCEL };
            returnCode[0] = returnVal == -1 ? CANCEL : returnCodes[returnVal];
        }
    });
    if (returnCode[0] == ALL) {
        alwaysOverwrite = true;
    } else if (returnCode[0] == CANCEL) {
        canceled = true;
    }
    return returnCode[0];
}

From source file:gov.redhawk.ide.pydev.PyDevConfigureStartup.java

License:Open Source License

@Override
public void earlyStartup() {
    final String app = System.getProperty("eclipse.application");
    final boolean runConfig = app == null || "org.eclipse.ui.ide.workbench".equals(app);
    if (!runConfig) {
        return;/*  ww  w  . j av  a2  s  . com*/
    }

    // If PyDev isn't configured at all, then prompt the user
    if (PydevPlugin.getPythonInterpreterManager().isConfigured()) {
        try {
            boolean configuredCorrectly = AutoConfigPydevInterpreterUtil
                    .isPydevConfigured(new NullProgressMonitor(), null);
            if (!configuredCorrectly) {
                PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {

                    @Override
                    public void run() {
                        final String[] buttons = { "Ok", "Cancel" };
                        final MessageDialog dialog = new MessageDialog(
                                PlatformUI.getWorkbench().getDisplay().getActiveShell(), "Configure PyDev",
                                null,
                                "PyDev appears to be mis-configured for REDHAWK, would you like it to be re-configured?",
                                MessageDialog.QUESTION, buttons, 0);
                        dialog.open();
                        PyDevConfigureStartup.this.result = dialog.getReturnCode();

                        if (PyDevConfigureStartup.this.result < 1) {
                            new ConfigurePythonJob(false).schedule();
                        }
                    }

                });
            }
        } catch (CoreException e) {
            RedhawkIdePyDevPlugin.getDefault().getLog().log(new Status(e.getStatus().getSeverity(),
                    RedhawkIdePyDevPlugin.PLUGIN_ID, "Failed to auto configure.", e));
        }
    } else {
        PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {

            @Override
            public void run() {
                new ConfigurePythonJob(false).schedule();
            }

        });
    }
}

From source file:gov.redhawk.ide.ui.wizard.RedhawkImportWizardPage1.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.
 * //ww  w  .  j  a  va2s . c  om
 * @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) {
        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.
    getControl().getDisplay().syncExec(new Runnable() {
        public void run() {
            dialog.open();
        }
    });
    return (dialog.getReturnCode() < 0) ? CANCEL : response[dialog.getReturnCode()];
}

From source file:net.tourbook.importdata.RawDataManager.java

License:Open Source License

private String importRawData_20_CopyFile(final TourbookDevice device, final String sourceFileName,
        final String destinationPath, final boolean buildNewFileName,
        final FileCollisionBehavior fileCollision) {

    String destFileName = new File(sourceFileName).getName();

    if (buildNewFileName) {

        destFileName = null;/*from   w w  w .j av  a 2  s . c o m*/

        try {
            destFileName = device.buildFileNameFromRawData(sourceFileName);
        } catch (final Exception e) {
            TourLogManager.logEx(e);
        } finally {

            if (destFileName == null) {

                MessageDialog
                        .openError(Display.getDefault().getActiveShell(),
                                Messages.Import_Data_Error_CreatingFileName_Title,
                                NLS.bind(Messages.Import_Data_Error_CreatingFileName_Message, //
                                        new Object[] { sourceFileName,
                                                new org.eclipse.core.runtime.Path(destinationPath)
                                                        .addTrailingSeparator().toString(),
                                                TEMP_IMPORTED_FILE }));

                destFileName = TEMP_IMPORTED_FILE;
            }
        }
    }
    final File newFile = new File(
            (new org.eclipse.core.runtime.Path(destinationPath).addTrailingSeparator().toString()
                    + destFileName));

    // get source file
    final File fileIn = new File(sourceFileName);

    // check if file already exist
    if (newFile.exists()) {
        // TODO allow user to rename the file

        boolean keepFile = false; // for MessageDialog result
        if (fileCollision.value == FileCollisionBehavior.ASK) {

            final Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
            final MessageDialog messageDialog = new MessageDialog(shell, Messages.Import_Wizard_Message_Title,
                    null, NLS.bind(Messages.Import_Wizard_Message_replace_existing_file, newFile),
                    MessageDialog.QUESTION,
                    new String[] { IDialogConstants.YES_LABEL, IDialogConstants.YES_TO_ALL_LABEL,
                            IDialogConstants.NO_LABEL, IDialogConstants.NO_TO_ALL_LABEL },
                    0);
            messageDialog.open();
            final int returnCode = messageDialog.getReturnCode();
            switch (returnCode) {

            case 1: // YES_TO_ALL
                fileCollision.value = FileCollisionBehavior.REPLACE;
                break;

            case 3: // NO_TO_ALL
                fileCollision.value = FileCollisionBehavior.KEEP;
            case 2: // NO
                keepFile = true;
                break;

            default:
                break;
            }
        }

        if (fileCollision.value == FileCollisionBehavior.KEEP || keepFile) {
            _isImportCanceled = true;
            fileIn.delete();
            return null;
        }
    }

    // copy source file into destination file
    FileInputStream inReader = null;
    FileOutputStream outReader = null;
    try {
        inReader = new FileInputStream(fileIn);
        outReader = new FileOutputStream(newFile);
        int c;

        while ((c = inReader.read()) != -1) {
            outReader.write(c);
        }

        inReader.close();
        outReader.close();

    } catch (final FileNotFoundException e) {
        TourLogManager.logEx(e);
        return null;
    } catch (final IOException e) {
        TourLogManager.logEx(e);
        return null;
    } finally {
        // close the files
        if (inReader != null) {
            try {
                inReader.close();
            } catch (final IOException e) {
                TourLogManager.logEx(e);
                return null;
            }
        }
        if (outReader != null) {
            try {
                outReader.close();
            } catch (final IOException e) {
                TourLogManager.logEx(e);
                return null;
            }
        }
    }

    // delete source file
    fileIn.delete();

    return newFile.getAbsolutePath();
}

From source file:net.tourbook.ui.UI.java

License:Open Source License

/**
 * @param file//from  ww  w  . ja  va2s  .  co  m
 * @return Returns <code>true</code> when the file should be overwritten, otherwise
 *         <code>false</code>
 */
public static boolean confirmOverwrite(final File file) {

    final Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();

    final MessageDialog dialog = new MessageDialog(//
            shell, Messages.app_dlg_confirmFileOverwrite_title, null,
            NLS.bind(Messages.app_dlg_confirmFileOverwrite_message, file.getPath()), MessageDialog.QUESTION,
            new String[] { IDialogConstants.YES_LABEL, IDialogConstants.CANCEL_LABEL }, 0);

    dialog.open();

    return dialog.getReturnCode() == 0;
}

From source file:net.tourbook.ui.UI.java

License:Open Source License

public static boolean confirmOverwrite(final FileCollisionBehavior fileCollision, final File file) {

    final boolean[] isOverwrite = { false };

    final int fileCollisionValue = fileCollision.value;

    if (fileCollisionValue == FileCollisionBehavior.REPLACE_ALL) {

        // overwrite is already confirmed
        isOverwrite[0] = true;/*from www .  java 2 s.c o  m*/

    } else if (fileCollisionValue == FileCollisionBehavior.ASK
            || fileCollisionValue == FileCollisionBehavior.REPLACE
            || fileCollisionValue == FileCollisionBehavior.KEEP) {

        Display.getDefault().syncExec(new Runnable() {
            @Override
            public void run() {

                final Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
                final MessageDialog dialog = new MessageDialog(//
                        shell, Messages.app_dlg_confirmFileOverwrite_title, null,
                        NLS.bind(Messages.app_dlg_confirmFileOverwrite_message, file.getPath()),
                        MessageDialog.QUESTION,
                        new String[] { IDialogConstants.YES_LABEL, IDialogConstants.YES_TO_ALL_LABEL,
                                IDialogConstants.NO_LABEL, IDialogConstants.NO_TO_ALL_LABEL,
                                IDialogConstants.CANCEL_LABEL },
                        0);
                dialog.open();

                final int returnCode = dialog.getReturnCode();
                switch (returnCode) {

                case -1: // dialog was canceled
                case 4:
                    fileCollision.value = FileCollisionBehavior.DIALOG_IS_CANCELED;
                    break;

                case 0: // YES
                    fileCollision.value = FileCollisionBehavior.REPLACE;
                    isOverwrite[0] = true;
                    break;

                case 1: // YES_TO_ALL
                    fileCollision.value = FileCollisionBehavior.REPLACE_ALL;
                    isOverwrite[0] = true;
                    break;

                case 2: // NO
                    fileCollision.value = FileCollisionBehavior.KEEP;
                    break;

                case 3: // NO_TO_ALL
                    fileCollision.value = FileCollisionBehavior.KEEP_ALL;
                    break;

                default:
                    break;
                }
            }
        });

    }

    return isOverwrite[0];
}

From source file:org.eclipse.birt.report.designer.ui.samples.ide.action.IDEOpenSampleReportAction.java

License:Open Source License

private IProject createProject(String projectName, boolean isJavaProject) {
    ProjectNameDialog projectNameDlg = new ProjectNameDialog(UIUtil.getDefaultShell());
    projectNameDlg.setTitle(Messages.getString("IDEOpenSampleReportAction.ProjectNameDialog.Title.PrjectName"));
    projectNameDlg.setProjectName(projectName);

    if (projectNameDlg.open() == Window.CANCEL) {
        return null;
    }//from   w  w  w.j  a v  a  2 s  .c o  m

    projectName = projectNameDlg.getProjectName();

    final IProject projectHandle = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);

    if (projectHandle.exists()) {
        String[] buttonLabels = new String[] { IDialogConstants.PROCEED_LABEL,
                Messages.getString("IDEOpenSampleReportAction.MessageDialog.ProjectExists.ButtonText"),
                IDialogConstants.CANCEL_LABEL };
        MessageDialog messageDlg = new MessageDialog(UIUtil.getDefaultShell(),
                Messages.getString("IDEOpenSampleReportAction.MessageDialog.ProjectExists.Title"), null,
                Messages.getFormattedString("IDEOpenSampleReportAction.MessageDialog.ProjectExists.Message",
                        buttonLabels),
                MessageDialog.INFORMATION, buttonLabels, 0);
        messageDlg.open();
        if (messageDlg.getReturnCode() == 0) {
            // proceed
            return projectHandle;
        }

        if (messageDlg.getReturnCode() == 1) {
            // overwrite
            try {
                projectHandle.delete(true, null);
            } catch (CoreException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

        if (messageDlg.getReturnCode() == 2) {
            // cancel
            return null;
        }

    }

    final IProjectDescription description = ResourcesPlugin.getWorkspace()
            .newProjectDescription(projectHandle.getName());

    if (isJavaProject == true) {
        String[] natures = new String[] { JavaCore.NATURE_ID,
                "org.eclipse.birt.report.designer.ui.reportprojectnature", //$NON-NLS-1$
        };
        description.setNatureIds(natures);
        addJavaBuildSpec(description);
    } else {
        String[] natures = new String[] { "org.eclipse.birt.report.designer.ui.reportprojectnature", //$NON-NLS-1$
        };
        description.setNatureIds(natures);
    }

    // create the new project operation
    WorkspaceModifyOperation op = new WorkspaceModifyOperation() {

        protected void execute(IProgressMonitor monitor) throws CoreException {
            create(description, projectHandle, monitor);
        }
    };

    try {
        new ProgressMonitorDialog(composite.getShell()).run(false, true, op);
    } catch (InterruptedException e) {
        ExceptionUtil.handle(e);
        return null;
    } catch (InvocationTargetException e) {
        // ie.- one of the steps resulted in a core exception
        Throwable t = e.getTargetException();
        if (t instanceof CoreException) {
            if (((CoreException) t).getStatus().getCode() == IResourceStatus.CASE_VARIANT_EXISTS) {
                MessageDialog.openError(composite.getShell(),
                        Messages.getString("NewReportProjectWizard.errorMessage"), //$NON-NLS-1$
                        Messages.getFormattedString("NewReportProjectWizard.caseVariantExistsError", //$NON-NLS-1$
                                new String[] { projectHandle.getName() }) //,
                );
            } else {
                ErrorDialog.openError(composite.getShell(),
                        Messages.getString("NewReportProjectWizard.errorMessage"), //$NON-NLS-1$
                        null, // no special message
                        ((CoreException) t).getStatus());
            }
        } else {
            // CoreExceptions are handled above, but unexpected runtime
            // exceptions and errors may still occur.
            ExceptionUtil.handle(e);

            MessageDialog.openError(composite.getShell(),
                    Messages.getString("NewReportProjectWizard.errorMessage"), //$NON-NLS-1$
                    Messages.getFormattedString("NewReportProjectWizard.internalError", //$NON-NLS-1$
                            new Object[] { t.getMessage() }));
        }
        return null;
    }

    return projectHandle;
}

From source file:org.eclipse.datatools.enablement.sybase.asa.schemaobjecteditor.examples.tableeditor.pages.columns.ASATableEditorColumnsViewerCellModifier.java

License:Open Source License

private boolean removeReferencingUniqueConstraints(ASATableEditorColumnRowData asaRow, boolean onlyRemovePK) {
    // If current is nullable and it's referenced by unique constraint/pk, should remove it from the constraint
    if (asaRow.getColumn() != null) {
        BaseTable table = (BaseTable) asaRow.getColumn().eContainer();
        List matches = TableModelUtil.getMatchedColumnUniqueConstraint(table, asaRow.getColumn());
        if (onlyRemovePK) {
            Iterator iter = matches.iterator();
            matches = new ArrayList();
            while (iter.hasNext()) {
                Object obj = iter.next();
                if (obj instanceof PrimaryKey) {
                    matches.add(obj);//from  w  ww. j av a2 s  .co m
                    break;
                }
            }
        }
        if (matches.size() > 0) {

            if (true) {
                MessageDialog d = new MessageDialog(_viewer.getControl().getShell(),
                        Messages.ASATableEditorColumnsViewerCellModifier_remove_constraints, null,
                        Messages.ASATableEditorColumnsViewerCellModifier_constraints_remove_also
                                + TableModelUtil.constructConstraintNamesList(matches)
                                + Messages.ASATableEditorColumnsViewerCellModifier_continue,
                        MessageDialog.QUESTION,
                        new String[] { IDialogConstants.OK_LABEL, IDialogConstants.CANCEL_LABEL }, 0);
                d.open();
                int result = d.getReturnCode();
                switch (result) {
                case MessageDialog.OK:
                    Iterator iter = matches.iterator();
                    List uniquesTobeRemoved = new ArrayList();
                    // table.eSetDeliver(true);
                    while (iter.hasNext()) {
                        uniquesTobeRemoved.add(iter.next());
                    }
                    table.getConstraints().removeAll(uniquesTobeRemoved);
                    // table.eSetDeliver(false);
                    return true;
                case MessageDialog.CANCEL:
                    asaRow.updateValue(ASATableEditorColumnsTableData.NULLABLE_COLUMN, "false"); //$NON-NLS-1$
                    _viewer.refresh();
                    return false;
                default:
                    break;
                }
            } else {
                Iterator iter = matches.iterator();
                // table.eSetDeliver(true);
                while (iter.hasNext()) {
                    table.getConstraints().remove(iter.next());
                }
                // table.eSetDeliver(false);
                return true;
            }
        }
        boolean nullable = false;
        if (asaRow.getValue(ASATableEditorColumnsTableData.NULLABLE_COLUMN) != null) {
            nullable = Boolean.valueOf((String) asaRow.getValue(ASATableEditorColumnsTableData.NULLABLE_COLUMN))
                    .booleanValue();
        }

        // If current column is selected to be nullable, should remove it from unique constraints
        if (nullable) {
            TableModelUtil.removeColumnFromRefConstraints(table, asaRow.getColumn());
        }

        boolean isPK = false;
        if (asaRow.getValue(ASATableEditorColumnsTableData.PRI_KEY_COLUMN) != null) {
            isPK = Boolean.valueOf((String) asaRow.getValue(ASATableEditorColumnsTableData.PRI_KEY_COLUMN))
                    .booleanValue();
        }
        // If current column is deleted from PK, remove it from PK
        if (table.getPrimaryKey() != null && !isPK) {
            table.getPrimaryKey().getMembers().remove(asaRow.getColumn());
        }
    }
    return true;
}

From source file:org.eclipse.datatools.sqltools.sqlbuilder.util.RSCCoreUIUtil.java

License:Open Source License

public static int launchSyncDialog(final MessageDialog dialog) {
    Display.getDefault().syncExec(new Runnable() {
        public void run() {
            dialog.open();//w  ww .  j a v a2  s .  co m
        };
    });
    return dialog.getReturnCode();
}

From source file:org.eclipse.datatools.sqltools.sqlbuilder.util.RSCCoreUIUtil.java

License:Open Source License

public static int launchASyncDialog(final MessageDialog dialog) {
    Display.getDefault().asyncExec(new Runnable() {
        public void run() {
            dialog.open();//from ww w . j a  v a  2s .  c  o  m
        };
    });
    return dialog.getReturnCode();
}