/** Creates a dialog that'll choose from a list of interpreter infos. */
  public static SelectionDialog createChooseIntepreterInfoDialog(
      IWorkbenchWindow workbenchWindow,
      IInterpreterInfo[] interpreters,
      String msg,
      boolean selectMultiple) {

    IStructuredContentProvider contentProvider =
        new IStructuredContentProvider() {

          public Object[] getElements(Object inputElement) {
            if (inputElement instanceof IInterpreterInfo[]) {
              return (IInterpreterInfo[]) inputElement;
            }
            return new Object[0];
          }

          public void dispose() {}

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

    LabelProvider labelProvider =
        new LabelProvider() {
          public Image getImage(Object element) {
            return PydevPlugin.getImageCache().get(UIConstants.PY_INTERPRETER_ICON);
          }

          public String getText(Object element) {
            if (element != null && element instanceof IInterpreterInfo) {
              IInterpreterInfo info = (IInterpreterInfo) element;
              return info.getNameForUI();
            }
            return super.getText(element);
          }
        };

    SelectionDialog selectionDialog;
    if (selectMultiple) {
      selectionDialog =
          new ListSelectionDialog(
              workbenchWindow.getShell(), interpreters, contentProvider, labelProvider, msg);
    } else {

      ListDialog listDialog = new ListDialog(workbenchWindow.getShell());

      listDialog.setContentProvider(contentProvider);
      listDialog.setLabelProvider(labelProvider);
      listDialog.setInput(interpreters);
      listDialog.setMessage(msg);
      selectionDialog = listDialog;
    }
    return selectionDialog;
  }
Ejemplo n.º 2
0
  public void prompt(Shell shell) {
    ListDialog dialog =
        new ListDialog(shell) {
          @Override
          protected int getTableStyle() {
            return super.getTableStyle() - SWT.SINGLE + SWT.MULTI;
          }
        };
    dialog.setTitle(Messages.RemoveFilterDialog_0);
    dialog.setMessage(Messages.RemoveFilterDialog_1);
    dialog.setAddCancelButton(true);
    dialog.setLabelProvider(
        new LabelProvider() {
          @Override
          public String getText(Object element) {
            return (String) element;
          }
        });
    dialog.setContentProvider(
        new IStructuredContentProvider() {
          public Object[] getElements(Object inputElement) {
            return (Object[]) inputElement;
          }

          public void dispose() {}

          public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {}
        });
    String[] filterPatterns = filter.getFilterPatterns();
    Arrays.sort(filterPatterns);
    dialog.setInput(filterPatterns);
    dialog.open();
    Object[] selected = dialog.getResult();
    if (selected == null) return;

    filter.removeFilterPatterns(selected);
  }