Source Code Cross Referenced for VisualPropertySupport.java in  » IDE-Netbeans » bpel » org » netbeans » modules » bpel » project » ui » customizer » 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 » bpel » org.netbeans.modules.bpel.project.ui.customizer 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * The contents of this file are subject to the terms of the Common Development
003:         * and Distribution License (the License). You may not use this file except in
004:         * compliance with the License.
005:         * 
006:         * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
007:         * or http://www.netbeans.org/cddl.txt.
008:         * 
009:         * When distributing Covered Code, include this CDDL Header Notice in each file
010:         * and include the License file at http://www.netbeans.org/cddl.txt.
011:         * If applicable, add the following below the CDDL Header, with the fields
012:         * enclosed by brackets [] replaced by your own identifying information:
013:         * "Portions Copyrighted [year] [name of copyright owner]"
014:         * 
015:         * The Original Software is NetBeans. The Initial Developer of the Original
016:         * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
017:         * Microsystems, Inc. All Rights Reserved.
018:         */
019:
020:        package org.netbeans.modules.bpel.project.ui.customizer;
021:
022:        import java.awt.event.ActionEvent;
023:        import java.awt.event.ActionListener;
024:        import java.util.Collections;
025:        import java.util.HashMap;
026:        import java.util.List;
027:
028:        import javax.swing.JCheckBox;
029:        import javax.swing.JComboBox;
030:        import javax.swing.JTextField;
031:        import javax.swing.event.DocumentEvent;
032:        import javax.swing.event.DocumentListener;
033:        import javax.swing.text.BadLocationException;
034:        import javax.swing.text.Document;
035:        import org.netbeans.modules.compapp.projects.base.ui.customizer.IcanproProjectProperties;
036:
037:        /** Class which makes creation of the GUI easier. Registers JComponent
038:         * property names and handles reading/storing the values from the components
039:         * automaticaly.
040:         *
041:         * @author Petr Hrebejk
042:         */
043:        public final class VisualPropertySupport {
044:
045:            private static final String WRONG_TYPE = "WrongType";
046:
047:            private IcanproProjectProperties webProperties;
048:            private HashMap component2property;
049:            private ComponentListener componentListener;
050:
051:            private int comboType; //0 ... display text == value
052:            //1 ... display text != value
053:            private String[] comboValues;
054:
055:            public VisualPropertySupport(IcanproProjectProperties webProperties) {
056:                this .webProperties = webProperties;
057:                this .component2property = new HashMap(10);
058:                this .componentListener = new ComponentListener();
059:            }
060:
061:            /** Registers the component with given property, Fills the component 
062:             * with given object.
063:             */
064:            public void register(JCheckBox component, String propertyName) {
065:
066:                Boolean value = (Boolean) getAsType(propertyName, Boolean.class);
067:                component2property.put(component, propertyName);
068:                component.setSelected(value != null && value.booleanValue());
069:                component.removeActionListener(componentListener);
070:                component.addActionListener(componentListener);
071:            }
072:
073:            /** Registers the component with given property, Fills the component
074:             * with given object.
075:             */
076:            public void register(JTextField component, String propertyName) {
077:                String value = (String) getAsType(propertyName, String.class);
078:                component2property.put(component.getDocument(), propertyName);
079:                component.setText(value != null ? value : "");
080:                component.getDocument().addDocumentListener(componentListener);
081:            }
082:
083:            /** Registers JTable containing VisualClassPath items and acompaniing
084:             *  buttons for handling the class path
085:             */
086:            public void register(VisualClasspathSupport component,
087:                    String propertyName) {
088:                List value = (List) getAsType(propertyName, List.class);
089:                component2property.put(component, propertyName);
090:                component.setVisualClassPathItems(value != null ? value
091:                        : Collections.EMPTY_LIST);
092:                component.removeActionListener(componentListener);
093:                component.addActionListener(componentListener);
094:            }
095:
096:            /** Registers combo box.
097:             */
098:            public void register(JComboBox component, String items[],
099:                    String propertyName) {
100:                comboType = 0;
101:                String value = (String) getAsType(propertyName, String.class);
102:                component2property.put(component, propertyName);
103:                // Add all items and find the selected one
104:                component.removeAllItems();
105:                int selectedIndex = 0;
106:                for (int i = 0; i < items.length; i++) {
107:                    component.addItem(items[i]);
108:                    if (items[i].equals(value)) {
109:                        selectedIndex = i;
110:                    }
111:                }
112:                component.setSelectedIndex(selectedIndex);
113:                component.removeActionListener(componentListener);
114:                component.addActionListener(componentListener);
115:            }
116:
117:            /** Registers combo box.
118:             */
119:            public void register(JComboBox component, String displayNames[],
120:                    String[] values, String propertyName) {
121:                comboType = 1;
122:                comboValues = values;
123:                String value = (String) getAsType(propertyName, String.class);
124:                component2property.put(component, propertyName);
125:                // Add all items and find the selected one
126:                component.removeAllItems();
127:                int selectedIndex = 0;
128:                for (int i = 0; i < displayNames.length; i++) {
129:                    component.addItem(displayNames[i]);
130:                    if (values[i].equals(value))
131:                        selectedIndex = i;
132:                }
133:                component.setSelectedIndex(selectedIndex);
134:                component.removeActionListener(componentListener);
135:                component.addActionListener(componentListener);
136:            }
137:
138:            /**
139:             * Registers JList containing VisualClassPath items and acompaniing buttons for handling the
140:             * class path
141:             *
142:             * @param component DOCUMENT ME!
143:             * @param propertyName DOCUMENT ME!
144:             */
145:            public void register(VisualArchiveIncludesSupport component,
146:                    String propertyName) {
147:                List value = (List) getAsType(propertyName, List.class);
148:                component2property.put(component, propertyName);
149:                component.setVisualWarItems((value != null) ? value
150:                        : Collections.EMPTY_LIST);
151:                component.removeActionListener(componentListener);
152:                component.addActionListener(componentListener);
153:            }
154:
155:            // Static methods for reading components and models ------------------------
156:
157:            private static Boolean readValue(JCheckBox checkBox) {
158:                return checkBox.isSelected() ? Boolean.TRUE : Boolean.FALSE;
159:            }
160:
161:            private static String readValue(Document document) {
162:                try {
163:                    return document.getText(0, document.getLength());
164:                } catch (BadLocationException e) {
165:                    assert false : "Invalid document "; //NOI18N
166:                    return ""; // NOI18N
167:                }
168:            }
169:
170:            private static String readValue(JComboBox comboBox) {
171:                return (String) comboBox.getSelectedItem();
172:            }
173:
174:            // Private methods ---------------------------------------------------------
175:
176:            private Object getAsType(String propertyName, Class expectedType) {
177:                return getAsType(propertyName, expectedType, true);
178:            }
179:
180:            private Object getAsType(String propertyName, Class expectedType,
181:                    boolean throwException) {
182:
183:                Object value = webProperties.get(propertyName);
184:
185:                if (value == null || expectedType.isInstance(value)) {
186:                    return value;
187:                } else if (throwException) {
188:                    throw new IllegalArgumentException("Value of property: "
189:                            + propertyName + // NOI18N
190:                            " exbected to be: " + expectedType.getName() + // NOI18N
191:                            " but was: " + value.getClass().getName() + "!"); // NOI18N
192:                } else {
193:                    return WRONG_TYPE;
194:                }
195:
196:            }
197:
198:            private class ComponentListener implements  ActionListener,
199:                    DocumentListener {
200:
201:                // Implementation of action listener -----------------------------------
202:
203:                public void actionPerformed(ActionEvent e) {
204:                    Object source = e.getSource();
205:                    String propertyName = (String) component2property
206:                            .get(source);
207:                    if (propertyName != null) {
208:                        if (source instanceof  JCheckBox) {
209:                            webProperties.put(propertyName,
210:                                    readValue((JCheckBox) source));
211:                        } else if (source instanceof  VisualClasspathSupport) {
212:                            webProperties.put(propertyName,
213:                                    ((VisualClasspathSupport) source)
214:                                            .getVisualClassPathItems());
215:                        } else if (source instanceof  JComboBox) {
216:                            if (((JComboBox) source).getItemCount() == 0) {
217:                                return;
218:                            }
219:
220:                            switch (comboType) {
221:                            case 0:
222:                                webProperties.put(propertyName,
223:                                        readValue((JComboBox) source));
224:                                break;
225:                            case 1:
226:                                webProperties.put(propertyName,
227:                                        comboValues[((JComboBox) source)
228:                                                .getSelectedIndex()]);
229:                                break;
230:                            }
231:                        } else if (source instanceof  VisualArchiveIncludesSupport) {
232:                            webProperties.put(propertyName,
233:                                    ((VisualArchiveIncludesSupport) source)
234:                                            .getVisualWarItems());
235:                        }
236:                    }
237:                }
238:
239:                // Implementation of document listener ---------------------------------
240:
241:                public void changedUpdate(DocumentEvent e) {
242:                    Document document = e.getDocument();
243:                    String propertyName = (String) component2property
244:                            .get(document);
245:                    if (propertyName != null) {
246:                        webProperties.put(propertyName, readValue(document));
247:                    }
248:                }
249:
250:                public void insertUpdate(DocumentEvent e) {
251:                    changedUpdate(e);
252:                }
253:
254:                public void removeUpdate(DocumentEvent e) {
255:                    changedUpdate(e);
256:                }
257:            }
258:        }
w_w_w___.j__a_v_a_2___s_.___com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.