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

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

Introduction

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

Prototype

int QUESTION_WITH_CANCEL

To view the source code for org.eclipse.jface.dialogs MessageDialog QUESTION_WITH_CANCEL.

Click Source Link

Document

Constant for a simple dialog with the question image and Yes/No/Cancel buttons (value 6).

Usage

From source file:org.eclipse.mylyn.reviews.r4e.upgrade.ui.R4EUpgradeController.java

License:Open Source License

/**
 * Method displayCompatibleUpgradeDialog.
 * //from   w  ww .  j  ava2  s. c om
 * @param aUpgrader
 *            IR4EVersionUpgrader
 * @return int
 */
public static int displayCompatibleUpgradeDialog(final String aElementMsg,
        final IR4EVersionUpgrader aUpgrader) {
    final int[] result = new int[1]; //We need this to be able to pass the result value outside.  This is safe as we are using SyncExec
    if (-1 == fUpgradeTestDialogResult) {
        final String upgraderMessage = COMPATIBILITY_COMPATIBLE_WARNING_MESSAGE
                + System.getProperty("line.separator") + System.getProperty("line.separator")
                + "Element meta-data Version: " + aUpgrader.getUpgradePath().getBaseVersion()
                + System.getProperty("line.separator") + System.getProperty("line.separator")
                + "Application meta-data Version: " + aUpgrader.getUpgradePath().getTargetVersion();

        R4EUpgradePlugin.Ftracer.traceWarning(upgraderMessage);
        Display.getDefault().syncExec(new Runnable() {
            public void run() {
                final MessageDialog dialog = new MessageDialog(null,
                        COMPATIBILITY_WARNING_DIALOG_TITLE + aElementMsg, null, upgraderMessage,
                        MessageDialog.QUESTION_WITH_CANCEL, COMPATIBLE_UPGRADE_DIALOG_BUTTONS, 0);
                result[0] = dialog.open();
            }
        });
    } else {
        result[0] = fUpgradeTestDialogResult;
    }
    return result[0];
}

From source file:org.eclipse.mylyn.reviews.r4e.upgrade.ui.R4EUpgradeController.java

License:Open Source License

/**
 * Method displayIncompatibleUpgradeDialog.
 * /*w w  w. jav  a  2 s  .c o  m*/
 * @param aUpgrader
 *            IR4EVersionUpgrader
 * @return int
 */
public static int displayIncompatibleUpgradeDialog(final String aElementMsg,
        final IR4EVersionUpgrader aUpgrader) {
    final int[] result = new int[1]; //We need this to be able to pass the result value outside.  This is safe as we are using SyncExec
    if (-1 == fUpgradeTestDialogResult) {
        final String upgraderMessage = COMPATIBILITY_INCOMPATIBLE_WARNING_MESSAGE
                + System.getProperty("line.separator") + System.getProperty("line.separator")
                + "Element meta-data Version: " + aUpgrader.getUpgradePath().getBaseVersion()
                + System.getProperty("line.separator") + System.getProperty("line.separator")
                + "Application meta-data Version: " + aUpgrader.getUpgradePath().getTargetVersion();
        R4EUpgradePlugin.Ftracer.traceWarning(upgraderMessage);
        Display.getDefault().syncExec(new Runnable() {
            public void run() {
                final MessageDialog dialog = new MessageDialog(null,
                        COMPATIBILITY_WARNING_DIALOG_TITLE + aElementMsg, null, upgraderMessage,
                        MessageDialog.QUESTION_WITH_CANCEL, INCOMPATIBLE_UPGRADE_DIALOG_BUTTONS, 0);
                result[0] = dialog.open();
            }
        });
    } else {
        result[0] = fUpgradeTestDialogResult;
    }
    return result[0];

}

From source file:org.eclipse.papyrus.diagram.composite.custom.edit.command.SetTypeWithDialogCommand.java

License:Open Source License

@Override
protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info)
        throws ExecutionException {

    CommandResult result;/*from ww w  .j  a  v a2s. c  o m*/
    Object currentValue = getElementToEdit().eGet(request.getFeature());
    if (currentValue != null) {
        String[] labels = new String[2];
        labels[0] = "OK";
        labels[1] = "Cancel";
        MessageDialog dialog = new MessageDialog(new Shell(), "Confirm changes", null,
                "Do you want to replace current type ?", MessageDialog.QUESTION_WITH_CANCEL, labels, 0);
        dialog.open();
        switch (dialog.getReturnCode()) {
        case MessageDialog.OK:
            result = super.doExecuteWithResult(monitor, info);
            break;
        default:
            result = CommandResult.newOKCommandResult();
            break;
        }
        ;

    } else {
        result = super.doExecuteWithResult(monitor, info);
    }

    return result;
}

