1 19 package org.netbeans.test.editor.app.core; 20 21 import org.netbeans.modules.java.editor.options.JavaOptions; 22 import org.w3c.dom.Element ; 23 import javax.swing.text.Document ; 24 import org.netbeans.test.editor.app.core.properties.BadPropertyNameException; 25 import org.netbeans.test.editor.app.core.properties.BooleanProperty; 26 import org.netbeans.test.editor.app.core.properties.Properties; 27 import org.netbeans.test.editor.app.gui.actions.TestDeleteAction; 28 import org.netbeans.test.editor.app.gui.tree.ActionsCache; 29 import org.netbeans.test.editor.app.util.ParsingUtils; 30 import org.openide.options.SystemOption; 31 32 37 public class TestSetCompletionAction extends TestSetAction { 38 39 private boolean caseSensitive; 40 private boolean instantSubstitution; 41 private boolean naturalSort; 42 43 public static String CASE_SENSITIVE = "CaseSensitive"; 44 public static String INSTANT_SUBSTITUTION = "InstantSubstitution"; 45 public static String NATURAL_SORT = "NaturalSort"; 46 47 48 public TestSetCompletionAction(int num) { 49 this("setCompletion"+Integer.toString(num)); 50 } 51 52 public TestSetCompletionAction(String name) { 53 super(name); 54 } 55 56 public TestSetCompletionAction(Element node) { 57 super(node); 58 setCaseSensitive(ParsingUtils.readBoolean(node, CASE_SENSITIVE)); 59 setInstantSubstitution(ParsingUtils.readBoolean(node, INSTANT_SUBSTITUTION)); 60 setNaturalSort(ParsingUtils.readBoolean(node, NATURAL_SORT)); 61 } 62 63 public Element toXML(Element node) { 64 node = super.toXML(node); 65 66 node.setAttribute(CASE_SENSITIVE, String.valueOf(getCaseSensitive())); 67 node.setAttribute(INSTANT_SUBSTITUTION, String.valueOf(getInstantSubstitution())); 68 node.setAttribute(NATURAL_SORT, String.valueOf(getNaturalSort())); 69 return node; 70 } 71 72 public void fromXML(Element node) throws BadPropertyNameException { 73 super.fromXML(node); 74 setCaseSensitive(ParsingUtils.readBoolean(node, CASE_SENSITIVE)); 75 setInstantSubstitution(ParsingUtils.readBoolean(node, INSTANT_SUBSTITUTION)); 76 setNaturalSort(ParsingUtils.readBoolean(node, NATURAL_SORT)); 77 } 78 79 public Properties getProperties() { 80 Properties ret=super.getProperties(); 81 ret.put(CASE_SENSITIVE, new BooleanProperty(caseSensitive)); 82 ret.put(INSTANT_SUBSTITUTION, new BooleanProperty(instantSubstitution)); 83 ret.put(NATURAL_SORT, new BooleanProperty(naturalSort)); 84 return ret; 85 } 86 87 public Object getProperty(String name) throws BadPropertyNameException { 88 if (name.compareTo(CASE_SENSITIVE) == 0) { 89 return new BooleanProperty(caseSensitive); 90 } else if (name.compareTo(INSTANT_SUBSTITUTION) == 0) { 91 return new BooleanProperty(instantSubstitution); 92 } else if (name.compareTo(NATURAL_SORT) == 0) { 93 return new BooleanProperty(naturalSort); 94 } else { 95 return super.getProperty(name); 96 } 97 } 98 99 public void setProperty(String name, Object value) throws BadPropertyNameException { 100 if (name.compareTo(CASE_SENSITIVE) == 0) { 101 setCaseSensitive(((BooleanProperty)value).getValue()); 102 } else if (name.compareTo(INSTANT_SUBSTITUTION) == 0) { 103 setInstantSubstitution(((BooleanProperty)value).getValue()); 104 } else if (name.compareTo(NATURAL_SORT) == 0) { 105 setNaturalSort(((BooleanProperty)value).getValue()); 106 } else { 107 super.setProperty(name, value); 108 } 109 } 110 111 public boolean getCaseSensitive() { 112 return caseSensitive; 113 } 114 115 public void setCaseSensitive(boolean value) { 116 boolean old = getCaseSensitive(); 117 118 caseSensitive = value; 119 firePropertyChange(CASE_SENSITIVE, old ? Boolean.TRUE : Boolean.FALSE, value ? Boolean.TRUE : Boolean.FALSE); 120 } 121 122 public boolean getInstantSubstitution() { 123 return instantSubstitution; 124 } 125 126 public void setInstantSubstitution(boolean value) { 127 boolean old = getInstantSubstitution(); 128 129 instantSubstitution = value; 130 firePropertyChange(INSTANT_SUBSTITUTION, old ? Boolean.TRUE : Boolean.FALSE, value ? Boolean.TRUE : Boolean.FALSE); 131 } 132 133 public boolean getNaturalSort() { 134 return naturalSort; 135 } 136 137 public void setNaturalSort(boolean value) { 138 boolean old = getNaturalSort(); 139 140 naturalSort = value; 141 firePropertyChange(NATURAL_SORT, old ? Boolean.TRUE : Boolean.FALSE, value ? Boolean.TRUE : Boolean.FALSE); 142 } 143 144 public void perform() { 145 super.perform(); 146 JavaOptions opts = (JavaOptions)(SystemOption.findObject(JavaOptions.class)); 147 opts.setCompletionCaseSensitive(caseSensitive); 148 opts.setCompletionInstantSubstitution(instantSubstitution); 149 opts.setCompletionNaturalSort(naturalSort); 150 } 151 } 152 | Popular Tags |