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

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

Introduction

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

Prototype

String NO_LABEL

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

Click Source Link

Document

The label for no buttons.

Usage

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

License:Open Source License

protected void okPressed() {
    // Get new path.
    IPath path = resourceGroup.getContainerFullPath().append(resourceGroup.getResource());

    //If the user does not supply a file extension and if the save 
    //as dialog was provided a default file name append the extension 
    //of the default filename to the new name
    if (path.getFileExtension() == null) {
        if (originalFile != null && originalFile.getFileExtension() != null) {
            path = path.addFileExtension(originalFile.getFileExtension());
        } else if (originalName != null) {
            int pos = originalName.lastIndexOf('.');
            if (++pos > 0 && pos < originalName.length()) {
                path = path.addFileExtension(originalName.substring(pos));
            }//from ww  w .  j  a  v a 2s . c  o m
        }
    }

    // If the path already exists then confirm overwrite.
    IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
    if (file.exists()) {
        String[] buttons = new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL,
                IDialogConstants.CANCEL_LABEL };
        String question = NLS.bind(IDEWorkbenchMessages.SaveAsDialog_overwriteQuestion, path.toString());
        MessageDialog d = new MessageDialog(getShell(), IDEWorkbenchMessages.Question, null, question,
                MessageDialog.QUESTION, buttons, 0) {
            protected int getShellStyle() {
                return super.getShellStyle() | SWT.SHEET;
            }
        };
        int overwrite = d.open();
        switch (overwrite) {
        case 0: // Yes
            break;
        case 1: // No
            return;
        case 2: // Cancel
        default:
            cancelPressed();
            return;
        }
    }

    // Store path and close.
    result = path;
    close();
}

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

License:Open Source License

/**
 * The <code>WizardDataTransfer</code> implementation of this 
 * <code>IOverwriteQuery</code> method asks the user whether the existing 
 * resource at the given path should be overwritten.
 *
 * @param pathString /*  ww  w.  j  a v  a 2 s  . c om*/
 * @return the user's reply: one of <code>"YES"</code>, <code>"NO"</code>, <code>"ALL"</code>, 
 *   or <code>"CANCEL"</code>
 */
public String queryOverwrite(String pathString) {

    Path path = new Path(pathString);

    String messageString;
    //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) {
        messageString = NLS.bind(IDEWorkbenchMessages.WizardDataTransfer_existsQuestion, pathString);
    } else {
        messageString = NLS.bind(IDEWorkbenchMessages.WizardDataTransfer_overwriteNameAndPathQuestion,
                path.lastSegment(), path.removeLastSegments(1).toOSString());
    }

    final MessageDialog dialog = new MessageDialog(getContainer().getShell(), 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) {
        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.
    getControl().getDisplay().syncExec(new Runnable() {
        public void run() {
            dialog.open();
        }
    });
    return dialog.getReturnCode() < 0 ? CANCEL : response[dialog.getReturnCode()];
}

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

License:Open Source License

/**
 * Displays a Yes/No question to the user with the specified message and returns
 * the user's response./*from   w ww.  j ava 2s .c o m*/
 *
 * @param message the question to ask
 * @return <code>true</code> for Yes, and <code>false</code> for No
 */
protected boolean queryYesNoQuestion(String message) {
    MessageDialog dialog = new MessageDialog(getContainer().getShell(), IDEWorkbenchMessages.Question,
            (Image) null, message, MessageDialog.NONE,
            new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 0) {
        protected int getShellStyle() {
            return super.getShellStyle() | SWT.SHEET;
        }
    };
    // ensure yes is the default

    return dialog.open() == 0;
}

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>// w  w w .ja  v a  2s  .  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 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>//from w w w  .ja  v a  2  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.ui.dialogs.YesNoCancelListSelectionDialog.java

License:Open Source License

protected void createButtonsForButtonBar(Composite parent) {
    createButton(parent, IDialogConstants.YES_ID, IDialogConstants.YES_LABEL, true);
    createButton(parent, IDialogConstants.NO_ID, IDialogConstants.NO_LABEL, false);
    createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false);
}

From source file:org.eclipse.ui.examples.jobs.actions.CreateJobsAction.java

License:Open Source License

private boolean askForExclusive() {
    MessageDialog dialog = new MessageDialog(window.getShell(), "Likes to be left alone?", //$NON-NLS-1$
            null, "Press yes if the jobs should be run one at a time, and no otherwise", //$NON-NLS-1$
            MessageDialog.QUESTION, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 1 // no is the default
    );//from   w w  w . j  ava  2 s  .co m
    return dialog.open() == 0;
}

From source file:org.eclipse.ui.examples.jobs.actions.CreateJobsAction.java

License:Open Source License

private boolean askForFailure() {
    MessageDialog dialog = new MessageDialog(window.getShell(), "Born to fail?", //$NON-NLS-1$
            null, "Should the jobs return an error status?", //$NON-NLS-1$
            MessageDialog.QUESTION, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 1 // no is the default
    );/*from   w ww  . j a  v  a2 s.  c om*/
    return dialog.open() == 0;
}

From source file:org.eclipse.ui.ide.dialogs.ResourceEncodingFieldEditor.java

License:Open Source License

