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:com.nokia.tools.s60.editor.actions.ThreePieceConvertAction.java

License:Open Source License

@Override
protected void doRun(Object element) {
    IContentData data = getContentData(element);
    if (data == null) {
        return;/* w w  w  . j  a v a 2  s  .  com*/
    }
    if (type == TYPE_CONVERT2SINGLE) {

        IPreferenceStore iPreferenceStore = UtilsPlugin.getDefault().getPreferenceStore();
        boolean ask = !iPreferenceStore.getBoolean(IMediaConstants.PREF_NINE_PIECE_2SINGLE_ASK);

        boolean replaceGfx = iPreferenceStore.getBoolean(IMediaConstants.PREF_NINE_PIECE_2SINGLE);

        if (ask) {
            int result = IDialogConstants.YES_ID;

            ISkinnableEntityAdapter ska = (ISkinnableEntityAdapter) data
                    .getAdapter(ISkinnableEntityAdapter.class);
            boolean isElementSkinned = ska.isSkinned();

            if (isElementSkinned) {
                ThreePieceOperationConfirmDialog dialog = new ThreePieceOperationConfirmDialog(
                        PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
                        ThreePieceOperationConfirmDialog.TYPE_2SINGLE);
                result = dialog.open();
            }
            if (result == IDialogConstants.OK_ID)
                replaceGfx = true;
            else
                return; // cancel pressed
        }

        if (ask && iPreferenceStore.getBoolean(IMediaConstants.PREF_NINE_PIECE_2SINGLE_ASK)) {
            // user selects to remeber settings this time - store
            // selected option
            iPreferenceStore.setValue(IMediaConstants.PREF_NINE_PIECE_2SINGLE, replaceGfx);
        }

        EditPart ep = getEditPart(element);
        // special way of update / undo / redo
        Convert2SingleBitmapCommand cmd = new Convert2SingleBitmapCommand(getContentData(element), ep,
                replaceGfx);
        execute(cmd, ep);
    } else {
        if (type == TYPE_CONVERT2THREE) {

            IPreferenceStore iPreferenceStore = UtilsPlugin.getDefault().getPreferenceStore();
            boolean ask = !iPreferenceStore.getBoolean(IMediaConstants.PREF_SINGLE_PIECE_2NINE_ASK);

            boolean fillParts = iPreferenceStore.getBoolean(IMediaConstants.PREF_SINGLE_PIECE_2NINE);

            if (ask) {
                ThreePieceOperationConfirmDialog dialog = new ThreePieceOperationConfirmDialog(
                        PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
                        ElevenPieceOperationConfirmDialog.TYPE_2ELEVEN);
                int result = dialog.open();
                if (result == IDialogConstants.OK_ID)
                    fillParts = true;
                else
                    return; // cancel pressed
            }

            if (ask && iPreferenceStore.getBoolean(IMediaConstants.PREF_SINGLE_PIECE_2NINE_ASK)) {
                // user selects to remeber settings this time - store
                // selected option
                iPreferenceStore.setValue(IMediaConstants.PREF_SINGLE_PIECE_2NINE, fillParts);
            }

            EditPart ep = getEditPart(element);
            // special way of update / undo / redo
            Convert2ThreeBitmapCommand cmd = new Convert2ThreeBitmapCommand(data, ep, fillParts);
            execute(cmd, ep);
        }
    }
}

From source file:com.nokia.tools.s60.ide.PerspectiveUtil.java

License:Open Source License

private static boolean shouldSwitchperspective() {
    String str = S60WorkspacePlugin.getDefault().getPreferenceStore()
            .getString(IS60IDEConstants.PREF_ACTIVATE_PERSPECTIVE);
    if (str.equals(MessageDialogWithToggle.ALWAYS))
        return true;
    else if (str.equals(MessageDialogWithToggle.NEVER))
        return false;
    MessageDialogWithToggle dialog = MessageDialogWithToggle.openYesNoQuestion(
            getActiveWorkbenchWindow().getShell(), S60IDEMessages.ConfirmPerspectiveSwitchTitle,
            S60IDEMessages.InfoWhyToLounchPerspective, null, false,
            S60WorkspacePlugin.getDefault().getPreferenceStore(), IS60IDEConstants.PREF_ACTIVATE_PERSPECTIVE);
    boolean bret = (dialog.getReturnCode() == IDialogConstants.YES_ID);
    return bret;/* w ww . ja  v a  2s .  com*/
}

From source file:com.nokia.tracebuilder.view.TraceViewDialogs.java

License:Open Source License

public int showCheckList(CheckListDialogParameters parameters) {
    Shell shell = view.getShell();//  www  . j a  va2 s .  c  o  m
    int ret = CANCEL;
    if (shell != null) {
        CheckListSelectionDialog dlg = new CheckListSelectionDialog(shell, parameters);
        int result = dlg.open();
        if (result == IDialogConstants.OK_ID || result == IDialogConstants.YES_ID) {
            ret = OK;
        }
    }
    return ret;
}

