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