001: /*
002: * CONFIDENTIAL AND PROPRIETARY SOURCE CODE OF
003: * NETSCAPE COMMUNICATIONS CORPORATION
004: *
005: * Copyright (c) 1996 Netscape Communications Corporation.
006: * All Rights Reserved.
007: * Use of this Source Code is subject to the terms of the applicable
008: * license agreement from Netscape Communications Corporation.
009: */
010:
011: package applications;
012:
013: import components.ClassificationWindow;
014: import components.SchemaTreeWindow;
015: import components.RDEditorWindow;
016: import components.TaxonomyTreeView;
017: import components.TaxonomyTreeWindow;
018: import graphical.TreeViewGroup;
019: import graphical.IconInternalWindow;
020: import graphical.WindowTiler;
021: import soif.CSID;
022: import soif.Schema;
023: import soif.SchemaGetter;
024: import soif.Taxonomy;
025: import soif.TaxonomyGetter;
026: import util.BTreeNode;
027: import util.ReportError;
028:
029: import netscape.application.Alert;
030: import netscape.application.Application;
031: import netscape.application.Bitmap;
032: import netscape.application.ExternalWindow;
033: import netscape.application.Menu;
034: import netscape.application.MenuItem;
035: import netscape.application.MenuView;
036: import netscape.application.Target;
037: import netscape.application.View;
038:
039: import netscape.util.Enumeration;
040: import netscape.util.Vector;
041:
042: public class Desktop extends Application implements Target {
043: private WindowTiler windowTiler;
044:
045: // SGP: public for sleazy manipulation by TTVs
046: public Schema schema;
047: public Taxonomy taxonomy;
048:
049: private SchemaTreeWindow schemaTreeWindow = null;
050: private ClassificationWindow classificationIW = null;
051:
052: private TreeViewGroup treeViewGroup;
053: private TaxonomyTreeView treeView = null;
054: private String testTaxonomy;
055: private String testSchema;
056: private String testClassRules;
057: private static ExternalWindow externalWindow;
058: private String CGITaxPost;
059:
060: private boolean standAlone = false;
061: private Bitmap bm;
062:
063: private SchemaGetter sg;
064: private TaxonomyGetter tg;
065:
066: private String CGILocation;
067: private String CGIDBLocation;
068: private String CGITarget;
069: private String CGISchemaRead;
070: private String CGITaxRead;
071: private String CGITaxWrite;
072: private String CGIRulesRead;
073: private String CGIRulesWrite;
074: private CSID csid;
075: private CSID dbcsid;
076:
077: public void init() {
078: super .init();
079:
080: Header.showVersion(Messages.TITLE_DESKTOP, true, true);
081:
082: boolean valid = true;
083:
084: bm = new Bitmap(components.Header.minCompass,
085: components.Header.minCompassSize.width,
086: components.Header.minCompassSize.height);
087:
088: externalWindow = new ExternalWindow();
089: setMainRootView(externalWindow.rootView());
090: mainRootView().setColor(graphical.Header.DESKTOPCOLOR);
091: externalWindow.setTitle(Messages.TITLE_DESKTOP);
092:
093: // Create window tiler
094: windowTiler = new WindowTiler();
095:
096: CGILocation = Header.parameterMacro(this , "CGILocation");
097: CGIDBLocation = Header.parameterMacro(this , "CGIDBLocation");
098: CGITarget = Header.parameterMacro(this , "CGITarget");
099: CGISchemaRead = Header.parameterMacro(this , "CGISchemaRead");
100: CGITaxRead = Header.parameterMacro(this , "CGITaxRead");
101: CGITaxWrite = Header.parameterMacro(this , "CGITaxWrite");
102: CGIRulesRead = Header.parameterMacro(this , "CGIRulesRead");
103: CGIRulesWrite = Header.parameterMacro(this , "CGIRulesWrite");
104:
105: csid = Header.parameterCSIDMacro(this );
106: dbcsid = Header.parameterDBCSIDMacro(this );
107:
108: if ((CGILocation == null) || (CGIDBLocation == null)
109: || (CGITarget == null) || (CGITaxRead == null)
110: || (CGITaxWrite == null) || (csid.isValid() == false)
111: || (dbcsid.isValid() == false)) {
112: valid = false;
113: }
114:
115: CGITaxPost = CGILocation + CGITarget + CGITaxWrite;
116:
117: testSchema = parameterNamed("testSchema");
118: testTaxonomy = parameterNamed("testTaxonomy");
119: testClassRules = parameterNamed("testClassRules");
120:
121: if ((testTaxonomy != null) && (testSchema != null)
122: && (testClassRules != null)) {
123: valid = true;
124: }
125:
126: if (standAlone) {
127: testSchema = "testSchema";
128: testTaxonomy = "testTaxonomy";
129: testClassRules = "testClassRules";
130: valid = true;
131: }
132:
133: if (valid) {
134: Menu menu = new Menu();
135: MenuItem fileMenuItem = menu
136: .addItemWithSubmenu(Messages.MENU_FILE);
137: fileMenuItem.submenu().addItem(Messages.CMD_NEWTAXWIND,
138: Messages.CMD_NEWTAXWIND, this );
139: fileMenuItem.submenu().addItem(Messages.CMD_NEWSCHWIND,
140: Messages.CMD_NEWSCHWIND, this );
141: fileMenuItem.submenu().addItem(Messages.CMD_NEWCRWIND,
142: Messages.CMD_NEWCRWIND, this );
143: fileMenuItem.submenu().addItem(Messages.CMD_NEWRDEDIT,
144: Messages.CMD_NEWRDEDIT, this );
145: fileMenuItem.submenu().addSeparator();
146: fileMenuItem.submenu().addItem(Messages.CMD_CLOSE,
147: Messages.CMD_CLOSE, this );
148: MenuItem windMenuItem = menu
149: .addItemWithSubmenu(Messages.MENU_WINDOW);
150: windMenuItem.setEnabled(false);
151: MenuView menuView = new MenuView(menu);
152: menuView.sizeToMinSize();
153: externalWindow.setMenuView(menuView);
154:
155: TaxonomyTreeWindow taxonomyTreeWindow;
156:
157: treeViewGroup = new TreeViewGroup();
158:
159: if (testSchema == null) {
160: sg = new SchemaGetter(CGILocation, CGITarget
161: + CGISchemaRead, csid);
162: sg.start();
163: schema = null;
164: } else {
165: ReportError.reportError(ReportError.WARNING,
166: ReportError.ADMIN, "Classification", "init",
167: Messages.USETESTSCHEMA);
168: sg = null;
169: schema = Instrument.testSchema();
170: }
171:
172: if (testTaxonomy == null) {
173: tg = new TaxonomyGetter(CGILocation, CGITarget
174: + CGITaxRead, csid);
175: tg.start();
176: taxonomy = null;
177: } else {
178: ReportError.reportError(ReportError.WARNING,
179: ReportError.ADMIN, "Desktop", "init",
180: Messages.USETESTTAXONOMY);
181:
182: tg = null;
183: taxonomy = Instrument.testTaxonomy();
184: }
185:
186: Header.EWSizer(externalWindow);
187: externalWindow.show();
188: }
189:
190: Header.showVersion(Messages.TITLE_DESKTOP, false, true);
191: }
192:
193: public void performCommand(String command, Object arg) {
194:
195: if (Messages.CMD_TAXSAVE.equals(command)) {
196: saveCommand();
197: } else if (Messages.CMD_NEWTAXWIND.equals(command)) {
198: if ((taxonomy == null) && (tg != null)) {
199: tg.waitFor();
200: taxonomy = tg.getTaxonomy();
201: }
202:
203: TaxonomyTreeWindow taxonomyTreeWindow = new TaxonomyTreeWindow(
204: graphical.Header.WINDOWHGAP,
205: externalWindow.menuView().height()
206: + graphical.Header.WINDOWVGAP,
207: (graphical.Header.IWINDWIDTH / 2), // Half normal width from desktop.
208: graphical.Header.IWINDHEIGHT, taxonomy, true, true,
209: this );
210:
211: taxonomyTreeWindow
212: .setDragSourcePolicy(graphical.DragPolicy.DRAGFROMCOPY);
213: taxonomyTreeWindow
214: .setDragDestinationPolicy(graphical.DragPolicy.DRAGTOACCEPT);
215: taxonomyTreeWindow.setDragDestinationTarget(this );
216: taxonomyTreeWindow.taxonomyTreeView.setLauncher(this ,
217: Messages.CMD_NEWTAXWIND);
218: taxonomyTreeWindow.taxonomyTreeView
219: .setTreeViewGroup(treeViewGroup);
220: taxonomyTreeWindow.setMinimize(bm,
221: components.Messages.LBL_TAXONOMY, externalWindow,
222: windowTiler);
223:
224: // SGP: sleaze
225: taxonomyTreeWindow.taxonomyTreeView.dt = this ;
226:
227: if (arg instanceof BTreeNode) {
228: taxonomyTreeWindow.taxonomyTreeView
229: .setBinaryTree((BTreeNode) arg);
230: }
231:
232: taxonomyTreeWindow.setDesktopBroadcastTarget(this );
233: taxonomyTreeWindow
234: .setDesktopBroadcastCommand(Messages.CMD_DESKTOP_BROADCAST);
235: windowTiler.addWindow(taxonomyTreeWindow); // Tile window (set position)
236: taxonomyTreeWindow.show();
237: } else if (Messages.CMD_NEWSCHWIND.equals(command)) {
238: if ((schema == null) && (sg != null)) {
239: sg.waitFor();
240: schema = sg.getSchema();
241: }
242:
243: // Only allow a single Schema Window
244: if (schemaTreeWindow == null) {
245: schemaTreeWindow = new SchemaTreeWindow(
246: graphical.Header.WINDOWHGAP, externalWindow
247: .menuView().height()
248: + graphical.Header.WINDOWVGAP,
249: graphical.Header.IWINDWIDTH,
250: graphical.Header.IWINDHEIGHT, schema, false,
251: false, false);
252: schemaTreeWindow.setRootView(externalWindow.rootView()); // SGP ??
253: schemaTreeWindow.setMinimize(bm,
254: components.Messages.LBL_SCHEMA, externalWindow,
255: windowTiler);
256: schemaTreeWindow
257: .setDragSourcePolicy(graphical.DragPolicy.DRAGFROMCOPY);
258: windowTiler.addWindow(schemaTreeWindow); // Tile window (set position)
259: }
260:
261: schemaTreeWindow.setDesktopBroadcastTarget(this );
262: schemaTreeWindow
263: .setDesktopBroadcastCommand(Messages.CMD_DESKTOP_BROADCAST);
264: schemaTreeWindow.hideIcon(); // Hide icon in case minimized
265: schemaTreeWindow.show();
266: } else if (Messages.CMD_NEWCRWIND.equals(command)) {
267: if ((schema == null) && (sg != null)) {
268: sg.waitFor();
269: schema = sg.getSchema();
270: }
271:
272: if ((taxonomy == null) && (tg != null)) {
273: tg.waitFor();
274: taxonomy = tg.getTaxonomy();
275: }
276:
277: // Only allow a single Classification Rules Window
278: if (classificationIW == null) {
279: if (testClassRules == null) {
280: classificationIW = new ClassificationWindow(
281: graphical.Header.WINDOWHGAP, externalWindow
282: .menuView().height()
283: + graphical.Header.WINDOWVGAP,
284: graphical.Header.IWINDWIDTH,
285: graphical.Header.IWINDHEIGHT, schema,
286: taxonomy, CGILocation, CGITarget,
287: CGIRulesRead, CGIRulesWrite, true);
288: } else {
289: ReportError.reportError(ReportError.WARNING,
290: ReportError.ADMIN, "Classification",
291: "init", Messages.USETESTCLASSRULES);
292:
293: classificationIW = new ClassificationWindow(
294: graphical.Header.WINDOWHGAP, externalWindow
295: .menuView().height()
296: + graphical.Header.WINDOWVGAP,
297: graphical.Header.IWINDWIDTH,
298: graphical.Header.IWINDHEIGHT, schema,
299: taxonomy, Instrument.testClassRules(), true);
300: classificationIW.testClassRules = testClassRules;
301: }
302: classificationIW.classificationView.notifyOfChange = classificationIW;
303: classificationIW.setMinimize(bm,
304: components.Messages.LBL_CLASSRULES,
305: externalWindow, windowTiler);
306: classificationIW.setRootView(externalWindow.rootView());
307: windowTiler.addWindow(classificationIW); // Tile window (set position)
308: }
309:
310: classificationIW.setDesktopBroadcastTarget(this );
311: classificationIW
312: .setDesktopBroadcastCommand(Messages.CMD_DESKTOP_BROADCAST);
313: classificationIW.hideIcon(); // Hide icon in case minimized
314: classificationIW.classificationView
315: .updateTaxonomyComboBox(taxonomy);
316: classificationIW.show();
317: } else if (Messages.CMD_NEWRDEDIT.equals(command)) {
318: if ((schema == null) && (sg != null)) {
319: sg.waitFor();
320: schema = sg.getSchema();
321: }
322:
323: if ((taxonomy == null) && (tg != null)) {
324: tg.waitFor();
325: taxonomy = tg.getTaxonomy();
326: }
327:
328: RDEditorWindow editorWindow = new RDEditorWindow(
329: externalWindow, windowTiler,
330: graphical.Header.WINDOWHGAP, externalWindow
331: .menuView().height()
332: + graphical.Header.WINDOWVGAP,
333: graphical.Header.IWINDWIDTH,
334: graphical.Header.IWINDHEIGHT,
335: (testTaxonomy != null), false, schema, taxonomy,
336: CGIDBLocation, CGILocation, dbcsid, csid);
337:
338: editorWindow.setMinimize(bm,
339: components.Messages.LBL_RDEDIT, externalWindow,
340: windowTiler);
341: editorWindow.setRootView(externalWindow.rootView());
342:
343: editorWindow.setDesktopBroadcastTarget(this );
344: editorWindow
345: .setDesktopBroadcastCommand(Messages.CMD_DESKTOP_BROADCAST);
346: windowTiler.addWindow(editorWindow); // Tile window (set position)
347: editorWindow.show();
348: } else if (Messages.CMD_CLOSE.equals(command)) {
349: Vector v = externalWindow.rootView().internalWindows();
350:
351: /* I must clone the vector otherwise when I show the window, it changes
352: * the positions of the windows in the vector. After I show the window it
353: * always ends up in the first location. So I end up processing the same
354: * window over and over.
355: */
356: v = ((Vector) v.clone());
357:
358: for (int i = 0; i < v.count(); i++) {
359: IconInternalWindow window = ((IconInternalWindow) v
360: .elementAt(i));
361: ((IconInternalWindow) window).show();
362:
363: if (window instanceof RDEditorWindow) {
364: if (((RDEditorWindow) window).closeRequest() == false) {
365: return;
366: }
367:
368: window.hide();
369: }
370:
371: if (window instanceof ClassificationWindow) {
372: if (((ClassificationWindow) window).closeRequest() == false) {
373: return;
374: }
375:
376: window.hide();
377: }
378:
379: if (window instanceof SchemaTreeWindow) {
380: if (((SchemaTreeWindow) window).closeRequest() == false) {
381: return;
382: }
383:
384: window.hide();
385: }
386:
387: if (window instanceof TaxonomyTreeWindow) {
388: if (((TaxonomyTreeWindow) window).closeRequest() == false) {
389: return;
390: }
391:
392: window.hide();
393: }
394: }
395:
396: externalWindow.dispose();
397: } else if (Messages.CMD_DESKTOP_BROADCAST.equals(command)) {
398: // A broadcast message has been received, it must be sent to all
399: // application windows. If they are interested in it they must
400: // include code in performCommmand() to process it. If not it
401: // ends up in IconInternalWindow.performCommand where it is
402: // discarded.
403: // System.out.println("Broadcasting Tax Chg Recd======\n" + "\n=======");
404:
405: Enumeration e = externalWindow.rootView().internalWindows()
406: .elements();
407:
408: while (e.hasMoreElements()) {
409: IconInternalWindow window = ((IconInternalWindow) e
410: .nextElement());
411: window.performCommand(command, arg);
412: }
413: }
414: }
415:
416: public boolean saveCommand() {
417: // SGP: the loop may not be needed anymore
418: Enumeration e = externalWindow.rootView().internalWindows()
419: .elements();
420: while (e.hasMoreElements()) {
421: Object o = e.nextElement();
422: if (o instanceof TaxonomyTreeWindow) {
423: treeView = ((TaxonomyTreeWindow) o).taxonomyTreeView;
424: treeView.clickCommand();
425: }
426: }
427: if ("".equals(taxonomy.getTaxonomyId())) {
428: Alert.runAlertExternally(Alert.notificationImage(),
429: Messages.INVALIDTAXID, "", Messages.CMD_OK, null,
430: null);
431: return false;
432: }
433:
434: int answer = Alert.runAlertExternally(
435: Alert.notificationImage(), Messages.REINDEXWARN, "",
436: Messages.CMD_SAVE, Messages.CMD_CANCEL, null);
437: if (answer == components.Header.SAVE_SAVE) { // Save
438: externalWindow.rootView().setOverrideCursor(
439: View.WAIT_CURSOR);
440:
441: if (testTaxonomy == null) {
442: communications.PostConnection.doWrite(CGITaxPost,
443: taxonomy.toSOIF());
444: } else {
445: System.out.println(taxonomy.toSOIF());
446: }
447: treeViewGroup.sendAction(treeView,
448: TreeViewGroup.CLEARCHANGE, null);
449:
450: externalWindow.rootView().removeOverrideCursor();
451:
452: Alert.runAlertExternally(Alert.notificationImage(),
453: Messages.SAVED_TAXONOMY, "", Messages.CMD_OK, null,
454: null);
455: graphical.Header.showStatus(Messages.SAVED);
456: return true;
457: } else if (answer == 2) { // Cancel
458: return false;
459: }
460:
461: return false;
462: }
463:
464: public static void main(String args[]) {
465: Desktop app;
466: app = new Desktop();
467: app.standAlone = true;
468: app.run();
469: System.exit(0);
470: }
471: }
|