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:descent.internal.ui.preferences.OptionsConfigurationBlock.java

License:Open Source License

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

    List /* <Key>*/ changedOptions = new ArrayList();
    boolean needsBuild = getChanges(currContext, changedOptions);
    if (changedOptions.isEmpty()) {
        return true;
    }//from  ww  w.jav a 2s. c  o 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:descent.internal.ui.wizards.buildpaths.BuildPathsBlock.java

License:Open Source License

public static IRemoveOldBinariesQuery getRemoveOldBinariesQuery(final Shell shell) {
    return new IRemoveOldBinariesQuery() {
        public boolean doQuery(final IPath oldOutputLocation) throws OperationCanceledException {
            final int[] res = new int[] { 1 };
            Display.getDefault().syncExec(new Runnable() {
                public void run() {
                    Shell sh = shell != null ? shell : JavaPlugin.getActiveWorkbenchShell();
                    String title = NewWizardMessages.BuildPathsBlock_RemoveBinariesDialog_title;
                    String message = Messages.format(
                            NewWizardMessages.BuildPathsBlock_RemoveBinariesDialog_description,
                            oldOutputLocation.toString());
                    MessageDialog dialog = new MessageDialog(sh, title, null, message, MessageDialog.QUESTION,
                            new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL,
                                    IDialogConstants.CANCEL_LABEL },
                            0);// w  w w . j a v  a  2s  . com
                    res[0] = dialog.open();
                }
            });
            if (res[0] == 0) {
                return true;
            } else if (res[0] == 1) {
                return false;
            }
            throw new OperationCanceledException();
        }
    };
}

From source file:descent.internal.ui.wizards.buildpaths.newsourcepage.AddFolderToBuildpathAction.java

License:Open Source License

/**
 * {@inheritDoc}//  w ww.java2s .c o  m
 */
public void run() {

    try {
        final IJavaProject project;
        Object object = fSelectedElements.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 = fSite.getShell() != null ? fSite.getShell() : JavaPlugin.getActiveWorkbenchShell();

        final boolean removeProjectFromClasspath;
        IPath outputLocation = project.getOutputLocation();
        final IPath defaultOutputLocation = outputLocation.makeRelative();
        final IPath newDefaultOutputLocation;
        final boolean removeOldClassFiles;
        IPath projPath = project.getProject().getFullPath();
        if (!(fSelectedElements.size() == 1 && fSelectedElements.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(fSelectedElements, 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,
                            projPath.toString());
                    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 result = addToClasspath(fSelectedElements, project,
                                newDefaultOutputLocation.makeAbsolute(), removeProjectFromClasspath,
                                removeOldClassFiles, monitor);
                        selectAndReveal(new StructuredSelection(result));
                    } catch (CoreException e) {
                        throw new InvocationTargetException(e);
                    }
                }
            };
            PlatformUI.getWorkbench().getProgressService().run(true, false, runnable);
        } catch (final InvocationTargetException e) {
            if (e.getCause() instanceof CoreException) {
                showExceptionDialog((CoreException) e.getCause());
            } else {
                JavaPlugin.log(e);
            }
        } catch (final InterruptedException e) {
        }
    } catch (CoreException e) {
        showExceptionDialog(e);
    }
}

From source file:descent.internal.ui.wizards.buildpaths.newsourcepage.RemoveLinkedFolderDialog.java

License:Open Source License

/**
 * Creates a new remove linked folder dialog.
 * //www.  j a va2 s  . c  o m
 * @param shell the parent shell to use
 * @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[] { folder.getFullPath() }),
            MessageDialog.QUESTION, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 0); // yes is the default
    Assert.isTrue(folder.isLinked());
}

From source file:descent.internal.ui.wizards.buildpaths.VariableBlock.java

License:Open Source License

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

    // remove all unchanged
    List changedElements = fVariablesList.getElements();
    for (int i = changedElements.size() - 1; i >= 0; i--) {
        CPVariableElement curr = (CPVariableElement) changedElements.get(i);
        if (curr.isReserved()) {
            changedElements.remove(curr);
        } else {/*from w  w  w  .ja va 2 s  .  c  om*/
            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 {
            dialog.run(true, true, runnable);
        } 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:distributed.plugin.ui.actions.ProcessActions.java

License:Open Source License

boolean validateSavedGraph(GraphEditor editor) {
    if (editor.isDirty()) {
        MessageDialog messageBox;/*from ww  w.j a v a2  s .  c  om*/
        Shell parent = getWorkbenchPart().getSite().getShell();
        String[] btnText = { "No", "Cancel", "Yes" };
        messageBox = new MessageDialog(parent, "Save", null, "Graph has been modified. Do you want to save it?",
                MessageDialog.QUESTION, btnText, 2);
        messageBox.open();
        int ans = messageBox.getReturnCode();
        if (ans == 0)
            return true;
        else if (ans == 1)
            return false;
        else if (ans == 2) {
            // TODO might need to put progress monitor
            IProgressMonitor monitor = null;
            editor.doSave(monitor);
            return true;
        } else
            return false;

    } else
        return true;
}

