Java Code Examples for com.intellij.ui.treeStructure.Tree#setRootVisible()

The following examples show how to use com.intellij.ui.treeStructure.Tree#setRootVisible() . 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: DirectoryChooserModuleTreeView.java    From consulo with Apache License 2.0 6 votes vote down vote up
public DirectoryChooserModuleTreeView(@Nonnull Project project) {
  myRootNode = new DefaultMutableTreeNode();
  myTree = new Tree(myRootNode);
  myTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
  myFileIndex = ProjectRootManager.getInstance(project).getFileIndex();
  myProject = project;
  myTree.setRootVisible(false);
  myTree.setShowsRootHandles(true);
  myTree.setCellRenderer(new MyTreeCellRenderer());
  new TreeSpeedSearch(myTree, new Convertor<TreePath, String>() {
    @Override
    public String convert(final TreePath o) {
      final Object userObject = ((DefaultMutableTreeNode)o.getLastPathComponent()).getUserObject();
      if (userObject instanceof Module) {
        return ((Module)userObject).getName();
      }
      else {
        if (userObject == null) return "";
        return userObject.toString();
      }
    }
  }, true);
}
 
Example 2
Source File: ActiveConnectionPanel.java    From p4ic4idea with Apache License 2.0 6 votes vote down vote up
private void setup() {
    root = new JPanel(new BorderLayout());
    JScrollPane scroll = new JBScrollPane();
    root.add(scroll, BorderLayout.CENTER);
    connectionTree = new Tree();
    scroll.setViewportView(connectionTree);

    connectionTree.getEmptyText().setText(P4Bundle.getString("connection.tree.initial"));
    connectionTree.setEditable(false);
    connectionTreeModel = new DefaultTreeModel(treeNode);
    connectionTree.setModel(connectionTreeModel);
    connectionTree.setCellRenderer(new ConnectionTreeCellRenderer());
    connectionTree.setRootVisible(false);
    DefaultTreeSelectionModel selectionModel = new DefaultTreeSelectionModel();
    selectionModel.setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    connectionTree.setSelectionModel(selectionModel);

    ActionGroup actionButtons = createActionGroup();
    ActionToolbar toolbar =
            ActionManager.getInstance().createActionToolbar("p4.active-connection",
                    actionButtons, false);
    root.add(toolbar.getComponent(), BorderLayout.WEST);

    // TODO add context menu support for each selected node type.
    // TODO add support for navigating to a file if a FilePath is selected.
}
 
Example 3
Source File: FileTemplateTabAsTree.java    From consulo with Apache License 2.0 6 votes vote down vote up
protected FileTemplateTabAsTree(String title) {
  super(title);
  myRoot = initModel();
  myTreeModel = new MyTreeModel(myRoot);
  myTree = new Tree(myTreeModel);
  myTree.setRootVisible(false);
  myTree.setShowsRootHandles(true);
  UIUtil.setLineStyleAngled(myTree);

  myTree.expandPath(TreeUtil.getPathFromRoot(myRoot));
  myTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
  myTree.setCellRenderer(new MyTreeCellRenderer());
  myTree.expandRow(0);

  myTree.addTreeSelectionListener(e -> onTemplateSelected());
  new TreeSpeedSearch(myTree);
}
 
Example 4
Source File: LiteralChooser.java    From intellij-plugin-v4 with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public Tree createTree(java.util.List<String> literals) {
	final CheckedTreeNode rootNode = new CheckedTreeNode("all literals not defined");
	for (String literal : literals) {
		CheckedTreeNode child = new CheckedTreeNode(new LiteralChooserObject(literal, Icons.LEXER_RULE));
		child.setChecked(true);
		rootNode.add(child);
	}
	DefaultTreeModel treeModel = new DefaultTreeModel(rootNode);

	selectedElements.addAll(literals); // all are "on" by default

	Tree tree = new Tree(treeModel);
	tree.setRootVisible(false);
	tree.setCellRenderer(new LiteralChooserRenderer());
	tree.addTreeSelectionListener(new MyTreeSelectionListener());

	return tree;
}
 