From source file:com.safi.workshop.sqlexplorer.connections.actions.CloseAllConnectionsAction.java

License:Open Source License

@Override
public void run() {
    if (!SafiServerPlugin.getDefault().isConnected()) {
        MessageDialog.openError(Display.getCurrent().getActiveShell(), "Not Connected",
                "You must be connected to a SafiServer instance to access this feature");
        return;/*from w  ww. ja v a  2s  .  c o  m*/
    }
    boolean confirm = AsteriskDiagramEditorPlugin.getDefault().getPluginPreferences()
            .getBoolean(IConstants.CONFIRM_BOOL_CLOSE_ALL_CONNECTIONS);
    if (confirm) {
        MessageDialogWithToggle dialog = MessageDialogWithToggle.openYesNoQuestion(
                getView().getSite().getShell(),
                Messages.getString("ConnectionsView.Actions.CloseAll.Confirm.Title"),
                Messages.getString("ConnectionsView.Actions.CloseAll.Confirm.Message"),
                Messages.getString("ConnectionsView.Actions.CloseAll.Confirm.Toggle"), false, null, null);

        if (dialog.getToggleState() && dialog.getReturnCode() == IDialogConstants.YES_ID)
            AsteriskDiagramEditorPlugin.getDefault().getPluginPreferences()
                    .setValue(IConstants.CONFIRM_BOOL_CLOSE_ALL_CONNECTIONS, false);
        if (dialog.getReturnCode() != IDialogConstants.YES_ID)
            return;
    }

    Set<SQLConnection> connections = getView().getSelectedConnections(true);
    for (SQLConnection connection : connections) {
        synchronized (connection) {
            Session session = connection.getSession();
            if (session != null) {
                synchronized (session) {
                    if (!session.isConnectionInUse())
                        session.disposeConnection();
                }
            } else
                connection.getUser().releaseFromPool(connection);
        }
    }

    setEnabled(false);
    getView().refresh();
}

From source file:com.safi.workshop.sqlexplorer.connections.actions.CloseConnectionAction.java

License:Open Source License

@Override
public void run() {
    if (!SafiServerPlugin.getDefault().isConnected()) {
        MessageDialog.openError(Display.getCurrent().getActiveShell(), "Not Connected",
                "You must be connected to a SafiServer instance to access this feature");
        return;//from   www.ja  v a  2  s .co  m
    }
    boolean confirm = AsteriskDiagramEditorPlugin.getDefault().getPluginPreferences()
            .getBoolean(IConstants.CONFIRM_BOOL_CLOSE_CONNECTION);
    for (SQLConnection connection : getView().getSelectedConnections(false)) {
        Session session = connection.getSession();
        if (session != null && !session.isConnectionInUse()) {
            if (confirm) {
                MessageDialogWithToggle dialog = MessageDialogWithToggle.openYesNoQuestion(
                        getView().getSite().getShell(),
                        Messages.getString("ConnectionsView.Actions.CloseAll.Confirm.Title"),
                        Messages.getString("ConnectionsView.Actions.CloseAll.Confirm.Message"),
                        Messages.getString("ConnectionsView.Actions.CloseAll.Confirm.Toggle"), false, null,
                        null);

                if (dialog.getToggleState() && dialog.getReturnCode() == IDialogConstants.YES_ID)
                    AsteriskDiagramEditorPlugin.getDefault().getPluginPreferences()
                            .setValue(IConstants.CONFIRM_BOOL_CLOSE_CONNECTION, false);
                if (dialog.getReturnCode() != IDialogConstants.YES_ID)
                    return;
            }
            session.disposeConnection();
        } else if (session == null)
            connection.getUser().releaseFromPool(connection);
    }

    getView().refresh();
}

From source file:com.safi.workshop.sqlexplorer.dialogs.SaveOutsideProjectDlg.java

License:Open Source License

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

From source file:com.safi.workshop.sqlexplorer.plugin.editors.SQLEditor.java

License:Open Source License

/**
 * Implementation for save-as; returns true if successfull, false if not (i.e. the user
 * cancelled the dialog)/*from w  w  w .  j a v  a 2 s. c o m*/
 * 
 * @return true if saved, false if cancelled
 */
