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.team.ui.SaveablePartDialog.java

License:Open Source License

/**
 * Save any changes to the compare editor.
 *///from ww  w  . j a va 2 s.c o m
private void saveChanges() {
    MessageDialog dialog = new MessageDialog(getShell(), TeamUIMessages.ParticipantCompareDialog_2, null,
            TeamUIMessages.ParticipantCompareDialog_3, MessageDialog.QUESTION,
            new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 0); // YES is the default

    if (input.isDirty() && dialog.open() == IDialogConstants.OK_ID) {
        BusyIndicator.showWhile(null, new Runnable() {
            public void run() {
                input.doSave(new NullProgressMonitor());
            }
        });
    }
}

From source file:org.eclipse.team.ui.synchronize.ModelMergeOperation.java

License:Open Source License

/**
 * Method invoked when the context contains changes that failed validation
 * by at least one {@link IResourceMappingMerger}.
 * By default, the user is prompted to inform them that unmergeable changes were found
 * and the {@link #handlePreviewRequest()} method is invoked.
 * Subclasses may override./*w  w w  . j av  a 2s  . c o m*/
 * @param status the status returned from the mergers that reported the validation failures
 */
protected void handleValidationFailure(final IStatus status) {
    final boolean[] result = new boolean[] { false };
    Runnable runnable = new Runnable() {
        public void run() {
            ErrorDialog dialog = new ErrorDialog(getShell(), TeamUIMessages.ModelMergeOperation_0,
                    TeamUIMessages.ModelMergeOperation_1, status,
                    IStatus.ERROR | IStatus.WARNING | IStatus.INFO) {
                protected void createButtonsForButtonBar(Composite parent) {
                    createButton(parent, IDialogConstants.YES_ID, IDialogConstants.YES_LABEL, false);
                    createButton(parent, IDialogConstants.NO_ID, IDialogConstants.NO_LABEL, true);
                    createDetailsButton(parent);
                }

                /* (non-Javadoc)
                 * @see org.eclipse.jface.dialogs.ErrorDialog#buttonPressed(int)
                 */
                protected void buttonPressed(int id) {
                    if (id == IDialogConstants.YES_ID)
                        super.buttonPressed(IDialogConstants.OK_ID);
                    else if (id == IDialogConstants.NO_ID)
                        super.buttonPressed(IDialogConstants.CANCEL_ID);
                    super.buttonPressed(id);
                }
            };
            int code = dialog.open();
            result[0] = code == 0;
        }
    };
    getShell().getDisplay().syncExec(runnable);
    if (result[0])
        handlePreviewRequest();
}

From source file:org.eclipse.team.ui.synchronize.ModelParticipantAction.java

License:Open Source License

/**
 * Convenience method that prompts to save changes in the given dirty model.
 * @param shell a shell/*from  ww w  . ja  v  a  2 s  .  c  o  m*/
 * @param saveable a dirty saveable model
 * @param allowCancel whether canceling the action is an option
 * @return whether the user choose to save (<code>true</code>) or revert (<code>false</code>() the model
 * @throws InterruptedException thrown if the user choose to cancel
 */
public static boolean promptToSaveChanges(final Shell shell, final SaveableComparison saveable,
        final boolean allowCancel) throws InterruptedException {
    final int[] result = new int[] { 0 };
    Runnable runnable = new Runnable() {
        public void run() {
            String[] options;
            if (allowCancel) {
                options = new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL,
                        IDialogConstants.CANCEL_LABEL };
            } else {
                options = new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL };
            }
            MessageDialog dialog = new MessageDialog(shell, TeamUIMessages.ModelParticipantAction_0, null,
                    NLS.bind(TeamUIMessages.ModelParticipantAction_1, saveable.getName()),
                    MessageDialog.QUESTION, options, result[0]);
            result[0] = dialog.open();
        }
    };
    shell.getDisplay().syncExec(runnable);
    if (result[0] == 2)
        throw new InterruptedException();
    return result[0] == 0;
}

From source file:org.eclipse.thym.ui.wizard.export.NativeBinaryDestinationPage.java

License:Open Source License

