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

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

Introduction

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

Prototype

String CANCEL_LABEL

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

Click Source Link

Document

The label for cancel buttons.

Usage

From source file:net.rim.ejde.internal.util.PromptDialog.java

License:Open Source License

public PromptDialog(Shell parentShell, String title, String initialAnswer, boolean obscure) {
    super(parentShell, title, null, title + ":", QUESTION,
            new String[] { IDialogConstants.OK_LABEL, IDialogConstants.CANCEL_LABEL }, 0);
    _obscure = obscure;/*from   w  w  w  .  jav a  2s.  c  om*/
    _response = null;
    _initialAnswer = initialAnswer;
}

From source file:net.sf.eclipse.tomcat.TomcatProjectChangeListener.java

License:Open Source License

public void resourceChanged(IResourceChangeEvent event) {
    if (event.getResource() instanceof IProject) {
        final TomcatProject project = TomcatProject.create((IProject) event.getResource());
        if (project != null) {

            Display.getDefault().syncExec(new Runnable() {
                public void run() {
                    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();

                    String[] labels = { IDialogConstants.OK_LABEL, IDialogConstants.CANCEL_LABEL };
                    MessageDialog dialog = new MessageDialog(window.getShell(), WIZARD_PROJECT_REMOVE_TITLE,
                            null, WIZARD_PROJECT_REMOVE_DESCRIPTION, MessageDialog.QUESTION, labels, 1);

                    if (dialog.open() == MessageDialog.OK) {
                        try {
                            project.removeContext();
                        } catch (Exception ex) {
                            TomcatLauncherPlugin.log(ex.getMessage());
                        }/* ww  w.  j a v a 2  s .c  o  m*/
                    }
                }
            });

        }
    }
}

From source file:net.sf.eclipsecs.ui.config.RuleConfigurationEditDialog.java

License:Open Source License

protected void createButtonsForButtonBar(Composite parent) {

    Button defautlt = createButton(parent, IDialogConstants.BACK_ID,
            Messages.RuleConfigurationEditDialog_btnDefaul, false);
    defautlt.setEnabled(!mReadonly);/*from  w w  w  . ja  va  2s.c o m*/

    // create OK and Cancel buttons by default
    createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true);
    createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false);
}

From source file:net.sf.eclipsecs.ui.stats.views.internal.CheckstyleMarkerFilterDialog.java

License:Open Source License

/**
 * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite)
 *//*from   w  ww . j a va  2  s  .  c  o  m*/
protected void createButtonsForButtonBar(Composite parent) {

    mBtnDefault = createButton(parent, IDialogConstants.BACK_ID,
            Messages.CheckstyleMarkerFilterDialog_btnRestoreDefault, false);
    mBtnDefault.addSelectionListener(mController);

    // create OK and Cancel buttons by default
    createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true);
    createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false);
}

From source file:net.sf.eclipsensis.dialogs.NSISAssociatedHeadersPropertyPage.java

License:Open Source License