public boolean doSave(boolean saveAs, IProgressMonitor monitor) {

    IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
    boolean haveProjects = projects != null && projects.length > 0;
    IEditorInput input = getEditorInput();

    boolean saveInsideProject = true;
    File file = null;
    if (input instanceof SQLEditorInput) {
        SQLEditorInput seInput = (SQLEditorInput) input;
        file = seInput.getFile();
    }

    // If we have a file, then we already have a filename outside of the project;
    // but if we're doing a save-as then recheck with the user
    if (file != null && !saveAs)
        saveInsideProject = false;

    // Either we're doing a save on a file outside a project or we're doing a save-as
    else if (input instanceof SQLEditorInput) {
        IConstants.Confirm confirm = SQLExplorerPlugin.getConfirm(IConstants.CONFIRM_YNA_SAVING_INSIDE_PROJECT);

        // If we're supposed to ask the user...
        if (confirm == IConstants.Confirm.ASK) {
            // Build up the message to ask
            String msg = Messages.getString("Confirm.SaveInsideProject.Intro") + "\n\n";
            if (!haveProjects)
                msg = msg + Messages.getString("Confirm.SaveInsideProject.NoProjectsConfigured") + "\n\n";
            msg = msg + Messages.getString("Confirm.SaveInsideProject.SaveInProject");

            // Ask them
            MessageDialogWithToggle dialog = MessageDialogWithToggle.openYesNoCancelQuestion(
                    getSite().getShell(), Messages.getString("SQLEditor.SaveAsDialog.Title"), msg,
                    Messages.getString("Confirm.SaveInsideProject.Toggle"), false, null, null);
            if (dialog.getReturnCode() == IDialogConstants.CANCEL_ID)
                return false;

            // If they turned on the toggle ("Use this answer in the future"), update the
            // preferences
            if (dialog.getToggleState()) {
                confirm = dialog.getReturnCode() == IDialogConstants.YES_ID ? IConstants.Confirm.YES
                        : IConstants.Confirm.NO;
                SQLExplorerPlugin.getDefault().getPreferenceStore()
                        .setValue(IConstants.CONFIRM_YNA_SAVING_INSIDE_PROJECT, confirm.toString());
            }

            // Whether to save inside or outside
            saveInsideProject = dialog.getReturnCode() == IDialogConstants.YES_ID;
        } else
            saveInsideProject = confirm == IConstants.Confirm.YES;
    }

    // Saving inside a project - convert SQLEditorInput into a Resource by letting
    // TextEditor do the work for us
    if (saveInsideProject) {
        if (!haveProjects) {
            MessageDialog.openError(getSite().getShell(), Messages.getString("Confirm.SaveInsideProject.Title"),
                    Messages.getString("Confirm.SaveInsideProject.CreateAProject"));
            return false;
        }
        if (input instanceof SQLEditorInput)
            saveAs = true;

        // Save it and use their EditorInput
        if (saveAs)
            textEditor.doSaveAs();
        else {
            if (monitor == null)
                monitor = textEditor.getProgressMonitor();

            textEditor.doSave(monitor);
        }
        if (input.equals(textEditor.getEditorInput()))
            return false;
        input = textEditor.getEditorInput();
        setInput(input);

        // Update the display
        setPartName(input.getName());
        setTitleToolTip(input.getToolTipText());

    } else {
        try {
            if (file == null || saveAs) {
                FileDialog dialog = new FileDialog(getSite().getShell(), SWT.SAVE);
                dialog.setText(Messages.getString("SQLEditor.SaveAsDialog.Title"));
                dialog.setFilterExtensions(SUPPORTED_FILETYPES);
                dialog.setFilterNames(SUPPORTED_FILETYPES);
                dialog.setFileName("*.sql");

                String path = dialog.open();
                if (path == null)
                    return false;
                file = new File(path);
            }

            // Save it
            saveToFile(file);

            // Update the editor input
            input = new SQLEditorInput(file);
            setInput(input);
            setPartName(input.getName());
            setTitleToolTip(input.getToolTipText());

        } catch (IOException e) {
            SQLExplorerPlugin.error("Couldn't save sql", e);
            MessageDialog.openError(getSite().getShell(), Messages.getString("SQLEditor.SaveAsDialog.Error"),
                    e.getMessage());
            return false;
        }

    }

    setIsDirty(textEditor.isDirty());
    return true;
}

From source file:com.siteview.mde.internal.ui.preferences.TargetPlatformPreferencePage.java

License:Open Source License

/**
 * Removes the selected targets// w  ww. j a  v a 2 s.c  o m
 */
