1 18 package org.netbeans.modules.changelog.settings; 19 20 import java.beans.*; 21 import java.util.*; 22 23 import org.openide.util.*; 24 25 import org.netbeans.modules.changelog.html.*; 26 27 31 public class DefaultServerInfoPE extends PropertyEditorSupport { 32 33 private static final java.util.ResourceBundle bundle = NbBundle.getBundle(DefaultServerInfoPE.class); 34 35 36 private final static String DEFAULTS = bundle.getString("DefaultServerInfoPE.noDefault.text"); 38 39 private String [] texts; 40 41 private String [] ids; 42 43 44 public String [] getTags() { 45 if (texts == null ) { 46 initValues(); 47 } 48 return texts; 49 } 50 51 private void initValues() { 52 Lookup.Template template = new Lookup.Template(ChangeLogHTMLService.class); 53 Lookup.Result result = Lookup.getDefault().lookup(template); 54 Collection col = result.allItems(); 55 texts = new String [col.size() + 1]; 56 ids = new String [col.size() + 1]; 57 texts[0] = DEFAULTS; 58 ids[0] = ""; 59 Iterator it = col.iterator(); 60 int index = 1; 61 while (it.hasNext()) { 62 Lookup.Item item = (Lookup.Item)it.next(); 63 ChangeLogHTMLService serv = (ChangeLogHTMLService)item.getInstance(); 64 texts[index] = serv.getName(); 65 ids[index] = item.getId(); 66 index = index + 1; 67 } 68 } 69 70 71 private int findIndexInArray(String [] arr, String value) { 72 for (int i = 0; i < arr.length; i++) { 73 if (value.equals(arr[i])) { 74 return i; 75 } 76 } 77 return -1; 78 } 79 80 89 public String getAsText() { 90 if (texts == null ) { 91 initValues(); 92 } 93 String value = (String )getValue(); 94 if (value == null) { 95 value = ""; 96 } 97 int i = findIndexInArray(ids, value); 98 if (i != -1) { 99 return texts[i]; 100 } 101 setValue(""); 102 return DEFAULTS; 103 } 104 105 112 public void setAsText(String text) throws java.lang.IllegalArgumentException { 113 if (texts == null ) { 114 initValues(); 115 } 116 int i = findIndexInArray(texts, text); 117 if (i != -1) { 118 setValue(ids[i]); 119 return; 120 } 121 setValue(""); 122 } 123 124 } 125 126 | Popular Tags |