KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > kelp > common > xmlc > CoreXMLCTool


1 /*
2  * Enhydra Java Application Server Project
3  *
4  * The contents of this file are subject to the Enhydra Public License
5  * Version 1.1 (the "License"); you may not use this file except in
6  * compliance with the License. You may obtain a copy of the License on
7  * the Enhydra web site ( http://www.enhydra.org/ ).
8  *
9  * Software distributed under the License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
11  * the License for the specific terms governing rights and limitations
12  * under the License.
13  *
14  * The Initial Developer of the Enhydra Application Server is Lutris
15  * Technologies, Inc. The Enhydra Application Server and portions created
16  * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
17  * All Rights Reserved.
18  *
19  * Contributor(s):
20  * Paul Mahar
21  *
22  */

23 package org.enhydra.kelp.common.xmlc;
24
25 // ToolBox
26
import org.enhydra.tool.common.InnerPanel;
27 import org.enhydra.tool.common.SwingUtil;
28 import org.enhydra.tool.common.ButtonPanel;
29 import org.enhydra.tool.common.event.FirstFocusEvent;
30 import org.enhydra.tool.common.event.FirstFocusListener;
31
32 // AddinCore
33
import org.enhydra.kelp.common.AbstractTool;
34 import org.enhydra.kelp.common.event.SelectionPanelEvent;
35 import org.enhydra.kelp.common.event.SelectionPanelListener;
36 import org.enhydra.kelp.common.event.WriteListener;
37 import org.enhydra.kelp.common.node.OtterProject;
38 import org.enhydra.kelp.common.node.OtterFileNode;
39 import org.enhydra.kelp.common.swing.AddinInnerPanel;
40 import org.enhydra.kelp.common.properties.XMLCProjectPropertyPanel;
41
42 // Standard imports
43
import java.awt.Component JavaDoc;
44 import java.awt.Frame JavaDoc;
45 import java.awt.event.ActionListener JavaDoc;
46 import java.lang.ref.WeakReference JavaDoc;
47 import java.util.ResourceBundle JavaDoc;
48
49 //
50
public class CoreXMLCTool extends AbstractTool
51     implements SelectionPanelListener, FirstFocusListener {
52     static ResourceBundle JavaDoc addinRes =
53         ResourceBundle.getBundle("org.enhydra.kelp.common.Res"); // nores
54

55     //
56
private XMLCNodeBuilder nodeBuilder = null;
57     private XMLCProjectPropertyPanel propertyPanel = null;
58     private XMLCInnerPanel innerPanel = null;
59     private XMLCButtonPanel buttonPanel = null;
60     private WeakReference JavaDoc compileRef = null;
61
62     public static void main(String JavaDoc[] args) {
63         SwingUtil.setLookAndFeelToSystem();
64         CoreXMLCTool tool = null;
65
66         tool = new CoreXMLCTool();
67         tool.showDialog(new Frame JavaDoc());
68         System.exit(0);
69     }
70
71     public static final String JavaDoc getDefaultTitle() {
72         return "XML Compiler";
73     }
74
75     public CoreXMLCTool() {
76         super();
77         innerPanel = new XMLCInnerPanel();
78         buttonPanel = new XMLCButtonPanel();
79         innerPanel.getSelectionPanel().addSelectionPanelListener(this);
80         innerPanel.setPropertyPanel(getPropertyPanel());
81         innerPanel.setSelectText(getSelectText());
82         innerPanel.addFirstFocusListener(this);
83     }
84
85     // implements SelectionPanelListener
86
public void onSelection(SelectionPanelEvent event) {
87         boolean enable = event.getSelected().size() > 0;
88
89         refreshCompile(enable);
90     }
91
92     // implements AbstractTool
93
public String JavaDoc getTitle() {
94         return CoreXMLCTool.getDefaultTitle();
95     }
96
97     // implements AbstractTool
98
public InnerPanel getInnerPanel() {
99         return innerPanel;
100     }
101
102     // implements AbstractTool
103
public ButtonPanel getButtonPanel() {
104         return buttonPanel;
105     }
106
107     public ActionListener JavaDoc 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 JavaDoc[] getSelectText() {
163         String JavaDoc[] s = {
164             "Documents Available", "Documents Selected"
165         };
166
167         return s;
168     }
169
170     // implements org.enhydra.kelp.common.tool.AbstractTool
171
protected String JavaDoc getBuildText() {
172         return addinRes.getString("buttonMake_Text");
173     }
174
175     // implements org.enhydra.kelp.common.tool.AbstractTool
176
protected String JavaDoc getProgressTitle() {
177         return addinRes.getString("XMLC_Progress");
178     }
179
180     // implements org.enhydra.kelp.common.tool.AbstractTool
181
protected AddinInnerPanel getPropertyPanel() {
182         if (propertyPanel == null) {
183             propertyPanel = new XMLCProjectPropertyPanel();
184         }
185         return propertyPanel;
186     }
187
188     private void buildImpl() {
189         if (nodeBuilder != null) {
190             nodeBuilder.setFresh(false);
191         }
192         nodeBuilder = new XMLCNodeBuilder(innerPanel.getWriteListeners());
193         nodeBuilder.setProject(getProject());
194         nodeBuilder.setNodes(getProject().getAllXMLCNodes());
195         nodeBuilder.addProgressListener(getProgressMeter());
196         getProgressMeter().addCancelListener(nodeBuilder);
197         nodeBuilder.build();
198     }
199
200     private Component JavaDoc getCompile() {
201         Component JavaDoc comp = null;
202
203         if (compileRef == null) {
204             comp =
205                 ButtonPanel.findButton(getInnerPanel().getTopLevelAncestor(),
206                                        XMLCButtonPanel.COMMAND_COMPILE);
207             if (comp != null) {
208                 compileRef = new WeakReference JavaDoc(comp);
209             }
210         } else {
211             comp = (Component JavaDoc) compileRef.get();
212         }
213         return comp;
214     }
215
216     private void refreshCompile() {
217         boolean enable = false;
218         OtterFileNode[] nodes = new OtterFileNode[0];
219
220         nodes = innerPanel.getNodes();
221         for (int i = 0; i < nodes.length; i++) {
222             if (nodes[i].isSelected()) {
223                 enable = true;
224                 break;
225             }
226         }
227         refreshCompile(enable);
228     }
229
230     private void refreshCompile(boolean enable) {
231         Component JavaDoc compileButton = getCompile();
232
233         if (compileButton != null) {
234             compileButton.setEnabled(enable);
235         }
236     }
237
238 }
239
Popular Tags