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.common.DataValidationException;
027:
028: // AddinCore
029: import org.enhydra.kelp.common.node.OtterNode;
030: import org.enhydra.kelp.common.node.OtterXMLCNode;
031: import org.enhydra.kelp.common.swing.AddinInnerPanel;
032: import org.enhydra.kelp.common.xmlc.MapDialog;
033: import org.enhydra.kelp.common.xmlc.XMLCOptionTab;
034:
035: // JDK
036: import java.awt.*;
037: import java.awt.event.*;
038: import java.beans.*;
039: import java.io.File;
040: import javax.swing.*;
041: import javax.swing.border.*;
042: import javax.swing.event.*;
043: import java.util.ResourceBundle;
044:
045: //
046: public class XMLCNodePropertyPanel extends AddinInnerPanel {
047: static ResourceBundle res = ResourceBundle
048: .getBundle("org.enhydra.kelp.common.Res"); // nores
049: private GridBagLayout layoutMain;
050: private JCheckBox checkCompile;
051: private JTextField textClassName;
052: private JPanel panelClassName;
053: private GridBagLayout layoutClassName;
054: private JRadioButton radioDefault;
055: private JRadioButton radioCustom;
056: private JRadioButton radioMap;
057: private JButton buttonMap;
058: private XMLCOptionTab optionTab;
059: private TitledBorder borderClassName;
060: private ButtonGroup radioGroup;
061: private JCheckBox checkStatic;
062: private LocalButtonListener buttonListener;
063: private LocalCheckListener checkListener;
064: private LocalRadioListener radioListener;
065:
066: /**
067: * Constructor declaration
068: *
069: *
070: */
071: public XMLCNodePropertyPanel() {
072: super ();
073: try {
074: jbInit();
075: pmInit();
076: } catch (Exception e) {
077: e.printStackTrace();
078: }
079: }
080:
081: // override AddinInnerPanel
082: public void read(OtterNode node) {
083: super .read(node);
084: OtterXMLCNode xmlcNode = null;
085: boolean b = false;
086: String s = new String();
087:
088: xmlcNode = getXMLCNode();
089: optionTab.setNode(xmlcNode);
090: optionTab.init();
091: optionTab.readProperties();
092: b = xmlcNode.isSelected();
093: checkCompile.setSelected(b);
094: if (b) {
095: checkStatic.setSelected(false);
096: } else {
097: b = xmlcNode.isStatic();
098: checkStatic.setSelected(b);
099: }
100: switch (xmlcNode.getClassNameType()) {
101: case OtterXMLCNode.CLASS_NAME_CUSTOM:
102: radioCustom.setSelected(true);
103: break;
104: case OtterXMLCNode.CLASS_NAME_MAPPED:
105: radioMap.setSelected(true);
106: break;
107: default:
108: radioDefault.setSelected(true);
109: break;
110: }
111: s = xmlcNode.getMetaDataHandler().getClassName();
112: textClassName.setText(s);
113: enableCompileOptions(checkCompile.isSelected()
114: && (!checkStatic.isSelected()));
115: refreshClassName();
116: }
117:
118: // override AddinInnerPanel
119: public void write(OtterNode node) throws DataValidationException {
120: super .write(node);
121: OtterXMLCNode xmlcNode = null;
122:
123: xmlcNode = getXMLCNode();
124: optionTab.writeProperties();
125: boolean b = checkCompile.isSelected();
126:
127: xmlcNode.setSelected(b);
128: if (b) {
129: xmlcNode.setStatic(false);
130: } else {
131: b = checkStatic.isSelected();
132: xmlcNode.setStatic(b);
133: }
134: String customClassName = textClassName.getText();
135:
136: xmlcNode.setCustomClassName(customClassName);
137: if (radioCustom.isSelected()) {
138: xmlcNode.setClassNameType(OtterXMLCNode.CLASS_NAME_CUSTOM);
139: } else if (radioDefault.isSelected()) {
140: xmlcNode.setClassNameType(OtterXMLCNode.CLASS_NAME_DEFAULT);
141: } else {
142: xmlcNode.setClassNameType(OtterXMLCNode.CLASS_NAME_MAPPED);
143: }
144: }
145:
146: // override AddinInnerPanel
147: public Component[] getFirstFocusComponents() {
148: Component[] comps = new Component[9];
149:
150: comps[0] = checkCompile;
151: comps[1] = textClassName;
152: comps[2] = panelClassName;
153: comps[3] = radioDefault;
154: comps[4] = radioCustom;
155: comps[5] = radioMap;
156: comps[6] = buttonMap;
157: comps[7] = optionTab;
158: comps[8] = checkStatic;
159: return comps;
160: }
161:
162: //
163: // PRIVATE
164: //
165:
166: /**
167: * Method declaration
168: *
169: *
170: * @exception Exception
171: */
172: private void pmInit() throws Exception {
173: radioGroup = (ButtonGroup) Beans.instantiate(getClass()
174: .getClassLoader(), ButtonGroup.class.getName());
175: radioGroup.add(radioDefault);
176: radioGroup.add(radioCustom);
177: radioGroup.add(radioMap);
178: refreshClassName();
179: radioListener = new LocalRadioListener();
180: radioDefault.addActionListener(radioListener);
181: radioCustom.addActionListener(radioListener);
182: radioMap.addActionListener(radioListener);
183:
184: //
185: buttonListener = new LocalButtonListener();
186: buttonMap.addActionListener(buttonListener);
187:
188: //
189: checkListener = new LocalCheckListener();
190: checkCompile.addActionListener(checkListener);
191: checkStatic.addActionListener(checkListener);
192: }
193:
194: /**
195: * Method declaration
196: *
197: *
198: * @exception Exception
199: */
200: private void jbInit() throws Exception {
201: checkCompile = (JCheckBox) Beans.instantiate(getClass()
202: .getClassLoader(), JCheckBox.class.getName());
203: textClassName = (JTextField) Beans.instantiate(getClass()
204: .getClassLoader(), JTextField.class.getName());
205: layoutMain = (GridBagLayout) Beans.instantiate(getClass()
206: .getClassLoader(), GridBagLayout.class.getName());
207: panelClassName = (JPanel) Beans.instantiate(getClass()
208: .getClassLoader(), JPanel.class.getName());
209: layoutClassName = (GridBagLayout) Beans.instantiate(getClass()
210: .getClassLoader(), GridBagLayout.class.getName());
211: radioDefault = (JRadioButton) Beans.instantiate(getClass()
212: .getClassLoader(), JRadioButton.class.getName());
213: radioCustom = (JRadioButton) Beans.instantiate(getClass()
214: .getClassLoader(), JRadioButton.class.getName());
215: radioMap = (JRadioButton) Beans.instantiate(getClass()
216: .getClassLoader(), JRadioButton.class.getName());
217: buttonMap = (JButton) Beans.instantiate(getClass()
218: .getClassLoader(), JButton.class.getName());
219: optionTab = (XMLCOptionTab) Beans.instantiate(getClass()
220: .getClassLoader(), XMLCOptionTab.class.getName());
221: checkStatic = (JCheckBox) Beans.instantiate(getClass()
222: .getClassLoader(), JCheckBox.class.getName());
223: checkCompile.setText(res.getString("checkCompile_Text"));
224: optionTab.setLayout(optionTab.getLayout());
225: panelClassName.setLayout(layoutClassName);
226: borderClassName = BorderFactory.createTitledBorder(res
227: .getString("Generated_class_name"));
228: panelClassName.setBorder(borderClassName);
229: radioDefault.setSelected(true);
230: radioDefault.setText(res.getString("Default"));
231: radioCustom.setText(res.getString("Custom"));
232: radioMap.setText(res.getString("radioMap_Text"));
233: buttonMap.setText(res.getString("buttonMap_Text"));
234: checkStatic.setText(res.getString("checkStatic_Text"));
235: panelClassName.add(textClassName, new GridBagConstraints(0, 1,
236: 4, GridBagConstraints.REMAINDER, 1.0, 1.0,
237: GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
238: new Insets(5, 5, 5, 5), 0, 0));
239: panelClassName.add(radioCustom, new GridBagConstraints(1, 0, 1,
240: 1, 0.0, 0.0, GridBagConstraints.CENTER,
241: GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
242: panelClassName.add(radioMap, new GridBagConstraints(2, 0, 1, 1,
243: 0.0, 0.0, GridBagConstraints.CENTER,
244: GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
245: panelClassName.add(radioDefault, new GridBagConstraints(0, 0,
246: 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
247: GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
248: panelClassName.add(buttonMap, new GridBagConstraints(3, 0, 1,
249: 1, 0.0, 0.0, GridBagConstraints.CENTER,
250: GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
251: this .setLayout(layoutMain);
252: this .add(checkCompile, new GridBagConstraints(0, 1, 1, 1, 0.1,
253: 0.1, GridBagConstraints.WEST,
254: GridBagConstraints.HORIZONTAL, new Insets(2, 5, 5, 5),
255: 0, 0));
256: this .add(panelClassName, new GridBagConstraints(0, 3, 1, 1,
257: 0.1, 0.1, GridBagConstraints.CENTER,
258: GridBagConstraints.HORIZONTAL, new Insets(3, 15, 3, 5),
259: 0, 0));
260: this .add(optionTab, new GridBagConstraints(0, 4, 1, 1, 0.1,
261: 0.1, GridBagConstraints.CENTER,
262: GridBagConstraints.HORIZONTAL, new Insets(3, 15, 5, 5),
263: 0, 0));
264: this .add(checkStatic, new GridBagConstraints(0, 0, 1, 1, 0.1,
265: 0.1, GridBagConstraints.WEST,
266: GridBagConstraints.HORIZONTAL, new Insets(5, 5, 2, 5),
267: 0, 0));
268: }
269:
270: private void enableCompileOptions(boolean enable) {
271: radioDefault.setEnabled(enable);
272: radioCustom.setEnabled(enable);
273: radioMap.setEnabled(enable);
274: textClassName.setEnabled(enable && radioCustom.isSelected());
275: if (textClassName.isEnabled()) {
276: textClassName.setBackground(SystemColor.info);
277: } else {
278: textClassName.setBackground(SystemColor.control);
279: }
280: buttonMap.setEnabled(enable);
281: optionTab.setEnabled(enable);
282: }
283:
284: private void refreshClassName() {
285: textClassName.setEnabled(radioCustom.isSelected());
286: if (textClassName.isEnabled()) {
287: textClassName.setBackground(SystemColor.info);
288: } else {
289: textClassName.setBackground(SystemColor.control);
290: }
291: if (getXMLCNode() != null) {
292: String className = new String();
293:
294: save();
295: className = getXMLCNode().getMetaDataHandler()
296: .getClassName();
297: textClassName.setText(className);
298: }
299: buttonMap.setEnabled(radioMap.isSelected());
300: }
301:
302: private OtterXMLCNode getXMLCNode() {
303: OtterXMLCNode xmlcNode = null;
304: OtterNode node = getNode();
305:
306: if (node instanceof OtterXMLCNode) {
307: xmlcNode = (OtterXMLCNode) node;
308: }
309: return xmlcNode;
310: }
311:
312: private void editMap() {
313: MapDialog dialog = null;
314: String t = res.getString("Edit_Project_Map");
315:
316: dialog = new MapDialog(((JDialog) this .getTopLevelAncestor()),
317: t, true);
318: dialog.setProject(getProject());
319: dialog.show();
320: }
321:
322: private class LocalButtonListener implements ActionListener {
323: public void actionPerformed(ActionEvent e) {
324: Object source = e.getSource();
325:
326: if (source == buttonMap) {
327: editMap();
328: refreshClassName();
329: }
330: }
331:
332: }
333:
334: //
335: private class LocalRadioListener implements ActionListener {
336: public void actionPerformed(ActionEvent e) {
337: JRadioButton source = (JRadioButton) e.getSource();
338:
339: if (source.isSelected()) {
340: refreshClassName();
341: }
342: }
343:
344: }
345:
346: //
347: private class LocalCheckListener implements ActionListener {
348: public void actionPerformed(ActionEvent e) {
349: Object source = null;
350:
351: source = e.getSource();
352: if (source == checkCompile && checkCompile.isSelected()) {
353: checkStatic.setSelected(false);
354: } else if (source == checkStatic
355: && checkStatic.isSelected()) {
356: checkCompile.setSelected(false);
357: }
358: enableCompileOptions(checkCompile.isSelected()
359: && (!checkStatic.isSelected()));
360: }
361:
362: }
363: }
|