KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > test > editor > app > gui > tree > TestGroupNodeDelegate


1 /*
2  * TestGroupNodeDelegate.java
3  *
4  * Created on November 12, 2002, 5:00 PM
5  */

6
7 package org.netbeans.test.editor.app.gui.tree;
8
9 import org.netbeans.test.editor.app.core.TestGroup;
10 import org.netbeans.test.editor.app.core.TestNode;
11 import java.beans.PropertyChangeEvent JavaDoc;
12 import java.beans.PropertyChangeListener JavaDoc;
13 import javax.swing.tree.DefaultTreeModel JavaDoc;
14 import javax.swing.tree.MutableTreeNode JavaDoc;
15 import org.netbeans.test.editor.app.Main;
16 import org.netbeans.test.editor.app.gui.TreeDialog;
17
18 /**
19  *
20  * @author eh103527
21  */

22 public class TestGroupNodeDelegate extends TestNodeDelegate implements PropertyChangeListener JavaDoc {
23     
24     public TestGroupNodeDelegate(TestGroup bean) {
25     super(bean, true);
26     }
27     
28     /** This method gets called when a bound property is changed.
29      * @param evt A PropertyChangeEvent object describing the event source
30      * and the property that has changed.
31      * CHANGE_CHILD = "Change child";
32      * REMOVE_CHILD = "Remove node";
33      * ADD_CHILD = "Add child";
34      * UP_CHILD = "Up child";
35      * DOWN_CHILD = "Down child";
36      *
37      */

38     public void propertyChange(PropertyChangeEvent JavaDoc evt) {
39     if (evt.getPropertyName().compareTo(TestGroup.ADD_CHILDS) == 0) {
40         TestNode[] nodes=(TestNode[])(evt.getNewValue());
41         int[] indices=new int[nodes.length];
42         TestNodeDelegate tnd;
43         
44         for (int i=0;i < nodes.length;i++) {
45         tnd = (TestNodeDelegate)(nodes[i].getNodeDelegate());
46         add(tnd);
47         indices[i]=getNodeNumber(tnd);
48         }
49         TreeDialog dlg=Main.frame.getTree();
50         if (dlg != null) {
51         DefaultTreeModel JavaDoc model=(DefaultTreeModel JavaDoc)(dlg.getTreeModel());
52         model.nodesWereInserted(this,indices);
53         }
54     } else if (evt.getPropertyName().compareTo(TestGroup.ADD_CHILD) == 0) {
55         TestNodeDelegate n=(TestNodeDelegate)(((TestNode)evt.getNewValue()).getNodeDelegate());
56         add(n);
57         TreeDialog dlg=Main.frame.getTree();
58         if (dlg != null) {
59         DefaultTreeModel JavaDoc model=(DefaultTreeModel JavaDoc)(dlg.getTreeModel());
60         model.nodesWereInserted(this,new int[] {getNodeNumber(n)});
61         }
62     } else if (evt.getPropertyName().equals(TestGroup.REMOVE_CHILD)) {
63         TestNodeDelegate n=(TestNodeDelegate)(((TestNode)evt.getNewValue()).getNodeDelegate());
64         int i=getNodeNumber(n);
65         remove(n);
66         TreeDialog dlg=Main.frame.getTree();
67         if (dlg != null) {
68         DefaultTreeModel JavaDoc model=(DefaultTreeModel JavaDoc)(dlg.getTreeModel());
69         model.nodesWereRemoved(this,new int[] {i},new Object JavaDoc[] {n});
70         }
71     } else if (evt.getPropertyName().equals(TestGroup.REMOVE_CHILDS)) {
72         TestNode[] nodes=(TestNode[])(evt.getNewValue());
73         TestNodeDelegate[] trees=new TestNodeDelegate[nodes.length];
74         int[] indices=new int[nodes.length];
75         int first;
76         for (int i=0;i < nodes.length;i++) {
77         trees[i]=(TestNodeDelegate)(nodes[i].getNodeDelegate());
78         first=getNodeNumber(trees[i]);
79         remove(trees[i]);
80         indices[i]=first;
81         }
82         TreeDialog dlg=Main.frame.getTree();
83         if (dlg != null) {
84         DefaultTreeModel JavaDoc model=(DefaultTreeModel JavaDoc)(dlg.getTreeModel());
85         model.nodesWereRemoved(this,indices,nodes);
86         }
87     } else if (evt.getPropertyName().equals(TestGroup.CHANGE_CHILD)) {
88         TestNodeDelegate n=(TestNodeDelegate)(((TestNode)evt.getNewValue()).getNodeDelegate());
89         int i=getNodeNumber(n);
90         TreeDialog dlg=Main.frame.getTree();
91         if (dlg != null) {
92         DefaultTreeModel JavaDoc model=(DefaultTreeModel JavaDoc)(dlg.getTreeModel());
93         model.nodesChanged(this,new int[] {i});
94         }
95     } else if (evt.getPropertyName().equals(TestGroup.UP_CHILD)) {
96         TestNodeDelegate n=(TestNodeDelegate)(((TestNode)evt.getNewValue()).getNodeDelegate());
97         int i=getNodeNumber(n);
98         insert(n, i-1);
99         TreeDialog dlg=Main.frame.getTree();
100         if (dlg != null) {
101         DefaultTreeModel JavaDoc model=(DefaultTreeModel JavaDoc)(dlg.getTreeModel());
102         model.nodeStructureChanged(this);
103         }
104     } else if (evt.getPropertyName().equals(TestGroup.DOWN_CHILD)) {
105         TestNodeDelegate n=(TestNodeDelegate)(((TestNode)evt.getNewValue()).getNodeDelegate());
106         int i=getNodeNumber(n);
107         insert(n, i+1);
108         TreeDialog dlg=Main.frame.getTree();
109         if (dlg != null) {
110         DefaultTreeModel JavaDoc model=(DefaultTreeModel JavaDoc)(dlg.getTreeModel());
111         model.nodeStructureChanged(this);
112         }
113     } else {
114         super.propertyChange(evt);
115     }
116     }
117     
118     private int getNodeNumber(TestNodeDelegate node) {
119     return getIndex(node);
120     }
121     
122 }
123
Popular Tags