Example 5
Source File: ContentEntryTreeEditor.java    From consulo with Apache License 2.0 6 votes vote down vote up
public ContentEntryTreeEditor(Project project, ModuleConfigurationState state) {
  myProject = project;
  myState = state;
  myTree = new Tree();
  myTree.setRootVisible(true);
  myTree.setShowsRootHandles(true);

  myEditingActionsGroup = new DefaultActionGroup();

  TreeUtil.installActions(myTree);
  new TreeSpeedSearch(myTree);

  myTreePanel = new MyPanel(new BorderLayout());
  final JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(myTree);
  myTreePanel.add(scrollPane, BorderLayout.CENTER);

  myTreePanel.setVisible(false);
  myDescriptor = FileChooserDescriptorFactory.createMultipleFoldersDescriptor();
  myDescriptor.setShowFileSystemRoots(false);
}
 
Example 6
Source File: StructureFilteringStrategy.java    From consulo with Apache License 2.0 6 votes vote down vote up
public MyUI() {
  myStructureTree = new Tree();
  myStructureTree.setRootVisible(false);
  myStructureTree.setShowsRootHandles(true);
  myStructureTree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {
    public void valueChanged(final TreeSelectionEvent e) {
      final List<FilePath> filePaths = new ArrayList<>(mySelection);

      mySelection.clear();
      final TreePath[] selectionPaths = myStructureTree.getSelectionPaths();
      if (selectionPaths != null) {
        for (TreePath selectionPath : selectionPaths) {
          mySelection.addAll(getFilePathsUnder((ChangesBrowserNode<?>)selectionPath.getLastPathComponent()));
        }
      }

      if (Comparing.haveEqualElements(filePaths, mySelection)) return;

      for (ChangeListener listener : myListeners) {
        listener.stateChanged(new ChangeEvent(this));
      }
    }
  });
  myScrollPane = ScrollPaneFactory.createScrollPane(myStructureTree);
}
 
Example 7
Source File: NewProjectPanel.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
@Override
protected JComponent createLeftComponent(@Nonnull Disposable parentDisposable) {
  NewModuleContext context = new NewModuleContext();

  NewModuleBuilder.EP_NAME.composite().setupContext(context);

  myTree = new Tree(new AsyncTreeModel(new StructureTreeModel<>(new NewProjectTreeStructure(context), parentDisposable), parentDisposable));
  myTree.setFont(UIUtil.getFont(UIUtil.FontSize.BIGGER, null));
  myTree.setOpaque(false);
  myTree.setBackground(SwingUIDecorator.get(SwingUIDecorator::getSidebarColor));
  myTree.setRootVisible(false);
  myTree.setRowHeight(JBUI.scale(24));

  TreeUtil.expandAll(myTree);
  return ScrollPaneFactory.createScrollPane(myTree, true);
}
 
Example 8
Source File: ModulesDependenciesPanel.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static void initTree(Tree tree, boolean isRightTree) {
  tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
  tree.setCellRenderer(new MyTreeCellRenderer());
  tree.setRootVisible(false);
  tree.setShowsRootHandles(true);
  UIUtil.setLineStyleAngled(tree);

  TreeUtil.installActions(tree);
  new TreeSpeedSearch(tree, new Convertor<TreePath, String>() {
    @Override
    public String convert(TreePath o) {
      return o.getLastPathComponent().toString();
    }
  }, true);
  PopupHandler.installUnknownPopupHandler(tree, createTreePopupActions(isRightTree, tree), ActionManager.getInstance());
}
 
Example 9
Source File: IMContactView.java    From SmartIM4IntelliJ with Apache License 2.0 5 votes vote down vote up
protected void initTree(Tree tree) {
    tree.setCellRenderer(getContactRenderer());
    tree.setShowsRootHandles(false);
    tree.setRootVisible(false);
    tree.addMouseListener(new IMContactDoubleClicker(getImPanel()));
    tree.setUI(new WideSelectionTreeUI() {

    });
}
 
