001: // FramesHelper.java
002: // $Id: FramesHelper.java,v 1.7 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.Panel;
016: import java.awt.ScrollPane;
017: import java.awt.Scrollbar;
018:
019: import java.awt.event.ActionEvent;
020: import java.awt.event.ActionListener;
021:
022: import java.util.Properties;
023: import java.util.StringTokenizer;
024:
025: import org.w3c.jigadm.PropertyManager;
026: import org.w3c.jigadm.RemoteResourceWrapper;
027:
028: import org.w3c.jigsaw.admin.RemoteAccessException;
029: import org.w3c.jigsaw.admin.RemoteResource;
030:
031: import org.w3c.jigadm.events.ResourceChangeEvent;
032:
033: import org.w3c.tools.widgets.BorderPanel;
034: import org.w3c.tools.widgets.FakeComboBox;
035: import org.w3c.tools.widgets.TreeBrowser;
036:
037: import org.w3c.tools.resources.Attribute;
038:
039: public class FramesHelper extends ResourceHelper {
040:
041: static private String FAL_ADD = "add";
042: static private String FAL_DELETE = "delete";
043: static private String FAL_EDIT = "edit";
044: static private String FAL_BACK = "back";
045:
046: class FramesActionListener implements ActionListener {
047:
048: class Performer extends Thread {
049: String action = null;
050:
051: public void run() {
052: if (action.equals(FAL_ADD)) {
053: addFrame();
054: } else if (action.equals(FAL_DELETE)) {
055: deleteCurrentFrame();
056: } else if (action.equals(FAL_BACK)) {
057: initAddPanel(prop);
058: }
059: }
060:
061: Performer(String action) {
062: this .action = action;
063: }
064: }
065:
066: public void actionPerformed(ActionEvent ae) {
067: String command = ae.getActionCommand();
068: (new Performer(command)).start();
069: }
070:
071: }
072:
073: private FramesActionListener fal;
074: RemoteResourceWrapper rrw = null;
075: RemoteResourceWrapper root_rrw = null;
076: AttributesHelper frameattr = null;
077: private boolean initialized = false;
078: Properties prop;
079: Panel widget;
080: Panel addFrame;
081: FakeComboBox combo;
082: Component centerComp;
083: FrameBrowser fb = null;
084:
085: protected void addFrame() {
086: String selected = combo.getText();
087: if (selected != null)
088: if (selected.length() > 0) {
089: boolean authorized = false;
090: boolean ok = true;
091: RemoteResource newFrame = null;
092: while (!authorized) {
093: try {
094: authorized = true;
095: newFrame = rrw.getResource().registerFrame(
096: null, selected);
097: } catch (RemoteAccessException ex) {
098: if (ex.getMessage().equals("Unauthorized")) {
099: authorized = false;
100: } else {
101: errorPopup("RemoteAccessException", ex);
102: ok = false;
103: }
104: } finally {
105: if (!authorized) {
106: rrw.getBrowser().popupDialog("admin");
107: }
108: }
109: }
110: if (ok) {
111: RemoteResourceWrapper nrrw = new RemoteResourceWrapper(
112: rrw, newFrame, rrw.getBrowser());
113: processEvent(new ResourceChangeEvent(rrw, "added",
114: null, nrrw));
115: //FIXME useful??
116: widget.validate();
117: widget.setVisible(true);
118: }
119: }
120: }
121:
122: protected void deleteCurrentFrame() {
123: if (rrw == root_rrw)
124: return;
125:
126: boolean authorized = false;
127: boolean ok = true;
128: while (!authorized) {
129: try {
130: authorized = true;
131: rrw.getFatherResource().unregisterFrame(
132: rrw.getResource());
133: // rrw = root_rrw; //FIXME
134: } catch (RemoteAccessException ex) {
135: if (ex.getMessage().equals("Unauthorized")) {
136: authorized = false;
137: } else {
138: errorPopup("RemoteAccessException", ex);
139: ok = false;
140: }
141: } finally {
142: if (!authorized) {
143: rrw.getBrowser().popupDialog("admin");
144: }
145: }
146: }
147: if (ok) {
148: initAddPanel(prop);
149: processEvent(new ResourceChangeEvent(
150: rrw.getFatherWrapper(), "deleted", rrw, null));
151: rrw = root_rrw;
152: }
153: }
154:
155: protected void editFrame(RemoteResourceWrapper framew) {
156: rrw = framew; //SURE FIXME ??
157: boolean authorized;
158: frameattr = new AttributesHelper();
159: frameattr.addResourceListener(new FramesHelperListener(fb));
160: widget.remove(centerComp);
161: authorized = false;
162: while (!authorized) {
163: try {
164: authorized = true;
165: frameattr.initialize(framew, null);
166: } catch (RemoteAccessException ex) {
167: if (ex.getMessage().equals("Unauthorized")) {
168: authorized = false;
169: } else {
170: errorPopup("RemoteAccessException", ex);
171: // do nothing
172: }
173: } finally {
174: if (!authorized) {
175: rrw.getBrowser().popupDialog("admin");
176: }
177: }
178: }
179: Panel interp = new Panel(new BorderLayout());
180: interp.add("Center", frameattr.getComponent());
181: centerComp = interp;
182:
183: Panel pbutton = new Panel(new GridLayout(1, 2, 2, 2));
184: Button back = new Button("Back to Add Frame menu");
185: back.setActionCommand(FAL_BACK);
186: back.addActionListener(fal);
187:
188: pbutton.add(back);
189:
190: if (rrw != root_rrw) {
191: Button del = new Button("Delete selected Frame");
192: del.setActionCommand(FAL_DELETE);
193: del.addActionListener(fal);
194:
195: pbutton.add(del);
196: }
197:
198: interp.add("South", pbutton);
199: widget.add("Center", centerComp);
200: widget.validate();
201: widget.setVisible(true);
202: }
203:
204: public void removeAll() {
205: widget.removeAll();
206: }
207:
208: public void removeCenterComp() {
209: widget.remove(centerComp);
210: }
211:
212: public Component getComponent() {
213: return widget;
214: }
215:
216: /**
217: * Commit changes (if any).
218: * @exception RemoteAccessException if a remote access error occurs.
219: */
220: public void commitChanges() throws RemoteAccessException {
221: if (!initialized)
222: return;
223: return;
224: }
225:
226: public boolean hasChanged() {
227: return false;
228: }
229:
230: public void resetChanges() {
231: }
232:
233: public void clearChanged() {
234: }
235:
236: public final String getTitle() {
237: return "Frames";
238: }
239:
240: public FramesHelper() {
241: widget = new Panel();
242: fal = new FramesActionListener();
243: }
244:
245: protected void initFrames() throws RemoteAccessException {
246: Panel fbrowser = new Panel(new BorderLayout());
247:
248: Scrollbar sv = new Scrollbar(Scrollbar.VERTICAL);
249: Scrollbar sh = new Scrollbar(Scrollbar.HORIZONTAL);
250: FrameTreeListener ftl = new FrameTreeListener(this );
251: fb = new FrameBrowser(ftl, root_rrw);
252: fb.setVerticalScrollbar(sv);
253: fb.setHorizontalScrollbar(sh);
254: fbrowser.add("Center", fb);
255: fbrowser.add("East", sv);
256: fbrowser.add("South", sh);
257:
258: BorderPanel border = new BorderPanel(BorderPanel.LOWERED);
259: border.setLayout(new BorderLayout());
260: border.add(fbrowser);
261:
262: widget.add("South", border);
263:
264: }
265:
266: protected void initAddPanel(Properties config) {
267: if (addFrame == null) {
268: addFrame = new Panel(new BorderLayout());
269: String af = config
270: .getProperty("org.w3c.jigadm.editors.frames");
271: StringTokenizer st = new StringTokenizer(af, "|");
272: ScrollPane fsp = new ScrollPane();
273: GridBagLayout fgbl = new GridBagLayout();
274: GridBagConstraints fgbc = new GridBagConstraints();
275: Panel fspp = new Panel(fgbl);
276: fsp.add(fspp);
277: PropertyManager pm = PropertyManager.getPropertyManager();
278: String downPath = pm.getIconLocation("down");
279: String leftPath = pm.getIconLocation("left");
280: combo = new FakeComboBox(35, 7, true, downPath, leftPath);
281: while (st.hasMoreTokens())
282: combo.add(st.nextToken().trim());
283: fspp.add(combo);
284: addFrame.add("Center", fsp); //Center
285: // Add listener to switch between frame chooser and configurer
286: Button newb = new Button("Add Frame");
287: newb.setActionCommand(FAL_ADD);
288: newb.addActionListener(fal);
289: addFrame.add("South", newb);
290: } else
291: widget.remove(centerComp);
292: widget.add("Center", addFrame);
293: centerComp = addFrame;
294: }
295:
296: /**
297: * initialize this helper
298: * @param rrw The RemoteResourceWrapper
299: * @param pr The properties
300: * @exception RemoteAccessException if a remote access error occurs.
301: */
302: public void initialize(RemoteResourceWrapper rrw, Properties pr)
303: throws RemoteAccessException {
304: if (!initialized)
305: initialized = true;
306: else {
307: widget.removeAll();
308: }
309:
310: RemoteResource rr;
311: this .prop = pr;
312: this .rrw = rrw;
313: this .root_rrw = rrw;
314: rr = rrw.getResource();
315:
316: if (rr.isFramed()) {
317: widget.setLayout(new BorderLayout());
318: // Create the Add Frame panel
319: initAddPanel(prop);
320: // add the frames
321: initFrames();
322: }
323: }
324: }
|