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:org.talend.mdm.repository.ui.wizards.imports.ImportServerObjectWizard.java

License:Open Source License

private int isOveride(String name, String obTypeName) {

    final MessageDialog dialog = new MessageDialog(getShell(), Messages.Confirm_Overwrite, null,
            Messages.bind(Messages.Confirm_Overwrite_Info, obTypeName, name), MessageDialog.QUESTION,
            new String[] { IDialogConstants.YES_LABEL, IDialogConstants.YES_TO_ALL_LABEL,
                    IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL },
            0);//from  w  ww  . j a  v  a2 s.  c  o m
    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:org.talend.repository.ui.actions.importproject.ImportDemoProjectItemsPage.java

License:Open Source License

public boolean performFinish() {
    List<DemoProjectBean> checkedElements = getCheckedElements();
    final List<ResourcesManager> finalCheckManagers = getResourceManagers(checkedElements);
    String warnMessage = populateExistItemRecords(finalCheckManagers);
    if (!warnMessage.equals("")) {
        MessageDialog dialog = new MessageDialog(getShell(),
                Messages.getString("ImportDemoProjectPage.overwrite"), null, warnMessage,
                MessageDialog.QUESTION, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL },
                0);/* ww w. ja  v  a 2 s  . c o  m*/
        dialog.open();
        int result = dialog.getReturnCode();
        if (result != MessageDialog.OK) {
            return false;
        }
    }

    ProgressDialog progressDialog = new ProgressDialog(getShell()) {

        private IProgressMonitor monitorWrap;

        @Override
        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            monitorWrap = new EventLoopProgressMonitor(monitor);
            try {
                for (ResourcesManager resManager : finalCheckManagers) {
                    List<ImportItem> projectRecords = importManager.populateImportingItems(resManager, true,
                            monitorWrap);
                    // clearOverWriteErrorMessages(projectRecords, overwrite);
                    importManager.importItemRecords(monitorWrap, resManager, projectRecords, true,
                            projectRecords.toArray(new ImportItem[0]), null);
                }
            } catch (Exception e) {
                ExceptionHandler.process(e);
            }
            monitorWrap.done();
            if (monitor.isCanceled()) {
                MessageDialog.openInformation(getShell(),
                        Messages.getString("ImportDemoProjectAction.messageDialogTitle.demoProjectCancel"),
                        Messages.getString(
                                "ImportDemoProjectAction.messageDialogContent.demoProjectImportedIncompletely"));
                return;
            } else {
                MessageDialog.openInformation(getShell(),
                        Messages.getString("ImportDemoProjectAction.messageDialogTitle.demoProject"), //$NON-NLS-1$
                        Messages.getString(
                                "ImportDemoProjectAction.messageDialogContent.demoProjectImportedSuccessfully")); //$NON-NLS-1$

            }
        }
    };

    try {
        progressDialog.executeProcess();
    } catch (InvocationTargetException e) {
        MessageBoxExceptionHandler.process(e.getTargetException(), getShell());
    } catch (InterruptedException e) {
        // Nothing to do
    }

    return true;
}

From source file:org.talend.repository.ui.wizards.exportjob.JobScriptsExportWizardPage.java

License:Open Source License

/**
 * The Finish button was pressed. Try to do the required work now and answer a boolean indicating success. If false
 * is returned then the wizard will not close.
 * /*  w ww  .j a v a  2 s  . c  o m*/
 * @returns boolean
 */
