void (AbstractTreeStructure treeStructure) { myPropertiesLabel.setBorder(JBUI.Borders.empty(0, 10)); myTreeModel = new StructureTreeModel<>(treeStructure, this); AsyncTreeModel asyncTreeModel = new AsyncTreeModel(myTreeModel, this); asyncTreeModel.addTreeModelListener(new TreeModelAdapter() { @Override public void treeNodesInserted(TreeModelEvent event) { Object[] childNodes = event.getChildren(); if (childNodes != null) { for (Object childNode : childNodes) { LibraryTableTreeContentElement element = TreeUtil.getUserObject(LibraryTableTreeContentElement.class, childNode); if (element != null && myTree != null) { myTreeModel.expand(element, myTree, path -> { }); } } } } }); myTree = new Tree(asyncTreeModel); myTree.setRootVisible(false); myTree.setShowsRootHandles(true); LibraryRootsTreeSpeedSearch.installOn(myTree); myTree.setCellRenderer(new LibraryTreeRenderer()); myTreePanel.setLayout(new BorderLayout()); ToolbarDecorator toolbarDecorator = ToolbarDecorator.createDecorator(myTree).disableUpDownActions() .setRemoveActionName(JavaUiBundle.message("library.remove.action")) .disableRemoveAction(); final List<AttachRootButtonDescriptor> popupItems = new ArrayList<>(); for (AttachRootButtonDescriptor descriptor : myDescriptor.createAttachButtons()) { Icon icon = descriptor.getToolbarIcon(); if (icon != null) { AttachItemAction action = new AttachItemAction(descriptor, descriptor.getButtonText(), icon); toolbarDecorator.addExtraAction(AnActionButton.fromAction(action)); } else { popupItems.add(descriptor); } } myAddExcludedRootActionButton = new AddExcludedRootActionButton(); toolbarDecorator.addExtraAction(myAddExcludedRootActionButton); toolbarDecorator.addExtraAction(new AnActionButton(JavaUiBundle.messagePointer("action.AnActionButton.text.remove"), IconUtil.getRemoveIcon()) { @Override public void actionPerformed(@NotNull AnActionEvent e) { final List<Object> selectedElements = getSelectedElements(); if (selectedElements.isEmpty()) { return; } ApplicationManager.getApplication().runWriteAction(() -> { for (Object selectedElement : selectedElements) { LibraryEditor libraryEditor = getLibraryEditor(); if (selectedElement instanceof ItemElement itemElement) { libraryEditor.removeRoot(itemElement.getUrl(), itemElement.getRootType()); myRootRemovalHandler.onRootRemoved(itemElement.getUrl(), itemElement.getRootType(), libraryEditor); } else if (selectedElement instanceof OrderRootTypeElement orderRootTypeElement) { final OrderRootType rootType = orderRootTypeElement.getOrderRootType(); final String[] urls = libraryEditor.getUrls(rootType); for (String url : urls) { libraryEditor.removeRoot(url, rootType); } } else if (selectedElement instanceof ExcludedRootElement excludedRootElement) { libraryEditor.removeExcludedRoot(excludedRootElement.getUrl()); } } }); libraryChanged(true); } @Override public void updateButton(@NotNull AnActionEvent e) { super.updateButton(e); Presentation presentation = e.getPresentation(); if (ContainerUtil.and(getSelectedElements(), new FilteringIterator.InstanceOf<>(ExcludedRootElement.class))) { presentation.setText(JavaUiBundle.message("action.text.cancel.exclusion")); } else { presentation.setText(getTemplatePresentation().getText()); } } @Override public @NotNull ActionUpdateThread getActionUpdateThread() { return ActionUpdateThread.EDT; } @Override public ShortcutSet getShortcut() { return CommonShortcuts.getDelete(); } }); toolbarDecorator.setAddAction(new AnActionButtonRunnable() { @Override public void run(AnActionButton button) { AttachFilesAction attachFilesAction = new AttachFilesAction(myDescriptor.getAttachFilesActionName()); if (popupItems.isEmpty()) { attachFilesAction.perform(); return; } List<AnAction> actions = new ArrayList<>(); actions.add(attachFilesAction); for (AttachRootButtonDescriptor descriptor : popupItems) { actions.add(new AttachItemAction(descriptor, descriptor.getButtonText(), null)); } final DefaultActionGroup group = new DefaultActionGroup(actions); JBPopupFactory.getInstance().createActionGroupPopup(null, group, DataManager.getInstance().getDataContext(button.getContextComponent()), JBPopupFactory.ActionSelectionAid.SPEEDSEARCH, true) .show(button.getPreferredPopupPoint()); } }); JPanel panel = toolbarDecorator.createPanel(); panel.setBorder(null); myTreePanel.add(panel, BorderLayout.CENTER); }