Java Code Examples for org.eclipse.ui.dialogs.ListDialog#OK

The following examples show how to use org.eclipse.ui.dialogs.ListDialog#OK . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NewMergeFileAssociationWizardPage.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
private void addVariables(Text target, Map bindings) {

        final List variables = new ArrayList(bindings.size());

        ILabelProvider labelProvider = new LabelProvider() {
            public String getText(Object element) {
                return ((StringPair) element).s1
                        + " - " + ((StringPair) element).s2; //$NON-NLS-1$
            }
        };

        IStructuredContentProvider contentsProvider = new IStructuredContentProvider() {
            public Object[] getElements(Object inputElement) {
                return variables.toArray(new StringPair[variables.size()]);
            }

            public void dispose() {
            }

            public void inputChanged(Viewer viewer, Object oldInput,
                    Object newInput) {
            }
        };

        for (Iterator it = bindings.keySet().iterator(); it.hasNext();) {
            StringPair variable = new StringPair();
            variable.s1 = (String) it.next(); // variable
            variable.s2 = (String) bindings.get(variable.s1); // description
            variables.add(variable);
        }

        ListDialog dialog = new ListDialog(this.getShell());
        dialog.setContentProvider(contentsProvider);
        dialog.setAddCancelButton(true);
        dialog.setLabelProvider(labelProvider);
        dialog.setInput(variables);
        dialog.setTitle(Policy
                .bind("DiffMergePreferencePage.addVariableDialogTitle")); //$NON-NLS-1$
        if (dialog.open() != ListDialog.OK)
            return;

        Object[] result = dialog.getResult();

        for (int i = 0; i < result.length; i++) {
            target.insert("${" + ((StringPair) result[i]).s1 + "}"); //$NON-NLS-1$ //$NON-NLS-2$
        }
    }
 
Example 2
Source File: DiffMergePreferencePage.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Add another variable to the given target. The variable is inserted at
 * current position A ListSelectionDialog is shown and the choose the
 * variables to add
 */
private void addVariables(Text target, Map bindings) {

    final List variables = new ArrayList(bindings.size());

    ILabelProvider labelProvider = new LabelProvider() {
        public String getText(Object element) {
            return ((StringPair) element).s1
                    + " - " + ((StringPair) element).s2; //$NON-NLS-1$
        }
    };

    IStructuredContentProvider contentsProvider = new IStructuredContentProvider() {
        public Object[] getElements(Object inputElement) {
            return variables.toArray(new StringPair[variables.size()]);
        }

        public void dispose() {
        }

        public void inputChanged(Viewer viewer, Object oldInput,
                Object newInput) {
        }
    };

    for (Iterator it = bindings.keySet().iterator(); it.hasNext();) {
        StringPair variable = new StringPair();
        variable.s1 = (String) it.next(); // variable
        variable.s2 = (String) bindings.get(variable.s1); // description
        variables.add(variable);
    }

    ListDialog dialog = new ListDialog(this.getShell());
    dialog.setContentProvider(contentsProvider);
    dialog.setAddCancelButton(true);
    dialog.setLabelProvider(labelProvider);
    dialog.setInput(variables);
    dialog.setTitle(Policy
            .bind("DiffMergePreferencePage.addVariableDialogTitle")); //$NON-NLS-1$
    if (dialog.open() != ListDialog.OK)
        return;

    Object[] result = dialog.getResult();

    for (int i = 0; i < result.length; i++) {
        target.insert("${" + ((StringPair) result[i]).s1 + "}"); //$NON-NLS-1$ //$NON-NLS-2$
    }
}
 
Example 3
Source File: MergeFileAssociationPreferencePage.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
private void addVariables(Text target, Map bindings) {

        final List variables = new ArrayList(bindings.size());

        ILabelProvider labelProvider = new LabelProvider() {
            public String getText(Object element) {
                return ((StringPair) element).s1
                        + " - " + ((StringPair) element).s2; //$NON-NLS-1$
            }
        };

        IStructuredContentProvider contentsProvider = new IStructuredContentProvider() {
            public Object[] getElements(Object inputElement) {
                return variables.toArray(new StringPair[variables.size()]);
            }

            public void dispose() {
            }

            public void inputChanged(Viewer viewer, Object oldInput,
                    Object newInput) {
            }
        };

        for (Iterator it = bindings.keySet().iterator(); it.hasNext();) {
            StringPair variable = new StringPair();
            variable.s1 = (String) it.next(); // variable
            variable.s2 = (String) bindings.get(variable.s1); // description
            variables.add(variable);
        }

        ListDialog dialog = new ListDialog(this.getShell());
        dialog.setContentProvider(contentsProvider);
        dialog.setAddCancelButton(true);
        dialog.setLabelProvider(labelProvider);
        dialog.setInput(variables);
        dialog.setTitle(Policy
                .bind("DiffMergePreferencePage.addVariableDialogTitle")); //$NON-NLS-1$
        if (dialog.open() != ListDialog.OK)
            return;

        Object[] result = dialog.getResult();

        for (int i = 0; i < result.length; i++) {
            target.insert("${" + ((StringPair) result[i]).s1 + "}"); //$NON-NLS-1$ //$NON-NLS-2$
        }
    }
 
