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.xmlc;
024:
025: // ToolBox
026: import org.enhydra.tool.common.InnerPanel;
027: import org.enhydra.tool.common.SwingUtil;
028: import org.enhydra.tool.common.ButtonPanel;
029: import org.enhydra.tool.common.event.FirstFocusEvent;
030: import org.enhydra.tool.common.event.FirstFocusListener;
031:
032: // AddinCore
033: import org.enhydra.kelp.common.AbstractTool;
034: import org.enhydra.kelp.common.event.SelectionPanelEvent;
035: import org.enhydra.kelp.common.event.SelectionPanelListener;
036: import org.enhydra.kelp.common.event.WriteListener;
037: import org.enhydra.kelp.common.node.OtterProject;
038: import org.enhydra.kelp.common.node.OtterFileNode;
039: import org.enhydra.kelp.common.swing.AddinInnerPanel;
040: import org.enhydra.kelp.common.properties.XMLCProjectPropertyPanel;
041:
042: // Standard imports
043: import java.awt.Component;
044: import java.awt.Frame;
045: import java.awt.event.ActionListener;
046: import java.lang.ref.WeakReference;
047: import java.util.ResourceBundle;
048:
049: //
050: public class CoreXMLCTool extends AbstractTool implements
051: SelectionPanelListener, FirstFocusListener {
052: static ResourceBundle addinRes = ResourceBundle
053: .getBundle("org.enhydra.kelp.common.Res"); // nores
054:
055: //
056: private XMLCNodeBuilder nodeBuilder = null;
057: private XMLCProjectPropertyPanel propertyPanel = null;
058: private XMLCInnerPanel innerPanel = null;
059: private XMLCButtonPanel buttonPanel = null;
060: private WeakReference compileRef = null;
061:
062: public static void main(String[] args) {
063: SwingUtil.setLookAndFeelToSystem();
064: CoreXMLCTool tool = null;
065:
066: tool = new CoreXMLCTool();
067: tool.showDialog(new Frame());
068: System.exit(0);
069: }
070:
071: public static final String getDefaultTitle() {
072: return "XML Compiler";
073: }
074:
075: public CoreXMLCTool() {
076: super ();
077: innerPanel = new XMLCInnerPanel();
078: buttonPanel = new XMLCButtonPanel();
079: innerPanel.getSelectionPanel().addSelectionPanelListener(this );
080: innerPanel.setPropertyPanel(getPropertyPanel());
081: innerPanel.setSelectText(getSelectText());
082: innerPanel.addFirstFocusListener(this );
083: }
084:
085: // implements SelectionPanelListener
086: public void onSelection(SelectionPanelEvent event) {
087: boolean enable = event.getSelected().size() > 0;
088:
089: refreshCompile(enable);
090: }
091:
092: // implements AbstractTool
093: public String getTitle() {
094: return CoreXMLCTool.getDefaultTitle();
095: }
096:
097: // implements AbstractTool
098: public InnerPanel getInnerPanel() {
099: return innerPanel;
100: }
101:
102: // implements AbstractTool
103: public ButtonPanel getButtonPanel() {
104: return buttonPanel;
105: }
106:
107: public ActionListener createButtonListener() {
108: return (new XMLCButtonListener(this ));
109: }
110:
111: // overrides AbstractTool
112: public void setProject(OtterProject project) {
113: super .setProject(project);
114: setNodes(project.getAllXMLCNodes());
115: }
116:
117: // overrides AbstractTool
118: public void clearAll() {
119: super .clearAll();
120: innerPanel.removeFirstFocusListener(this );
121: if (compileRef != null) {
122: compileRef.clear();
123: }
124: innerPanel = null;
125: buttonPanel = null;
126: compileRef = null;
127: }
128:
129: public void build() {
130: innerPanel.selectOutputTab();
131: innerPanel.save();
132: innerPanel.clearOutput();
133: openProgress();
134: buildImpl();
135: }
136:
137: // implements FirstFocusListener
138: public void onFirstFocus(FirstFocusEvent event) {
139: refreshCompile();
140: }
141:
142: //
143: // PROTECTED
144: //
145: // implements org.enhydra.kelp.common.tool.AbstractTool
146:
147: /**
148: * Get source files that can be selected for compilation.
149: */
150: protected OtterFileNode[] getNodes() {
151: return innerPanel.getNodes();
152: }
153:
154: /**
155: * Set the source files that can be selected for compilation
156: */
157: protected void setNodes(OtterFileNode[] n) {
158: innerPanel.setNodes(n);
159: refreshCompile();
160: }
161:
162: protected String[] getSelectText() {
163: String[] s = { "Documents Available", "Documents Selected" };
164:
165: return s;
166: }
167:
168: // implements org.enhydra.kelp.common.tool.AbstractTool
169: protected String getBuildText() {
170: return addinRes.getString("buttonMake_Text");
171: }
172:
173: // implements org.enhydra.kelp.common.tool.AbstractTool
174: protected String getProgressTitle() {
175: return addinRes.getString("XMLC_Progress");
176: }
177:
178: // implements org.enhydra.kelp.common.tool.AbstractTool
179: protected AddinInnerPanel getPropertyPanel() {
180: if (propertyPanel == null) {
181: propertyPanel = new XMLCProjectPropertyPanel();
182: }
183: return propertyPanel;
184: }
185:
186: private void buildImpl() {
187: if (nodeBuilder != null) {
188: nodeBuilder.setFresh(false);
189: }
190: nodeBuilder = new XMLCNodeBuilder(innerPanel
191: .getWriteListeners());
192: nodeBuilder.setProject(getProject());
193: nodeBuilder.setNodes(getProject().getAllXMLCNodes());
194: nodeBuilder.addProgressListener(getProgressMeter());
195: getProgressMeter().addCancelListener(nodeBuilder);
196: nodeBuilder.build();
197: }
198:
199: private Component getCompile() {
200: Component comp = null;
201:
202: if (compileRef == null) {
203: comp = ButtonPanel.findButton(getInnerPanel()
204: .getTopLevelAncestor(),
205: XMLCButtonPanel.COMMAND_COMPILE);
206: if (comp != null) {
207: compileRef = new WeakReference(comp);
208: }
209: } else {
210: comp = (Component) compileRef.get();
211: }
212: return comp;
213: }
214:
215: private void refreshCompile() {
216: boolean enable = false;
217: OtterFileNode[] nodes = new OtterFileNode[0];
218:
219: nodes = innerPanel.getNodes();
220: for (int i = 0; i < nodes.length; i++) {
221: if (nodes[i].isSelected()) {
222: enable = true;
223: break;
224: }
225: }
226: refreshCompile(enable);
227: }
228:
229: private void refreshCompile(boolean enable) {
230: Component compileButton = getCompile();
231:
232: if (compileButton != null) {
233: compileButton.setEnabled(enable);
234: }
235: }
236:
237: }
|