Search in sources :

Example 16 with TreeNode

use of javax.swing.tree.TreeNode in project intellij-community by JetBrains.

the class AbstractOpeningExpander method onAfterRefresh.

public void onAfterRefresh(final RepositoryTreeNode node) {
    myKeepingExpander.onAfterRefresh(node);
    if (node.isLeaf()) {
        return;
    }
    final String myUrl = node.getURL().toString();
    final ExpandVariants expandVariant = expandNode(myUrl);
    if (ExpandVariants.DO_NOTHING.equals(expandVariant)) {
        return;
    }
    // then expanded
    myBrowser.expandNode(node);
    if (ExpandVariants.EXPAND_AND_EXIT.equals(expandVariant)) {
        removeSelf();
    } else {
        final Enumeration children = node.children();
        while (children.hasMoreElements()) {
            final TreeNode treeNode = (TreeNode) children.nextElement();
            if (treeNode instanceof RepositoryTreeNode) {
                final RepositoryTreeNode repositoryTreeNode = (RepositoryTreeNode) treeNode;
                final String childUrl = repositoryTreeNode.getURL().toString();
                if (checkChild(childUrl)) {
                    if ((mySelectionPath != null) && (mySelectionPath.equals(childUrl))) {
                        myBrowser.setSelectedNode(repositoryTreeNode);
                    }
                    repositoryTreeNode.reload(this, false);
                    return;
                }
            }
        }
        removeSelf();
    }
}
Also used : Enumeration(java.util.Enumeration) RepositoryTreeNode(org.jetbrains.idea.svn.dialogs.RepositoryTreeNode) TreeNode(javax.swing.tree.TreeNode) RepositoryTreeNode(org.jetbrains.idea.svn.dialogs.RepositoryTreeNode)

Example 17 with TreeNode

use of javax.swing.tree.TreeNode in project intellij-community by JetBrains.

the class DynamicToolWindowWrapper method createTable.

