Source Code Cross Referenced for ReferenceTool.java in  » Workflow-Engines » osbl-1_0 » org » osbl » client » wings » navigation » 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 » osbl 1_0 » org.osbl.client.wings.navigation 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.osbl.client.wings.navigation;
002:
003:        import org.osbl.client.wings.shell.*;
004:        import org.osbl.client.wings.form.FormTool;
005:        import org.osbl.client.wings.form.ObjectForm;
006:        import org.osbl.client.wings.XLabel;
007:        import org.osbl.client.wings.XIcons;
008:        import org.osbl.client.wings.action.ShowEditorAction;
009:        import org.osbl.client.ClientResourceProvider;
010:        import org.osbl.*;
011:        import org.wings.*;
012:        import org.wings.session.SessionManager;
013:        import org.wings.border.SEmptyBorder;
014:        import org.wingx.XDivision;
015:        import org.concern.LoaderException;
016:        import org.conform.*;
017:        import org.conform.format.Format;
018:        import org.conform.format.NoFormat;
019:        import org.apache.commons.logging.LogFactory;
020:
021:        import javax.swing.*;
022:        import java.util.*;
023:        import java.net.URLEncoder;
024:        import java.io.UnsupportedEncodingException;
025:        import java.awt.event.ActionEvent;
026:
027:        public class ReferenceTool extends AbstractTool implements  FormTool {
028:            private static org.apache.commons.logging.Log LOG = LogFactory
029:                    .getLog(ReferenceTool.class);
030:
031:            XDivision panel;
032:            private ObjectForm objectForm;
033:            private XLabel links = new ReferencesLabel();
034:            private ObjectLocators objectLocators;
035:
036:            public ReferenceTool() {
037:                putValue(Tool.NAME, Client.getInstance().getResourceProvider()
038:                        .getMessage("tool.references"));
039:            }
040:
041:            public void setForm(ObjectForm objectForm) {
042:                this .objectForm = objectForm;
043:                putValue(Tool.KEY, "Reference: "
044:                        + objectForm.getType().getName());
045:            }
046:
047:            public SComponent getComponent() {
048:                if (panel == null) {
049:                    panel = new XDivision(new SGridLayout(2));
050:                    panel.setTitle((String) getValue(NAME));
051:                    panel.setBorder(new SEmptyBorder(8, 8, 8, 8));
052:                    panel.setPreferredSize(SDimension.FULLWIDTH);
053:
054:                    SButton button = new SButton(new RefreshAction());
055:                    button.setVerticalAlignment(SConstants.TOP_ALIGN);
056:                    button.setStyle("borderless");
057:                    panel.add(button);
058:
059:                    links.setVerticalAlignment(SConstants.TOP_ALIGN);
060:                    links.setAjaxLinking(true);
061:                    links.setWordWrap(true);
062:                    panel.add(links);
063:                }
064:                return panel;
065:            }
066:
067:            private void refresh() {
068:                ReferenceCheckers referenceCheckers = (ReferenceCheckers) ServiceProvider
069:                        .getInstance().getService("ReferenceCheckers");
070:                List references = referenceCheckers.referenceChecks(objectForm
071:                        .getType(), Collections.singleton(objectForm
072:                        .getObject()));
073:                if (references != null && references.size() != 0) {
074:                    StringBuilder builder = new StringBuilder();
075:                    for (Object object : references) {
076:                        if (builder.length() != 0)
077:                            builder.append(", ");
078:
079:                        builder.append('[');
080:                        builder.append(query(object));
081:                        builder.append(' ');
082:                        builder.append(format(object));
083:                        builder.append(']');
084:                    }
085:                    links.setXText(builder.toString());
086:                } else
087:                    links.setText(null);
088:            }
089:
090:            private String query(Object object) {
091:                Class type = object.getClass();
092:                ObjectLocator objectLocator = getObjectLocators().get(type);
093:                if (objectLocator == null) {
094:                    LOG.warn("No ObjectLocator for " + type.getName());
095:                    return null;
096:                }
097:
098:                Map<String, String> query = objectLocator.queryByObject(object);
099:
100:                StringBuilder builder = new StringBuilder();
101:                try {
102:                    builder.append('?');
103:                    builder.append("push=");
104:                    builder.append(type.getName());
105:
106:                    for (Map.Entry<String, String> entry : query.entrySet()) {
107:                        builder.append('&');
108:                        builder.append(entry.getKey());
109:                        builder.append('=');
110:                        builder.append(URLEncoder.encode(entry.getValue(),
111:                                "UTF-8"));
112:                    }
113:                } catch (UnsupportedEncodingException e) {
114:                    throw new RuntimeException(e); // won't happen
115:                }
116:
117:                return builder.toString();
118:            }
119:
120:            public String format(Object object) throws LoaderException {
121:                Client client = Client.getInstance();
122:                ClientResourceProvider resourceProvider = client
123:                        .getResourceProvider();
124:                BeanMetaProvider beanMetaProvider = client
125:                        .getBeanMetaProvider();
126:                BeanMeta beanMeta = beanMetaProvider.getBeanMeta(object
127:                        .getClass());
128:
129:                String patternKey = (String) beanMeta
130:                        .getAttribute(PropertyMeta.ATTRIBUTE_PATTERN_KEY);
131:                Format subjectFormat = beanMeta.getFormat();
132:                if (subjectFormat == null)
133:                    subjectFormat = new NoFormat();
134:
135:                if (patternKey != null)
136:                    subjectFormat.setPattern(resourceProvider.getMessage(client
137:                            .getLocale(), patternKey));
138:
139:                return subjectFormat.format(object);
140:            }
141:
142:            public ObjectLocators getObjectLocators() {
143:                if (objectLocators == null)
144:                    objectLocators = (ObjectLocators) ServiceProvider
145:                            .getInstance().getService("ObjectLocators");
146:                return objectLocators;
147:            }
148:
149:            class RefreshAction extends AbstractAction {
150:                public RefreshAction() {
151:                    putValue(SMALL_ICON, XIcons.REFRESH);
152:                }
153:
154:                public void actionPerformed(ActionEvent e) {
155:                    refresh();
156:                }
157:            }
158:
159:            private class ReferencesLabel extends XLabel {
160:                public ReferencesLabel() {
161:                    setAjaxLinking(true);
162:                }
163:
164:                protected void handleEvent() {
165:                    String push = SessionManager.getSession()
166:                            .getServletRequest().getParameter("push");
167:                    if (push != null) {
168:                        try {
169:                            ClassLoader classLoader = Thread.currentThread()
170:                                    .getContextClassLoader();
171:                            Window parent = Window.currentWindow(objectForm
172:                                    .getEnvironment());
173:                            ShowEditorAction action = new ShowEditorAction(
174:                                    parent, classLoader.loadClass(push), push);
175:                            action = (ShowEditorAction) Client.getInstance()
176:                                    .getActionProvider().configure(action);
177:                            if (action.isEnabled()) {
178:                                action.navigate(query());
179:                            }
180:                        } catch (ClassNotFoundException e) {
181:                            LOG.warn(push, e);
182:                        }
183:                        return;
184:                    }
185:                }
186:
187:                private Map<String, String> query() {
188:                    Map<String, String[]> map = SessionManager.getSession()
189:                            .getServletRequest().getParameterMap();
190:                    Map<String, String> query = new HashMap<String, String>();
191:                    for (Map.Entry<String, String[]> entry : map.entrySet()) {
192:                        String key = entry.getKey();
193:                        String[] value = entry.getValue();
194:                        if (value != null && value.length == 1)
195:                            query.put(key, value[0]);
196:                    }
197:                    query.put("locale", SessionManager.getSession().getLocale()
198:                            .toString());
199:                    query.put("user", SessionManager.getSession()
200:                            .getServletRequest().getUserPrincipal().getName());
201:                    return query;
202:                }
203:            }
204:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.