1 6 7 package org.netbeans.test.editor.app.core; 8 9 import java.util.Map ; 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 ; 19 20 24 public class TestAddAbbreviationAction extends TestAddAction { 25 26 private String abbrevName = ""; 27 28 private String abbrevContent = ""; 29 30 public static String ABBREV_NAME = "AbbreviationName"; 31 32 public static String ABBREV_CONTENT = "AbbreviationContent"; 33 34 35 public TestAddAbbreviationAction(int num) { 36 this("addAbbreviation"+Integer.toString(num)); 37 } 38 39 public TestAddAbbreviationAction(String name) { 40 super(name); 41 } 42 43 public TestAddAbbreviationAction(Element 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 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 getProperty(String 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 name, Object value) throws BadPropertyNameException { 77 if (value == null) { 78 throw new NullPointerException (); 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 toXML(Element 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 map=opts.getAbbrevMap(); 103 map.put(abbrevName, abbrevContent); 104 opts.setAbbrevMap(map); 105 } 106 107 111 public java.lang.String getAbbrevName() { 112 return abbrevName; 113 } 114 115 119 public void setAbbrevName(java.lang.String abbrevName) { 120 String old = getAbbrevName(); 121 122 this.abbrevName = abbrevName; 123 firePropertyChange(ABBREV_NAME, old, abbrevName); 124 } 125 126 130 public java.lang.String getAbbrevContent() { 131 return abbrevContent; 132 } 133 134 138 public void setAbbrevContent(java.lang.String abbrevContent) { 139 String old = getAbbrevContent(); 140 141 this.abbrevContent = abbrevContent; 142 firePropertyChange(ABBREV_CONTENT, old, abbrevContent); 143 } 144 145 } 146 | Popular Tags |