@Override
public String queryOverwrite(String pathString) {

    final MessageDialog dialog = new MessageDialog(getShell(), "Overwrite Files?", null,
            pathString + " already exists. Would you like to overwrite it?", MessageDialog.QUESTION,
            new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL,
                    IDialogConstants.CANCEL_LABEL },
            0);/*from  ww w .  j av a2  s  .c  o m*/
    String[] response = new String[] { YES, NO, CANCEL };
    //most likely to be called from non-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.thym.ui.wizard.export.NativeProjectDestinationPage.java

License:Open Source License

@Override
public String queryOverwrite(String pathString) {
    final MessageDialog dialog = new MessageDialog(getShell(), "Overwrite Files?", null,
            "Directory " + pathString + " already exists. Would you like to overwrite it?",
            MessageDialog.QUESTION,/*from  w  w w  .  java  2s . c o m*/
            new String[] { IDialogConstants.YES_LABEL, IDialogConstants.YES_TO_ALL_LABEL,
                    IDialogConstants.NO_LABEL, IDialogConstants.NO_TO_ALL_LABEL,
                    IDialogConstants.CANCEL_LABEL },
            0);
    String[] response = new String[] { YES, ALL, NO, NO_ALL, CANCEL };
    //most likely to be called from non-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.tracecompass.totalads.ui.models.delete.DeleteModelHandler.java

License:Open Source License

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {

    String msgTitle = "TotalADS"; //$NON-NLS-1$
    //  MessageBox msgBoxYesNo = new MessageBox(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
    //        SWT.ICON_INFORMATION | SWT.YES | SWT.NO);

    //msgBoxYesNo.setText(msgTitle);

    try {//from   w w w .j ava2  s  .  c  o m

        // checking if a model is selected
        if (fSelectedModels.size() <= 0) {
            MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), msgTitle,
                    Messages.DeleteModelHandler_SelModel);
            return null;
        }
        //
        // Get confirmation
        //
        Iterator<String> it = fSelectedModels.iterator();
        String message = Messages.DeleteModelHandler_WantToDel;
        int count = 1;
        while (it.hasNext()) {
            if (count == 1 && fSelectedModels.size() <= 2) {
                message += it.next() + " "; //$NON-NLS-1$
            } else if (count == 1 && fSelectedModels.size() > 2) {
                message += it.next() + ", "; //$NON-NLS-1$
            } else if (count > 1 && count < fSelectedModels.size()) {
                message += it.next() + ", "; //$NON-NLS-1$
            } else if (count > 1 && count == fSelectedModels.size()) {
                message += Messages.DeleteModelHandler_And + it.next();
            }

            count++;
        }
        message += "?"; //$NON-NLS-1$
        MessageDialog msgBoxYesNo = new MessageDialog(Display.getDefault().getActiveShell(), msgTitle, null,
                message, MessageDialog.QUESTION,
                new String[] { IDialogConstants.NO_LABEL, IDialogConstants.YES_LABEL, }, 0);

        if (msgBoxYesNo.open() == 1) {//YES
            // Delete models now
            it = fSelectedModels.iterator();
            while (it.hasNext()) {
                String err = DBMSFactory.INSTANCE.deleteDatabase(it.next());
                if (!err.isEmpty()) { // if the database is not connected
                    MessageDialog.openError(
                            org.eclipse.ui.PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
                            msgTitle, err);
                    break;
                }
            }
        }

    } catch (Exception ex) {
        if (ex.getMessage() != null) {
            MessageDialog.openError(
                    org.eclipse.ui.PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), msgTitle,
                    ex.getMessage());
        } else {
            MessageDialog.openError(
                    org.eclipse.ui.PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), msgTitle,
                    Messages.DeleteModelHandler_ErrDel);
        }

        Logger.getLogger(DeleteModelHandler.class.getName()).log(Level.SEVERE, ex.getMessage(), ex);
        // Check if connection still exists and all the views are notified
        // of the presence and absence of connection
        DBMSFactory.INSTANCE.verifyConnection();
    }

    return null;
}

From source file:org.eclipse.ui.actions.CopyFilesAndFoldersOperation.java

License:Open Source License

