1 19 20 22 25 package org.netbeans.modules.tasklist.usertasks.editors; 26 27 import java.util.Date ; 28 import java.text.ParseException ; 29 import java.text.SimpleDateFormat ; 30 import java.awt.Component ; 31 import java.beans.FeatureDescriptor ; 32 import java.beans.PropertyEditorSupport ; 33 import org.netbeans.modules.tasklist.usertasks.DateSelectionPanel; 34 import org.openide.explorer.propertysheet.ExPropertyEditor; 35 import org.openide.explorer.propertysheet.PropertyEnv; 36 37 import org.openide.nodes.Node; 39 import org.openide.util.Exceptions; 40 import org.openide.util.NbBundle; 41 42 43 49 public class DateEditor extends PropertyEditorSupport 50 implements ExPropertyEditor { 51 private static SimpleDateFormat format = new SimpleDateFormat (); 52 53 private boolean editable = true; 56 57 62 public boolean isEditable(){ 63 return editable; 64 } 65 66 public void setAsText(String s) throws java.lang.IllegalArgumentException { 67 if (s.trim().length() == 0) { 68 setValue(null); 69 return; 70 } 71 try { 72 setValue(format.parse(s)); 73 } catch (ParseException e) { 74 String msg = NbBundle.getMessage(DateEditor.class, 75 "IllegalDateValue", new Object [] {s}); RuntimeException iae = new IllegalArgumentException (msg); 77 Exceptions.attachLocalizedMessage(iae, msg); 78 throw iae; 79 } 80 } 81 82 public String getAsText() { 83 Object val = getValue(); 84 if (val instanceof Date ) { 85 return format.format((Date ) val); 86 } else if (val instanceof Long ) { 87 long v = ((Long ) val).longValue(); 88 if (v == 0) 89 return ""; else 91 return format.format(new Date (v)); 92 } else { 93 return ""; } 95 } 96 97 public boolean supportsCustomEditor () { 98 return true; 99 } 100 101 public Component getCustomEditor() { 102 Date d; 103 if (getValue() instanceof Date ) { 104 d = (Date ) getValue(); 105 } else if (getValue() instanceof Long ) { 106 d = new Date (((Long ) getValue()).longValue()); 107 } else { 108 d = new Date (); 109 setValue(d); 110 } 111 return new DateSelectionPanel(d); 112 } 113 114 public void attachEnv(PropertyEnv env) { 115 FeatureDescriptor desc = env.getFeatureDescriptor(); 116 if (desc instanceof Node.Property){ 117 Node.Property prop = (Node.Property)desc; 118 editable = prop.canWrite(); 119 } 120 } 121 } 122 | Popular Tags |