Source Code Cross Referenced for BeanConnector.java in  » Workflow-Engines » OSWorkflow » com » opensymphony » workflow » designer » beanutils » 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 » Workflow Engines » OSWorkflow » com.opensymphony.workflow.designer.beanutils 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.opensymphony.workflow.designer.beanutils;
002:
003:        import java.awt.*;
004:        import java.awt.event.*;
005:        import java.text.ParseException;
006:        import java.util.HashMap;
007:        import java.util.Iterator;
008:        import java.util.Map;
009:        import javax.swing.*;
010:        import javax.swing.event.*;
011:
012:        import com.opensymphony.workflow.designer.editor.DetailPanel;
013:        import com.opensymphony.workflow.designer.editor.ResultEditor;
014:        import com.opensymphony.workflow.designer.editor.WorkflowEditor;
015:        import com.opensymphony.workflow.designer.WorkflowDesigner;
016:        import com.opensymphony.workflow.loader.WorkflowDescriptor;
017:
018:        public class BeanConnector {
019:            Object source;
020:            DetailPanel panel = null;
021:
022:            Map mappings = new HashMap();
023:
024:            public BeanConnector(Object aSource) {
025:                source = aSource;
026:            }
027:
028:            public BeanConnector() {
029:            }
030:
031:            public void setSource(Object aSource) {
032:                source = aSource;
033:
034:                update();
035:            }
036:
037:            public void setPanel(DetailPanel panel) {
038:                this .panel = panel;
039:            }
040:
041:            public void update() {
042:                // Set values
043:                for (Iterator iterator = mappings.entrySet().iterator(); iterator
044:                        .hasNext();) {
045:                    Map.Entry entry = (Map.Entry) iterator.next();
046:                    getProperty((Component) entry.getKey());
047:                }
048:            }
049:
050:            public Object getSource() {
051:                return source;
052:            }
053:
054:            public Component connect(final Component aComponent,
055:                    final String aName) {
056:                mappings.put(aComponent, aName);
057:
058:                if (source != null) {
059:                    getProperty(aComponent);
060:                }
061:
062:                // Connect to component
063:                if (aComponent instanceof  JSpinner) {
064:                    ((JSpinner) aComponent)
065:                            .addChangeListener(new ChangeListener() {
066:                                public void stateChanged(ChangeEvent e) {
067:                                    setProperty(aComponent);
068:                                }
069:                            });
070:                } else if (aComponent instanceof  JList) {
071:                    ((JList) aComponent)
072:                            .addListSelectionListener(new ListSelectionListener() {
073:                                public void valueChanged(ListSelectionEvent e) {
074:                                    setProperty(aComponent);
075:                                }
076:                            });
077:                } else if (aComponent instanceof  JComboBox) {
078:                    ((JComboBox) aComponent)
079:                            .addActionListener(new ActionListener() {
080:                                public void actionPerformed(ActionEvent e) {
081:                                    setProperty(aComponent);
082:                                }
083:                            });
084:                } else if (aComponent instanceof  JComponent) {
085:                    aComponent.addFocusListener(new FocusListener() {
086:                        public void focusGained(FocusEvent e) {
087:
088:                        }
089:
090:                        public void focusLost(FocusEvent e) {
091:                            if (panel != null) {
092:                                if (panel instanceof  ResultEditor) {
093:                                    setProperty(e.getComponent());
094:                                } else if (panel instanceof  WorkflowEditor) {
095:                                    WorkflowDescriptor desc = (WorkflowDescriptor) panel
096:                                            .getDescriptor();
097:                                    String oldName = desc.getName();
098:                                    String newName = ((JTextField) e
099:                                            .getComponent()).getText();
100:                                    newName = newName.trim();
101:                                    if ((!oldName.equals(newName))
102:                                            && (newName.length() > 0)) {
103:                                        WorkflowDesigner.INSTANCE
104:                                                .renameWorkflow(oldName,
105:                                                        newName);
106:                                        setProperty(e.getComponent());
107:                                    }
108:                                }
109:                            } else
110:                                setProperty(e.getComponent());
111:                        }
112:                    });
113:                }
114:
115:                return aComponent;
116:            }
117:
118:            public void setProperty(Component comp) {
119:                String name = (String) mappings.get(comp);
120:                Object value = null;
121:                if (comp instanceof  JFormattedTextField) {
122:                    try {
123:                        value = ((JFormattedTextField) comp).getFormatter()
124:                                .stringToValue(
125:                                        ((JFormattedTextField) comp).getText());
126:                    } catch (ParseException e) {
127:                        e.printStackTrace();
128:                        return;
129:                    }
130:                } else if (comp instanceof  JTextField) {
131:                    value = ((JTextField) comp).getText();
132:                } else if (comp instanceof  JSpinner) {
133:                    value = ((JSpinner) comp).getValue();
134:                } else if (comp instanceof  JRadioButton) {
135:                    JRadioButton button = (JRadioButton) comp;
136:                    if (!button.isSelected())
137:                        return;
138:                    value = button.getActionCommand();
139:                } else if (comp instanceof  JCheckBox) {
140:                    value = new Boolean(((JCheckBox) comp).isSelected());
141:                } else if (comp instanceof  JList) {
142:                    value = new Integer(((JList) comp).getSelectedIndex());
143:                } else if (comp instanceof  JComboBox) {
144:                    value = ((JComboBox) comp).getSelectedItem();
145:                }
146:
147:                if (source instanceof  Map) {
148:                    if (value == null)
149:                        ((Map) source).remove(name);
150:                    else
151:                        ((Map) source).put(name, value);
152:                } else {
153:                    try {
154:                        PropertyUtils.setProperty(source, name, value);
155:                    } catch (IllegalArgumentException e) {
156:                        try {
157:                            PropertyUtils.setProperty(source, name, value
158:                                    .toString());
159:                        } catch (Exception e1) {
160:                            e1.printStackTrace();
161:                        }
162:                    } catch (IndexOutOfBoundsException e) {
163:                        e.printStackTrace();
164:                    } catch (Exception e) {
165:                        e.printStackTrace();
166:                    }
167:                }
168:            }
169:
170:            public void getProperty(Component comp) {
171:                try {
172:                    String name = (String) mappings.get(comp);
173:                    if (name == null)
174:                        return;
175:                    Object value;
176:                    if (source instanceof  Map) {
177:                        value = ((Map) source).get(name);
178:                    } else {
179:                        //if we try to index into a non-existent property, just set it to null
180:                        try {
181:                            value = PropertyUtils.getProperty(source, name);
182:                        } catch (NullPointerException ex) {
183:                            value = null;
184:                        } catch (NoSuchMethodException ex) {
185:                            value = null;
186:                        } catch (IndexOutOfBoundsException ex) {
187:                            value = null;
188:                        }
189:                    }
190:
191:                    //         LogFactory.getLog(this.getClass()).info("Get " + name + "=" + value);
192:
193:                    if (comp instanceof  JFormattedTextField) {
194:                        if (value == null) {
195:                            ((JFormattedTextField) comp).setText("");
196:                        } else
197:                            ((JFormattedTextField) comp).setValue(value);
198:                    } else if (comp instanceof  JTextField) {
199:                        if (value == null)
200:                            value = "";
201:                        ((JTextField) comp).setText(value.toString());
202:                    } else if (comp instanceof  JSpinner) {
203:                        if (value != null)
204:                            ((JSpinner) comp).setValue(value);
205:                    } else if (comp instanceof  JRadioButton) {
206:                        if (value == null)
207:                            value = Boolean.FALSE;
208:
209:                        if (((JRadioButton) comp).getActionCommand().equals(
210:                                value.toString()))
211:                            ((JRadioButton) comp).setSelected(true);
212:                    } else if (comp instanceof  JCheckBox) {
213:                        if (value == null)
214:                            value = Boolean.FALSE;
215:
216:                        ((JCheckBox) comp).setSelected(new Boolean(value
217:                                .toString()).booleanValue());
218:                    } else if (comp instanceof  JList) {
219:                        if (value == null)
220:                            value = "0";
221:                        ((JList) comp).setSelectedIndex(Integer.parseInt(value
222:                                .toString()));
223:                    } else if (comp instanceof  JComboBox) {
224:                        if (value == null)
225:                            value = "0";
226:                        ((JComboBox) comp).setSelectedItem(value);
227:                    } else if (comp instanceof  JLabel) {
228:                        if (value == null)
229:                            value = "";
230:                        ((JLabel) comp).setText(value.toString());
231:                    }
232:                } catch (Exception e) {
233:                    e.printStackTrace();
234:                }
235:            }
236:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.