Source Code Cross Referenced for ConnectionPanel2.java in  » IDE-Netbeans » form » org » netbeans » modules » form » wizard » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » IDE Netbeans » form » org.netbeans.modules.form.wizard 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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-2006 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:        package org.netbeans.modules.form.wizard;
043:
044:        import java.beans.*;
045:        import java.util.*;
046:        import javax.swing.event.*;
047:
048:        import org.openide.awt.Mnemonics;
049:        import org.openide.util.NbBundle;
050:        import org.netbeans.modules.form.*;
051:
052:        /**
053:         * The UI component of the ConnectionWizardPanel2.
054:         *
055:         * @author Tomas Pavek
056:         */
057:
058:        class ConnectionPanel2 extends javax.swing.JPanel {
059:
060:            private ConnectionWizardPanel2 wizardPanel;
061:
062:            private Object[] propertyListData;
063:            private Object[] methodListData;
064:            private MethodDescriptor[] methodDescriptors;
065:            private PropertyDescriptor[] propDescriptors;
066:
067:            java.util.ResourceBundle bundle;
068:
069:            /** Creates new form ConnectionPanel2 */
070:            ConnectionPanel2(ConnectionWizardPanel2 wizardPanel) {
071:                this .wizardPanel = wizardPanel;
072:
073:                initComponents();
074:
075:                bundle = NbBundle.getBundle(ConnectionPanel2.class);
076:
077:                setName(bundle.getString("CTL_CW_Step2_Title")); // NOI18N
078:
079:                javax.swing.ButtonGroup gr = new javax.swing.ButtonGroup();
080:                gr.add(propertyButton);
081:                gr.add(methodButton);
082:                gr.add(codeButton);
083:
084:                targetComponentName.setText(wizardPanel.getTargetComponent()
085:                        .getName());
086:
087:                actionList
088:                        .setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
089:                actionList
090:                        .addListSelectionListener(new ListSelectionListener() {
091:                            public void valueChanged(ListSelectionEvent evt) {
092:                                if (!evt.getValueIsAdjusting())
093:                                    ConnectionPanel2.this .wizardPanel
094:                                            .fireStateChanged();
095:                            }
096:                        });
097:
098:                // localization code
099:                Mnemonics.setLocalizedText(targetNameLabel, bundle
100:                        .getString("CTL_CW_TargetComponent")); // NOI18N
101:                targetComponentName.setToolTipText(bundle
102:                        .getString("CTL_CW_TargetComponent_Hint")); // NOI18N
103:                Mnemonics.setLocalizedText(propertyButton, bundle
104:                        .getString("CTL_CW_SetProperty")); // NOI18N
105:                propertyButton.setToolTipText(bundle
106:                        .getString("CTL_CW_SetProperty_Hint")); // NOI18N
107:                Mnemonics.setLocalizedText(methodButton, bundle
108:                        .getString("CTL_CW_MethodCall")); // NOI18N
109:                methodButton.setToolTipText(bundle
110:                        .getString("CTL_CW_MethodCall_Hint")); // NOI18N
111:                Mnemonics.setLocalizedText(codeButton, bundle
112:                        .getString("CTL_CW_XUserCode")); // NOI18N
113:                codeButton.setToolTipText(bundle
114:                        .getString("CTL_CW_XUserCode_Hint")); // NOI18N
115:
116:                targetComponentName.getAccessibleContext()
117:                        .setAccessibleDescription(
118:                                bundle.getString("ACSD_CW_TargetComponent")); // NOI18N
119:                propertyButton.getAccessibleContext().setAccessibleDescription(
120:                        bundle.getString("ACSD_CW_SetProperty")); // NOI18N
121:                methodButton.getAccessibleContext().setAccessibleDescription(
122:                        bundle.getString("ACSD_CW_MethodCall")); // NOI18N
123:                codeButton.getAccessibleContext().setAccessibleDescription(
124:                        bundle.getString("ACSD_CW_XUserCode")); // NOI18N
125:                actionList.getAccessibleContext().setAccessibleDescription(
126:                        bundle.getString("ACSD_CW_ActionList")); // NOI18N
127:                getAccessibleContext().setAccessibleDescription(
128:                        bundle.getString("ACSD_CW_ConnectionPanel2")); // NOI18N
129:
130:                updateActionList();
131:
132:                putClientProperty("WizardPanel_contentSelectedIndex",
133:                        new Integer(1)); // NOI18N
134:            }
135:
136:            @Override
137:            public java.awt.Dimension getPreferredSize() {
138:                return new java.awt.Dimension(450, 300);
139:            }
140:
141:            int getActionType() {
142:                if (methodButton.isSelected())
143:                    return ConnectionWizardPanel2.METHOD_TYPE;
144:                else if (propertyButton.isSelected())
145:                    return ConnectionWizardPanel2.PROPERTY_TYPE;
146:                else
147:                    return ConnectionWizardPanel2.CODE_TYPE;
148:            }
149:
150:            MethodDescriptor getSelectedMethod() {
151:                if (!methodButton.isSelected()
152:                        || actionList.getSelectedIndex() == -1)
153:                    return null;
154:                return methodDescriptors[actionList.getSelectedIndex()];
155:            }
156:
157:            PropertyDescriptor getSelectedProperty() {
158:                if (!propertyButton.isSelected()
159:                        || actionList.getSelectedIndex() == -1)
160:                    return null;
161:                return propDescriptors[actionList.getSelectedIndex()];
162:            }
163:
164:            private void updateActionList() {
165:                if (codeButton.isSelected()) {
166:                    actionList.setListData(new String[] {
167:                            bundle.getString("CTL_CW_UserCodeText1"), // NOI18N
168:                            bundle.getString("CTL_CW_UserCodeText2") }); // NOI18N
169:                    actionList.setEnabled(false);
170:                    actionList.getAccessibleContext().setAccessibleName(
171:                            codeButton.getText());
172:                } else if (propertyButton.isSelected()) {
173:                    // properties list
174:                    actionList.setEnabled(true);
175:                    if (propertyListData == null) {
176:                        BeanInfo targetBeanInfo = wizardPanel
177:                                .getTargetComponent().getBeanInfo();
178:                        PropertyDescriptor[] descs = targetBeanInfo
179:                                .getPropertyDescriptors();
180:
181:                        // filter out read-only properties // [FUTURE: provide also indexed properties]
182:                        List<PropertyDescriptor> list = new ArrayList<PropertyDescriptor>();
183:                        for (int i = 0; i < descs.length; i++) {
184:                            if (descs[i].getWriteMethod() != null) {
185:                                list.add(descs[i]);
186:                            }
187:                        }
188:
189:                        // sort the properties by name
190:                        Collections.sort(list,
191:                                new Comparator<PropertyDescriptor>() {
192:                                    public int compare(PropertyDescriptor o1,
193:                                            PropertyDescriptor o2) {
194:                                        return o1.getName().compareTo(
195:                                                o2.getName());
196:                                    }
197:                                });
198:
199:                        propDescriptors = new PropertyDescriptor[list.size()];
200:                        list.toArray(propDescriptors);
201:
202:                        propertyListData = new String[propDescriptors.length];
203:                        for (int i = 0; i < propDescriptors.length; i++) {
204:                            propertyListData[i] = propDescriptors[i].getName();
205:                        }
206:                    }
207:                    actionList.setListData(propertyListData);
208:                    actionList.getAccessibleContext().setAccessibleName(
209:                            propertyButton.getText());
210:                } else {
211:                    // methods list
212:                    actionList.setEnabled(true);
213:                    if (methodListData == null) {
214:                        BeanInfo targetBeanInfo = wizardPanel
215:                                .getTargetComponent().getBeanInfo();
216:                        methodDescriptors = targetBeanInfo
217:                                .getMethodDescriptors();
218:                        ArrayList<MethodDescriptor> list = new ArrayList<MethodDescriptor>();
219:                        for (int i = 0; i < methodDescriptors.length; i++) {
220:                            list.add(methodDescriptors[i]);
221:                        }
222:
223:                        // sort the methods by name
224:                        Collections.sort(list,
225:                                new Comparator<MethodDescriptor>() {
226:                                    public int compare(MethodDescriptor o1,
227:                                            MethodDescriptor o2) {
228:                                        return o1.getName().compareTo(
229:                                                o2.getName());
230:                                    }
231:                                });
232:
233:                        // copy it back to the array as it is used later
234:                        list.toArray(methodDescriptors);
235:
236:                        methodListData = new String[list.size()];
237:                        int i = 0;
238:                        for (Iterator it = list.iterator(); it.hasNext();) {
239:                            methodListData[i++] = getMethodName((MethodDescriptor) it
240:                                    .next());
241:                        }
242:                    }
243:                    actionList.setListData(methodListData);
244:                    actionList.getAccessibleContext().setAccessibleName(
245:                            methodButton.getText());
246:                }
247:                actionList.revalidate();
248:                actionList.repaint();
249:            }
250:
251:            private static String getMethodName(MethodDescriptor desc) {
252:                StringBuffer sb = new StringBuffer(desc.getName());
253:                Class[] params = desc.getMethod().getParameterTypes();
254:                if ((params == null) || (params.length == 0)) {
255:                    sb.append("()"); // NOI18N
256:                } else {
257:                    for (int i = 0; i < params.length; i++) {
258:                        if (i == 0)
259:                            sb.append("("); // NOI18N
260:                        else
261:                            sb.append(", "); // NOI18N
262:                        sb.append(org.openide.util.Utilities
263:                                .getShortClassName(params[i]));
264:                    }
265:                    sb.append(")"); // NOI18N
266:                }
267:
268:                return sb.toString();
269:            }
270:
271:            /** This method is called from within the constructor to
272:             * initialize the form.
273:             * WARNING: Do NOT modify this code. The content of this method is
274:             * always regenerated by the Form Editor.
275:             */
276:            private void initComponents() {//GEN-BEGIN:initComponents
277:                targerInfoPanel = new javax.swing.JPanel();
278:                targetNamePanel = new javax.swing.JPanel();
279:                targetNameLabel = new javax.swing.JLabel();
280:                targetComponentName = new javax.swing.JTextField();
281:                actionTypePanel = new javax.swing.JPanel();
282:                propertyButton = new javax.swing.JRadioButton();
283:                methodButton = new javax.swing.JRadioButton();
284:                codeButton = new javax.swing.JRadioButton();
285:                actionPanel = new javax.swing.JScrollPane();
286:                actionList = new javax.swing.JList();
287:
288:                setLayout(new java.awt.BorderLayout(0, 2));
289:
290:                targerInfoPanel.setLayout(new java.awt.BorderLayout(0, 6));
291:
292:                targetNamePanel.setLayout(new java.awt.FlowLayout(
293:                        java.awt.FlowLayout.LEFT, 0, 0));
294:
295:                targetNameLabel.setLabelFor(targetComponentName);
296:                targetNameLabel.setText("Target Component:");
297:                targetNameLabel.setBorder(new javax.swing.border.EmptyBorder(
298:                        new java.awt.Insets(0, 0, 0, 6)));
299:                targetNamePanel.add(targetNameLabel);
300:
301:                targetComponentName.setEditable(false);
302:                targetComponentName.setText("jTextField1");
303:                targetNamePanel.add(targetComponentName);
304:
305:                targerInfoPanel.add(targetNamePanel,
306:                        java.awt.BorderLayout.NORTH);
307:
308:                actionTypePanel.setLayout(new java.awt.FlowLayout(
309:                        java.awt.FlowLayout.LEFT, 0, 0));
310:
311:                propertyButton.setSelected(true);
312:                propertyButton.setText("Set Property");
313:                propertyButton.setMargin(new java.awt.Insets(2, 2, 2, 10));
314:                propertyButton
315:                        .addActionListener(new java.awt.event.ActionListener() {
316:                            public void actionPerformed(
317:                                    java.awt.event.ActionEvent evt) {
318:                                ConnectionPanel2.this 
319:                                        .actionTypeButtonPressed(evt);
320:                            }
321:                        });
322:
323:                actionTypePanel.add(propertyButton);
324:
325:                methodButton.setText("Method Call");
326:                methodButton.setMargin(new java.awt.Insets(2, 2, 2, 10));
327:                methodButton
328:                        .addActionListener(new java.awt.event.ActionListener() {
329:                            public void actionPerformed(
330:                                    java.awt.event.ActionEvent evt) {
331:                                ConnectionPanel2.this 
332:                                        .actionTypeButtonPressed(evt);
333:                            }
334:                        });
335:
336:                actionTypePanel.add(methodButton);
337:
338:                codeButton.setText("User Code");
339:                codeButton
340:                        .addActionListener(new java.awt.event.ActionListener() {
341:                            public void actionPerformed(
342:                                    java.awt.event.ActionEvent evt) {
343:                                ConnectionPanel2.this 
344:                                        .actionTypeButtonPressed(evt);
345:                            }
346:                        });
347:
348:                actionTypePanel.add(codeButton);
349:
350:                targerInfoPanel.add(actionTypePanel,
351:                        java.awt.BorderLayout.CENTER);
352:
353:                add(targerInfoPanel, java.awt.BorderLayout.NORTH);
354:
355:                actionPanel.setViewportView(actionList);
356:
357:                add(actionPanel, java.awt.BorderLayout.CENTER);
358:
359:            }//GEN-END:initComponents
360:
361:            private void actionTypeButtonPressed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_actionTypeButtonPressed
362:                updateActionList();
363:                wizardPanel.fireStateChanged();
364:                if (evt.getSource() != codeButton)
365:                    actionList.requestFocus();
366:            }//GEN-LAST:event_actionTypeButtonPressed
367:
368:            // Variables declaration - do not modify//GEN-BEGIN:variables
369:            private javax.swing.JRadioButton codeButton;
370:            private javax.swing.JList actionList;
371:            private javax.swing.JRadioButton methodButton;
372:            private javax.swing.JScrollPane actionPanel;
373:            private javax.swing.JPanel targetNamePanel;
374:            private javax.swing.JRadioButton propertyButton;
375:            private javax.swing.JPanel targerInfoPanel;
376:            private javax.swing.JLabel targetNameLabel;
377:            private javax.swing.JTextField targetComponentName;
378:            private javax.swing.JPanel actionTypePanel;
379:            // End of variables declaration//GEN-END:variables
380:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.