@Override
public Control createControl(final Composite parent) {
    mOriginalHeaders = mHeaderAssociationManager
            .getAssociatedHeaders((IFile) ((NSISProperties) mSettings).getResource());
    mHeaders = new HashSet<IFile>();
    initHeaders();// w  ww.  j  a  va  2s .c  om
    final IFilter filter = new IFilter() {
        public boolean select(Object toTest) {
            if (toTest instanceof IFile) {
                String ext = ((IFile) toTest).getFileExtension();
                if (ext != null && ext.equalsIgnoreCase(INSISConstants.NSH_EXTENSION)) {
                    return mHeaders != null && !mHeaders.contains(toTest);
                }
            }
            return false;
        }
    };

    Composite composite = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout(2, false);
    composite.setLayout(layout);

    Label l = new Label(composite, SWT.NONE);
    l.setText(EclipseNSISPlugin.getResourceString("associated.headers.title")); //$NON-NLS-1$
    GridData data = new GridData(SWT.FILL, SWT.FILL, true, false);
    data.horizontalSpan = 2;
    l.setLayoutData(data);

    Table table = new Table(composite, SWT.FULL_SELECTION | SWT.MULTI | SWT.V_SCROLL | SWT.BORDER);
    table.setHeaderVisible(true);
    table.setLinesVisible(true);
    TableColumn column = new TableColumn(table, SWT.LEFT, 0);
    column.setText(EclipseNSISPlugin.getResourceString("associated.headers.column.label")); //$NON-NLS-1$
    table.addControlListener(new TableResizer());

    mViewer = new TableViewer(table);
    mViewer.setContentProvider(new CollectionContentProvider());
    mViewer.setLabelProvider(new CollectionLabelProvider() {
        @Override
        public String getColumnText(Object element, int columnIndex) {
            if (element instanceof IFile) {
                return ((IFile) element).getFullPath().toString();
            }
            return null;
        }
    });
    mViewer.setComparator(new ViewerComparator() {
        @Override
        public int compare(Viewer viewer, Object e1, Object e2) {
            if (e1 instanceof IFile && e2 instanceof IFile) {
                return ((IFile) e1).getFullPath().toString().compareTo(((IFile) e2).getFullPath().toString());
            }
            return super.compare(viewer, e1, e2);
        }
    });
    data = new GridData(SWT.FILL, SWT.FILL, true, true);
    data.verticalSpan = 2;
    table.setLayoutData(data);
    Button addButton = new Button(composite, SWT.PUSH);
    addButton.setImage(CommonImages.ADD_ICON);
    addButton.setToolTipText(EclipseNSISPlugin.getResourceString("add.associated.header.toolip")); //$NON-NLS-1$
    addButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent arg0) {
            FileSelectionDialog dialog = new FileSelectionDialog(parent.getShell(),
                    ((NSISProperties) mSettings).getResource().getParent(), filter);
            dialog.setDialogMessage(EclipseNSISPlugin.getResourceString("nsis.script.prompt")); //$NON-NLS-1$
            dialog.setHelpAvailable(false);
            if (dialog.open() == Window.OK) {
                IFile file = dialog.getFile();
                IFile script = mHeaderAssociationManager.getAssociatedScript(file);
                if (script != null && !script.equals(((NSISProperties) mSettings).getResource())
                        && mReassociateHeaderWarning.getSelection()) {

                    MessageDialogWithToggle dlg = new MessageDialogWithToggle(parent.getShell(),
                            EclipseNSISPlugin.getResourceString("confirm.title"), //$NON-NLS-1$
                            EclipseNSISPlugin.getShellImage(),
                            EclipseNSISPlugin.getFormattedString("associated.header.warning", //$NON-NLS-1$
                                    new String[] { file.getFullPath().toString(),
                                            script.getFullPath().toString() }),
                            MessageDialog.QUESTION,
                            new String[] { IDialogConstants.OK_LABEL, IDialogConstants.CANCEL_LABEL }, 0,
                            EclipseNSISPlugin.getResourceString("associated.header.toggle.message"), false); //$NON-NLS-1$
                    dlg.open();
                    if (dialog.getReturnCode() == IDialogConstants.OK_ID) {
                        mReassociateHeaderWarning.setSelection(!dlg.getToggleState());
                    } else {
                        return;
                    }
                }
                if (!mHeaders.contains(file)) {
                    mHeaders.add(file);
                    mViewer.refresh(false);
                }
            }
        }
    });
    addButton.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false));

    final Button removeButton = new Button(composite, SWT.PUSH);
    removeButton.setImage(CommonImages.DELETE_ICON);
    removeButton.setToolTipText(EclipseNSISPlugin.getResourceString("remove.associated.header.toolip")); //$NON-NLS-1$
    removeButton.setEnabled(false);
    removeButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent arg0) {
            IStructuredSelection sel = (IStructuredSelection) mViewer.getSelection();
            if (!sel.isEmpty()) {
                mHeaders.removeAll(sel.toList());
                mViewer.refresh(false);
            }
        }
    });
    data = new GridData(SWT.FILL, SWT.TOP, false, false);
    data.verticalSpan = 2;
    removeButton.setLayoutData(data);

    Composite c = new Composite(composite, SWT.NONE);
    data = new GridData(SWT.FILL, SWT.FILL, true, false);
    c.setLayoutData(data);
    layout = new GridLayout(2, false);
    layout.marginWidth = layout.marginHeight = 0;
    layout.horizontalSpacing = 3;
    c.setLayout(layout);

    mReassociateHeaderWarning = new Button(c, SWT.CHECK);
    mReassociateHeaderWarning.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false));
    mReassociateHeaderWarning.setSelection(NSISPreferences.getInstance().getPreferenceStore()
            .getBoolean(INSISPreferenceConstants.WARN_REASSOCIATE_HEADER));
    l = new Label(c, SWT.WRAP);
    l.setText(EclipseNSISPlugin.getResourceString("show.associated.header.warning.label")); //$NON-NLS-1$
    l.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, true, false));

    mViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            removeButton.setEnabled((selection != null && !selection.isEmpty()));
        }
    });

    mViewer.setInput(mHeaders);
    PlatformUI.getWorkbench().getHelpSystem().setHelp(composite,
            INSISConstants.PLUGIN_CONTEXT_PREFIX + "nsis_assochdrproperties_context"); //$NON-NLS-1$
    return composite;
}