Example 10
Source File: MemberChooser.java    From consulo with Apache License 2.0 5 votes vote down vote up
protected Tree createTree() {
  final Tree tree = new Tree(new DefaultTreeModel(new DefaultMutableTreeNode()));

  tree.setCellRenderer(getTreeCellRenderer());
  UIUtil.setLineStyleAngled(tree);
  tree.setRootVisible(false);
  tree.setShowsRootHandles(true);
  tree.addKeyListener(new TreeKeyListener());
  tree.addTreeSelectionListener(new MyTreeSelectionListener());

  if (!myAllowMultiSelection) {
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
  }

  new DoubleClickListener() {
    @Override
    protected boolean onDoubleClick(MouseEvent e) {
      if (tree.getPathForLocation(e.getX(), e.getY()) != null) {
        doOKAction();
        return true;
      }
      return false;
    }
  }.installOn(tree);

  TreeUtil.installActions(tree);
  return tree;
}
 
Example 11
Source File: ImageDuplicateResultsDialog.java    From consulo with Apache License 2.0 5 votes vote down vote up
public ImageDuplicateResultsDialog(Project project, List<VirtualFile> images, Map<String, Set<VirtualFile>> duplicates) {
  super(project);
  myProject = project;
  myImages = images;
  PropertiesComponent.getInstance(myProject).loadFields(myResourceModules);
  myDuplicates = duplicates;
  setModal(false);
  myTree = new Tree(new MyRootNode());
  myTree.setRootVisible(true);
  myTree.setCellRenderer(new MyCellRenderer());
  init();
  TreeUtil.expandAll(myTree);
  setTitle("Image Duplicates");
  TreeUtil.selectFirstNode(myTree);
}
 
Example 12
Source File: AnalyzeDependenciesComponent.java    From consulo with Apache License 2.0 5 votes vote down vote up
/**
 * @return a created tree component (to be used as
 */
private JComponent createTreeComponent() {
  myExplanationTree = new Tree(new DefaultTreeModel(buildTree()));
  myExplanationTree.setRootVisible(false);
  myExplanationTree.setCellRenderer(new ExplanationTreeRenderer());
  DataManager.registerDataProvider(myExplanationTree, this);
  TreeUtil.expandAll(myExplanationTree);
  final NavigateAction navigateAction = new NavigateAction();
  navigateAction.registerCustomShortcutSet(new CustomShortcutSet(CommonShortcuts.DOUBLE_CLICK_1.getShortcuts()[0]), myExplanationTree);
  DefaultActionGroup group = new DefaultActionGroup();
  group.addAction(navigateAction);
  PopupHandler.installUnknownPopupHandler(myExplanationTree, group, ActionManager.getInstance());
  return new JBScrollPane(myExplanationTree);
}
 
Example 13
Source File: ActionsTree.java    From consulo with Apache License 2.0 5 votes vote down vote up
public ActionsTree() {
  myRoot = new DefaultMutableTreeNode(ROOT);

  myTree = new Tree(new MyModel(myRoot)) {
    @Override
    public void paint(Graphics g) {
      super.paint(g);
      Rectangle visibleRect = getVisibleRect();
      Rectangle clip = g.getClipBounds();
      for (int row = 0; row < getRowCount(); row++) {
        Rectangle rowBounds = getRowBounds(row);
        rowBounds.x = 0;
        rowBounds.width = Integer.MAX_VALUE;

        if (rowBounds.intersects(clip)) {
          Object node = getPathForRow(row).getLastPathComponent();

          if (node instanceof DefaultMutableTreeNode) {
            Object data = ((DefaultMutableTreeNode)node).getUserObject();
            Rectangle fullRowRect = new Rectangle(visibleRect.x, rowBounds.y, visibleRect.width, rowBounds.height);
            paintRowData(this, data, fullRowRect, (Graphics2D)g);
          }
        }
      }
      
    }
  };
  myTree.setRootVisible(false);
  myTree.setShowsRootHandles(true);

  myTree.putClientProperty(WideSelectionTreeUI.STRIPED_CLIENT_PROPERTY, Boolean.TRUE);
  myTree.setCellRenderer(new KeymapsRenderer());

  myTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);

  myComponent = ScrollPaneFactory.createScrollPane(myTree,
                                                   ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
                                                   ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
}
 