/**
 * Check if the user wishes to overwrite the supplied resource or all
 * resources.//from  w  w w  .  j  a v  a  2 s  .  c o  m
 * 
 * @param source
 *            the source resource
 * @param destination
 *            the resource to be overwritten
 * @return one of IDialogConstants.YES_ID, IDialogConstants.YES_TO_ALL_ID,
 *         IDialogConstants.NO_ID, IDialogConstants.CANCEL_ID indicating
 *         whether the current resource or all resources can be overwritten,
 *         or if the operation should be canceled.
 */
private int checkOverwrite(final IResource source, final IResource destination) {
    final int[] result = new int[1];

    // Dialogs need to be created and opened in the UI thread
    Runnable query = new Runnable() {
        public void run() {
            String message;
            int resultId[] = { IDialogConstants.YES_ID, IDialogConstants.YES_TO_ALL_ID, IDialogConstants.NO_ID,
                    IDialogConstants.CANCEL_ID };
            String labels[] = new String[] { IDialogConstants.YES_LABEL, IDialogConstants.YES_TO_ALL_LABEL,
                    IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL };

            if (destination.getType() == IResource.FOLDER) {
                if (homogenousResources(source, destination)) {
                    message = NLS.bind(IDEWorkbenchMessages.CopyFilesAndFoldersOperation_overwriteMergeQuestion,
                            destination.getFullPath().makeRelative());
                } else {
                    if (destination.isLinked()) {
                        message = NLS.bind(
                                IDEWorkbenchMessages.CopyFilesAndFoldersOperation_overwriteNoMergeLinkQuestion,
                                destination.getFullPath().makeRelative());
                    } else {
                        message = NLS.bind(
                                IDEWorkbenchMessages.CopyFilesAndFoldersOperation_overwriteNoMergeNoLinkQuestion,
                                destination.getFullPath().makeRelative());
                    }
                    resultId = new int[] { IDialogConstants.YES_ID, IDialogConstants.NO_ID,
                            IDialogConstants.CANCEL_ID };
                    labels = new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL,
                            IDialogConstants.CANCEL_LABEL };
                }
            } else {
                String[] bindings = new String[] { IDEResourceInfoUtils.getLocationText(destination),
                        IDEResourceInfoUtils.getDateStringValue(destination),
                        IDEResourceInfoUtils.getLocationText(source),
                        IDEResourceInfoUtils.getDateStringValue(source) };
                message = NLS.bind(
                        IDEWorkbenchMessages.CopyFilesAndFoldersOperation_overwriteWithDetailsQuestion,
                        bindings);
            }
            MessageDialog dialog = new MessageDialog(messageShell,
                    IDEWorkbenchMessages.CopyFilesAndFoldersOperation_resourceExists, null, message,
                    MessageDialog.QUESTION, labels, 0) {
                protected int getShellStyle() {
                    return super.getShellStyle() | SWT.SHEET;
                }
            };
            dialog.open();
            if (dialog.getReturnCode() == SWT.DEFAULT) {
                // A window close returns SWT.DEFAULT, which has to be
                // mapped to a cancel
                result[0] = IDialogConstants.CANCEL_ID;
            } else {
                result[0] = resultId[dialog.getReturnCode()];
            }
        }
    };
    messageShell.getDisplay().syncExec(query);
    return result[0];
}

From source file:org.eclipse.ui.actions.CopyFilesAndFoldersOperation.java

License:Open Source License

/**
 * Performs an import of the given stores into the provided container.
 * Returns a status indicating if the import was successful.
 * //from  www.  ja  va2 s .co m
 * @param stores
 *            stores that are to be imported
 * @param target
 *            container to which the import will be done
 * @param monitor
 *            a progress monitor for showing progress and for cancelation
 */
