KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jac > aspects > gui > RelationNode


1 /*
2   Copyright (C) 2002 Renaud Pawlak, Laurent Martelli
3   
4   This program is free software; you can redistribute it and/or modify
5   it under the terms of the GNU Lesser General Public License as
6   published by the Free Software Foundation; either version 2 of the
7   License, or (at your option) any later version.
8
9   This program is distributed in the hope that it will be useful, but
10   WITHOUT ANY WARRANTY; without even the implied warranty of
11   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12   Lesser General Public License for more details.
13
14   You should have received a copy of the GNU Lesser General Public
15   License along with this program; if not, write to the Free Software
16   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
17   USA */

18
19 package org.objectweb.jac.aspects.gui;
20
21 import org.apache.log4j.Logger;
22 import org.objectweb.jac.core.rtti.CollectionItem;
23 import org.objectweb.jac.core.rtti.FieldItem;
24
25 /**
26  * This tree node represents a relation. */

27
28 public class RelationNode extends AbstractNode implements CollectionUpdate {
29     static Logger logger = Logger.getLogger("gui.treeview");
30     static Logger loggerEvents = Logger.getLogger("gui.events");
31
32     Object JavaDoc substance;
33    
34     /**
35      * Constructs the node.
36      *
37      * @param model the tree model
38      * @param substance the object that holds the relation
39      * @param relation the substance relation */

40
41     public RelationNode(TreeView model,
42                         Object JavaDoc substance, FieldItem relation) {
43         super(model,relation,true);
44         this.substance = substance;
45         rebuildData();
46     }
47
48     /**
49      * Rebuild the node's data. */

50
51     protected void rebuildData() {
52         Object JavaDoc object = getUserObject();
53         logger.debug("rebuildData on "+this);
54         if ( object instanceof FieldItem ) {
55             text = ((FieldItem)object).getName();
56             icon = GuiAC.getIcon((FieldItem)object);
57         }
58     }
59
60     /**
61      * Unregister all the events this node is listening to. */

62     public void unregisterEvents() {
63         Utils.unregister(substance,this);
64     }
65
66     // CollectionUpdate interface
67

68     public void onChange(Object JavaDoc substance, CollectionItem collection,
69                          Object JavaDoc value, Object JavaDoc param) {
70         loggerEvents.debug("collectionUpdated");
71         int[] indices = new int[getChildCount()];
72         for(int i=0;i<indices.length;i++) {
73             indices[i]=i;
74         }
75         AbstractNode[] removedNodes = new AbstractNode[getChildCount()];
76         for(int i=0;i<indices.length;i++) {
77             removedNodes[i]=(AbstractNode)getChildAt(i);
78         }
79         removeAllChildren();
80         model.nodesWereRemoved(this,indices,removedNodes);
81     }
82
83     public void onAdd(Object JavaDoc substance, CollectionItem collection,
84                       Object JavaDoc value, Object JavaDoc added, Object JavaDoc param) {
85         onChange(substance,collection,value,param);
86     }
87
88     public void onRemove(Object JavaDoc substance, CollectionItem collection,
89                          Object JavaDoc value, Object JavaDoc removed, Object JavaDoc param) {
90         onChange(substance,collection,value,param);
91     }
92
93     public String JavaDoc toString() {
94         return "RelationNode["+getUserObject()+"]";
95     }
96 }
97
Popular Tags