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

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

Introduction

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

Prototype

int YES_ID

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

Click Source Link

Document

Button id for a "Yes" button (value 2).

Usage

From source file:org.eclipse.sirius.common.ui.tools.api.dialog.SiriusMessageDialogWithToggle.java

License:Open Source License

/**
 * Attempt to find a standard JFace button id that matches the specified
 * button label. If no match can be found, use the default id provided.
 * //from   www . j a va2 s. c om
 * Overridden to investigate the provided buttons.
 * 
 * @param buttonLabel
 *            the button label whose id is sought
 * @param defaultId
 *            the id to use for the button if there is no standard id
 * @return the id for the specified button label
 */
// CHECKSTYLE:OFF
private int mapButtonLabelToButtonID(String buttonLabel, int defaultId) {
    // CHECKSTYLE:OON
    // Not pretty but does the job...
    if (IDialogConstants.OK_LABEL.equals(buttonLabel)) {
        return IDialogConstants.OK_ID;
    }

    if (IDialogConstants.YES_LABEL.equals(buttonLabel)) {
        return IDialogConstants.YES_ID;
    }

    if (IDialogConstants.NO_LABEL.equals(buttonLabel)) {
        return IDialogConstants.NO_ID;
    }

    if (IDialogConstants.CANCEL_LABEL.equals(buttonLabel)) {
        return IDialogConstants.CANCEL_ID;
    }

    if (IDialogConstants.YES_TO_ALL_LABEL.equals(buttonLabel)) {
        return IDialogConstants.YES_TO_ALL_ID;
    }

    if (IDialogConstants.SKIP_LABEL.equals(buttonLabel)) {
        return IDialogConstants.SKIP_ID;
    }

    if (IDialogConstants.STOP_LABEL.equals(buttonLabel)) {
        return IDialogConstants.STOP_ID;
    }

    if (IDialogConstants.ABORT_LABEL.equals(buttonLabel)) {
        return IDialogConstants.ABORT_ID;
    }

    if (IDialogConstants.RETRY_LABEL.equals(buttonLabel)) {
        return IDialogConstants.RETRY_ID;
    }

    if (IDialogConstants.IGNORE_LABEL.equals(buttonLabel)) {
        return IDialogConstants.IGNORE_ID;
    }

    if (IDialogConstants.PROCEED_LABEL.equals(buttonLabel)) {
        return IDialogConstants.PROCEED_ID;
    }

    if (IDialogConstants.OPEN_LABEL.equals(buttonLabel)) {
        return IDialogConstants.OPEN_ID;
    }

    if (IDialogConstants.CLOSE_LABEL.equals(buttonLabel)) {
        return IDialogConstants.CLOSE_ID;
    }

    if (IDialogConstants.BACK_LABEL.equals(buttonLabel)) {
        return IDialogConstants.BACK_ID;
    }

    if (IDialogConstants.NEXT_LABEL.equals(buttonLabel)) {
        return IDialogConstants.NEXT_ID;
    }

    if (IDialogConstants.FINISH_LABEL.equals(buttonLabel)) {
        return IDialogConstants.FINISH_ID;
    }

    if (IDialogConstants.HELP_LABEL.equals(buttonLabel)) {
        return IDialogConstants.HELP_ID;
    }

    if (IDialogConstants.NO_TO_ALL_LABEL.equals(buttonLabel)) {
        return IDialogConstants.NO_TO_ALL_ID;
    }

    if (IDialogConstants.SHOW_DETAILS_LABEL.equals(buttonLabel)) {
        return IDialogConstants.DETAILS_ID;
    }

    if (IDialogConstants.HIDE_DETAILS_LABEL.equals(buttonLabel)) {
        return IDialogConstants.DETAILS_ID;
    }

    for (String providedButton : buttonsMap.keySet()) {
        if (providedButton.equals(buttonLabel)) {
            return buttonsMap.get(providedButton);
        }
    }

    // No XXX_LABEL in IDialogConstants for these. Unlikely
    // they would be used in a message dialog though.
    // public int SELECT_ALL_ID = 18;
    // public int DESELECT_ALL_ID = 19;
    // public int SELECT_TYPES_ID = 20;

    return defaultId;
}

From source file:org.eclipse.sirius.common.ui.tools.api.util.SWTUtil.java

License:Open Source License

/**
 * Show a dialog to ask the user to save or not the content of the Session.
 * The window's return codes can be ISaveablePart2.CANCEL,
 * ISaveablePart2.YES or ISaveablePart2.NO.
 * /*w ww .  j av  a  2  s. co m*/
 * @param label
 *            the name of the element to save or any other label
 * @param canCancel
 *            <code>true</code> if the save can be cancel,
 *            <code>false</code> otherwise
 * @param stillOpenElsewhere
 *            <code>true</code> the object to save is open elsewhere,
 *            <code>false</code> otherwise
 * @return the return code
 */