From source file:net.sf.eclipsensis.dialogs.NSISTaskTagsPreferencePage.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override/*from  w w w. java2 s.  c  o m*/
public boolean performOk() {
    if (super.performOk()) {
        Collection<NSISTaskTag> taskTags = (Collection<NSISTaskTag>) mTableViewer.getInput();
        boolean caseSensitive = mCaseSensitiveButton.getSelection();
        boolean different = (caseSensitive != NSISPreferences.getInstance().isCaseSensitiveTaskTags());
        if (!different) {
            if (taskTags.size() == mOriginalTags.size()) {
                for (Iterator<NSISTaskTag> iter = taskTags.iterator(); iter.hasNext();) {
                    if (!mOriginalTags.contains(iter.next())) {
                        different = true;
                        break;
                    }
                }
            } else {
                different = true;
            }
        }
        if (different) {
            if (taskTags.size() > 0) {
                boolean defaultFound = false;
                for (Iterator<NSISTaskTag> iter = taskTags.iterator(); iter.hasNext();) {
                    NSISTaskTag element = iter.next();
                    if (element.isDefault()) {
                        defaultFound = true;
                        break;
                    }
                }
                if (!defaultFound) {
                    if (taskTags.size() == 1) {
                        NSISTaskTag taskTag = (NSISTaskTag) taskTags.toArray()[0];
                        taskTag.setDefault(true);
                        mTableViewer.setChecked(taskTag, true);
                    } else {
                        Common.openError(getShell(),
                                EclipseNSISPlugin.getResourceString("task.tag.dialog.missing.default"), //$NON-NLS-1$
                                EclipseNSISPlugin.getShellImage());
                        return false;
                    }
                }
            }
        }
        boolean updateTaskTags = false;
        if (different) {
            NSISPreferences.getInstance().setTaskTags(taskTags);
            NSISPreferences.getInstance().setCaseSensitiveTaskTags(caseSensitive);
            MessageDialog dialog = new MessageDialog(getShell(),
                    EclipseNSISPlugin.getResourceString("confirm.title"), //$NON-NLS-1$
                    EclipseNSISPlugin.getShellImage(),
                    EclipseNSISPlugin.getResourceString("task.tags.settings.changed"), MessageDialog.QUESTION, //$NON-NLS-1$
                    new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL,
                            IDialogConstants.CANCEL_LABEL },
                    0);
            dialog.setBlockOnOpen(true);
            int rv = dialog.open();
            if (rv == 2) {
                //Cancel
                return false;
            } else {
                updateTaskTags = (rv == 0);
            }
            NSISPreferences.getInstance().store();
        }
        if (updateTaskTags) {
            new NSISTaskTagUpdater().updateTaskTags();
            NSISEditorUtilities.updatePresentations();
            mOriginalTags.clear();
            mOriginalTags.addAll(taskTags);
        }
        return true;
    }
    return false;
}

From source file:net.sf.eclipsensis.editor.NSISEditor.java

License:Open Source License

