JTree - with two tree Models

I have two types of tree Models that I would like to combine into one tree i did the combination this way:
public CombainedTreeModel(BaseTreeModel firstSubTree,BaseTreeModel secondSubTree) {
super(null);
BaseTreeNode root=new BaseTreeNode("root");
insertNodeInto(firstSubTree.getTreeRoot(),root,GuiConstants.INDEX_ZERO);
insertNodeInto(secondSubTree.getTreeRoot(),root,GuiConstants.INDEX_ONE);
and used the combined model (that is extends of BaseTreeModel -> DefaultTreeModel.) as the input of the tree.
I see that there are elements in the tree but they are not visible.....
what is the problem?

I had a bit different interpertation for the MVC in swing:
model - is a pure java class holds the data
control- the treeModel that pass the commands to the model and after the comand was done - remove/add/update node from the tree and commite reload so the view will be refreshed
view - the Jtree
Everything in this model used to be ok until i combined two tree model to a third model so they will be displayed together.
this is how I remove a node:
public void removeContentServer(int contentServerId) throws BitBandGuiRemoveException, BitBandGuiFindException {
if (logger.isDebugEnabled())
logger.debug("ContentTreeModel.removeContentServer");
BaseContentTreeNode contentServerNode = getContentServerNode(contentServerId);
networkModel.removeContentServer(contentServerId);
contentServerNode.removeFromParent();
if (logger.isDebugEnabled()) {
logger.debug("remove content server from the model" + contentServerId);
synchronized (contentServerNode) {
contentServerNode.removeFromParent();
if (logger.isDebugEnabled()) {
logger.debug("remove content server from the tree model");
reload(root);
}

Similar Messages

  • Demantra - can it run with two Data Models in parallel?

    Hello,
    we face the following situation: we have items that have to planned on a daily basis; many other items, however, only need weekly planning.
    Demantra only allows one base time unit in its data model. If we choose "daily" for all products, the system size will increase enormously.
    If we choose "weekly" for all products, we can not plan our daily products for specific days in the week.
    The idea is now to set up a Demantra System with two data models in parallel. Is this possible? Would they reside in different databases or database users?
    The Business Modeller allows to create new models, but can they run in parallel? If they can, how would the user access the different data models?
    Thanks for any hints on this! 

    Can you please elaborate on this issue?
    Thanks

  • GW Messenger with two trees

    Hi,
    I have two trees with a Messenger system.
    Is it possible to communicate between people in two trees with GroupWise Messenger?
    Is it possible to link the two systems like GroupWise?
    Or can GroupWise Messenger system authenticate users from two LDAP sources?

    Aanthonisse,
    It appears that in the past few days you have not received a response to your
    posting. That concerns us, and has triggered this automated reply.
    Has your problem been resolved? If not, you might try one of the following options:
    - Visit http://support.novell.com and search the knowledgebase and/or check all
    the other self support options and support programs available.
    - You could also try posting your message again. Make sure it is posted in the
    correct newsgroup. (http://forums.novell.com)
    Be sure to read the forum FAQ about what to expect in the way of responses:
    http://forums.novell.com/faq.php
    If this is a reply to a duplicate posting, please ignore and accept our apologies
    and rest assured we will issue a stern reprimand to our posting bot.
    Good luck!
    Your Novell Product Support Forums Team
    http://support.novell.com/forums/

  • Column selection with column tree model

    Hello!
    I created a column tree model. I would like to be able to select a column when i click on its header. How can I do that? There is no problem to select one item. I try to select all the items of a column but if do that this is the lines which are selected. The item_selection parameter is set to 'X'.
    Thanks in advance,

    Hi,
    I am not sure if I understood your problem right. But just in case, if you are referring to this...
    You say you need a check box to select your nodes. So you would have to add your item names in a separate column and then add the check box in a separate column using ADD_COLUMN method. You would have to use treemcitac structure and make use of ADD_ITEMS to add them.
    Once you add the column for check box, code your logic and build your tree hierarchy with all the correct node keys. For example, the root node will have node_key = 1 and parent_key = 0. The node that comes under the root node in the first hierarchy level will have node_key = 2 and parent_key = 1. Code your logic so that you build your tree hierarchy.
    Build the tree structure using treemcnota as you have done. Add the nodes built using treemcnota using ADD_NODES.
    According to your requirement,
    COL1                                                                           COL2 (for checkbox)  } -> Build using treemcitac
    Preimport (Root)  -> Root Node
    Request Checks (Node_1)  -> parent_key = Preimport
    Check Req Status (Item_1) -> parent_key = Request Checks (Node_1)
    Check Req Scope (Item_2)
    Check Req Componenets (Item_3)
    Object List Checks (Node_2)
    Check obj type (Item_1)
    check deletions (Item_2)
    Object Checks (Node_3)
    "Build the tree nodes using treemcnota and add these nodes using ADD_NODES
    Again, I am not sure if your problem is this. Hope this might be helpful.

  • ALVOOPS with Two Tree display not clearing the prevoious fetched data

    I have screen 2000 (Main tree) and 3000 (Sub tree). From main tree an item is double click the corresponding item id is to be taken and populate the data based on the id and display in second Sub tree. I did the process.
    My problem is
    1st time the data is populating.
    2nd time fetching the 2nd id then process and creating the second tree data
    But finally display the 1st data
    I tried using Delete_all_node, cleared the table, free the container but no use
    Please help me.
    Regards,
    Anand Babu R

    I have screen 2000 (Main tree) and 3000 (Sub tree). From main tree an item is double click the corresponding item id is to be taken and populate the data based on the id and display in second Sub tree. I did the process.
    My problem is
    1st time the data is populating.
    2nd time fetching the 2nd id then process and creating the second tree data
    But finally display the 1st data
    I tried using Delete_all_node, cleared the table, free the container but no use
    Please help me.
    Regards,
    Anand Babu R

  • Can I use an universal infrarot remote control? Menue security says yes, you can use every bla bla, but i tried my luck with two different models, no funktion!

    Hello from Germany,
    I bought an cheap universal remote control (infrarot) because apple says...you can use every infrarot remote control, but no! No function.
    It doesn't work, mh! It is necessary to by the apple product or not, I don't want to waste my time with a wrong information.
    Thank you for answering

    http://store.apple.com/us/product/MC377LL/A

  • Error in drag and drop with a Tree component

    Hello, everybody.
    I'm doing a drag and drop with two trees.
    But, when I drag from a tree to another show this error:
    "oracle.job.RowNotFoundException:JBO25020: View line of oracle.jbo.Key[4.4] key not found in ViewTreeNodeRepository13_71."
    Besides that, in my property SelectionListerner, when I have this line: "#{bindings.TreeNodeRepository.treeModel.makeCurrent}" there is a warning that says: "Reference makeCurrent not found".
    Anyone can help me?
    Thanks!

    Hi,
    +Besides that, in my property SelectionListerner, when I have this line: "#{bindings.TreeNodeRepository.treeModel.makeCurrent}" there is a warning that says: "Reference makeCurrent not found".+
    Don't worry, its a designtime warning because the EL cannot be resolved. MakeCurrent is a method on the FacesCtrl binding equivalent to ADF, which is applied at runtime and not available at design time
    +But, when I drag from a tree to another show this error: "oracle.job.RowNotFoundException:JBO25020: View line of oracle.jbo.Key[4.4] key not found in ViewTreeNodeRepository13_71."+
    In drag and drop, ADF Faces performs the drag. However, the rest of the drop handling is up to the developer. Without any more information of what yur drop handler is doing, this question cannot be answered
    Frank

  • Show two trees with same context structure

    Hi,
    I'm having problems showing two trees using the same context structure but different data simultaneously.
    Here is my context structure:
    tree (value node)
    - expanded (boolean)
    - label (string)
    - leaf (boolean)
    - recursion (recursion node with ref on tree)
    I fill the first two layers of this tree in wdDoInit, the rest is loaded dynamically triggered by the onLoadChildren event.
    This setting works fine for one tree. But I have the requirement to set up a second tree using the context structure of the first tree with different data. The problem is both should be shown simultaneously.
    What I expected to work is:
    1. to wrap the above mentioned structure into a container
    2. make the tree a prototype (singleton=false) and
    3. instantiate two tree nodes
    4. fill both nodes with data
    5. bind each with its corresponding ui elements manually
    So the "shared" context structure would be:
    treeContainer (value node)
    - tree (value node, singleton=false)
    -- expanded (boolean)
    -- label (string)
    -- leaf (boolean)
    -- recursion (recursion node with ref on tree)
    My data mapping code begins with these lines
    ITreeContainerElement treeContainerElement =
    treeContainerNode.createTreeContainerElement();
    treeContainerNode.addElement(treeContainerElement);
    ITreeNode treeFactory = wdContext.nodeTree();
    which is then called one time for each tree. What happens is that both trees show the aggregated data, so each tree shows the data for both trees. When I use the factory of the element instead
    ITreeContainerElement treeContainerElement =
    treeContainerNode.createTreeContainerElement();
    treeContainerNode.addElement(treeContainerElement);
    ITreeNode treeFactory = treeContainerElement.nodeTree();
    both trees show the data for the first tree.
    I am aware that when I copy the context tree to a different location and rename every value node, e.h. tree2, recursion2 that this will work. But the problem is that the two trees will interact together, e.g. copy branches, and I want to use the typed API since the tree will get quite complex and they have absolutely the same structure.
    I guess I'm getting sth. terribly wrong here with my understanding of the context, so any help is appreciated.
    Best regards,
    Fabian

    Hi,
    It seems to be that my understanding of the context was terribly wrong. After I traced the behaviour in the debugger I realized that I made one important fault. The datasource of the UI elements should have been bound to the first and second instance of the recursion node container. Therefore the parent node should not be singleton since I access two instances simultaneously.
    However, I now separated both trees in the context for the sake of maintainability. I work now with the generic API In order to reuse the functionality.
    To determine the correct container I introduced the convention that the tree value node should only contain the recursion node. Then I use the following code to determine the right container:
         private IWDNode getContainer(IWDNodeElement parentElement) {
              IWDNode parentContainer = parentElement.node();
              IWDNodeInfo parentContainerInfo = parentContainer.getNodeInfo();
              boolean isRecursive = parentContainerInfo.isRecursive();
              String childName = null;
              if (isRecursive)
                   childName = parentContainerInfo.getName();
              else {
                   IWDNodeInfo recursiveNodeInfo =
                        (IWDNodeInfo) parentContainer
                             .getNodeInfo()
                             .iterateChildren()
                             .next();
                   childName = recursiveNodeInfo.getName();
              return parentContainer.getChildNode(childName, parentElement.index());
    I'm sorry if my question was somehow imprecise and lead into the wrong direction. With the code now working I reckon the question as answered and give you both points for good answers!
    Best regards,
    Fabian

  • Integration of SAP IS-U Two Contract Model with CRM 7.0 Contract Mgmt

    Hi,
    We have 2-Contract model for all customers in SAP IS-U for distribution and supply services. We are also planning to implement CRM 7.0 Contract management and integrate with SAP IS-U. There is a talk in the air that CRM 7.0 Contract Management does not work with 2-Contract model in IS-U because of some POD replication issues in CRM and heard that some clients are currently facing this issue. 
    Our client is operating in Deregulated environment and we were planning to use Two contract model to separate the services.
    Has anyone faced this issue in your projects or Is SAP working on this issue?
    Please let me know if there are any workarounds where we can still use 2-contract model and integrate with CRM 7.0? Any help or inputs that can you can provide will be very helpful to us.
    Thanks in advance.
    Sachin

    DearSachin,
    As per Design it's only possible to have one contract at the same time per PoD.
    If you in a deregulation market it's recommended you to use the IDE integration in CRM.
    Unfortunatly your desired business scenario can be achieved on project base only. There are several ideas how to provide the data and the information. One would be to download only the most used contract category into the CRM system (eiher grid usage or supply) and have the other contract only in IS-U (no replication). With a customer enhancement it would be possible do retrieve the whole supply sceanario within the IC webclient.
    Another idea would be to attach a new customer based field to the contract which indicates if the contract is a grid usage or supply contract and have the check for double contracts respect that data - this solution is quite tricky and should be considered only by very experienced consultants.
    Or use 1 installation with 1 contract for simple supply scenario. The schema contains a rate for both, distribution and default supply. The default supply can be switched with an installation fact. In CRM, there is 1 contract with 1 product. If a customer switches to a 3rd party supplier, an inbound message from the supplier creates a second installation with a supply contract and switches off the default supply rate. This installation/contract is not visible in CRM, it is not replicated to CRM.
    As you can see, there are some ideas how to solve your needs on project base, but unfortunatly SAP generally will not change the main architecture which allows several contracts per PoD.
    I hope this information is helpful for you.
    Regards
    Olivia

  • CheckBox node tree with two diferent kind of nodes

    Hai ,
    I need to build a check box tree with two different kind of nodes , Child and Parent nodes .
    CheckBox node tree with two diferent kind of nodes.
    HOw will i write the renderer and editor for this ?

    Study the method getTreeCellRendererComponent() of the class DefaultTreeCellRenderer.

  • Define Data Model with Two Excel Sources

    Good afternoon --
    I am attempting to join two Excel spreadsheets within BI Publisher 11g (have tried both 11.1.1.5 and 11.1.1.6) and continue to receive an XDOException / NullPointerException error. Although my original use case involved two complex spreadsheets, I have attempted to test with two simple spreadsheets with these columns:
    Key_Project
    Project_Name
    Project_Description
    TaskID
    Task_Name     
    Project_ID     
    Percentage_Complete
    Can successfully load each spreadsheet into BIP and render the XML, but as soon as I load both sheets and create a join between Key_Project and Project_ID I receive either an empty dataset or an error. The error looks like this:
    XML Parsing Error: mismatched tag. Expected: </img>.
    Location: https://obi-demo.cadm.harvard.edu/xmlpserver/servlet/xdo
    Line Number 2, Column 580:
    But if you scroll to the end you can see this ambiguous error message:
    oracle.xdo.XDOException: java.lang.NullPointerException
    Please help with any and all suggestions... All my searches on Oracle Forums, My Oracle Support, and Google have come up empty so far...
    Thanks,
    Jason

    if u find any solution plz update me on [email protected] , i am also getting the same error

  • How to hide a tree node from the GUI but still keep it in the tree model?

    Hi, All
    I used a JTree in my project in which I have a DefaultTreeModel to store all the tree structure and a JTree show it on the screen. But for some reason, I want to hide some of the nodes from the user, but I don't want to remove them from the tree model because later on I still need to use them.
    I searched on the web, some people suggested method to hide the root node, but that's not appliable to my project because I want to hide some non-root nodes; Some people also suggested to collapse the parent node when there are child to hide, it is not appliable to me either, because there still some other childnodes (sibling of the node to hide) I want to show.
    How can I hide some of the tree node from the user? Thanks for any information.
    Linda

    Here's an example using a derivation of DefaultTreeModel that shows (or does not show) two types of Sneech (appologies to the good Dr Zeus) by overiding two methods on the model.
    Now, there are many things wrong with this example (using instanceof, for example), but it's pretty tight and shows one way of doing what you want.
    Note: to make it useful, you''d have to change the implementation of setShowStarBelliedSneeches() to do something more sophisticated than simply firing a structure change event on the root node. You'd want to find all the star bellied sneech nodes and call fireTreeNodesRemoved(). That way the tree would stay expanded rather than collapse as it does now.
    import javax.swing.JTree;
    import javax.swing.JScrollPane;
    import javax.swing.JOptionPane;
    import javax.swing.JCheckBox;
    import javax.swing.JPanel;
    import javax.swing.tree.TreePath;
    import javax.swing.tree.DefaultTreeModel;
    import javax.swing.tree.DefaultMutableTreeNode;
    import java.awt.Dimension;
    import java.awt.BorderLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.util.Enumeration;
    class FilteredTree
         private class PlainBelliedSneech {
              public String toString() { return "Plain Bellied Sneech"; }
         private class StarBelliedSneech {
              public String toString() { return "Star Bellied Sneech"; }
         private class FilteredTreeModel
              extends DefaultTreeModel
              private boolean mShowStarBelliedSneeches= true;
              private DefaultMutableTreeNode mRoot;
              FilteredTreeModel(DefaultMutableTreeNode root)
                   super(root);
                   mRoot= root;
              public Object getChild(Object parent, int index)
                   DefaultMutableTreeNode node=
                        (DefaultMutableTreeNode) parent;
                   if (mShowStarBelliedSneeches)
                        return node.getChildAt(index);
                   int pos= 0;
                   for (int i= 0, cnt= 0; i< node.getChildCount(); i++) {
                        if (((DefaultMutableTreeNode) node.getChildAt(i)).getUserObject()
                                            instanceof PlainBelliedSneech)
                             if (cnt++ == index) {
                                  pos= i;
                                  break;
                   return node.getChildAt(pos);
              public int getChildCount(Object parent)
                   DefaultMutableTreeNode node=
                        (DefaultMutableTreeNode) parent;
                   if (mShowStarBelliedSneeches)
                        return node.getChildCount();
                   int childCount= 0;
                   Enumeration children= node.children();
                   while (children.hasMoreElements()) {
                        if (((DefaultMutableTreeNode) children.nextElement()).getUserObject()
                                            instanceof PlainBelliedSneech)
                             childCount++;
                   return childCount;
              public boolean getShowStarBelliedSneeches() {
                   return mShowStarBelliedSneeches;
              public void setShowStarBelliedSneeches(boolean showStarBelliedSneeches)
                   if (showStarBelliedSneeches != mShowStarBelliedSneeches) {
                        mShowStarBelliedSneeches= showStarBelliedSneeches;
                        Object[] path= { mRoot };
                        int[] childIndices= new int[root.getChildCount()];
                        Object[] children= new Object[root.getChildCount()];
                        for (int i= 0; i< root.getChildCount(); i++) {
                             childIndices= i;
                             children[i]= root.getChildAt(i);
                        fireTreeStructureChanged(this, path, childIndices, children);
         private FilteredTree()
              final DefaultMutableTreeNode root= new DefaultMutableTreeNode("Root");
              DefaultMutableTreeNode parent;
              DefaultMutableTreeNode child;
              for (int i= 0; i< 2; i++) {
                   parent= new DefaultMutableTreeNode(new PlainBelliedSneech());
                   root.add(parent);
                   for (int j= 0; j< 2; j++) {
                        child= new DefaultMutableTreeNode(new StarBelliedSneech());
                        parent.add(child);
                        for (int k= 0; k< 2; k++)
                             child.add(new DefaultMutableTreeNode(new PlainBelliedSneech()));
                   for (int j= 0; j< 2; j++)
                        parent.add(new DefaultMutableTreeNode(new PlainBelliedSneech()));
                   parent= new DefaultMutableTreeNode(new StarBelliedSneech());
                   root.add(parent);
                   for (int j= 0; j< 2; j++) {
                        child= new DefaultMutableTreeNode(new PlainBelliedSneech());
                        parent.add(child);
                        for (int k= 0; k< 2; k++)
                             child.add(new DefaultMutableTreeNode(new StarBelliedSneech()));
                   for (int j= 0; j< 2; j++)
                        parent.add(new DefaultMutableTreeNode(new StarBelliedSneech()));
              final FilteredTreeModel model= new FilteredTreeModel(root);
              JTree tree= new JTree(model);
    tree.setShowsRootHandles(true);
    tree.putClientProperty("JTree.lineStyle", "Angled");
              tree.setRootVisible(false);
              JScrollPane sp= new JScrollPane(tree);
              sp.setPreferredSize(new Dimension(200,400));
              final JCheckBox check= new JCheckBox("Show Star Bellied Sneeches");
              check.setSelected(model.getShowStarBelliedSneeches());
              check.addActionListener(new ActionListener() {
                   public void actionPerformed(ActionEvent e) {
                        model.setShowStarBelliedSneeches(check.isSelected());
              JPanel panel= new JPanel(new BorderLayout());
              panel.add(check, BorderLayout.NORTH);
              panel.add(sp, BorderLayout.CENTER);
              JOptionPane.showOptionDialog(
                   null, panel, "Sneeches on Beeches",
                   JOptionPane.DEFAULT_OPTION,
                   JOptionPane.PLAIN_MESSAGE,
                   null, new String[0], null
              System.exit(0);
         public static void main(String[] argv) {
              new FilteredTree();

  • How to get correct node in JTree with DISCONTIGUOUS_TREE_SELECTION mode?

    The following code creats a JTree with DISCONTIGUOUS_TREE_SELECTION mode. When select a single node, the node's name is printed correctly as expected. However, in Window environment, after select one node, if holding the ctrl key and select a different node, the program still prints out the name of the first selected node although both nodes are highlighted. Can some one tell me how to get the name of the second (i.e. the last) selected node printed?
    Thank you very much!
    import javax.swing.*;
    import javax.swing.tree.*;
    import javax.swing.event.*;
    import java.io.*;
    public class TestTree extends JFrame {
    JTree tree;
    public TestTree() {
    super();
    setBounds(0,0,500,500);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    tree = new JTree();
    getContentPane().add(tree);
    TreeSelectionModel model = new DefaultTreeSelectionModel();
    model.setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
    tree.setSelectionModel(model);
    tree.addTreeSelectionListener(new TreeSelectionListener() {
    public void valueChanged(TreeSelectionEvent e) {
    Object obj = tree.getLastSelectedPathComponent();
    System.out.println(obj.toString());
    public static void main(String [] args) {
    TestTree test = new TestTree();
    test.show();

    Hi!
    Try this, maybe it's what you want?
    /Smedman
    public void valueChanged(TreeSelectionEvent e)
        TreePath[] paths = tree.getSelectionPaths();
        for (int i = 0; i < paths.length; i++)
            System.out.println(paths.getLastPathComponent());

  • JTree with XML Content

    Hi Friends,
    I am trying to create a JTree whose data will come from a XML Document. Whenever the tree is refreshed (There is a JPopupMenu on the tree which allows the user to call refresh), the tree must update itself with the underlying XML document. If there is any change in the xml doc, it must be reflected in the tree. However, the tree must not collapse when the refresh is called. For example if I have a tree like this:-
    + Root
        |
        ------ Child #1
        |            |
        |            -------- A
        |            |
        |            -------- B
        |
        +------ Child #2
        |
        ------- Child #3
                    |
                    -------- AAA
                    |
                    -------- BBBThe XML Document for the above tree structure would be:-
    <?xml version="1.0" encoding="UTF-8"?>
    <Root>Root
          <Child> Child #1
                <SubChild>A</SubChild>
                <SubChild>B</SubChild>
          </Child>
          <Child> Child #2
                <SubChild>AA</SubChild>
                <SubChild>BB</SubChild>
          </Child>
          <Child> Child #3
                <SubChild>AAA</SubChild>
                <SubChild>BBB</SubChild>
          </Child>
    </Root>Now if i add another node (CCC) in Child #3 (by adding another Subchild element in the XML document), and click refresh on the tree, the tree should look like:-
    + Root
        |
        ------ Child #1
        |            |
        |            -------- A
        |            |
        |            -------- B
        |
        +------ Child #2
        |
        ------- Child #3
                    |
                    -------- AAA
                    |
                    -------- BBB
                    |
                    -------- CCCHowever, if i am trying to reload the tree model, after reading the XML file, the whole tree collapses.
    Can anyone please help me out with this problem?
    Thanx a lot in advance,
    ~Debopam

    * XMLNode.java
    * Created on December 18, 2004, 4:25 PM
    package debopam.utils.xml;
    import java.util.Enumeration;
    import java.util.NoSuchElementException;
    import java.util.Vector;
    import javax.swing.tree.MutableTreeNode;
    import javax.swing.tree.TreeNode;
    import org.jdom.Element;
    * @author Debopam Ghoshal
    public class XMLNode implements MutableTreeNode
        private Element nodeElement;
        private XMLNode parent;
        /** optional user object */
        transient protected Object     userObject;
        /** true if the node is able to have children */
        protected boolean allowsChildren;
        /** array of children, may be null if this node has no children */
        protected Vector children;
         * An enumeration that is always empty. This is used when an enumeration
         * of a leaf node's children is requested.
        static public final Enumeration<TreeNode> EMPTY_ENUMERATION
                = new Enumeration<TreeNode>()
            public boolean hasMoreElements()
            { return false; }
            public TreeNode nextElement()
                throw new NoSuchElementException("No more elements");
        /** Creates a new instance of XMLNode */
        public XMLNode(Element nodeElement, boolean allowsChildren)
            this.nodeElement = nodeElement;
            this.allowsChildren = allowsChildren;
        public XMLNode(String nodeName, boolean allowsChildren)
            nodeElement = new Element(nodeName);
            this.allowsChildren = allowsChildren;
         * Creates and returns a forward-order enumeration of this node's
         * children.  Modifying this node's child array invalidates any child
         * enumerations created before the modification.
         * @return     an Enumeration of this node's children
        public java.util.Enumeration children()
            if(children == null)
                return EMPTY_ENUMERATION;
            else
                return children.elements();
         * Returns true if this node is allowed to have children.
         * @return     true if this node allows children, else false
        public boolean getAllowsChildren()
            return allowsChildren;
         * Determines whether or not this node is allowed to have children.
         * If <code>allows</code> is false, all of this node's children are
         * removed.
         * <p>
         * Note: By default, a node allows children.
         * @param     allows     true if this node is allowed to have children
        public void setAllowsChildren(boolean allows)
            if (allows != allowsChildren)
                allowsChildren = allows;
                if (!allowsChildren)
                    removeAllChildren();
         * Returns the child at the specified index in this node's child array.
         * @param     index     an index into this node's child array
         * @exception     ArrayIndexOutOfBoundsException     if <code>index</code>
         *                              is out of bounds
         * @return     the TreeNode in this node's child array at  the specified index
        public javax.swing.tree.TreeNode getChildAt(int index)
            if (children == null)
                throw new ArrayIndexOutOfBoundsException("node has no children");
            return (TreeNode)children.elementAt(index);
         * Returns the number of children of this node.
         * @return     an int giving the number of children of this node
        public int getChildCount()
            if (children == null)
                return 0;
            else
                return children.size();
         * Returns the index of the specified child in this node's child array.
         * If the specified node is not a child of this node, returns
         * <code>-1</code>.  This method performs a linear search and is O(n)
         * where n is the number of children.
         * @param     aChild     the TreeNode to search for among this node's children
         * @exception     IllegalArgumentException     if <code>aChild</code>
         *                                   is null
         * @return     an int giving the index of the node in this node's child
         *          array, or <code>-1</code> if the specified node is a not
         *          a child of this node
        public int getIndex(TreeNode aChild)
            if (aChild == null)
                throw new IllegalArgumentException("argument is null");
            if (!isNodeChild(aChild))
                return -1;
            return children.indexOf(aChild);     // linear search
         * Returns this node's parent or null if this node has no parent.
         * @return     this node's parent TreeNode, or null if this node has no parent
        public TreeNode getParent()
            return parent;
         * Removes <code>newChild</code> from its present parent (if it has a
         * parent), sets the child's parent to this node, and then adds the child
         * to this node's child array at index <code>childIndex</code>.
         * <code>newChild</code> must not be null and must not be an ancestor of
         * this node.
         * @param     newChild     the MutableTreeNode to insert under this node
         * @param     childIndex     the index in this node's child array
         *                    where this node is to be inserted
         * @exception     ArrayIndexOutOfBoundsException     if
         *                    <code>childIndex</code> is out of bounds
         * @exception     IllegalArgumentException     if
         *                    <code>newChild</code> is null or is an
         *                    ancestor of this node
         * @exception     IllegalStateException     if this node does not allow
         *                              children
         * @see     #isNodeDescendant
        public void insert(MutableTreeNode newChild, int childIndex)
            if (!allowsChildren)
                throw new IllegalStateException("node does not allow children");
            else if (newChild == null)
                throw new IllegalArgumentException("new child is null");
            else if (isNodeAncestor(newChild))
                throw new IllegalArgumentException("new child is an ancestor");
            MutableTreeNode oldParent = (MutableTreeNode)newChild.getParent();
            if (oldParent != null)
                oldParent.remove(newChild);
            newChild.setParent(this);
            if (children == null)
                children = new Vector();
            children.insertElementAt(newChild, childIndex);
        public boolean isLeaf()
            return !nodeElement.hasChildren();
         * Removes the child at the specified index from this node's children
         * and sets that node's parent to null. The child node to remove
         * must be a <code>MutableTreeNode</code>.
         * @param     childIndex     the index in this node's child array
         *                    of the child to remove
         * @exception     ArrayIndexOutOfBoundsException     if
         *                    <code>childIndex</code> is out of bounds
        public void remove(int childIndex)
            MutableTreeNode child = (MutableTreeNode)getChildAt(childIndex);
            children.removeElementAt(childIndex);
            child.setParent(null);
         * Removes <code>aChild</code> from this node's child array, giving it a
         * null parent.
         * @param     aChild     a child of this node to remove
         * @exception     IllegalArgumentException     if <code>aChild</code>
         *                         is null or is not a child of this node
        public void remove(MutableTreeNode aChild)
            if (aChild == null)
                throw new IllegalArgumentException("argument is null");
            if (!isNodeChild(aChild))
                throw new IllegalArgumentException("argument is not a child");
            remove(getIndex(aChild));     // linear search
         * Removes the subtree rooted at this node from the tree, giving this
         * node a null parent.  Does nothing if this node is the root of its
         * tree.
        public void removeFromParent()
            MutableTreeNode parent = (MutableTreeNode)getParent();
            if (parent != null)
                parent.remove(this);
         * Sets this node's parent to <code>newParent</code> but does not
         * change the parent's child array.  This method is called from
         * <code>insert()</code> and <code>remove()</code> to
         * reassign a child's parent, it should not be messaged from anywhere
         * else.
         * @param     newParent     this node's new parent
        public void setParent(MutableTreeNode mutableTreeNode)
            this.parent = parent;
        public void setUserObject(Object obj)
            this.userObject = obj;
        public Element getXMLElement()
            return this.nodeElement;
        public String toString()
            return this.nodeElement.getTextTrim();
         * Returns true if <code>anotherNode</code> is an ancestor of this node
         * -- if it is this node, this node's parent, or an ancestor of this
         * node's parent.  (Note that a node is considered an ancestor of itself.)
         * If <code>anotherNode</code> is null, this method returns false.  This
         * operation is at worst O(h) where h is the distance from the root to
         * this node.
         * @see          #isNodeDescendant
         * @see          #getSharedAncestor
         * @param     anotherNode     node to test as an ancestor of this node
         * @return     true if this node is a descendant of <code>anotherNode</code>
        public boolean isNodeAncestor(TreeNode anotherNode)
            if (anotherNode == null)
                return false;
            TreeNode ancestor = this;
            do
                if (ancestor == anotherNode)
                    return true;
            } while((ancestor = ancestor.getParent()) != null);
            return false;
         * Returns true if <code>aNode</code> is a child of this node.  If
         * <code>aNode</code> is null, this method returns false.
         * @return     true if <code>aNode</code> is a child of this node; false if
         *            <code>aNode</code> is null
        public boolean isNodeChild(TreeNode aNode)
            boolean retval;
            if (aNode == null)
                retval = false;
            else
                if (getChildCount() == 0)
                    retval = false;
                else
                    retval = (aNode.getParent() == this);
            return retval;
         * Removes all of this node's children, setting their parents to null.
         * If this node has no children, this method does nothing.
        public void removeAllChildren()
            for (int i = getChildCount()-1; i >= 0; i--)
                remove(i);
         * Removes <code>newChild</code> from its parent and makes it a child of
         * this node by adding it to the end of this node's child array.
         * @see          #insert
         * @param     newChild     node to add as a child of this node
         * @exception     IllegalArgumentException    if <code>newChild</code>
         *                              is null
         * @exception     IllegalStateException     if this node does not allow
         *                              children
        public void add(MutableTreeNode newChild)
            if(newChild != null && newChild.getParent() == this)
                insert(newChild, getChildCount() - 1);
            else
                insert(newChild, getChildCount());
         * Indicates whether some other object is "equal to" this one.
         * @param   obj   the reference object with which to compare.
         * @return  <code>true</code> if this object is the same as the obj
         *          argument; <code>false</code> otherwise.
        public boolean equals(XMLNode node)
            boolean retValue;
            retValue = (this.getXMLElement().getTextTrim().equals(node.getXMLElement().getTextTrim())) &&
                    (this.getXMLElement().getParent().getTextTrim().equals(node.getXMLElement().getParent().getTextTrim()));
            return retValue;
    * XMLTreeModel.java
    * Created on December 20, 2004, 11:29 AM
    package debopam.utils.xml;
    import java.io.File;
    import java.io.IOException;
    import java.io.ObjectInputStream;
    import java.io.ObjectOutputStream;
    import java.io.Serializable;
    import java.util.EventListener;
    import java.util.List;
    import java.util.Vector;
    import javax.swing.event.EventListenerList;
    import javax.swing.event.TreeModelEvent;
    import javax.swing.event.TreeModelListener;
    import javax.swing.tree.TreeModel;
    import javax.swing.tree.TreePath;
    import org.jdom.Document;
    import org.jdom.Element;
    import org.jdom.input.SAXBuilder;
    * @author Debopam Ghoshal
    public class XMLTreeModel implements TreeModel
        private XMLNode rootNode;
        private String xmlFileName;
        private Document xmlDocument;
        /** Listeners. */
        protected EventListenerList listenerList = new EventListenerList();
         * Determines how the <code>isLeaf</code> method figures
         * out if a node is a leaf node. If true, a node is a leaf
         * node if it does not allow children. (If it allows
         * children, it is not a leaf node, even if no children
         * are present.) That lets you distinguish between <i>folder</i>
         * nodes and <i>file</i> nodes in a file system, for example.
         * <p>
         * If this value is false, then any node which has no
         * children is a leaf node, and any node may acquire
         * children.
         * @see TreeNode#getAllowsChildren
         * @see TreeModel#isLeaf
         * @see #setAsksAllowsChildren
        protected boolean asksAllowsChildren;
        /** Creates a new instance of XMLTreeModel */
        public XMLTreeModel(String xmlFileName, boolean asksAllowsChildren)
            this.xmlFileName = xmlFileName;
            this.asksAllowsChildren = asksAllowsChildren;
            loadXMLDocument();
            rootNode = makeRootNode();
        public XMLTreeModel(String xmlFileName)
            this(xmlFileName, false);
        private void loadXMLDocument()
            System.out.println("loading xml document...");
            try
                this.xmlDocument = null;
                this.xmlDocument = new SAXBuilder().build(new File(xmlFileName));
            catch(Exception x)
                System.out.println("Error while loading XML Document.");
                x.printStackTrace();
        private XMLNode makeRootNode()
            XMLNode root = new XMLNode(xmlDocument.getRootElement(), true);
            addChildren(root, xmlDocument.getRootElement());
            return root;
        private void addChildren(XMLNode parentXMLNode, Element element)
            List children = element.getChildren();
            for(int i = 0; i < children.size(); i++)
                Element childElement = (Element)children.get(i);
                XMLNode childNode = new XMLNode(childElement, true);
                parentXMLNode.add(childNode);
                addChildren(childNode, childElement);
         * Sets whether or not to test leafness by asking getAllowsChildren()
         * or isLeaf() to the TreeNodes.  If newvalue is true, getAllowsChildren()
         * is messaged, otherwise isLeaf() is messaged.
        public void setAsksAllowsChildren(boolean newValue)
            asksAllowsChildren = newValue;
         * Tells how leaf nodes are determined.
         * @return true if only nodes which do not allow children are
         *         leaf nodes, false if nodes which have no children
         *         (even if allowed) are leaf nodes
         * @see #asksAllowsChildren
        public boolean asksAllowsChildren()
            return asksAllowsChildren;
         * Returns the child of <I>parent</I> at index <I>index</I> in the parent's
         * child array.  <I>parent</I> must be a node previously obtained from
         * this data source. This should not return null if <i>index</i>
         * is a valid index for <i>parent</i> (that is <i>index</i> >= 0 &&
         * <i>index</i> < getChildCount(<i>parent</i>)).
         * @param   parent  a node in the tree, obtained from this data source
         * @return  the child of <I>parent</I> at index <I>index</I>
        public Object getChild(Object parent, int index)
            return ((XMLNode)parent).getChildAt(index);
         * Returns the number of children of <I>parent</I>.  Returns 0 if the node
         * is a leaf or if it has no children.  <I>parent</I> must be a node
         * previously obtained from this data source.
         * @param   parent  a node in the tree, obtained from this data source
         * @return  the number of children of the node <I>parent</I>
        public int getChildCount(Object parent)
            return ((XMLNode)parent).getChildCount();
         * Returns the index of child in parent.
         * If either the parent or child is <code>null</code>, returns -1.
         * @param parent a note in the tree, obtained from this data source
         * @param child the node we are interested in
         * @return the index of the child in the parent, or -1
         *    if either the parent or the child is <code>null</code>
        public int getIndexOfChild(Object parent, Object child)
            if(parent == null || child == null)
                return -1;
            return ((XMLNode)parent).getIndex((XMLNode)child);
         * Sets the root to <code>root</code>. A null <code>root</code> implies
         * the tree is to display nothing, and is legal.
        public void setRoot(XMLNode rootNode)
            Object oldRoot = this.rootNode;
            this.rootNode = rootNode;
            if (rootNode == null && oldRoot != null)
                fireTreeStructureChanged(this, null);
            else
                nodeStructureChanged(rootNode);
         * Returns the root of the tree.  Returns null only if the tree has
         * no nodes.
         * @return  the root of the tree
        public Object getRoot()
            return rootNode;
         * Returns whether the specified node is a leaf node.
         * The way the test is performed depends on the
         * <code>askAllowsChildren</code> setting.
         * @param node the node to check
         * @return true if the node is a leaf node
         * @see #asksAllowsChildren
         * @see TreeModel#isLeaf
        public boolean isLeaf(Object node)
            if(asksAllowsChildren)
                return !((XMLNode)node).getAllowsChildren();
            return ((XMLNode)node).isLeaf();
         * This sets the user object of the TreeNode identified by path
         * and posts a node changed.  If you use custom user objects in
         * the TreeModel you're going to need to subclass this and
         * set the user object of the changed node to something meaningful.
        public void valueForPathChanged(TreePath path, Object newValue)
            XMLNode aNode = (XMLNode)path.getLastPathComponent();
            aNode.setUserObject(newValue);
            nodeChanged(aNode);
         * Invoked this to insert newChild at location index in parents children.
         * This will then message nodesWereInserted to create the appropriate
         * event. This is the preferred way to add children as it will create
         * the appropriate event.
        public void insertNodeInto(XMLNode newChild, XMLNode parent, int index)
            parent.insert(newChild, index);
            int[] newIndexs = new int[1];
            newIndexs[0] = index;
            nodesWereInserted(parent, newIndexs);
         * Message this to remove node from its parent. This will message
         * nodesWereRemoved to create the appropriate event. This is the
         * preferred way to remove a node as it handles the event creation
         * for you.
        public void removeNodeFromParent(XMLNode node)
            XMLNode parent = (XMLNode)node.getParent();
            if(parent == null)
                throw new IllegalArgumentException("node does not have a parent.");
            int[] childIndex = new int[1];
            Object[] removedArray = new Object[1];
            childIndex[0] = parent.getIndex(node);
            parent.remove(childIndex[0]);
            removedArray[0] = node;
            nodesWereRemoved(parent, childIndex, removedArray);
         * Invoke this method after you've changed how node is to be
         * represented in the tree.
        public void nodeChanged(XMLNode node)
            if(listenerList != null && node != null)
                XMLNode parent = (XMLNode)node.getParent();
                if(parent != null)
                    int        anIndex = parent.getIndex(node);
                    if(anIndex != -1)
                        int[] cIndexs = new int[1];
                        cIndexs[0] = anIndex;
                        nodesChanged(parent, cIndexs);
                else if (node == getRoot())
                    nodesChanged(node, null);
         * Invoke this method if you've modified the TreeNodes upon which this
         * model depends.  The model will notify all of its listeners that the
         * model has changed.
        public void reload()
            loadXMLDocument();
            XMLNode tempRootNode = makeRootNode();
            if(!tempRootNode.equals(rootNode))
                // Means that the root node itself has changed.
                System.out.println("Root node changed");
                reload(rootNode);
            //else
                checkForNodesChanged(tempRootNode, rootNode);
         * Invoke this method if you've modified the TreeNodes upon which this
         * model depends.  The model will notify all of its listeners that the
         * model has changed below the node <code>node</code> (PENDING).
        public void reload(XMLNode node)
            if(node != null)
                fireTreeStructureChanged(this, getPathToRoot(node), null, null);
         * Invoke this method after you've inserted some TreeNodes into
         * node.  childIndices should be the index of the new elements and
         * must be sorted in ascending order.
        public void nodesWereInserted(XMLNode node, int[] childIndices)
            if(listenerList != null && node != null && childIndices != null
                    && childIndices.length > 0)
                int               cCount = childIndices.length;
                Object[]          newChildren = new Object[cCount];
                for(int counter = 0; counter < cCount; counter++)
                    newChildren[counter] = node.getChildAt(childIndices[counter]);
                fireTreeNodesInserted(this, getPathToRoot(node), childIndices,
                        newChildren);
         * Invoke this method after you've removed some TreeNodes from
         * node.  childIndices should be the index of the removed elements and
         * must be sorted in ascending order. And removedChildren should be
         * the array of the children objects that were removed.
        public void nodesWereRemoved(XMLNode node, int[] childIndices,
                Object[] removedChildren)
            if(node != null && childIndices != null)
                fireTreeNodesRemoved(this, getPathToRoot(node), childIndices,
                        removedChildren);
         * Invoke this method after you've changed how the children identified by
         * childIndicies are to be represented in the tree.
        public void nodesChanged(XMLNode node, int[] childIndices)
            if(node != null)
                if (childIndices != null)
                    int cCount = childIndices.length;
                    if(cCount > 0)
                        Object[] cChildren = new Object[cCount];
                        for(int counter = 0; counter < cCount; counter++)
                            cChildren[counter] = node.getChildAt
                                    (childIndices[counter]);
                        fireTreeNodesChanged(this, getPathToRoot(node),
                                childIndices, cChildren);
                else if (node == getRoot())
                    fireTreeNodesChanged(this, getPathToRoot(node), null, null);
         * Invoke this method if you've totally changed the children of
         * node and its childrens children...  This will post a
         * treeStructureChanged event.
        public void nodeStructureChanged(XMLNode node)
            if(node != null)
                fireTreeStructureChanged(this, getPathToRoot(node), null, null);
         * Builds the parents of node up to and including the root node,
         * where the original node is the last element in the returned array.
         * The length of the returned array gives the node's depth in the
         * tree.
         * @param aNode the TreeNode to get the path for
        public XMLNode[] getPathToRoot(XMLNode aNode)
            return getPathToRoot(aNode, 0);
         * Builds the parents of node up to and including the root node,
         * where the original node is the last element in the returned array.
         * The length of the returned array gives the node's depth in the
         * tree.
         * @param aNode  the TreeNode to get the path for
         * @param depth  an int giving the number of steps already taken towards
         *        the root (on recursive calls), used to size the returned array
         * @return an array of TreeNodes giving the path from the root to the
         *         specified node
        protected XMLNode[] getPathToRoot(XMLNode aNode, int depth)
            XMLNode[] retNodes;
            // This method recurses, traversing towards the root in order
            // size the array. On the way back, it fills in the nodes,
            // starting from the root and working back to the original node.
            /* Check for null, in case someone passed in a null node, or
               they passed in an element that isn't rooted at root. */
            if(aNode == null)
                if(depth == 0)
                    return null;
                else
                    retNodes = new XMLNode[depth];
            else
                depth++;
                if(aNode == rootNode)
                    retNodes = new XMLNode[depth];
                else
                    retNodes = getPathToRoot((XMLNode)aNode.getParent(), depth);
                retNodes[retNodes.length - depth] = aNode;
            return retNodes;
        //  Events
         * Adds a listener for the TreeModelEvent posted after the tree changes.
         * @see     #removeTreeModelListener
         * @param   l       the listener to add
        public void addTreeModelListener(TreeModelListener l)
            listenerList.add(TreeModelListener.class, l);
         * Removes a listener previously added with <B>addTreeModelListener()</B>.
         * @see     #addTreeModelListener
         * @param   l       the listener to remove
        public void removeTreeModelListener(TreeModelListener l)
            listenerList.remove(TreeModelListener.class, l);
         * Returns an array of all the tree model listeners
         * registered on this model.
         * @return all of this model's <code>TreeModelListener</code>s
         *         or an empty
         *         array if no tree model listeners are currently registered
         * @see #addTreeModelListener
         * @see #removeTreeModelListener
         * @since 1.4
        public TreeModelListener[] getTreeModelListeners()
            return (TreeModelListener[])listenerList.getListeners(
                    TreeModelListener.class);
         * Notifies all listeners that have registered interest for
         * notification on this event type.  The event instance
         * is lazily created using the parameters passed into
         * the fire method.
         * @param source the node being changed
         * @param path the path to the root node
         * @param childIndices the indices of the changed elements
         * @param children the changed elements
         * @see EventListenerList
        protected void fireTreeNodesChanged(Object source, Object[] path,
                int[] childIndices,
                Object[] children)
            // Guaranteed to return a non-null array
            Object[] listeners = listenerList.getListenerList();
            TreeModelEvent e = null;
            // Process the listeners last to first, notifying
            // those that are interested in this event
            for (int i = listeners.length-2; i>=0; i-=2)
                if (listeners==TreeModelListener.class)
    // Lazily create the event:
    if (e == null)
    e = new TreeModelEvent(source, path,
    childIndices, children);
    ((TreeModelListener)listeners[i+1]).treeNodesChanged(e);
    * Notifies all listeners that have registered interest for
    * notification on this event type. The event instance

  • Bette way to referenced tree model nodes from UI to perform actions on them

    A singleton facade is built.
    Its init() method loads several "tree model configs", each of them referenced by a name.
    This singleton creates a Project instance for a given "tree model config" calling the facade method -> createProject(String pjrName, String modelConfigName)
    When the Project is built a new Model instance is set ( remember the model instance is a tree holding nodes )
    The new Project instance built is added to a List that the facade has and then it's returned to the UI part that called ->createProject(prjName,modelconfigName)
    Given the Project instance the UI has to build a JTree representation of the model that the project references and the UI will have button actions that should call methods of the Nodes of the model referenced by the Project.
    Doing it this way the UI will be able to reference objects directly without going through the facade.
    Maybe I should return to the UI something like a ProjectKey instance instead of letting have the UI the Project instance ?
    It should be better if I process the possible node actions behind the Facade and not the UI, but how can I do it ?
    Having a ProjectKey in my UI I could ask the facade a model tree representation but not having the real nodes, otherwise having some NodeKey instances ?

    Sounds like you want to represent a tree structure, without a reference to the real tree.
    I'll take it further: maybe you don't want the UI to know there's a real tree data-structure with nodes and pointers to children, because maybe you build the tree on the fly from a database.
    So use the Builder pattern instead of committing to a specific data structure.
    Google results for Builder pattern: http://www.google.com/search?hl=en&q=builder+pattern&btnG=Google+Search
    Your UI should know how to construct nodes and children graphically, when told. This means it should have methods like addNode, but related to the domain: addSubProject maybe.
    A Project object is the Director, knowing which part goes where, but it doesn't know the real end result (a JPanel or HTML). So it has a method buildProject(Builder e) or exportProject(Exporter e), where all logic of assembling the parts is.
    When you have that, write a class JTreeProjectExporter implements Exporter.
    Hope this helps.

Maybe you are looking for

  • Cannot connect to a local user in pdborcl

    Hi all, I created a local user named "dwh" in the pdborcl (a pdb)...Impossible to connect using sqlplus...(On windows 7) So .. SELECT v.name, v.open_mode, NVL(v.restricted, 'n/a') "RESTRICTED", d.status FROM v$pdbs v, dba_pdbs d WHERE v.guid = d.guid

  • Can you disable the bounce effect while scrolling?

    Whenever you scroll in applications like Safari and Mail and you reach the 'border' of the application, you get a little bounce effect like in iOS. I find this to be very annoying and I was wondering if there was a way to turn this off.

  • Remove element from GUI

    Hi guys, I am adding elements to the gui like this: var myText = win.add("edittext", undefined, "whatever"); Later in my code I need to remove this element from UI. Is it possible?

  • Early 2011 MBP Slowing Down

    Hello, I have an early 2011 MBP (15-inch), system report below: MacBook Pro (15-inch, Early 2011) Processor: 2 GHz Intel Core i7 Memory: 16 GB 1333 MHz DDR3 Startup Disk: Macintosh SSD Graphics: HD Graphics 3000 512 MB Lately, my MBP has been slowing

  • Capture process not enqueuing any message

    DB Version : 10.2.0.4 I am trying to setup a simple capture process. The streams administrator (say APPS) is the queue owner as well as base table owner. I perform the following steps : 1. Setup the queue using dbms_streams_adm.set_up_queue 2. Add a