Java Code Examples for com.intellij.ui.components.JBList

The following examples show how to use com.intellij.ui.components.JBList. These examples are extracted from open source projects. 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 Project: PackageTemplates   Source File: LibraryDialog.java    License: Apache License 2.0 6 votes vote down vote up
private void createBinaryFileList() {
    ArrayList<Pair<String, BinaryFileLibModel>> libModels = new ArrayList<>();
    libModels.add(new Pair<>("key1", new BinaryFileLibModel("C:/foo/bar/path1")));
    libModels.add(new Pair<>("key2", new BinaryFileLibModel("C:/foo/bar/path2")));
    libModels.add(new Pair<>("key3", new BinaryFileLibModel("C:/foo/bar/path3")));


    listBinaryFiles = new JBList<>(libModels);
    listBinaryFiles.setCellRenderer((list, value, index, isSelected, cellHasFocus) -> {
        return new JBLabel(value.first);
    });
    listBinaryFiles.addListSelectionListener(arg0 -> {
        if (!arg0.getValueIsAdjusting()) {
            presenter.onBinaryFileSelected(listBinaryFiles.getSelectedValue());
        }
    });

}
 
Example 2
Source Project: tmc-intellij   Source File: ProjectListManager.java    License: MIT License 6 votes vote down vote up
public void refreshCourse(String course) {
    logger.info("Refreshing course {}. @ProjectListManager", course);
    List<JBList> list = currentListElements.get(course);
    if (list == null) {
        return;
    }

    for (JBList jbList : list) {
        if (jbList == null || !jbList.getName().equals(course)) {
            continue;
        }
        DefaultListModel model = (DefaultListModel) jbList.getModel();
        model.removeAllElements();
        addExercisesToList(new ObjectFinder(), course, model, new CourseAndExerciseManager());
        jbList.setModel(model);
    }
    refreshAllCourses();
}
 
Example 3
Source Project: tmc-intellij   Source File: CourseTabFactory.java    License: MIT License 6 votes vote down vote up
private void addRightMouseButtonFunctionality(MouseEvent mouseEvent,
                                              final JBList list,
                                              JBScrollPane panel) {

    logger.info("Adding functionality for right mouse button. @CourseTabFactory");
    if (!SwingUtilities.isRightMouseButton(mouseEvent)) {
        return;
    }

    int index = list.locationToIndex(mouseEvent.getPoint());
    list.setSelectedIndex(index);
    PopUpMenu menu = new PopUpMenu();
    JBMenuItem openInExplorer = new JBMenuItem("Open path");
    final Object selectedItem = list.getSelectedValue();
    JBMenuItem deleteFolder = new JBMenuItem("Delete folder");

    openInExplorer.addActionListener(createOpenInExploreListener(list, selectedItem));

    deleteFolder.addActionListener(createDeleteButtonActionListener(list, selectedItem));

    menu.add(openInExplorer);
    menu.add(deleteFolder);
    menu.show(panel, mouseEvent.getX(), mouseEvent.getY());
    menu.setLocation(mouseEvent.getXOnScreen(), mouseEvent.getYOnScreen());

}
 
Example 4
Source Project: tmc-intellij   Source File: OrganizationCard.java    License: MIT License 6 votes vote down vote up
public OrganizationCard(Organization organization, JBList parent) {
    this.initComponents();

    this.organization = organization;
    this.parent = parent;

    this.organizationName.setText(organization.getName());
    String information = organization.getInformation();
    if (information.length() > 188) {
        information = information.substring(0, 187) + "...";
    }
    this.organizationInformation.setText(information);
    this.organizationSlug.setText("/" + organization.getSlug());

    setLogo();
}
 