@Override
protected void installTextDragAndDrop(ISourceViewer viewer) {
    if (mTextDragAndDropEnabled || viewer == null) {
        return;//  w  w w  .j a va  2s  . co m
    }

    if (mTextDragAndDropInstalled) {
        mTextDragAndDropEnabled = true;
        return;
    }

    final IDragAndDropService dndService = (IDragAndDropService) getSite()
            .getService(IDragAndDropService.class);
    if (dndService == null) {
        return;
    }

    mTextDragAndDropEnabled = true;

    final StyledText st = viewer.getTextWidget();

    // Install drag source
    final ISelectionProvider selectionProvider = viewer.getSelectionProvider();
    final DragSource source = new DragSource(st, DND.DROP_COPY | DND.DROP_MOVE);
    source.setTransfer(new Transfer[] { TextTransfer.getInstance() });
    source.addDragListener(new DragSourceAdapter() {
        String mSelectedText;
        Point mSelection;

        @Override
        public void dragStart(DragSourceEvent event) {
            mTextDragAndDropToken = null;

            if (!mTextDragAndDropEnabled) {
                event.doit = false;
                event.image = null;
                return;
            }

            try {
                mSelection = st.getSelection();
                int offset = st.getOffsetAtLocation(new Point(event.x, event.y));
                Point p = st.getLocationAtOffset(offset);
                if (p.x > event.x) {
                    offset--;
                }
                event.doit = offset > mSelection.x && offset < mSelection.y;

                ISelection selection = selectionProvider.getSelection();
                if (selection instanceof ITextSelection) {
                    mSelectedText = ((ITextSelection) selection).getText();
                } else {
                    mSelectedText = st.getSelectionText();
                }
            } catch (IllegalArgumentException ex) {
                event.doit = false;
            }
        }

        @Override
        public void dragSetData(DragSourceEvent event) {
            event.data = mSelectedText;
            mTextDragAndDropToken = this; // Can be any non-null object
        }

        @Override
        public void dragFinished(DragSourceEvent event) {
            try {
                if (event.detail == DND.DROP_MOVE && validateEditorInputState()) {
                    Point newSelection = st.getSelection();
                    int length = mSelection.y - mSelection.x;
                    int delta = 0;
                    if (newSelection.x < mSelection.x) {
                        delta = length;
                    }
                    st.replaceTextRange(mSelection.x + delta, length, ""); //$NON-NLS-1$

                    if (mTextDragAndDropToken == null) {
                        // Move in same editor - end compound change
                        IRewriteTarget target = (IRewriteTarget) getAdapter(IRewriteTarget.class);
                        if (target != null) {
                            target.endCompoundChange();
                        }
                    }

                }
            } finally {
                mTextDragAndDropToken = null;
            }
        }
    });

    // Install drag target
    DropTargetListener dropTargetListener = new DropTargetAdapter() {
        private Point mSelection;

        @Override
        public void dragEnter(DropTargetEvent event) {
            if (NSISCommandTransfer.INSTANCE.isSupportedType(event.currentDataType)
                    || FileTransfer.getInstance().isSupportedType(event.currentDataType)) {
                //Don't want default feedback- we will do it ourselves
                event.feedback = DND.FEEDBACK_NONE;
                if (event.detail == DND.DROP_DEFAULT) {
                    event.detail = DND.DROP_COPY;
                }
            } else {
                mTextDragAndDropToken = null;
                mSelection = st.getSelection();

                if (!mTextDragAndDropEnabled) {
                    event.detail = DND.DROP_NONE;
                    event.feedback = DND.FEEDBACK_NONE;
                    return;
                }

                if (event.detail == DND.DROP_DEFAULT) {
                    event.detail = DND.DROP_MOVE;
                }
            }
        }

        @Override
        public void dragOperationChanged(DropTargetEvent event) {
            if (NSISCommandTransfer.INSTANCE.isSupportedType(event.currentDataType)
                    || FileTransfer.getInstance().isSupportedType(event.currentDataType)) {
                // Don't want default feedback- we will do it ourselves
                event.feedback = DND.FEEDBACK_NONE;
                if (event.detail == DND.DROP_DEFAULT) {
                    event.detail = DND.DROP_COPY;
                }
            } else {
                if (!mTextDragAndDropEnabled) {
                    event.detail = DND.DROP_NONE;
                    event.feedback = DND.FEEDBACK_NONE;
                    return;
                }

                if (event.detail == DND.DROP_DEFAULT) {
                    event.detail = DND.DROP_MOVE;
                }
            }
        }

        @Override
        public void dragOver(DropTargetEvent event) {
            if (NSISCommandTransfer.INSTANCE.isSupportedType(event.currentDataType)
                    || FileTransfer.getInstance().isSupportedType(event.currentDataType)) {
                // Don't want default feedback- we will do it ourselves
                event.feedback = DND.FEEDBACK_NONE;
                st.setFocus();
                Point location = st.getDisplay().map(null, st, event.x, event.y);
                location.x = Math.max(0, location.x);
                location.y = Math.max(0, location.y);
                int offset;
                try {
                    offset = st.getOffsetAtLocation(new Point(location.x, location.y));
                } catch (IllegalArgumentException ex) {
                    try {
                        offset = st.getOffsetAtLocation(new Point(0, location.y));
                    } catch (IllegalArgumentException ex2) {
                        offset = st.getCharCount();
                        Point maxLocation = st.getLocationAtOffset(offset);
                        if (location.y >= maxLocation.y) {
                            if (location.x < maxLocation.x) {
                                offset = st.getOffsetAtLocation(new Point(location.x, maxLocation.y));
                            }
                        }
                    }
                }
                IDocument doc = getDocumentProvider().getDocument(getEditorInput());
                offset = getCaretOffsetForInsertCommand(doc, offset);

                st.setCaretOffset(offset);
            } else {
                if (!mTextDragAndDropEnabled) {
                    event.feedback = DND.FEEDBACK_NONE;
                    return;
                }

                event.feedback |= DND.FEEDBACK_SCROLL;
            }
        }

        @Override
        public void drop(DropTargetEvent event) {
            if (NSISCommandTransfer.INSTANCE.isSupportedType(event.currentDataType)) {
                insertCommand((NSISCommand) event.data, false);
            } else if (FileTransfer.getInstance().isSupportedType(event.currentDataType)) {
                int dropNSISFilesAction = NSISPreferences.getInstance().getPreferenceStore()
                        .getInt(DROP_EXTERNAL_FILES_ACTION);
                switch (dropNSISFilesAction) {
                case DROP_EXTERNAL_FILES_ASK:
                    MessageDialog dialog = new MessageDialog(getSite().getShell(),
                            EclipseNSISPlugin.getResourceString("drop.external.files.ask.title"), //$NON-NLS-1$
                            EclipseNSISPlugin.getShellImage(),
                            EclipseNSISPlugin.getResourceString("drop.external.files.ask.message"), //$NON-NLS-1$
                            MessageDialog.QUESTION,
                            new String[] { IDialogConstants.OK_LABEL, IDialogConstants.CANCEL_LABEL }, 0);
                    if (dialog.open() != 0) {
                        break;
                    }
                    //$FALL-THROUGH$
                case DROP_EXTERNAL_FILES_OPEN_IN_EDITORS:
                    openFiles((String[]) event.data);
                    return;
                default:
                    break;
                }
                insertFiles((String[]) event.data);
            } else {
                try {
                    if (!mTextDragAndDropEnabled) {
                        return;
                    }

                    if (mTextDragAndDropToken != null && event.detail == DND.DROP_MOVE) {
                        // Move in same editor
                        int caretOffset = st.getCaretOffset();
                        if (mSelection.x <= caretOffset && caretOffset <= mSelection.y) {
                            event.detail = DND.DROP_NONE;
                            return;
                        }

                        // Start compound change
                        IRewriteTarget target = (IRewriteTarget) getAdapter(IRewriteTarget.class);
                        if (target != null) {
                            target.beginCompoundChange();
                        }
                    }

                    if (!validateEditorInputState()) {
                        event.detail = DND.DROP_NONE;
                        return;
                    }

                    String text = (String) event.data;
                    Point newSelection = st.getSelection();
                    st.insert(text);
                    st.setSelectionRange(newSelection.x, text.length());
                } finally {
                    mTextDragAndDropToken = null;
                }
            }
        }
    };
    dndService.addMergedDropTarget(st, DND.DROP_DEFAULT | DND.DROP_MOVE | DND.DROP_COPY, new Transfer[] {
            NSISCommandTransfer.INSTANCE, FileTransfer.getInstance(), TextTransfer.getInstance() },
            dropTargetListener);

    mTextDragAndDropInstalled = true;
    mTextDragAndDropEnabled = true;
}