private static int showStandardSaveDialog(final String label, final boolean canCancel,
        boolean stillOpenElsewhere) {
    // Step 1: getting the save buttons
    Map<String, Integer> buttons = Maps.newLinkedHashMap();
    buttons.put(IDialogConstants.YES_LABEL, IDialogConstants.YES_ID);
    buttons.put(IDialogConstants.NO_LABEL, IDialogConstants.NO_ID);

    // Step 2 :opening window
    int temporaryResult = openSaveDialog(label, canCancel, buttons, stillOpenElsewhere);

    return temporaryResult;
}

From source file:org.eclipse.sirius.common.ui.tools.api.util.SWTUtil.java

License:Open Source License

/**
 * @see org.eclipse.internal.SaveablesList#promptForSaving(List,
 *      org.eclipse.jface.window.IShellProvider,
 *      org.eclipse.jface.operation.IRunnableContext, boolean, boolean)
 *///  ww w.j  av a 2s. com
private static int openSaveDialog(String label, final boolean canCancel, Map<String, Integer> buttons,
        boolean stillOpenElsewhere) {
    int choice = ISaveablePart2.YES;

    // Get user preference for still open beahvior
    IPreferenceStore platformUIPrefStore = PlatformUI.getPreferenceStore();
    boolean dontPrompt = stillOpenElsewhere
            && !platformUIPrefStore.getBoolean(IWorkbenchPreferenceConstants.PROMPT_WHEN_SAVEABLE_STILL_OPEN);
    if (dontPrompt) {
        choice = ISaveablePart2.NO;
    } else {
        final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
        if (window != null && buttons != null) {
            final MessageDialog dialog = createSaveDialog(label, canCancel, buttons, stillOpenElsewhere,
                    window);

            choice = dialog.open();

            // User has pressed "Escape" or has closed the dialog
            if (choice == SWT.DEFAULT) {
                choice = IDialogConstants.CANCEL_ID;
            }

            // React to the use preference choice.
            // map value of choice back to ISaveablePart2 values
            switch (choice) {
            case IDialogConstants.YES_ID:
                choice = ISaveablePart2.YES;
                break;
            case IDialogConstants.NO_ID:
                choice = ISaveablePart2.NO;
                break;
            case IDialogConstants.CANCEL_ID:
                choice = ISaveablePart2.CANCEL;
                break;
            default:
                break;
            }

            if (stillOpenElsewhere) {
                MessageDialogWithToggle dialogWithToggle = (MessageDialogWithToggle) dialog;
                if (choice != ISaveablePart2.CANCEL && dialogWithToggle.getToggleState()) {
                    // change the rpeference
                    platformUIPrefStore.setValue(IWorkbenchPreferenceConstants.PROMPT_WHEN_SAVEABLE_STILL_OPEN,
                            false);
                }
            }
        }
    }

    return choice;
}

From source file:org.eclipse.tcf.te.tcf.ui.wizards.pages.PeerExportWizardPage.java

License:Open Source License

public boolean finish() {
    final Object[] configs = fViewer.getCheckedElements();
    final boolean overwrite = fOverwrite.getSelection();
    final String path = fDestinationField.getText().trim();
    IDialogSettings settings = getDialogSettings();
    settings.put(OVERWRITE, overwrite);//w  ww  .  ja  va2  s  .c o  m
    settings.put(OLD_PATH, path);
    UIJob exportjob = new UIJob(getContainer().getShell().getDisplay(), Messages.PeerExportWizard_title) {
        @Override
        public IStatus runInUIThread(IProgressMonitor monitor) {
            if (monitor == null) {
                monitor = new NullProgressMonitor();
            }
            IPath destpath = new Path(path);
            File destfolder = destpath.toFile();
            boolean exist = destfolder.exists();
            if (!exist) {
                exist = destfolder.mkdirs();
            }
            if (exist) {
                monitor.beginTask(Messages.PeerExportWizard_title, configs.length);
                boolean toggleState = false;
                int toggleResult = -1;
                for (Object config : configs) {
                    IURIPersistenceService service = ServiceManager.getInstance().getService(config,
                            IExportPersistenceService.class);
                    if (service == null) {
                        service = ServiceManager.getInstance().getService(config, IURIPersistenceService.class);
                    }
                    if (service != null) {
                        try {
                            URI uri = service.getURI(config);
                            File defaultFile = new File(uri.normalize());
                            defaultFile = new Path(defaultFile.toString()).removeFileExtension().toFile();
                            File file = destpath.append(defaultFile.getName()).addFileExtension("peer") //$NON-NLS-1$
                                    .toFile();
                            if (file.exists() && !overwrite) {
                                if (!toggleState || toggleResult < 0) {
                                    MessageDialogWithToggle dialog = MessageDialogWithToggle.openYesNoQuestion(
                                            getShell(), null,
                                            NLS.bind(Messages.PeerExportWizardPage_overwriteDialog_message,
                                                    file.toString()),
                                            Messages.PeerExportWizardPage_overwriteDialogToggle_message,
                                            toggleState, null, null);
                                    toggleState = dialog.getToggleState();
                                    toggleResult = dialog.getReturnCode();
                                }
                                if (toggleResult != IDialogConstants.YES_ID) {
                                    continue;
                                }
                            }
                            service.write(config, file.toURI());
                        } catch (Exception e) {
                        }
                    }
                    monitor.worked(1);
                }
                monitor.done();
            }
            return Status.OK_STATUS;
        }
    };
    exportjob.schedule();
    return true;
}

