KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * TestAddAbbreviationAction.java
3  *
4  * Created on December 10, 2002, 3:17 PM
5  */

6
7 package org.netbeans.test.editor.app.core;
8
9 import java.util.Map JavaDoc;
10 import org.netbeans.modules.java.editor.options.JavaOptions;
11 import org.netbeans.test.editor.app.core.properties.BadPropertyNameException;
12 import org.netbeans.test.editor.app.core.properties.MultiLineStringProperty;
13 import org.netbeans.test.editor.app.core.properties.Properties;
14 import org.netbeans.test.editor.app.core.properties.Property;
15 import org.netbeans.test.editor.app.core.properties.StringProperty;
16 import org.netbeans.test.editor.app.util.ParsingUtils;
17 import org.openide.options.SystemOption;
18 import org.w3c.dom.Element JavaDoc;
19
20 /**
21  *
22  * @author eh103527
23  */

24 public class TestAddAbbreviationAction extends TestAddAction {
25     
26     private String JavaDoc abbrevName = "";
27     
28     private String JavaDoc abbrevContent = "";
29     
30     public static String JavaDoc ABBREV_NAME = "AbbreviationName";
31     
32     public static String JavaDoc ABBREV_CONTENT = "AbbreviationContent";
33     
34     /** Creates a new instance of TestAddAbbreviationAction */
35     public TestAddAbbreviationAction(int num) {
36         this("addAbbreviation"+Integer.toString(num));
37     }
38     
39     public TestAddAbbreviationAction(String JavaDoc name) {
40         super(name);
41     }
42     
43     public TestAddAbbreviationAction(Element JavaDoc node) {
44         super(node);
45         setAbbrevName(ParsingUtils.fromSafeString(node.getAttribute(ABBREV_NAME)));
46         if ((abbrevContent = ParsingUtils.loadString(node, ABBREV_CONTENT)) == null) {
47             abbrevContent="";
48         }
49     }
50     
51     public void fromXML(Element JavaDoc node) throws BadPropertyNameException {
52         super.fromXML(node);
53         setAbbrevName(ParsingUtils.fromSafeString(node.getAttribute(ABBREV_NAME)));
54         if ((abbrevContent = ParsingUtils.loadString(node, ABBREV_CONTENT)) == null) {
55             abbrevContent="";
56         }
57     }
58     
59     public Properties getProperties() {
60         Properties ret=super.getProperties();
61         ret.put(ABBREV_NAME, new StringProperty(abbrevName));
62         ret.put(ABBREV_CONTENT, new MultiLineStringProperty(abbrevContent));
63         return ret;
64     }
65     
66     public Object JavaDoc getProperty(String JavaDoc name) throws BadPropertyNameException {
67         if (name.compareTo(ABBREV_NAME) == 0) {
68             return new StringProperty(abbrevName);
69         } else if (name.compareTo(ABBREV_CONTENT) == 0) {
70             return new MultiLineStringProperty(abbrevContent);
71         } else {
72             return super.getProperty(name);
73         }
74     }
75     
76     public void setProperty(String JavaDoc name, Object JavaDoc value) throws BadPropertyNameException {
77         if (value == null) {
78             throw new NullPointerException JavaDoc();
79         } else if (name.compareTo(ABBREV_NAME) == 0) {
80             setAbbrevName(((Property)(value)).getProperty());
81         } else if (name.compareTo(ABBREV_CONTENT) == 0) {
82             setAbbrevContent(((Property)(value)).getProperty());
83         } else {
84             super.setProperty(name, value);
85         }
86     }
87     
88     public Element JavaDoc toXML(Element JavaDoc node) {
89         node = super.toXML(node);
90         node.setAttribute(ABBREV_NAME, ParsingUtils.toSafeString(getAbbrevName()));
91         node = ParsingUtils.saveString(node, ABBREV_CONTENT, abbrevContent);
92         return node;
93     }
94     
95     public void perform() {
96         super.perform();
97         if (abbrevName == null || abbrevName.length() == 0) {
98             System.err.println("Error performing Add Abbreviation Action: abbreviation name is empty.");
99             return;
100         }
101         JavaOptions opts = (JavaOptions)(SystemOption.findObject(JavaOptions.class));
102         Map JavaDoc map=opts.getAbbrevMap();
103         map.put(abbrevName, abbrevContent);
104         opts.setAbbrevMap(map);
105     }
106     
107     /** Getter for property abbrevName.
108      * @return Value of property abbrevName.
109      *
110      */

111     public java.lang.String JavaDoc getAbbrevName() {
112         return abbrevName;
113     }
114     
115     /** Setter for property abbrevName.
116      * @param abbrevName New value of property abbrevName.
117      *
118      */

119     public void setAbbrevName(java.lang.String JavaDoc abbrevName) {
120         String JavaDoc old = getAbbrevName();
121         
122         this.abbrevName = abbrevName;
123         firePropertyChange(ABBREV_NAME, old, abbrevName);
124     }
125     
126     /** Getter for property abbrevContent.
127      * @return Value of property abbrevContent.
128      *
129      */

130     public java.lang.String JavaDoc getAbbrevContent() {
131         return abbrevContent;
132     }
133     
134     /** Setter for property abbrevContent.
135      * @param abbrevContent New value of property abbrevContent.
136      *
137      */

138     public void setAbbrevContent(java.lang.String JavaDoc abbrevContent) {
139         String JavaDoc old = getAbbrevContent();
140         
141         this.abbrevContent = abbrevContent;
142         firePropertyChange(ABBREV_CONTENT, old, abbrevContent);
143     }
144     
145 }
146
Popular Tags