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