Example 5
Source Project: intellij   Source File: AddSourceToProjectDialog.java    License: Apache License 2.0 6 votes vote down vote up
AddSourceToProjectDialog(Project project, List<TargetInfo> targets) {
  super(project, /* canBeParent= */ true, IdeModalityType.MODELESS);
  this.project = project;

  mainPanel = new JPanel(new VerticalLayout(12));

  JList<TargetInfo> targetsComponent = new JBList<>(targets);
  if (targets.size() == 1) {
    targetsComponent.setSelectedIndex(0);
  }
  this.targetsComponent = targetsComponent;

  setTitle("Add Source File to Project");
  setupUi();
  init();
}
 
Example 6
Source Project: GitToolBox   Source File: GtRepoChooser.java    License: Apache License 2.0 6 votes vote down vote up
GtRepoChooser(@NotNull Project project, @Nullable Component parentComponent) {
  super(project, parentComponent, false, IdeModalityType.PROJECT);
  this.project = project;
  repoList = new JBList<>();
  repoList.setCellRenderer(new ColoredListCellRenderer<GitRepository>() {
    @Override
    protected void customizeCellRenderer(@NotNull JList<? extends GitRepository> list, GitRepository value, int index,
                                         boolean selected, boolean hasFocus) {
      append(GtUtil.name(value));
      StringBand url = new StringBand(" (");
      url.append(value.getRoot().getPresentableUrl());
      url.append(")");
      append(url.toString(), SimpleTextAttributes.GRAYED_ATTRIBUTES);
    }
  });
  JBScrollPane scrollPane = new JBScrollPane(repoList);
  centerPanel = JBUI.Panels.simplePanel().addToCenter(scrollPane);
  centerPanel.setPreferredSize(JBUI.size(400, 300));
  setTitle(ResBundle.message("configurable.prj.autoFetch.exclusions.add.title"));
  init();
}
 
Example 7
private JBList createJBList(DefaultListModel pluginsModel) {
	JBList jbList = new JBList(pluginsModel);
	jbList.setCellRenderer(new DefaultListCellRenderer() {
		@Override
		public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected,
													  boolean cellHasFocus) {
			final Component comp = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
			CustomActionModel goal = (CustomActionModel) value;
			setText(goal.getName());
			return comp;
		}
	});
	jbList.setDragEnabled(true);
	jbList.setDropMode(DropMode.INSERT);
	jbList.setTransferHandler(new MyListDropHandler(jbList));

	new MyDragListener(jbList);
	return jbList;
}
 
Example 8
Source Project: intellij-haxe   Source File: HaxeRestoreReferencesDialog.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected JComponent createCenterPanel() {
  final JPanel panel = new JPanel(new BorderLayout(UIUtil.DEFAULT_HGAP, UIUtil.DEFAULT_VGAP));
  myList = new JBList((Object[])myNamedElements);
  myList.setCellRenderer(new FQNameCellRenderer());
  panel.add(ScrollPaneFactory.createScrollPane(myList), BorderLayout.CENTER);

  panel.add(new JBLabel(CodeInsightBundle.message("dialog.paste.on.import.text"), SMALL, BRIGHTER), BorderLayout.NORTH);

  final JPanel buttonPanel = new JPanel(new VerticalFlowLayout());
  final JButton okButton = new JButton(CommonBundle.getOkButtonText());
  getRootPane().setDefaultButton(okButton);
  buttonPanel.add(okButton);
  final JButton cancelButton = new JButton(CommonBundle.getCancelButtonText());
  buttonPanel.add(cancelButton);

  panel.setPreferredSize(new Dimension(500, 400));

  return panel;
}
 