From source file:net.sf.eclipsensis.installoptions.actions.INIFileDeleteControlAction.java

License:Open Source License

@Override
protected boolean doRun2(INIFile iniFile, INISection section) {
    boolean showOnShift = InstallOptionsPlugin.getDefault().getPreferenceStore()
            .getBoolean(IInstallOptionsConstants.PREFERENCE_DELETE_CONTROL_WARNING);
    if (!showOnShift || WinAPI.INSTANCE.getKeyState(WinAPI.VK_SHIFT) < 0) {
        MessageDialogWithToggle dialog = new MessageDialogWithToggle(
                PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), mEditor.getPartName(),
                InstallOptionsPlugin.getShellImage(),
                InstallOptionsPlugin.getFormattedString("delete.control.action.warning", //$NON-NLS-1$
                        new String[] { section.getName() }), MessageDialog.WARNING,
                new String[] { IDialogConstants.OK_LABEL, IDialogConstants.CANCEL_LABEL }, 0,
                InstallOptionsPlugin.getResourceString("delete.control.warning.toggle.label"), showOnShift); //$NON-NLS-1$
        dialog.open();/*from   w w  w  .  ja v a 2s. c  om*/
        if (dialog.getReturnCode() == IDialogConstants.OK_ID) {
            InstallOptionsPlugin.getDefault().getPreferenceStore().setValue(
                    IInstallOptionsConstants.PREFERENCE_DELETE_CONTROL_WARNING, dialog.getToggleState());
        } else {
            return false;
        }
    }
    iniFile.removeChild(section);
    iniFile.update(INILine.VALIDATE_FIX_ERRORS);
    updateDocument(iniFile, section);
    return true;
}

