--- /dev/null
+// ClassAttributeEditor.java\r
+// $Id: ClassAttributeEditor.java,v 1.2 2010/06/15 17:52:56 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
+import org.w3c.tools.widgets.MessagePopup;\r
+\r
+/**\r
+ * ClassAttributeEditor :\r
+ * @author Benoit Mahe <bmahe@sophia.inria.fr>\r
+ */\r
+\r
+public class ClassAttributeEditor extends AttributeEditor {\r
+\r
+ private Class 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.getName()).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 = getClassAttribute();\r
+ }\r
+\r
+ /**\r
+ * reset the changes (if any)\r
+ */\r
+\r
+ public void resetChanges() {\r
+ setClassAttribute(origs);\r
+ }\r
+\r
+ protected void setClassAttribute(Class c) {\r
+ if (c != null)\r
+ widget.setText(c.getName());\r
+ else \r
+ widget.setText("");\r
+ }\r
+\r
+ protected Class getClassAttribute() {\r
+ String classname = widget.getText();\r
+ if (classname != null)\r
+ if (classname.length() > 0) {\r
+ try {\r
+ Class c = Class.forName(classname);\r
+ //Added by Jeff Huang\r
+ //TODO: FIXIT\r
+ return c;\r
+ } catch (ClassNotFoundException ex) {\r
+ (new MessagePopup("Error","Class not found : "+\r
+ classname)).show();\r
+ return null;\r
+ }\r
+ }\r
+ return null;\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 getClassAttribute();\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
+ setClassAttribute((Class)o);\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,\r
+ Attribute a,\r
+ Object o,\r
+ Properties p)\r
+ throws RemoteAccessException\r
+ {\r
+ RemoteResource r = w.getResource();\r
+ if(o == null) {\r
+ Class v = null;\r
+ // FIXME\r
+ v = (Class) r.getValue(a.getName());\r
+ \r
+ if(v == null)\r
+ if(a.getDefault() != null)\r
+ v = (Class)a.getDefault();\r
+ if ( v != null ) {\r
+ origs = v;\r
+ setClassAttribute(origs);\r
+ } \r
+ } else {\r
+ origs = (Class)o;\r
+ }\r
+ setClassAttribute(origs);\r
+ }\r
+\r
+ public ClassAttributeEditor() {\r
+ widget = new TextField();\r
+ }\r
+\r
+}\r