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

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

Introduction

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

Prototype

int QUESTION

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

Click Source Link

Document

Constant for the question image, or a simple dialog with the question image and Yes/No buttons (value 3).

Usage

From source file:ext.org.eclipse.jdt.internal.ui.preferences.OptionsConfigurationBlock.java

License:Open Source License

protected boolean processChanges(IWorkbenchPreferenceContainer container) {
    IScopeContext currContext = fLookupOrder[0];

    List<Key> changedOptions = new ArrayList<Key>();
    boolean needsBuild = getChanges(currContext, changedOptions);
    if (changedOptions.isEmpty()) {
        return true;
    }/*from ww w .j a  v a 2  s .co  m*/
    if (needsBuild) {
        int count = getRebuildCount();
        if (count > fRebuildCount) {
            needsBuild = false; // build already requested
            fRebuildCount = count;
        }
    }

    boolean doBuild = false;
    if (needsBuild) {
        String[] strings = getFullBuildDialogStrings(fProject == null);
        if (strings != null) {
            MessageDialog dialog = new MessageDialog(getShell(), strings[0], null, strings[1],
                    MessageDialog.QUESTION, new String[] { IDialogConstants.YES_LABEL,
                            IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL },
                    2);
            int res = dialog.open();
            if (res == 0) {
                doBuild = true;
            } else if (res != 1) {
                return false; // cancel pressed
            }
        }
    }
    if (container != null) {
        // no need to apply the changes to the original store: will be done by the page container
        if (doBuild) { // post build
            incrementRebuildCount();
            container.registerUpdateJob(CoreUtility.getBuildJob(fProject));
        }
    } else {
        // apply changes right away
        try {
            fManager.applyChanges();
        } catch (BackingStoreException e) {
            JavaPlugin.log(e);
            return false;
        }
        if (doBuild) {
            CoreUtility.getBuildJob(fProject).schedule();
        }

    }
    return true;
}

From source file:ext.org.eclipse.jdt.internal.ui.refactoring.reorg.DeleteAction.java

License:Open Source License

/**
 * Removes or hides the selected working sets.
 * //from   w ww. j  a  va 2s  . c  o  m
 * @param selection the selected working sets
 * @since 3.5
 */
private void deleteWorkingSets(IStructuredSelection selection) {
    MessageDialog dialog;
    if (selection.size() == 1) {
        IWorkingSet workingSet = (IWorkingSet) selection.getFirstElement();
        final String workingSetID = workingSet.getId();
        dialog = new MessageDialog(getShell(), ReorgMessages.DeleteWorkingSet_single, null,
                MessageFormat.format(ReorgMessages.DeleteWorkingSet_removeorhideworkingset_single,
                        new Object[] { workingSet.getLabel() }),
                MessageDialog.QUESTION, new String[] { ReorgMessages.DeleteWorkingSet_Hide,
                        ReorgMessages.DeleteWorkingSet_Remove, IDialogConstants.CANCEL_LABEL },
                0) {
            /*
             * @see org.eclipse.jface.dialogs.MessageDialog#createButton(org.eclipse.swt.widgets.Composite, int, java.lang.String, boolean)
             * @since 3.5
             */
            @Override
            protected Button createButton(Composite parent, int id, String label, boolean defaultButton) {
                Button button = super.createButton(parent, id, label, defaultButton);
                if (id == REMOVE_BUTTON && IWorkingSetIDs.OTHERS.equals(workingSetID))
                    button.setEnabled(false);
                return button;
            }
        };
    } else {
        dialog = new MessageDialog(getShell(), ReorgMessages.DeleteWorkingSet_multiple, null,
                MessageFormat.format(ReorgMessages.DeleteWorkingSet_removeorhideworkingset_multiple,
                        new Object[] { new Integer(selection.size()) }),
                MessageDialog.QUESTION, new String[] { ReorgMessages.DeleteWorkingSet_Hide,
                        ReorgMessages.DeleteWorkingSet_Remove, IDialogConstants.CANCEL_LABEL },
                0);
    }

    int dialogResponse = dialog.open();
    if (dialogResponse == REMOVE_BUTTON) {
        Iterator<?> iter = selection.iterator();
        IWorkingSetManager manager = PlatformUI.getWorkbench().getWorkingSetManager();
        while (iter.hasNext()) {
            IWorkingSet workingSet = (IWorkingSet) iter.next();
            if (!(IWorkingSetIDs.OTHERS.equals(workingSet.getId())))
                manager.removeWorkingSet(workingSet);
        }
    } else if (dialogResponse == HIDE_BUTTON) {
        IWorkbenchPage page = JavaPlugin.getActivePage();
        if (page != null) {
            IWorkbenchPart activePart = page.getActivePart();
            if (activePart instanceof PackageExplorerPart) {
                PackageExplorerPart packagePart = (PackageExplorerPart) activePart;
                WorkingSetModel model = packagePart.getWorkingSetModel();
                List<IWorkingSet> activeWorkingSets = new ArrayList<IWorkingSet>(
                        Arrays.asList(model.getActiveWorkingSets()));
                activeWorkingSets.removeAll(SelectionUtil.toList(selection));
                model.setActiveWorkingSets(
                        activeWorkingSets.toArray(new IWorkingSet[activeWorkingSets.size()]));
            }
        }
    }
}

