Java Code Examples for com.intellij.ui.components.JBList#setSelectionMode()

The following examples show how to use com.intellij.ui.components.JBList#setSelectionMode() . 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: ActionMacroConfigurationPanel.java    From consulo with Apache License 2.0 6 votes vote down vote up
public ActionMacroConfigurationPanel() {
  myMacrosList = new JBList();
  myMacroActionsList = new JBList();
  myMacrosList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
  myMacroActionsList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

  myMacrosList.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
    public void valueChanged(ListSelectionEvent e) {
      final int selIndex = myMacrosList.getSelectedIndex();
      if (selIndex == -1) {
        ((DefaultListModel)myMacroActionsList.getModel()).removeAllElements();
      }
      else {
        initActionList((ActionMacro)myMacrosModel.getElementAt(selIndex));
      }
    }
  });
}
 
Example 2
Source File: NewItemWithTemplatesPopupPanel.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
private JBList<T> createTemplatesList(@Nonnull ListModel<T> model, ListCellRenderer<T> renderer) {
  JBList<T> list = new JBList<>(model);
  MouseAdapter mouseListener = new MouseAdapter() {
    @Override
    public void mouseClicked(MouseEvent e) {
      if (myApplyAction != null && e.getClickCount() > 1) myApplyAction.consume(e);
    }
  };

  list.addMouseListener(mouseListener);
  list.setCellRenderer(renderer);
  list.setFocusable(false);
  list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

  Border border = JBUI.Borders.merge(JBUI.Borders.emptyLeft(JBUIScale.scale(5)), JBUI.Borders.customLine(JBUI.CurrentTheme.NewClassDialog.bordersColor(), 1, 0, 0, 0), true);
  list.setBorder(border);
  return list;
}
 
Example 3
Source File: CourseTabFactory.java    From tmc-intellij with MIT License 5 votes vote down vote up
public void createCourseSpecificTab(
        ObjectFinder finder,
        ProjectOpener opener,
        String course,
        JTabbedPane tabbedPaneBase,
        CourseAndExerciseManager courseAndExerciseManager) {
    logger.info("Creating course specific tab. @CourseTabFactory");
    final JBScrollPane panel = new JBScrollPane();
    final JBList list = new JBList();
    list.setCellRenderer(new ProjectListRenderer());

    DefaultListModel defaultListModel = new DefaultListModel();
    panel.setBorder(BorderFactory.createTitledBorder(""));

    ProjectListManagerHolder.get()
            .addExercisesToList(finder, course, defaultListModel, courseAndExerciseManager);

    if (defaultListModel.getSize() <= 0) {
        return;
    }

    list.setName(course);
    list.setModel(defaultListModel);

    MouseListener mouseListener = createMouseListenerForWindow(opener, panel, list);
    list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    list.addMouseListener(mouseListener);

    panel.setName(course);
    panel.setViewportView(list);

    ProjectListManagerHolder.get().addList(list);
    tabbedPaneBase.addTab(course, panel);
    tabbedPaneBase.addMouseListener(tabMouseListener(tabbedPaneBase));
    setScrollBarToBottom(course, tabbedPaneBase, panel);
}
 
Example 4
Source File: SubclassTestChooser.java    From intellij with Apache License 2.0 5 votes vote down vote up
static void chooseSubclass(
    ConfigurationContext context,
    PsiClass testClass,
    Consumer<PsiClass> callbackOnClassSelection) {
  List<PsiClass> classes = findTestSubclasses(testClass);
  if (!testClass.hasModifierProperty(PsiModifier.ABSTRACT)) {
    classes.add(testClass);
  }
  if (classes.isEmpty()) {
    return;
  }
  if (classes.size() == 1) {
    callbackOnClassSelection.accept(classes.get(0));
    return;
  }
  PsiClassListCellRenderer renderer = new PsiClassListCellRenderer();
  classes.sort(renderer.getComparator());
  JBList<PsiClass> list = new JBList<>(classes);
  list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
  list.setCellRenderer(renderer);
  JBPopupFactory.getInstance()
      .createListPopupBuilder(list)
      .setTitle("Choose test class to run")
      .setMovable(false)
      .setResizable(false)
      .setRequestFocus(true)
      .setCancelOnWindowDeactivation(false)
      .setItemChoosenCallback(
          () -> callbackOnClassSelection.accept((PsiClass) list.getSelectedValue()))
      .createPopup()
      .showInBestPositionFor(context.getDataContext());
}
 