From source file:net.sf.eclipsensis.installoptions.actions.PreviewAction.java

License:Open Source License

@Override
public void run() {
    if (mEditor != null) {
        Shell shell = mEditor.getSite().getShell();
        if (mEditor.isDirty()) {
            boolean autosaveBeforePreview = mPreferenceStore
                    .getBoolean(IInstallOptionsConstants.PREFERENCE_AUTOSAVE_BEFORE_PREVIEW);
            boolean shouldSave = autosaveBeforePreview;
            if (!shouldSave) {
                MessageDialogWithToggle dialog = new MessageDialogWithToggle(shell,
                        EclipseNSISPlugin.getResourceString("confirm.title"), //$NON-NLS-1$
                        InstallOptionsPlugin.getShellImage(),
                        InstallOptionsPlugin.getResourceString("save.before.preview.confirm"), //$NON-NLS-1$
                        MessageDialog.QUESTION,
                        new String[] { IDialogConstants.OK_LABEL, IDialogConstants.CANCEL_LABEL }, 0,
                        InstallOptionsPlugin.getResourceString("confirm.toggle.message"), false); //$NON-NLS-1$
                dialog.open();//from   w w w .  java  2  s.  c o m
                shouldSave = dialog.getReturnCode() == IDialogConstants.OK_ID;
                if (shouldSave && dialog.getToggleState()) {
                    mPreferenceStore.setValue(IInstallOptionsConstants.PREFERENCE_AUTOSAVE_BEFORE_PREVIEW,
                            true);
                }
            }
            if (shouldSave) {
                ProgressMonitorDialog dialog = new ProgressMonitorDialog(shell);
                dialog.open();
                IProgressMonitor progressMonitor = dialog.getProgressMonitor();
                mEditor.doSave(progressMonitor);
                dialog.close();
                if (progressMonitor.isCanceled()) {
                    return;
                }
            } else {
                return;
            }
        }
        INIFile iniFile = mEditor.getINIFile();
        if (iniFile.hasErrors()) {
            Common.openError(shell, InstallOptionsPlugin.getResourceString("ini.errors.preview.error"), //$NON-NLS-1$
                    InstallOptionsPlugin.getShellImage());
            return;
        }
        INISection settings = iniFile.findSections(InstallOptionsModel.SECTION_SETTINGS)[0];
        INIKeyValue numFields = settings.findKeyValues(InstallOptionsModel.PROPERTY_NUMFIELDS)[0];
        if (Integer.parseInt(numFields.getValue()) <= 0) {
            Common.openError(shell, InstallOptionsPlugin.getResourceString("ini.numfields.preview.error"), //$NON-NLS-1$
                    InstallOptionsPlugin.getShellImage());
        } else {
            IPathEditorInput editorInput = NSISEditorUtilities.getPathEditorInput(mEditor);
            if (editorInput instanceof IFileEditorInput) {
                IFile file = ((IFileEditorInput) editorInput).getFile();
                if (file.exists()) {
                    IPath location = file.getLocation();
                    if (location != null) {
                        doPreview(iniFile, location.toFile());
                    } else {
                        Common.openError(shell, EclipseNSISPlugin.getResourceString("local.filesystem.error"), //$NON-NLS-1$
                                InstallOptionsPlugin.getShellImage());
                    }
                }
            } else if (editorInput != null) {
                doPreview(iniFile, new File(editorInput.getPath().toOSString()));
            }
        }
    }
}

From source file:net.sf.eclipsensis.util.Common.java

License:Open Source License

public static boolean openConfirm(Shell parent, String title, String message, Image icon) {
    MessageDialog dialog = new MessageDialog(parent, title, icon, message, MessageDialog.QUESTION,
            new String[] { IDialogConstants.OK_LABEL, IDialogConstants.CANCEL_LABEL }, 0);
    return dialog.open() == 0;
}