From source file:org.eclipse.tcf.te.tcf.ui.wizards.pages.PeerImportWizardPage.java

License:Open Source License

public boolean finish() {
    final Object[] configs = fViewer.getCheckedElements();
    final boolean overwrite = fOverwrite.getSelection();
    final String path = fLocationField.getText().trim();
    IDialogSettings settings = getDialogSettings();
    settings.put(OVERWRITE, overwrite);//from   ww w.j av a  2  s . com
    settings.put(OLD_PATH, path);
    UIJob importjob = new UIJob(getContainer().getShell().getDisplay(), Messages.PeerImportWizard_title) {
        @Override
        public IStatus runInUIThread(IProgressMonitor monitor) {
            final IPeerModel model = ModelManager.getPeerModel();
            final IProgressMonitor finalMonitor;
            if (monitor == null) {
                finalMonitor = new NullProgressMonitor();
            } else {
                finalMonitor = monitor;
            }
            finalMonitor.beginTask(Messages.PeerImportWizard_title, configs.length);
            boolean toggleState = false;
            int toggleResult = -1;
            for (final Object config : configs) {
                if (config instanceof IPeer) {
                    final AtomicReference<IPeerNode> peerNode = new AtomicReference<IPeerNode>();
                    Protocol.invokeAndWait(new Runnable() {
                        @Override
                        public void run() {
                            peerNode.set(model.getService(IPeerModelLookupService.class)
                                    .lkupPeerModelById(((IPeer) config).getID()));
                            if (peerNode.get() == null) {
                                for (IPeerNode peer : model.getPeerNodes()) {
                                    String name = peer.getPeer().getName();
                                    if (name.equalsIgnoreCase(((IPeer) config).getName())) {
                                        peerNode.set(peer);
                                        break;
                                    }
                                }
                            }
                        }
                    });
                    // And create a new one if we cannot find it
                    IURIPersistenceService service = ServiceManager.getInstance()
                            .getService(IImportPersistenceService.class);
                    if (service == null) {
                        service = ServiceManager.getInstance().getService(IURIPersistenceService.class);
                    }
                    if (peerNode.get() != null) {
                        if (!toggleState || toggleResult < 0) {
                            MessageDialogWithToggle dialog = MessageDialogWithToggle.openYesNoQuestion(
                                    getShell(), null,
                                    NLS.bind(Messages.PeerImportWizardPage_overwriteDialog_message,
                                            peerNode.get().getName()),
                                    Messages.PeerImportWizardPage_overwriteDialogToggle_message, toggleState,
                                    null, null);
                            toggleState = dialog.getToggleState();
                            toggleResult = dialog.getReturnCode();
                        }
                        if (toggleResult != IDialogConstants.YES_ID) {
                            continue;
                        }
                        try {
                            service.delete(peerNode.get().getPeer(), null);
                        } catch (IOException e) {
                        }
                    }
                    try {
                        URI uri = service.getURI(config);
                        File file = new File(uri.normalize());
                        service.write(config, file.toURI());
                    } catch (IOException e) {
                    }
                }
                finalMonitor.worked(1);
            }
            Protocol.invokeLater(new Runnable() {
                @Override
                public void run() {
                    model.getService(IPeerModelRefreshService.class).refresh(null);
                }
            });
            finalMonitor.done();
            return Status.OK_STATUS;
        }
    };
    importjob.schedule();
    return true;
}

From source file:org.eclipse.tcf.te.ui.handler.ConnectableCommandHandler.java