Example 9
Source Project: consulo   Source File: CommonProgramParametersPanel.java    License: Apache License 2.0 6 votes vote down vote up
@Deprecated // use MacroComboBoxWithBrowseButton instead
protected JComponent createComponentWithMacroBrowse(@Nonnull final TextFieldWithBrowseButton textAccessor) {
  final FixedSizeButton button = new FixedSizeButton(textAccessor);
  button.setIcon(AllIcons.RunConfigurations.Variables);
  button.addActionListener(new ActionListener() {
    @Override
    public void actionPerformed(ActionEvent e) {
      //noinspection unchecked
      final JList list = new JBList(myWorkingDirectoryComboBox.getChildComponent().getModel());
      JBPopupFactory.getInstance().createListPopupBuilder(list).setItemChoosenCallback(() -> {
        final Object value = list.getSelectedValue();
        if (value instanceof String) {
          textAccessor.setText((String)value);
        }
      }).setMovable(false).setResizable(false).createPopup().showUnderneathOf(button);
    }
  });

  JPanel panel = new JPanel(new BorderLayout());
  panel.add(textAccessor, BorderLayout.CENTER);
  panel.add(button, BorderLayout.EAST);
  return panel;
}
 
Example 10
Source Project: MavenHelper   Source File: ApplicationSettingsForm.java    License: Apache License 2.0 6 votes vote down vote up
private JBList createJBList(DefaultListModel pluginsModel) {
	JBList jbList = new JBList(pluginsModel);
	jbList.setCellRenderer(new DefaultListCellRenderer() {
		@Override
		public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected,
													  boolean cellHasFocus) {
			final Component comp = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
			Goal goal = (Goal) value;

			setText(goal.getPresentableName());
			return comp;
		}
	});
	jbList.setDragEnabled(true);
	jbList.setDropMode(DropMode.INSERT);
	jbList.setTransferHandler(new MyListDropHandler(jbList));

	new MyDragListener(jbList);
	return jbList;
}
 
Example 11
Source Project: consulo   Source File: RecentChangesPopup.java    License: Apache License 2.0 6 votes vote down vote up
public void show() {
  List<RecentChange> cc = myVcs.getRecentChanges(myGateway.createTransientRootEntry());
  if (cc.isEmpty()) {
    Messages.showInfoMessage(myProject, LocalHistoryBundle.message("recent.changes.to.changes"), getTitle());
    return;
  }

  final JList list = new JBList(createModel(cc));
  list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
  list.setCellRenderer(new RecentChangesListCellRenderer());

  Runnable selectAction = new Runnable() {
    public void run() {
      RecentChange c = (RecentChange)list.getSelectedValue();
      showRecentChangeDialog(c);
    }
  };

  showList(list, selectAction);
}
 
Example 12
Source Project: consulo   Source File: SchemesToImportPopup.java    License: Apache License 2.0 6 votes vote down vote up
public void show(Collection<T> schemes) {
  if (schemes.isEmpty()) {
    Messages.showMessageDialog("There are no available schemes to import", "Import", Messages.getWarningIcon());
    return;
  }

  final JList list = new JBList(new CollectionListModel<T>(schemes));
  list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
  list.setCellRenderer(new SchemesToImportListCellRenderer());

  Runnable selectAction = new Runnable() {
    @Override
    public void run() {
      onSchemeSelected((T)list.getSelectedValue());
    }
  };

  showList(list, selectAction);
}
 
Example 13
Source Project: consulo   Source File: FileChooserDialogImpl.java    License: Apache License 2.0 6 votes vote down vote up
private void showRecentFilesPopup() {
  final JBList files = new JBList(getRecentFiles()) {
    @Override
    public Dimension getPreferredSize() {
      return new Dimension(myPathTextField.getField().getWidth(), super.getPreferredSize().height);
    }
  };
  files.setCellRenderer(new ColoredListCellRenderer() {
    @Override
    protected void customizeCellRenderer(JList list, Object value, int index, boolean selected, boolean hasFocus) {
      final String path = value.toString();
      append(path);
      final VirtualFile file = LocalFileSystem.getInstance().findFileByIoFile(new File(path));
      if (file != null) {
        setIcon(VfsIconUtil.getIcon(file, Iconable.ICON_FLAG_READ_STATUS, null));
      }
    }
  });
  JBPopupFactory.getInstance().createListPopupBuilder(files).setItemChoosenCallback(new Runnable() {
    @Override
    public void run() {
      myPathTextField.getField().setText(files.getSelectedValue().toString());
    }
  }).createPopup().showUnderneathOf(myPathTextField.getField());
}
 