private JScrollPane createTable(final MutableTreeNode myTreeRoot) {
    ColumnInfo[] columnInfos = { new ClassColumnInfo(myColumnNames[CLASS_OR_ELEMENT_NAME_COLUMN]), new PropertyTypeColumnInfo(myColumnNames[TYPE_COLUMN]) };
    myTreeTableModel = new ListTreeTableModelOnColumns(myTreeRoot, columnInfos);
    myTreeTable = new MyTreeTable(myTreeTableModel);
    new TreeTableSpeedSearch(myTreeTable, new Convertor<TreePath, String>() {

        @Override
        public String convert(TreePath o) {
            final Object node = o.getLastPathComponent();
            if (node instanceof DefaultMutableTreeNode) {
                final Object object = ((DefaultMutableTreeNode) node).getUserObject();
                if (object instanceof DNamedElement) {
                    return ((DNamedElement) object).getName();
                }
            }
            return "";
        }
    });
    DefaultActionGroup group = new DefaultActionGroup();
    group.add(ActionManager.getInstance().getAction(RemoveDynamicAction.GROOVY_DYNAMIC_REMOVE));
    PopupHandler.installUnknownPopupHandler(myTreeTable, group, ActionManager.getInstance());
    final MyColoredTreeCellRenderer treeCellRenderer = new MyColoredTreeCellRenderer();
    myTreeTable.setDefaultRenderer(String.class, new TableCellRenderer() {

        @Override
        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
            if (value instanceof String) {
                try {
                    final PsiType type = JavaPsiFacade.getElementFactory(myProject).createTypeFromText((String) value, null);
                    String shortName = type.getPresentableText();
                    return new JLabel(shortName);
                } catch (IncorrectOperationException e) {
                    LOG.debug("Type cannot be created", e);
                }
                return new JLabel(QuickfixUtil.shortenType((String) value));
            }
            return new JLabel();
        }
    });
    myTreeTable.setTreeCellRenderer(treeCellRenderer);
    myTreeTable.setRootVisible(false);
    myTreeTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    final MyPropertyTypeCellEditor typeCellEditor = new MyPropertyTypeCellEditor();
    typeCellEditor.addCellEditorListener(new CellEditorListener() {

        @Override
        public void editingStopped(ChangeEvent e) {
            final TreeTableTree tree = getTree();
            String newTypeValue = ((MyPropertyTypeCellEditor) e.getSource()).getCellEditorValue();
            if (newTypeValue == null || tree == null) {
                myTreeTable.editingStopped(e);
                return;
            }
            try {
                final PsiType type = JavaPsiFacade.getElementFactory(myProject).createTypeFromText(newTypeValue, null);
                String canonical = type.getCanonicalText();
                if (canonical != null)
                    newTypeValue = canonical;
            } catch (IncorrectOperationException ex) {
            //do nothing in case bad string is entered
            }
            final TreePath editingTypePath = tree.getSelectionPath();
            if (editingTypePath == null)
                return;
            final TreePath editingClassPath = editingTypePath.getParentPath();
            Object oldTypeValue = myTreeTable.getValueAt(tree.getRowForPath(editingTypePath), TYPE_COLUMN);
            if (!(oldTypeValue instanceof String)) {
                myTreeTable.editingStopped(e);
                return;
            }
            final Object editingPropertyObject = myTreeTable.getValueAt(tree.getRowForPath(editingTypePath), CLASS_OR_ELEMENT_NAME_COLUMN);
            final Object editingClassObject = myTreeTable.getValueAt(tree.getRowForPath(editingClassPath), CLASS_OR_ELEMENT_NAME_COLUMN);
            if (!(editingPropertyObject instanceof DItemElement) || !(editingClassObject instanceof DClassElement)) {
                myTreeTable.editingStopped(e);
                return;
            }
            final DItemElement dynamicElement = (DItemElement) editingPropertyObject;
            final String name = dynamicElement.getName();
            final String className = ((DClassElement) editingClassObject).getName();
            if (dynamicElement instanceof DPropertyElement) {
                DynamicManager.getInstance(myProject).replaceDynamicPropertyType(className, name, (String) oldTypeValue, newTypeValue);
            } else if (dynamicElement instanceof DMethodElement) {
                final List<ParamInfo> myPairList = ((DMethodElement) dynamicElement).getPairs();
                DynamicManager.getInstance(myProject).replaceDynamicMethodType(className, name, myPairList, (String) oldTypeValue, newTypeValue);
            }
        }

        @Override
        public void editingCanceled(ChangeEvent e) {
            myTreeTable.editingCanceled(e);
        }
    });
    RefactoringListenerManager.getInstance(myProject).addListenerProvider(new RefactoringElementListenerProvider() {

        @Override
        @Nullable
        public RefactoringElementListener getListener(final PsiElement element) {
            if (element instanceof PsiClass) {
                final String qualifiedName = ((PsiClass) element).getQualifiedName();
                return new RefactoringElementListener() {

                    @Override
                    public void elementMoved(@NotNull PsiElement newElement) {
                        renameElement(qualifiedName, newElement);
                    }

                    @Override
                    public void elementRenamed(@NotNull PsiElement newElement) {
                        renameElement(qualifiedName, newElement);
                    }

                    private void renameElement(String oldClassName, PsiElement newElement) {
                        if (newElement instanceof PsiClass) {
                            final String newClassName = ((PsiClass) newElement).getQualifiedName();
                            final DRootElement rootElement = DynamicManager.getInstance(myProject).getRootElement();
                            final DClassElement oldClassElement = rootElement.getClassElement(oldClassName);
                            final TreeNode oldClassNode = TreeUtil.findNodeWithObject((DefaultMutableTreeNode) myTreeRoot, oldClassElement);
                            DynamicManager.getInstance(myProject).replaceClassName(oldClassElement, newClassName);
                            myTreeTableModel.nodeChanged(oldClassNode);
                        }
                    }
                };
            }
            return null;
        }
    });
    myTreeTable.setDefaultEditor(String.class, typeCellEditor);
    myTreeTable.registerKeyboardAction(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent event) {
            final int selectionRow = myTreeTable.getTree().getLeadSelectionRow();
            myTreeTable.editCellAt(selectionRow, CLASS_OR_ELEMENT_NAME_COLUMN, event);
        }
    }, KeyStroke.getKeyStroke(KeyEvent.VK_F2, 0), JComponent.WHEN_FOCUSED);
    myTreeTable.registerKeyboardAction(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent event) {
            final int selectionRow = myTreeTable.getTree().getLeadSelectionRow();
            myTreeTable.editCellAt(selectionRow, TYPE_COLUMN, event);
        }
    }, KeyStroke.getKeyStroke(KeyEvent.VK_F2, InputEvent.CTRL_MASK), JComponent.WHEN_FOCUSED);
    myTreeTable.getTree().setShowsRootHandles(true);
    myTreeTable.getTableHeader().setReorderingAllowed(false);
    myTreeTable.setPreferredScrollableViewportSize(new Dimension(300, myTreeTable.getRowHeight() * 10));
    myTreeTable.getColumn(myColumnNames[CLASS_OR_ELEMENT_NAME_COLUMN]).setPreferredWidth(200);
    myTreeTable.getColumn(myColumnNames[TYPE_COLUMN]).setPreferredWidth(160);
    JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(myTreeTable);
    scrollPane.setPreferredSize(JBUI.size(600, 400));
    return scrollPane;
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) ActionEvent(java.awt.event.ActionEvent) ColumnInfo(com.intellij.util.ui.ColumnInfo) CellEditorListener(javax.swing.event.CellEditorListener) MutableTreeNode(javax.swing.tree.MutableTreeNode) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) TreeNode(javax.swing.tree.TreeNode) TreeTableTree(com.intellij.ui.treeStructure.treetable.TreeTableTree) TableCellRenderer(javax.swing.table.TableCellRenderer) ListTreeTableModelOnColumns(com.intellij.ui.treeStructure.treetable.ListTreeTableModelOnColumns) RefactoringElementListener(com.intellij.refactoring.listeners.RefactoringElementListener) TreePath(javax.swing.tree.TreePath) ChangeEvent(javax.swing.event.ChangeEvent) RefactoringElementListenerProvider(com.intellij.refactoring.listeners.RefactoringElementListenerProvider) ActionListener(java.awt.event.ActionListener) IncorrectOperationException(com.intellij.util.IncorrectOperationException) Nullable(org.jetbrains.annotations.Nullable)