Example 14
Source File: VcsPullRequestsForm.java    From azure-devops-intellij with MIT License 5 votes vote down vote up
protected void createCustomView() {
    //Tree in a scroll panel
    pullRequestsTree = new Tree();
    pullRequestsTree.setCellRenderer(new PRTreeCellRenderer());
    pullRequestsTree.setShowsRootHandles(true);
    pullRequestsTree.setRootVisible(false);
    pullRequestsTree.setRowHeight(0); //dynamically have row height computed for each row
    scrollPanel = new JBScrollPane(pullRequestsTree);
}
 
Example 15
Source File: NewErrorTreeViewPanel.java    From consulo with Apache License 2.0 4 votes vote down vote up
public NewErrorTreeViewPanel(Project project, String helpId, boolean createExitAction, boolean createToolbar, @Nullable Runnable rerunAction) {
  myProject = project;
  myHelpId = helpId;
  myConfiguration = ErrorTreeViewConfiguration.getInstance(project);
  setLayout(new BorderLayout());

  myAutoScrollToSourceHandler = new AutoScrollToSourceHandler() {
    @Override
    protected boolean isAutoScrollMode() {
      return myConfiguration.isAutoscrollToSource();
    }

    @Override
    protected void setAutoScrollMode(boolean state) {
      myConfiguration.setAutoscrollToSource(state);
    }
  };

  myMessagePanel = new JPanel(new BorderLayout());

  myErrorViewStructure = new ErrorViewStructure(project, canHideWarningsOrInfos());
  DefaultMutableTreeNode root = new DefaultMutableTreeNode();
  root.setUserObject(myErrorViewStructure.createDescriptor(myErrorViewStructure.getRootElement(), null));
  final DefaultTreeModel treeModel = new DefaultTreeModel(root);
  myTree = new Tree(treeModel) {
    @Override
    public void setRowHeight(int i) {
      super.setRowHeight(0);
      // this is needed in order to make UI calculate the height for each particular row
    }
  };
  myBuilder = new ErrorViewTreeBuilder(myTree, treeModel, myErrorViewStructure);

  myExporterToTextFile = new ErrorViewTextExporter(myErrorViewStructure);
  myOccurenceNavigatorSupport = new MyOccurenceNavigatorSupport(myTree);

  myAutoScrollToSourceHandler.install(myTree);
  TreeUtil.installActions(myTree);
  UIUtil.setLineStyleAngled(myTree);
  myTree.setRootVisible(false);
  myTree.setShowsRootHandles(true);
  myTree.setLargeModel(true);

  JScrollPane scrollPane = NewErrorTreeRenderer.install(myTree);
  scrollPane.setBorder(IdeBorderFactory.createBorder(SideBorder.LEFT));
  myMessagePanel.add(scrollPane, BorderLayout.CENTER);

  if (createToolbar) {
    add(createToolbarPanel(rerunAction), BorderLayout.WEST);
  }

  add(myMessagePanel, BorderLayout.CENTER);

  myTree.addKeyListener(new KeyAdapter() {
    @Override
    public void keyPressed(KeyEvent e) {
      if (e.getKeyCode() == KeyEvent.VK_ENTER) {
        navigateToSource(false);
      }
    }
  });

  myTree.addMouseListener(new PopupHandler() {
    @Override
    public void invokePopup(Component comp, int x, int y) {
      popupInvoked(comp, x, y);
    }
  });

  EditSourceOnDoubleClickHandler.install(myTree);
}
 
