KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > test > editor > app > core > TestNode


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.test.editor.app.core;
20
21 import java.beans.*;
22 import javax.swing.JEditorPane JavaDoc;
23
24 import java.util.Vector JavaDoc;
25
26 import org.w3c.dom.Element JavaDoc;
27 import java.io.IOException JavaDoc;
28 import java.util.Vector JavaDoc;
29 import java.util.Collection JavaDoc;
30 import java.util.Enumeration JavaDoc;
31 import java.util.HashMap JavaDoc;
32 import javax.swing.tree.TreeNode JavaDoc;
33 import org.netbeans.test.editor.app.core.actions.ActionRegistry;
34 import org.netbeans.test.editor.app.core.cookies.Cookie;
35 import org.netbeans.test.editor.app.core.cookies.PerformCookie;
36 import org.netbeans.test.editor.app.core.properties.ArrayProperty;
37 import org.netbeans.test.editor.app.core.properties.BadPropertyNameException;
38 import org.netbeans.test.editor.app.core.properties.Properties;
39 import org.netbeans.test.editor.app.core.properties.StringProperty;
40 import org.netbeans.test.editor.app.gui.actions.TestDeleteAction;
41 import org.netbeans.test.editor.app.gui.actions.TestDownAction;
42 import org.netbeans.test.editor.app.gui.actions.TestPropertiesAction;
43 import org.netbeans.test.editor.app.gui.actions.TestRenameAction;
44 import org.netbeans.test.editor.app.gui.actions.TestUpAction;
45 import org.netbeans.test.editor.app.gui.tree.ActionsCache;
46 import org.netbeans.test.editor.app.gui.tree.TestNodeDelegate;
47
48 /**
49  *
50  * @author ehucka
51  * @version
52  */

53 public abstract class TestNode extends Object JavaDoc implements java.io.Serializable JavaDoc, XMLNode {
54     
55     public static final String JavaDoc CHANGE_NAME = "Change Name";
56     
57     public static final String JavaDoc NAME = "Name";
58     
59     protected String JavaDoc name;
60     
61     protected boolean isPerforming;
62     
63     protected static int nameCounter=1;
64     
65     public TestGroup owner;
66     
67     protected PropertyChangeSupport propertySupport;
68     
69     private TreeNode JavaDoc nodeDelegate = null;
70     
71     protected HashMap JavaDoc cookieSet;
72     
73     /** Creates new TestNode */
74     public TestNode(String JavaDoc name) {
75         propertySupport = new PropertyChangeSupport( this );
76         this.name=name;
77         isPerforming=false;
78         registerActions();
79         registerCookies();
80     }
81     
82     public TestNode(Element JavaDoc node) {
83         this(node.getAttribute(NAME));
84     }
85     
86     public abstract boolean isParent();
87     public abstract void perform();
88     public abstract void stop();
89     protected abstract void registerCookies();
90     
91     public Element JavaDoc toXML(Element JavaDoc node) {
92         node.setAttribute(NAME, name);
93         return node;
94     }
95     
96     public JEditorPane JavaDoc getEditor() {
97         return owner.getEditor();
98     }
99     
100     public Logger getLogger() {
101         return owner.getLogger();
102     }
103     
104     public String JavaDoc getName() {
105         return name;
106     }
107     
108     public final void setName(String JavaDoc value) {
109         String JavaDoc oldValue = name;
110         name = value;
111         firePropertyChange(CHANGE_NAME, oldValue, name);
112     }
113     
114     public void addPropertyChangeListener(PropertyChangeListener listener) {
115         propertySupport.addPropertyChangeListener(listener);
116     }
117     
118     public void removePropertyChangeListener(PropertyChangeListener listener) {
119         propertySupport.removePropertyChangeListener(listener);
120     }
121     
122     public void firePropertyChange(String JavaDoc name,Object JavaDoc oldV, Object JavaDoc newV) {
123         if (oldV == newV) oldV=null;
124         propertySupport.firePropertyChange(name,oldV,newV);
125     }
126     
127     public boolean isPerfoming() {
128         return isPerforming;
129     }
130     
131     public void delete() {
132         owner.remove(this);
133     }
134     
135     public static int getNameCounter() {
136         return nameCounter++;
137     }
138     
139     public TreeNode JavaDoc createNodeDelegate() {
140         return new TestNodeDelegate(this);
141     }
142     
143     public final TreeNode JavaDoc getNodeDelegate() {
144         if (nodeDelegate == null) {
145             nodeDelegate = createNodeDelegate();
146         }
147         return nodeDelegate;
148     }
149     //?????????????????????????????????????????????
150
public HashMap JavaDoc getCookieSet() {
151         if (cookieSet == null) {
152             cookieSet=new HashMap JavaDoc();
153         }
154         return cookieSet;
155     }
156     
157     public Cookie getCookie(Class JavaDoc clazz) {
158         return (Cookie)cookieSet.get(clazz);
159     }
160     
161     protected void registerActions() {
162         ActionsCache.getDefault().addNodeActions(getClass(), ActionRegistry.getDefault().getActions(getCookieSet().values()));
163         ActionsCache.getDefault().addNodeAction(getClass(), new TestUpAction());
164         ActionsCache.getDefault().addNodeAction(getClass(), new TestDownAction());
165         ActionsCache.getDefault().addNodeAction(getClass(), new TestRenameAction());
166         ActionsCache.getDefault().addNodeAction(getClass(), new TestDeleteAction());
167         ActionsCache.getDefault().addNodeAction(getClass(), new TestRenameAction());
168         ActionsCache.getDefault().addNodeAction(getClass(), new TestPropertiesAction());
169     }
170     
171     public final Vector JavaDoc getActions() {
172         Vector JavaDoc v=ActionsCache.getDefault().getActions(getClass());
173         if (v == null) {
174             registerActions();
175             v=ActionsCache.getDefault().getActions(getClass());
176         }
177         return v;
178     }
179     
180     public TestGroup getOwner() {
181         return owner;
182     }
183     
184     public void fromXML(Element JavaDoc node) throws BadPropertyNameException {
185         name=node.getAttribute(NAME);
186     }
187     
188     public Properties getProperties() {
189         Properties ret=new Properties();
190         ret.put(NAME, new StringProperty(name));
191         return ret;
192     }
193     
194     public Object JavaDoc getProperty(String JavaDoc name) throws BadPropertyNameException {
195         if (name.compareTo(NAME) == 0) {
196             return new StringProperty(name);
197         } else {
198             throw new BadPropertyNameException(name+" isn't name of any property.");
199         }
200     }
201     
202     public void setProperty(String JavaDoc name, Object JavaDoc value) throws BadPropertyNameException {
203         if (name.compareTo(NAME) == 0) {
204             setName(((StringProperty)value).getProperty());
205         } else {
206             throw new BadPropertyNameException(name+" isn't name of any property.");
207         }
208     }
209     
210     public String JavaDoc toString() {
211         return name;
212     }
213     
214 }
Popular Tags