License:Open Source License

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    IStructuredSelection selection = getSelection(event);

    List<IConnectable> connectables = getConnectables(selection);

    if (handleDirty) {
        for (IEditorReference ref : PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
                .getEditorReferences()) {
            if (ref.isDirty()) {
                try {
                    IConnectable connectable = getConnectable(ref.getEditorInput());
                    if (connectable != null && connectables.contains(connectable)) {
                        int result = OptionalMessageDialog.openYesNoCancelDialog(
                                HandlerUtil.getActiveShell(event),
                                Messages.AbstractEditorCommandHandler_saveDialog_title,
                                NLS.bind(Messages.AbstractEditorCommandHandler_saveDialog_message,
                                        ref.getTitle()),
                                null, null);
                        switch (result) {
                        case IDialogConstants.YES_ID:
                            ref.getEditor(true).doSave(null);
                            break;
                        case IDialogConstants.CANCEL_ID:
                            return null;
                        }/*from  w  ww  .  j  a va  2s .c  o m*/
                    }
                } catch (Exception e) {
                }
            }
        }
    }

    return internalExecute(event, selection, connectables);
}

From source file:org.eclipse.team.internal.ccvs.ui.actions.CommitAction.java

License:Open Source License

public static boolean isIncludeChangeSets(final Shell shell, final String message) {
    if (CVSUIPlugin.getPlugin().getChangeSetManager().getSets().length == 0)
        return false;
    final IPreferenceStore store = CVSUIPlugin.getPlugin().getPreferenceStore();
    final String option = store.getString(ICVSUIConstants.PREF_INCLUDE_CHANGE_SETS_IN_COMMIT);
    if (option.equals(MessageDialogWithToggle.ALWAYS))
        return true; // no, always switch

    if (option.equals(MessageDialogWithToggle.NEVER))
        return false; // no, never switch

    // Ask the user whether to switch
    final int[] result = new int[] { 0 };
    Utils.syncExec(new Runnable() {
        public void run() {
            final MessageDialogWithToggle m = MessageDialogWithToggle.openYesNoQuestion(shell,
                    CVSUIMessages.CommitAction_1, message, CVSUIMessages.ShowAnnotationOperation_4,
                    false /* toggle state */, store, ICVSUIConstants.PREF_INCLUDE_CHANGE_SETS_IN_COMMIT);

            result[0] = m.getReturnCode();
        }// ww  w .  ja  v  a2 s. co  m
    }, shell);

    switch (result[0]) {
    // yes
    case IDialogConstants.YES_ID:
    case IDialogConstants.OK_ID:
        return true;
    // no
    case IDialogConstants.NO_ID:
        return false;
    }
    return false;
}

From source file:org.eclipse.team.internal.ccvs.ui.actions.TagAction.java

License:Open Source License

/**
 * Prompts the user for a tag name./*from  w  w  w  . j  a va  2  s .com*/
 * Note: This method is designed to be overridden by test cases.
 * @return the operation, or null to cancel
 */
protected ITagOperation configureOperation() {
    IPreferenceStore store = CVSUIPlugin.getPlugin().getPreferenceStore();
    ITagOperation operation = createTagOperation();
    if (operation.isEmpty()) {
        return null;
    }
    if (!performPrompting(operation)) {
        return null;
    }
    TagAsVersionDialog dialog = new TagAsVersionDialog(getShell(), CVSUIMessages.TagAction_tagResources,
            operation);
    if (dialog.open() != Window.OK)
        return null;

    // The user has indicated they want to force a move.  Make sure they really do.      
    if (dialog.shouldMoveTag() && store.getBoolean(ICVSUIConstants.PREF_CONFIRM_MOVE_TAG)) {
        MessageDialogWithToggle confirmDialog = MessageDialogWithToggle.openYesNoQuestion(getShell(),
                CVSUIMessages.TagAction_moveTagConfirmTitle,
                NLS.bind(CVSUIMessages.TagAction_moveTagConfirmMessage, new String[] { dialog.getTagName() }),
                null, false, null, null);

        if (confirmDialog.getReturnCode() == IDialogConstants.YES_ID) {
            store.setValue(ICVSUIConstants.PREF_CONFIRM_MOVE_TAG, !confirmDialog.getToggleState());
        } else {
            return null;
        }
    }

    // The user is a cowboy and wants to do it.
    return dialog.getOperation();
}

From source file:org.eclipse.team.internal.ccvs.ui.AddToVersionControlDialog.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, true);
    super.createButtonsForButtonBar(parent);
}

From source file:org.eclipse.team.internal.ccvs.ui.AddToVersionControlDialog.java

License:Open Source License

protected void buttonPressed(int id) {
    // hijack yes and no buttons to set the correct return
    // codes./* w  w w. j  a  v  a  2  s. com*/
    if (id == IDialogConstants.YES_ID || id == IDialogConstants.NO_ID) {
        setReturnCode(id);
        close();
    } else {
        super.buttonPressed(id);
    }
}