Source Code Cross Referenced for SimpleNavigatorPanel.java in  » Workflow-Engines » JaWE » org » enhydra » jawe » components » simplenavigator » 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 » JaWE » org.enhydra.jawe.components.simplenavigator 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.enhydra.jawe.components.simplenavigator;
002:
003:        import java.awt.BorderLayout;
004:        import java.awt.Color;
005:        import java.awt.Point;
006:        import java.awt.Rectangle;
007:        import java.awt.event.MouseAdapter;
008:        import java.awt.event.MouseEvent;
009:        import java.awt.event.MouseListener;
010:        import java.util.ArrayList;
011:        import java.util.Iterator;
012:        import java.util.List;
013:
014:        import javax.swing.BorderFactory;
015:        import javax.swing.JComponent;
016:        import javax.swing.JPanel;
017:        import javax.swing.JPopupMenu;
018:        import javax.swing.JScrollPane;
019:        import javax.swing.JToolBar;
020:        import javax.swing.JTree;
021:        import javax.swing.JViewport;
022:        import javax.swing.ScrollPaneConstants;
023:        import javax.swing.SwingUtilities;
024:        import javax.swing.tree.TreeModel;
025:        import javax.swing.tree.TreePath;
026:        import javax.swing.tree.TreeSelectionModel;
027:
028:        import org.enhydra.jawe.BarFactory;
029:        import org.enhydra.jawe.JaWEComponent;
030:        import org.enhydra.jawe.JaWEComponentView;
031:        import org.enhydra.jawe.JaWEManager;
032:        import org.enhydra.jawe.XPDLElementChangeInfo;
033:        import org.enhydra.jawe.base.controller.JaWEActions;
034:        import org.enhydra.jawe.components.XPDLTreeCellRenderer;
035:        import org.enhydra.jawe.components.XPDLTreeModel;
036:        import org.enhydra.jawe.components.XPDLTreeNode;
037:        import org.enhydra.shark.xpdl.XMLCollection;
038:        import org.enhydra.shark.xpdl.XMLElement;
039:        import org.enhydra.shark.xpdl.XMLElementChangeInfo;
040:        import org.enhydra.shark.xpdl.elements.Activities;
041:        import org.enhydra.shark.xpdl.elements.Activity;
042:        import org.enhydra.shark.xpdl.elements.ActivitySet;
043:        import org.enhydra.shark.xpdl.elements.ActivitySets;
044:        import org.enhydra.shark.xpdl.elements.Package;
045:        import org.enhydra.shark.xpdl.elements.Transition;
046:        import org.enhydra.shark.xpdl.elements.Transitions;
047:        import org.enhydra.shark.xpdl.elements.WorkflowProcess;
048:        import org.enhydra.shark.xpdl.elements.WorkflowProcesses;
049:
050:        /**
051:         *  Used to display Package hierarchy tree.
052:         *
053:         *  @author Sasa Bojanic
054:         */
055:        public class SimpleNavigatorPanel extends JPanel implements 
056:                JaWEComponentView {
057:
058:            protected XPDLTreeModel treeModel;
059:
060:            protected JTree tree;
061:
062:            protected JToolBar toolbar;
063:            protected JScrollPane scrollPane;
064:            protected SimpleNavigator controller;
065:            protected int xClick, yClick;
066:
067:            protected MouseListener mouseListener;
068:            protected XPDLTreeCellRenderer renderer;
069:
070:            public SimpleNavigatorPanel(SimpleNavigator controller) {
071:                this .controller = controller;
072:            }
073:
074:            public void configure() {
075:                //      setLayout(new BoxLayout(this,BoxLayout.X_AXIS));
076:                setBorder(BorderFactory.createEtchedBorder());
077:                setLayout(new BorderLayout());
078:                toolbar = BarFactory
079:                        .createToolbar("defaultToolbar", controller);
080:                toolbar.setFloatable(false);
081:                if (toolbar.getComponentCount() > 0) {
082:                    add(toolbar, BorderLayout.NORTH);
083:                }
084:                init();
085:            }
086:
087:            public void printTreeModel() {
088:                printTreeModel(treeModel.getRootNode());
089:            }
090:
091:            public void printTreeModel(XPDLTreeNode n) {
092:                System.err.println("There are " + n.getChildCount()
093:                        + " children for " + n.getXPDLElement());
094:                for (int i = 0; i < n.getChildCount(); i++) {
095:                    printTreeModel((XPDLTreeNode) n.getChildAt(i));
096:                }
097:
098:            }
099:
100:            public void init() {
101:                controller.getSettings().adjustActions();
102:                treeModel = new SimpleNavigatorTreeModel(controller);
103:
104:                tree = new JTree(treeModel) {
105:                    public void scrollRectToVisible(Rectangle aRect) {
106:                        aRect.x = scrollPane.getHorizontalScrollBar()
107:                                .getValue();
108:                        super .scrollRectToVisible(aRect);
109:                    }
110:                };
111:
112:                // setting some tree properties
113:                tree.getSelectionModel().setSelectionMode(
114:                        TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
115:                tree.setRootVisible(false);
116:                tree.setShowsRootHandles(true);
117:                renderer = new XPDLTreeCellRenderer(controller);
118:                Color bckColor = controller.getNavigatorSettings()
119:                        .getBackGroundColor();
120:
121:                renderer.setBackgroundNonSelectionColor(bckColor);
122:                renderer.setBackgroundSelectionColor(controller
123:                        .getNavigatorSettings().getSelectionColor());
124:                tree.setBackground(bckColor);
125:                tree.setCellRenderer(renderer);
126:                tree.addTreeSelectionListener(controller);
127:
128:                /** MouseListener for JTree */
129:                mouseListener = new MouseAdapter() {
130:                    public void mouseClicked(MouseEvent me) {
131:                        xClick = me.getX();
132:                        yClick = me.getY();
133:                        TreePath path = tree.getPathForLocation(xClick, yClick);
134:
135:                        if (path != null) {
136:                            tree.setAnchorSelectionPath(path);
137:
138:                            if (SwingUtilities.isRightMouseButton(me)) {
139:                                if (!tree.isPathSelected(path)) {
140:                                    tree.setSelectionPath(path);
141:                                }
142:
143:                                JPopupMenu popup = BarFactory.createPopupMenu(
144:                                        "default", controller);
145:
146:                                popup.show(tree, me.getX(), me.getY());
147:                            }
148:
149:                            XPDLTreeNode node = (XPDLTreeNode) path
150:                                    .getLastPathComponent();
151:
152:                            if (me.getClickCount() > 1
153:                                    && !SwingUtilities.isRightMouseButton(me)
154:                                    && tree.getModel().isLeaf(node)) {
155:                                JaWEManager
156:                                        .getInstance()
157:                                        .getJaWEController()
158:                                        .getJaWEActions()
159:                                        .getAction(
160:                                                JaWEActions.EDIT_PROPERTIES_ACTION)
161:                                        .actionPerformed(null);
162:                            }
163:                        } else {
164:                            TreePath close = tree.getClosestPathForLocation(
165:                                    xClick, yClick);
166:                            Rectangle rect = tree.getPathBounds(close);
167:                            if (rect == null
168:                                    || !(rect.y < yClick && rect.y
169:                                            + rect.height > yClick)) {
170:                                JaWEManager.getInstance().getJaWEController()
171:                                        .getSelectionManager().setSelection(
172:                                                (XMLElement) null, false);
173:                                tree.clearSelection();
174:                            }
175:                        }
176:
177:                        tree.getParent().requestFocus();
178:                    }
179:                };
180:
181:                tree.addMouseListener(mouseListener);
182:
183:                // creates panel
184:                scrollPane = new JScrollPane();
185:                scrollPane
186:                        .setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
187:                scrollPane
188:                        .setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
189:                scrollPane.setViewportView(tree);
190:                JViewport port = scrollPane.getViewport();
191:                port.setScrollMode(JViewport.BLIT_SCROLL_MODE);
192:                scrollPane.setBackground(Color.lightGray);
193:                //scrollPane.getVerticalScrollBar().setUnitIncrement(20);
194:                //      scrollPane.getHorizontalScrollBar().setUnitIncrement(40);
195:
196:                add(scrollPane, BorderLayout.CENTER);
197:            }
198:
199:            public TreeModel getTreeModel() {
200:                return treeModel;
201:            }
202:
203:            public JTree getTree() {
204:                return tree;
205:            }
206:
207:            public JaWEComponent getJaWEComponent() {
208:                return controller;
209:            }
210:
211:            public JComponent getDisplay() {
212:                return this ;
213:            }
214:
215:            public Point getMouseClickLocation() {
216:                return new Point(xClick, yClick);
217:            }
218:
219:            public void handleXPDLChangeEvent(XPDLElementChangeInfo info) {
220:                int action = info.getAction();
221:                XMLElement el = info.getChangedElement();
222:                List l = info.getChangedSubElements();
223:
224:                tree.removeTreeSelectionListener(controller);
225:
226:                if (action == XPDLElementChangeInfo.SELECTED) {
227:                    tree.clearSelection();
228:                }
229:
230:                if (el instanceof  Activity
231:                        || el instanceof  Package
232:                        || el instanceof  WorkflowProcesses
233:                        || el instanceof  WorkflowProcess
234:                        || el instanceof  ActivitySets
235:                        || el instanceof  ActivitySet
236:                        || el instanceof  Activities
237:                        || (el instanceof  Transitions && action == XPDLElementChangeInfo.SELECTED)) {
238:                    if (action == XMLElementChangeInfo.INSERTED) {
239:                        if (l != null && l.size() > 0) {
240:                            Iterator it1 = l.iterator();
241:                            while (it1.hasNext()) {
242:                                treeModel.insertNode((XMLElement) it1.next());
243:                            }
244:                        } else {
245:                            if (el instanceof  Package) {
246:                                treeModel.insertNode(el);
247:                            }
248:                        }
249:                        if (el instanceof  Package) {
250:                            controller.getSettings().adjustActions();
251:                        }
252:                    } else if (action == XMLElementChangeInfo.REMOVED) {
253:                        if (l != null && l.size() > 0) {
254:                            Iterator it1 = l.iterator();
255:                            while (it1.hasNext()) {
256:                                treeModel.removeNode((XMLElement) it1.next());
257:                            }
258:                        } else {
259:                            treeModel.removeNode(el);
260:                        }
261:                        if (treeModel.getRootNode().getChildCount() == 0) {
262:                            reinitialize();
263:                            return;
264:                        }
265:                    } else if (action == XPDLElementChangeInfo.SELECTED) {
266:                        if (el != null) {
267:                            List toSelect = new ArrayList();
268:                            if (l != null) {
269:                                toSelect.addAll(l);
270:                            }
271:                            if (toSelect.size() == 0) {
272:                                toSelect.add(el);
273:                            }
274:                            for (int i = 0; i < toSelect.size(); i++) {
275:                                XMLElement toSel = (XMLElement) toSelect.get(i);
276:                                if (toSelect instanceof  Transitions
277:                                        || toSelect instanceof  Transition) {
278:                                    continue;
279:                                }
280:                                XPDLTreeNode n = treeModel.findNode(toSel);
281:                                TreePath tp = null;
282:                                if (n != null) {
283:                                    tp = new TreePath(n.getPath());
284:                                    tree.addSelectionPath(tp);
285:                                }
286:                                if (tp != null) {
287:                                    tree.scrollPathToVisible(tp);
288:                                }
289:                            }
290:                        }
291:                    } else if (action == XMLElementChangeInfo.REPOSITIONED) {
292:                        List elsToReposition = new ArrayList();
293:                        List newPositions = new ArrayList();
294:                        if (el instanceof  XMLCollection) {
295:                            if (l != null) {
296:                                elsToReposition.addAll(l);
297:                                newPositions.addAll((List) info.getNewValue());
298:                            }
299:                            for (int j = 0; j < elsToReposition.size(); j++) {
300:                                XMLElement eltr = (XMLElement) elsToReposition
301:                                        .get(j);
302:                                treeModel.repositionNode(eltr,
303:                                        ((Integer) newPositions.get(j))
304:                                                .intValue());
305:                            }
306:                        }
307:                    }
308:                }
309:
310:                tree.addTreeSelectionListener(controller);
311:            }
312:
313:            protected void reinitialize() {
314:                remove(scrollPane);
315:                treeModel.clearTree();
316:                tree.getSelectionModel().clearSelection();
317:                tree.removeMouseListener(mouseListener);
318:                tree.removeTreeSelectionListener(controller);
319:                tree.setCellRenderer(null);
320:                init();
321:            }
322:
323:            // before doing this, listener has to be removed
324:            public void setCurrentSelection() {
325:                List toSelect = JaWEManager.getInstance().getJaWEController()
326:                        .getSelectionManager().getSelectedElements();
327:                for (int i = 0; i < toSelect.size(); i++) {
328:                    XMLElement toSel = (XMLElement) toSelect.get(i);
329:                    if (toSel instanceof  Package
330:                            || toSel instanceof  WorkflowProcess
331:                            || toSel instanceof  ActivitySet
332:                            || toSel instanceof  Activity) {
333:                        XPDLTreeNode n = treeModel.findNode(toSel);
334:                        TreePath tp = null;
335:                        if (n != null) {
336:                            tp = new TreePath(n.getPath());
337:                            tree.addSelectionPath(tp);
338:                        }
339:                        if (tp != null) {
340:                            tree.scrollPathToVisible(tp);
341:                        }
342:                    }
343:                }
344:            }
345:
346:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.