Source Code Cross Referenced for ContextMenuListener.java in  » Workflow-Engines » osbl-1_0 » newprocess » diagram » cust » annotations » contributor » 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 » newprocess.diagram.cust.annotations.contributor 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * 
003:         */package newprocess.diagram.cust.annotations.contributor;
004:
005:        import java.util.Iterator;
006:        import java.util.Vector;
007:
008:        import newprocess.diagram.cust.annotations.actions.FavouriteAnnotationAction;
009:        import newprocess.diagram.cust.annotations.actions.LinkToAction;
010:        import newprocess.diagram.cust.annotations.actions.ManageAnnotationAction;
011:        import newprocess.diagram.cust.annotations.actions.ProgramAnnotationAction;
012:        import newprocess.diagram.cust.annotations.commands.ReadCommand;
013:        import newprocess.diagram.cust.annotations.utils.FeatureUtil;
014:        import newprocess.diagram.cust.annotations.utils.PropertiesPageUtil;
015:
016:        import org.eclipse.core.resources.IProject;
017:        import org.eclipse.emf.common.util.EList;
018:        import org.eclipse.gef.EditPart;
019:        import org.eclipse.gef.GraphicalViewer;
020:        import org.eclipse.jface.action.ActionContributionItem;
021:        import org.eclipse.jface.action.IMenuListener;
022:        import org.eclipse.jface.action.IMenuManager;
023:        import org.eclipse.jface.action.MenuManager;
024:        import org.eclipse.jface.action.Separator;
025:        import org.eclipse.jface.resource.ImageDescriptor;
026:        import org.eclipse.jface.viewers.ISelection;
027:        import org.eclipse.jface.viewers.IStructuredSelection;
028:        import org.eclipse.ui.PlatformUI;
029:        import org.eclipse.ui.ide.IDE.SharedImages;
030:
031:        /**
032:         * @author sh
033:         *
034:         */
035:        public class ContextMenuListener implements  IMenuListener {
036:            private IProject project = null;
037:            private GraphicalViewer viewer = null;
038:            private EditPart selectedEditPart = null;
039:            private IStructuredSelection structuredSelection = null;
040:
041:            /**
042:             * Constructor
043:             */
044:            public ContextMenuListener(GraphicalViewer viewer, IProject project) {
045:                this .project = project;
046:                this .viewer = viewer;
047:            }
048:
049:            /* (non-Javadoc)
050:             * @see org.eclipse.jface.action.IMenuListener#menuAboutToShow(org.eclipse.jface.action.IMenuManager)
051:             */
052:            public void menuAboutToShow(IMenuManager manager) {
053:                // set the selected EditPart
054:                selectionChanged();
055:
056:                // fill the context menu
057:                if (selectedEditPart == null)
058:                    return;
059:                fillContextMenu(manager);
060:            }
061:
062:            /**
063:             * fill the context Menu with entries
064:             */
065:            private void fillContextMenu(IMenuManager manager) {
066:                manager.setRemoveAllWhenShown(true);
067:                manager.remove("AnnotationsMenuID");
068:
069:                // add a submenu for the Annotations
070:                IMenuManager submenuManager = new MenuManager("Annotations",
071:                        "AnnotationsMenuID");
072:                manager.insertAfter("additions", submenuManager);
073:
074:                // insert some entries specified in the properties sheet page
075:                createProgramsEntries(submenuManager);
076:
077:                // insert the "Link to..." entry
078:                createLinkToEntry(submenuManager);
079:
080:                // insert the "Edit..." entry
081:                createEditEntry(submenuManager);
082:
083:                // insert the favourite annotations
084:                createFavouriteEntries(submenuManager);
085:            }
086:
087:            /**
088:             * create the program entries specified 
089:             * in the properties sheet page 
090:             */
091:            private void createProgramsEntries(IMenuManager submenuManager) {
092:                // in the first release the applications
093:                // "MSWord", "MSExcel", "Websites"
094:                // are specified
095:                submenuManager.add(new Separator("programs"));
096:                PropertiesPageUtil propertiesUtil = new PropertiesPageUtil(
097:                        project.getName());
098:                Vector<ProgramAnnotationAction> actions = propertiesUtil
099:                        .createProgramActions(structuredSelection);
100:                for (Iterator iter = actions.iterator(); iter.hasNext();) {
101:                    ProgramAnnotationAction element = (ProgramAnnotationAction) iter
102:                            .next();
103:                    submenuManager.add(new ActionContributionItem(element));
104:                }
105:            }
106:
107:            /**
108:             * create the "Link to..." entry
109:             */
110:            private void createLinkToEntry(IMenuManager submenuManager) {
111:                submenuManager.add(new Separator("management"));
112:                // create the images
113:                ImageDescriptor linkToImage = PlatformUI.getWorkbench()
114:                        .getSharedImages().getImageDescriptor(
115:                                SharedImages.IMG_OBJS_BKMRK_TSK);
116:                LinkToAction linkAction = new LinkToAction("Link to...",
117:                        linkToImage, selectedEditPart, project.toString());
118:                submenuManager.add(new ActionContributionItem(linkAction));
119:            }
120:
121:            /**
122:             * create the "Edit..." entry
123:             */
124:            private void createEditEntry(IMenuManager submenuManager) {
125:                // create the images
126:                ImageDescriptor manageImage = PlatformUI.getWorkbench()
127:                        .getSharedImages().getImageDescriptor(
128:                                SharedImages.IMG_OBJS_BKMRK_TSK);
129:                ManageAnnotationAction manageAction = new ManageAnnotationAction(
130:                        "Edit...", manageImage, selectedEditPart, project
131:                                .getName());
132:                submenuManager.add(new ActionContributionItem(manageAction));
133:            }
134:
135:            /**
136:             * create the items to be shown in the
137:             * Favourites List of the context menu
138:             */
139:            private void createFavouriteEntries(IMenuManager submenuManager) {
140:                // get the stored Annotations
141:                ReadCommand readCom = new ReadCommand();
142:                EList annotations = readCom.getValues(selectedEditPart);
143:                if (annotations == null)
144:                    return;
145:
146:                // create an action for each annotation
147:                FavouriteAnnotationAction favAction = null;
148:                submenuManager.add(new Separator("favourites"));
149:                for (Iterator iter = annotations.iterator(); iter.hasNext();) {
150:                    String element = (String) iter.next();
151:                    favAction = createFavouriteAction(element);
152:                    submenuManager.add(new ActionContributionItem(favAction));
153:                }
154:            }
155:
156:            /**
157:             * creates the actions for the 
158:             * favourite entries
159:             */
160:            private FavouriteAnnotationAction createFavouriteAction(String path) {
161:                // create the images
162:                ImageDescriptor favouriteImage = PlatformUI.getWorkbench()
163:                        .getSharedImages().getImageDescriptor(
164:                                SharedImages.IMG_OBJS_BKMRK_TSK);
165:                // create an action for each entry
166:                FavouriteAnnotationAction favAction = new FavouriteAnnotationAction(
167:                        project.getName(), path, favouriteImage);
168:                return favAction;
169:            }
170:
171:            /**
172:             * set the specified editPart
173:             */
174:            private void selectionChanged() {
175:                ISelection selection = viewer.getSelection();
176:                if (selection == null) {
177:                    selectedEditPart = null;
178:                    return;
179:                }
180:                if (selection instanceof  IStructuredSelection) {
181:                    structuredSelection = (IStructuredSelection) selection;
182:                    if (!selection.isEmpty()) {
183:                        Object object = structuredSelection.getFirstElement();
184:                        if (object instanceof  EditPart) {
185:                            // check if the given EditPart supports the Annotation mechanism
186:                            FeatureUtil featureUtil = new FeatureUtil();
187:                            boolean isSupported = featureUtil
188:                                    .isAttributeSupported((EditPart) object);
189:                            if (isSupported)
190:                                selectedEditPart = (EditPart) object;
191:                            else
192:                                selectedEditPart = null;
193:                        }
194:                    }
195:                }
196:            }
197:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.