KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.util.Arrays JavaDoc;
23 import org.netbeans.editor.Utilities;
24 import org.netbeans.editor.ext.Completion;
25 import org.netbeans.editor.ext.ExtEditorUI;
26 import org.netbeans.test.editor.app.Main;
27 import org.netbeans.test.editor.app.gui.*;
28 import org.netbeans.test.editor.app.core.TestAction;
29 import org.netbeans.test.editor.app.core.properties.ArrayProperty;
30 import org.netbeans.test.editor.app.core.properties.BadPropertyNameException;
31 import org.netbeans.test.editor.app.core.properties.Properties;
32 import org.netbeans.test.editor.app.gui.actions.TestDeleteAction;
33 import org.netbeans.test.editor.app.gui.tree.ActionsCache;
34 import org.netbeans.test.editor.app.util.ParsingUtils;
35 import org.w3c.dom.Element JavaDoc;
36 /**
37  *
38  * @author ehucka
39  * @version
40  */

41 public class TestCompletionAction extends TestAction {
42     
43     public static final String JavaDoc COMMAND="Command";
44     private String JavaDoc command;
45     
46     public TestCompletionAction(int num) {
47     this("completion"+Integer.toString(num),"completion-down");
48     }
49     
50     /** Creates new TestLogAction */
51     public TestCompletionAction(String JavaDoc name, String JavaDoc command) {
52     super(name);
53     setCommand(command);
54     }
55     
56     public TestCompletionAction(Element JavaDoc node) {
57     super(node);
58     setCommand(ParsingUtils.fromSafeString(node.getAttribute(COMMAND))); //???
59
}
60     
61     public Element JavaDoc toXML(Element JavaDoc node) {
62     node = super.toXML(node);
63     node.setAttribute(COMMAND, ParsingUtils.toSafeString(getCommand()));
64     return node;
65     }
66     
67     public void fromXML(Element JavaDoc node) throws BadPropertyNameException {
68     super.fromXML(node);
69     setCommand(ParsingUtils.fromSafeString(node.getAttribute(COMMAND)));
70     }
71     
72     public Properties getProperties() {
73     Properties ret=super.getProperties();
74     ret.put(COMMAND, new ArrayProperty(command,getCompletionActions()));
75     return ret;
76     }
77     
78     public Object JavaDoc getProperty(String JavaDoc name) throws BadPropertyNameException {
79     if (name.compareTo(COMMAND) == 0) {
80         return new ArrayProperty(command,getCompletionActions());
81     } else {
82         return super.getProperty(name);
83     }
84     }
85     
86     public void setProperty(String JavaDoc name, Object JavaDoc value) throws BadPropertyNameException {
87     if (name.compareTo(COMMAND) == 0) {
88         setCommand(((ArrayProperty)(value)).getProperty());
89     } else {
90         super.setProperty(name, value);
91     }
92     }
93     
94     public void setCommand(String JavaDoc value) {
95     String JavaDoc oldValue = command;
96     command = value;
97     firePropertyChange(COMMAND, oldValue, command);
98     }
99     
100     public String JavaDoc getCommand() {
101     return command;
102     }
103     
104     public void perform() {
105     isPerforming=true;
106     getLogger().performAction(this);
107     isPerforming=false;
108     }
109     
110     public void stop() {
111     }
112     
113     private Completion getCompletion() {
114     return ((ExtEditorUI)(Utilities.getEditorUI(Main.frame.getEditor()))).getCompletion();
115     }
116     
117     public String JavaDoc[] getCompletionActions() {
118     ArrayList JavaDoc ret=new ArrayList JavaDoc();
119     Object JavaDoc[] keys=getCompletion().getJDCPopupPanel().getActionMap().keys();
120     for (int i=0;i < keys.length;i++) {
121         if (((String JavaDoc)keys[i]).indexOf("completion") == 0 ) {
122         ret.add(keys[i]);
123         }
124     }
125     String JavaDoc[] rets=(String JavaDoc[])(ret.toArray(new String JavaDoc[] {}));
126     Arrays.sort(rets);
127     
128     return rets;
129     }
130 }
131
132
Popular Tags