public Pair<Image, Point> createDraggedImage(DnDAction action, Point dragOrigin) { final List<PackagingElementNode<?>> nodes = getNodesToDrag(); if (nodes.size() == 1) { return DnDAwareTree.getDragImage(this, getPathFor(nodes.get(0)), dragOrigin); } return DnDAwareTree.getDragImage( this, ProjectBundle.message("drag.n.drop.text.0.packaging.elements", nodes.size()), dragOrigin); }
public void expand(@Nullable final Object[] path, final boolean requestFocus) { if (getTreeBuilder() == null || path == null) return; getTreeBuilder().buildNodeForPath(path); DefaultMutableTreeNode node = getTreeBuilder().getNodeForPath(path); if (node == null) { return; } TreePath treePath = new TreePath(node.getPath()); myTree.expandPath(treePath); if (requestFocus) { myTree.requestFocus(); } TreeUtil.selectPath(myTree, treePath); }
@NotNull public FavoritesTreeNodeDescriptor[] getSelectedNodeDescriptors() { TreePath[] path = myTree.getSelectionPaths(); if (path == null) { return FavoritesTreeNodeDescriptor.EMPTY_ARRAY; } ArrayList<FavoritesTreeNodeDescriptor> result = new ArrayList<FavoritesTreeNodeDescriptor>(); for (TreePath treePath : path) { DefaultMutableTreeNode lastPathNode = (DefaultMutableTreeNode) treePath.getLastPathComponent(); Object userObject = lastPathNode.getUserObject(); if (!(userObject instanceof FavoritesTreeNodeDescriptor)) { continue; } FavoritesTreeNodeDescriptor treeNodeDescriptor = (FavoritesTreeNodeDescriptor) userObject; result.add(treeNodeDescriptor); } return result.toArray(new FavoritesTreeNodeDescriptor[result.size()]); }
public TreePath[] getSelectionPaths() { return myTree == null ? null : myTree.getSelectionPaths(); }
public FavoritesTreeViewPanel(Project project, String helpId, String name) { super(new BorderLayout()); myProject = project; myHelpId = helpId; myListName = name; myFavoritesTreeStructure = new FavoritesTreeStructure(project, myListName); DefaultMutableTreeNode root = new DefaultMutableTreeNode(); root.setUserObject(myFavoritesTreeStructure.getRootElement()); final DefaultTreeModel treeModel = new DefaultTreeModel(root); myTree = new DnDAwareTree(treeModel); myBuilder = new FavoritesViewTreeBuilder( myProject, myTree, treeModel, myFavoritesTreeStructure, myListName); TreeUtil.installActions(myTree); UIUtil.setLineStyleAngled(myTree); myTree.setRootVisible(false); myTree.setShowsRootHandles(true); myTree.setLargeModel(true); new TreeSpeedSearch(myTree); ToolTipManager.sharedInstance().registerComponent(myTree); myTree.setCellRenderer( new NodeRenderer() { public void customizeCellRenderer( JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) { super.customizeCellRenderer(tree, value, selected, expanded, leaf, row, hasFocus); if (value instanceof DefaultMutableTreeNode) { final DefaultMutableTreeNode node = (DefaultMutableTreeNode) value; // only favorites roots to explain final Object userObject = node.getUserObject(); if (userObject instanceof FavoritesTreeNodeDescriptor) { final FavoritesTreeNodeDescriptor favoritesTreeNodeDescriptor = (FavoritesTreeNodeDescriptor) userObject; AbstractTreeNode treeNode = favoritesTreeNodeDescriptor.getElement(); final ItemPresentation presentation = treeNode.getPresentation(); String locationString = presentation.getLocationString(); if (locationString != null && locationString.length() > 0) { append(" (" + locationString + ")", SimpleTextAttributes.GRAY_ATTRIBUTES); } else if (node.getParent() != null && node.getParent().getParent() == null) { final String location = favoritesTreeNodeDescriptor.getLocation(); if (location != null && location.length() > 0) { append(" (" + location + ")", SimpleTextAttributes.GRAY_ATTRIBUTES); } } } } } }); JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(myTree); myTreePopupHandler = CustomizationUtil.installPopupHandler( myTree, IdeActions.GROUP_FAVORITES_VIEW_POPUP, ActionPlaces.FAVORITES_VIEW_POPUP); add(scrollPane, BorderLayout.CENTER); // add(createActionsToolbar(), BorderLayout.NORTH); EditSourceOnDoubleClickHandler.install(myTree); EditSourceOnEnterKeyHandler.install(myTree); myCopyPasteDelegator = new CopyPasteDelegator(myProject, this) { @NotNull protected PsiElement[] getSelectedElements() { return getSelectedPsiElements(); } }; }