@Override
public boolean finish() {
    // TODO
    if (treeViewer != null) {
        treeViewer.removeCheckStateListener(checkStateListener);
    }

    saveWidgetValues();

    if (!ensureTargetIsValid()) {
        return false;
    }

    if (ensureLog4jSettingIsValid()) {
        MessageDialog dialog = new MessageDialog(getShell(), "Question", null,
                Messages.getString("Log4jSettingPage.IlleagalBuild"), MessageDialog.QUESTION,
                new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 0);
        dialog.open();
        int result = dialog.getReturnCode();
        if (result != MessageDialog.OK) {
            return false;
        }
    }

    JobExportType jobExportType = getCurrentExportType1();
    if (JobExportType.POJO.equals(jobExportType)) {
        IRunnableWithProgress worker = new IRunnableWithProgress() {

            @Override
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                buildJobWithMaven(JobExportType.POJO, monitor);
            }
        };

        try {
            getContainer().run(false, true, worker);
        } catch (InvocationTargetException e) {
            MessageBoxExceptionHandler.process(e.getCause(), getShell());
            return false;
        } catch (InterruptedException e) {
            return false;
        }

    } else {

        List<ContextParameterType> contextEditableResultValuesList = null;
        if (manager != null) {
            contextEditableResultValuesList = manager.getContextEditableResultValuesList();
        }
        manager = createJobScriptsManager();
        if (nodes.length == 1) {
            RepositoryNode node = nodes[0];
            if (node.getType() == ENodeType.SYSTEM_FOLDER) {
                manager.setTopFolderName(ProjectManager.getInstance().getCurrentProject().getLabel());
            } else {
                manager.setTopFolderName(getDefaultFileNameWithType());
            }
        } else {
            manager.setTopFolderName(getDefaultFileNameWithType());
        }

        // for feature:11976, recover back the old default manager value with ContextParameters
        if (contextEditableResultValuesList == null) {
            manager.setContextEditableResultValuesList(new ArrayList<ContextParameterType>());
        } else {
            manager.setContextEditableResultValuesList(contextEditableResultValuesList);
        }

        manager.setMultiNodes(isMultiNodes());
        // achen modify to fix bug 0006222

        IRunnableWithProgress worker = new JobExportAction(Arrays.asList(getCheckNodes()),
                getSelectedJobVersion(), manager, originalRootFolderName, getProcessType());

        try {
            getContainer().run(false, true, worker);
        } catch (InvocationTargetException e) {
            MessageBoxExceptionHandler.process(e.getCause(), getShell());
            return false;
        } catch (InterruptedException e) {
            return false;
        }
    }

    // see bug 7181
    if (zipOption != null && zipOption.equals("true")) { //$NON-NLS-1$
        // unzip
        try {
            String zipFile;
            if (manager != null) {
                zipFile = manager.getDestinationPath();
            } else {
                zipFile = getDestinationValue();
                int separatorIndex = zipFile.lastIndexOf(File.separator);
                if (separatorIndex == -1) {
                    String userDir = System.getProperty("user.dir"); //$NON-NLS-1$
                    zipFile = userDir + File.separator + zipFile;
                }
            }
            // Added by Marvin Wang on Feb.1, 2012 for bug TDI-18824
            File file = new File(zipFile);
            if (file.exists()) {
                ZipToFile.unZipFile(zipFile, file.getParentFile().getAbsolutePath());
            }
        } catch (Exception e) {
            MessageBoxExceptionHandler.process(e, getShell());
            return false;
        }
    }

    if (treeViewer != null) {
        treeViewer.dispose();
    }

    // end
    return true;
}

From source file:org.tigris.subversion.subclipse.ui.operations.SVNOperation.java

License:Open Source License

/**
 * This method prompts the user to overwrite an existing resource. It uses the
 * <code>involvesMultipleResources</code> to determine what buttons to show.
 * @param project//  ww  w .  j av  a 2  s.  c o  m
 * @return
 */
protected boolean promptToOverwrite(final String title, final String msg) {
    if (!confirmOverwrite) {
        return true;
    }
    final String buttons[];
    if (involvesMultipleResources()) {
        buttons = new String[] { IDialogConstants.YES_LABEL, IDialogConstants.YES_TO_ALL_LABEL,
                IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL };
    } else {
        buttons = new String[] { IDialogConstants.OK_LABEL, IDialogConstants.CANCEL_LABEL };
    }
    final Shell displayShell = getShell();
    if (displayShell == null) {
        // We couldn't get a shell (perhaps due to shutdown)
        return false;
    }

    // run in syncExec because callback is from an operation,
    // which is probably not running in the UI thread.
    final int[] code = new int[] { 0 };
    displayShell.getDisplay().syncExec(new Runnable() {
        public void run() {
            MessageDialog dialog = new MessageDialog(displayShell, title, null, msg, MessageDialog.QUESTION,
                    buttons, 0);
            dialog.open();
            code[0] = dialog.getReturnCode();
        }
    });
    if (involvesMultipleResources()) {
        switch (code[0]) {
        case 0://Yes
            return true;
        case 1://Yes to all
            confirmOverwrite = false;
            return true;
        case 2://No
            return false;
        case 3://Cancel
        default:
            throw new OperationCanceledException();
        }
    } else {
        return code[0] == 0;
    }
}

From source file:org.tigris.subversion.subclipse.ui.subscriber.CommitSynchronizeOperation.java

License:Open Source License

/**
 * Prompts the user to determine how conflicting changes should be handled.
 * Note: This method is designed to be overridden by test cases.
 * @return 0 to sync conflicts, 1 to sync all non-conflicts, 2 to cancel
 *//* w  w w . j av a  2  s. c  o  m*/
