001: package org.enhydra.kelp.ant.deployer;
002:
003: /**
004: * <p>Title: </p>
005: * <p>Description: New dialog for Kelp XML Compiler based on Ant tool.</p>
006: * <p>Copyright: Copyright (c) 2003</p>
007: * <p>Company: </p>
008: * @author Damir Milovic
009: * @version 1.0
010: */
011:
012: // ToolBox
013: import org.enhydra.tool.common.DataValidationException;
014:
015: // AddinCore
016: import org.enhydra.kelp.common.event.WriteListener;
017: import org.enhydra.kelp.common.node.OtterFileNode;
018: import org.enhydra.kelp.common.node.OtterNode;
019: import org.enhydra.kelp.common.swing.AddinInnerPanel;
020: import org.enhydra.kelp.ant.swing.AntOutputPanel;
021:
022: // JDK
023: import java.util.ArrayList;
024: import java.util.Arrays;
025: import java.util.ResourceBundle;
026: import java.awt.*;
027: import java.beans.*;
028: import javax.swing.*;
029: import org.enhydra.tool.common.ButtonPanel;
030: import org.enhydra.tool.swing.layout.*;
031:
032: //import com.borland.jbcl.layout.*;
033:
034: //
035: public class AntDeployInnerPanel extends AddinInnerPanel {
036:
037: //
038: static ResourceBundle res = ResourceBundle
039: .getBundle("org.enhydra.kelp.common.Res"); // nores
040:
041: //
042:
043: private GridBagLayout layoutMain = null;
044: private AntOutputPanel outputPanel = null;
045: private AntDeployGeneralPanel generalPanel = null;
046: private AntDeployInputPanel inputPanel = null;
047: private AntDeployContentPanel contentPanel = null;
048: private JTabbedPane tab = null;
049: private WriteListener[] writeListeners = new WriteListener[0];
050: XYLayout xYLayout1 = new XYLayout();
051:
052: public static AntDeployInnerPanel XMLCfindAncestor(Component comp) {
053: Component found = null;
054: AntDeployInnerPanel ancestor = null;
055:
056: found = AddinInnerPanel.findAncestor(comp);
057: if (found == null) {
058: } else if (found instanceof AntDeployInnerPanel) {
059: ancestor = (AntDeployInnerPanel) found;
060: }
061: return ancestor;
062: }
063:
064: public AntDeployInnerPanel() {
065: try {
066: jbInit();
067: pmInit();
068: } catch (Exception ex) {
069: ex.printStackTrace();
070: }
071: }
072:
073: // override AddinInnerPanel
074: public void initPreferredSize() {
075: Dimension d = new Dimension();
076:
077: d.height = 425;
078: d.width = 550;
079: setPreferredSize(d);
080: }
081:
082: // overwrite org.enhydra.kelp.common.swing.InnerPanel
083: public void clearAll() {
084: super .clearAll();
085: layoutMain = null;
086: writeListeners = new WriteListener[0];
087: }
088:
089: // //7.2.2003
090: // public FileNodeSelectionPanel getSelectionPanel() {
091: // return selectionPanel;
092: // }
093: // protected void setSelectText(String[] s) {
094: // getSelectionPanel().setSelectText(s);
095: // }
096: // protected String[] getSelectText() {
097: // return getSelectionPanel().getSelectText();
098: // }
099: // /**
100: // * Get source files that can be selected for compilation.
101: // */
102: // protected OtterFileNode[] getNodes() {
103: // return selectionPanel.getNodes();
104: // }
105: protected void setNodes(OtterFileNode[] n) {
106: inputPanel.setNodes(n);
107: }
108:
109: public void selectOutputTab() {
110: selectTab(outputPanel);
111: }
112:
113: //
114: // PROTECTED
115: //
116:
117: public synchronized WriteListener[] getWriteListeners() {
118: return writeListeners;
119: }
120:
121: public synchronized void addWriteListener(WriteListener l) {
122: ArrayList list = null;
123: list = new ArrayList(Arrays.asList(writeListeners));
124: if (!list.contains(l)) {
125: list.add(l);
126: list.trimToSize();
127: writeListeners = new WriteListener[list.size()];
128: writeListeners = (WriteListener[]) list
129: .toArray(writeListeners);
130: }
131: list.clear();
132: }
133:
134: public synchronized void removeWriteListener(WriteListener l) {
135: ArrayList list = null;
136: list = new ArrayList(Arrays.asList(writeListeners));
137: if (list.contains(l)) {
138: list.remove(l);
139: list.trimToSize();
140: writeListeners = new WriteListener[list.size()];
141: writeListeners = (WriteListener[]) list
142: .toArray(writeListeners);
143: }
144: list.clear();
145: }
146:
147: // override AddinInnerPanel
148: public void read(OtterNode node) {
149: super .read(node);
150: generalPanel.setProject(getProject());
151: outputPanel.setProject(getProject());
152: inputPanel.setProject(getProject());
153: contentPanel.setProject(getProject());
154: }
155:
156: // override AddinInnerPanel
157: public void write(OtterNode node) throws DataValidationException {
158: super .write(node);
159: if (getProject() == null) {
160: System.err
161: .println("AntDeployInnerPanel.write(OtterProject p) : no project set");
162: } else {
163: outputPanel.setProject(getProject());
164: }
165: }
166:
167: // override AddinInnerPanel
168: protected Component[] getFirstFocusComponents() {
169: Component[] comps = new Component[1];
170:
171: comps[0] = tab;
172: return comps;
173: }
174:
175: //
176: // PRIVATE
177: //
178: // override AddinInnerPanel
179: public void save() {
180: super .save();
181: // FIXME project.save()
182: }
183:
184: //DACHA{
185: //protected void clearOutput() {
186: public void clearOutput() {
187: //}DACHA
188: outputPanel.clearOutput();
189: }
190:
191: protected void back() {
192: int index = tab.getSelectedIndex();
193: int indexNew = 0;
194: if (index > 0) {
195: indexNew = --index;
196: tab.setSelectedIndex(indexNew);
197: }
198: refresh();
199: }
200:
201: protected void next() {
202: int index = tab.getSelectedIndex();
203: int indexNew = 0;
204: if (index < tab.getTabCount()) {
205: indexNew = ++index;
206: tab.setSelectedIndex(indexNew);
207: }
208: refresh();
209: }
210:
211: //
212: // PRIVATE
213: //
214: private void refresh() {
215: Component back = null;
216: Component next = null;
217: boolean backEnable = true;
218: boolean nextEnable = true;
219:
220: back = getBack();
221: next = getNext();
222: int index = tab.getSelectedIndex();
223:
224: if (index == 0) {
225: backEnable = false;
226: } else if (index == (tab.getTabCount() - 1)) {
227: nextEnable = false;
228: }
229: if (back != null) {
230: back.setEnabled(backEnable);
231: }
232: if (next != null) {
233: next.setEnabled(nextEnable);
234: }
235: //getSelectedStep().refresh();
236: }
237:
238: private Component getNext() {
239: Component comp = ButtonPanel.findButton(getTopLevelAncestor(),
240: ButtonPanel.COMMAND_NEXT);
241: return comp;
242: }
243:
244: private Component getBack() {
245: Component comp = ButtonPanel.findButton(getTopLevelAncestor(),
246: ButtonPanel.COMMAND_BACK);
247: return comp;
248: }
249:
250: private void selectTab(final JPanel goPanel) {
251: SelectTab runSwing = null;
252:
253: runSwing = new SelectTab(tab, goPanel);
254: try {
255: if (SwingUtilities.isEventDispatchThread()) {
256: runSwing.run();
257: } else {
258: SwingUtilities.invokeAndWait(runSwing);
259: }
260: } catch (Exception e) {
261: e.printStackTrace();
262: }
263: try {
264: Thread.sleep(500);
265: } catch (InterruptedException e) {
266:
267: //
268: }
269: }
270:
271: /**
272: * Add listeners and other items that are not generated by
273: * the JBuilder designer.
274: */
275: private void pmInit() {
276: tab.add(res.getString("General"), generalPanel);
277: tab.add(res.getString("Input"), inputPanel);
278: tab.add(res.getString("Content"), contentPanel);
279: tab.add(res.getString("Output"), outputPanel);
280: addWriteListener(outputPanel);
281: }
282:
283: /**
284: * UI code generated by JBuilder.
285: * <P><I>Do not modify the signature of this method.</I></P>
286: */
287: private void jbInit() throws Exception {
288: layoutMain = (GridBagLayout) Beans.instantiate(getClass()
289: .getClassLoader(), GridBagLayout.class.getName());
290:
291: outputPanel = (AntOutputPanel) Beans.instantiate(getClass()
292: .getClassLoader(), AntOutputPanel.class.getName());
293:
294: generalPanel = (AntDeployGeneralPanel) Beans.instantiate(
295: getClass().getClassLoader(),
296: AntDeployGeneralPanel.class.getName());
297:
298: inputPanel = (AntDeployInputPanel) Beans.instantiate(getClass()
299: .getClassLoader(), AntDeployInputPanel.class.getName());
300:
301: contentPanel = (AntDeployContentPanel) Beans.instantiate(
302: getClass().getClassLoader(),
303: AntDeployContentPanel.class.getName());
304:
305: tab = (JTabbedPane) Beans.instantiate(getClass()
306: .getClassLoader(), JTabbedPane.class.getName());
307:
308: this .setLayout(layoutMain);
309: this .setMinimumSize(new Dimension(20, 20));
310: this .setPreferredSize(new Dimension(20, 20));
311: this .add(tab, new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0,
312: GridBagConstraints.WEST, GridBagConstraints.BOTH,
313: new Insets(5, -1, 6, 9), 5, 5));
314: }
315:
316: private class SelectTab implements Runnable {
317: private JTabbedPane tp = null;
318: private JPanel go = null;
319:
320: protected SelectTab(JTabbedPane t, JPanel g) {
321: tp = t;
322: go = g;
323: }
324:
325: synchronized public void run() {
326: tp.setSelectedComponent(go);
327: try {
328: SwingUtilities.windowForComponent(tp).repaint();
329: } catch (NullPointerException e) {
330:
331: // ignore for windows not yet open.
332: }
333: }
334:
335: }
336:
337: }
|