001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: /*
042: * ExportDataSourcesDialog.java
043: *
044: * Created on March 8, 2004, 12:09 PM
045: */
046:
047: package org.netbeans.modules.visualweb.ejb.ui;
048:
049: import org.netbeans.modules.visualweb.ejb.datamodel.EjbGroup;
050: import org.netbeans.modules.visualweb.ejb.datamodel.MethodInfo;
051: import java.awt.Component;
052: import java.util.Enumeration;
053: import javax.swing.*;
054: import javax.swing.event.TreeSelectionEvent;
055: import javax.swing.event.TreeSelectionListener;
056: import javax.swing.tree.DefaultMutableTreeNode;
057: import javax.swing.tree.DefaultTreeCellRenderer;
058: import javax.swing.tree.DefaultTreeModel;
059: import javax.swing.tree.TreeNode;
060: import javax.swing.tree.TreePath;
061: import javax.swing.tree.TreeSelectionModel;
062: import org.openide.util.NbBundle;
063: import org.openide.util.Utilities;
064:
065: /**
066: * A panle to allow the user to configure the EJB business methods
067: *
068: * @author dongmei cao
069: */
070: public class ConfigureMethodsPanel extends JPanel {
071:
072: private EjbGroup ejbGroup;
073: private MethodDetailPanel methodDetailPanel;
074:
075: public ConfigureMethodsPanel(EjbGroup ejbGrp) {
076:
077: initComponents();
078:
079: setName(NbBundle.getMessage(ConfigureMethodsPanel.class,
080: "CONFIGURE_METHODS"));
081:
082: // Have the cell renderer to display nice icons
083: methodTree.setCellRenderer(new DefaultTreeCellRenderer() {
084: public Component getTreeCellRendererComponent(JTree tree,
085: Object value, boolean sel, boolean expanded,
086: boolean leaf, int row, boolean hasFocus) {
087:
088: super .getTreeCellRendererComponent(tree, value, sel,
089: expanded, leaf, row, hasFocus);
090:
091: if (value instanceof EjbGroupTreeNodes.MethodNode) {
092: // Method node
093: MethodInfo method = ((EjbGroupTreeNodes.MethodNode) value)
094: .getMethod();
095: if (method.getReturnType().isCollection()
096: && method.getReturnType()
097: .getElemClassName() == null)
098: // Show the warning icon to indicate to the user that extra info needed
099: setIcon(new ImageIcon(
100: Utilities
101: .loadImage("org/netbeans/modules/visualweb/ejb/resources/warning.png")));
102: else
103: setIcon(new ImageIcon(
104: Utilities
105: .loadImage("org/netbeans/modules/visualweb/ejb/resources/methodPublic.gif")));
106: } else {
107: // Must be session ejb node
108: setIcon(new ImageIcon(
109: Utilities
110: .loadImage("org/netbeans/modules/visualweb/ejb/resources/session_bean.png")));
111: }
112:
113: return this ;
114: }
115: });
116:
117: this .ejbGroup = ejbGrp;
118:
119: setEjbGroup(ejbGrp);
120: }
121:
122: public void setEjbGroup(EjbGroup ejbGrp) {
123: this .ejbGroup = ejbGrp;
124:
125: EjbGroupTreeNodes nodes = new EjbGroupTreeNodes(ejbGroup);
126: DefaultTreeModel treeModel = new DefaultTreeModel(nodes
127: .getRoot());
128: methodTree.setModel(treeModel);
129: methodTree.getSelectionModel().setSelectionMode(
130: TreeSelectionModel.SINGLE_TREE_SELECTION);
131:
132: // By default, expand all the nodes
133: expandAll(true);
134:
135: // Programatically select a node
136: if (nodes.geFirstNodeToBeSelected() != null) {
137: methodTree.setSelectionPath(new TreePath(nodes
138: .geFirstNodeToBeSelected().getPath()));
139: methodDetailPanel = new MethodDetailPanel(ejbGroup, nodes
140: .geFirstNodeToBeSelected().getMethod());
141: } else {
142: methodDetailPanel = new MethodDetailPanel(ejbGroup, null);
143: }
144:
145: methodPanel.add(methodDetailPanel);
146:
147: methodTree
148: .addTreeSelectionListener(new TreeSelectionListener() {
149: public void valueChanged(TreeSelectionEvent e) {
150: DefaultMutableTreeNode node = (DefaultMutableTreeNode) methodTree
151: .getLastSelectedPathComponent();
152:
153: if (node == null
154: || e.getOldLeadSelectionPath() == null)
155: return;
156:
157: // Set the element class and parameter name modification for the previous selection
158: DefaultMutableTreeNode prevNode = (DefaultMutableTreeNode) e
159: .getOldLeadSelectionPath()
160: .getLastPathComponent();
161: if (prevNode instanceof EjbGroupTreeNodes.MethodNode) {
162: MethodInfo prevMethod = ((EjbGroupTreeNodes.MethodNode) prevNode)
163: .getMethod();
164: if (prevMethod.getReturnType()
165: .isCollection())
166: methodDetailPanel
167: .updateColElemClassName();
168:
169: // Programmatically stop the CellEditor so that we do not lose the very last editting value
170: methodDetailPanel.stopLastCellEditing();
171: }
172:
173: if (node instanceof EjbGroupTreeNodes.MethodNode) {
174: // A method is selected
175: methodDetailPanel
176: .setMethod(((EjbGroupTreeNodes.MethodNode) node)
177: .getMethod());
178: }
179: }
180: });
181:
182: }
183:
184: // If expand is true, expands all nodes in the tree.
185: // Otherwise, collapses all nodes in the tree.
186: public void expandAll(boolean expand) {
187: TreeNode root = (TreeNode) methodTree.getModel().getRoot();
188:
189: // Traverse tree from root
190: expandAll(methodTree, new TreePath(root), expand);
191: }
192:
193: private void expandAll(JTree tree, TreePath parent, boolean expand) {
194: // Traverse children
195: TreeNode node = (TreeNode) parent.getLastPathComponent();
196: if (node.getChildCount() >= 0) {
197: for (Enumeration e = node.children(); e.hasMoreElements();) {
198: TreeNode n = (TreeNode) e.nextElement();
199: TreePath path = parent.pathByAddingChild(n);
200: expandAll(tree, path, expand);
201: }
202: }
203:
204: // Expansion or collapse must be done bottom-up
205: if (expand) {
206: tree.expandPath(parent);
207: } else {
208: tree.collapsePath(parent);
209: }
210: }
211:
212: public MethodDetailPanel getMethodDetailPanel() {
213: return this .methodDetailPanel;
214: }
215:
216: /** This method is called from within the constructor to
217: * initialize the form.
218: * WARNING: Do NOT modify this code. The content of this method is
219: * always regenerated by the Form Editor.
220: */
221: // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
222: private void initComponents() {
223: java.awt.GridBagConstraints gridBagConstraints;
224:
225: selectionPanel = new javax.swing.JPanel();
226: treeScrollPanel = new javax.swing.JScrollPane();
227: methodTree = new javax.swing.JTree();
228: methodsLabel = new javax.swing.JLabel();
229: methodPanel = new javax.swing.JPanel();
230:
231: setLayout(new java.awt.GridBagLayout());
232:
233: selectionPanel.setBorder(javax.swing.BorderFactory
234: .createEmptyBorder(5, 10, 10, 10));
235: selectionPanel.setVerifyInputWhenFocusTarget(false);
236: selectionPanel.setLayout(new java.awt.BorderLayout());
237:
238: methodTree.setRootVisible(false);
239: methodTree.setVisibleRowCount(12);
240: treeScrollPanel.setViewportView(methodTree);
241: java.util.ResourceBundle bundle = java.util.ResourceBundle
242: .getBundle("org/netbeans/modules/visualweb/ejb/ui/Bundle"); // NOI18N
243: methodTree.getAccessibleContext().setAccessibleName(
244: bundle.getString("EJB_METHODS")); // NOI18N
245: methodTree.getAccessibleContext().setAccessibleDescription(
246: bundle.getString("EJB_METHODS")); // NOI18N
247:
248: selectionPanel.add(treeScrollPanel,
249: java.awt.BorderLayout.CENTER);
250: treeScrollPanel.getAccessibleContext().setAccessibleName(
251: bundle.getString("EJB_METHODS")); // NOI18N
252: treeScrollPanel.getAccessibleContext()
253: .setAccessibleDescription(
254: bundle.getString("EJB_METHODS")); // NOI18N
255:
256: methodsLabel.setLabelFor(methodTree);
257: org.openide.awt.Mnemonics.setLocalizedText(methodsLabel,
258: org.openide.util.NbBundle.getMessage(
259: ConfigureMethodsPanel.class, "EJB_METHODS")); // NOI18N
260: selectionPanel.add(methodsLabel, java.awt.BorderLayout.NORTH);
261: methodsLabel.getAccessibleContext().setAccessibleName(
262: org.openide.util.NbBundle.getMessage(
263: ConfigureMethodsPanel.class, "EJB_METHODS")); // NOI18N
264: methodsLabel.getAccessibleContext().setAccessibleDescription(
265: org.openide.util.NbBundle.getMessage(
266: ConfigureMethodsPanel.class, "EJB_METHODS")); // NOI18N
267:
268: gridBagConstraints = new java.awt.GridBagConstraints();
269: gridBagConstraints.gridx = 0;
270: gridBagConstraints.gridy = 0;
271: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
272: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
273: gridBagConstraints.weightx = 0.3;
274: gridBagConstraints.weighty = 1.0;
275: gridBagConstraints.insets = new java.awt.Insets(12, 0, 0, 0);
276: add(selectionPanel, gridBagConstraints);
277: selectionPanel.getAccessibleContext().setAccessibleName(
278: bundle.getString("EJB_METHODS")); // NOI18N
279: selectionPanel.getAccessibleContext().setAccessibleDescription(
280: bundle.getString("EJB_METHODS")); // NOI18N
281:
282: methodPanel.setMinimumSize(new java.awt.Dimension(0, 0));
283: methodPanel.setLayout(new java.awt.BorderLayout());
284: gridBagConstraints = new java.awt.GridBagConstraints();
285: gridBagConstraints.gridx = 2;
286: gridBagConstraints.gridy = 0;
287: gridBagConstraints.gridwidth = 2;
288: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
289: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
290: gridBagConstraints.weightx = 0.7;
291: gridBagConstraints.weighty = 1.0;
292: gridBagConstraints.insets = new java.awt.Insets(12, 17, 0, 12);
293: add(methodPanel, gridBagConstraints);
294: methodPanel.getAccessibleContext().setAccessibleName(
295: bundle.getString("METHOD_DETAILS")); // NOI18N
296: methodPanel.getAccessibleContext().setAccessibleDescription(
297: bundle.getString("METHOD_DETAILS")); // NOI18N
298:
299: getAccessibleContext().setAccessibleName(
300: org.openide.util.NbBundle.getMessage(
301: ConfigureMethodsPanel.class,
302: "EXPORT_EJB_DATASOURCES")); // NOI18N
303: getAccessibleContext().setAccessibleDescription(
304: org.openide.util.NbBundle.getMessage(
305: ConfigureMethodsPanel.class,
306: "EXPORT_EJB_DATASOURCES")); // NOI18N
307: }// </editor-fold>//GEN-END:initComponents
308:
309: // Variables declaration - do not modify//GEN-BEGIN:variables
310: private javax.swing.JPanel methodPanel;
311: private javax.swing.JTree methodTree;
312: private javax.swing.JLabel methodsLabel;
313: private javax.swing.JPanel selectionPanel;
314: private javax.swing.JScrollPane treeScrollPanel;
315: // End of variables declaration//GEN-END:variables
316:
317: }
|