1 19 package org.netbeans.modules.j2ee.sun.share.config; 20 21 import java.beans.PropertyEditor ; 22 import java.beans.PropertyEditorSupport ; 23 import java.awt.Component ; 24 import java.awt.event.ActionListener ; 25 import javax.swing.JComponent ; 26 import javax.swing.KeyStroke ; 27 import org.netbeans.modules.j2ee.sun.share.configbean.ASDDVersion; 28 29 import org.openide.explorer.propertysheet.ExPropertyEditor; 30 import org.openide.explorer.propertysheet.InplaceEditor; 31 import org.openide.explorer.propertysheet.PropertyEnv; 32 33 34 43 public class VersionEditor extends PropertyEditorSupport implements ExPropertyEditor, InplaceEditor.Factory { 44 45 51 public static final int APP_SERVER_7_0 = 0; 52 public static final int APP_SERVER_8_0 = 1; 54 public static final int APP_SERVER_8_1 = 2; 55 public static final int APP_SERVER_9_0 = 3; 56 57 private String curr_Sel; 58 private String [] choices; 59 60 public VersionEditor(final int minVersion, final int maxVersion) { 61 assert minVersion >= APP_SERVER_7_0 && minVersion <= APP_SERVER_9_0; 62 assert maxVersion >= APP_SERVER_7_0 && maxVersion <= APP_SERVER_9_0; 63 assert minVersion <= maxVersion; 64 65 int numChoices = maxVersion - minVersion + 1; 66 curr_Sel = ASDDVersion.asDDVersions[APP_SERVER_8_1].toString(); 67 choices = new String [numChoices]; 68 for(int i = 0; i < numChoices; i++) { 69 choices[i] = ASDDVersion.asDDVersions[minVersion + i].toString(); 70 } 71 } 72 73 public String getAsText() { 74 return curr_Sel; 75 } 76 77 public void setAsText(String string) throws IllegalArgumentException { 78 if((string == null) || (string.equals(""))) { throw new IllegalArgumentException ("text field cannot be empty"); } else { 81 curr_Sel = string; 82 } 83 this.firePropertyChange(); 84 } 85 86 public void setValue(Object val) { 87 if (! (val instanceof String )) { 88 throw new IllegalArgumentException ("value must be String"); } 90 91 curr_Sel = (String ) val; 92 super.setValue(curr_Sel); 93 } 94 95 public Object getValue() { 96 return curr_Sel; 97 } 98 99 public String getJavaInitializationString() { 100 return getAsText(); 101 } 102 103 public String [] getTags() { 104 return choices; 105 } 106 107 110 public void attachEnv(PropertyEnv env) { 111 env.registerInplaceEditorFactory(this); 112 } 113 114 117 public InplaceEditor getInplaceEditor() { 118 return null; 119 } 120 121 123 static int fromASDDVersion(ASDDVersion asDDVersion) { 124 int result = APP_SERVER_8_1; 125 126 if(ASDDVersion.SUN_APPSERVER_7_0.equals(asDDVersion)) { 127 result = APP_SERVER_7_0; 128 } else if(ASDDVersion.SUN_APPSERVER_8_0.equals(asDDVersion)) { 131 result = APP_SERVER_8_0; 132 } else if(ASDDVersion.SUN_APPSERVER_8_1.equals(asDDVersion)) { 133 result = APP_SERVER_8_1; 134 } else if(ASDDVersion.SUN_APPSERVER_9_0.equals(asDDVersion)) { 135 result = APP_SERVER_9_0; 136 } else { 137 throw new IllegalArgumentException ("Unrecognized appserver version: " + asDDVersion); 138 } 139 140 return result; 141 } 142 } 143 | Popular Tags |