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.properties;
024:
025: // ToolBox
026: import org.enhydra.tool.ToolBoxInfo;
027: import org.enhydra.tool.common.DataValidationException;
028:
029: // AddinCore
030: import org.enhydra.kelp.common.event.ExtensionChangeEvent;
031: import org.enhydra.kelp.common.event.ExtensionChangeListener;
032: import org.enhydra.kelp.common.node.OtterProject;
033: import org.enhydra.kelp.common.node.OtterNode;
034: import org.enhydra.kelp.common.swing.AddinInnerPanel;
035: import org.enhydra.kelp.common.swing.ExtensionPanel;
036: import org.enhydra.kelp.common.xmlc.XMLCOptionPanel;
037: import org.enhydra.kelp.common.xmlc.XMLCInnerPanel;
038: import org.enhydra.kelp.common.xmlc.MapDialog;
039:
040: // JDK
041: import javax.swing.*;
042: import javax.swing.border.*;
043: import java.awt.*;
044: import java.awt.event.*;
045: import java.beans.*;
046: import java.io.File;
047: import java.util.ResourceBundle;
048:
049: //
050: public class XMLCProjectPropertyPanel extends AddinInnerPanel implements
051: ExtensionChangeListener {
052:
053: // strings OK to resource
054: static ResourceBundle res = ResourceBundle
055: .getBundle("org.enhydra.kelp.common.Res"); // nores
056: private final String mapAll = res.getString("All");
057: private final String mapSelected = res.getString("Selected");
058: private final String mapNone = res.getString("None");
059:
060: //
061: private boolean active = false;
062: private GridBagLayout layoutCompile;
063: private TitledBorder borderMappings;
064: private JPanel panelMappings;
065: private GridBagLayout layoutMap;
066: private JButton buttonMap;
067: private JPanel panelTrace;
068: private GridBagLayout layoutTrace;
069: private JCheckBox checkPrintParseInfo;
070: private JCheckBox checkPrintAccessorInfo;
071: private JCheckBox checkPrintDocumentInfo;
072: private JCheckBox checkPrintDOM;
073: private JCheckBox checkVerbose;
074: private JComboBox comboMap;
075: private JLabel labelMap;
076: private ExtensionPanel extensionPanel;
077: private XMLCOptionPanel optionPanel;
078: private JPanel panelMake;
079: private JCheckBox checkBuild;
080: private GridBagLayout layoutMake;
081: private JTabbedPane tabPane;
082: private JPanel panelCompile;
083: private BorderLayout layoutMain;
084: private LocalButtonListener buttonListener = null;
085:
086: /**
087: * Constructor declaration
088: *
089: */
090: public XMLCProjectPropertyPanel() {
091: try {
092: jbInit();
093: pmInit();
094: } catch (Exception e) {
095: e.printStackTrace();
096: }
097: }
098:
099: // ExtensionChangeListener
100: public void onChange(ExtensionChangeEvent event) {
101: XMLCInnerPanel innerPanel = null;
102:
103: innerPanel = XMLCInnerPanel.XMLCfindAncestor(this );
104: if (innerPanel == null) {
105:
106: // nothing to refresh;
107: } else {
108: getProject().setDocTypes(event.getExtensions());
109: innerPanel.getSelectionPanel().setNodes(
110: getProject().getAllDocuments());
111: }
112: }
113:
114: // override AddinInnerPanel
115: public void read(OtterNode node) {
116: super .read(node);
117: OtterProject project = null;
118:
119: project = getProject();
120: optionPanel.setNode(project);
121: optionPanel.readProperties();
122: if (comboMap.getItemCount() > 0) {
123: comboMap.removeAllItems();
124: }
125: if (project.isOpenBuild()) {
126:
127: // Primetime
128: checkBuild.setEnabled(true);
129: checkBuild.setSelected(project.isXMLCBuild());
130: comboMap.addItem(mapAll);
131: comboMap.addItem(mapSelected);
132: comboMap.addItem(mapNone);
133: int vScope = project.getVerifiedMapScope();
134:
135: switch (vScope) {
136: case OtterProject.MAP_SCOPE_NONE:
137: comboMap.setSelectedItem(mapNone);
138: break;
139: case OtterProject.MAP_SCOPE_SELECTED:
140: comboMap.setSelectedItem(mapSelected);
141: break;
142: default:
143: project.setMapScope(OtterProject.MAP_SCOPE_ALL);
144: comboMap.setSelectedItem(mapAll);
145: break;
146: }
147: } else {
148:
149: // Win32 and JDeveloper
150: checkBuild.setEnabled(false);
151: checkBuild.setSelected(false);
152: comboMap.addItem(mapAll);
153: comboMap.addItem(mapNone);
154: if (project.getMapScope() == OtterProject.MAP_SCOPE_NONE) {
155: comboMap.setSelectedItem(mapNone);
156: } else {
157: comboMap.setSelectedItem(mapAll);
158: project.setMapScope(OtterProject.MAP_SCOPE_ALL);
159: }
160: }
161: checkPrintDOM.setSelected(project.isPrintDOM());
162: checkPrintParseInfo.setSelected(project.isPrintParseInfo());
163: checkPrintAccessorInfo.setSelected(project
164: .isPrintAccessorInfo());
165: checkPrintDocumentInfo.setSelected(project
166: .isPrintDocumentInfo());
167: checkVerbose.setSelected(project.isVerbose());
168: extensionPanel.setExtensions(project.getDocTypes());
169: extensionPanel.setDefaults(ToolBoxInfo.getSupportedDocTypes());
170: active = true;
171: }
172:
173: // override AddinInnerPanel
174: public void write(OtterNode node) throws DataValidationException {
175: super .write(node);
176: String item = null;
177: OtterProject project = null;
178:
179: project = getProject();
180: item = comboMap.getSelectedItem().toString().trim();
181: optionPanel.writeProperties();
182: if (project != null && active) {
183: if (item.equalsIgnoreCase(mapAll)) {
184: project.setMapScope(OtterProject.MAP_SCOPE_ALL);
185: } else if (item.equalsIgnoreCase(mapSelected)) {
186: project.setMapScope(OtterProject.MAP_SCOPE_SELECTED);
187: } else if (item.equalsIgnoreCase(mapNone)) {
188: project.setMapScope(OtterProject.MAP_SCOPE_NONE);
189: }
190: }
191: if (project.isOpenBuild()) {
192: // Primetime
193: project.setXMLCBuild(checkBuild.isSelected());
194: } else {
195:
196: // Win32 and JDeveloper
197: project.setXMLCBuild(false);
198: }
199: project.setPrintDOM(checkPrintDOM.isSelected());
200: project.setPrintParseInfo(checkPrintParseInfo.isSelected());
201: project.setPrintAccessorInfo(checkPrintAccessorInfo
202: .isSelected());
203: project.setPrintDocumentInfo(checkPrintDocumentInfo
204: .isSelected());
205: project.setVerbose(checkVerbose.isSelected());
206: project.setDocTypes(extensionPanel.getExtensions());
207: }
208:
209: // override AddinInnerPanel
210: public Component[] getFirstFocusComponents() {
211: Component[] comps = new Component[14];
212:
213: comps[0] = panelMappings;
214: comps[1] = buttonMap;
215: comps[2] = checkPrintParseInfo;
216: comps[3] = checkPrintAccessorInfo;
217: comps[4] = checkPrintDocumentInfo;
218: comps[5] = checkPrintDOM;
219: comps[6] = checkVerbose;
220: comps[7] = comboMap;
221: comps[8] = extensionPanel;
222: comps[9] = optionPanel;
223: comps[10] = panelMake;
224: comps[11] = checkBuild;
225: comps[12] = tabPane;
226: comps[13] = panelCompile;
227: return comps;
228: }
229:
230: /**
231: * Method declaration
232: *
233: */
234: private void pmInit() {
235: buttonListener = new LocalButtonListener();
236: buttonMap.addActionListener(buttonListener);
237: extensionPanel.addListener(this );
238: }
239:
240: /**
241: * Method declaration
242: *
243: *
244: * @throws Exception
245: */
246: private void jbInit() throws Exception {
247: layoutCompile = (GridBagLayout) Beans.instantiate(getClass()
248: .getClassLoader(), GridBagLayout.class.getName());
249: extensionPanel = (ExtensionPanel) Beans.instantiate(getClass()
250: .getClassLoader(), ExtensionPanel.class.getName());
251: optionPanel = (XMLCOptionPanel) Beans.instantiate(getClass()
252: .getClassLoader(), XMLCOptionPanel.class.getName());
253: borderMappings = new TitledBorder(new String());
254: panelMappings = (JPanel) Beans.instantiate(getClass()
255: .getClassLoader(), JPanel.class.getName());
256: layoutMap = (GridBagLayout) Beans.instantiate(getClass()
257: .getClassLoader(), GridBagLayout.class.getName());
258: buttonMap = (JButton) Beans.instantiate(getClass()
259: .getClassLoader(), JButton.class.getName());
260: panelTrace = (JPanel) Beans.instantiate(getClass()
261: .getClassLoader(), JPanel.class.getName());
262: layoutTrace = (GridBagLayout) Beans.instantiate(getClass()
263: .getClassLoader(), GridBagLayout.class.getName());
264: checkPrintParseInfo = (JCheckBox) Beans.instantiate(getClass()
265: .getClassLoader(), JCheckBox.class.getName());
266: checkPrintAccessorInfo = (JCheckBox) Beans.instantiate(
267: getClass().getClassLoader(), JCheckBox.class.getName());
268: checkPrintDocumentInfo = (JCheckBox) Beans.instantiate(
269: getClass().getClassLoader(), JCheckBox.class.getName());
270: checkPrintDOM = (JCheckBox) Beans.instantiate(getClass()
271: .getClassLoader(), JCheckBox.class.getName());
272: checkVerbose = (JCheckBox) Beans.instantiate(getClass()
273: .getClassLoader(), JCheckBox.class.getName());
274: comboMap = (JComboBox) Beans.instantiate(getClass()
275: .getClassLoader(), JComboBox.class.getName());
276: labelMap = (JLabel) Beans.instantiate(getClass()
277: .getClassLoader(), JLabel.class.getName());
278: panelMake = (JPanel) Beans.instantiate(getClass()
279: .getClassLoader(), JPanel.class.getName());
280: checkBuild = (JCheckBox) Beans.instantiate(getClass()
281: .getClassLoader(), JCheckBox.class.getName());
282: layoutMake = (GridBagLayout) Beans.instantiate(getClass()
283: .getClassLoader(), GridBagLayout.class.getName());
284: tabPane = (JTabbedPane) Beans.instantiate(getClass()
285: .getClassLoader(), JTabbedPane.class.getName());
286: panelCompile = (JPanel) Beans.instantiate(getClass()
287: .getClassLoader(), JPanel.class.getName());
288: layoutMain = (BorderLayout) Beans.instantiate(getClass()
289: .getClassLoader(), BorderLayout.class.getName());
290: borderMappings.setTitle(res.getString("borderMappings_Title"));
291: panelMappings.setBorder(borderMappings);
292: panelTrace.setLayout(layoutTrace);
293: panelMappings.setLayout(layoutMap);
294: buttonMap.setText(res.getString("buttonMap_Text"));
295: checkPrintParseInfo.setText(res
296: .getString("checkPrintParseInfo_Text"));
297: checkPrintDocumentInfo.setText(res
298: .getString("checkPrintDocumentInfo_Text"));
299: checkPrintDOM.setText(res.getString("checkPrintDOM_Text"));
300: checkVerbose.setText(res.getString("checkVerbose_Text"));
301: checkPrintAccessorInfo.setText(res
302: .getString("checkPrintAccessorInfo_Text"));
303: labelMap.setHorizontalAlignment(SwingConstants.RIGHT);
304: labelMap.setText(res.getString("labelMap_Text"));
305: checkBuild.setEnabled(false);
306: checkBuild.setText(res.getString("checkBuild_Text"));
307: panelMake.setLayout(layoutMake);
308: panelMake.add(checkBuild, new GridBagConstraints(0, 0, 1, 1,
309: 0.1, 0.1, GridBagConstraints.CENTER,
310: GridBagConstraints.HORIZONTAL, new Insets(2, 2, 2, 2),
311: 0, 0));
312: panelMappings.add(buttonMap, new GridBagConstraints(2, 0, 1, 1,
313: 0.0, 0.0, GridBagConstraints.CENTER,
314: GridBagConstraints.NONE, new Insets(2, 2, 1, 2), 0, 0));
315: panelMappings.add(comboMap, new GridBagConstraints(1, 0, 1, 1,
316: 0.2, 0.2, GridBagConstraints.CENTER,
317: GridBagConstraints.HORIZONTAL, new Insets(2, 2, 1, 2),
318: 0, 0));
319: panelMappings.add(labelMap, new GridBagConstraints(0, 0, 1, 1,
320: 0.2, 0.2, GridBagConstraints.EAST,
321: GridBagConstraints.HORIZONTAL, new Insets(2, 2, 1, 2),
322: 0, 0));
323: panelCompile.setLayout(layoutCompile);
324: panelCompile.add(panelMappings, new GridBagConstraints(0, 2, 1,
325: 1, 0.0, 0.0, GridBagConstraints.CENTER,
326: GridBagConstraints.HORIZONTAL, new Insets(2, 2, 2, 0),
327: 5, 5));
328: panelCompile.add(optionPanel, new GridBagConstraints(0, 3, 1,
329: 1, 0.1, 0.1, GridBagConstraints.CENTER,
330: GridBagConstraints.HORIZONTAL, new Insets(1, 2, 2, 2),
331: 0, 0));
332: panelTrace.add(checkPrintDocumentInfo, new GridBagConstraints(
333: 1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST,
334: GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0),
335: 0, 0));
336: panelTrace.add(checkPrintParseInfo, new GridBagConstraints(1,
337: 1, 1, 1, 0.0, 0.0, GridBagConstraints.WEST,
338: GridBagConstraints.HORIZONTAL, new Insets(2, 2, 2, 2),
339: 5, 0));
340: panelTrace.add(checkPrintDOM, new GridBagConstraints(0, 2, 1,
341: 1, 0.0, 0.0, GridBagConstraints.WEST,
342: GridBagConstraints.HORIZONTAL, new Insets(2, 2, 2, 2),
343: 5, 0));
344: panelTrace.add(checkVerbose, new GridBagConstraints(0, 1, 1, 1,
345: 0.0, 0.0, GridBagConstraints.CENTER,
346: GridBagConstraints.NONE, new Insets(2, 2, 2, 2), 5, 0));
347: panelTrace.add(checkPrintAccessorInfo, new GridBagConstraints(
348: 0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST,
349: GridBagConstraints.HORIZONTAL, new Insets(2, 2, 2, 2),
350: 5, 0));
351: tabPane.add(panelCompile, res.getString("Compile"));
352: tabPane.add(extensionPanel, res.getString("XMLC_Types"));
353: tabPane.add(panelTrace, res.getString("Trace"));
354: this .setLayout(layoutMain);
355: this .add(tabPane, BorderLayout.CENTER);
356: this .add(panelMake, BorderLayout.NORTH);
357: }
358:
359: /**
360: * Method declaration
361: *
362: */
363: private void editProjectMap() {
364: MapDialog dialog = new MapDialog(((JDialog) this
365: .getTopLevelAncestor()), res
366: .getString("Edit_Project_Map"), true);
367:
368: dialog.setProject(getProject());
369: dialog.show();
370: }
371:
372: private class LocalButtonListener implements ActionListener {
373: public void actionPerformed(ActionEvent event) {
374: Object source = event.getSource();
375:
376: if (source == buttonMap) {
377: editProjectMap();
378: }
379: }
380:
381: }
382: }
|