001: /*
002: * Enhydra Java Application Server Project
003: *
004: * The contents of this file are subject to the Enhydra Public License
005: * Version 1.1 (the "License"); you may not use this file except in
006: * compliance with the License. You may obtain a copy of the License on
007: * the Enhydra web site ( http://www.enhydra.org/ ).
008: *
009: * Software distributed under the License is distributed on an "AS IS"
010: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
011: * the License for the specific terms governing rights and limitations
012: * under the License.
013: *
014: * The Initial Developer of the Enhydra Application Server is Lutris
015: * Technologies, Inc. The Enhydra Application Server and portions created
016: * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
017: * All Rights Reserved.
018: *
019: * Contributor(s):
020: * Paul Mahar
021: *
022: */
023: package org.enhydra.kelp.common.dods;
024:
025: // Kelp imports
026: import org.enhydra.kelp.common.event.WriteEvent;
027: import org.enhydra.kelp.common.event.WriteListener;
028: import org.enhydra.kelp.common.node.OtterNode;
029: import org.enhydra.kelp.common.node.OtterProject;
030: import org.enhydra.kelp.common.swing.AddinInnerPanel;
031:
032: // ToolBox imports
033: import org.enhydra.tool.common.DataValidationException;
034: import org.enhydra.tool.common.ButtonPanel;
035: import org.enhydra.tool.common.ToolException;
036:
037: // Standard imports
038: import java.awt.*;
039: import java.lang.ref.WeakReference;
040: import javax.swing.*;
041: import javax.swing.event.*;
042: import java.beans.*;
043:
044: //
045: public class DodsInnerPanel extends AddinInnerPanel {
046:
047: private int showIndex = 0;
048: private JTabbedPane tab = null;
049: private BorderLayout layoutMain = null;
050: private GeneralPanel generalPanel = null;
051: private WeakReference backRef = null;
052: private WeakReference nextRef = null;
053:
054: public DodsInnerPanel() {
055: super ();
056: try {
057: jbInit();
058: pmInit();
059: } catch (Exception ex) {
060: ex.printStackTrace();
061: }
062: }
063:
064: // override AddinInnerPanel
065: public void read(OtterNode node) {
066: super .read(node);
067: DodsStep[] steps = new DodsStep[0];
068:
069: steps = getSteps();
070: for (int i = 0; i < steps.length; i++) {
071: steps[i].read(getProject());
072: }
073:
074: }
075:
076: // override AddinInnerPanel
077: public void write(OtterNode node) throws DataValidationException {
078: super .write(node);
079:
080: generalPanel.write(getProject());
081: }
082:
083: // override AddinInnerPanel
084: public void initPreferredSize() {
085: Dimension d = new Dimension();
086:
087: d.height = 500;
088: d.width = 600;
089: setPreferredSize(d);
090: }
091:
092: // override AddinInnerPanel
093: public void clearAll() {
094: super .clearAll();
095: if (backRef != null) {
096: backRef.clear();
097: }
098: if (nextRef != null) {
099: nextRef.clear();
100: }
101: generalPanel.clearAll();
102: backRef = null;
103: nextRef = null;
104: generalPanel = null;
105: }
106:
107: //
108: private void refresh() {
109: Component back = null;
110: Component next = null;
111: boolean backEnable = true;
112: boolean nextEnable = true;
113:
114: int index = tab.getSelectedIndex();
115:
116: if (index == 0) {
117: backEnable = false;
118: } else if (index == (tab.getTabCount() - 1)) {
119: nextEnable = false;
120: }
121: if (back != null) {
122: back.setEnabled(backEnable);
123: }
124: if (next != null) {
125: next.setEnabled(nextEnable);
126: }
127: generalPanel.refresh();
128: }
129:
130: protected void back() {
131: int index = tab.getSelectedIndex();
132:
133: if (index > 0) {
134: showIndex = --index;
135: tab.setSelectedIndex(showIndex);
136: }
137: refresh();
138: }
139:
140: private WriteListener getWriteListener() {
141: return generalPanel.getWriteListener();
142: }
143:
144: protected void generate(CoreDodsTool tool) {
145:
146: if (getProject() != null) {
147:
148: Generator generate = null;
149: try {
150: WriteEvent clear;
151:
152: clear = new WriteEvent(this , WriteEvent.CLEAR,
153: new String());
154: trySave();
155: generate = new Generator(getWriteListener());
156: generate.setProject(getProject());
157: generate.setEcho(true);
158: generate.addProgressListener(tool.getProgressMeter());
159: tool.getProgressMeter().addCancelListener(generate);
160: getWriteListener().onWrite(clear);
161:
162: tool.openProgress();
163:
164: generate.setOwner(getWindow());
165: generate.setDoneDialog(true);
166:
167: generate.build();
168:
169: } catch (DataValidationException e) {
170: JOptionPane.showMessageDialog(this , e
171: .getValidationMessage());
172: } catch (ToolException e) {
173: JOptionPane.showMessageDialog(this , e.getMessage());
174: e.printStackTrace(System.err);
175: }
176: }
177: }
178:
179: // override InnerPanel
180: protected Component[] getFirstFocusComponents() {
181: Component[] comps = new Component[0];
182: Component[] genComps = new Component[0];
183:
184: genComps = generalPanel.getFirstFocusComponents();
185: comps = new Component[genComps.length + 1];
186: comps[0] = tab;
187: for (int i = 0; i < genComps.length; i++) {
188: comps[i + 1] = genComps[i];
189: }
190: return comps;
191: }
192:
193: // override InnerPanel
194: public void save() {
195: if (getProject() == null) {
196: System.err.println("DodsInnerPanel.save() - project null");
197: } else {
198: try {
199: trySave();
200: } catch (DataValidationException e) {
201: System.err.println(e.getValidationMessage());
202: } catch (ToolException e) {
203: System.err.println(e.getMessage());
204: }
205: }
206: }
207:
208: private void trySave() throws DataValidationException,
209: ToolException {
210: try {
211: write(getProject());
212: } catch (DataValidationException e) {
213: }
214: }
215:
216: //
217: private void pmInit() {
218: generalPanel = new GeneralPanel();
219: addInstructor(generalPanel);
220: }
221:
222: private void addInstructor(Instructor i) {
223: InstructPanel ip = null;
224:
225: if (i instanceof JPanel) {
226: ip = new InstructPanel();
227: ip.addInstuctor(i);
228: tab.add(ip, i.getTab());
229: } else {
230: throw new RuntimeException("Instructor not a JPanel: "
231: + i.getTitle());
232: }
233: }
234:
235: private void jbInit() throws Exception {
236: tab = (JTabbedPane) Beans.instantiate(getClass()
237: .getClassLoader(), JTabbedPane.class.getName());
238: layoutMain = (BorderLayout) Beans.instantiate(getClass()
239: .getClassLoader(), BorderLayout.class.getName());
240: this .setLayout(layoutMain);
241: this .add(tab, BorderLayout.CENTER);
242: }
243:
244: private class TabChangeListener implements ChangeListener {
245: public void stateChanged(ChangeEvent e) {
246: if (!tab.getSelectedComponent().isShowing()) {
247: int selectIndex = tab.getSelectedIndex();
248:
249: if (selectIndex > showIndex) {
250: tab.setSelectedIndex(showIndex);
251: for (int i = showIndex; i < selectIndex; i++) {
252: break;
253: }
254: showIndex = tab.getSelectedIndex();
255: } else if (selectIndex < showIndex) {
256: showIndex = selectIndex;
257: }
258: }
259: refresh();
260: }
261:
262: }
263:
264: private DodsStep[] getSteps() {
265: DodsStep[] steps = new DodsStep[1];
266:
267: steps[0] = generalPanel;
268: return steps;
269: }
270:
271: }
|