Example 14
Source Project: consulo   Source File: RecentLocationsAction.java    License: Apache License 2.0 6 votes vote down vote up
private static void initSearchActions(@Nonnull Project project,
                                      @Nonnull RecentLocationsDataModel data,
                                      @Nonnull ListWithFilter<RecentLocationItem> listWithFilter,
                                      @Nonnull JBList<RecentLocationItem> list,
                                      @Nonnull JBCheckBox checkBox,
                                      @Nonnull JBPopup popup,
                                      @Nonnull Ref<? super Boolean> navigationRef) {
  listWithFilter.addMouseListener(new MouseAdapter() {
    @Override
    public void mouseClicked(MouseEvent event) {
      int clickCount = event.getClickCount();
      if (clickCount > 1 && clickCount % 2 == 0) {
        event.consume();
        navigateToSelected(project, list, popup, navigationRef);
      }
    }
  });

  DumbAwareAction.create(e -> navigateToSelected(project, list, popup, navigationRef)).registerCustomShortcutSet(CustomShortcutSet.fromString("ENTER"), listWithFilter, popup);

  DumbAwareAction.create(e -> removePlaces(project, listWithFilter, list, data, checkBox.isSelected()))
          .registerCustomShortcutSet(CustomShortcutSet.fromString("DELETE", "BACK_SPACE"), listWithFilter, popup);
}
 
Example 15
Source Project: consulo   Source File: RecentLocationsAction.java    License: Apache License 2.0 6 votes vote down vote up
private static void removePlaces(@Nonnull Project project,
                                 @Nonnull ListWithFilter<RecentLocationItem> listWithFilter,
                                 @Nonnull JBList<RecentLocationItem> list,
                                 @Nonnull RecentLocationsDataModel data,
                                 boolean showChanged) {
  List<RecentLocationItem> selectedValue = list.getSelectedValuesList();
  if (selectedValue.isEmpty()) {
    return;
  }

  int index = list.getSelectedIndex();

  IdeDocumentHistory ideDocumentHistory = IdeDocumentHistory.getInstance(project);
  for (RecentLocationItem item : selectedValue) {
    if (showChanged) {
      ContainerUtil.filter(ideDocumentHistory.getChangePlaces(), info -> IdeDocumentHistoryImpl.isSame(info, item.getInfo())).forEach(info -> ideDocumentHistory.removeChangePlace(info));
    }
    else {
      ContainerUtil.filter(ideDocumentHistory.getBackPlaces(), info -> IdeDocumentHistoryImpl.isSame(info, item.getInfo())).forEach(info -> ideDocumentHistory.removeBackPlace(info));
    }
  }

  updateModel(listWithFilter, data, showChanged);

  if (list.getModel().getSize() > 0) ScrollingUtil.selectItem(list, index < list.getModel().getSize() ? index : index - 1);
}
 
Example 16
Source Project: consulo   Source File: ProjectLibraryTabContext.java    License: Apache License 2.0 6 votes vote down vote up
public ProjectLibraryTabContext(final ClasspathPanel classpathPanel, StructureConfigurableContext context) {
  super(classpathPanel, context);

  StructureLibraryTableModifiableModelProvider projectLibrariesProvider = context.getProjectLibrariesProvider();
  Library[] libraries = projectLibrariesProvider.getModifiableModel().getLibraries();
  final Condition<Library> condition = LibraryEditingUtil.getNotAddedLibrariesCondition(myClasspathPanel.getRootModel());

  myItems = ContainerUtil.filter(libraries, condition);
  ContainerUtil.sort(myItems, new Comparator<Library>() {
    @Override
    public int compare(Library o1, Library o2) {
      return StringUtil.compare(o1.getName(), o2.getName(), false);
    }
  });

  myLibraryList = new JBList(myItems);
  myLibraryList.setCellRenderer(new ColoredListCellRendererWrapper<Library>() {
    @Override
    protected void doCustomize(JList list, Library value, int index, boolean selected, boolean hasFocus) {
      final CellAppearanceEx appearance = OrderEntryAppearanceService.getInstance().forLibrary(classpathPanel.getProject(), value, false);

      appearance.customize(this);
    }
  });
  new ListSpeedSearch(myLibraryList);
}
 
