1 19 package org.netbeans.test.editor.app.core; 20 21 import java.util.ArrayList ; 22 import java.util.Arrays ; 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 ; 36 41 public class TestCompletionAction extends TestAction { 42 43 public static final String COMMAND="Command"; 44 private String command; 45 46 public TestCompletionAction(int num) { 47 this("completion"+Integer.toString(num),"completion-down"); 48 } 49 50 51 public TestCompletionAction(String name, String command) { 52 super(name); 53 setCommand(command); 54 } 55 56 public TestCompletionAction(Element node) { 57 super(node); 58 setCommand(ParsingUtils.fromSafeString(node.getAttribute(COMMAND))); } 60 61 public Element toXML(Element node) { 62 node = super.toXML(node); 63 node.setAttribute(COMMAND, ParsingUtils.toSafeString(getCommand())); 64 return node; 65 } 66 67 public void fromXML(Element 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 getProperty(String 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 name, Object 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 value) { 95 String oldValue = command; 96 command = value; 97 firePropertyChange(COMMAND, oldValue, command); 98 } 99 100 public String 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 [] getCompletionActions() { 118 ArrayList ret=new ArrayList (); 119 Object [] keys=getCompletion().getJDCPopupPanel().getActionMap().keys(); 120 for (int i=0;i < keys.length;i++) { 121 if (((String )keys[i]).indexOf("completion") == 0 ) { 122 ret.add(keys[i]); 123 } 124 } 125 String [] rets=(String [])(ret.toArray(new String [] {})); 126 Arrays.sort(rets); 127 128 return rets; 129 } 130 } 131 132 | Popular Tags |