private void handleRemove() {
    IStructuredSelection selection = (IStructuredSelection) fTableViewer.getSelection();
    if (!selection.isEmpty()) {
        List selected = selection.toList();

        // If we are going to remove a workspace file, prompt to ask the user first
        boolean isWorkspace = false;
        for (Iterator iterator = selected.iterator(); iterator.hasNext();) {
            ITargetDefinition currentTarget = (ITargetDefinition) iterator.next();
            if (currentTarget.getHandle() instanceof WorkspaceFileTargetHandle) {
                isWorkspace = true;
                break;
            }
        }
        if (isWorkspace) {
            MDEPreferencesManager preferences = new MDEPreferencesManager(IMDEUIConstants.PLUGIN_ID);
            String choice = preferences.getString(IPreferenceConstants.PROP_PROMPT_REMOVE_TARGET);
            if (!MessageDialogWithToggle.ALWAYS.equalsIgnoreCase(choice)) {
                MessageDialogWithToggle dialog = MessageDialogWithToggle.openYesNoQuestion(getShell(),
                        MDEUIMessages.TargetPlatformPreferencePage2_19,
                        MDEUIMessages.TargetPlatformPreferencePage2_20,
                        MDEUIMessages.TargetPlatformPreferencePage2_21, false,
                        MDEPlugin.getDefault().getPreferenceStore(),
                        IPreferenceConstants.PROP_PROMPT_REMOVE_TARGET);
                preferences.savePluginPreferences();
                if (dialog.getReturnCode() != IDialogConstants.YES_ID) {
                    return;
                }
            }
        }

        if (fActiveTarget != null && selected.contains(fActiveTarget)) {
            fActiveTarget = null;
            setMessage(MDEUIMessages.TargetPlatformPreferencePage2_22, IMessageProvider.INFORMATION);
        }
        fRemoved.addAll(selected);
        fTargets.removeAll(selected);
        // Quick hack because the first refresh loses the checkedState, which is being used to bold the active target
        fTableViewer.refresh(false);
        fTableViewer.refresh(true);
    }
}

From source file:com.skratchdot.electribe.model.esx.editor.handlers.ExportHandler.java

License:Open Source License

/**
 * Attempts to export .wav files to the given directory. It will export
 * all samples that are being used in the workspace.
 * @param workbench//from www . j a v a 2 s  . c  o m
 * @param directory A valid, non-null path to the directory in which .wav files will be exported to
 */
public static void exportAudioFilesToDirectory(IWorkbench workbench, String directory) {
    IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
    IWorkbenchPage page = window.getActivePage();
    IEditorPart editor = page.getActiveEditor();

    // We've chosen to load a few audio files into the active editor
    if (directory != null) {
        // If the active editor is an EsxEditor
        if (editor != null && editor instanceof EsxEditor) {

            // Get our EsxFile
            EditingDomain editingDomain = ((EsxEditor) editor).getEditingDomain();
            Resource resource = (Resource) editingDomain.getResourceSet().getResources().get(0);
            Object rootObject = resource.getContents().get(0);
            if (rootObject instanceof EsxFile) {
                EsxFile esxFile = (EsxFile) rootObject;

                // These will be used if we bring up the overwrite files prompt
                boolean rememberThisDecision = false;
                boolean overwriteAllFiles = false;
                boolean writeCurrentFile = false;

                for (int i = 0; i < esxFile.getSamples().size(); i++) {
                    Sample currentSample = esxFile.getSamples().get(i);
                    if (currentSample.isEmpty() == false) {

                        // Setup Filename
                        String filename = ""
                                + EsxPreferenceStore.getString(EsxPreferenceNames.EXPORT_FILENAME_FORMAT)
                                + ".wav";
                        filename = filename.replace("%s%", currentSample.getName().trim());
                        filename = filename.replace("%n%", currentSample.getSampleNumberCurrent().getLiteral());
                        filename = filename.replaceAll("[^a-zA-Z0-9 _.-]", "_");

                        File file = new File(directory + File.separator + filename);
                        writeCurrentFile = true;

                        // Check if we need to overwrite the file
                        if (file.exists()) {
                            if (rememberThisDecision) {
                                writeCurrentFile = overwriteAllFiles;
                            } else {
                                MessageDialogWithToggle dialog = MessageDialogWithToggle.openYesNoQuestion(
                                        window.getShell(),
                                        EsxEditorUtil.getString("_UI_Export_Samples_Overwrite_Title"),
                                        EsxEditorUtil.getString("_UI_Export_Samples_Overwrite_Message",
                                                file.getAbsoluteFile()),
                                        EsxEditorUtil.getString("_UI_Export_Samples_Overwrite_Toggle"),
                                        rememberThisDecision, null, null);
                                writeCurrentFile = dialog.getReturnCode() == IDialogConstants.YES_ID;
                                if (dialog.getToggleState() == true) {
                                    rememberThisDecision = true;
                                    overwriteAllFiles = writeCurrentFile;
                                }
                            }
                        }

                        if (writeCurrentFile == true) {
                            try {
                                currentSample.export(file);
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        }
                    }
                }
            }
        }
    }
}

From source file:com.trivadis.loganalysis.ui.internal.Perspective.java

License:Open Source License

private static Selection getConfirmCancel(MessageDialogWithToggle dialog) {
    return (dialog.getReturnCode() == IDialogConstants.YES_ID) ? Selection.ALWAYS : Selection.NEVER;
}