Example 17
Source Project: consulo   Source File: CustomFoldingRegionsPopup.java    License: Apache License 2.0 6 votes vote down vote up
CustomFoldingRegionsPopup(@Nonnull Collection<FoldingDescriptor> descriptors,
                          @Nonnull final Editor editor,
                          @Nonnull final Project project) {
  myEditor = editor;
  myRegionsList = new JBList();
  //noinspection unchecked
  myRegionsList.setModel(new MyListModel(orderByPosition(descriptors)));
  myRegionsList.setSelectedIndex(0);

  final PopupChooserBuilder popupBuilder = JBPopupFactory.getInstance().createListPopupBuilder(myRegionsList);
  myPopup = popupBuilder
          .setTitle(IdeBundle.message("goto.custom.region.command"))
          .setResizable(false)
          .setMovable(false)
          .setItemChoosenCallback(new Runnable() {
            @Override
            public void run() {
              PsiElement navigationElement = getNavigationElement();
              if (navigationElement != null) {
                navigateTo(editor, navigationElement);
                IdeDocumentHistory.getInstance(project).includeCurrentCommandAsNavigation();
              }
            }
          }).createPopup();
}
 
Example 18
Source Project: consulo   Source File: SearchEverywhereUI.java    License: Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public JBList<Object> createList() {
  myListModel = new SearchListModel();
  addListDataListener(myListModel);

  return new JBList<>(myListModel);
}
 
Example 19
Source Project: consulo   Source File: MacrosDialog.java    License: Apache License 2.0 5 votes vote down vote up
public MacrosDialog(Component parent) {
  super(parent, true);
  MacroManager.getInstance().cacheMacrosPreview(DataManager.getInstance().getDataContext(parent));
  setTitle(IdeBundle.message("title.macros"));
  setOKButtonText(IdeBundle.message("button.insert"));

  myMacrosModel = new DefaultListModel();
  myMacrosList = new JBList(myMacrosModel);
  myPreviewTextarea = new JTextArea();

  init();
}
 
Example 20
Source Project: patcher   Source File: PatcherDialog.java    License: Apache License 2.0 5 votes vote down vote up
private void createUIComponents() {
    VirtualFile[] data = event.getData(DataKeys.VIRTUAL_FILE_ARRAY);
    fieldList = new JBList(data);
    fieldList.setEmptyText("No File Selected!");
    ToolbarDecorator decorator = ToolbarDecorator.createDecorator(fieldList);
    filePanel = decorator.createPanel();
}
 
Example 21
@NotNull
private JComponent createGallery() {
  myProjectTypeGallery = new ASGallery<ModuleGalleryEntry>(
    JBList.createDefaultListModel(),
    image -> image == null ? null : image.getIcon() == null ? null : image.getIcon(),
    label -> label == null ? message("android.wizard.gallery.item.none") : label.getName(), DEFAULT_GALLERY_THUMBNAIL_SIZE,
    null
  ) {

    @Override
    public Dimension getPreferredScrollableViewportSize() {
      // The default implementation assigns a height as tall as the screen.
      // When calling setVisibleRowCount(2), the underlying implementation is buggy, and  will have a gap on the right and when the user
      // resizes, it enters on an adjustment loop at some widths (can't decide to fit 3 or for elements, and loops between the two)
      Dimension cellSize = computeCellSize();
      int heightInsets = getInsets().top + getInsets().bottom;
      int widthInsets = getInsets().left + getInsets().right;
      // Don't want to show an exact number of rows, since then it's not obvious there's another row available.
      return new Dimension(cellSize.width * 5 + widthInsets, (int)(cellSize.height * 1.2) + heightInsets);
    }
  };

  myProjectTypeGallery.setBorder(BorderFactory.createLineBorder(JBColor.border()));
  AccessibleContext accessibleContext = myProjectTypeGallery.getAccessibleContext();
  if (accessibleContext != null) {
    accessibleContext.setAccessibleDescription(getTitle());
  }
  return new JBScrollPane(myProjectTypeGallery);
}
 
