001: // StringAttributeEditor.java
002: // $Id: StringAttributeEditor.java,v 1.6 2000/08/16 21:37:28 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: public class StringAttributeEditor extends AttributeEditor {
022:
023: private String origs;
024: TextField widget;
025:
026: /**
027: * Tells if the edited value has changed
028: * @return true if the value changed.
029: */
030:
031: public boolean hasChanged() {
032: return !origs.equals(widget.getText());
033: }
034:
035: /**
036: * set the current value to be the original value, ie: changed
037: * must return <strong>false</strong> after a reset.
038: */
039:
040: public void clearChanged() {
041: origs = widget.getText();
042: }
043:
044: /**
045: * reset the changes (if any)
046: */
047:
048: public void resetChanges() {
049: widget.setText(origs);
050: }
051:
052: /**
053: * Get the current value of the edited value
054: * @return an object or <strong>null</strong> if the object was not
055: * initialized
056: */
057:
058: public Object getValue() {
059: return widget.getText();
060: }
061:
062: /**
063: * Set the value of the edited value
064: * @param o the new value.
065: */
066:
067: public void setValue(Object o) {
068: widget.setText(o.toString());
069: }
070:
071: /**
072: * get the Component created by the editor.
073: * @return a Component
074: */
075:
076: public Component getComponent() {
077: return widget;
078: }
079:
080: /**
081: * Initialize the editor
082: * @param w the ResourceWrapper father of the attribute
083: * @param a the Attribute we are editing
084: * @param o the value of the above attribute
085: * @param p some Properties, used to fine-tune the editor
086: * @exception RemoteAccessException if a remote access error occurs.
087: */
088:
089: public void initialize(RemoteResourceWrapper w, Attribute a,
090: Object o, Properties p) throws RemoteAccessException {
091: RemoteResource r = w.getResource();
092: if (o == null) {
093: String v = null;
094: // FIXME
095: v = (String) r.getValue(a.getName());
096:
097: if (v == null)
098: if (a.getDefault() != null)
099: v = a.getDefault().toString();
100: if (v != null) {
101: origs = v;
102: widget.setText(origs);
103: }
104: } else {
105: origs = o.toString();
106: }
107: widget.setText(origs);
108: }
109:
110: public StringAttributeEditor() {
111: widget = new TextField();
112: origs = "";
113: }
114: }
|