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; }
public InspectionTree(final Project project) { super(new InspectionRootNode(project)); setCellRenderer(new CellRenderer()); // project)); setShowsRootHandles(true); UIUtil.setLineStyleAngled(this); addTreeWillExpandListener(new ExpandListener()); myExpandedUserObjects = new HashSet<Object>(); myExpandedUserObjects.add(project); TreeUtil.installActions(this); new TreeSpeedSearch( this, new Convertor<TreePath, String>() { @Override public String convert(TreePath o) { return InspectionsConfigTreeComparator.getDisplayTextToSort( o.getLastPathComponent().toString()); } }); addTreeSelectionListener( new TreeSelectionListener() { @Override public void valueChanged(TreeSelectionEvent e) { TreePath newSelection = e.getNewLeadSelectionPath(); if (newSelection != null) { mySelectionPath = new SelectionPath(newSelection); } } }); }
protected void initTree() { ((DefaultTreeModel) myTree.getModel()).setRoot(myRoot); myTree.setRootVisible(false); myTree.setShowsRootHandles(true); UIUtil.setLineStyleAngled(myTree); TreeUtil.installActions(myTree); myTree.setCellRenderer( new ColoredTreeCellRenderer() { public void customizeCellRenderer( JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) { if (value instanceof MyNode) { final MyNode node = ((MyNode) value); setIcon(node.getIcon(expanded)); final Font font = UIUtil.getTreeFont(); if (node.isDisplayInBold()) { setFont(font.deriveFont(Font.BOLD)); } else { setFont(font.deriveFont(Font.PLAIN)); } append( node.getDisplayName(), node.isDisplayInBold() ? SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES : SimpleTextAttributes.REGULAR_ATTRIBUTES); } } }); initToolbar(); ArrayList<AnAction> actions = createActions(true); if (actions != null) { final DefaultActionGroup group = new DefaultActionGroup(); for (AnAction action : actions) { group.add(action); } actions = getAdditionalActions(); if (actions != null) { group.addSeparator(); for (AnAction action : actions) { group.add(action); } } PopupHandler.installPopupHandler( myTree, group, ActionPlaces.UNKNOWN, ActionManager.getInstance()); // popup should follow the selection } }
private void initTree(final MyTree tree, boolean isRightTree) { tree.setCellRenderer(new MyTreeCellRenderer()); tree.setRootVisible(false); tree.setShowsRootHandles(true); UIUtil.setLineStyleAngled(tree); TreeUtil.installActions(tree); SmartExpander.installOn(tree); EditSourceOnDoubleClickHandler.install(tree); new TreeSpeedSearch(tree); PopupHandler.installUnknownPopupHandler( tree, createTreePopupActions(isRightTree), ActionManager.getInstance()); }
public JsonTreeTableView(TreeNode rootNode, ColumnInfo[] columnInfos) { super(new ListTreeTableModelOnColumns(rootNode, columnInfos)); this.columns = columnInfos; final TreeTableTree tree = getTree(); tree.setShowsRootHandles(true); tree.setRootVisible(false); UIUtil.setLineStyleAngled(tree); setTreeCellRenderer(new KeyCellRenderer()); TreeUtil.expand(tree, 2); new TreeTableSpeedSearch( this, new Convertor<TreePath, String>() { @Override public String convert(final TreePath path) { final NoSqlTreeNode node = (NoSqlTreeNode) path.getLastPathComponent(); NodeDescriptor descriptor = node.getDescriptor(); return descriptor.getFormattedKey(); } }); }
@Override protected JComponent createCenterPanel() { final DefaultTreeModel model = new DefaultTreeModel(new DefaultMutableTreeNode()); myTree = new Tree(model); ProjectAbstractTreeStructureBase treeStructure = new AbstractProjectTreeStructure(myProject) { @Override public boolean isFlattenPackages() { return false; } @Override public boolean isShowMembers() { return myIsShowMembers; } @Override public boolean isHideEmptyMiddlePackages() { return true; } @Override public boolean isAbbreviatePackageNames() { return false; } @Override public boolean isShowLibraryContents() { return myIsShowLibraryContents; } @Override public boolean isShowModules() { return false; } }; myBuilder = new ProjectTreeBuilder(myProject, myTree, model, AlphaComparator.INSTANCE, treeStructure); myTree.setRootVisible(false); myTree.setShowsRootHandles(true); myTree.expandRow(0); myTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); myTree.setCellRenderer(new NodeRenderer()); UIUtil.setLineStyleAngled(myTree); JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(myTree); scrollPane.setPreferredSize(new Dimension(500, 300)); myTree.addKeyListener( new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { if (KeyEvent.VK_ENTER == e.getKeyCode()) { doOKAction(); } } }); new DoubleClickListener() { @Override protected boolean onDoubleClick(MouseEvent event) { TreePath path = myTree.getPathForLocation(event.getX(), event.getY()); if (path != null && myTree.isPathSelected(path)) { doOKAction(); return true; } return false; } }.installOn(myTree); myTree.addTreeSelectionListener( new TreeSelectionListener() { @Override public void valueChanged(TreeSelectionEvent e) { handleSelectionChanged(); } }); new TreeSpeedSearch(myTree); myTabbedPane = new TabbedPaneWrapper(getDisposable()); final JPanel dummyPanel = new JPanel(new BorderLayout()); String name = null; /* if (myInitialClass != null) { name = myInitialClass.getName(); } */ myGotoByNamePanel = new ChooseByNamePanel( myProject, createChooseByNameModel(), name, myScope.isSearchInLibraries(), getContext()) { @Override protected void showTextFieldPanel() {} @Override protected void close(boolean isOk) { super.close(isOk); if (isOk) { doOKAction(); } else { doCancelAction(); } } @NotNull @Override protected Set<Object> filter(@NotNull Set<Object> elements) { return doFilter(elements); } @Override protected void initUI( ChooseByNamePopupComponent.Callback callback, ModalityState modalityState, boolean allowMultipleSelection) { super.initUI(callback, modalityState, allowMultipleSelection); dummyPanel.add(myGotoByNamePanel.getPanel(), BorderLayout.CENTER); IdeFocusTraversalPolicy.getPreferredFocusedComponent(myGotoByNamePanel.getPanel()) .requestFocus(); } @Override protected void showList() { super.showList(); if (myInitialClass != null && myList.getModel().getSize() > 0) { myList.setSelectedValue(myInitialClass, true); myInitialClass = null; } } @Override protected void chosenElementMightChange() { handleSelectionChanged(); } }; Disposer.register(myDisposable, myGotoByNamePanel); myTabbedPane.addTab(IdeBundle.message("tab.chooser.search.by.name"), dummyPanel); myTabbedPane.addTab(IdeBundle.message("tab.chooser.project"), scrollPane); myGotoByNamePanel.invoke(new MyCallback(), getModalityState(), false); myTabbedPane.addChangeListener( new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { handleSelectionChanged(); } }); return myTabbedPane.getComponent(); }
public CustomizableActionsPanel() { //noinspection HardCodedStringLiteral Group rootGroup = new Group("root", null, null); final DefaultMutableTreeNode root = new DefaultMutableTreeNode(rootGroup); DefaultTreeModel model = new DefaultTreeModel(root); myActionsTree.setModel(model); myActionsTree.setRootVisible(false); myActionsTree.setShowsRootHandles(true); UIUtil.setLineStyleAngled(myActionsTree); myActionsTree.setCellRenderer(new MyTreeCellRenderer()); setButtonsDisabled(); final ActionManager actionManager = ActionManager.getInstance(); myActionsTree .getSelectionModel() .addTreeSelectionListener( new TreeSelectionListener() { public void valueChanged(TreeSelectionEvent e) { final TreePath[] selectionPaths = myActionsTree.getSelectionPaths(); final boolean isSingleSelection = selectionPaths != null && selectionPaths.length == 1; myAddActionButton.setEnabled(isSingleSelection); if (isSingleSelection) { final DefaultMutableTreeNode node = (DefaultMutableTreeNode) selectionPaths[0].getLastPathComponent(); String actionId = getActionId(node); if (actionId != null) { final AnAction action = actionManager.getAction(actionId); myEditIconButton.setEnabled( action != null && action.getTemplatePresentation() != null); } else { myEditIconButton.setEnabled(false); } } else { myEditIconButton.setEnabled(false); } myAddSeparatorButton.setEnabled(isSingleSelection); myRemoveActionButton.setEnabled(selectionPaths != null); if (selectionPaths != null) { for (TreePath selectionPath : selectionPaths) { if (selectionPath.getPath() != null && selectionPath.getPath().length <= 2) { setButtonsDisabled(); return; } } } myMoveActionUpButton.setEnabled(isMoveSupported(myActionsTree, -1)); myMoveActionDownButton.setEnabled(isMoveSupported(myActionsTree, 1)); myRestoreDefaultButton.setEnabled(!findActionsUnderSelection().isEmpty()); } }); myAddActionButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { final List<TreePath> expandedPaths = TreeUtil.collectExpandedPaths(myActionsTree); final TreePath selectionPath = myActionsTree.getLeadSelectionPath(); if (selectionPath != null) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) selectionPath.getLastPathComponent(); final FindAvailableActionsDialog dlg = new FindAvailableActionsDialog(); dlg.show(); if (dlg.isOK()) { final Set<Object> toAdd = dlg.getTreeSelectedActionIds(); if (toAdd == null) return; for (final Object o : toAdd) { final ActionUrl url = new ActionUrl( ActionUrl.getGroupPath(new TreePath(node.getPath())), o, ActionUrl.ADDED, node.getParent().getIndex(node) + 1); addCustomizedAction(url); ActionUrl.changePathInActionsTree(myActionsTree, url); if (o instanceof String) { DefaultMutableTreeNode current = new DefaultMutableTreeNode(url.getComponent()); current.setParent((DefaultMutableTreeNode) node.getParent()); editToolbarIcon((String) o, current); } } ((DefaultTreeModel) myActionsTree.getModel()).reload(); } } TreeUtil.restoreExpandedPaths(myActionsTree, expandedPaths); } }); myEditIconButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { myRestoreAllDefaultButton.setEnabled(true); final List<TreePath> expandedPaths = TreeUtil.collectExpandedPaths(myActionsTree); final TreePath selectionPath = myActionsTree.getLeadSelectionPath(); if (selectionPath != null) { EditIconDialog dlg = new EditIconDialog((DefaultMutableTreeNode) selectionPath.getLastPathComponent()); dlg.show(); if (dlg.isOK()) { myActionsTree.repaint(); } } TreeUtil.restoreExpandedPaths(myActionsTree, expandedPaths); } }); myAddSeparatorButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { final List<TreePath> expandedPaths = TreeUtil.collectExpandedPaths(myActionsTree); final TreePath selectionPath = myActionsTree.getLeadSelectionPath(); if (selectionPath != null) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) selectionPath.getLastPathComponent(); final ActionUrl url = new ActionUrl( ActionUrl.getGroupPath(selectionPath), Separator.getInstance(), ActionUrl.ADDED, node.getParent().getIndex(node) + 1); ActionUrl.changePathInActionsTree(myActionsTree, url); addCustomizedAction(url); ((DefaultTreeModel) myActionsTree.getModel()).reload(); } TreeUtil.restoreExpandedPaths(myActionsTree, expandedPaths); } }); myRemoveActionButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { final List<TreePath> expandedPaths = TreeUtil.collectExpandedPaths(myActionsTree); final TreePath[] selectionPath = myActionsTree.getSelectionPaths(); if (selectionPath != null) { for (TreePath treePath : selectionPath) { final ActionUrl url = CustomizationUtil.getActionUrl(treePath, ActionUrl.DELETED); ActionUrl.changePathInActionsTree(myActionsTree, url); addCustomizedAction(url); } ((DefaultTreeModel) myActionsTree.getModel()).reload(); } TreeUtil.restoreExpandedPaths(myActionsTree, expandedPaths); } }); myMoveActionUpButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { final List<TreePath> expandedPaths = TreeUtil.collectExpandedPaths(myActionsTree); final TreePath[] selectionPath = myActionsTree.getSelectionPaths(); if (selectionPath != null) { for (TreePath treePath : selectionPath) { final ActionUrl url = CustomizationUtil.getActionUrl(treePath, ActionUrl.MOVE); final int absolutePosition = url.getAbsolutePosition(); url.setInitialPosition(absolutePosition); url.setAbsolutePosition(absolutePosition - 1); ActionUrl.changePathInActionsTree(myActionsTree, url); addCustomizedAction(url); } ((DefaultTreeModel) myActionsTree.getModel()).reload(); TreeUtil.restoreExpandedPaths(myActionsTree, expandedPaths); for (TreePath path : selectionPath) { myActionsTree.addSelectionPath(path); } } } }); myMoveActionDownButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { final List<TreePath> expandedPaths = TreeUtil.collectExpandedPaths(myActionsTree); final TreePath[] selectionPath = myActionsTree.getSelectionPaths(); if (selectionPath != null) { for (int i = selectionPath.length - 1; i >= 0; i--) { TreePath treePath = selectionPath[i]; final ActionUrl url = CustomizationUtil.getActionUrl(treePath, ActionUrl.MOVE); final int absolutePosition = url.getAbsolutePosition(); url.setInitialPosition(absolutePosition); url.setAbsolutePosition(absolutePosition + 1); ActionUrl.changePathInActionsTree(myActionsTree, url); addCustomizedAction(url); } ((DefaultTreeModel) myActionsTree.getModel()).reload(); TreeUtil.restoreExpandedPaths(myActionsTree, expandedPaths); for (TreePath path : selectionPath) { myActionsTree.addSelectionPath(path); } } } }); myRestoreAllDefaultButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { mySelectedSchema.copyFrom(new CustomActionsSchema()); patchActionsTreeCorrespondingToSchema(root); myRestoreAllDefaultButton.setEnabled(false); } }); myRestoreDefaultButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { final List<ActionUrl> otherActions = new ArrayList<ActionUrl>(mySelectedSchema.getActions()); otherActions.removeAll(findActionsUnderSelection()); mySelectedSchema.copyFrom(new CustomActionsSchema()); for (ActionUrl otherAction : otherActions) { mySelectedSchema.addAction(otherAction); } final List<TreePath> treePaths = TreeUtil.collectExpandedPaths(myActionsTree); patchActionsTreeCorrespondingToSchema(root); restorePathsAfterTreeOptimization(treePaths); myRestoreDefaultButton.setEnabled(false); } }); patchActionsTreeCorrespondingToSchema(root); myTreeExpansionMonitor = TreeExpansionMonitor.install(myActionsTree); }
@NotNull private JTree createTree() { DefaultMutableTreeNode root = new DefaultMutableTreeNode(); final Tree tree = new Tree(new DefaultTreeModel(root)) /* { @Override protected void paintComponent(Graphics g) { DuplicateNodeRenderer.paintDuplicateNodesBackground(g, this); super.paintComponent(g); } }*/; tree.setOpaque(false); tree.setToggleClickCount(-1); SliceUsageCellRenderer renderer = new SliceUsageCellRenderer(); renderer.setOpaque(false); tree.setCellRenderer(renderer); UIUtil.setLineStyleAngled(tree); tree.setRootVisible(false); tree.setShowsRootHandles(true); tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); tree.setSelectionPath(new TreePath(root.getPath())); // ActionGroup group = // (ActionGroup)ActionManager.getInstance().getAction(IdeActions.GROUP_METHOD_HIERARCHY_POPUP); // PopupHandler.installPopupHandler(tree, group, ActionPlaces.METHOD_HIERARCHY_VIEW_POPUP, // ActionManager.getInstance()); EditSourceOnDoubleClickHandler.install(tree); new TreeSpeedSearch(tree); TreeUtil.installActions(tree); ToolTipManager.sharedInstance().registerComponent(tree); myAutoScrollToSourceHandler.install(tree); tree.getSelectionModel() .addTreeSelectionListener( new TreeSelectionListener() { @Override public void valueChanged(final TreeSelectionEvent e) { treeSelectionChanged(); } }); tree.addKeyListener( new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { if (KeyEvent.VK_ENTER == e.getKeyCode()) { List<Navigatable> navigatables = getNavigatables(); if (navigatables.isEmpty()) return; for (Navigatable navigatable : navigatables) { if (navigatable instanceof AbstractTreeNode && ((AbstractTreeNode) navigatable).getValue() instanceof Usage) { navigatable = (Usage) ((AbstractTreeNode) navigatable).getValue(); } if (navigatable.canNavigateToSource()) { navigatable.navigate(false); if (navigatable instanceof Usage) { ((Usage) navigatable).highlightInEditor(); } } } e.consume(); } } }); tree.addTreeWillExpandListener( new TreeWillExpandListener() { @Override public void treeWillCollapse(TreeExpansionEvent event) {} @Override public void treeWillExpand(TreeExpansionEvent event) { TreePath path = event.getPath(); SliceNode node = fromPath(path); node.calculateDupNode(); } }); return tree; }
protected JComponent createCenterPanel() { JPanel panel = new JPanel(); panel.setLayout(new BorderLayout()); myModel = new DefaultTreeModel(new DefaultMutableTreeNode()); createTreeModel(); myTree = new Tree(myModel); UIUtil.setLineStyleAngled(myTree); myTree.setCellRenderer( new DefaultTreeCellRenderer() { public Component getTreeCellRendererComponent( JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) { super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus); setIcon(expanded ? Icons.PACKAGE_OPEN_ICON : Icons.PACKAGE_ICON); if (value instanceof DefaultMutableTreeNode) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) value; Object object = node.getUserObject(); if (object instanceof PsiPackage) { String name = ((PsiPackage) object).getName(); if (name != null && name.length() > 0) { setText(name); } else { setText(IdeBundle.message("node.default")); } } } return this; } }); myTree.setBorder(BorderFactory.createEtchedBorder()); JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(myTree); scrollPane.setPreferredSize(new Dimension(500, 300)); new TreeSpeedSearch( myTree, new Convertor<TreePath, String>() { public String convert(TreePath path) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent(); Object object = node.getUserObject(); if (object instanceof PsiPackage) return ((PsiPackage) object).getName(); else return ""; } }); myTree .getSelectionModel() .addTreeSelectionListener( new TreeSelectionListener() { public void valueChanged(TreeSelectionEvent e) { PsiPackage selection = getTreeSelection(); if (selection != null) { String name = selection.getQualifiedName(); setTitle( myTitle + " - " + ("".equals(name) ? IdeBundle.message("node.default.package") : name)); } else { setTitle(myTitle); } } }); panel.add(scrollPane, BorderLayout.CENTER); DefaultActionGroup group = createActionGroup(myTree); ActionToolbar toolBar = ActionManager.getInstance().createActionToolbar(ActionPlaces.UNKNOWN, group, true); panel.add(toolBar.getComponent(), BorderLayout.NORTH); toolBar.getComponent().setAlignmentX(JComponent.LEFT_ALIGNMENT); return panel; }
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(); } }; }