From source file:org.eclipse.rap.examples.pages.MessageDialogUtil.java

License:Open Source License

private static String[] getButtonLabels(int kind) {
    String[] dialogButtonLabels;/* ww w.  j a  v a2s.  co  m*/
    switch (kind) {
    case MessageDialog.ERROR:
    case MessageDialog.INFORMATION:
    case MessageDialog.WARNING: {
        dialogButtonLabels = new String[] { IDialogConstants.get().OK_LABEL };
        break;
    }
    case MessageDialog.CONFIRM: {
        dialogButtonLabels = new String[] { IDialogConstants.get().OK_LABEL,
                IDialogConstants.get().CANCEL_LABEL };
        break;
    }
    case MessageDialog.QUESTION: {
        dialogButtonLabels = new String[] { IDialogConstants.get().YES_LABEL, IDialogConstants.get().NO_LABEL };
        break;
    }
    case MessageDialog.QUESTION_WITH_CANCEL: {
        dialogButtonLabels = new String[] { IDialogConstants.get().YES_LABEL, IDialogConstants.get().NO_LABEL,
                IDialogConstants.get().CANCEL_LABEL };
        break;
    }
    default: {
        throw new IllegalArgumentException("Illegal value for kind in MessageDialog.open()");
    }
    }
    return dialogButtonLabels;
}

From source file:org.eclipse.rcptt.ui.panels.main.ControlPanelWindow.java

License:Open Source License

private boolean openSaveDialog() {
    if (getModel() != null && !getModel().exists()) {
        return true;
    }// ww w  .j ava2s .  c  o  m
    MessageDialog dialog = new MessageDialog(getShell(), Messages.ControlPanelWindow_SaveDialogTitle, null,
            Messages.ControlPanelWindow_SaveDialogMsg, MessageDialog.QUESTION_WITH_CANCEL, new String[] {
                    IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL },
            0);
    int returnCode = dialog.open(); // Number of pressed button
    if (returnCode == 0) {
        if (getModel() != null) {
            save();
        } else {
            if (!saveAs()) {
                return false;
            }
        }
    }
    switch (returnCode) {
    case 2:
        return false; // User clicked Cancel button
    default:
        return true;
    }
}

From source file:org.eclipse.scada.sec.ui.ConfirmationDialogFuture.java

License:Open Source License

private Boolean showDialog(final ConfirmationCallback cb, final Display display, final Shell parentShell,
        final String dialogTitle) {
    switch (cb.getConfirmationType()) {
    case CONFIRM:
        return MessageDialog.openConfirm(parentShell, dialogTitle, cb.getLabel()) ? true : null;
    case ERROR:/*from   w  w w  .java  2 s .com*/
        MessageDialog.openError(parentShell, dialogTitle, cb.getLabel());
        return true;
    case WARNING:
        MessageDialog.openWarning(parentShell, dialogTitle, cb.getLabel());
        return true;
    case INFORMATION:
        MessageDialog.openInformation(parentShell, dialogTitle, cb.getLabel());
        return true;
    case QUESTION:
        return MessageDialog.openQuestion(parentShell, dialogTitle, cb.getLabel());
    case QUESTION_WITH_CANCEL: {
        final MessageDialog dialog = new MessageDialog(parentShell, dialogTitle, null, cb.getLabel(),
                MessageDialog.QUESTION_WITH_CANCEL, new String[] { IDialogConstants.YES_LABEL,
                        IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL },
                0);
        final int result = dialog.open();
        if (result == 2 /*CANCEL*/) {
            return null;
        } else {
            return result == Window.OK;
        }
    }
    default:
        throw new IllegalArgumentException(
                String.format("Unable to process type: %s", cb.getConfirmationType()));
    }
}

From source file:org.eclipse.ui.dialogs.WizardNewFileCreationPage.java

License:Open Source License

