KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > gui > action > JavaCompletionInJspEditor


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-2006Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package gui.action;
21
22 import java.awt.event.KeyEvent JavaDoc;
23 import javax.swing.JComponent JavaDoc;
24 import org.netbeans.jellytools.EditorOperator;
25 import org.netbeans.jellytools.EditorWindowOperator;
26 import org.netbeans.jellytools.ProjectsTabOperator;
27 import org.netbeans.jellytools.nodes.Node;
28 import org.netbeans.jellytools.actions.ActionNoBlock;
29 import org.netbeans.jellytools.actions.Action.Shortcut;
30 import org.netbeans.jellytools.actions.OpenAction;
31 import org.netbeans.jemmy.operators.ComponentOperator;
32 import org.netbeans.performance.test.guitracker.LoggingRepaintManager;
33 import org.netbeans.test.web.performance.WebPerformanceTestCase;
34
35 /**
36  * Test of java completion in opened source editor.
37  *
38  * @author anebuzelsky@netbeans.org, mmirilovic@netbeans.org
39  */

40 public class JavaCompletionInJspEditor extends WebPerformanceTestCase {
41     
42     /** Creates a new instance of JavaCompletionInEditor */
43     public JavaCompletionInJspEditor(String JavaDoc testName) {
44         super(testName);
45         expectedTime = WINDOW_OPEN;
46         init();
47     }
48     
49     /** Creates a new instance of JavaCompletionInEditor */
50     public JavaCompletionInJspEditor(String JavaDoc testName, String JavaDoc performanceDataName) {
51         super(testName, performanceDataName);
52         expectedTime = WINDOW_OPEN;
53         init();
54     }
55     
56     protected void init() {
57         super.init();
58         WAIT_AFTER_OPEN = 6000;
59         shcut = new Shortcut(KeyEvent.VK_SPACE, KeyEvent.CTRL_MASK);
60     }
61     
62     public String JavaDoc text;
63     public Shortcut shcut;
64     protected LoggingRepaintManager.RegionFilter COMPLETION_DIALOG_FILTER =
65         new LoggingRepaintManager.RegionFilter() {
66         public boolean accept(JComponent JavaDoc comp) {
67             return comp.getClass().getName().startsWith("org.netbeans.editor.ext.");
68         }
69     
70         public String JavaDoc getFilterName() {
71             return "Completion Dialog Filter (accepts only componenets from" +
72                     "'org.netbeans.editor.ext.**' packages";
73         }
74 };
75     
76     public void testScriptletCC() {
77         text = "<% ";
78         measureTime();
79     }
80     
81     public void testExpressionCC() {
82         text = "<%= request.";
83         measureTime();
84     }
85     
86     public void testDeclarationCC() {
87         text = "<%! java.";
88         measureTime();
89     }
90     
91     public void testAllTags() {
92         text = "<";
93         measureTime();
94     }
95     
96     public void testTagAttribute1() {
97         text = "<%@page ";
98         measureTime();
99     }
100     
101     public void testTagAttribute2() {
102         text = "<jsp:useBean ";
103         measureTime();
104     }
105     
106     public void testAttributeValue1() {
107         text = "<%@page import=\"";
108         measureTime();
109     }
110     
111     public void testAttributeValue2() {
112         text = "<%@include file=\"";
113         measureTime();
114     }
115     
116     public void testAttributeValue3() {
117         text = "<jsp:useBean id=\"bean\" scope=\"";
118         measureTime();
119     }
120     
121     public void testAttributeValue4() {
122         text = "<jsp:useBean id=\"beanInstanceName\" scope=\"session\" class=\"";
123         measureTime();
124     }
125     
126     public void testAttributeValue5() {
127         text = "<jsp:getProperty name=\"bean\" property=\"";
128         measureTime();
129     }
130     
131     public void testAttributeValue6() {
132         text = "<%@taglib prefix=\"d\" tagdir=\"";
133         measureTime();
134     }
135     
136     private EditorOperator editorOperator;
137     
138     protected void initialize() {
139         jspOptions().setCaretBlinkRate(0);
140         // delay between the caret stops and the update of his position in status bar
141
jspOptions().setStatusBarCaretDelay(0);
142         jspOptions().setCodeFoldingEnable(false);
143         jspOptions().setCompletionAutoPopupDelay(0);
144         jspOptions().setJavaDocAutoPopup(false);
145         javaOptions().setCompletionAutoPopupDelay(0);
146         javaOptions().setJavaDocAutoPopup(false);
147         // turn off the error hightlighting feature
148
/* TODO doesn't work after retouche integration
149         javaSettings().setParsingErrors(0);
150         */

151         
152         new OpenAction().performAPI(new Node(new ProjectsTabOperator().
153             getProjectRootNode("TestWebProject"),"Web Pages|index.jsp"));
154         editorOperator = new EditorWindowOperator().getEditor("index.jsp");
155         eventTool().waitNoEvent(1000);
156         waitNoEvent(2000);
157     }
158     
159     public void prepare() {
160         // scroll to the place where we start
161
editorOperator.activateWindow();
162         clearTestLine();
163         editorOperator.setCaretPositionToLine(8);
164         // insert the initial text
165
editorOperator.insert(text);
166         // wait
167
eventTool().waitNoEvent(500);
168     }
169     
170     public ComponentOperator open(){
171         repaintManager().setRegionFilter(COMPLETION_DIALOG_FILTER);
172         // invoke the completion dialog
173
new ActionNoBlock(null, null, shcut).perform(editorOperator);
174         return null;
175     }
176     
177     public void close() {
178         repaintManager().setRegionFilter(null);
179         new ActionNoBlock(null, null, new Shortcut(KeyEvent.VK_ESCAPE)).
180             perform(editorOperator);
181         clearTestLine();
182     }
183     
184     protected void shutdown() {
185         super.shutdown();
186         editorOperator.closeDiscard();
187     }
188     
189     private void clearTestLine() {
190         int linelength = editorOperator.getText(8).length();
191         if (linelength > 1)
192             editorOperator.delete(8,1,linelength-1);
193     }
194 }
Popular Tags