Example usage for org.eclipse.jface.dialogs IDialogConstants YES_LABEL

List of usage examples for org.eclipse.jface.dialogs IDialogConstants YES_LABEL

Introduction

In this page you can find the example usage for org.eclipse.jface.dialogs IDialogConstants YES_LABEL.

Prototype

String YES_LABEL

To view the source code for org.eclipse.jface.dialogs IDialogConstants YES_LABEL.

Click Source Link

Document

The label for yes buttons.

Usage

From source file:de.sebastianbenz.task.ui.editor.ExtLinkedXtextEditor.java

License:Open Source License

@Override
protected void performSaveAs(IProgressMonitor progressMonitor) {

    Shell shell = getSite().getShell();//from w w  w.  j  a va2  s . co m
    final IEditorInput input = getEditorInput();

    // Customize save as if the file is linked, and it is in the special external link project
    //
    if (input instanceof IFileEditorInput && ((IFileEditorInput) input).getFile().isLinked()
            && ((IFileEditorInput) input).getFile().getProject().getName()
                    .equals(ExtLinkedFileHelper.AUTOLINK_PROJECT_NAME)) {
        final IEditorInput newInput;
        IDocumentProvider provider = getDocumentProvider();

        // 1. If file is "untitled" suggest last save location
        // 2. ...otherwise use the file's location (i.e. likely to be a rename in same folder)
        // 3. If a "last save location" is unknown, use user's home
        //
        String suggestedName = null;
        String suggestedPath = null;
        {
            // is it "untitled"
            java.net.URI uri = ((IURIEditorInput) input).getURI();
            String tmpProperty = null;
            try {
                tmpProperty = ((IFileEditorInput) input).getFile()
                        .getPersistentProperty(TmpFileStoreEditorInput.UNTITLED_PROPERTY);
            } catch (CoreException e) {
                // ignore - tmpProperty will be null
            }
            boolean isUntitled = tmpProperty != null && "true".equals(tmpProperty);

            // suggested name
            IPath oldPath = URIUtil.toPath(uri);
            // TODO: input.getName() is probably always correct
            suggestedName = isUntitled ? input.getName() : oldPath.lastSegment();

            // suggested path
            try {
                suggestedPath = isUntitled
                        ? ((IFileEditorInput) input).getFile().getWorkspace().getRoot()
                                .getPersistentProperty(LAST_SAVEAS_LOCATION)
                        : oldPath.toOSString();
            } catch (CoreException e) {
                // ignore, suggestedPath will be null
            }

            if (suggestedPath == null) {
                // get user.home
                suggestedPath = System.getProperty("user.home");
            }
        }
        FileDialog dialog = new FileDialog(shell, SWT.SAVE);
        if (suggestedName != null)
            dialog.setFileName(suggestedName);
        if (suggestedPath != null)
            dialog.setFilterPath(suggestedPath);

        dialog.setFilterExtensions(new String[] { "*.todo", "*.taskpaper", "*.*" });
        String path = dialog.open();
        if (path == null) {
            if (progressMonitor != null)
                progressMonitor.setCanceled(true);
            return;
        }

        // Check whether file exists and if so, confirm overwrite
        final File localFile = new File(path);
        if (localFile.exists()) {
            MessageDialog overwriteDialog = new MessageDialog(shell, "Save As", null,
                    path + " already exists.\nDo you want to replace it?", MessageDialog.WARNING,
                    new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 1); // 'No' is the default
            if (overwriteDialog.open() != Window.OK) {
                if (progressMonitor != null) {
                    progressMonitor.setCanceled(true);
                    return;
                }
            }
        }

        IFileStore fileStore;
        try {
            fileStore = EFS.getStore(localFile.toURI());
        } catch (CoreException ex) {
            String title = "Problems During Save As...";
            String msg = "Save could not be completed. " + ex.getMessage();
            MessageDialog.openError(shell, title, msg);
            return;
        }

        IFile file = getWorkspaceFile(fileStore);
        if (file != null)
            newInput = new FileEditorInput(file);
        else {
            IURIEditorInput uriInput = new FileStoreEditorInput(fileStore);
            java.net.URI uri = uriInput.getURI();
            IFile linkedFile = linkedFileHelper.obtainLink(uri, false);

            newInput = new FileEditorInput(linkedFile);
        }

        if (provider == null) {
            // editor has been closed while the dialog was open
            return;
        }

        boolean success = false;
        try {

            provider.aboutToChange(newInput);
            provider.saveDocument(progressMonitor, newInput, provider.getDocument(input), true);
            success = true;

        } catch (CoreException x) {
            final IStatus status = x.getStatus();
            if (status == null || status.getSeverity() != IStatus.CANCEL) {
                String title = "Problems During Save As...";
                String msg = "Save could not be completed. " + x.getMessage();
                MessageDialog.openError(shell, title, msg);
            }
        } finally {
            provider.changed(newInput);
            if (success)
                setInput(newInput);
            // the linked file must be removed (esp. if it is an "untitled" link).
            linkedFileHelper.unlinkInput(((IFileEditorInput) input));
            // remember last saveAs location
            String lastLocation = URIUtil.toPath(((FileEditorInput) newInput).getURI()).toOSString();
            try {
                ((FileEditorInput) newInput).getFile().getWorkspace().getRoot()
                        .setPersistentProperty(LAST_SAVEAS_LOCATION, lastLocation);
            } catch (CoreException e) {
                // ignore
            }
        }

        if (progressMonitor != null)
            progressMonitor.setCanceled(!success);

        return;
    }

    super.performSaveAs(progressMonitor);
}

From source file:de.tub.tfs.henshin.editor.ui.dialog.resources.ResourcesDialog.java

License:Open Source License

@Override
protected void okPressed() {
    IPath path = resourceGroup.getResourceFullPath();
    IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(path);

    if (file.exists() && type == SWT.SAVE) {
        String[] buttons = new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL,
                IDialogConstants.CANCEL_LABEL };
        MessageDialog confirm = new MessageDialog(getShell(), "Overwrite Question", null,
                "The file" + file.getName() + " already exists. Do you want to replace the existing file?",
                MessageDialog.QUESTION, buttons, 0);

        int result = confirm.open();

        switch (result) {
        case 0://from   w ww.java2 s .  c o  m
            break;
        case 1:
            return;
        default:
            cancelPressed();
            break;
        }
    }

    this.result = file.getRawLocation().toFile();
    super.okPressed();
}

From source file:de.uni_koeln.ub.drc.ui.facades.IDialogConstantsHelperImpl.java

License:Open Source License

@Override
String getYesLabelInternal() {
    return IDialogConstants.YES_LABEL;
}

From source file:de.walware.statet.nico.ui.util.ToolMessageDialog.java

License:Open Source License

public static boolean openQuestion(final ToolProcess tool, final Shell parent, final String title,
        final String message) {
    final ToolMessageDialog dialog = new ToolMessageDialog(tool, parent, title, null, message, QUESTION,
            new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 0);
    return (dialog.open() == 0);
}

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  www  . j  a va  2 s .  com*/
    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);/*  www.  j  a  v a 2 s  . c o m*/
                    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}//from   www.  ja  va  2s.  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.
 * /* w  ww.  j  av a2s .  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 {// w  ww  . ja v a2  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 {
            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: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 w w  w .j  av  a2  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;
}