001: // ClassAttributeEditor.java
002: // $Id: ClassAttributeEditor.java,v 1.5 2000/08/16 21:37:26 ylafon Exp $
003: // (c) COPYRIGHT MIT and INRIA, 1997.
004: // Please first read the full copyright statement in file COPYRIGHT.html
005:
006: package org.w3c.jigadm.editors;
007:
008: import java.awt.Component;
009: import java.awt.TextComponent;
010: import java.awt.TextField;
011:
012: import java.util.Properties;
013:
014: import org.w3c.tools.resources.Attribute;
015:
016: import org.w3c.jigsaw.admin.RemoteAccessException;
017: import org.w3c.jigsaw.admin.RemoteResource;
018:
019: import org.w3c.jigadm.RemoteResourceWrapper;
020:
021: import org.w3c.tools.widgets.MessagePopup;
022:
023: /**
024: * ClassAttributeEditor :
025: * @author Benoit Mahe <bmahe@sophia.inria.fr>
026: */
027:
028: public class ClassAttributeEditor extends AttributeEditor {
029:
030: private Class origs;
031: TextField widget;
032:
033: /**
034: * Tells if the edited value has changed
035: * @return true if the value changed.
036: */
037:
038: public boolean hasChanged() {
039: return !((origs.getName()).equals(widget.getText()));
040: }
041:
042: /**
043: * set the current value to be the original value, ie: changed
044: * must return <strong>false</strong> after a reset.
045: */
046:
047: public void clearChanged() {
048: origs = getClassAttribute();
049: }
050:
051: /**
052: * reset the changes (if any)
053: */
054:
055: public void resetChanges() {
056: setClassAttribute(origs);
057: }
058:
059: protected void setClassAttribute(Class c) {
060: if (c != null)
061: widget.setText(c.getName());
062: else
063: widget.setText("");
064: }
065:
066: protected Class getClassAttribute() {
067: String classname = widget.getText();
068: if (classname != null)
069: if (classname.length() > 0) {
070: try {
071: Class c = Class.forName(classname);
072: return c;
073: } catch (ClassNotFoundException ex) {
074: (new MessagePopup("Error", "Class not found : "
075: + classname)).show();
076: return null;
077: }
078: }
079: return null;
080: }
081:
082: /**
083: * Get the current value of the edited value
084: * @return an object or <strong>null</strong> if the object was not
085: * initialized
086: */
087:
088: public Object getValue() {
089: return getClassAttribute();
090: }
091:
092: /**
093: * Set the value of the edited value
094: * @param o the new value.
095: */
096:
097: public void setValue(Object o) {
098: setClassAttribute((Class) o);
099: }
100:
101: /**
102: * get the Component created by the editor.
103: * @return a Component
104: */
105:
106: public Component getComponent() {
107: return widget;
108: }
109:
110: /**
111: * Initialize the editor
112: * @param w the ResourceWrapper father of the attribute
113: * @param a the Attribute we are editing
114: * @param o the value of the above attribute
115: * @param p some Properties, used to fine-tune the editor
116: * @exception RemoteAccessException if a remote access error occurs.
117: */
118:
119: public void initialize(RemoteResourceWrapper w, Attribute a,
120: Object o, Properties p) throws RemoteAccessException {
121: RemoteResource r = w.getResource();
122: if (o == null) {
123: Class v = null;
124: // FIXME
125: v = (Class) r.getValue(a.getName());
126:
127: if (v == null)
128: if (a.getDefault() != null)
129: v = (Class) a.getDefault();
130: if (v != null) {
131: origs = v;
132: setClassAttribute(origs);
133: }
134: } else {
135: origs = (Class) o;
136: }
137: setClassAttribute(origs);
138: }
139:
140: public ClassAttributeEditor() {
141: widget = new TextField();
142: }
143:
144: }
|