private int promptForConflicts(Shell shell, SyncInfoSet syncSet) {
    String[] buttons = new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL };
    String title = Policy.bind("SyncAction.commit.conflict.title"); //$NON-NLS-1$
    String question = Policy.bind("SyncAction.commit.conflict.question"); //$NON-NLS-1$
    final MessageDialog dialog = new MessageDialog(shell, title, null, question, MessageDialog.QUESTION,
            buttons, 0);
    shell.getDisplay().syncExec(new Runnable() {
        public void run() {
            dialog.open();
        }
    });
    return dialog.getReturnCode();
}

From source file:org.tigris.subversion.subclipse.ui.util.PromptingDialog.java

License:Open Source License

/**
 * Opens the confirmation dialog based on the prompt condition settings.
 *///  ww w . ja v  a2 s  . com
private boolean confirmOverwrite(String msg) throws InterruptedException {
    if (!confirmOverwrite) {
        return true;
    }
    final MessageDialog dialog = new MessageDialog(shell, title, null, msg, MessageDialog.QUESTION, buttons, 0);

    // run in syncExec because callback is from an operation,
    // which is probably not running in the UI thread.
    shell.getDisplay().syncExec(new Runnable() {
        public void run() {
            dialog.open();
        }
    });
    if (hasMultipleResources) {
        switch (dialog.getReturnCode()) {
        case 0://Yes
            return true;
        case 1://Yes to all
            confirmOverwrite = false;
            return true;
        case 2://No
            return false;
        case 3://Cancel
        default:
            throw new InterruptedException();
        }
    } else {
        return dialog.getReturnCode() == 0;
    }
}

From source file:org.tigris.subversion.subclipse.ui.wizards.generatediff.GenerateDiffFileWizard.java

License:Open Source License

/**
 * Completes processing of the wizard. If this method returns <code>
 * true</code>, the wizard will close; otherwise, it will stay active.
 *///w w  w  .  j  a  va  2  s  .  c om
public boolean performFinish() {
    String fs = mainPage.getFilesystemFile();
    IFile ws = mainPage.getWorkspaceFile();
    int type = mainPage.getSaveType();
    boolean eclipseFormat = optionsPage.isMultiPatch();
    boolean projectRelative = optionsPage.isProjectRelative();

    try {
        if (type != mainPage.CLIPBOARD) {
            File file = new File(fs != null ? fs : ws.getLocation().toOSString());
            if (file.exists()) {
                // prompt then delete
                String title = Policy.bind("GenerateSVNDiff.overwriteTitle"); //$NON-NLS-1$
                String msg = Policy.bind("GenerateSVNDiff.overwriteMsg"); //$NON-NLS-1$
                final MessageDialog dialog = new MessageDialog(getShell(), title, null, msg,
                        MessageDialog.QUESTION,
                        new String[] { IDialogConstants.YES_LABEL, IDialogConstants.CANCEL_LABEL }, 0);

                dialog.open();

                if (dialog.getReturnCode() != 0) {
                    // cancel
                    return false;
                }
            }
            GenerateDiffFileOperation generateDiffFileOperation = new GenerateDiffFileOperation(getResources(),
                    getUnaddedResources(), file, false, false, eclipseFormat, projectRelative, getShell());
            generateDiffFileOperation.setSelectedResources(selectedResources);
            getContainer().run(true, true, generateDiffFileOperation);
            if (type == mainPage.WORKSPACE) {
                ws.getParent().refreshLocal(IResource.DEPTH_ONE, null);
            }
        } else {
            GenerateDiffFileOperation generateDiffFileOperation = new GenerateDiffFileOperation(getResources(),
                    getUnaddedResources(), null, true, false, eclipseFormat, projectRelative, getShell());
            generateDiffFileOperation.setSelectedResources(selectedResources);
            getContainer().run(true, true, generateDiffFileOperation);
        }
        return true;
    } catch (InterruptedException e1) {
        return true;
    } catch (CoreException e) {
        SVNUIPlugin.openError(getShell(), Policy.bind("GenerateSVNDiff.error"), null, e); //$NON-NLS-1$
        return false;
    } catch (InvocationTargetException e2) {
        SVNUIPlugin.openError(getShell(), Policy.bind("GenerateSVNDiff.error"), null, e2); //$NON-NLS-1$
        return false;
    }
}

From source file:spritey.ui.wizards.SpriteSheetWizard.java

License:Open Source License