Example 16
Source File: ServersToolWindowContent.java    From consulo with Apache License 2.0 4 votes vote down vote up
public ServersToolWindowContent(@Nonnull Project project) {
  super(new BorderLayout());
  myProject = project;

  myTreeModel = new DefaultTreeModel(new DefaultMutableTreeNode());
  myTree = new Tree(myTreeModel);
  myTree.setRootVisible(false);

  myTree.setShowsRootHandles(true);
  myTree.setCellRenderer(new NodeRenderer());
  myTree.setLineStyleAngled();

  getMainPanel().add(createToolbar(), BorderLayout.WEST);
  Splitter splitter = new OnePixelSplitter(false, 0.3f);
  splitter.setFirstComponent(ScrollPaneFactory.createScrollPane(myTree, SideBorder.LEFT));
  myPropertiesPanelLayout = new CardLayout();
  myPropertiesPanel = new JPanel(myPropertiesPanelLayout);
  myMessageLabel = new JLabel(EMPTY_SELECTION_MESSAGE, SwingConstants.CENTER);
  myPropertiesPanel.add(MESSAGE_CARD, new Wrapper(myMessageLabel));
  splitter.setSecondComponent(myPropertiesPanel);
  getMainPanel().add(splitter, BorderLayout.CENTER);

  setupBuilder(project);

  for (RemoteServersViewContributor contributor : RemoteServersViewContributor.EP_NAME.getExtensionList()) {
    contributor.setupTree(myProject, myTree, myBuilder);
  }

  myTree.addTreeSelectionListener(new TreeSelectionListener() {
    @Override
    public void valueChanged(TreeSelectionEvent e) {
      onSelectionChanged();
    }
  });
  new DoubleClickListener() {
    @Override
    protected boolean onDoubleClick(MouseEvent event) {
      Set<ServersTreeStructure.RemoteServerNode> nodes = getSelectedRemoteServerNodes();
      if (nodes.size() == 1) {
        RemoteServer<?> server = nodes.iterator().next().getValue();
        ServerConnectionManager.getInstance().getOrCreateConnection(server).computeDeployments(EmptyRunnable.INSTANCE);
        return true;
      }
      return false;
    }
  }.installOn(myTree);
}
 
Example 17
Source File: PantsConsoleViewPanel.java    From intellij-pants-plugin with Apache License 2.0 4 votes vote down vote up
public PantsConsoleViewPanel(Project project, ConsoleView console) {
  myProject = project;
  myConfiguration = ErrorTreeViewConfiguration.getInstance(project);
  setLayout(new BorderLayout());

  AutoScrollToSourceHandler autoScrollToSourceHandler = new AutoScrollToSourceHandler() {
    @Override
    protected boolean isAutoScrollMode() {
      return myConfiguration.isAutoscrollToSource();
    }

    @Override
    protected void setAutoScrollMode(boolean state) {
      myConfiguration.setAutoscrollToSource(state);
    }
  };

  JPanel myMessagePanel = new JPanel(new BorderLayout());

  DefaultMutableTreeNode root = new DefaultMutableTreeNode();
  final DefaultTreeModel treeModel = new DefaultTreeModel(root);
  Tree tree = createTree(treeModel);
  tree.getEmptyText().setText(IdeBundle.message("errortree.noMessages"));

  autoScrollToSourceHandler.install(tree);
  TreeUtil.installActions(tree);

  tree.setRootVisible(false);
  tree.setShowsRootHandles(true);
  tree.setLargeModel(true);

  JScrollPane scrollPane = NewErrorTreeRenderer.install(tree);
  scrollPane.setBorder(IdeBorderFactory.createBorder(SideBorder.LEFT));
  myMessagePanel.add(console.getComponent(), BorderLayout.CENTER);

  add(createToolbarPanel(), BorderLayout.WEST);

  add(myMessagePanel, BorderLayout.CENTER);

  EditSourceOnDoubleClickHandler.install(tree);
}
 