/**
 * Creates a new file resource in the selected container and with the
 * selected name. Creates any missing resource containers along the path;
 * does nothing if the container resources already exist.
 * <p>/*from  w  w w  .  j  a  va2 s  . c  o  m*/
 * In normal usage, this method is invoked after the user has pressed Finish
 * on the wizard; the enablement of the Finish button implies that all
 * controls on on this page currently contain valid values.
 * </p>
 * <p>
 * Note that this page caches the new file once it has been successfully
 * created; subsequent invocations of this method will answer the same file
 * resource without attempting to create it again.
 * </p>
 * <p>
 * This method should be called within a workspace modify operation since it
 * creates resources.
 * </p>
 * 
 * @return the created file resource, or <code>null</code> if the file was
 *         not created
 */
public IFile createNewFile() {
    if (newFile != null) {
        return newFile;
    }

    // create the new file and cache it if successful

    final IPath containerPath = resourceGroup.getContainerFullPath();
    IPath newFilePath = containerPath.append(resourceGroup.getResource());
    final IFile newFileHandle = createFileHandle(newFilePath);
    final InputStream initialContents = getInitialContents();

    createLinkTarget();

    if (linkTargetPath != null) {
        URI resolvedPath = newFileHandle.getPathVariableManager().resolveURI(linkTargetPath);
        try {
            if (resolvedPath.getScheme() != null && resolvedPath.getSchemeSpecificPart() != null) {
                IFileStore store = EFS.getStore(resolvedPath);
                if (!store.fetchInfo().exists()) {
                    MessageDialog dlg = new MessageDialog(getContainer().getShell(),
                            IDEWorkbenchMessages.WizardNewFileCreationPage_createLinkLocationTitle, null,
                            NLS.bind(IDEWorkbenchMessages.WizardNewFileCreationPage_createLinkLocationQuestion,
                                    linkTargetPath),
                            MessageDialog.QUESTION_WITH_CANCEL, new String[] { IDialogConstants.YES_LABEL,
                                    IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL },
                            0);
                    int result = dlg.open();
                    if (result == Window.OK) {
                        store.getParent().mkdir(0, new NullProgressMonitor());
                        OutputStream stream = store.openOutputStream(0, new NullProgressMonitor());
                        stream.close();
                    }
                    if (result == 2)
                        return null;
                }
            }
        } catch (CoreException e) {
            MessageDialog.open(MessageDialog.ERROR, getContainer().getShell(),
                    IDEWorkbenchMessages.WizardNewFileCreationPage_internalErrorTitle,
                    NLS.bind(IDEWorkbenchMessages.WizardNewFileCreationPage_internalErrorMessage,
                            e.getMessage()),
                    SWT.SHEET);

            return null;
        } catch (IOException e) {
            MessageDialog.open(MessageDialog.ERROR, getContainer().getShell(),
                    IDEWorkbenchMessages.WizardNewFileCreationPage_internalErrorTitle,
                    NLS.bind(IDEWorkbenchMessages.WizardNewFileCreationPage_internalErrorMessage,
                            e.getMessage()),
                    SWT.SHEET);

            return null;
        }
    }

    IRunnableWithProgress op = new IRunnableWithProgress() {
        public void run(IProgressMonitor monitor) {
            CreateFileOperation op = new CreateFileOperation(newFileHandle, linkTargetPath, initialContents,
                    IDEWorkbenchMessages.WizardNewFileCreationPage_title);
            try {
                // see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=219901
                // directly execute the operation so that the undo state is
                // not preserved.  Making this undoable resulted in too many 
                // accidental file deletions.
                op.execute(monitor, WorkspaceUndoUtil.getUIInfoAdapter(getShell()));
            } catch (final ExecutionException e) {
                getContainer().getShell().getDisplay().syncExec(new Runnable() {
                    public void run() {
                        if (e.getCause() instanceof CoreException) {
                            ErrorDialog.openError(getContainer().getShell(), // Was
                                    // Utilities.getFocusShell()
                                    IDEWorkbenchMessages.WizardNewFileCreationPage_errorTitle, null, // no special
                                    // message
                                    ((CoreException) e.getCause()).getStatus());
                        } else {
                            IDEWorkbenchPlugin.log(getClass(), "createNewFile()", e.getCause()); //$NON-NLS-1$
                            MessageDialog.openError(getContainer().getShell(),
                                    IDEWorkbenchMessages.WizardNewFileCreationPage_internalErrorTitle,
                                    NLS.bind(
                                            IDEWorkbenchMessages.WizardNewFileCreationPage_internalErrorMessage,
                                            e.getCause().getMessage()));
                        }
                    }
                });
            }
        }
    };
    try {
        getContainer().run(true, true, op);
    } catch (InterruptedException e) {
        return null;
    } catch (InvocationTargetException e) {
        // Execution Exceptions are handled above but we may still get
        // unexpected runtime errors.
        IDEWorkbenchPlugin.log(getClass(), "createNewFile()", e.getTargetException()); //$NON-NLS-1$
        MessageDialog.open(MessageDialog.ERROR, getContainer().getShell(),
                IDEWorkbenchMessages.WizardNewFileCreationPage_internalErrorTitle,
                NLS.bind(IDEWorkbenchMessages.WizardNewFileCreationPage_internalErrorMessage,
                        e.getTargetException().getMessage()),
                SWT.SHEET);

        return null;
    }

    newFile = newFileHandle;

    return newFile;
}

