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


001:        package newprocess.diagram.providers;
002:
003:        import java.util.ArrayList;
004:        import java.util.HashMap;
005:        import java.util.Iterator;
006:        import java.util.List;
007:        import java.util.Map;
008:
009:        import newprocess.diagram.edit.parts.ProcessEditPart;
010:
011:        import newprocess.diagram.part.New_processDiagramEditor;
012:        import newprocess.diagram.part.New_processDiagramEditorPlugin;
013:        import newprocess.diagram.part.New_processVisualIDRegistry;
014:
015:        import org.eclipse.core.resources.IFile;
016:        import org.eclipse.core.resources.IMarker;
017:        import org.eclipse.core.resources.IResource;
018:
019:        import org.eclipse.core.runtime.CoreException;
020:
021:        import org.eclipse.draw2d.FlowLayout;
022:        import org.eclipse.draw2d.Label;
023:
024:        import org.eclipse.emf.ecore.resource.Resource;
025:
026:        import org.eclipse.emf.transaction.util.TransactionUtil;
027:
028:        import org.eclipse.emf.workspace.util.WorkspaceSynchronizer;
029:
030:        import org.eclipse.gef.EditDomain;
031:        import org.eclipse.gef.EditPart;
032:        import org.eclipse.gef.GraphicalEditPart;
033:
034:        import org.eclipse.gef.editparts.AbstractConnectionEditPart;
035:
036:        import org.eclipse.gmf.runtime.common.core.service.AbstractProvider;
037:        import org.eclipse.gmf.runtime.common.core.service.IOperation;
038:
039:        import org.eclipse.gmf.runtime.common.ui.resources.FileChangeManager;
040:        import org.eclipse.gmf.runtime.common.ui.resources.IFileObserver;
041:
042:        import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil;
043:
044:        import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditDomain;
045:
046:        import org.eclipse.gmf.runtime.diagram.ui.services.decorator.AbstractDecorator;
047:        import org.eclipse.gmf.runtime.diagram.ui.services.decorator.CreateDecoratorsOperation;
048:        import org.eclipse.gmf.runtime.diagram.ui.services.decorator.IDecorator;
049:        import org.eclipse.gmf.runtime.diagram.ui.services.decorator.IDecoratorProvider;
050:        import org.eclipse.gmf.runtime.diagram.ui.services.decorator.IDecoratorTarget;
051:
052:        import org.eclipse.gmf.runtime.draw2d.ui.mapmode.MapModeUtil;
053:
054:        import org.eclipse.gmf.runtime.notation.Diagram;
055:        import org.eclipse.gmf.runtime.notation.Edge;
056:        import org.eclipse.gmf.runtime.notation.View;
057:
058:        import org.eclipse.swt.graphics.Image;
059:
060:        import org.eclipse.ui.ISharedImages;
061:        import org.eclipse.ui.PlatformUI;
062:
063:        /** 
064:         * @generated
065:         */
066:        public class New_processValidationDecoratorProvider extends
067:                AbstractProvider implements  IDecoratorProvider {
068:            /**
069:             * @generated
070:             */
071:            private static final String KEY = "validationStatus"; //$NON-NLS-1$
072:            /**
073:             * @generated
074:             */
075:            private static final String MARKER_TYPE = New_processDiagramEditorPlugin.ID
076:                    + "." + "diagnostic"; //$NON-NLS-1$ //$NON-NLS-2$
077:            /**
078:             * @generated
079:             */
080:            private static MarkerObserver fileObserver = null;
081:
082:            /**
083:             * @generated
084:             */
085:            public void createDecorators(IDecoratorTarget decoratorTarget) {
086:                EditPart editPart = (EditPart) decoratorTarget
087:                        .getAdapter(EditPart.class);
088:                if (editPart instanceof  org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart
089:                        || editPart instanceof  AbstractConnectionEditPart) {
090:                    Object model = editPart.getModel();
091:                    if ((model instanceof  View)) {
092:                        View view = (View) model;
093:                        if (!(view instanceof  Edge) && !view.isSetElement()) {
094:                            return;
095:                        }
096:                    }
097:                    EditDomain ed = editPart.getViewer().getEditDomain();
098:                    if (!(ed instanceof  DiagramEditDomain)) {
099:                        return;
100:                    }
101:                    if (((DiagramEditDomain) ed).getEditorPart() instanceof  New_processDiagramEditor) {
102:                        decoratorTarget.installDecorator(KEY,
103:                                new StatusDecorator(decoratorTarget));
104:                    }
105:                }
106:            }
107:
108:            /**
109:             * @generated
110:             */
111:            public boolean provides(IOperation operation) {
112:                if (!(operation instanceof  CreateDecoratorsOperation)) {
113:                    return false;
114:                }
115:
116:                IDecoratorTarget decoratorTarget = ((CreateDecoratorsOperation) operation)
117:                        .getDecoratorTarget();
118:                View view = (View) decoratorTarget.getAdapter(View.class);
119:                return view != null
120:                        && ProcessEditPart.MODEL_ID
121:                                .equals(New_processVisualIDRegistry
122:                                        .getModelID(view));
123:            }
124:
125:            /**
126:             * @generated
127:             */
128:            public static class StatusDecorator extends AbstractDecorator {
129:                /**
130:                 * @generated
131:                 */
132:                private String viewId;
133:
134:                /**
135:                 * @generated
136:                 */
137:                public StatusDecorator(IDecoratorTarget decoratorTarget) {
138:                    super (decoratorTarget);
139:                    try {
140:                        final View view = (View) getDecoratorTarget()
141:                                .getAdapter(View.class);
142:                        TransactionUtil.getEditingDomain(view).runExclusive(
143:                                new Runnable() {
144:                                    public void run() {
145:                                        StatusDecorator.this .viewId = view != null ? ViewUtil
146:                                                .getIdStr(view)
147:                                                : null;
148:                                    }
149:                                });
150:                    } catch (Exception e) {
151:                        New_processDiagramEditorPlugin.getInstance().logError(
152:                                "ViewID access failure", e); //$NON-NLS-1$			
153:                    }
154:                }
155:
156:                /**
157:                 * @generated
158:                 */
159:                public void refresh() {
160:                    removeDecoration();
161:
162:                    View view = (View) getDecoratorTarget().getAdapter(
163:                            View.class);
164:                    EditPart editPart = (EditPart) getDecoratorTarget()
165:                            .getAdapter(EditPart.class);
166:                    if (view == null || view.eResource() == null) {
167:                        return;
168:                    }
169:
170:                    IResource resource = getResource(view);
171:                    // make sure we have a resource and that it exists in an open project
172:                    if (resource == null || !resource.exists()) {
173:                        return;
174:                    }
175:
176:                    // query for all the validation markers of the current resource
177:                    IMarker[] markers = null;
178:                    try {
179:                        markers = resource.findMarkers(MARKER_TYPE, true,
180:                                IResource.DEPTH_INFINITE);
181:                    } catch (CoreException e) {
182:                        New_processDiagramEditorPlugin.getInstance().logError(
183:                                "Validation marker refresh failure", e); //$NON-NLS-1$
184:                    }
185:                    if (markers == null || markers.length == 0) {
186:                        return;
187:                    }
188:
189:                    String elementId = ViewUtil.getIdStr(view);
190:                    if (elementId == null) {
191:                        return;
192:                    }
193:
194:                    IMarker foundMarker = null;
195:                    Label toolTip = null;
196:                    int severity = IMarker.SEVERITY_INFO;
197:                    for (int i = 0; i < markers.length; i++) {
198:                        IMarker marker = markers[i];
199:                        String attribute = marker
200:                                .getAttribute(
201:                                        org.eclipse.gmf.runtime.common.ui.resources.IMarker.ELEMENT_ID,
202:                                        ""); //$NON-NLS-1$
203:                        if (attribute.equals(elementId)) {
204:                            int nextSeverity = marker.getAttribute(
205:                                    IMarker.SEVERITY, IMarker.SEVERITY_INFO);
206:                            Image nextImage = getImage(nextSeverity);
207:                            if (foundMarker == null) {
208:                                foundMarker = marker;
209:                                toolTip = new Label(marker.getAttribute(
210:                                        IMarker.MESSAGE, ""), nextImage);
211:                            } else {
212:                                if (toolTip.getChildren().isEmpty()) {
213:                                    Label comositeLabel = new Label();
214:                                    FlowLayout fl = new FlowLayout(false);
215:                                    fl.setMinorSpacing(0);
216:                                    comositeLabel.setLayoutManager(fl);
217:                                    comositeLabel.add(toolTip);
218:                                    toolTip = comositeLabel;
219:                                }
220:                                toolTip.add(new Label(marker.getAttribute(
221:                                        IMarker.MESSAGE, ""), nextImage)); //$NON-NLS-1$
222:                            }
223:                            severity = (nextSeverity > severity) ? nextSeverity
224:                                    : severity;
225:                        }
226:                    }
227:                    if (foundMarker == null) {
228:                        return;
229:                    }
230:
231:                    // add decoration
232:                    if (editPart instanceof  GraphicalEditPart) {
233:                        Image img = getImage(severity);
234:                        if (view instanceof  Edge) {
235:                            setDecoration(getDecoratorTarget()
236:                                    .addConnectionDecoration(img, 50, true));
237:                        } else {
238:                            int margin = -1;
239:                            if (editPart instanceof  GraphicalEditPart) {
240:                                margin = MapModeUtil.getMapMode(
241:                                        ((GraphicalEditPart) editPart)
242:                                                .getFigure()).DPtoLP(margin);
243:                            }
244:                            setDecoration(getDecoratorTarget()
245:                                    .addShapeDecoration(
246:                                            img,
247:                                            IDecoratorTarget.Direction.NORTH_EAST,
248:                                            margin, true));
249:                        }
250:                        getDecoration().setToolTip(toolTip);
251:                    }
252:                }
253:
254:                /**
255:                 * @generated
256:                 */
257:                private Image getImage(int severity) {
258:                    String imageName = ISharedImages.IMG_OBJS_ERROR_TSK;
259:                    switch (severity) {
260:                    case IMarker.SEVERITY_ERROR:
261:                        imageName = ISharedImages.IMG_OBJS_ERROR_TSK;
262:                        break;
263:                    case IMarker.SEVERITY_WARNING:
264:                        imageName = ISharedImages.IMG_OBJS_WARN_TSK;
265:                        break;
266:                    default:
267:                        imageName = ISharedImages.IMG_OBJS_INFO_TSK;
268:                    }
269:                    return PlatformUI.getWorkbench().getSharedImages()
270:                            .getImage(imageName);
271:                }
272:
273:                /**
274:                 * @generated
275:                 */
276:                private static IResource getResource(View view) {
277:                    Resource model = view.eResource();
278:                    if (model != null) {
279:                        return WorkspaceSynchronizer.getFile(model);
280:                    }
281:                    return null;
282:                }
283:
284:                /**
285:                 * @generated
286:                 */
287:                public void activate() {
288:                    View view = (View) getDecoratorTarget().getAdapter(
289:                            View.class);
290:                    if (view == null)
291:                        return;
292:                    Diagram diagramView = view.getDiagram();
293:                    if (diagramView == null)
294:                        return;
295:                    IFile file = WorkspaceSynchronizer.getFile(diagramView
296:                            .eResource());
297:                    if (file != null) {
298:                        if (fileObserver == null) {
299:                            fileObserver = new MarkerObserver(diagramView);
300:                        }
301:
302:                        fileObserver.registerDecorator(this );
303:                    }
304:                }
305:
306:                /**
307:                 * @generated
308:                 */
309:                public void deactivate() {
310:                    if (fileObserver != null) {
311:                        fileObserver.unregisterDecorator(this );
312:                        if (!fileObserver.isRegistered()) {
313:                            fileObserver = null;
314:                        }
315:                    }
316:
317:                    super .deactivate();
318:                }
319:
320:                /**
321:                 * @generated
322:                 */
323:                String getViewId() {
324:                    return viewId;
325:                }
326:            }
327:
328:            /**
329:             * @generated
330:             */
331:            static class MarkerObserver implements  IFileObserver {
332:                /**
333:                 * @generated
334:                 */
335:                private HashMap mapOfIdsToDecorators = null;
336:                /**
337:                 * @generated
338:                 */
339:                private boolean isRegistered = false;
340:                /**
341:                 * @generated
342:                 */
343:                private Diagram diagramView;
344:
345:                /**
346:                 * @generated
347:                 */
348:                private MarkerObserver(Diagram diagramView) {
349:                    this .diagramView = diagramView;
350:                }
351:
352:                /**
353:                 * @generated
354:                 */
355:                private void registerDecorator(StatusDecorator decorator) {
356:                    if (decorator == null) {
357:                        return;
358:                    }
359:
360:                    if (mapOfIdsToDecorators == null) {
361:                        mapOfIdsToDecorators = new HashMap();
362:                    }
363:
364:                    String decoratorViewId = decorator.getViewId();
365:                    if (decoratorViewId == null) {
366:                        return;
367:                    }
368:
369:                    /* Add to the list */
370:                    List list = (List) mapOfIdsToDecorators
371:                            .get(decoratorViewId);
372:                    if (list == null) {
373:                        list = new ArrayList(2);
374:                        list.add(decorator);
375:                        mapOfIdsToDecorators.put(decoratorViewId, list);
376:                    } else if (!list.contains(decorator)) {
377:                        list.add(decorator);
378:                    }
379:
380:                    /* Register with the file change manager */
381:                    if (!isRegistered()) {
382:                        FileChangeManager.getInstance().addFileObserver(this );
383:                        isRegistered = true;
384:                    }
385:                }
386:
387:                /**
388:                 * @generated
389:                 */
390:                private void unregisterDecorator(StatusDecorator decorator) {
391:                    /* Return if invalid decorator */
392:                    if (decorator == null) {
393:                        return;
394:                    }
395:
396:                    /* Return if the decorator has invalid view id */
397:                    String decoratorViewId = decorator.getViewId();
398:                    if (decoratorViewId == null) {
399:                        return;
400:                    }
401:
402:                    if (mapOfIdsToDecorators != null) {
403:                        List list = (List) mapOfIdsToDecorators
404:                                .get(decoratorViewId);
405:                        if (list != null) {
406:                            list.remove(decorator);
407:                            if (list.isEmpty()) {
408:                                mapOfIdsToDecorators.remove(decoratorViewId);
409:                            }
410:                        }
411:
412:                        if (mapOfIdsToDecorators.isEmpty()) {
413:                            mapOfIdsToDecorators = null;
414:                        }
415:                    }
416:
417:                    if (mapOfIdsToDecorators == null) {
418:                        /* Unregister with the file change manager */
419:                        if (isRegistered()) {
420:                            FileChangeManager.getInstance().removeFileObserver(
421:                                    this );
422:                            isRegistered = false;
423:                        }
424:                    }
425:                }
426:
427:                /**
428:                 * @generated
429:                 */
430:                public void handleFileRenamed(IFile oldFile, IFile file) { /* Empty Code */
431:                }
432:
433:                /**
434:                 * @generated
435:                 */
436:                public void handleFileMoved(IFile oldFile, IFile file) { /* Empty Code */
437:                }
438:
439:                /**
440:                 * @generated
441:                 */
442:                public void handleFileDeleted(IFile file) { /* Empty Code */
443:                }
444:
445:                /**
446:                 * @generated
447:                 */
448:                public void handleFileChanged(IFile file) { /* Empty Code */
449:                }
450:
451:                /**
452:                 * @generated
453:                 */
454:                public void handleMarkerAdded(IMarker marker) {
455:                    if (marker
456:                            .getAttribute(
457:                                    org.eclipse.gmf.runtime.common.ui.resources.IMarker.ELEMENT_ID,
458:                                    null) != null) {
459:                        handleMarkerChanged(marker);
460:                    }
461:                }
462:
463:                /**
464:                 * @generated
465:                 */
466:                public void handleMarkerDeleted(IMarker marker, Map attributes) {
467:                    if (mapOfIdsToDecorators == null) {
468:                        return;
469:                    }
470:                    // Extract the element guid from the marker and retrieve
471:                    // corresponding view
472:                    String elementId = (String) attributes
473:                            .get(org.eclipse.gmf.runtime.common.ui.resources.IMarker.ELEMENT_ID);
474:                    List list = elementId != null ? (List) mapOfIdsToDecorators
475:                            .get(elementId) : null;
476:                    if (list != null && !list.isEmpty()) {
477:                        refreshDecorators(list);
478:                    }
479:                }
480:
481:                /**
482:                 * @generated
483:                 */
484:                public void handleMarkerChanged(IMarker marker) {
485:                    if (mapOfIdsToDecorators == null
486:                            || !MARKER_TYPE.equals(getType(marker))) {
487:                        return;
488:                    }
489:                    // Extract the element ID list from the marker and retrieve
490:                    // corresponding view	
491:                    String elementId = marker
492:                            .getAttribute(
493:                                    org.eclipse.gmf.runtime.common.ui.resources.IMarker.ELEMENT_ID,
494:                                    ""); //$NON-NLS-1$
495:                    List list = elementId != null ? (List) mapOfIdsToDecorators
496:                            .get(elementId) : null;
497:
498:                    if (list != null && !list.isEmpty()) {
499:                        refreshDecorators(list);
500:                    }
501:                }
502:
503:                /**
504:                 * @generated
505:                 */
506:                private void refreshDecorators(List decorators) {
507:                    final List decoratorsToRefresh = decorators;
508:                    PlatformUI.getWorkbench().getDisplay().asyncExec(
509:                            new Runnable() {
510:                                public void run() {
511:                                    try {
512:                                        TransactionUtil.getEditingDomain(
513:                                                diagramView).runExclusive(
514:                                                new Runnable() {
515:                                                    public void run() {
516:                                                        for (Iterator it = decoratorsToRefresh
517:                                                                .iterator(); it
518:                                                                .hasNext();) {
519:                                                            IDecorator decorator = (IDecorator) it
520:                                                                    .next();
521:                                                            if (decorator != null) {
522:                                                                decorator
523:                                                                        .refresh();
524:                                                            }
525:                                                        }
526:                                                    }
527:                                                });
528:                                    } catch (Exception e) {
529:                                        New_processDiagramEditorPlugin
530:                                                .getInstance()
531:                                                .logError(
532:                                                        "Decorator refresh failure", e); //$NON-NLS-1$
533:                                    }
534:                                }
535:                            });
536:                }
537:
538:                /**
539:                 * @generated
540:                 */
541:                private boolean isRegistered() {
542:                    return isRegistered;
543:                }
544:
545:                /**
546:                 * @generated
547:                 */
548:                private String getType(IMarker marker) {
549:                    try {
550:                        return marker.getType();
551:                    } catch (CoreException e) {
552:                        New_processDiagramEditorPlugin.getInstance().logError(
553:                                "Validation marker refresh failure", e); //$NON-NLS-1$
554:                        return ""; //$NON-NLS-1$
555:                    }
556:                }
557:            }
558:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.