Example 18
Source File: AnalyzeSizeToolWindow.java    From size-analyzer with Apache License 2.0 4 votes vote down vote up
private Tree createSuggestionTree() {
  DefaultMutableTreeNode rootNode =
      new DefaultMutableTreeNode("Hurray! Your application is already optimized for size.");
  for (Category category : categoryDisplayOrder) {
    ImmutableList<Suggestion> suggestions = categorizedSuggestions.get(category);
    if (!suggestions.isEmpty()) {
      Map<IssueType, List<Suggestion>> suggestionMap =
          suggestions.stream().collect(Collectors.groupingBy(Suggestion::getIssueType));
      rootNode.add(buildNodesForCategory(category, suggestionMap));
    }
  }
  Tree tree = new Tree(rootNode);
  // Show the root if we do not have any size suggestions for the developer.
  tree.setRootVisible(rootNode.getChildCount() == 0);

  tree.addTreeSelectionListener(
      (TreeSelectionEvent e) -> {
        Object selectedNode = e.getPath().getLastPathComponent();
        Object selection = ((DefaultMutableTreeNode) selectedNode).getUserObject();
        descriptionAutoFixButton.setVisible(false);
        descriptionAutoFixStrut.setVisible(false);
        descriptionTitle.setVisible(false);
        descriptionTitleStrut.setVisible(false);
        description.setVisible(false);
        descriptionStrut.setVisible(false);
        descriptionMoreInfo.setVisible(false);
        if (selection instanceof SuggestionData || selection instanceof IssueTypeData) {
          splitter.setSecondComponent(descriptionPanel);
          descriptionTitle.setVisible(true);
          descriptionTitleStrut.setVisible(true);
          description.setVisible(true);
          showInformationInDescriptionPanelFor((DefaultMutableTreeNode) selectedNode);
        } else if (selection instanceof CategoryData) {
          splitter.setSecondComponent(categoryPanel);
          showCategoryInCategoryPanelFor((DefaultMutableTreeNode) selectedNode);
        } else if (selection instanceof String) {
          splitter.setSecondComponent(descriptionPanel);
          description.setVisible(true);
          String escapedSelection = escapeHtml4((String) selection);
          description.setText("<html> " + escapedSelection + "</html>");
        }
      });

  tree.setCellRenderer(new SuggestionTreeCellRenderer(tree.getCellRenderer()));

  return tree;
}
 
Example 19
Source File: FileChooserDialogImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
protected JTree createTree() {
  Tree internalTree = createInternalTree();
  myFileSystemTree = new FileSystemTreeImpl(myProject, myChooserDescriptor, internalTree, null, null, null);
  internalTree.setRootVisible(myChooserDescriptor.isTreeRootVisible());
  internalTree.setShowsRootHandles(true);
  Disposer.register(myDisposable, myFileSystemTree);

  myFileSystemTree.addOkAction(new Runnable() {
    public void run() {
      doOKAction();
    }
  });
  JTree tree = myFileSystemTree.getTree();
  if (!Registry.is("file.chooser.async.tree.model")) tree.setCellRenderer(new NodeRenderer());
  tree.getSelectionModel().addTreeSelectionListener(new FileTreeSelectionListener());
  tree.addTreeExpansionListener(new FileTreeExpansionListener());
  setOKActionEnabled(false);

  myFileSystemTree.addListener(new FileSystemTree.Listener() {
    public void selectionChanged(final List<? extends VirtualFile> selection) {
      updatePathFromTree(selection, false);
    }
  }, myDisposable);

  new FileDrop(tree, new FileDrop.Target() {
    public FileChooserDescriptor getDescriptor() {
      return myChooserDescriptor;
    }

    public boolean isHiddenShown() {
      return myFileSystemTree.areHiddensShown();
    }

    public void dropFiles(final List<VirtualFile> files) {
      if (!myChooserDescriptor.isChooseMultiple() && files.size() > 0) {
        selectInTree(new VirtualFile[]{files.get(0)}, true);
      }
      else {
        selectInTree(VfsUtilCore.toVirtualFileArray(files), true);
      }
    }
  });

  return tree;
}