Example 5
Source File: DataSourceListPanel.java    From intellij-xquery with Apache License 2.0 5 votes vote down vote up
private JBList prepareDataSourcesList(DefaultListModel dataSourcesListModel) {
    final JBList dataSourcesList = new JBList(dataSourcesListModel);
    dataSourcesList.getEmptyText().setText("No data sources defined");
    dataSourcesList.setDragEnabled(false);
    dataSourcesList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    dataSourcesList.setCellRenderer(new DataSourceConfigurationCellRenderer());
    dataSourcesList.addListSelectionListener(getSelectionChangedListener());
    return dataSourcesList;
}
 
Example 6
Source File: UserDefinedLibraryPanel.java    From intellij-xquery with Apache License 2.0 5 votes vote down vote up
private JBList preparePathList(DefaultListModel pathListModel) {
    final JBList pathList = new JBList(pathListModel);
    pathList.getEmptyText().setText("No classpath entries defined");
    pathList.setDragEnabled(false);
    pathList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    pathList.setName(PATH_LIST_NAME);
    return pathList;
}
 
Example 7
Source File: ShowAmbigTreesDialog.java    From intellij-plugin-v4 with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static JBPopup createAmbigTreesPopup(final PreviewState previewState,
                                            final AmbiguityInfo ambigInfo) {
	final JBList list = new JBList("Show all phrase interpretations");
	list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
	JBPopupFactory factory = JBPopupFactory.getInstance();
	PopupChooserBuilder builder = factory.createListPopupBuilder(list);
	builder.setItemChoosenCallback(() -> popupAmbigTreesDialog(previewState, ambigInfo));
	return builder.createPopup();
}
 
Example 8
Source File: ShowAmbigTreesDialog.java    From intellij-plugin-v4 with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static JBPopup createLookaheadTreesPopup(final PreviewState previewState,
                                                final LookaheadEventInfo lookaheadInfo) {
	final JBList list = new JBList("Show all lookahead interpretations");
	list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
	JBPopupFactory factory = JBPopupFactory.getInstance();
	PopupChooserBuilder builder = factory.createListPopupBuilder(list);
	builder.setItemChoosenCallback(() -> popupLookaheadTreesDialog(previewState, lookaheadInfo));

	return builder.createPopup();
}
 
Example 9
Source File: RunConfigurationBeforeRunProvider.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
protected JComponent createCenterPanel() {
  myJBList = new JBList(mySettings);
  myJBList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
  myJBList.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
    @Override
    public void valueChanged(ListSelectionEvent e) {
      Object selectedValue = myJBList.getSelectedValue();
      if (selectedValue instanceof RunnerAndConfigurationSettings) {
        mySelectedSettings = (RunnerAndConfigurationSettings)selectedValue;
      }
      else {
        mySelectedSettings = null;
      }
      setOKActionEnabled(mySelectedSettings != null);
    }
  });
  myJBList.setCellRenderer(new ColoredListCellRenderer() {
    @Override
    protected void customizeCellRenderer(JList list, Object value, int index, boolean selected, boolean hasFocus) {
      if (value instanceof RunnerAndConfigurationSettings) {
        RunnerAndConfigurationSettings settings = (RunnerAndConfigurationSettings)value;
        RunManagerEx runManager = RunManagerEx.getInstanceEx(myProject);
        setIcon(runManager.getConfigurationIcon(settings));
        RunConfiguration configuration = settings.getConfiguration();
        append(configuration.getName(), settings.isTemporary() ? SimpleTextAttributes.GRAY_ATTRIBUTES : SimpleTextAttributes.REGULAR_ATTRIBUTES);
      }
    }
  });
  return new JBScrollPane(myJBList);
}
 