Example 22
@Override
protected void onWizardStarting(@NotNull ModelWizard.Facade wizard) {
  myProjectTypeGallery.setModel(JBList.createDefaultListModel(myModuleGalleryEntryList.toArray()));
  myProjectTypeGallery.setDefaultAction(new AbstractAction() {
    @Override
    public void actionPerformed(ActionEvent actionEvent) {
      wizard.goForward();
    }
  });

  myProjectTypeGallery.setSelectedIndex(0);
}
 
Example 23
@Override
protected void onWizardStarting(@NotNull ModelWizard.Facade wizard) {
  myProjectTypeGallery.setModel(JBList.createDefaultListModel(myModuleGalleryEntryList.toArray()));
  myProjectTypeGallery.setDefaultAction(new AbstractAction() {
    @Override
    public void actionPerformed(ActionEvent actionEvent) {
      wizard.goForward();
    }
  });

  myProjectTypeGallery.setSelectedIndex(0);
}
 
Example 24
Source Project: tmc-intellij   Source File: CourseTabFactory.java    License: 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 25
Source Project: tmc-intellij   Source File: CourseTabFactory.java    License: MIT License 5 votes vote down vote up
@NotNull
private ActionListener createOpenInExploreListener(final JBList list,
                                                   final Object selectedItem) {
    return actionEvent -> {
        logger.info("Right mouse button action performed. @CourseTabFactory");

        try {
            if (selectedItem.getClass() != Exercise.class) {
                Desktop.getDesktop().open(new File(TmcSettingsManager
                        .get().getProjectBasePath()
                        + File.separator + list.getParent()
                        .getParent().getName() + File.separator
                        + list.getSelectedValue()));
            } else {
                logger.info("Getting TMC project directory "
                        + "from settingsTmc. @CourseTabFactory");
                Desktop.getDesktop().open(new File(((Exercise)selectedItem)
                        .getExerciseDirectory(TmcSettingsManager
                                .get().getTmcProjectDirectory()).toString()));
            }
        } catch (IOException e1) {
            logger.warn("IOException occurred. Something interrupted "
                            + "the mouse action. @CourseTabFactory",
                    e1, e1.getStackTrace());
            new ErrorMessageService().showErrorMessageWithExceptionDetails(e1,
                    "IOException occurred. Something interrupted the mouse action.",
                    true);
        }
    };
}
 
Example 26
Source Project: tmc-intellij   Source File: CourseTabFactory.java    License: MIT License 5 votes vote down vote up
@NotNull
private ActionListener createDeleteButtonActionListener(final JBList list,
                                                        final Object selectedItem) {
    return actionEvent -> {
        logger.info("Trying to delete folder. @CourseTabFactory");
        if (Messages
                .showYesNoDialog("Are you sure you wish to permanently delete this folder?",
                        "Delete Exercise", Messages.getWarningIcon()) != 0) {
            return;
        }

        try {
            if (selectedItem.getClass() != Exercise.class) {
                FileUtils.deleteDirectory(new File(TmcSettingsManager
                        .get().getProjectBasePath()
                        + File.separator + list.getParent()
                        .getParent().getName() + File.separator
                        + list.getSelectedValue()));
            } else {
                logger.info("Getting TMC project directory "
                        + "from settingsTmc. @CourseTabFactory");
                FileUtils.deleteDirectory(new File(((Exercise) selectedItem)
                        .getExerciseDirectory(TmcSettingsManager
                                .get().getTmcProjectDirectory()).toString()));
            }
            new ProjectListWindow().refreshProjectList();
        } catch (IOException e1) {
            logger.warn("IOException occurred. Something interrupted "
                            + "the mouse action. @CourseTabFactory",
                    e1, e1.getStackTrace());
            new ErrorMessageService().showErrorMessageWithExceptionDetails(e1,
                    "IOException occurred. Something interrupted the mouse action.",
                    true);
        }
    };
}
 