From source file:org.eclipse.ui.dialogs.WizardNewFolderMainPage.java

License:Open Source License

/**
 * Creates a new folder resource in the selected container and with the
 * selected name. Creates any missing resource containers along the path;
 * does nothing if the container resources already exist.
 * <p>//w  w  w  . ja  v  a2  s .co  m
 * In normal usage, this method is invoked after the user has pressed Finish
 * on the wizard; the enablement of the Finish button implies that all
 * controls on this page currently contain valid values.
 * </p>
 * <p>
 * Note that this page caches the new folder once it has been successfully
 * created; subsequent invocations of this method will answer the same
 * folder resource without attempting to create it again.
 * </p>
 * <p>
 * This method should be called within a workspace modify operation since it
 * creates resources.
 * </p>
 * 
 * @return the created folder resource, or <code>null</code> if the folder
 *         was not created
 */
public IFolder createNewFolder() {
    if (newFolder != null) {
        return newFolder;
    }

    // create the new folder and cache it if successful
    final IPath containerPath = resourceGroup.getContainerFullPath();
    IPath newFolderPath = containerPath.append(resourceGroup.getResource());
    final IFolder newFolderHandle = createFolderHandle(newFolderPath);

    final boolean createVirtualFolder = useVirtualFolder != null && useVirtualFolder.getSelection();
    createLinkTarget();
    if (linkTargetPath != null) {
        URI resolvedPath = newFolderHandle.getPathVariableManager().resolveURI(linkTargetPath);
        try {
            IFileStore store = EFS.getStore(resolvedPath);
            if (!store.fetchInfo().exists()) {
                MessageDialog dlg = new MessageDialog(getContainer().getShell(),
                        IDEWorkbenchMessages.WizardNewFolderCreationPage_createLinkLocationTitle, null,
                        NLS.bind(IDEWorkbenchMessages.WizardNewFolderCreationPage_createLinkLocationQuestion,
                                linkTargetPath),
                        MessageDialog.QUESTION_WITH_CANCEL, new String[] { IDialogConstants.YES_LABEL,
                                IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL },
                        0);
                int result = dlg.open();
                if (result == Window.OK) {
                    store.mkdir(0, new NullProgressMonitor());
                }
                if (result == 2)
                    return null;
            }
        } catch (CoreException e) {
            MessageDialog.open(MessageDialog.ERROR, getContainer().getShell(),
                    IDEWorkbenchMessages.WizardNewFileCreationPage_internalErrorTitle,
                    NLS.bind(IDEWorkbenchMessages.WizardNewFileCreationPage_internalErrorMessage,
                            e.getMessage()),
                    SWT.SHEET);

            return null;
        }
    }
    IRunnableWithProgress op = new IRunnableWithProgress() {
        public void run(IProgressMonitor monitor) {
            AbstractOperation op;
            op = new CreateFolderOperation(newFolderHandle, linkTargetPath, createVirtualFolder, filterList,
                    IDEWorkbenchMessages.WizardNewFolderCreationPage_title);
            try {
                // see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=219901
                // directly execute the operation so that the undo state is
                // not preserved.  Making this undoable can result in accidental
                // folder (and file) deletions.
                op.execute(monitor, WorkspaceUndoUtil.getUIInfoAdapter(getShell()));
            } catch (final ExecutionException e) {
                getContainer().getShell().getDisplay().syncExec(new Runnable() {
                    public void run() {
                        if (e.getCause() instanceof CoreException) {
                            ErrorDialog.openError(getContainer().getShell(), // Was Utilities.getFocusShell()
                                    IDEWorkbenchMessages.WizardNewFolderCreationPage_errorTitle, null, // no special message
                                    ((CoreException) e.getCause()).getStatus());
                        } else {
                            IDEWorkbenchPlugin.log(getClass(), "createNewFolder()", e.getCause()); //$NON-NLS-1$
                            MessageDialog.openError(getContainer().getShell(),
                                    IDEWorkbenchMessages.WizardNewFolderCreationPage_internalErrorTitle,
                                    NLS.bind(IDEWorkbenchMessages.WizardNewFolder_internalError,
                                            e.getCause().getMessage()));
                        }
                    }
                });
            }
        }
    };

    try {
        getContainer().run(true, true, op);
    } catch (InterruptedException e) {
        return null;
    } catch (InvocationTargetException e) {
        // ExecutionExceptions are handled above, but unexpected runtime
        // exceptions and errors may still occur.
        IDEWorkbenchPlugin.log(getClass(), "createNewFolder()", e.getTargetException()); //$NON-NLS-1$
        MessageDialog.open(MessageDialog.ERROR, getContainer().getShell(),
                IDEWorkbenchMessages.WizardNewFolderCreationPage_internalErrorTitle,
                NLS.bind(IDEWorkbenchMessages.WizardNewFolder_internalError,
                        e.getTargetException().getMessage()),
                SWT.SHEET);
        return null;
    }

    newFolder = newFolderHandle;

    return newFolder;
}

