--- /dev/null
+// StringAttributeEditor.java\r
+// $Id: StringAttributeEditor.java,v 1.1 2010/06/15 12:20:43 smhuang Exp $\r
+// (c) COPYRIGHT MIT and INRIA, 1997.\r
+// Please first read the full copyright statement in file COPYRIGHT.html\r
+\r
+package org.w3c.jigadmin.attributes ;\r
+\r
+import java.awt.Component;\r
+\r
+import javax.swing.JTextField;\r
+import javax.swing.BorderFactory;\r
+\r
+import java.util.Properties;\r
+import org.w3c.tools.resources.Attribute;\r
+import org.w3c.tools.resources.StringAttribute;\r
+\r
+import org.w3c.jigsaw.admin.RemoteResource;\r
+import org.w3c.jigsaw.admin.RemoteAccessException;\r
+\r
+import org.w3c.jigadm.RemoteResourceWrapper;\r
+import org.w3c.jigadm.editors.AttributeEditor;\r
+\r
+public class StringAttributeEditor extends AttributeEditor {\r
+\r
+ private String origs;\r
+ JTextField widget;\r
+\r
+ /**\r
+ * Tells if the edited value has changed\r
+ * @return true if the value changed.\r
+ */\r
+\r
+ public boolean hasChanged() {\r
+ return !origs.equals(widget.getText());\r
+ }\r
+\r
+ /**\r
+ * set the current value to be the original value, ie: changed\r
+ * must return <strong>false</strong> after a reset.\r
+ */\r
+\r
+ public void clearChanged() {\r
+ origs = widget.getText();\r
+ }\r
+\r
+ /**\r
+ * reset the changes (if any)\r
+ */\r
+\r
+ public void resetChanges() {\r
+ widget.setText(origs);\r
+ }\r
+\r
+ /**\r
+ * Get the current value of the edited value\r
+ * @return an object or <strong>null</strong> if the object was not\r
+ * initialized\r
+ */\r
+\r
+ public Object getValue() {\r
+ String wt = widget.getText();\r
+ if ((wt != null) && (wt.length() > 0)) {\r
+ return widget.getText();\r
+ } else {\r
+ return null;\r
+ }\r
+ }\r
+\r
+ /**\r
+ * Set the value of the edited value\r
+ * @param o the new value.\r
+ */\r
+\r
+ public void setValue(Object o) {\r
+ widget.setText(o.toString());\r
+ }\r
+\r
+ /**\r
+ * get the Component created by the editor.\r
+ * @return a Component\r
+ */\r
+\r
+ public Component getComponent() {\r
+ return widget;\r
+ }\r
+\r
+ /**\r
+ * Initialize the editor\r
+ * @param w the ResourceWrapper father of the attribute\r
+ * @param a the Attribute we are editing\r
+ * @param o the value of the above attribute\r
+ * @param p some Properties, used to fine-tune the editor\r
+ * @exception RemoteAccessException if a remote access error occurs.\r
+ */\r
+\r
+ public void initialize(RemoteResourceWrapper w, Attribute a, Object o,\r
+ Properties p)\r
+ throws RemoteAccessException\r
+ {\r
+ RemoteResource r = w.getResource();\r
+ if(o == null) {\r
+ String v = (String) r.getValue(a.getName());\r
+ if(v == null)\r
+ if(a.getDefault() != null)\r
+ v = a.getDefault().toString();\r
+ if ( v != null ) {\r
+ origs = v;\r
+ widget.setText(origs);\r
+ } \r
+ } else {\r
+ origs = o.toString();\r
+ }\r
+ widget.setText(origs);\r
+ }\r
+\r
+ public StringAttributeEditor() {\r
+ widget = new JTextField();\r
+ widget.setBorder(BorderFactory.createLoweredBevelBorder());\r
+ origs = "";\r
+ }\r
+}\r