@Override
public boolean performFinish() {
    isOverwrite = saveAsPage.isOverwrite();

    OverwriteQuery callback = new OverwriteQuery() {
        @Override//from   w  w w  .j a v a 2 s .  co  m
        public int queryOverwrite(String path) {
            if (isOverwrite) {
                return OverwriteQuery.ALL;
            }

            String[] buttons = new String[] { IDialogConstants.YES_LABEL, IDialogConstants.YES_TO_ALL_LABEL,
                    IDialogConstants.NO_LABEL, IDialogConstants.NO_TO_ALL_LABEL,
                    IDialogConstants.CANCEL_LABEL };

            File file = new File(path);
            String message = NLS.bind(Messages.SAVE_AS_OVERWRITE_FILE, file.getName(), file.getParent());
            final MessageDialog dialog = new MessageDialog(getShell(), Messages.SPRITE_SHEET_WIZARD_TITLE, null,
                    message, MessageDialog.QUESTION, buttons, 0) {
                @Override
                protected int getShellStyle() {
                    return super.getShellStyle() | SWT.SHEET;
                }
            };

            // This method is called from a non-UI thread, therefore,
            // opening dialog has to be wrapped into runnable and executed
            // in the UI thread.
            getShell().getDisplay().syncExec(new Runnable() {
                @Override
                public void run() {
                    dialog.open();
                }
            });
            return dialog.getReturnCode();
        }
    };

    try {
        SaveSheetOperation op = new SaveSheetOperation(newSheetPage.getConstraints(), newSheetPage.getSheet(),
                saveAsPage.getImageFile(), saveAsPage.getMetadataFile(), callback);
        getContainer().run(true, true, op);

        Shell parent = getContainer().getShell();
        IStatus status = op.getStatus();

        if (!status.isOK()) {
            // To make dialogs consistent throughout the application,
            // display a custom error dialog with details button only when
            // there are multiple problems. Otherwise display an OS native
            // dialog.
            if (status.isMultiStatus()) {
                ErrorDialog.openError(parent, Messages.SPRITE_SHEET_WIZARD_TITLE, null, status);
            } else {
                MessageDialog.open(MessageDialog.ERROR, parent, Messages.SPRITE_SHEET_WIZARD_TITLE,
                        status.getMessage(), SWT.SHEET);
            }
        } else {
            MessageDialog.open(MessageDialog.INFORMATION, parent, Messages.SPRITE_SHEET_WIZARD_TITLE,
                    Messages.SPRITE_SHEET_WIZARD_BUILT_SUCCESSFULLY, SWT.SHEET);
        }
    } catch (InterruptedException e) {
        return false;
    } catch (InvocationTargetException e) {
        throw new InternalError("Error occurred during save operation.", e);
    }
    return false;
}

From source file:ummisco.gama.ui.commands.RefreshHandler.java

void checkLocationDeleted(final IProject project) throws CoreException {
    if (!project.exists()) {
        return;/* w w  w  .  ja v  a 2 s  . c o m*/
    }
    final IFileInfo location = IDEResourceInfoUtils.getFileInfo(project.getLocationURI());
    if (!location.exists()) {
        final String message = NLS.bind(IDEWorkbenchMessages.RefreshAction_locationDeletedMessage,
                project.getName(), location.toString());

        final MessageDialog dialog = new MessageDialog(WorkbenchHelper.getShell(),
                IDEWorkbenchMessages.RefreshAction_dialogTitle, null, message, MessageDialog.QUESTION,
                new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 0) {
            @Override
            protected int getShellStyle() {
                return super.getShellStyle() | SWT.SHEET;
            }
        };
        WorkbenchHelper.run(() -> dialog.open());

        // Do the deletion back in the operation thread
        if (dialog.getReturnCode() == 0) { // yes was chosen
            project.delete(true, true, null);
        }
    }
}

From source file:ummisco.gama.ui.navigator.actions.RefreshAction.java

License:Open Source License

/**
 * Checks whether the given project's location has been deleted. If so, prompts the user with whether to delete the
 * project or not.//from  w ww .ja va 2s .  c om
 */
void checkLocationDeleted(final IProject project) throws CoreException {
    if (!project.exists()) {
        return;
    }
    final IFileInfo location = IDEResourceInfoUtils.getFileInfo(project.getLocationURI());
    if (!location.exists()) {
        final String message = NLS.bind(IDEWorkbenchMessages.RefreshAction_locationDeletedMessage,
                project.getName(), location.toString());

        final MessageDialog dialog = new MessageDialog(WorkbenchHelper.getShell(),
                IDEWorkbenchMessages.RefreshAction_dialogTitle, null, message, MessageDialog.QUESTION,
                new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 0) {
            @Override
            protected int getShellStyle() {
                return super.getShellStyle() | SWT.SHEET;
            }
        };
        WorkbenchHelper.run(() -> dialog.open());

        // Do the deletion back in the operation thread
        if (dialog.getReturnCode() == 0) { // yes was chosen
            project.delete(true, true, null);
        }
    }
}