Example usage for org.eclipse.jface.dialogs MessageDialog CONFIRM

List of usage examples for org.eclipse.jface.dialogs MessageDialog CONFIRM

Introduction

In this page you can find the example usage for org.eclipse.jface.dialogs MessageDialog CONFIRM.

Prototype

int CONFIRM

To view the source code for org.eclipse.jface.dialogs MessageDialog CONFIRM.

Click Source Link

Document

Constant for a simple dialog with the question image and OK/Cancel buttons (value 5).

Usage

From source file:org.xmind.ui.internal.editor.MindMapEditor.java

License:Open Source License

@Override
public void fileRemoved(final String title, final String message, final String[] buttons, boolean forceQuit) {
    if (workbookRef.getState() != IWorkbookRef.NORMAL) {
        return;/*from w w w . ja  v a 2  s  .  c  o m*/
    }

    if (forceQuit) {
        Display.getDefault().asyncExec(new Runnable() {

            @Override
            public void run() {
                closeEditor();
            }
        });
        return;
    }

    Display.getDefault().asyncExec(new Runnable() {

        @Override
        public void run() {
            deactivateFileNotifier();
            getEditorSite().getPage().activate(MindMapEditor.this);
            if (!isDirty()) {
                closeEditor();
            } else {
                MessageDialog dialog = new MessageDialog(null, title, null,
                        NLS.bind(MindMapMessages.MindMapEditor_fileRemovedDialog_message_prefix + message,
                                workbookRef.getName()),
                        MessageDialog.CONFIRM, buttons, 0);

                int code = dialog.open();
                if (code == 0) {
                    doSaveAs();
                } else if (code == 1 || code == -1) {
                    closeEditor();
                }

                activateFileNotifier();
            }
        }
    });
}

From source file:org.xmind.ui.internal.handlers.SaveWorkbookAsHandler.java

License:Open Source License

@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
    final IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
    Object selection = HandlerUtil.getCurrentSelectionChecked(event);
    if (selection instanceof IStructuredSelection) {
        selection = ((IStructuredSelection) selection).getFirstElement();
    }/*  ww  w .ja v a2s  . c o m*/
    if (!(selection instanceof IWorkbookRef))
        return null;

    final String preferredWizardId = event.getParameter(MindMapCommandConstants.SAVE_AS_WIZARD_ID_PARAM);
    final Set<String> excludedWizardIds = getExcludedWizardIds(event);

    final IWorkbookRef oldWorkbookRef = (IWorkbookRef) selection;
    final IWorkbookRef[] result = new IWorkbookRef[1];

    final ProgressMonitorDialog jobRunner = new ProgressMonitorDialog(window.getShell());
    jobRunner.setOpenOnRun(false);

    SafeRunner.run(new SafeRunnable() {
        @Override
        public void run() throws Exception {
            result[0] = org.xmind.ui.internal.e4handlers.SaveWorkbookAsHandler
                    .saveWorkbookAs(new ISaveContext() {

                        @Override
                        public Object getContextVariable(String key) {
                            Object variable = HandlerUtil.getVariable(event, key);
                            return variable == IEvaluationContext.UNDEFINED_VARIABLE ? null : variable;
                        }

                        @Override
                        public <T> T getContextVariable(Class<T> key) {
                            return window.getService(key);
                        }
                    }, oldWorkbookRef, jobRunner, new IFilter() {
                        @Override
                        public boolean select(Object wizardId) {
                            if (preferredWizardId != null) {
                                return preferredWizardId.equals(wizardId);
                            } else if (!excludedWizardIds.isEmpty()) {
                                return !excludedWizardIds.contains(wizardId);
                            }
                            return true;
                        }
                    }, false);
        }
    });

    final IWorkbookRef newWorkbookRef = result[0];
    if (newWorkbookRef == null || newWorkbookRef.equals(oldWorkbookRef))
        return null;

    MessageDialog dialog = new MessageDialog(window.getShell(),
            MindMapMessages.SaveWorkbookAsHandler_doneDialog_title, null,
            MindMapMessages.SaveWorkbookAsHandler_doneDialog_message, MessageDialog.CONFIRM, new String[] {

                    MindMapMessages.SaveWorkbookAsHandler_doneDialog_okButton_text,

                    MindMapMessages.SaveWorkbookAsHandler_doneDialog_cancelButton_text

            }, 0);
    if (dialog.open() != MessageDialog.OK)
        return null;

    try {
        window.getActivePage().openEditor(MindMapUI.getEditorInputFactory().createEditorInput(newWorkbookRef),
                MindMapUI.MINDMAP_EDITOR_ID, true);
    } catch (PartInitException e) {
        throw new ExecutionException(e.getMessage(), e);
    }

    return null;
}

From source file:seeit3d.base.core.handler.DefaultVisualizationStateChecker.java

License:Open Source License

@Override
public boolean checkState(List<Container> containers) {
    boolean askNeeded = false;
    if (containers.size() > CONTAINERS_THRESHOLD) {
        askNeeded = true;/*from  w w w.  j  ava2 s . co m*/
    }
    int polycylinders = 0;
    for (Container container : containers) {
        polycylinders += container.countPolyCylinders();
    }
    if (polycylinders > POLYCYLINDERS_THRESHOLD) {
        askNeeded = true;
    }

    if (askNeeded) {
        answer = null;
        Display.getDefault().syncExec(new Runnable() {
            @Override
            public void run() {
                Shell shell = new Shell(Display.getCurrent());
                boolean confirm = MessageDialog.open(MessageDialog.CONFIRM, shell,
                        "Possibly too much information",
                        "Too much information is about to be visualized, it could block your computer.\nAre you sure you want to continue?",
                        SWT.NONE);
                answer = new Boolean(confirm);
            }
        });

        while (answer == null) {
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                ErrorHandler.error(e);
            }
        }
        return answer;
    } else {
        return true;
    }
}