1 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 ; 12 import java.beans.PropertyChangeListener ; 13 import javax.swing.tree.DefaultTreeModel ; 14 import javax.swing.tree.MutableTreeNode ; 15 import org.netbeans.test.editor.app.Main; 16 import org.netbeans.test.editor.app.gui.TreeDialog; 17 18 22 public class TestGroupNodeDelegate extends TestNodeDelegate implements PropertyChangeListener { 23 24 public TestGroupNodeDelegate(TestGroup bean) { 25 super(bean, true); 26 } 27 28 38 public void propertyChange(PropertyChangeEvent 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 model=(DefaultTreeModel )(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 model=(DefaultTreeModel )(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 model=(DefaultTreeModel )(dlg.getTreeModel()); 69 model.nodesWereRemoved(this,new int[] {i},new Object [] {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 model=(DefaultTreeModel )(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 model=(DefaultTreeModel )(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 model=(DefaultTreeModel )(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 model=(DefaultTreeModel )(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 |