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.TaxonomyTreeWindow;
014: import graphical.TreeViewGroup;
015: import graphical.WindowTiler;
016: import soif.CSID;
017: import soif.Taxonomy;
018: import util.BTreeNode;
019: import util.ReportError;
020:
021: import netscape.application.Alert;
022: import netscape.application.Application;
023: import netscape.application.Bitmap;
024: import netscape.application.ExternalWindow;
025: import netscape.application.Menu;
026: import netscape.application.MenuItem;
027: import netscape.application.MenuView;
028: import netscape.application.Size;
029: import netscape.application.Target;
030: import netscape.application.View;
031: import netscape.application.Window;
032: import netscape.application.WindowOwner;
033: import netscape.util.Enumeration;
034:
035: public class TaxonomyEdit extends Application implements Target,
036: WindowOwner {
037: private WindowTiler windowTiler;
038:
039: // SGP: public for sleazy manipulation by TTVs
040: public Taxonomy taxonomy;
041:
042: // Saved taxonomy for unsaved changes test
043: private String savedTaxonomy = null;
044:
045: private TreeViewGroup treeViewGroup;
046: private String testTaxonomy;
047: private static ExternalWindow externalWindow;
048: private String CGITaxPost;
049:
050: private Bitmap bm;
051: private boolean standAlone = false;
052:
053: private boolean taxonomySaved = false;
054: private boolean pro = false;
055:
056: public void init() {
057: super .init();
058:
059: Header.showVersion(Messages.TITLE_TAXONOMYEDIT, true, true);
060:
061: boolean valid = true;
062:
063: bm = new Bitmap(components.Header.minCompass,
064: components.Header.minCompassSize.width,
065: components.Header.minCompassSize.height);
066:
067: externalWindow = new ExternalWindow();
068: setMainRootView(externalWindow.rootView());
069: mainRootView().setColor(graphical.Header.DESKTOPCOLOR);
070: externalWindow.setTitle(Messages.TITLE_TAXONOMYEDIT);
071: externalWindow.setOwner(this ); // To intercept close
072:
073: // Create window tiler
074: windowTiler = new WindowTiler();
075:
076: String CGILocation = Header.parameterMacro(this , "CGILocation");
077: String CGITarget = Header.parameterMacro(this , "CGITarget");
078: String CGITaxRead = Header.parameterMacro(this , "CGITaxRead");
079: String CGITaxWrite = Header.parameterMacro(this , "CGITaxWrite");
080:
081: CSID csid = Header.parameterCSIDMacro(this );
082:
083: if ((CGILocation == null) || (CGITarget == null)
084: || (CGITaxRead == null) || (CGITaxWrite == null)
085: || (csid.isValid() == false)) {
086: valid = false;
087: }
088:
089: CGITaxPost = CGILocation + CGITarget + CGITaxWrite;
090:
091: testTaxonomy = (standAlone) ? "testTaxonomy"
092: : parameterNamed("testTaxonomy");
093: if (testTaxonomy != null) {
094: valid = true;
095: }
096:
097: if (parameterNamed("pro") != null)
098: pro = parameterNamed("pro").equals("true");
099:
100: if (valid) {
101: Menu menu = new Menu();
102: MenuItem fileMenuItem = menu
103: .addItemWithSubmenu(Messages.MENU_FILE);
104: if (testTaxonomy != null) {
105: fileMenuItem.submenu().addItem("dumpTree()",
106: "dumpTree()", this );
107: fileMenuItem.submenu().addItem("recursiveDump()",
108: "recursiveDump()", this );
109: }
110: fileMenuItem.submenu().addItem(
111: applications.Messages.CMD_SAVE,
112: components.Messages.SCUT_SAVE,
113: applications.Messages.CMD_TAXSAVE, this );
114: fileMenuItem.submenu().addItem(Messages.CMD_CLOSE,
115: components.Messages.SCUT_CLOSE, Messages.CMD_CLOSE,
116: this );
117: MenuItem windMenuItem = menu
118: .addItemWithSubmenu(Messages.MENU_WINDOW);
119: windMenuItem.submenu().addItem(Messages.CMD_NEWTAXWIND,
120: Messages.CMD_NEWTAXWIND, this );
121: MenuView menuView = new MenuView(menu);
122: menuView.sizeToMinSize();
123: externalWindow.setMenuView(menuView);
124:
125: TaxonomyTreeWindow taxonomyTreeWindow;
126:
127: treeViewGroup = new TreeViewGroup();
128:
129: if (testTaxonomy == null) {
130: taxonomyTreeWindow = new TaxonomyTreeWindow(0, 0,
131: graphical.Header.IWINDWIDTH,
132: graphical.Header.IWINDHEIGHT, CGILocation,
133: CGITarget, CGITaxRead, CGITaxWrite, csid, pro,
134: true, false, this );
135: } else {
136: ReportError.reportError(ReportError.WARNING,
137: ReportError.ADMIN, "TaxonomyEdit", "init",
138: Messages.USETESTTAXONOMY);
139:
140: taxonomyTreeWindow = new TaxonomyTreeWindow(0, 0,
141: graphical.Header.IWINDWIDTH,
142: graphical.Header.IWINDHEIGHT, Instrument
143: .testTaxonomy(), true, false, this );
144: }
145: taxonomy = taxonomyTreeWindow.taxonomyTreeView.taxonomy;
146:
147: // Convert taxonomy to a string for unsaved changes tests
148: if (taxonomy != null) {
149: savedTaxonomy = taxonomy.toStringTree(true, false,
150: false);
151: }
152:
153: taxWindMacro(taxonomyTreeWindow);
154: taxonomyTreeWindow.moveTo(graphical.Header.WINDOWHGAP,
155: externalWindow.menuView().height()
156: + graphical.Header.WINDOWVGAP);
157:
158: Header.EWSizer(externalWindow, taxonomyTreeWindow);
159:
160: windowTiler.addWindow(taxonomyTreeWindow); // Tile window (set position)
161: taxonomyTreeWindow.show();
162: externalWindow.show();
163: }
164:
165: Header.showVersion(Messages.TITLE_TAXONOMYEDIT, false, true);
166: }
167:
168: private void taxWindMacro(TaxonomyTreeWindow taxonomyTreeWindow) {
169: taxonomyTreeWindow.taxonomyTreeView.setLauncher(this ,
170: Messages.CMD_NEWTAXWIND);
171: taxonomyTreeWindow.taxonomyTreeView
172: .setTreeViewGroup(treeViewGroup);
173: taxonomyTreeWindow.setMinimize(bm,
174: components.Messages.LBL_TAXONOMY, externalWindow,
175: windowTiler);
176: taxonomyTreeWindow.taxonomyTreeView.te = this ; // SGP: sleaze
177: // NOTE: the following two statements turn on w/in tree d'n'd.
178: // if there is an insurmountable problem, removing them will
179: // revert to default behaviour.
180: taxonomyTreeWindow.taxonomyTreeView
181: .setDragSourcePolicy(graphical.DragPolicy.DRAGFROMMOVE);
182: taxonomyTreeWindow.taxonomyTreeView
183: .setDragDestinationPolicy(graphical.DragPolicy.DRAGTOACCEPTINCLUDE);
184: }
185:
186: public void performCommand(String command, Object arg) {
187: if (applications.Messages.CMD_TAXSAVE.equals(command)) {
188: saveCommand();
189: } else if ("dumpTree()".equals(command)) {
190: taxonomy.binaryTree.dumpTree();
191: } else if ("recursiveDump()".equals(command)) {
192: taxonomy.binaryTree.getRoot().recursiveDump();
193: } else if (Messages.CMD_NEWTAXWIND.equals(command)) {
194: TaxonomyTreeWindow taxonomyTreeWindow = new TaxonomyTreeWindow(
195: graphical.Header.WINDOWHGAP, externalWindow
196: .menuView().height()
197: + graphical.Header.WINDOWVGAP,
198: graphical.Header.IWINDWIDTH,
199: graphical.Header.IWINDHEIGHT, taxonomy, true,
200: false, this );
201: taxWindMacro(taxonomyTreeWindow);
202: if (arg instanceof BTreeNode) {
203: taxonomyTreeWindow.taxonomyTreeView
204: .setBinaryTree((BTreeNode) arg);
205: }
206: windowTiler.addWindow(taxonomyTreeWindow); // Tile window (set position)
207: taxonomyTreeWindow.show();
208: } else if (Messages.CMD_CLOSE.equals(command)) {
209: // Loop thru all tree view windows and ensure changes are saved.
210: Enumeration e = externalWindow.rootView().internalWindows()
211: .elements();
212:
213: while (e.hasMoreElements()) {
214: Object o = e.nextElement();
215: if (o instanceof TaxonomyTreeWindow) {
216: ((TaxonomyTreeWindow) o).taxonomyTreeView
217: .completeEditing();
218: }
219: }
220:
221: if ((taxonomy != null) && (savedTaxonomy != null)) {
222: // System.out.println("taxonomy======\n" + taxonomy.toStringTree(true, false, false) + "\n=======");
223: // System.out.println("savedTaxonomy======\n" + savedTaxonomy + "\n=======");
224: if (savedTaxonomy.equals(taxonomy.toStringTree(true,
225: false, false)) == false) {
226: int answer = Alert.runAlertExternally(Alert
227: .notificationImage(),
228: components.Messages.TITLE_CE_UNSAVED, "",
229: Messages.CMD_SAVE,
230: components.Messages.CMD_DISCARD,
231: Messages.CMD_CANCEL);
232:
233: if (answer == components.Header.SAVE_SAVE) { // Save
234: saveCommand();
235: taxonomySaved = false; // Supress next reindex warning
236: } else if (answer == components.Header.SAVE_CANCEL) { // Cancel?
237: return;
238: }
239: }
240: }
241:
242: if (taxonomySaved == true) {
243: if (pro) {
244: Alert.runAlertExternally(Alert.warningImage(),
245: Messages.EXIT_TAXONOMY,
246: Messages.REINDEX_INFO_PRO, Messages.CMD_OK,
247: null, null);
248: } else {
249: Alert.runAlertExternally(Alert.warningImage(),
250: Messages.EXIT_TAXONOMY,
251: Messages.REINDEX_INFO, Messages.CMD_OK,
252: null, null);
253: }
254: }
255:
256: externalWindow.dispose();
257: externalWindow = null;
258: }
259: }
260:
261: public boolean saveCommand() {
262: Enumeration e = externalWindow.rootView().internalWindows()
263: .elements();
264: while (e.hasMoreElements()) {
265: Object o = e.nextElement();
266: if (o instanceof TaxonomyTreeWindow) {
267: ((TaxonomyTreeWindow) o).taxonomyTreeView
268: .clickCommand();
269: ((TaxonomyTreeWindow) o).taxonomyTreeView
270: .completeEditing();
271: }
272: }
273: if ("".equals(taxonomy.getTaxonomyId())) {
274: Alert.runAlertExternally(Alert.notificationImage(),
275: Messages.INVALIDTAXID, "", Messages.CMD_OK, null,
276: null);
277: return false;
278: }
279:
280: externalWindow.rootView().setOverrideCursor(View.WAIT_CURSOR);
281:
282: if (testTaxonomy != null) {
283: System.out.println(taxonomy.toSOIF());
284: } else {
285: // System.out.println("doWrite()======\n" + "\n=======");
286: communications.PostConnection.doWrite(CGITaxPost, taxonomy
287: .toSOIF());
288: // System.out.println("doWrite() complete======\n" + "\n=======");
289: }
290:
291: // System.out.println("sendAction()======\n" + "\n=======");
292: treeViewGroup.sendAction(null, TreeViewGroup.CLEARCHANGE, null);
293: // System.out.println("sendAction() complete======\n" + "\n=======");
294:
295: // Convert taxonomy to a string for unsaved changes tests
296: if (taxonomy != null) {
297: savedTaxonomy = taxonomy.toStringTree(true, false, false);
298: }
299:
300: externalWindow.rootView().removeOverrideCursor();
301:
302: // Display reindexing reminder.
303: Alert.runAlertExternally(Alert.warningImage(),
304: Messages.SAVED_TAXONOMY, Messages.REINDEX_INFO,
305: Messages.CMD_OK, null, null);
306: graphical.Header.showStatus(Messages.SAVED);
307: taxonomySaved = true; // Display reindexing reminder on close
308: return true;
309: }
310:
311: public static void main(String args[]) {
312: TaxonomyEdit app;
313: app = new TaxonomyEdit();
314: app.standAlone = true;
315: app.run();
316: System.exit(0);
317: }
318:
319: /**
320: * WindowOwner interface. Used to intercept close on application window
321: * and check for unsaved changes.
322: */
323:
324: public void windowDidHide(Window window) {
325: /*
326: * Removed this, it causes a crash if the applet is closed and
327: * then the user clicks on the disable button in the admin window
328:
329: stopRunning();
330:
331: */
332: // System.out.println("windowDidHide======\n");
333: }
334:
335: public boolean windowWillHide(Window window) {
336: // System.out.println("windowWillHide======\n");
337: // Loop thru all tree view windows and ensure changes are saved.
338: Enumeration e = externalWindow.rootView().internalWindows()
339: .elements();
340:
341: while (e.hasMoreElements()) {
342: Object o = e.nextElement();
343: if (o instanceof TaxonomyTreeWindow) {
344: ((TaxonomyTreeWindow) o).taxonomyTreeView
345: .completeEditing();
346: }
347: }
348:
349: if ((taxonomy != null) && (savedTaxonomy != null)) {
350: if (savedTaxonomy.equals(taxonomy.toStringTree(true, false,
351: false)) == false) {
352: int answer = Alert.runAlertExternally(Alert
353: .notificationImage(),
354: components.Messages.TITLE_CE_UNSAVED, "",
355: Messages.CMD_SAVE,
356: components.Messages.CMD_DISCARD,
357: Messages.CMD_CANCEL);
358:
359: if (answer == components.Header.SAVE_SAVE) { // Save
360: saveCommand();
361: taxonomySaved = false; // Supress next reindex warning
362: } else if (answer == components.Header.SAVE_CANCEL) { // Cancel?
363: return false;
364: }
365: }
366: }
367:
368: if (taxonomySaved == true) {
369: Alert.runAlertExternally(Alert.warningImage(),
370: Messages.EXIT_TAXONOMY, Messages.REINDEX_INFO,
371: Messages.CMD_OK, null, null);
372: }
373:
374: return true;
375: }
376:
377: public void windowDidBecomeMain(Window window) {
378: }
379:
380: public void windowDidResignMain(Window window) {
381: }
382:
383: public void windowDidShow(Window window) {
384: }
385:
386: public boolean windowWillShow(Window window) {
387: return true;
388: }
389:
390: public void windowWillSizeBy(Window window, Size size) {
391: }
392: }
|