1 19 20 package org.netbeans.beaninfo.editors; 21 22 import java.beans.*; 23 import java.io.File ; 24 import java.text.MessageFormat ; 25 import org.netbeans.core.UIExceptions; 26 import org.openide.explorer.propertysheet.ExPropertyEditor; 27 import org.openide.explorer.propertysheet.PropertyEnv; 28 29 import org.openide.loaders.DataFolder; 30 import org.openide.util.NbBundle; 31 32 37 public class DataFolderEditor extends PropertyEditorSupport implements ExPropertyEditor { 38 39 40 public DataFolderEditor() { 41 } 42 43 private DataFolderPanel dfPanel; 44 45 PropertyEnv env; 46 47 53 public String getAsText() { 54 DataFolder df = (DataFolder)getValue (); 55 String result; 56 if (df == null) { 57 result = getString ("LAB_DefaultDataFolder"); } else { 59 result = df.getName(); 60 } 61 if (result.length() ==0) { 62 result = File.pathSeparator; 63 } 64 return result; 65 } 66 67 73 public void setAsText(String text) { 74 if (text==null || 75 "".equals(text) || 76 text.equals(getString ("LAB_DefaultDataFolder")) || 77 File.pathSeparator.equals(text)) { 78 setValue(null); 80 } else { 81 IllegalArgumentException iae = new IllegalArgumentException (); 83 String msg = MessageFormat.format( 84 NbBundle.getMessage( 85 DataFolderEditor.class, "FMT_DF_UNKNOWN"), new Object [] {text}); UIExceptions.annotateUser(iae, iae.getMessage(), msg, null, 87 new java.util.Date ()); 88 throw iae; 89 } 90 } 91 92 public boolean supportsCustomEditor () { 93 return true; 94 } 95 96 public java.awt.Component getCustomEditor () { 97 dfPanel = getDFPanel(); 98 Object val = getValue(); 99 if (val instanceof DataFolder) { 100 dfPanel.setTargetFolder((DataFolder)val); 101 } 102 return dfPanel; 103 } 104 105 109 public void setValue(Object newValue) { 110 Object oldValue = getValue(); 111 super.setValue(newValue); 112 DataFolderPanel dfp = getDFPanel(); 113 if ((newValue != oldValue)&&(dfp != null) && (newValue instanceof DataFolder)){ 114 dfp.setTargetFolder((DataFolder)newValue); 115 } 116 117 } 118 119 122 void setDataFolder(DataFolder newDf) { 123 super.setValue(newDf); 124 } 125 126 public DataFolderPanel getDFPanel() { 127 if (dfPanel == null) { 128 dfPanel = new DataFolderPanel(this); 129 } 130 return dfPanel; 131 } 132 133 private static String getString (String s) { 134 return org.openide.util.NbBundle.getBundle (DataFolderEditor.class).getString (s); 135 } 136 137 public void attachEnv(PropertyEnv env) { 138 this.env = env; 139 } 140 } 141 | Popular Tags |