001: // ResourcesHelper.java
002: // $Id: ResourcesHelper.java,v 1.12 2000/08/16 21:37:27 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.BorderLayout;
009: import java.awt.Button;
010: import java.awt.Component;
011: import java.awt.Container;
012: import java.awt.GridBagConstraints;
013: import java.awt.GridBagLayout;
014: import java.awt.GridLayout;
015: import java.awt.Label;
016: import java.awt.Panel;
017: import java.awt.ScrollPane;
018: import java.awt.TextComponent;
019: import java.awt.TextField;
020:
021: import java.awt.event.ActionEvent;
022: import java.awt.event.ActionListener;
023:
024: import java.util.Hashtable;
025: import java.util.Properties;
026: import java.util.StringTokenizer;
027:
028: import org.w3c.jigsaw.admin.RemoteAccessException;
029: import org.w3c.jigsaw.admin.RemoteResource;
030:
031: import org.w3c.jigadm.PropertyManager;
032: import org.w3c.jigadm.RemoteResourceWrapper;
033:
034: import org.w3c.tools.resources.Attribute;
035:
036: import org.w3c.tools.widgets.FakeComboBox;
037:
038: public class ResourcesHelper extends ResourceHelper {
039:
040: class AddResourceListener implements ActionListener {
041:
042: public void actionPerformed(ActionEvent ae) {
043: addResource();
044: }
045: }
046:
047: RemoteResourceWrapper rrw = null;
048: RemoteResource rr = null;
049: RemoteResource[] child = null;
050: private boolean initialized = false;
051: Properties prop;
052: FakeComboBox combo;
053: TextField tf;
054: Panel widget;
055: Panel addPanel = null;
056:
057: protected void addResource() {
058: if (tf.getText().length() > 0) {
059: RemoteResource nrr;
060: String selected = combo.getText();
061: if (selected != null)
062: if (selected.length() > 0) {
063: try {
064: nrr = rrw.getResource().registerResource(
065: tf.getText(), selected);
066: } catch (RemoteAccessException ex) {
067: // Add a fancy error
068: return;
069: }
070: RemoteResourceWrapper nrrw;
071: nrrw = new RemoteResourceWrapper(rrw, nrr, rrw
072: .getBrowser());
073: rrw.getBrowser()
074: .insertNode(rrw, nrrw, tf.getText());
075: }
076: }
077: }
078:
079: protected RemoteResourceWrapper getWrapper() {
080: return rrw;
081: }
082:
083: public Component getComponent() {
084: return widget;
085: }
086:
087: /**
088: * commit changes (if any)
089: * @exception RemoteAccessException if a remote access error occurs.
090: */
091: public void commitChanges() throws RemoteAccessException {
092: if (!initialized)
093: return;
094: return;
095: }
096:
097: public boolean hasChanged() {
098: return false;
099: }
100:
101: public void resetChanges() {
102: }
103:
104: public void clearChanged() {
105: }
106:
107: public final String getTitle() {
108: return "Resources";
109: }
110:
111: public ResourcesHelper() {
112: widget = new Panel();
113: }
114:
115: protected void initAddPanel(Properties config) {
116: if (addPanel == null) {
117: Panel tfp;
118: addPanel = new Panel(new BorderLayout());
119:
120: String af = (String) config
121: .get("org.w3c.jigadm.editors.resource.resources");
122: if (af == null)
123: return;
124: StringTokenizer st = new StringTokenizer(af, "|");
125: ScrollPane fsp = new ScrollPane();
126: GridBagLayout fgbl = new GridBagLayout();
127: GridBagConstraints fgbc = new GridBagConstraints();
128: Panel fspp = new Panel(fgbl);
129: fsp.add(fspp);
130: PropertyManager pm = PropertyManager.getPropertyManager();
131: String downPath = pm.getIconLocation("down");
132: String leftPath = pm.getIconLocation("left");
133: combo = new FakeComboBox(35, 7, true, downPath, leftPath);
134: while (st.hasMoreTokens())
135: combo.add(st.nextToken().trim());
136: fspp.add(combo);
137: addPanel.add("Center", fsp);
138: Button newb = new Button("Add Resource");
139: newb.addActionListener(new AddResourceListener());
140: addPanel.add("South", newb);
141: tfp = new Panel(new GridLayout(1, 2));
142: tf = new TextField();
143: tfp.add(new Label("identifier"));
144: tfp.add(tf);
145: addPanel.add("North", tfp);
146: }
147: widget.add("Center", addPanel);
148:
149: }
150:
151: /**
152: * initialize this helper
153: * @param rrw The RemoteResourceWrapper
154: * @param pr The properties
155: * @exception RemoteAccessException if a remote access error occurs.
156: */
157: public void initialize(RemoteResourceWrapper rrw, Properties pr)
158: throws RemoteAccessException {
159: if (!initialized)
160: initialized = true;
161: else
162: return;
163:
164: this .rrw = rrw;
165: rr = rrw.getResource();
166: widget.setLayout(new BorderLayout());
167: initAddPanel(pr);
168: }
169: }
|