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.SchemaTreeWindow;
014: import graphical.DragListView;
015: import graphical.WindowTiler;
016: import soif.CSID;
017: import util.ReportError;
018:
019: import netscape.application.Alert;
020: import netscape.application.Application;
021: import netscape.application.Bitmap;
022: import netscape.application.ExternalWindow;
023: import netscape.application.ListItem;
024: import netscape.application.Menu;
025: import netscape.application.MenuItem;
026: import netscape.application.MenuView;
027: import netscape.application.Size;
028: import netscape.application.Target;
029: import netscape.application.View;
030: import netscape.application.Window;
031: import netscape.application.WindowOwner;
032:
033: public class SchemaEdit extends Application implements Target,
034: WindowOwner {
035: private WindowTiler windowTiler;
036:
037: private SchemaTreeWindow schemaTreeWindow;
038: private String testSchema;
039: private ExternalWindow externalWindow;
040: public boolean changed;
041:
042: private boolean standAlone = false;
043:
044: public void init() {
045: super .init();
046:
047: Header.showVersion(Messages.TITLE_SCHEMAEDIT, true, true);
048:
049: boolean valid = true;
050:
051: changed = false;
052:
053: externalWindow = new ExternalWindow();
054: setMainRootView(externalWindow.rootView());
055: mainRootView().setColor(graphical.Header.DESKTOPCOLOR);
056: externalWindow.setTitle(Messages.TITLE_SCHEMAEDIT);
057: externalWindow.setOwner(this ); // To intercept close
058:
059: // Create window tiler
060: windowTiler = new WindowTiler();
061:
062: String CGILocation = Header.parameterMacro(this , "CGILocation");
063: String CGITarget = Header.parameterMacro(this , "CGITarget");
064: String CGISchemaRead = Header.parameterMacro(this ,
065: "CGISchemaRead");
066: String CGISchemaWrite = Header.parameterMacro(this ,
067: "CGISchemaWrite");
068: String CGISchemaWriteReindex = Header.parameterMacro(this ,
069: "CGISchemaWriteReindex");
070:
071: CSID csid = Header.parameterCSIDMacro(this );
072:
073: if ((CGILocation == null) || (CGITarget == null)
074: || (CGISchemaRead == null) || (CGISchemaWrite == null)
075: || (CGISchemaWriteReindex == null)
076: || (csid.isValid() == false)) {
077: valid = false;
078: }
079:
080: testSchema = (standAlone) ? "testSchema"
081: : parameterNamed("testSchema");
082: if (testSchema != null) {
083: valid = true;
084: }
085:
086: if (valid) {
087: Menu menu = new Menu();
088: MenuItem fileMenuItem = menu
089: .addItemWithSubmenu(Messages.MENU_FILE);
090: fileMenuItem.submenu().addItem(Messages.CMD_SAVE,
091: components.Messages.SCUT_SAVE, Messages.CMD_SAVE,
092: this );
093: fileMenuItem.submenu().addItem(Messages.CMD_CLOSE,
094: components.Messages.SCUT_CLOSE, Messages.CMD_CLOSE,
095: this );
096: MenuView menuView = new MenuView(menu);
097: menuView.sizeToMinSize();
098: externalWindow.setMenuView(menuView);
099:
100: if (testSchema == null) {
101: schemaTreeWindow = new SchemaTreeWindow(0, 0,
102: graphical.Header.IWINDWIDTH,
103: graphical.Header.IWINDHEIGHT, CGILocation,
104: CGITarget, CGISchemaRead, CGISchemaWrite, csid,
105: true, false, true);
106: } else {
107: ReportError.reportError(ReportError.WARNING,
108: ReportError.ADMIN, "SchemaEdit", "init",
109: Messages.USETESTSCHEMA);
110:
111: schemaTreeWindow = new SchemaTreeWindow(0, 0,
112: graphical.Header.IWINDWIDTH,
113: graphical.Header.IWINDHEIGHT, Instrument
114: .testSchema(), true, false, true);
115: }
116: if (CGISchemaWriteReindex != null) {
117: schemaTreeWindow.schemaTreeView
118: .setWriteReindex(CGISchemaWriteReindex);
119: }
120:
121: schemaTreeWindow.schemaTreeView.notifyOfChange = this ;
122: schemaTreeWindow.moveTo(graphical.Header.WINDOWHGAP,
123: externalWindow.menuView().height()
124: + graphical.Header.WINDOWVGAP);
125: schemaTreeWindow.setCloseable(false);
126: schemaTreeWindow.setMinimize(new Bitmap(
127: components.Header.minCompass,
128: components.Header.minCompassSize.width,
129: components.Header.minCompassSize.height),
130: components.Messages.LBL_SCHEMA, externalWindow,
131: windowTiler);
132:
133: Header.EWSizer(externalWindow, schemaTreeWindow);
134:
135: windowTiler.addWindow(schemaTreeWindow); // Tile window (set position)
136: schemaTreeWindow.setCloseable(true);
137: schemaTreeWindow.setCloseCommand(Messages.CMD_CLOSE);
138: schemaTreeWindow.setCloseTarget(this );
139: schemaTreeWindow.show();
140: externalWindow.show();
141: }
142:
143: Header.showVersion(Messages.TITLE_SCHEMAEDIT, false, true);
144: }
145:
146: public void performCommand(String command, Object arg) {
147: if (Messages.CMD_SAVE.equals(command)) {
148: if (!schemaTreeWindow.schemaTreeView.valid()) {
149: return;
150: }
151:
152: String status = null;
153:
154: schemaTreeWindow.schemaTreeView.completeEditing();
155: schemaTreeWindow.schemaTreeView.getDetail();
156: externalWindow.rootView().setOverrideCursor(
157: View.WAIT_CURSOR);
158: if (testSchema == null) {
159: status = schemaTreeWindow.schemaTreeView.writeSchema();
160: } else {
161: System.out
162: .println(schemaTreeWindow.schemaTreeView.schema
163: .toSOIF());
164: status = "";
165: }
166: externalWindow.rootView().removeOverrideCursor();
167: changed = false; // SGP: not always correct,
168: // because some of the save choices get made in
169: // schemaTreeView. ought to tighten up the save
170: // in general, it's spread across two classes.
171: if (status != null) {
172: if (!status.equals("NODIALOG")) {
173: Alert.runAlertExternally(Alert.notificationImage(),
174: Messages.SAVED_SCHEMA,
175: Messages.SERVER_RESTART, Messages.CMD_OK,
176: null, null);
177: graphical.Header.showStatus(Messages.SAVED);
178: }
179: }
180: } else if (Messages.CMD_CLOSE.equals(command)) {
181: if (changed) {
182: int answer = Alert.runAlertExternally(Alert
183: .notificationImage(), Messages.CHANGED_DATA,
184: "", components.Messages.CMD_SAVE,
185: components.Messages.CMD_DISCARD,
186: components.Messages.CMD_CANCEL);
187:
188: if (answer == components.Header.SAVE_CANCEL) { // Cancel close?
189: return;
190: }
191:
192: if (answer == components.Header.SAVE_SAVE) { // Save
193: performCommand(Messages.CMD_SAVE, null);
194: }
195:
196: externalWindow.dispose();
197: } else {
198: externalWindow.dispose();
199: }
200: } else if (graphical.Messages.MSG_CHANGED_DATA.equals(command)) {
201: changed = true;
202: }
203: }
204:
205: public static void main(String args[]) {
206: SchemaEdit app;
207: app = new SchemaEdit();
208: app.standAlone = true;
209: app.run();
210: System.exit(0);
211: }
212:
213: /**
214: * WindowOwner interface. Used to intercept close on application window
215: * and check for unsaved changes.
216: */
217:
218: public void windowDidHide(Window window) {
219: /*
220: * Removed this, it causes a crash if the applet is closed and
221: * then the user clicks on the disable button in the admin window
222:
223: stopRunning();
224:
225: */
226: }
227:
228: public boolean windowWillHide(Window window) {
229: if (changed) {
230: int answer = Alert.runAlertExternally(Alert
231: .notificationImage(), Messages.CHANGED_DATA, "",
232: components.Messages.CMD_SAVE,
233: components.Messages.CMD_DISCARD,
234: components.Messages.CMD_CANCEL);
235:
236: if (answer == components.Header.SAVE_CANCEL) { // Cancel close?
237: return false;
238: }
239:
240: if (answer == components.Header.SAVE_SAVE) { // Save
241: performCommand(Messages.CMD_SAVE, null);
242: }
243: }
244:
245: return true;
246: }
247:
248: public void windowDidBecomeMain(Window window) {
249: }
250:
251: public void windowDidResignMain(Window window) {
252: }
253:
254: public void windowDidShow(Window window) {
255: }
256:
257: public boolean windowWillShow(Window window) {
258: return true;
259: }
260:
261: public void windowWillSizeBy(Window window, Size size) {
262: }
263: }
|