Search in sources :

Example 91 with DefaultMutableTreeNode

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

the class ComponentTree method getSelectedComponents.

/**
   * TODO[vova] should return pair <RadComponent, TreePath>
   *
   * @return currently selected components.
   */
@NotNull
public RadComponent[] getSelectedComponents() {
    final TreePath[] paths = getSelectionPaths();
    if (paths == null) {
        return RadComponent.EMPTY_ARRAY;
    }
    final ArrayList<RadComponent> result = new ArrayList<>(paths.length);
    for (TreePath path : paths) {
        final DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
        if (node != null && node.getUserObject() instanceof ComponentPtrDescriptor) {
            final ComponentPtrDescriptor descriptor = (ComponentPtrDescriptor) node.getUserObject();
            final ComponentPtr ptr = descriptor.getElement();
            if (ptr != null && ptr.isValid()) {
                result.add(ptr.getComponent());
            }
        }
    }
    return result.toArray(new RadComponent[result.size()]);
}
Also used : TreePath(javax.swing.tree.TreePath) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) NotNull(org.jetbrains.annotations.NotNull)

Example 92 with DefaultMutableTreeNode

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

the class ZapTocMerger method processMerge.

/**
     * Processes unite-append merge
     * 
     * @param node The master node
     * @return Merged master node
     */
// Note: the implementation and JavaDoc has been copied (verbatim) from the base method to call the method
// ZapTocMerger#mergeNodes(TreeNode, TreeNode) instead of UniteAppendMerge#mergeNodes(TreeNode, TreeNode).
@Override
public TreeNode processMerge(TreeNode node) {
    DefaultMutableTreeNode masterNode = (DefaultMutableTreeNode) node;
    // masterNode
    if (masterNode.equals(slaveTopNode)) {
        return masterNode;
    }
    // masterNode
    if (slaveTopNode.getChildCount() == 0) {
        return masterNode;
    }
    mergeNodes(masterNode, slaveTopNode);
    return masterNode;
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode)

Example 93 with DefaultMutableTreeNode

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

the class ZapTocMerger method mergeNodes.

/**
     * Merge Nodes. Merge two nodes according to the merging rules of the masterNode. Each Subclass should override this
     * implementation.
     * 
     * @param master The master node to merge with
     * @param slave The node to merge into the master
     */
// Note: the implementation and JavaDoc has been copied (verbatim) from UniteAppendMerge#mergeNodes(TreeNode, TreeNode)
// except for the call to doCustomMerge(DefaultMutableTreeNode, DefaultMutableTreeNode) and the calls to
// MergeHelpUtilities.mergeNode* which is set, using DEFAULT_MERGE_TYPE, to merge with this class instead.
public static void mergeNodes(TreeNode master, TreeNode slave) {
    DefaultMutableTreeNode masterNode = (DefaultMutableTreeNode) master;
    DefaultMutableTreeNode slaveNode = (DefaultMutableTreeNode) slave;
    int masterCnt = masterNode.getChildCount();
    // loop thru the slaves
    while (slaveNode.getChildCount() > 0) {
        DefaultMutableTreeNode slaveNodeChild = (DefaultMutableTreeNode) slaveNode.getFirstChild();
        // loop thru the master children
        for (int m = 0; m < masterCnt; m++) {
            DefaultMutableTreeNode masterAtM = (DefaultMutableTreeNode) masterNode.getChildAt(m);
            if (doCustomMerge(slaveNodeChild, masterAtM)) {
                slaveNodeChild = null;
                break;
            }
            // see if the names are the same
            if (MergeHelpUtilities.compareNames(masterAtM, slaveNodeChild) == 0) {
                if (MergeHelpUtilities.haveEqualID(masterAtM, slaveNodeChild)) {
                    // ID and name the same merge the slave node in
                    MergeHelpUtilities.mergeNodes(DEFAULT_MERGE_TYPE, masterAtM, slaveNodeChild);
                    // Need to remove the slaveNodeChild from the list
                    slaveNodeChild.removeFromParent();
                    slaveNodeChild = null;
                    break;
                }
                // Names are the same but the ID are not
                // Mark the nodes and add the slaveChild
                MergeHelpUtilities.markNodes(masterAtM, slaveNodeChild);
                masterNode.add(slaveNodeChild);
                MergeHelpUtilities.mergeNodeChildren(DEFAULT_MERGE_TYPE, slaveNodeChild);
                slaveNodeChild = null;
                break;
            }
        }
        if (slaveNodeChild != null) {
            masterNode.add(slaveNodeChild);
            MergeHelpUtilities.mergeNodeChildren(DEFAULT_MERGE_TYPE, slaveNodeChild);
        }
    }
    // There are no more children.
    // Remove slaveNode from it's parent
    slaveNode.removeFromParent();
    slaveNode = null;
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode)

Example 94 with DefaultMutableTreeNode

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

the class ZapTocView method getDataAsTree.

// Note: The implementation has been copied (verbatim) from the base method except for the use of a custom TreeItemFactory.
@Override
public DefaultMutableTreeNode getDataAsTree() {
    HelpSet hs = getHelpSet();
    Hashtable<?, ?> params = getParameters();
    URL url;
    if (params == null || !params.containsKey("data")) {
        DefaultMutableTreeNode node = new DefaultMutableTreeNode();
        return node;
    }
    try {
        url = new URL(hs.getHelpSetURL(), (String) params.get("data"));
    } catch (Exception ex) {
        throw new Error("Trouble getting URL to TOC data; " + ex);
    }
    return parse(url, hs, hs.getLocale(), new TreeItemFactoryImpl(), this);
}
Also used : HelpSet(javax.help.HelpSet) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) URL(java.net.URL) BadIDException(javax.help.BadIDException)

Example 95 with DefaultMutableTreeNode

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

the class DynamicManagerImpl method removeClassFromTree.

private void removeClassFromTree(DClassElement classElement) {
    DynamicToolWindowWrapper wrapper = DynamicToolWindowWrapper.getInstance(myProject);
    ListTreeTableModelOnColumns model = wrapper.getTreeTableModel();
    final DefaultMutableTreeNode node = (DefaultMutableTreeNode) TreeUtil.findNodeWithObject(classElement, model, model.getRoot());
    if (node == null)
        return;
    DefaultMutableTreeNode parent = (DefaultMutableTreeNode) node.getParent();
    doRemove(wrapper, node, parent);
}
Also used : ListTreeTableModelOnColumns(com.intellij.ui.treeStructure.treetable.ListTreeTableModelOnColumns) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode)

Aggregations

DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)692 TreePath (javax.swing.tree.TreePath)185 DefaultTreeModel (javax.swing.tree.DefaultTreeModel)98 ArrayList (java.util.ArrayList)51 Nullable (org.jetbrains.annotations.Nullable)50 TreeNode (javax.swing.tree.TreeNode)42 Test (org.junit.Test)39 JTree (javax.swing.JTree)38 NotNull (org.jetbrains.annotations.NotNull)32 VirtualFile (com.intellij.openapi.vfs.VirtualFile)28 JScrollPane (javax.swing.JScrollPane)25 TreeSelectionEvent (javax.swing.event.TreeSelectionEvent)23 TreeSelectionListener (javax.swing.event.TreeSelectionListener)23 Module (com.intellij.openapi.module.Module)20 File (java.io.File)20 Tree (com.intellij.ui.treeStructure.Tree)19 Enumeration (java.util.Enumeration)19 MouseEvent (java.awt.event.MouseEvent)18 IOException (java.io.IOException)17 MProduct (org.compiere.model.MProduct)17