Example 4
Source File: AbstractInterpreterEditor.java    From Pydev with Eclipse Public License 1.0 4 votes vote down vote up
public void restoreInterpreterInfos(boolean editorChanged,
        Shell shell, IInterpreterManager iInterpreterManager) {
    final Set<String> interpreterNamesToRestore = this.getInterpreterExeOrJarToRestoreAndClear();
    final IInterpreterInfo[] exesList = this.getExesList();

    if (!editorChanged && interpreterNamesToRestore.size() == 0) {
        IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
        SelectionDialog listDialog = AbstractInterpreterPreferencesPage.createChooseIntepreterInfoDialog(
                workbenchWindow, exesList,
                "Select interpreters to be restored", true);

        int open = listDialog.open();
        if (open != ListDialog.OK) {
            return;
        }
        Object[] result = listDialog.getResult();
        if (result == null || result.length == 0) {
            return;

        }
        for (Object o : result) {
            interpreterNamesToRestore.add(((IInterpreterInfo) o).getExecutableOrJar());
        }

    }

    //this is the default interpreter
    ProgressMonitorDialog monitorDialog = new AsynchronousProgressMonitorDialog(shell);
    monitorDialog.setBlockOnOpen(false);

    try {
        IRunnableWithProgress operation = new IRunnableWithProgress() {

            @Override
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                monitor.beginTask("Restoring PYTHONPATH", IProgressMonitor.UNKNOWN);
                try {
                    pushExpectedSetInfos();
                    //clear all but the ones that appear
                    iInterpreterManager.setInfos(exesList, interpreterNamesToRestore, monitor);
                } finally {
                    popExpectedSetInfos();
                    monitor.done();
                }
            }
        };

        monitorDialog.run(true, true, operation);

    } catch (Exception e) {
        Log.log(e);
    }
}
 
Example 5
Source File: PySelectInterpreter.java    From Pydev with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public void run(IAction action) {
    try {
        PyEdit editor = getPyEdit();
        IPythonNature nature = editor.getPythonNature();
        if (nature != null) {
            IInterpreterManager interpreterManager = nature.getRelatedInterpreterManager();

            final IInterpreterInfo[] interpreterInfos = interpreterManager.getInterpreterInfos();
            if (interpreterInfos == null || interpreterInfos.length == 0) {
                PyDialogHelpers.openWarning("No interpreters available",
                        "Unable to change default interpreter because no interpreters are available (add more interpreters in the related preferences page).");
                return;
            }
            if (interpreterInfos.length == 1) {
                PyDialogHelpers.openWarning("Only 1 interpreters available",
                        "Unable to change default interpreter because only 1 interpreter is configured (add more interpreters in the related preferences page).");
                return;
            }
            // Ok, more than 1 found.
            IWorkbenchWindow workbenchWindow = EditorUtils.getActiveWorkbenchWindow();
            Assert.isNotNull(workbenchWindow);
            SelectionDialog listDialog = AbstractInterpreterPreferencesPage.createChooseIntepreterInfoDialog(
                    workbenchWindow, interpreterInfos,
                    "Select interpreter to be made the default.", false);

            int open = listDialog.open();
            if (open != ListDialog.OK || listDialog.getResult().length != 1) {
                return;
            }
            Object[] result = listDialog.getResult();
            if (result == null || result.length == 0) {
                return;

            }
            final IInterpreterInfo selectedInterpreter = ((IInterpreterInfo) result[0]);
            if (selectedInterpreter != interpreterInfos[0]) {
                // Ok, some interpreter (which wasn't already the default) was selected.
                Arrays.sort(interpreterInfos, (a, b) -> {
                    if (a == selectedInterpreter) {
                        return -1;
                    }
                    if (b == selectedInterpreter) {
                        return 1;
                    }
                    return 0; // Don't change order for the others.
                });

                Shell shell = EditorUtils.getShell();

                setInterpreterInfosWithProgressDialog(interpreterManager, interpreterInfos, shell);
            }
        }
    } catch (Exception e) {
        Log.log(e);
    }
}