private void init(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) {
        toolbarDecorator.addExtraAction(new AttachItemAction(descriptor, descriptor.getButtonText(), icon));
      }
      else {
        popupItems.add(descriptor);
      }
    }
    toolbarDecorator.addExtraAction(new AddExcludedRootActionButton());
    toolbarDecorator.addExtraAction(new DumbAwareAction(JavaUiBundle.messagePointer("action.AnActionButton.text.remove"), IconUtil.getRemoveIcon()) {
      {
        setShortcutSet(CommonShortcuts.getDelete());
      }
      @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 update(@NotNull AnActionEvent 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;
      }
    });
    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);
  }
private void init(AbstractTreeStructure treeStructure)