Source Code Cross Referenced for TypeModule.java in  » Content-Management-System » contelligent » de » finix » contelligent » client » modules » types » 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 » Content Management System » contelligent » de.finix.contelligent.client.modules.types 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2001-2006 C:1 Financial Services GmbH
003:         *
004:         * This software is free software; you can redistribute it and/or
005:         * modify it under the terms of the GNU Lesser General Public
006:         * License Version 2.1, as published by the Free Software Foundation.
007:         *
008:         * This software is distributed in the hope that it will be useful,
009:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
010:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
011:         * Lesser General Public License for more details.
012:         *
013:         * You should have received a copy of the GNU Lesser General Public
014:         * License along with this library; if not, write to the Free Software
015:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
016:         */
017:
018:        package de.finix.contelligent.client.modules.types;
019:
020:        import java.awt.BorderLayout;
021:        import java.awt.Color;
022:        import java.awt.Dimension;
023:        import java.awt.event.MouseAdapter;
024:        import java.awt.event.MouseEvent;
025:        import java.util.Collections;
026:        import java.util.Comparator;
027:        import java.util.Iterator;
028:        import java.util.Vector;
029:        import java.util.logging.Level;
030:        import java.util.logging.Logger;
031:
032:        import javax.swing.DefaultListModel;
033:        import javax.swing.JLabel;
034:        import javax.swing.JList;
035:        import javax.swing.JPanel;
036:        import javax.swing.JScrollPane;
037:        import javax.swing.JSplitPane;
038:        import javax.swing.JTextArea;
039:        import javax.swing.JTree;
040:        import javax.swing.ListCellRenderer;
041:        import javax.swing.event.ListSelectionEvent;
042:        import javax.swing.event.ListSelectionListener;
043:        import javax.swing.tree.DefaultMutableTreeNode;
044:        import javax.swing.tree.DefaultTreeCellRenderer;
045:        import javax.swing.tree.DefaultTreeModel;
046:        import javax.swing.tree.TreePath;
047:
048:        import de.finix.contelligent.client.base.PackageManager;
049:        import de.finix.contelligent.client.base.Type;
050:        import de.finix.contelligent.client.base.TypeFactory;
051:        import de.finix.contelligent.client.base.TypeNotFoundException;
052:        import de.finix.contelligent.client.i18n.Resources;
053:        import de.finix.contelligent.client.modules.AbstractModule;
054:        import de.finix.contelligent.client.modules.ModuleInitException;
055:        import de.finix.contelligent.client.modules.event.ModuleAdapter;
056:        import de.finix.contelligent.client.modules.event.ModuleEvent;
057:        import de.finix.contelligent.client.modules.preferences.PreferencesModule;
058:
059:        public class TypeModule extends AbstractModule {
060:
061:            private static Logger logger = Logger.getLogger(TypeModule.class
062:                    .getName());
063:
064:            private JTree hierarchyTree;
065:
066:            private TypeTableModel typeTableModel;
067:
068:            private JList types;
069:
070:            private JTree packages;
071:
072:            private TypeTable typeTable;
073:
074:            private Type dummyType; // required to paint empty hierarchy tree
075:
076:            private JSplitPane typeInfoFrame;
077:
078:            private JTextArea description;
079:
080:            private String selectedPackage = "";
081:
082:            public void init() throws ModuleInitException {
083:                Vector<Type> allTypes = new Vector<Type>(TypeFactory
084:                        .getInstance().getTypes().values());
085:                // preload type images
086:                for (Iterator i = allTypes.iterator(); i.hasNext();) {
087:                    Type type = ((Type) i.next());
088:                    type.preloadIcon();
089:
090:                    if (dummyType == null) {
091:                        dummyType = type;
092:                    }
093:                }
094:                try {
095:                    setPreferredSize(new Dimension(800, 600));
096:
097:                    DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode(
098:                            "system");
099:                    PackageManager.Package pkg = null;
100:                    for (Iterator i = PackageManager.getInstance()
101:                            .getPackages().iterator(); i.hasNext();) {
102:                        pkg = (PackageManager.Package) i.next();
103:                        DefaultMutableTreeNode node = new DefaultMutableTreeNode(
104:                                pkg);
105:                        rootNode.add(node);
106:                    }
107:                    if (pkg != null) {
108:                        Vector typeList = getTypeList(pkg);
109:
110:                        packages = new JTree(rootNode);
111:                        packages.setRootVisible(false);
112:                        packages.addMouseListener(new MouseAdapter() {
113:                            public void mousePressed(MouseEvent e) {
114:                                TreePath path = packages.getPathForLocation(e
115:                                        .getX(), e.getY());
116:                                packages.setSelectionPath(path);
117:
118:                                DefaultMutableTreeNode node = (DefaultMutableTreeNode) packages
119:                                        .getLastSelectedPathComponent();
120:                                if (node == null)
121:                                    return;
122:                                if (node.getUserObject() instanceof  PackageManager.Package) {
123:                                    PackageManager.Package pkg = (PackageManager.Package) node
124:                                            .getUserObject();
125:                                    DefaultListModel listModel = new DefaultListModel();
126:                                    selectedPackage = pkg.getIdentifier();
127:                                    Vector typeList = getTypeList(pkg);
128:                                    for (Iterator iterator = typeList
129:                                            .iterator(); iterator.hasNext();) {
130:                                        listModel.addElement(iterator.next());
131:                                    }
132:                                    types.setModel(listModel);
133:                                    typeTableModel.setType(null);
134:                                    DefaultTreeModel treeModel = new DefaultTreeModel(
135:                                            new DefaultMutableTreeNode(
136:                                                    dummyType));
137:                                    hierarchyTree.setModel(treeModel);
138:                                    hierarchyTree.setRootVisible(false);
139:
140:                                }
141:                            }
142:                        });
143:                        JLabel packageLabel = new JLabel(Resources
144:                                .getLocalString("packages"));
145:                        JScrollPane packageScroller = new JScrollPane(packages);
146:                        JPanel packagePanel = new JPanel(new BorderLayout());
147:                        packagePanel.setOpaque(false);
148:                        packagePanel.add(packageLabel, BorderLayout.NORTH);
149:                        packagePanel.add(packageScroller, BorderLayout.CENTER);
150:                        packagePanel.setMinimumSize(new Dimension(150, 150));
151:
152:                        types = new JList();
153:                        types.setBackground(Color.white);
154:                        types.setCellRenderer(new TypeRenderer());
155:                        types
156:                                .addListSelectionListener(new ListSelectionListener() {
157:                                    public void valueChanged(
158:                                            ListSelectionEvent event) {
159:                                        JList types = (JList) event.getSource();
160:                                        Type selectedType = (Type) types
161:                                                .getSelectedValue();
162:
163:                                        if (selectedType != null) {
164:                                            typeTableModel
165:                                                    .setType(selectedType);
166:                                            DefaultMutableTreeNode node = new DefaultMutableTreeNode(
167:                                                    selectedType);
168:                                            DefaultMutableTreeNode rootNode = createHierarchy(
169:                                                    selectedType
170:                                                            .getSuperTypeName(),
171:                                                    node);
172:                                            DefaultTreeModel treeModel = new DefaultTreeModel(
173:                                                    rootNode);
174:                                            hierarchyTree.setModel(treeModel);
175:                                            hierarchyTree.setRootVisible(true);
176:                                            hierarchyTree
177:                                                    .scrollPathToVisible(new TreePath(
178:                                                            node.getPath()));
179:                                            String descText = (selectedType
180:                                                    .isBlueprint() ? Resources
181:                                                    .getLocalString("type_blueprint")
182:                                                    + ": "
183:                                                    + selectedType
184:                                                            .getBlueprintPath()
185:                                                    : Resources
186:                                                            .getLocalString("type_basic"))
187:                                                    + "\n\n"
188:                                                    + selectedType
189:                                                            .getDescriptionText(PreferencesModule
190:                                                                    .getDefaultLanguage());
191:                                            description.setText(descText);
192:                                        }
193:                                    }
194:                                });
195:
196:                        JScrollPane typeScroller = new JScrollPane(types);
197:                        JLabel typeLabel = new JLabel(Resources
198:                                .getLocalString("types"));
199:                        JPanel typePanel = new JPanel(new BorderLayout());
200:                        typePanel.setOpaque(false);
201:                        typePanel.add(typeLabel, BorderLayout.NORTH);
202:                        typePanel.add(typeScroller, BorderLayout.CENTER);
203:
204:                        JLabel treeLabel = new JLabel(Resources
205:                                .getLocalString("type_hierarchy"));
206:                        hierarchyTree = new JTree(new DefaultMutableTreeNode(
207:                                dummyType));
208:                        hierarchyTree.setRootVisible(false);
209:                        hierarchyTree
210:                                .setCellRenderer(new TypeTreeCellRenderer());
211:                        JScrollPane treeScroller = new JScrollPane(
212:                                hierarchyTree);
213:                        JPanel treePanel = new JPanel(new BorderLayout());
214:                        treePanel.setOpaque(false);
215:                        treePanel.add(treeLabel, BorderLayout.NORTH);
216:                        treePanel.add(treeScroller, BorderLayout.CENTER);
217:
218:                        JLabel tableLabel = new JLabel(Resources
219:                                .getLocalString("type_properties"));
220:                        JPanel tablePanel = new JPanel(new BorderLayout());
221:                        tablePanel.setOpaque(false);
222:                        typeTableModel = new TypeTableModel(null);
223:                        typeTable = new TypeTable(typeTableModel);
224:                        typeTable.getColumnModel().getColumn(0)
225:                                .setPreferredWidth(50);
226:                        typeTable.getColumnModel().getColumn(1)
227:                                .setPreferredWidth(100);
228:                        typeTable.getColumnModel().getColumn(2)
229:                                .setPreferredWidth(30);
230:                        typeTable.getColumnModel().getColumn(3)
231:                                .setPreferredWidth(10);
232:                        typeTable.getColumnModel().getColumn(4)
233:                                .setPreferredWidth(10);
234:                        typeTable.getColumnModel().getColumn(5)
235:                                .setPreferredWidth(5);
236:                        typeTable.getColumnModel().getColumn(6)
237:                                .setPreferredWidth(30);
238:                        typeTable.getColumnModel().getColumn(7)
239:                                .setPreferredWidth(75);
240:                        JScrollPane tableScroller = new JScrollPane(typeTable);
241:                        tableScroller.getViewport().setOpaque(false);
242:                        tableScroller.setOpaque(false);
243:                        tablePanel.add(tableLabel, BorderLayout.NORTH);
244:                        tablePanel.add(tableScroller, BorderLayout.CENTER);
245:
246:                        JSplitPane mainFrame = new JSplitPane(
247:                                JSplitPane.VERTICAL_SPLIT);
248:                        mainFrame.setOpaque(false);
249:
250:                        JSplitPane upperFrame = new JSplitPane(
251:                                JSplitPane.HORIZONTAL_SPLIT);
252:                        upperFrame.setOpaque(false);
253:                        upperFrame.setLeftComponent(packagePanel);
254:
255:                        JSplitPane typeFrame = new JSplitPane(
256:                                JSplitPane.HORIZONTAL_SPLIT);
257:                        typeFrame.setOpaque(false);
258:                        typeFrame.setLeftComponent(typePanel);
259:                        typeFrame.setRightComponent(treePanel);
260:                        upperFrame.setRightComponent(typeFrame);
261:
262:                        JLabel typeDescriptionLabel = new JLabel(Resources
263:                                .getLocalString("type_description"));
264:                        JPanel typeDescriptionPanel = new JPanel(
265:                                new BorderLayout());
266:                        typeDescriptionPanel.setOpaque(false);
267:                        description = new JTextArea();
268:                        description.setEditable(false);
269:                        description.setLineWrap(true);
270:                        description.setText(Resources
271:                                .getLocalString("no_type_selected"));
272:                        JScrollPane typeDescriptionScroller = new JScrollPane(
273:                                description);
274:                        typeDescriptionPanel.add(typeDescriptionLabel,
275:                                BorderLayout.NORTH);
276:                        typeDescriptionPanel.add(typeDescriptionScroller,
277:                                BorderLayout.CENTER);
278:
279:                        typeInfoFrame = new JSplitPane(
280:                                JSplitPane.VERTICAL_SPLIT);
281:                        typeInfoFrame.setOpaque(false);
282:                        typeInfoFrame.setTopComponent(tablePanel);
283:                        typeInfoFrame.setBottomComponent(typeDescriptionPanel);
284:
285:                        mainFrame.setTopComponent(upperFrame);
286:                        mainFrame.setBottomComponent(typeInfoFrame);
287:
288:                        add(mainFrame, BorderLayout.CENTER);
289:
290:                        addModuleListener(new ModuleAdapter() {
291:                            public void moduleActivated(ModuleEvent event) {
292:                                typeInfoFrame.setDividerLocation(0.5);
293:                            }
294:                        });
295:
296:                    }
297:                } catch (Throwable t) {
298:                    throw new ModuleInitException(
299:                            "Type module could not be initialized", t);
300:                }
301:            }
302:
303:            private DefaultMutableTreeNode createHierarchy(
304:                    String super TypeName, DefaultMutableTreeNode node) {
305:                if (super TypeName == null)
306:                    return node;
307:                // recursive request to supertype...
308:                try {
309:                    Type super Type = TypeFactory.getInstance().getType(
310:                            super TypeName);
311:                    DefaultMutableTreeNode parentNode = new DefaultMutableTreeNode(
312:                            super Type);
313:                    parentNode.add(node);
314:                    return createHierarchy(super Type.getSuperTypeName(),
315:                            parentNode);
316:                } catch (TypeNotFoundException e) {
317:                    // serverside configuration error
318:                    logger.log(Level.SEVERE,
319:                            "Type not found - server configuration error!", e);
320:                    return null;
321:                }
322:            }
323:
324:            private Vector getTypeList(PackageManager.Package pkg) {
325:                Vector<Type> typeList = new Vector<Type>(TypeFactory
326:                        .getInstance().getTypes(pkg).values());
327:
328:                Collections.sort(typeList, new Comparator<Type>() {
329:                    public int compare(Type t1, Type t2) {
330:                        String s1 = t1.getName();
331:                        String s2 = t2.getName();
332:                        return (s1.compareTo(s2));
333:                    }
334:
335:                    public boolean equals(Object obj) {
336:                        if (obj == this )
337:                            return true;
338:                        return false;
339:                    }
340:
341:                    public int hashCode() {
342:                        return -1;
343:                    }
344:                });
345:                return typeList;
346:            }
347:
348:            private class TypeRenderer extends JLabel implements 
349:                    ListCellRenderer {
350:
351:                public TypeRenderer() {
352:                    setOpaque(true);
353:                    setHorizontalAlignment(LEFT);
354:                    setVerticalAlignment(CENTER);
355:                }
356:
357:                public java.awt.Component getListCellRendererComponent(
358:                        JList list, Object value, int index,
359:                        boolean isSelected, boolean cellHasFocus) {
360:
361:                    if (isSelected) {
362:                        setBackground(list.getSelectionBackground());
363:                        setForeground(list.getSelectionForeground());
364:                    } else {
365:                        setBackground(Color.white);
366:                        setForeground(list.getForeground());
367:                    }
368:
369:                    Type type = (Type) value;
370:                    setIcon(type.getIcon());
371:                    setText(type.getName().substring(
372:                            selectedPackage.length() + 1));
373:
374:                    return this ;
375:                }
376:            }
377:
378:            class TypeTreeCellRenderer extends DefaultTreeCellRenderer {
379:                public java.awt.Component getTreeCellRendererComponent(
380:                        JTree tree, Object value, boolean selected,
381:                        boolean expanded, boolean leaf, int row,
382:                        boolean hasFocus) {
383:
384:                    super .getTreeCellRendererComponent(tree, value, selected,
385:                            expanded, leaf, row, hasFocus);
386:
387:                    Type type = (Type) ((DefaultMutableTreeNode) value)
388:                            .getUserObject();
389:                    setIcon(type.getIcon());
390:                    setText(type.getName());
391:                    return this;
392:                }
393:            }
394:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.