From source file:ext.org.eclipse.jdt.internal.ui.wizards.buildpaths.newsourcepage.AddFolderToBuildpathAction.java

License:Open Source License

/**
 * {@inheritDoc}//www.j  a v a 2s  . c o  m
 */
@Override
public void run() {

    try {
        final IJavaProject project;
        Object object = getSelectedElements().get(0);
        if (object instanceof IJavaProject) {
            project = (IJavaProject) object;
        } else if (object instanceof IPackageFragment) {
            project = ((IPackageFragment) object).getJavaProject();
        } else {
            IFolder folder = (IFolder) object;
            project = JavaCore.create(folder.getProject());
            if (project == null)
                return;
        }

        final Shell shell = getShell();

        final boolean removeProjectFromClasspath;
        IPath outputLocation = project.getOutputLocation();
        final IPath defaultOutputLocation = outputLocation.makeRelative();
        final IPath newDefaultOutputLocation;
        final boolean removeOldClassFiles;
        IPath projPath = project.getProject().getFullPath();
        if (!(getSelectedElements().size() == 1 && getSelectedElements().get(0) instanceof IJavaProject) && //if only the project should be added, then the query does not need to be executed
                (outputLocation.equals(projPath) || defaultOutputLocation.segmentCount() == 1)) {

            final OutputFolderQuery outputFolderQuery = ClasspathModifierQueries.getDefaultFolderQuery(shell,
                    defaultOutputLocation);
            if (outputFolderQuery.doQuery(true, ClasspathModifier.getValidator(getSelectedElements(), project),
                    project)) {
                newDefaultOutputLocation = outputFolderQuery.getOutputLocation();
                removeProjectFromClasspath = outputFolderQuery.removeProjectFromClasspath();

                if (BuildPathsBlock.hasClassfiles(project.getProject()) && outputLocation.equals(projPath)) {
                    String title = NewWizardMessages.BuildPathsBlock_RemoveBinariesDialog_title;
                    String message = Messages.format(
                            NewWizardMessages.BuildPathsBlock_RemoveBinariesDialog_description,
                            BasicElementLabels.getPathLabel(projPath, false));
                    MessageDialog dialog = new MessageDialog(shell, title, null, message,
                            MessageDialog.QUESTION, new String[] { IDialogConstants.YES_LABEL,
                                    IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL },
                            0);
                    int answer = dialog.open();
                    if (answer == 0) {
                        removeOldClassFiles = true;
                    } else if (answer == 1) {
                        removeOldClassFiles = false;
                    } else {
                        return;
                    }
                } else {
                    removeOldClassFiles = false;
                }
            } else {
                return;
            }
        } else {
            removeProjectFromClasspath = false;
            removeOldClassFiles = false;
            newDefaultOutputLocation = defaultOutputLocation;
        }

        try {
            final IRunnableWithProgress runnable = new IRunnableWithProgress() {
                public void run(IProgressMonitor monitor)
                        throws InvocationTargetException, InterruptedException {
                    try {
                        List<IJavaElement> result = addToClasspath(getSelectedElements(), project,
                                newDefaultOutputLocation.makeAbsolute(), removeProjectFromClasspath,
                                removeOldClassFiles, monitor);
                        selectAndReveal(new StructuredSelection(result));
                    } catch (CoreException e) {
                        throw new InvocationTargetException(e);
                    }
                }
            };
            fContext.run(false, false, runnable);
        } catch (final InvocationTargetException e) {
            if (e.getCause() instanceof CoreException) {
                showExceptionDialog((CoreException) e.getCause(),
                        NewWizardMessages.AddSourceFolderToBuildpathAction_ErrorTitle);
            } else {
                JavaPlugin.log(e);
            }
        } catch (final InterruptedException e) {
        }
    } catch (CoreException e) {
        showExceptionDialog(e, NewWizardMessages.AddSourceFolderToBuildpathAction_ErrorTitle);
    }
}

