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 components;
012:
013: import graphical.DragPolicy;
014: import graphical.TreeWindow;
015: import soif.CSID;
016: import soif.Schema;
017: import soif.Taxonomy;
018: import util.BTreeNode;
019:
020: import netscape.application.Alert;
021: import netscape.application.ExternalWindow;
022: import netscape.application.Menu;
023: import netscape.application.MenuItem;
024: import netscape.application.MenuView;
025: import netscape.application.View;
026:
027: /* SGP: later provide methods for graphics swapping */
028: // SGP: should TTV be public?
029: public class ClassificationWindow extends TreeWindow {
030: public ClassificationView classificationView;
031: public String testClassRules;
032:
033: private Taxonomy m_taxonomy;
034:
035: private boolean changed = false;
036:
037: public ClassificationWindow(int x, int y, int width, int height,
038: Schema schema, Taxonomy taxonomy, String ruleset[],
039: boolean menus) {
040: super (x, y, width, height, null, Messages.TITLE_CLASSRULES);
041:
042: classificationView = new ClassificationView(0, 0, width,
043: height, schema, taxonomy, ruleset);
044:
045: commonConstruction(width, height, menus, taxonomy);
046: }
047:
048: public ClassificationWindow(int x, int y, int width, int height,
049: Schema schema, Taxonomy taxonomy, String CGILocation,
050: String CGITarget, String CGIRulesRead,
051: String CGIRulesWrite, boolean menus) {
052: super (x, y, width, height, null, Messages.TITLE_CLASSRULES);
053:
054: classificationView = new ClassificationView(0, 0, width,
055: height, schema, taxonomy, CGILocation, CGITarget,
056: CGIRulesRead, CGIRulesWrite);
057:
058: commonConstruction(width, height, menus, taxonomy);
059: }
060:
061: private void commonConstruction(int width, int height,
062: boolean menus, Taxonomy taxonomy) {
063: m_taxonomy = taxonomy;
064:
065: testClassRules = null;
066: addSubview(classificationView);
067: setResizable(true);
068: setMinSize(width, height);
069: setTitle(Messages.TITLE_CLASSRULES);
070:
071: classificationView
072: .setDragDestinationPolicy(DragPolicy.DRAGTOACCEPT);
073: classificationView
074: .setHorizResizeInstruction(View.WIDTH_CAN_CHANGE);
075: classificationView
076: .setVertResizeInstruction(View.HEIGHT_CAN_CHANGE);
077:
078: if (menus) {
079: Menu menu = new Menu();
080: MenuItem fileMenuItem = menu
081: .addItemWithSubmenu(Messages.MENU_FILE);
082: fileMenuItem.submenu().addItem(Messages.CMD_SAVE,
083: Messages.CMD_SAVE, this );
084: fileMenuItem.submenu().addItem(Messages.CMD_CLOSE,
085: Messages.CMD_CLOSE, this );
086: MenuItem windMenuItem = menu
087: .addItemWithSubmenu(Messages.MENU_EDIT);
088: windMenuItem.submenu().addItem(Messages.CMD_NEW,
089: Messages.CMD_NEW, this );
090: windMenuItem.submenu().addItem(Messages.CMD_DELETE,
091: Messages.CMD_DELETE, this );
092: MenuView menuView = new MenuView(menu);
093: menuView.sizeToMinSize();
094: setMenuView(menuView);
095: classificationView.hideEditButtons();
096: }
097:
098: // Set up so that close button sends a CMD_CLOSE. Then we will
099: // automatically check for unsaved changes when the close button is hit.
100: setCloseCommand(Messages.CMD_CLOSE);
101: setCloseTarget(this );
102: }
103:
104: public void performCommand(String command, Object arg) {
105: if (Messages.CMD_SAVE.equals(command)) {
106: rootView().setOverrideCursor(View.WAIT_CURSOR);
107: classificationView.clickCommand();
108: if (testClassRules == null) {
109: classificationView.writeClassRules();
110: } else {
111: System.out.println(classificationView
112: .toStringClassRules());
113: }
114: rootView().removeOverrideCursor();
115: changed = false;
116: Alert.runAlertExternally(Alert.notificationImage(),
117: applications.Messages.SAVED_CLASSRULES, "",
118: Messages.CMD_OK, null, null);
119: graphical.Header.showStatus(applications.Messages.SAVED);
120: } else if (Messages.CMD_CLOSE.equals(command)) {
121: if (closeRequest() == false) { // Check for ensaved changes (MCW)
122: return;
123: }
124:
125: hide();
126: } else if (Messages.CMD_NEW.equals(command)) {
127: classificationView.newButtonPress();
128: } else if (Messages.CMD_DELETE.equals(command)) {
129: classificationView.deleteButtonPress();
130: } else if (applications.Messages.CMD_DESKTOP_BROADCAST
131: .equals(command)) {
132: // System.out.println("Rules Editor Tax Chg Recd======\n" + "\n=======");
133:
134: if (applications.Messages.CMD_TAX_CHG.equals(arg)) {
135: classificationView.updateTaxonomyComboBox(m_taxonomy);
136: return;
137: }
138: } else if (graphical.Messages.MSG_CHANGED_DATA.equals(command)) {
139: changed = true;
140: } else {
141: super .performCommand(command, arg);
142: }
143: }
144:
145: public boolean closeRequest() {
146: // If there are unsaved changes display dialog and allow Save changes,
147: // Discard changes and Cancel changes. (MCW)
148:
149: if (changed == true) {
150: int answer = Alert.runAlertExternally(Alert
151: .notificationImage(), Messages.TITLE_CR_UNSAVED,
152: "", Messages.CMD_SAVE, Messages.CMD_DISCARD,
153: Messages.CMD_CANCEL);
154: if (answer == components.Header.SAVE_SAVE) { // Save
155: performCommand(applications.Messages.CMD_SAVE, null);
156: return true;
157: } else if (answer == components.Header.SAVE_CONTINUE) { // Discard?
158: return true;
159: }
160:
161: return false; // Cancelled - stay open
162: }
163:
164: return true; // No changes - close
165: }
166: }
|