Example 18 with TreeNode

use of javax.swing.tree.TreeNode in project intellij-community by JetBrains.

the class SvnMergeSourceDetails method addRecursively.

private void addRecursively(final SvnFileRevision revision, final MyNode node, final List<TreePath> nodesToExpand) {
    final MyNode current = new MyNode(new MyNamedConfigurable(revision, myFile, myProject, myListsMap));
    node.add(current);
    final TreeNode[] path = ((DefaultTreeModel) myTree.getModel()).getPathToRoot(node);
    nodesToExpand.add(new TreePath(path));
    final List<SvnFileRevision> mergeSources = revision.getMergeSources();
    for (SvnFileRevision source : mergeSources) {
        addRecursively(source, current, nodesToExpand);
    }
}
Also used : TreePath(javax.swing.tree.TreePath) TreeNode(javax.swing.tree.TreeNode) DefaultTreeModel(javax.swing.tree.DefaultTreeModel)

Example 19 with TreeNode

use of javax.swing.tree.TreeNode in project zaproxy by zaproxy.

the class JCheckBoxTree method addSubtreeToCheckingStateTracking.

// Creating data structure of the current model for the checking mechanism
private void addSubtreeToCheckingStateTracking(DefaultMutableTreeNode node) {
    TreeNode[] path = node.getPath();
    TreePath tp = new TreePath(path);
    CheckedNode cn = new CheckedNode(false, node.getChildCount() > 0, false);
    nodesCheckingState.put(tp, cn);
    for (int i = 0; i < node.getChildCount(); i++) {
        addSubtreeToCheckingStateTracking((DefaultMutableTreeNode) tp.pathByAddingChild(node.getChildAt(i)).getLastPathComponent());
    }
}
Also used : TreePath(javax.swing.tree.TreePath) TreeNode(javax.swing.tree.TreeNode) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode)

Example 20 with TreeNode

use of javax.swing.tree.TreeNode in project zaproxy by zaproxy.

the class NodeSelectDialog method showDialog.

public SiteNode showDialog(SiteNode defaultNode) {
    // Assume Contexts cant be selected
    this.getTreeContext().setVisible(false);
    SiteNode siteRoot = (SiteNode) Model.getSingleton().getSession().getSiteTree().getRoot();
    populateNode(siteRoot, (SiteNode) this.siteTree.getRoot(), defaultNode);
    if (selectedSiteNode != null) {
        // Found the default node, select it
        TreePath path = new TreePath(this.siteTree.getPathToRoot(selectedSiteNode));
        this.getTreeSite().setExpandsSelectedPaths(true);
        this.getTreeSite().setSelectionPath(path);
        this.getTreeSite().scrollPathToVisible(path);
        this.getTreeSite().expandPath(path);
    } else {
        // no default path, just expand the top level
        TreePath path = new TreePath(this.siteTree.getPathToRoot((TreeNode) this.siteTree.getRoot()));
        this.getTreeSite().expandPath(path);
    }
    this.setVisible(true);
    // The dialog is modal so this wont return until the dialog visibility is unset
    return selectedSiteNode;
}
Also used : TreePath(javax.swing.tree.TreePath) TreeNode(javax.swing.tree.TreeNode) SiteNode(org.parosproxy.paros.model.SiteNode)

Aggregations

TreeNode (javax.swing.tree.TreeNode)149 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)74 TreePath (javax.swing.tree.TreePath)56 Nullable (org.jetbrains.annotations.Nullable)20 DefaultTreeModel (javax.swing.tree.DefaultTreeModel)12 ArrayList (java.util.ArrayList)10 Enumeration (java.util.Enumeration)10 NotNull (org.jetbrains.annotations.NotNull)10 MutableTreeNode (javax.swing.tree.MutableTreeNode)8 JTree (javax.swing.JTree)7 JMeterTreeNode (org.apache.jmeter.gui.tree.JMeterTreeNode)6 AbstractTreeNode (com.intellij.ide.util.treeView.AbstractTreeNode)4 Project (com.intellij.openapi.project.Project)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 CheckedTreeNode (com.intellij.ui.CheckedTreeNode)4 Tree (com.intellij.ui.treeStructure.Tree)4 Point (java.awt.Point)4 File (java.io.File)4 AllIcons (com.intellij.icons.AllIcons)3 Pair (com.intellij.openapi.util.Pair)3