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


0001:        package newprocess.diagram.part;
0002:
0003:        import java.io.IOException;
0004:
0005:        import java.util.ArrayList;
0006:        import java.util.Collection;
0007:        import java.util.Collections;
0008:        import java.util.HashMap;
0009:        import java.util.Iterator;
0010:        import java.util.Map;
0011:
0012:        import java.util.Map.Entry;
0013:
0014:        import org.eclipse.core.resources.IFile;
0015:        import org.eclipse.core.resources.IResource;
0016:        import org.eclipse.core.resources.IResourceChangeEvent;
0017:        import org.eclipse.core.resources.IResourceChangeListener;
0018:        import org.eclipse.core.resources.IResourceDelta;
0019:        import org.eclipse.core.resources.IResourceDeltaVisitor;
0020:        import org.eclipse.core.resources.IResourceStatus;
0021:        import org.eclipse.core.resources.IStorage;
0022:        import org.eclipse.core.resources.IWorkspace;
0023:        import org.eclipse.core.resources.ResourcesPlugin;
0024:
0025:        import org.eclipse.core.runtime.CoreException;
0026:        import org.eclipse.core.runtime.IPath;
0027:        import org.eclipse.core.runtime.IProgressMonitor;
0028:        import org.eclipse.core.runtime.IStatus;
0029:        import org.eclipse.core.runtime.Status;
0030:
0031:        import org.eclipse.core.runtime.jobs.ISchedulingRule;
0032:        import org.eclipse.core.runtime.jobs.MultiRule;
0033:
0034:        import org.eclipse.emf.common.notify.Notification;
0035:
0036:        import org.eclipse.emf.common.util.URI;
0037:
0038:        import org.eclipse.emf.ecore.EObject;
0039:
0040:        import org.eclipse.emf.ecore.resource.Resource;
0041:        import org.eclipse.emf.ecore.resource.ResourceSet;
0042:
0043:        import org.eclipse.emf.ecore.util.EContentAdapter;
0044:
0045:        import org.eclipse.emf.transaction.NotificationFilter;
0046:        import org.eclipse.emf.transaction.TransactionalEditingDomain;
0047:
0048:        import org.eclipse.emf.workspace.util.WorkspaceSynchronizer;
0049:
0050:        import org.eclipse.gmf.runtime.diagram.ui.resources.editor.document.DiagramDocument;
0051:        import org.eclipse.gmf.runtime.diagram.ui.resources.editor.document.IDiagramDocument;
0052:        import org.eclipse.gmf.runtime.diagram.ui.resources.editor.document.IDiagramDocumentProvider;
0053:        import org.eclipse.gmf.runtime.diagram.ui.resources.editor.document.IDocument;
0054:
0055:        import org.eclipse.gmf.runtime.diagram.ui.resources.editor.ide.document.FileEditorInputProxy;
0056:        import org.eclipse.gmf.runtime.diagram.ui.resources.editor.ide.document.StorageDocumentProvider;
0057:
0058:        import org.eclipse.gmf.runtime.diagram.ui.resources.editor.internal.EditorStatusCodes;
0059:
0060:        import org.eclipse.gmf.runtime.diagram.ui.resources.editor.internal.util.DiagramIOUtil;
0061:
0062:        import org.eclipse.gmf.runtime.notation.Diagram;
0063:
0064:        import org.eclipse.swt.widgets.Display;
0065:
0066:        import org.eclipse.ui.IEditorInput;
0067:        import org.eclipse.ui.IFileEditorInput;
0068:        import org.eclipse.ui.IStorageEditorInput;
0069:
0070:        import org.eclipse.ui.part.FileEditorInput;
0071:
0072:        /**
0073:         * @generated
0074:         */
0075:        public class New_processDocumentProvider extends
0076:                StorageDocumentProvider implements  IDiagramDocumentProvider {
0077:            /**
0078:             * @generated
0079:             */
0080:            private final String myContentObjectURI;
0081:
0082:            /**
0083:             * @generated
0084:             */
0085:            public New_processDocumentProvider() {
0086:                this (null);
0087:            }
0088:
0089:            /**
0090:             * @generated
0091:             */
0092:            public New_processDocumentProvider(String rootObjectURI) {
0093:                myContentObjectURI = rootObjectURI;
0094:            }
0095:
0096:            /**
0097:             * @generated
0098:             */
0099:            protected ElementInfo createElementInfo(Object element)
0100:                    throws CoreException {
0101:                if (false == element instanceof  FileEditorInputProxy) {
0102:                    throw new CoreException(new Status(IStatus.ERROR,
0103:                            New_processDiagramEditorPlugin.ID, 0,
0104:                            "Incorrect element used: " + element
0105:                                    + " instead of FileEditorInputProxy", null));
0106:                }
0107:                FileEditorInputProxy editorInput = (FileEditorInputProxy) element;
0108:                IDiagramDocument document = (IDiagramDocument) createDocument(editorInput);
0109:
0110:                ResourceSetInfo info = new ResourceSetInfo(document,
0111:                        editorInput);
0112:                info.setModificationStamp(computeModificationStamp(info));
0113:                info.fStatus = null;
0114:                ResourceSetModificationListener modificationListener = new ResourceSetModificationListener(
0115:                        info);
0116:                info.getResourceSet().eAdapters().add(modificationListener);
0117:                return info;
0118:            }
0119:
0120:            /**
0121:             * @generated
0122:             */
0123:            private long computeModificationStamp(ResourceSetInfo info) {
0124:                int result = 0;
0125:                for (Iterator it = info.getResourceSet().getResources()
0126:                        .iterator(); it.hasNext();) {
0127:                    Resource nextResource = (Resource) it.next();
0128:                    IFile file = WorkspaceSynchronizer.getFile(nextResource);
0129:                    if (file != null) {
0130:                        if (file.getLocation() != null) {
0131:                            result += file.getLocation().toFile()
0132:                                    .lastModified();
0133:                        } else {
0134:                            result += file.getModificationStamp();
0135:                        }
0136:                    }
0137:                }
0138:                return result;
0139:            }
0140:
0141:            /**
0142:             * @generated
0143:             */
0144:            protected IDocument createEmptyDocument() {
0145:                return new DiagramDocument();
0146:            }
0147:
0148:            /**
0149:             * @generated
0150:             */
0151:            protected boolean setDocumentContent(IDocument document,
0152:                    IEditorInput editorInput) throws CoreException {
0153:                if (editorInput instanceof  FileEditorInputProxy
0154:                        && document instanceof  IDiagramDocument) {
0155:                    FileEditorInputProxy editorInputProxy = (FileEditorInputProxy) editorInput;
0156:                    IDiagramDocument diagramDocument = (IDiagramDocument) document;
0157:                    diagramDocument.setEditingDomain(editorInputProxy
0158:                            .getEditingDomain());
0159:                }
0160:                return super .setDocumentContent(document, editorInput);
0161:            }
0162:
0163:            /**
0164:             * @generated
0165:             */
0166:            protected void setDocumentContentFromStorage(IDocument document,
0167:                    IStorage storage) throws CoreException {
0168:                IDiagramDocument diagramDocument = (IDiagramDocument) document;
0169:                Diagram diagram = diagramDocument.getDiagram();
0170:
0171:                TransactionalEditingDomain domain = diagramDocument
0172:                        .getEditingDomain();
0173:                diagram = DiagramIOUtil.load(domain, storage, true,
0174:                        getProgressMonitor());
0175:                if (myContentObjectURI != null
0176:                        && diagram != null
0177:                        && diagram.eResource() != null
0178:                        && !diagram.eResource().getURIFragment(diagram).equals(
0179:                                myContentObjectURI)) {
0180:                    EObject anotherContentObject = diagram.eResource()
0181:                            .getEObject(myContentObjectURI);
0182:                    document.setContent(anotherContentObject);
0183:                } else {
0184:                    document.setContent(diagram);
0185:                }
0186:            }
0187:
0188:            /**
0189:             * @generated
0190:             */
0191:            public long getModificationStamp(Object element) {
0192:                ResourceSetInfo info = getResourceSetInfo(element);
0193:                if (info != null) {
0194:                    return computeModificationStamp(info);
0195:                }
0196:                return super .getModificationStamp(element);
0197:            }
0198:
0199:            /**
0200:             * @generated
0201:             */
0202:            public long getSynchronizationStamp(Object element) {
0203:                if (element instanceof  FileEditorInputProxy) {
0204:                    ResourceSetInfo info = getResourceSetInfo(element);
0205:                    if (info != null) {
0206:                        return info.getModificationStamp();
0207:                    }
0208:                }
0209:                return super .getSynchronizationStamp(element);
0210:            }
0211:
0212:            /**
0213:             * @generated
0214:             */
0215:            public boolean isDeleted(Object element) {
0216:                if (element instanceof  IFileEditorInput) {
0217:                    IFileEditorInput input = (IFileEditorInput) element;
0218:                    IPath path = input.getFile().getLocation();
0219:                    if (path == null) {
0220:                        return true;
0221:                    }
0222:                    return !path.toFile().exists();
0223:                }
0224:                return super .isDeleted(element);
0225:            }
0226:
0227:            /**
0228:             * @generated
0229:             */
0230:            public ResourceSetInfo getResourceSetInfo(Object editorInput) {
0231:                return (ResourceSetInfo) super .getElementInfo(editorInput);
0232:            }
0233:
0234:            /**
0235:             * @generated
0236:             */
0237:            protected void disposeElementInfo(Object element, ElementInfo info) {
0238:                if (info instanceof  ResourceSetInfo) {
0239:                    ResourceSetInfo resourceSetInfo = (ResourceSetInfo) info;
0240:                    resourceSetInfo.dispose();
0241:                }
0242:                super .disposeElementInfo(element, info);
0243:            }
0244:
0245:            /**
0246:             * @generated
0247:             */
0248:            protected void doValidateState(Object element,
0249:                    Object computationContext) throws CoreException {
0250:                ResourceSetInfo info = getResourceSetInfo(element);
0251:                if (info != null) {
0252:                    Collection files2Validate = new ArrayList();
0253:                    for (Iterator it = info.getResourceSet().getResources()
0254:                            .iterator(); it.hasNext();) {
0255:                        Resource nextResource = (Resource) it.next();
0256:                        IFile file = WorkspaceSynchronizer
0257:                                .getFile(nextResource);
0258:                        if (file != null && file.isReadOnly()) {
0259:                            files2Validate.add(file);
0260:                        }
0261:                    }
0262:                    ResourcesPlugin.getWorkspace().validateEdit(
0263:                            (IFile[]) files2Validate
0264:                                    .toArray(new IFile[files2Validate.size()]),
0265:                            computationContext);
0266:                }
0267:
0268:                super .doValidateState(element, computationContext);
0269:            }
0270:
0271:            /**
0272:             * @generated
0273:             */
0274:            public boolean isModifiable(Object element) {
0275:                if (!isStateValidated(element)) {
0276:                    if (element instanceof  FileEditorInputProxy) {
0277:                        return true;
0278:                    }
0279:                }
0280:                return super .isModifiable(element);
0281:            }
0282:
0283:            /**
0284:             * @generated
0285:             */
0286:            protected void updateCache(IStorageEditorInput input)
0287:                    throws CoreException {
0288:                ResourceSetInfo info = getResourceSetInfo(input);
0289:                if (info != null) {
0290:                    for (Iterator it = info.getResourceSet().getResources()
0291:                            .iterator(); it.hasNext();) {
0292:                        Resource nextResource = (Resource) it.next();
0293:                        IFile file = WorkspaceSynchronizer
0294:                                .getFile(nextResource);
0295:                        if (file != null && file.isReadOnly()) {
0296:                            info.fIsReadOnly = true;
0297:                            info.fIsModifiable = false;
0298:                            return;
0299:                        }
0300:                    }
0301:                    info.fIsReadOnly = false;
0302:                    info.fIsModifiable = true;
0303:                    return;
0304:                }
0305:                super .updateCache(input);
0306:            }
0307:
0308:            /**
0309:             * @generated
0310:             */
0311:            public boolean isSynchronized(Object element) {
0312:                ResourceSetInfo info = getResourceSetInfo(element);
0313:                if (info != null) {
0314:                    return info.isSynchronized();
0315:                }
0316:                return super .isSynchronized(element);
0317:            }
0318:
0319:            /**
0320:             * @generated
0321:             */
0322:            protected ISchedulingRule getResetRule(Object element) {
0323:                ResourceSetInfo info = getResourceSetInfo(element);
0324:                if (info != null) {
0325:                    Collection rules = new ArrayList();
0326:                    for (Iterator it = info.getResourceSet().getResources()
0327:                            .iterator(); it.hasNext();) {
0328:                        Resource nextResource = (Resource) it.next();
0329:                        IFile file = WorkspaceSynchronizer
0330:                                .getFile(nextResource);
0331:                        if (file != null) {
0332:                            rules.add(ResourcesPlugin.getWorkspace()
0333:                                    .getRuleFactory().modifyRule(file));
0334:                        }
0335:                    }
0336:                    return new MultiRule((ISchedulingRule[]) rules
0337:                            .toArray(new ISchedulingRule[rules.size()]));
0338:                }
0339:                return null;
0340:            }
0341:
0342:            /**
0343:             * @generated
0344:             */
0345:            protected ISchedulingRule getSaveRule(Object element) {
0346:                ResourceSetInfo info = getResourceSetInfo(element);
0347:                if (info != null) {
0348:                    Collection rules = new ArrayList();
0349:                    for (Iterator it = info.getResourceSet().getResources()
0350:                            .iterator(); it.hasNext();) {
0351:                        Resource nextResource = (Resource) it.next();
0352:                        IFile file = WorkspaceSynchronizer
0353:                                .getFile(nextResource);
0354:                        if (file != null) {
0355:                            rules.add(computeSchedulingRule(file));
0356:                        }
0357:                    }
0358:                    return new MultiRule((ISchedulingRule[]) rules
0359:                            .toArray(new ISchedulingRule[rules.size()]));
0360:                }
0361:                return null;
0362:            }
0363:
0364:            /**
0365:             * @generated
0366:             */
0367:            protected ISchedulingRule getSynchronizeRule(Object element) {
0368:                ResourceSetInfo info = getResourceSetInfo(element);
0369:                if (info != null) {
0370:                    Collection rules = new ArrayList();
0371:                    for (Iterator it = info.getResourceSet().getResources()
0372:                            .iterator(); it.hasNext();) {
0373:                        Resource nextResource = (Resource) it.next();
0374:                        IFile file = WorkspaceSynchronizer
0375:                                .getFile(nextResource);
0376:                        if (file != null) {
0377:                            rules.add(ResourcesPlugin.getWorkspace()
0378:                                    .getRuleFactory().refreshRule(file));
0379:                        }
0380:                    }
0381:                    return new MultiRule((ISchedulingRule[]) rules
0382:                            .toArray(new ISchedulingRule[rules.size()]));
0383:                }
0384:                return null;
0385:            }
0386:
0387:            /**
0388:             * @generated
0389:             */
0390:            protected ISchedulingRule getValidateStateRule(Object element) {
0391:                ResourceSetInfo info = getResourceSetInfo(element);
0392:                if (info != null) {
0393:                    Collection files = new ArrayList();
0394:                    for (Iterator it = info.getResourceSet().getResources()
0395:                            .iterator(); it.hasNext();) {
0396:                        Resource nextResource = (Resource) it.next();
0397:                        IFile file = WorkspaceSynchronizer
0398:                                .getFile(nextResource);
0399:                        if (file != null) {
0400:                            files.add(file);
0401:                        }
0402:                    }
0403:                    return ResourcesPlugin.getWorkspace().getRuleFactory()
0404:                            .validateEditRule(
0405:                                    (IFile[]) files.toArray(new IFile[files
0406:                                            .size()]));
0407:                }
0408:                return null;
0409:            }
0410:
0411:            /**
0412:             * @generated
0413:             */
0414:            private ISchedulingRule computeSchedulingRule(
0415:                    IResource toCreateOrModify) {
0416:                if (toCreateOrModify.exists())
0417:                    return ResourcesPlugin.getWorkspace().getRuleFactory()
0418:                            .modifyRule(toCreateOrModify);
0419:
0420:                IResource parent = toCreateOrModify;
0421:                do {
0422:                    /*
0423:                     * XXX This is a workaround for
0424:                     * https://bugs.eclipse.org/bugs/show_bug.cgi?id=67601
0425:                     * IResourceRuleFactory.createRule should iterate the hierarchy
0426:                     * itself.
0427:                     */
0428:                    toCreateOrModify = parent;
0429:                    parent = toCreateOrModify.getParent();
0430:                } while (parent != null && !parent.exists());
0431:
0432:                return ResourcesPlugin.getWorkspace().getRuleFactory()
0433:                        .createRule(toCreateOrModify);
0434:            }
0435:
0436:            /**
0437:             * @generated
0438:             */
0439:            protected void doSynchronize(Object element,
0440:                    IProgressMonitor monitor) throws CoreException {
0441:                ResourceSetInfo info = getResourceSetInfo(element);
0442:                if (info != null && element instanceof  FileEditorInputProxy) {
0443:                    handleResourcesChanged(info, info.getResourceSet()
0444:                            .getResources(), monitor);
0445:                    return;
0446:                }
0447:                super .doSynchronize(element, monitor);
0448:            }
0449:
0450:            /**
0451:             * @generated
0452:             */
0453:            protected void handleResourcesMoved(Map movedPathToResource) {
0454:                for (Iterator it = movedPathToResource.entrySet().iterator(); it
0455:                        .hasNext();) {
0456:                    Entry nextEntry = (Entry) it.next();
0457:                    IPath newPath = (IPath) nextEntry.getKey();
0458:                    Resource resource = (Resource) nextEntry.getValue();
0459:                    resource.setURI(URI.createURI(newPath.toString()));
0460:                }
0461:            }
0462:
0463:            /**
0464:             * @generated
0465:             */
0466:            protected void markWholeResourceSetAsDirty(ResourceSet resourceSet) {
0467:                for (Iterator it = resourceSet.getResources().iterator(); it
0468:                        .hasNext();) {
0469:                    Resource nextResource = (Resource) it.next();
0470:                    nextResource.setModified(true);
0471:                }
0472:            }
0473:
0474:            /**
0475:             * @generated
0476:             */
0477:            protected void handleResourcesChanged(ResourceSetInfo info,
0478:                    Collection changedResources, IProgressMonitor monitor) {
0479:                info.stopResourceListening();
0480:                for (Iterator it = changedResources.iterator(); it.hasNext();) {
0481:                    Resource nextResource = (Resource) it.next();
0482:                    IFile file = WorkspaceSynchronizer.getFile(nextResource);
0483:                    if (file != null) {
0484:                        try {
0485:                            file
0486:                                    .refreshLocal(IResource.DEPTH_INFINITE,
0487:                                            monitor);
0488:                        } catch (CoreException e) {
0489:                            handleCoreException(e,
0490:                                    "FileDocumentProvider.handleElementContentChanged");
0491:                        }
0492:                    }
0493:                    nextResource.unload();
0494:                }
0495:                info.startResourceListening();
0496:
0497:                fireElementContentAboutToBeReplaced(info.getEditorInput());
0498:                removeUnchangedElementListeners(info.getEditorInput(), info);
0499:                info.fStatus = null;
0500:                try {
0501:                    setDocumentContent(info.fDocument, info.getEditorInput());
0502:                } catch (CoreException e) {
0503:                    info.fStatus = e.getStatus();
0504:                }
0505:                if (!info.fCanBeSaved) {
0506:                    info.setModificationStamp(computeModificationStamp(info));
0507:                }
0508:                addUnchangedElementListeners(info.getEditorInput(), info);
0509:                fireElementContentReplaced(info.getEditorInput());
0510:            }
0511:
0512:            /**
0513:             * @generated
0514:             */
0515:            protected void doSaveDocument(IProgressMonitor monitor,
0516:                    Object element, IDocument document, boolean overwrite)
0517:                    throws CoreException {
0518:                ResourceSetInfo info = getResourceSetInfo(element);
0519:                if (info != null) {
0520:                    if (!overwrite && !info.isSynchronized()) {
0521:                        throw new CoreException(new Status(IStatus.ERROR,
0522:                                New_processDiagramEditorPlugin.ID,
0523:                                IResourceStatus.OUT_OF_SYNC_LOCAL,
0524:                                "The file has been changed on the file system",
0525:                                null));
0526:                    }
0527:                    info.stopResourceListening();
0528:                    fireElementStateChanging(element);
0529:                    try {
0530:                        monitor.beginTask("Saving diagram editor", info
0531:                                .getResourceSet().getResources().size());
0532:                        for (Iterator it = info.getResourceSet().getResources()
0533:                                .iterator(); it.hasNext();) {
0534:                            Resource nextResource = (Resource) it.next();
0535:                            monitor.setTaskName("Saving "
0536:                                    + nextResource.getURI());
0537:                            if (nextResource.isLoaded()
0538:                                    && (!nextResource.isTrackingModification() || nextResource
0539:                                            .isModified())) {
0540:                                nextResource.save(Collections.EMPTY_MAP);
0541:                            }
0542:                            monitor.worked(1);
0543:                        }
0544:                        monitor.done();
0545:                    } catch (IOException e) {
0546:                        fireElementStateChangeFailed(element);
0547:                        throw new CoreException(new Status(IStatus.ERROR,
0548:                                New_processDiagramEditorPlugin.ID,
0549:                                EditorStatusCodes.RESOURCE_FAILURE, e
0550:                                        .getLocalizedMessage(), null));
0551:                    } catch (RuntimeException x) {
0552:                        fireElementStateChangeFailed(element);
0553:                        throw x;
0554:                    } finally {
0555:                        info.startResourceListening();
0556:                    }
0557:
0558:                    if (info != null) {
0559:                        info
0560:                                .setModificationStamp(computeModificationStamp(info));
0561:                        info.setSynchronized();
0562:                    }
0563:                }
0564:                super .doSaveDocument(monitor, element, document, overwrite);
0565:            }
0566:
0567:            /**
0568:             * @generated
0569:             */
0570:            protected void handleElementMoved(FileEditorInputProxy input,
0571:                    IPath path) {
0572:                IWorkspace workspace = ResourcesPlugin.getWorkspace();
0573:                IFile newFile = workspace.getRoot().getFile(path);
0574:                fireElementMoved(input, newFile == null ? null
0575:                        : new FileEditorInput(newFile));
0576:            }
0577:
0578:            /**
0579:             * @generated
0580:             */
0581:            protected void handleElementDeleted(FileEditorInputProxy input) {
0582:                fireElementDeleted(input);
0583:            }
0584:
0585:            /**
0586:             * @generated
0587:             */
0588:            public IEditorInput createInputWithEditingDomain(
0589:                    IEditorInput editorInput, TransactionalEditingDomain domain) {
0590:                if (editorInput instanceof  IFileEditorInput) {
0591:                    return new FileEditorInputProxy(
0592:                            (IFileEditorInput) editorInput, domain);
0593:                }
0594:                assert false;
0595:                return null;
0596:            }
0597:
0598:            /**
0599:             * @generated
0600:             */
0601:            public IDiagramDocument getDiagramDocument(Object element) {
0602:                IDocument doc = getDocument(element);
0603:                if (doc instanceof  IDiagramDocument) {
0604:                    return (IDiagramDocument) doc;
0605:                }
0606:                return null;
0607:            }
0608:
0609:            /**
0610:             * @generated
0611:             */
0612:            protected class ResourceSetInfo extends StorageInfo {
0613:
0614:                /**
0615:                 * @generated
0616:                 */
0617:                private long myModificationStamp = IResource.NULL_STAMP;
0618:
0619:                /**
0620:                 * @generated
0621:                 */
0622:                private ResourceSetSynchronizer mySynchronizer;
0623:
0624:                /**
0625:                 * @generated
0626:                 */
0627:                private ResourceSet myResourceSet;
0628:
0629:                /**
0630:                 * @generated
0631:                 */
0632:                private Collection myUnSynchronizedResources = new ArrayList();
0633:
0634:                /**
0635:                 * @generated
0636:                 */
0637:                private FileEditorInputProxy myEditorInput;
0638:
0639:                /**
0640:                 * @generated
0641:                 */
0642:                public ResourceSetInfo(IDiagramDocument document,
0643:                        FileEditorInputProxy editorInput) {
0644:                    super (document);
0645:                    myResourceSet = document.getEditingDomain()
0646:                            .getResourceSet();
0647:                    myEditorInput = editorInput;
0648:                    mySynchronizer = new ResourceSetSynchronizer(this );
0649:                    startResourceListening();
0650:                }
0651:
0652:                /**
0653:                 * @generated
0654:                 */
0655:                public long getModificationStamp() {
0656:                    return myModificationStamp;
0657:                }
0658:
0659:                /**
0660:                 * @generated
0661:                 */
0662:                public void setModificationStamp(long modificationStamp) {
0663:                    myModificationStamp = modificationStamp;
0664:                }
0665:
0666:                /**
0667:                 * @generated
0668:                 */
0669:                public ResourceSetSynchronizer getSynchronizer() {
0670:                    return mySynchronizer;
0671:                }
0672:
0673:                /**
0674:                 * @generated
0675:                 */
0676:                public ResourceSet getResourceSet() {
0677:                    return myResourceSet;
0678:                }
0679:
0680:                /**
0681:                 * @generated
0682:                 */
0683:                public FileEditorInputProxy getEditorInput() {
0684:                    return myEditorInput;
0685:                }
0686:
0687:                /**
0688:                 * @generated
0689:                 */
0690:                public void dispose() {
0691:                    stopResourceListening();
0692:                }
0693:
0694:                /**
0695:                 * @generated
0696:                 */
0697:                public boolean isSynchronized() {
0698:                    return myUnSynchronizedResources.size() == 0;
0699:                }
0700:
0701:                /**
0702:                 * @generated
0703:                 */
0704:                public void setSynchronized() {
0705:                    myUnSynchronizedResources.clear();
0706:                }
0707:
0708:                /**
0709:                 * @generated
0710:                 */
0711:                public void setUnSynchronized(Resource resource) {
0712:                    myUnSynchronizedResources.add(resource);
0713:                }
0714:
0715:                /**
0716:                 * @generated
0717:                 */
0718:                public void setSynchronized(Resource resource) {
0719:                    myUnSynchronizedResources.remove(resource);
0720:                }
0721:
0722:                /**
0723:                 * @generated
0724:                 */
0725:                public final void stopResourceListening() {
0726:                    ResourcesPlugin.getWorkspace()
0727:                            .removeResourceChangeListener(mySynchronizer);
0728:                }
0729:
0730:                /**
0731:                 * @generated
0732:                 */
0733:                public final void startResourceListening() {
0734:                    ResourcesPlugin.getWorkspace().addResourceChangeListener(
0735:                            mySynchronizer, IResourceChangeEvent.POST_CHANGE);
0736:                }
0737:
0738:            }
0739:
0740:            /**
0741:             * @generated
0742:             */
0743:            protected class ResourceSetSynchronizer implements 
0744:                    IResourceChangeListener {
0745:
0746:                /**
0747:                 * @generated
0748:                 */
0749:                private ResourceSetInfo myInfo;
0750:
0751:                /**
0752:                 * @generated
0753:                 */
0754:                protected ResourceSetSynchronizer(ResourceSetInfo info) {
0755:                    myInfo = info;
0756:                }
0757:
0758:                /**
0759:                 * @generated
0760:                 */
0761:                public void resourceChanged(IResourceChangeEvent event) {
0762:                    final ResourceDeltaVisitor deltaVisitor = new ResourceDeltaVisitor();
0763:                    try {
0764:                        event.getDelta().accept(deltaVisitor);
0765:                    } catch (CoreException e) {
0766:                        handleCoreException(e,
0767:                                "FileDocumentProvider.resourceChanged");
0768:                    }
0769:                    synchronized (myInfo) {
0770:                        if (!myInfo.isSynchronized()) {
0771:                            return;
0772:                        }
0773:                    }
0774:
0775:                    Display.getDefault().asyncExec(new Runnable() {
0776:
0777:                        public void run() {
0778:                            if (deltaVisitor.getDeletedResources().size() > 0) {
0779:                                // Just closing editor
0780:                                handleElementDeleted(myInfo.getEditorInput());
0781:                                return;
0782:                            }
0783:
0784:                            Entry diagramEntry = getDiagramResourceEntry(deltaVisitor
0785:                                    .getMovedResourcesMap());
0786:                            if (diagramEntry != null) {
0787:                                deltaVisitor.getMovedResourcesMap().remove(
0788:                                        diagramEntry.getKey());
0789:                                // Setting new editor input since diagram file was
0790:                                // renamed Could be processed together with the rest of
0791:                                // moved resources if FileEditorInputProxy will wupport
0792:                                // IFileEditorInput substitution
0793:                                handleElementMoved(myInfo.getEditorInput(),
0794:                                        (IPath) diagramEntry.getKey());
0795:                            }
0796:                            if (deltaVisitor.getMovedResourcesMap().size() > 0) {
0797:                                handleResourcesMoved(deltaVisitor
0798:                                        .getMovedResourcesMap());
0799:                            }
0800:                            if (deltaVisitor.getChangedResources().size() > 0
0801:                                    || deltaVisitor.getMovedResourcesMap()
0802:                                            .size() > 0) {
0803:                                // reloading changed resources + changing URIs for moved
0804:                                // resources
0805:                                handleResourcesChanged(myInfo, deltaVisitor
0806:                                        .getChangedResources(), null);
0807:                            }
0808:                            if (deltaVisitor.getMovedResourcesMap().size() > 0) {
0809:                                // Marking whole ResourceSet as changed to preserve
0810:                                // changes in resource URIs made by
0811:                                // handleResourcesMoved() call
0812:                                markWholeResourceSetAsDirty(myInfo
0813:                                        .getResourceSet());
0814:                            }
0815:                        }
0816:                    });
0817:                }
0818:
0819:                /**
0820:                 * @generated
0821:                 */
0822:                private Entry getDiagramResourceEntry(Map movedResources) {
0823:                    for (Iterator it = movedResources.entrySet().iterator(); it
0824:                            .hasNext();) {
0825:                        Entry nextEntry = (Entry) it.next();
0826:                        Resource nextResource = (Resource) nextEntry.getValue();
0827:                        IFile file = WorkspaceSynchronizer
0828:                                .getFile(nextResource);
0829:                        if (file != null
0830:                                && file.equals(myInfo.getEditorInput()
0831:                                        .getFile())) {
0832:                            return nextEntry;
0833:                        }
0834:                    }
0835:                    return null;
0836:                }
0837:
0838:                /**
0839:                 * @generated
0840:                 */
0841:                private class ResourceDeltaVisitor implements 
0842:                        IResourceDeltaVisitor {
0843:
0844:                    /**
0845:                     * @generated
0846:                     */
0847:                    private Collection myChangedResources = new ArrayList();
0848:
0849:                    /**
0850:                     * @generated
0851:                     */
0852:                    private Map myMovedResources = new HashMap();
0853:
0854:                    /**
0855:                     * @generated
0856:                     */
0857:                    private Collection myDeletedResources = new ArrayList();
0858:
0859:                    /**
0860:                     * Can be called from any thread
0861:                     * @generated
0862:                     */
0863:                    public boolean visit(IResourceDelta delta) {
0864:                        if (delta.getFlags() != IResourceDelta.MARKERS
0865:                                && delta.getResource().getType() == IResource.FILE) {
0866:                            if ((delta.getKind() & (IResourceDelta.CHANGED | IResourceDelta.REMOVED)) != 0) {
0867:                                Resource resource = myInfo.getResourceSet()
0868:                                        .getResource(
0869:                                                URI.createURI(delta
0870:                                                        .getFullPath()
0871:                                                        .toString()), false);
0872:                                if (resource != null && resource.isLoaded()) {
0873:                                    synchronized (myInfo) {
0874:                                        if (myInfo.fCanBeSaved) {
0875:                                            myInfo.setUnSynchronized(resource);
0876:                                            return false;
0877:                                        }
0878:                                    }
0879:                                    if ((delta.getKind() & IResourceDelta.REMOVED) != 0) {
0880:                                        // element could be either moved/deleted or
0881:                                        // changed.
0882:                                        if ((IResourceDelta.MOVED_TO & delta
0883:                                                .getFlags()) != 0) {
0884:                                            IPath destination = delta
0885:                                                    .getMovedToPath();
0886:                                            myMovedResources.put(destination,
0887:                                                    resource);
0888:                                        } else {
0889:                                            myDeletedResources.add(resource);
0890:                                        }
0891:                                    } else {
0892:                                        myChangedResources.add(resource);
0893:                                    }
0894:                                }
0895:                            }
0896:                        }
0897:
0898:                        return true;
0899:                    }
0900:
0901:                    /**
0902:                     * @generated
0903:                     */
0904:                    public Collection getChangedResources() {
0905:                        return myChangedResources;
0906:                    }
0907:
0908:                    /**
0909:                     * @generated
0910:                     */
0911:                    public Collection getDeletedResources() {
0912:                        return myDeletedResources;
0913:                    }
0914:
0915:                    /**
0916:                     * @generated
0917:                     */
0918:                    public Map getMovedResourcesMap() {
0919:                        return myMovedResources;
0920:                    }
0921:                }
0922:
0923:            }
0924:
0925:            /**
0926:             * @generated
0927:             */
0928:            private class ResourceSetModificationListener extends
0929:                    EContentAdapter {
0930:
0931:                /**
0932:                 * @generated
0933:                 */
0934:                private NotificationFilter myModifiedFilter;
0935:
0936:                /**
0937:                 * @generated
0938:                 */
0939:                private ResourceSetInfo myInfo;
0940:
0941:                /**
0942:                 * @generated
0943:                 */
0944:                public ResourceSetModificationListener(ResourceSetInfo info) {
0945:                    myInfo = info;
0946:                    myModifiedFilter = NotificationFilter
0947:                            .createEventTypeFilter(Notification.SET)
0948:                            .or(
0949:                                    NotificationFilter
0950:                                            .createEventTypeFilter(Notification.UNSET))
0951:                            .and(
0952:                                    NotificationFilter.createFeatureFilter(
0953:                                            Resource.class,
0954:                                            Resource.RESOURCE__IS_MODIFIED));
0955:                }
0956:
0957:                /**
0958:                 * @generated
0959:                 */
0960:                public void notifyChanged(Notification notification) {
0961:                    if (notification.getNotifier() instanceof  ResourceSet) {
0962:                        super .notifyChanged(notification);
0963:                    }
0964:                    if (myModifiedFilter.matches(notification)) {
0965:                        if (notification.getNotifier() instanceof  Resource) {
0966:                            Resource resource = (Resource) notification
0967:                                    .getNotifier();
0968:                            if (resource.isLoaded()) {
0969:                                boolean modified = false;
0970:                                for (Iterator it = myInfo.getResourceSet()
0971:                                        .getResources().iterator(); it
0972:                                        .hasNext()
0973:                                        && !modified;) {
0974:                                    Resource nextResource = (Resource) it
0975:                                            .next();
0976:                                    if (nextResource.isLoaded()) {
0977:                                        modified = nextResource.isModified();
0978:                                    }
0979:                                }
0980:                                boolean dirtyStateChanged = false;
0981:                                synchronized (myInfo) {
0982:                                    if (modified != myInfo.fCanBeSaved) {
0983:                                        myInfo.fCanBeSaved = modified;
0984:                                        dirtyStateChanged = true;
0985:                                    }
0986:                                    if (!resource.isModified()) {
0987:                                        myInfo.setSynchronized(resource);
0988:                                    }
0989:                                }
0990:                                if (dirtyStateChanged) {
0991:                                    fireElementDirtyStateChanged(myInfo
0992:                                            .getEditorInput(), modified);
0993:                                    if (!modified) {
0994:                                        myInfo
0995:                                                .setModificationStamp(computeModificationStamp(myInfo));
0996:                                    }
0997:                                }
0998:                            }
0999:
1000:                        }
1001:                    }
1002:                }
1003:            }
1004:
1005:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.