From source file:ext.org.eclipse.jdt.internal.ui.wizards.buildpaths.newsourcepage.RemoveLinkedFolderDialog.java

License:Open Source License

/**
 * Creates a new remove linked folder dialog.
 *
 * @param shell the parent shell to use//from   w w w  .j  a v a2s  .c  o  m
 * @param folder the linked folder to remove
 */
RemoveLinkedFolderDialog(final Shell shell, final IFolder folder) {
    super(shell, NewWizardMessages.ClasspathModifierQueries_confirm_remove_linked_folder_label, null,
            Messages.format(NewWizardMessages.ClasspathModifierQueries_confirm_remove_linked_folder_message,
                    new Object[] { BasicElementLabels.getPathLabel(folder.getFullPath(), false) }),
            MessageDialog.QUESTION, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 0); // yes is the default
    Assert.isTrue(folder.isLinked());
}

From source file:ext.org.eclipse.jdt.internal.ui.wizards.buildpaths.VariableBlock.java

License:Open Source License

public boolean performOk() {
    ArrayList<String> removedVariables = new ArrayList<String>();
    ArrayList<String> changedVariables = new ArrayList<String>();
    removedVariables.addAll(Arrays.asList(JavaCore.getClasspathVariableNames()));

    // remove all unchanged
    List<CPVariableElement> changedElements = fVariablesList.getElements();
    for (int i = changedElements.size() - 1; i >= 0; i--) {
        CPVariableElement curr = changedElements.get(i);
        if (curr.isReadOnly()) {
            changedElements.remove(curr);
        } else {//from  w  w  w.ja  va 2  s. co  m
            IPath path = curr.getPath();
            IPath prevPath = JavaCore.getClasspathVariable(curr.getName());
            if (prevPath != null && prevPath.equals(path)) {
                changedElements.remove(curr);
            } else {
                changedVariables.add(curr.getName());
            }
        }
        removedVariables.remove(curr.getName());
    }
    int steps = changedElements.size() + removedVariables.size();
    if (steps > 0) {

        boolean needsBuild = false;
        if (fAskToBuild && doesChangeRequireFullBuild(removedVariables, changedVariables)) {
            String title = NewWizardMessages.VariableBlock_needsbuild_title;
            String message = NewWizardMessages.VariableBlock_needsbuild_message;

            MessageDialog buildDialog = new MessageDialog(getShell(), title, null, message,
                    MessageDialog.QUESTION, new String[] { IDialogConstants.YES_LABEL,
                            IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL },
                    2);
            int res = buildDialog.open();
            if (res != 0 && res != 1) {
                return false;
            }
            needsBuild = (res == 0);
        }

        final VariableBlockRunnable runnable = new VariableBlockRunnable(removedVariables, changedElements);
        final ProgressMonitorDialog dialog = new ProgressMonitorDialog(getShell());
        try {
            PlatformUI.getWorkbench().getProgressService().runInUI(dialog, runnable,
                    ResourcesPlugin.getWorkspace().getRoot());
        } catch (InvocationTargetException e) {
            ExceptionHandler.handle(new InvocationTargetException(new NullPointerException()), getShell(),
                    NewWizardMessages.VariableBlock_variableSettingError_titel,
                    NewWizardMessages.VariableBlock_variableSettingError_message);
            return false;
        } catch (InterruptedException e) {
            return false;
        }

        if (needsBuild) {
            CoreUtility.getBuildJob(null).schedule();
        }
    }
    return true;
}