Example 10
Source File: AbstractExternalSystemConfigurable.java    From consulo with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
private void prepareProjectSettings(@Nonnull SystemSettings s) {
  myProjectsModel = new DefaultListModel();
  myProjectsList = new JBList(myProjectsModel);
  myProjectsList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

  addTitle(ExternalSystemBundle.message("settings.title.linked.projects", myExternalSystemId.getReadableName()));
  myComponent.add(new JBScrollPane(myProjectsList), ExternalSystemUiUtil.getFillLineConstraints(1));

  addTitle(ExternalSystemBundle.message("settings.title.project.settings"));
  List<ProjectSettings> settings = ContainerUtilRt.newArrayList(s.getLinkedProjectsSettings());
  myProjectsList.setVisibleRowCount(Math.max(3, Math.min(5, settings.size())));
  ContainerUtil.sort(settings, new Comparator<ProjectSettings>() {
    @Override
    public int compare(ProjectSettings s1, ProjectSettings s2) {
      return getProjectName(s1.getExternalProjectPath()).compareTo(getProjectName(s2.getExternalProjectPath()));
    }
  });

  myProjectSettingsControls.clear();
  for (ProjectSettings setting : settings) {
    ExternalSystemSettingsControl<ProjectSettings> control = createProjectSettingsControl(setting);
    control.fillUi(myComponent, 1);
    myProjectsModel.addElement(getProjectName(setting.getExternalProjectPath()));
    myProjectSettingsControls.add(control);
    control.showUi(false);
  }

  myProjectsList.addListSelectionListener(new ListSelectionListener() {
    @SuppressWarnings("unchecked")
    @Override
    public void valueChanged(ListSelectionEvent e) {
      if (e.getValueIsAdjusting()) {
        return;
      }
      int i = myProjectsList.getSelectedIndex();
      if (i < 0) {
        return;
      }
      if (myActiveProjectSettingsControl != null) {
        myActiveProjectSettingsControl.showUi(false);
      }
      myActiveProjectSettingsControl = myProjectSettingsControls.get(i);
      myActiveProjectSettingsControl.showUi(true);
    }
  });

  
  if (!myProjectsModel.isEmpty()) {
    addTitle(ExternalSystemBundle.message("settings.title.system.settings", myExternalSystemId.getReadableName()));
    myProjectsList.setSelectedIndex(0);
  }
}
 
Example 11
Source File: ChooseOneOrAllRunnable.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public void run() {
  if (myClasses.length == 1) {
    //TODO: cdr this place should produce at least warning
    // selected(myClasses[0]);
    selected((T[])ArrayUtil.toObjectArray(myClasses[0].getClass(), myClasses[0]));
  }
  else if (myClasses.length > 0) {
    PsiElementListCellRenderer<T> renderer = createRenderer();

    Arrays.sort(myClasses, renderer.getComparator());

    if (ApplicationManager.getApplication().isUnitTestMode()) {
      selected(myClasses);
      return;
    }
    Vector<Object> model = new Vector<Object>(Arrays.asList(myClasses));
    model.insertElementAt(CodeInsightBundle.message("highlight.thrown.exceptions.chooser.all.entry"), 0);

    myList = new JBList(model);
    myList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    myList.setCellRenderer(renderer);

    final PopupChooserBuilder builder = new PopupChooserBuilder(myList);
    renderer.installSpeedSearch(builder);

    final Runnable callback = new Runnable() {
      @Override
      public void run() {
        int idx = myList.getSelectedIndex();
        if (idx < 0) return;
        if (idx > 0) {
          selected((T[])ArrayUtil.toObjectArray(myClasses[idx-1].getClass(), myClasses[idx-1]));
        }
        else {
          selected(myClasses);
        }
      }
    };

    ApplicationManager.getApplication().invokeLater(new Runnable() {
      @Override
      public void run() {
        builder.
          setTitle(myTitle).
          setItemChoosenCallback(callback).
          createPopup().
          showInBestPositionFor(myEditor);
      }
    });
  }
}