From source file:org.eclipse.wst.sse.ui.internal.UnknownContentTypeDialog2.java

License:Open Source License

public UnknownContentTypeDialog2(Shell parent, IPreferenceStore store, String fileName,
        IContentTypeSettings contentTypeSettings) {
    // set message to null in super so that message does not appear twice
    super(parent, SSEUIMessages.UnknownContentTypeDialog_0, null, null, MessageDialog.QUESTION_WITH_CANCEL,
            new String[] { IDialogConstants.OK_LABEL, IDialogConstants.CANCEL_LABEL }, 0);
    this.fFileName = fileName;
    this.fContentTypeSettings = contentTypeSettings;
}

From source file:org.evosuite.eclipse.popup.actions.TestGenerationAction.java

License:Open Source License

/**
 * Add a new test generation job to the job queue
 * /*from   ww  w.  j  a v a2s. c  o  m*/
 * @param target
 */
protected void addTestJob(final IResource target) {
    IJavaElement element = JavaCore.create(target);
    if (element == null) {
        return;
    }
    IJavaElement packageElement = element.getParent();

    String packageName = packageElement.getElementName();

    final String targetClass = (!packageName.isEmpty() ? packageName + "." : "")
            + target.getName().replace(".java", "").replace(File.separator, ".");
    System.out.println("* Scheduling new automated job for " + targetClass);
    final String targetClassWithoutPackage = target.getName().replace(".java", "");

    final String suiteClassName = targetClass + Properties.JUNIT_SUFFIX;

    final String suiteFileName = target.getProject().getLocation() + "/evosuite-tests/"
            + suiteClassName.replace('.', File.separatorChar) + ".java";
    System.out.println("Checking for " + suiteFileName);
    File suiteFile = new File(suiteFileName);
    Job job = null;
    if (suiteFile.exists()) {

        MessageDialog dialog = new MessageDialog(shell, "Existing test suite found", null, // image
                "A test suite for class \"" + targetClass
                        + "\" already exists. EvoSuite will overwrite this test suite. Do you really want to proceed?",
                MessageDialog.QUESTION_WITH_CANCEL,
                new String[] { "Overwrite", "Extend", "Rename Original", "Cancel" }, 0);

        int returnCode = dialog.open();
        // 0 == overwrite
        // 1 == extend
        if (returnCode == 1) {
            IWorkspaceRoot wroot = target.getWorkspace().getRoot();
            IResource suiteResource = wroot.getFileForLocation(new Path(suiteFileName));
            job = new TestExtensionJob(shell, suiteResource, targetClass, suiteClassName);
        } else if (returnCode == 2) {
            // 2 == Rename
            renameSuite(target, packageName, targetClassWithoutPackage + Properties.JUNIT_SUFFIX + ".java");
        } else if (returnCode > 2) {
            // Cancel
            return;
        }
    }

    if (job == null)
        job = new TestGenerationJob(shell, target, targetClass, suiteClassName);

    job.setPriority(Job.SHORT);
    IResourceRuleFactory ruleFactory = ResourcesPlugin.getWorkspace().getRuleFactory();
    ISchedulingRule rule = ruleFactory.createRule(target.getProject());

    //IFolder folder = proj.getFolder(ResourceUtil.EVOSUITE_FILES);
    job.setRule(rule);
    job.setUser(true);
    job.schedule(); // start as soon as possible
}