protected void doStore() {

    String encoding = getSelectedEncoding();

    // Clear the value if nothing is selected
    if (isDefaultSelected()) {
        encoding = null;//w w w  . j  a v  a 2 s .  co m
    }
    // Don't update if the same thing is selected
    final boolean hasSameEncoding = hasSameEncoding(encoding);
    final boolean hasSameSeparateDerivedEncodings = hasSameSeparateDerivedEncodings();
    if (hasSameEncoding && hasSameSeparateDerivedEncodings) {
        return;
    }

    String descriptionCharset = getCharsetFromDescription();
    if (descriptionCharset != null && !(descriptionCharset.equals(encoding)) && encoding != null) {
        Shell shell = null;
        DialogPage page = getPage();
        if (page != null) {
            shell = page.getShell();
        }

        MessageDialog dialog = new MessageDialog(shell,
                IDEWorkbenchMessages.ResourceEncodingFieldEditor_EncodingConflictTitle, null,
                NLS.bind(IDEWorkbenchMessages.ResourceEncodingFieldEditor_EncodingConflictMessage, encoding,
                        descriptionCharset),
                MessageDialog.WARNING, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL },
                0) {
            protected int getShellStyle() {
                return super.getShellStyle() | SWT.SHEET;
            }
        }; // yes is the
           // default
        if (dialog.open() > 0) {
            return;
        }
    }

    IDEEncoding.addIDEEncoding(encoding);

    final String finalEncoding = encoding;

    Job charsetJob = new Job(IDEWorkbenchMessages.IDEEncoding_EncodingJob) {
        /*
         * (non-Javadoc)
         * 
         * @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor)
         */
        protected IStatus run(IProgressMonitor monitor) {
            try {
                if (!hasSameEncoding) {
                    if (resource instanceof IContainer) {
                        ((IContainer) resource).setDefaultCharset(finalEncoding, monitor);
                    } else {
                        ((IFile) resource).setCharset(finalEncoding, monitor);
                    }
                }
                if (!hasSameSeparateDerivedEncodings) {
                    Preferences prefs = new ProjectScope((IProject) resource)
                            .getNode(ResourcesPlugin.PI_RESOURCES);
                    if (getStoredSeparateDerivedEncodingsValue())
                        prefs.remove(ResourcesPlugin.PREF_SEPARATE_DERIVED_ENCODINGS);
                    else
                        prefs.putBoolean(ResourcesPlugin.PREF_SEPARATE_DERIVED_ENCODINGS, true);
                    prefs.flush();
                }
                return Status.OK_STATUS;
            } catch (CoreException e) {// If there is an error return the
                // default
                IDEWorkbenchPlugin.log(IDEWorkbenchMessages.ResourceEncodingFieldEditor_ErrorStoringMessage,
                        e.getStatus());
                return e.getStatus();
            } catch (BackingStoreException e) {
                IDEWorkbenchPlugin.log(IDEWorkbenchMessages.ResourceEncodingFieldEditor_ErrorStoringMessage, e);
                return new Status(IStatus.ERROR, IDEWorkbenchPlugin.IDE_WORKBENCH, e.getMessage(), e);
            }
        }
    };

    charsetJob.schedule();

}

From source file:org.eclipse.ui.ide.examples.projectsnapshot.ProjectRefreshSnapshotExportWizardPage.java

License:Open Source License

private boolean executeSnapshotOperation(final IProject[] projects) {
    final MultiStatus status = new MultiStatus(IDEWorkbenchPlugin.IDE_WORKBENCH, 0,
            Messages.ProjectRefreshSnapshotExportWizardPage_errorsOccurred, null);

    final IPath snapshotPath = new Path(directorySnapshotPathField.getText().trim());
    for (int i = 0; i < projects.length; i++) {
        IProject project = projects[i];//from w  ww .  j  av a 2  s .  c o m
        try {
            String projectName = project.getName();
            boolean cancelled = false;
            IPath zipPath = snapshotPath.append(projectName + "-index.zip"); //$NON-NLS-1$
            if (zipPath.toFile().exists()) {
                String[] buttons = new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL,
                        IDialogConstants.CANCEL_LABEL };
                String question = NLS.bind(Messages.ProjectRefreshSnapshotExportWizardPage_overwrite,
                        zipPath.toString());
                MessageDialog d = new MessageDialog(getShell(),
                        Messages.ProjectRefreshSnapshotExportWizardPage_question, null, question,
                        MessageDialog.QUESTION, buttons, 0) {
                    protected int getShellStyle() {
                        return super.getShellStyle() | SWT.SHEET;
                    }
                };
                int overwrite = d.open();
                switch (overwrite) {
                case 0: // Yes
                    break;
                case 1: // No
                    continue;
                case 2: // Cancel
                default:
                    cancelled = true;
                    break;
                }
            }
            if (cancelled)
                break;
            URI snapshotLocation = org.eclipse.core.filesystem.URIUtil.toURI(zipPath);
            project.saveSnapshot(IProject.SNAPSHOT_TREE, snapshotLocation, null);
        } catch (CoreException e) {
            status.merge(e.getStatus());
        }
    }
    if (!status.isOK()) {
        IDEWorkbenchPlugin.log("", status); //$NON-NLS-1$
        ErrorDialog.openError(getContainer().getShell(), getErrorDialogTitle(), null, // no special message
                status);
        return false;
    }

    return true;
}