private void performFileImport(IFileStore[] stores, IContainer target, IProgressMonitor monitor) {
    IOverwriteQuery query = new IOverwriteQuery() {
        public String queryOverwrite(String pathString) {
            if (alwaysOverwrite) {
                return ALL;
            }

            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 };
            messageShell.getDisplay().syncExec(new Runnable() {
                public void run() {
                    MessageDialog dialog = new MessageDialog(messageShell,
                            IDEWorkbenchMessages.CopyFilesAndFoldersOperation_question, null, msg,
                            MessageDialog.QUESTION, options, 0) {
                        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];
        }
    };

    ImportOperation op = new ImportOperation(target.getFullPath(), stores[0].getParent(),
            FileStoreStructureProvider.INSTANCE, query, Arrays.asList(stores));
    op.setContext(messageShell);
    op.setCreateContainerStructure(false);
    op.setVirtualFolders(createVirtualFoldersAndLinks);
    op.setCreateLinks(createLinks);
    op.setRelativeVariable(relativeVariable);
    try {
        op.run(monitor);
    } catch (InterruptedException e) {
        return;
    } catch (InvocationTargetException e) {
        if (e.getTargetException() instanceof CoreException) {
            displayError(((CoreException) e.getTargetException()).getStatus());
        } else {
            display(e);
        }
        return;
    }
    // Special case since ImportOperation doesn't throw a CoreException on
    // failure.
    IStatus status = op.getStatus();
    if (!status.isOK()) {
        if (errorStatus == null) {
            errorStatus = new MultiStatus(PlatformUI.PLUGIN_ID, IStatus.ERROR, getProblemsMessage(), null);
        }
        errorStatus.merge(status);
    }
}

From source file:org.eclipse.ui.actions.ReadOnlyStateChecker.java

License:Open Source License

/**
  * Open a message dialog with Yes No, Yes To All and Cancel buttons. Return the
  * code that indicates the selection./*w w w . j a  v a2 s. c  om*/
  * @return int 
  *   one of
  *      YES_TO_ALL_ID
  *      YES_ID
  *      NO_ID
  *      CANCEL_ID
  *       
  * @param resource - the resource being queried.
  */
private int queryYesToAllNoCancel(IResource resource) {

    final MessageDialog dialog = new MessageDialog(this.shell, this.titleMessage, null,
            MessageFormat.format(this.mainMessage, new Object[] { resource.getName() }), MessageDialog.QUESTION,
            new String[] { IDialogConstants.YES_LABEL, IDialogConstants.YES_TO_ALL_LABEL,
                    IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL },
            0) {
        protected int getShellStyle() {
            return super.getShellStyle() | SWT.SHEET;
        }
    };
    shell.getDisplay().syncExec(new Runnable() {
        public void run() {
            dialog.open();
        }
    });
    int result = dialog.getReturnCode();
    if (result == 0) {
        return IDialogConstants.YES_ID;
    }
    if (result == 1) {
        return IDialogConstants.YES_TO_ALL_ID;
    }
    if (result == 2) {
        return IDialogConstants.NO_ID;
    }
    return IDialogConstants.CANCEL_ID;
}

From source file:org.eclipse.ui.actions.RefreshAction.java

License:Open Source License

/**
 * Checks whether the given project's location has been deleted. If so,
 * prompts the user with whether to delete the project or not.
 *///from   w w w.  j ava2 s .c  o m
void checkLocationDeleted(IProject project) throws CoreException {
    if (!project.exists()) {
        return;
    }
    IFileInfo location = IDEResourceInfoUtils.getFileInfo(project.getLocationURI());
    if (!location.exists()) {
        String message = NLS.bind(IDEWorkbenchMessages.RefreshAction_locationDeletedMessage, project.getName(),
                location.toString());

        final MessageDialog dialog = new MessageDialog(getShell(),
                IDEWorkbenchMessages.RefreshAction_dialogTitle, // dialog
                // title
                null, // use default window icon
                message, MessageDialog.QUESTION,
                new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 0) {
            protected int getShellStyle() {
                return super.getShellStyle() | SWT.SHEET;
            }
        }; // yes is the
           // default

        // Must prompt user in UI thread (we're in the operation thread
        // here).
        getShell().getDisplay().syncExec(new Runnable() {
            public void run() {
                dialog.open();
            }
        });

        // Do the deletion back in the operation thread
        if (dialog.getReturnCode() == 0) { // yes was chosen
            project.delete(true, true, null);
        }
    }
}