From source file:eclipse.spellchecker.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  .  ja v a  2 s.  c  o  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) {
            if (ResourcesPlugin.getWorkspace().getRoot().getProjects().length == 0) {
                doBuild = true; // don't bother the user
            } else {
                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) {
            Activator.log(e);
            return false;
        }
        if (doBuild) {
            CoreUtility.getBuildJob(fProject).schedule();
        }

    }
    return true;
}

From source file:edu.tsinghua.lumaqq.ui.helper.ShellLauncher.java

License:Open Source License

/**
 * ??/*w w w.  j av  a 2 s.c  o  m*/
 * 
  * @param url
  *       URL
  * @param title
  *       ?
  * @param errorString
  *       ?
  */
public void openBrowserShell(String url, String title, String errorString) {
    // ?????
    String browser = main.getOptionHelper().getBrowser();
    try {
        if (browser.equals("")) {
            MessageDialog dialog = new MessageDialog(main.getShell(), message_box_common_question_title, null,
                    message_box_browser_not_set, MessageDialog.QUESTION,
                    new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL,
                            IDialogConstants.CANCEL_LABEL },
                    0);

            switch (dialog.open()) {
            case 0:
                main.getShellLauncher().openSystemOptionWindow().setCurrentPage(SystemOptionWindow.OTHER);
                break;
            case 1:
                BrowserShell bs = ShellFactory.createBrowserShell(main);
                bs.setUrl(url);
                bs.setTitle(title);
                bs.open();
                break;
            }
        } else
            Runtime.getRuntime().exec(browser.replaceAll("\\[URL\\]", url));
    } catch (Throwable t) {
        MessageDialog.openWarning(main.getShell(), message_box_common_warning_title, errorString);
    }
}

From source file:edu.tsinghua.lumaqq.ui.MainShell.java

License:Open Source License

/**
 * /*from w  w w .  ja  va 2s  .c  o  m*/
 * 
 * @param e
 */
public void onDiskDownload(IStructuredSelection s) {
    if (s.isEmpty())
        return;

    Object obj = s.getFirstElement();
    if (obj instanceof File) {
        File f = (File) obj;
        DirectoryDialog dialog = new DirectoryDialog(getShell());
        String dir = dialog.open();
        if (dir != null) {
            // ?
            if (!dir.endsWith(java.io.File.separator))
                dir += java.io.File.separatorChar;
            java.io.File diskfile = new java.io.File(dir + f.name);
            boolean resume = false;
            if (diskfile.exists()) {
                MessageDialog msg = new MessageDialog(getShell(), message_box_common_question_title, null,
                        NLS.bind(message_box_resume_file, diskfile.getAbsolutePath()), MessageDialog.QUESTION,
                        new String[] { button_resume, button_overwrite, button_cancel }, 0);
                switch (msg.open()) {
                case 0:
                    resume = true;
                    break;
                case 1:
                    resume = false;
                    break;
                default:
                    return;
                }
            }

            // 
            if (f.owner == 0)
                return;
            diskJobQueue.addJob(new DownloadFileJob(f, dir, resume));
        }
    }
}

From source file:edu.utexas.cs.orc.orceclipse.project.OrcPathEditor.java

License:Open Source License

@Override
protected String getNewInputObject() {
    // prompt dir or JAR
    final MessageDialog typeDialog = new MessageDialog(getShell(), Messages.OrcPathEditor_TypeDialogTitle, null,
            Messages.OrcPathEditor_TypeDialogMessage1 + pathDescriptionForDialogMessage
                    + Messages.OrcPathEditor_TypeDialogMessage2,
            MessageDialog.QUESTION, TYPE_DIALOG_BUTTON_LABELS, SWT.DEFAULT);
    switch (typeDialog.open()) {
    case 0: // workspace dir:
        return chooseWorkspaceFolder();
    case 1: // workspace JAR:
        return chooseWorkspaceJarFile();
    case 2: // external dir:
        final String selectedFolder = super.getNewInputObject();
        if (selectedFolder != null) {
            return Path.fromOSString(selectedFolder).addTrailingSeparator().toPortableString();
        } else {/* w  w w  . ja va2 s  .  c o m*/
            return null;
        }
    case 3: // external JAR:
        return chooseExternalJarFile();
    default: // canceled
        return null;
    }
}