KickJava   Java API By Example, From Geeks To Geeks.

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


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.util.ArrayList JavaDoc;
22 import org.netbeans.test.editor.app.core.TestGroup;
23 import org.w3c.dom.Element JavaDoc;
24
25 import java.util.Collection JavaDoc;
26 import java.util.Vector JavaDoc;
27 import org.netbeans.test.editor.app.core.actions.ActionRegistry;
28 import org.netbeans.test.editor.app.core.cookies.LoggingCookie;
29 import org.netbeans.test.editor.app.core.cookies.PackCookie;
30 import org.netbeans.test.editor.app.core.cookies.PerformCookie;
31 import org.netbeans.test.editor.app.gui.actions.TestDeleteAction;
32 import org.netbeans.test.editor.app.gui.actions.TestPackAction;
33 import org.netbeans.test.editor.app.gui.actions.TreeNewType;
34
35 /**
36  *
37  * @author ehucka
38  * @version
39  */

40 public class TestStep extends TestGroup {
41     
42     /** Creates new TestStep */
43     public TestStep(int num) {
44         this("step"+Integer.toString(num));
45     }
46     
47     public TestStep(String JavaDoc name) {
48         super(name);
49     }
50     
51     public TestStep(Element JavaDoc node) {
52         super(node);
53     }
54     
55     public Element JavaDoc toXML(Element JavaDoc node) {
56         return super.toXML(node);
57     }
58     
59     public void startLogging() {
60         System.err.println("Start Logging");
61         getLogger().clear();
62         getLogger().startLogging();
63     }
64     
65     public void stopLogging() {
66         System.err.println("Stop Logging");
67         getLogger().stopLogging();
68         TestNode[] nodes=getLogger().saveActions(this);
69         getLogger().clear();
70         firePropertyChange(ADD_CHILDS,null,nodes);
71     }
72     
73     public boolean isLogging() {
74         return getLogger().isLogging();
75     }
76     
77     public void perform() {
78         isPerforming=true;
79         for(int i=0;i < getChildCount();i++) {
80             if (!isPerforming) break;
81             get(i).perform();
82         }
83         isPerforming=false;
84     }
85     
86     public void stop() {
87         isPerforming=false;
88     }
89     
90     public void delete() {
91         TestNode n;
92         TestCallAction ca;
93         
94         for(int i=0;i < owner.getChildCount();i++) {
95             n=owner.get(i);
96             if (n instanceof TestCallAction) {
97                 ca=(TestCallAction)n;
98                 if (name.compareTo(ca.getToCall()) == 0) {
99                     ca.setToCall("");
100                 }
101                 if (name.compareTo(ca.getToSet()) == 0) {
102                     ca.setToSet("");
103                 }
104             }
105         }
106         owner.remove(this);
107     }
108     
109     public boolean isPacked() {
110         TestNode tn;
111         for (int i=0;i < getChildCount();i++) {
112             tn=(TestNode)(get(i));
113             if (tn instanceof TestLogAction && tn.getName().compareTo(TestStringAction.STRINGED_NAME) == 0) {
114                 return false;
115             }
116         }
117         return true;
118     }
119     
120     public void pack() {
121         TestAction[] tas=TestStringAction.generate(getChildNodes());
122         removeAll();
123         addNodes(tas);
124     }
125     
126     protected void registerNewTypes() {
127         ActionRegistry.getDefault().addRegisteredNewType(getClass(), TestLogAction.class);
128         ActionRegistry.getDefault().addRegisteredNewType(getClass(), TestStringAction.class);
129         ActionRegistry.getDefault().addRegisteredNewType(getClass(), TestCompletionAction.class);
130         ActionRegistry.getDefault().addRegisteredNewType(getClass(), TestSetKitAction.class);
131         ActionRegistry.getDefault().addRegisteredNewType(getClass(), TestSetIEAction.class);
132         ActionRegistry.getDefault().addRegisteredNewType(getClass(), TestSetJavaIEAction.class);
133         ActionRegistry.getDefault().addRegisteredNewType(getClass(), TestSetCompletionAction.class);
134         ActionRegistry.getDefault().addRegisteredNewType(getClass(), TestAddAbbreviationAction.class);
135     }
136     
137     protected void registerCookies() {
138         getCookieSet().put(PerformCookie.class,new PerformCookie() {
139             public void perform() {
140                 TestStep.this.perform();
141             }
142             
143             public boolean isPerforming() {
144                 return TestStep.this.isPerforming;
145             }
146         });
147         getCookieSet().put(LoggingCookie.class,new LoggingCookie() {
148             public void start() {
149                 TestStep.this.startLogging();
150             }
151             public void stop() {
152                 TestStep.this.stopLogging();
153             }
154             public boolean isLogging() {
155                 return TestStep.this.isLogging();
156             }
157         });
158         getCookieSet().put(PackCookie.class,new PackCookie() {
159             public void pack() {
160                 TestStep.this.pack();
161             }
162             public boolean isPacked() {
163                 return TestStep.this.isPacked();
164             }
165         });
166     }
167 }
168
Popular Tags