From source file:fable.framework.toolbox.FableUtils.java

License:Open Source License

/**
 * Displays an question MessageDialog./*from   w  w  w  .  j a  v a2 s .  c  o m*/
 * 
 * @param message
 *            The question to ask.
 * @return 0 if the user presses OK button, 1 for Cancel, 2 for No.
 */
public static int questionMsg(final String message) {
    String[] buttons = { "OK", "Cancel", "No" };
    MessageDialog dialog = new MessageDialog(null, "Question", null, message, MessageDialog.QUESTION, buttons,
            0);
    return dialog.open();
}

From source file:fr.inria.linuxtools.internal.tmf.ui.project.wizards.tracepkg.importexport.ImportTracePackageWizardPage.java

License:Open Source License

private int promptForOverwrite(String traceName) {
    final MessageDialog dialog = new MessageDialog(getContainer().getShell(), null, null,
            MessageFormat.format(Messages.ImportTracePackageWizardPage_AlreadyExists, traceName),
            MessageDialog.QUESTION, new String[] { IDialogConstants.NO_TO_ALL_LABEL, IDialogConstants.NO_LABEL,
                    IDialogConstants.YES_TO_ALL_LABEL, IDialogConstants.YES_LABEL, },
            3) {/*from   w  w w.  ja  v  a2s. c o m*/
        @Override
        protected int getShellStyle() {
            return super.getShellStyle() | SWT.SHEET;
        }
    };
    return dialog.open();
}

From source file:gov.nasa.ensemble.common.ui.wizard.AbstractEnsembleProjectExportWizardPage.java

License:Open Source License

@Override
public String queryOverwrite(String pathString) {

    Path path = new Path(pathString);
    String messageString;//from  ww  w.j av  a2s.  c  om
    //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) {
        // PATH_TO_FILE already exists.  Would you like to overwrite it?
        //messageString = NLS.bind(IDEWorkbenchMessages.WizardDataTransfer_existsQuestion, pathString);

        IFolder folder = ResourcesPlugin.getWorkspace().getRoot().getFolder(path);
        IPath location = folder.getLocation();
        File file = null;
        if (location == null) {
            file = new File(pathString);
        }

        else {
            file = location.toFile();
        }

        messageString = getDialogQuestionText(file);

    } else {
        messageString = NLS.bind(IDEWorkbenchMessages.WizardDataTransfer_overwriteNameAndPathQuestion,
                path.lastSegment(), path.removeLastSegments(1).toOSString());
        String osString = path.toOSString();
        Date date = new Date(new File(osString).lastModified());
        messageString += System.getProperty("line.separator") + System.getProperty("line.separator") + "'"
                + path.lastSegment() + "' was last modified on: " + date;
    }

    final MessageDialog dialog = new MessageDialog(getShellForMessageDialog(), 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) {
        @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.
    WidgetUtils.runInDisplayThread(getShell(), new Runnable() {
        @Override
        public void run() {
            dialog.open();
        }
    });
    return dialog.getReturnCode() < 0 ? CANCEL : response[dialog.getReturnCode()];
}

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   w  w w.  j  a  va 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.codegen.ui.internal.GenerateFilesDialog.java

License:Open Source License

protected boolean checkSystemFile(boolean newValue, FileStatus element) {
    if (!askedSystemFileGenerate && newValue) {
        if (!element.getDoItDefault()) {
            MessageDialog dialog = new MessageDialog(getShell(), getShell().getText(), null,
                    "The 'SYSTEM' file '" + element.getFilename()
                            + "' has been modified and may contain code that was written by the user.\n\n"
                            + "It is recommended you overwrite this file.\n\n"
                            + "Do you want to overwrite this file?",
                    MessageDialog.QUESTION, new String[] { "Yes", "No" }, 1);
            if (dialog.open() == 0) {
                askedSystemFileGenerate = true;
                return true;
            } else {
                return false;
            }/*from w ww . j  a v  a2s  .  c o  m*/
        }
    }

    return true;
}