Example 27
Source Project: tmc-intellij   Source File: CourseListWindow.java    License: MIT License 5 votes vote down vote up
public CourseListWindow(List<Course> courses) {
    Course[] courseArray = courses.toArray(new Course[courses.size()]);
    this.courses = new JBList<>(courseArray);
    this.courses.setFixedCellHeight(107);
    this.courses.setFixedCellWidth(346);


    this.courses.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
    this.button = new JButton("Select");
    button.addActionListener(new SelectCourseListener(this));

    this.courses.setCellRenderer(new CourseCellRenderer());
    this.courses.setVisibleRowCount(4);
    JScrollPane pane = new JBScrollPane(this.courses);
    Dimension d = pane.getPreferredSize();
    d.width = 800;
    d.height = (int) (d.height * 1.12);
    pane.setPreferredSize(d);
    pane.setBorder(new EmptyBorder(5, 0, 5, 0));
    pane.setViewportBorder(new EmptyBorder(0, 0, 0, 0));
    pane.getVerticalScrollBar().setUnitIncrement(10);

    this.courses.setBackground(new Color(242, 241, 240));

    this.courses.setSelectedIndex(setDefaultSelectedIndex());
    this.courses.addMouseListener(
        new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent event) {
                if (event.getClickCount() >= 2) {
                    button.doClick();
                }
            }
        });
    add(pane);
    add(button);
}
 
Example 28
@Override
public void invoke(@NotNull Project project, Editor editor, @NotNull PsiElement element) throws IncorrectOperationException {
     // filter libraries to only be Camel libraries
    Set<String> artifacts = ServiceManager.getService(project, CamelService.class).getLibraries();

    // find the camel component from those libraries
    boolean consumerOnly = getCamelIdeaUtils().isConsumerEndpoint(element);
    List<String> names = findCamelComponentNamesInArtifact(artifacts, consumerOnly, project);

    // no camel endpoints then exit
    if (names.isEmpty()) {
        return;
    }

    // show popup to chose the component
    JBList list = new JBList(names.toArray(new Object[names.size()]));
    PopupChooserBuilder builder = JBPopupFactory.getInstance().createListPopupBuilder(list);
    builder.setAdText(names.size() + " components");
    builder.setTitle("Add Camel Endpoint");
    builder.setItemChoosenCallback(() -> {
        String line = (String) list.getSelectedValue();
        int pos = editor.getCaretModel().getCurrentCaret().getOffset();
        if (pos > 0) {
            // must run this as write action because we change the source code
            new WriteCommandAction(project, element.getContainingFile()) {
                @Override
                protected void run(@NotNull Result result) throws Throwable {
                    String text = line + ":";
                    editor.getDocument().insertString(pos, text);
                    editor.getCaretModel().moveToOffset(pos + text.length());
                }
            }.execute();
        }
    });

    JBPopup popup = builder.createPopup();
    popup.showInBestPositionFor(editor);
}
 
Example 29
Source Project: intellij   Source File: SubclassTestChooser.java    License: 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 30
Source Project: p4ic4idea   Source File: P4RootConfigPanel.java    License: Apache License 2.0 5 votes vote down vote up
private void createUIComponents() {
    // custom component creation code
    myConfigPartStack = new ConfigPartStack(vcsRoot, configConnectionController);

    problemListModel = new DefaultListModel<>();
    myProblemsList = new JBList<>(problemListModel);
    myProblemsList.setCellRenderer(new ProblemRenderer());

    myCheckConnectionSpinner = new AsyncProcessIcon("Checking Connection");
}