Adding JMCR-Stable version
[Benchmarks_CSolver.git] / JMCR-Stable / real-world application / jigsaw / src / org / w3c / jigadm / editors / FileEditor.java
diff --git a/JMCR-Stable/real-world application/jigsaw/src/org/w3c/jigadm/editors/FileEditor.java b/JMCR-Stable/real-world application/jigsaw/src/org/w3c/jigadm/editors/FileEditor.java
new file mode 100644 (file)
index 0000000..348d439
--- /dev/null
@@ -0,0 +1,116 @@
+// FileEditor.java\r
+// $Id: FileEditor.java,v 1.1 2010/06/15 12:22: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.jigadm.editors ;\r
+\r
+import java.awt.Component;\r
+import java.awt.TextComponent;\r
+import java.awt.TextField;\r
+\r
+import java.util.Properties;\r
+\r
+import org.w3c.tools.resources.Attribute;\r
+\r
+import org.w3c.jigsaw.admin.RemoteAccessException;\r
+import org.w3c.jigsaw.admin.RemoteResource;\r
+\r
+import org.w3c.jigadm.RemoteResourceWrapper;\r
+\r
+public class FileEditor extends AttributeEditor {\r
+\r
+    private String origs;\r
+    TextField 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
+       return widget.getText();\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 = null;\r
+           // FIXME\r
+           v = (String) r.getValue(a.getName());\r
+          \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 FileEditor() {\r
+       widget = new TextField();\r
+       origs = "";\r
+    }\r
+}\r