Exemplo n.º 1
0
 /** @generated */
 protected void disposeElementInfo(Object element, ElementInfo info) {
   if (info instanceof ResourceSetInfo) {
     ResourceSetInfo resourceSetInfo = (ResourceSetInfo) info;
     resourceSetInfo.dispose();
   }
   super.disposeElementInfo(element, info);
 }
Exemplo n.º 2
0
    /** @generated */
    public void notifyChanged(Notification notification) {
      if (notification.getNotifier() instanceof ResourceSet) {
        super.notifyChanged(notification);
      }
      if (!notification.isTouch() && myModifiedFilter.matches(notification)) {
        if (notification.getNotifier() instanceof Resource) {
          Resource resource = (Resource) notification.getNotifier();
          if (resource.isLoaded()) {
            boolean modified = false;
            for (Iterator /*<org.eclipse.emf.ecore.resource.Resource>*/ it =
                    myInfo.getLoadedResourcesIterator();
                it.hasNext() && !modified; ) {
              Resource nextResource = (Resource) it.next();
              if (nextResource.isLoaded()) {
                modified = nextResource.isModified();
              }
            }
            boolean dirtyStateChanged = false;
            synchronized (myInfo) {
              if (modified != myInfo.fCanBeSaved) {
                myInfo.fCanBeSaved = modified;
                dirtyStateChanged = true;
              }
            }
            if (dirtyStateChanged) {
              fireElementDirtyStateChanged(myInfo.getEditorInput(), modified);

              if (!modified) {
                myInfo.setModificationStamp(computeModificationStamp(myInfo));
              }
            }
          }
        }
      }
    }
Exemplo n.º 3
0
 /** @generated */
 protected void doUpdateStateCache(Object element) throws CoreException {
   ResourceSetInfo info = getResourceSetInfo(element);
   if (info != null) {
     info.setUpdateCache(true);
   }
   super.doUpdateStateCache(element);
 }
Exemplo n.º 4
0
 /** @generated */
 public boolean isSynchronized(Object element) {
   ResourceSetInfo info = getResourceSetInfo(element);
   if (info != null) {
     return info.isSynchronized();
   }
   return super.isSynchronized(element);
 }
Exemplo n.º 5
0
 /** @generated */
 protected void doSynchronize(Object element, IProgressMonitor monitor) throws CoreException {
   ResourceSetInfo info = getResourceSetInfo(element);
   if (info != null) {
     for (Iterator<Resource> it = info.getLoadedResourcesIterator(); it.hasNext(); ) {
       Resource nextResource = it.next();
       handleElementChanged(info, nextResource, monitor);
     }
     return;
   }
   super.doSynchronize(element, monitor);
 }
  /** @generated */
  protected void handleElementChanged(
      ResourceSetInfo info, Resource changedResource, IProgressMonitor monitor) {
    IFile file = WorkspaceSynchronizer.getFile(changedResource);
    if (file != null) {
      try {
        file.refreshLocal(IResource.DEPTH_INFINITE, monitor);
      } catch (CoreException ex) {
        CallGraphDiagramEditorPlugin.getInstance()
            .logError(Messages.CallGraphDocumentProvider_handleElementContentChanged, ex);
        // Error message to log was initially taken from
        // org.eclipse.gmf.runtime.diagram.ui.resources.editor.ide.internal.l10n.EditorMessages.FileDocumentProvider_handleElementContentChanged
      }
    }
    changedResource.unload();

    fireElementContentAboutToBeReplaced(info.getEditorInput());
    removeUnchangedElementListeners(info.getEditorInput(), info);
    info.fStatus = null;
    try {
      setDocumentContent(info.fDocument, info.getEditorInput());
    } catch (CoreException e) {
      info.fStatus = e.getStatus();
    }
    if (!info.fCanBeSaved) {
      info.setModificationStamp(computeModificationStamp(info));
    }
    addUnchangedElementListeners(info.getEditorInput(), info);
    fireElementContentReplaced(info.getEditorInput());
  }
 /** @generated */
 protected ISchedulingRule getSaveRule(Object element) {
   ResourceSetInfo info = getResourceSetInfo(element);
   if (info != null) {
     LinkedList<ISchedulingRule> rules = new LinkedList<ISchedulingRule>();
     for (Iterator<Resource> it = info.getLoadedResourcesIterator(); it.hasNext(); ) {
       Resource nextResource = it.next();
       IFile file = WorkspaceSynchronizer.getFile(nextResource);
       if (file != null) {
         rules.add(computeSchedulingRule(file));
       }
     }
     return new MultiRule((ISchedulingRule[]) rules.toArray(new ISchedulingRule[rules.size()]));
   }
   return null;
 }
 /** @generated */
 protected ISchedulingRule getSynchronizeRule(Object element) {
   ResourceSetInfo info = getResourceSetInfo(element);
   if (info != null) {
     Collection rules = new ArrayList();
     for (Iterator it = info.getResourceSet().getResources().iterator(); it.hasNext(); ) {
       Resource nextResource = (Resource) it.next();
       IFile file = WorkspaceSynchronizer.getFile(nextResource);
       if (file != null) {
         rules.add(ResourcesPlugin.getWorkspace().getRuleFactory().refreshRule(file));
       }
     }
     return new MultiRule((ISchedulingRule[]) rules.toArray(new ISchedulingRule[rules.size()]));
   }
   return null;
 }
 /** @generated */
 protected ISchedulingRule getValidateStateRule(Object element) {
   ResourceSetInfo info = getResourceSetInfo(element);
   if (info != null) {
     Collection files = new ArrayList();
     for (Iterator it = info.getResourceSet().getResources().iterator(); it.hasNext(); ) {
       Resource nextResource = (Resource) it.next();
       IFile file = WorkspaceSynchronizer.getFile(nextResource);
       if (file != null) {
         files.add(file);
       }
     }
     return ResourcesPlugin.getWorkspace()
         .getRuleFactory()
         .validateEditRule((IFile[]) files.toArray(new IFile[files.size()]));
   }
   return null;
 }
Exemplo n.º 10
0
 /** @generated */
 public boolean isReadOnly(Object element) {
   ResourceSetInfo info = getResourceSetInfo(element);
   if (info != null) {
     if (info.isUpdateCache()) {
       try {
         updateCache(element);
       } catch (CoreException ex) {
         StateChartDiagramEditorPlugin.getInstance()
             .logError(Messages.StateChartDocumentProvider_isModifiable, ex);
         // Error message to log was initially taken from
         // org.eclipse.gmf.runtime.diagram.ui.resources.editor.ide.internal.l10n.EditorMessages.StorageDocumentProvider_isModifiable
       }
     }
     return info.isReadOnly();
   }
   return super.isReadOnly(element);
 }
  /** @generated */
  protected void doValidateState(Object element, Object computationContext) throws CoreException {
    ResourceSetInfo info = getResourceSetInfo(element);
    if (info != null) {
      Collection files2Validate = new ArrayList();
      for (Iterator it = info.getResourceSet().getResources().iterator(); it.hasNext(); ) {
        Resource nextResource = (Resource) it.next();
        IFile file = WorkspaceSynchronizer.getFile(nextResource);
        if (file != null && file.isReadOnly()) {
          files2Validate.add(file);
        }
      }
      ResourcesPlugin.getWorkspace()
          .validateEdit(
              (IFile[]) files2Validate.toArray(new IFile[files2Validate.size()]),
              computationContext);
    }

    super.doValidateState(element, computationContext);
  }
Exemplo n.º 12
0
 /** @generated */
 private long computeModificationStamp(ResourceSetInfo info) {
   int result = 0;
   for (Iterator<Resource> it = info.getLoadedResourcesIterator(); it.hasNext(); ) {
     Resource nextResource = it.next();
     File file = getFile(nextResource);
     if (file != null && file.exists()) {
       result += file.lastModified();
     }
   }
   return result;
 }
Exemplo n.º 13
0
  /** @generated */
  protected ElementInfo createElementInfo(Object element) throws CoreException {
    if (false == element instanceof URIEditorInput) {
      throw new CoreException(
          new Status(
              IStatus.ERROR,
              StateChartDiagramEditorPlugin.ID,
              0,
              NLS.bind(
                  Messages.StateChartDocumentProvider_IncorrectInputError,
                  new Object[] {
                    element, "org.eclipse.emf.common.ui.URIEditorInput"
                  }), //$NON-NLS-1$
              null));
    }
    IEditorInput editorInput = (IEditorInput) element;
    IDiagramDocument document = (IDiagramDocument) createDocument(editorInput);

    ResourceSetInfo info = new ResourceSetInfo(document, editorInput);
    info.setModificationStamp(computeModificationStamp(info));
    info.fStatus = null;
    return info;
  }
 /** @generated */
 public boolean isModifiable(Object element) {
   if (!isStateValidated(element)) {
     if (element instanceof FileEditorInput || element instanceof URIEditorInput) {
       return true;
     }
   }
   ResourceSetInfo info = getResourceSetInfo(element);
   if (info != null) {
     if (info.isUpdateCache()) {
       try {
         updateCache(element);
       } catch (CoreException ex) {
         CallGraphDiagramEditorPlugin.getInstance()
             .logError(Messages.CallGraphDocumentProvider_isModifiable, ex);
         // Error message to log was initially taken from
         // org.eclipse.gmf.runtime.diagram.ui.resources.editor.ide.internal.l10n.EditorMessages.StorageDocumentProvider_isModifiable
       }
     }
     return info.isModifiable();
   }
   return super.isModifiable(element);
 }
 /** @generated */
 private long computeModificationStamp(ResourceSetInfo info) {
   int result = 0;
   for (Iterator it = info.getResourceSet().getResources().iterator(); it.hasNext(); ) {
     Resource nextResource = (Resource) it.next();
     IFile file = WorkspaceSynchronizer.getFile(nextResource);
     if (file != null) {
       if (file.getLocation() != null) {
         result += file.getLocation().toFile().lastModified();
       } else {
         result += file.getModificationStamp();
       }
     }
   }
   return result;
 }
Exemplo n.º 16
0
  /** @generated */
  protected void handleElementChanged(
      ResourceSetInfo info, Resource changedResource, IProgressMonitor monitor) {
    changedResource.unload();

    fireElementContentAboutToBeReplaced(info.getEditorInput());
    removeUnchangedElementListeners(info.getEditorInput(), info);
    info.fStatus = null;
    try {
      setDocumentContent(info.fDocument, info.getEditorInput());
    } catch (CoreException e) {
      info.fStatus = e.getStatus();
    }
    if (!info.fCanBeSaved) {
      info.setModificationStamp(computeModificationStamp(info));
    }
    addUnchangedElementListeners(info.getEditorInput(), info);
    fireElementContentReplaced(info.getEditorInput());
  }
 /** @generated */
 protected void updateCache(Object element) throws CoreException {
   ResourceSetInfo info = getResourceSetInfo(element);
   if (info != null) {
     for (Iterator it = info.getResourceSet().getResources().iterator(); it.hasNext(); ) {
       Resource nextResource = (Resource) it.next();
       IFile file = WorkspaceSynchronizer.getFile(nextResource);
       if (file != null && file.isReadOnly()) {
         info.setReadOnly(true);
         info.setModifiable(false);
         return;
       }
     }
     info.setReadOnly(false);
     info.setModifiable(true);
     return;
   }
 }
Exemplo n.º 18
0
 /** @generated */
 protected void updateCache(Object element) throws CoreException {
   ResourceSetInfo info = getResourceSetInfo(element);
   if (info != null) {
     for (Iterator<Resource> it = info.getLoadedResourcesIterator(); it.hasNext(); ) {
       Resource nextResource = it.next();
       File file = getFile(nextResource);
       if (file != null && file.exists() && !file.canWrite()) {
         info.setReadOnly(true);
         info.setModifiable(false);
         return;
       }
     }
     info.setReadOnly(false);
     info.setModifiable(true);
     return;
   }
 }
  @Override
  protected void doSaveDocument(
      IProgressMonitor monitor, Object element, IDocument document, boolean overwrite)
      throws CoreException {

    try {
      // Automatic validation with result
      IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
      CustomValidateAction action = new CustomValidateAction(page, (IEditorInput) element);
      monitor.setTaskName("Validation");
      action.run(monitor);
      if (!action.result) {
        // If validation failed, do not save
        ProblemsView problem = (ProblemsView) page.findView("org.eclipse.ui.views.ProblemView");
        page.activate(problem);
        monitor.setCanceled(true);
        return;
      }
    } catch (Exception e) {
      MindDiagramEditorPlugin.getInstance().logError("Problems occured during validation", e);
      return;
    }

    MindProxy mindRoot = MindProxyFactory.INSTANCE.getRootProxy();
    HashMap<String, Rectangle> boundsMemory = new HashMap<String, Rectangle>();
    HashMap<String, Bendpoints> bendpointsMemory = new HashMap<String, Bendpoints>();
    if (mindRoot != null) {
      SaveUtil.saveBounds(mindRoot.getEditPart(), boundsMemory, bendpointsMemory);
    }

    // Prepare the transaction that will prepare the main definition
    // All merged items are deleted because they must not be serialized
    TransactionalEditingDomain domain = getDiagramDocument(element).getEditingDomain();
    TransactionImpl transaction = new TransactionImpl(domain, false);
    EObject root = ((DiagramImpl) document.getContent()).getElement();

    ResourceSetInfo info = getResourceSetInfo(element);
    if (info != null) {
      if (!overwrite && !info.isSynchronized()) {
        throw new CoreException(
            new Status(
                IStatus.ERROR,
                MindDiagramEditorPlugin.ID,
                IResourceStatus.OUT_OF_SYNC_LOCAL,
                Messages.MindDocumentProvider_UnsynchronizedFileSaveError,
                null));
      }
      info.stopResourceListening();
      fireElementStateChanging(element);
      try {
        monitor.beginTask(
            Messages.MindDocumentProvider_SaveDiagramTask,
            info.getResourceSet().getResources().size() + 1); // "Saving diagram"

        LazyLinkingResource xtextResource = null;
        GMFResource gmfResource = null;

        for (Iterator /*<org.eclipse.emf.ecore.resource.Resource>*/<?> it =
                info.getLoadedResourcesIterator();
            it.hasNext(); ) {
          Resource nextResource = (Resource) it.next();
          monitor.setTaskName(
              NLS.bind(Messages.MindDocumentProvider_SaveNextResourceTask, nextResource.getURI()));
          if (nextResource.isLoaded() && !info.getEditingDomain().isReadOnly(nextResource)) {
            if (nextResource instanceof LazyLinkingResource) {
              // Serialize later
              xtextResource = (LazyLinkingResource) nextResource;
            } else {
              // Save GMF
              try {
                if (nextResource instanceof GMFResource) gmfResource = (GMFResource) nextResource;
                nextResource.save(MindDiagramEditorUtil.getSaveOptions());
              } catch (IOException e) {
                fireElementStateChangeFailed(element);
                throw new CoreException(
                    new Status(
                        IStatus.ERROR,
                        MindDiagramEditorPlugin.ID,
                        EditorStatusCodes.RESOURCE_FAILURE,
                        e.getLocalizedMessage(),
                        null));
              }
            }
          }
          monitor.worked(1);
        }

        // Delete merged elements from the model before saving
        if (root instanceof AdlDefinitionCustomImpl) {
          try {
            transaction.start();
            prepareMainDefinitionBeforeSave((AdlDefinitionCustomImpl) root);
            transaction.commit();
          } catch (InterruptedException e) {
            MindDiagramEditorPlugin.getInstance().logError("Clean merge failed", e);
          } catch (RollbackException e) {
            MindDiagramEditorPlugin.getInstance().logError("Clean merge failed", e);
            transaction.rollback();
          } finally {
          }
        }

        // Merged items are deleted, they will not to be serialized
        // We can save xtext resource
        try {
          xtextResource.save(MindDiagramEditorUtil.getSaveOptions());
        } catch (IOException e) {
          fireElementStateChangeFailed(element);
          throw new CoreException(
              new Status(
                  IStatus.ERROR,
                  MindDiagramEditorPlugin.ID,
                  EditorStatusCodes.RESOURCE_FAILURE,
                  e.getLocalizedMessage(),
                  null));
        }

        // Restore merged elements
        if (root instanceof AdlDefinitionCustomImpl) {
          try {
            transaction.start();
            restoreMainDefinitionAfterSave((AdlDefinitionCustomImpl) root);
            transaction.commit();
          } catch (InterruptedException e) {
            MindDiagramEditorPlugin.getInstance().logError("Restore merge failed", e);
          } catch (RollbackException e) {
            e.printStackTrace();
            MindDiagramEditorPlugin.getInstance().logError("Restore merge failed", e);
            transaction.rollback();
          } finally {
          }
        }

        // Update diagram
        try {
          MindDiagramUpdateCommand update = new MindDiagramUpdateAllCommand(false);
          update.execute(new ExecutionEvent());
        } catch (ExecutionException e) {
          MindDiagramEditorPlugin.getInstance().logError("Update failed", e);
        } finally {
        }

        // Now that editParts have been recreated by the update,
        // we are able to restore the saved bounds
        if (mindRoot != null) {
          SaveUtil.restoreBounds(mindRoot.getEditPart(), boundsMemory, bendpointsMemory);
          boundsMemory.clear();
        }

        // DocumentProvider thinks resource is modified because of restoreMainDefinition
        // Set value to false
        gmfResource.setModified(false);

        monitor.done();
        info.setModificationStamp(computeModificationStamp(info));
      } catch (RuntimeException x) {
        fireElementStateChangeFailed(element);
        throw x;
      } finally {
        info.startResourceListening();
      }
    } else {
      URI newResoruceURI;
      List<IFile> affectedFiles = null;
      if (element instanceof FileEditorInput) {
        IFile newFile = ((FileEditorInput) element).getFile();
        affectedFiles = Collections.singletonList(newFile);
        newResoruceURI = URI.createPlatformResourceURI(newFile.getFullPath().toString(), true);
      } else if (element instanceof URIEditorInput) {
        newResoruceURI = ((URIEditorInput) element).getURI();
      } else {
        fireElementStateChangeFailed(element);
        throw new CoreException(
            new Status(
                IStatus.ERROR,
                MindDiagramEditorPlugin.ID,
                0,
                NLS.bind(
                    Messages.MindDocumentProvider_IncorrectInputError,
                    new Object[] {
                      element,
                      "org.eclipse.ui.part.FileEditorInput",
                      "org.eclipse.emf.common.ui.URIEditorInput"
                    }), //$NON-NLS-1$ //$NON-NLS-2$
                null));
      }
      if (false == document instanceof IDiagramDocument) {
        fireElementStateChangeFailed(element);
        throw new CoreException(
            new Status(
                IStatus.ERROR,
                MindDiagramEditorPlugin.ID,
                0,
                "Incorrect document used: "
                    + document
                    + " instead of org.eclipse.gmf.runtime.diagram.ui.resources.editor.document.IDiagramDocument",
                null)); //$NON-NLS-1$ //$NON-NLS-2$
      }
      IDiagramDocument diagramDocument = (IDiagramDocument) document;
      final Resource newResource =
          diagramDocument.getEditingDomain().getResourceSet().createResource(newResoruceURI);
      final Diagram diagramCopy = (Diagram) EcoreUtil.copy(diagramDocument.getDiagram());
      try {
        new AbstractTransactionalCommand(
            diagramDocument.getEditingDomain(),
            NLS.bind(Messages.MindDocumentProvider_SaveAsOperation, diagramCopy.getName()),
            affectedFiles) {
          protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info)
              throws ExecutionException {
            newResource.getContents().add(diagramCopy);
            return CommandResult.newOKCommandResult();
          }
        }.execute(monitor, null);
        newResource.save(MindDiagramEditorUtil.getSaveOptions());
      } catch (ExecutionException e) {
        fireElementStateChangeFailed(element);
        throw new CoreException(
            new Status(
                IStatus.ERROR, MindDiagramEditorPlugin.ID, 0, e.getLocalizedMessage(), null));
      } catch (IOException e) {
        fireElementStateChangeFailed(element);
        throw new CoreException(
            new Status(
                IStatus.ERROR, MindDiagramEditorPlugin.ID, 0, e.getLocalizedMessage(), null));
      }
      newResource.unload();
    }
  }
Exemplo n.º 20
0
 /** @generated */
 protected void doSaveDocument(
     IProgressMonitor monitor, Object element, IDocument document, boolean overwrite)
     throws CoreException {
   ResourceSetInfo info = getResourceSetInfo(element);
   if (info != null) {
     if (!overwrite && !info.isSynchronized()) {
       throw new CoreException(
           new Status(
               IStatus.ERROR,
               StateChartDiagramEditorPlugin.ID,
               IStatus.ERROR,
               Messages.StateChartDocumentProvider_UnsynchronizedFileSaveError,
               null));
     }
     fireElementStateChanging(element);
     try {
       monitor.beginTask(
           Messages.StateChartDocumentProvider_SaveDiagramTask,
           info.getResourceSet().getResources().size() + 1); // "Saving diagram"
       for (Iterator<Resource> it = info.getLoadedResourcesIterator(); it.hasNext(); ) {
         Resource nextResource = it.next();
         monitor.setTaskName(
             NLS.bind(
                 Messages.StateChartDocumentProvider_SaveNextResourceTask, nextResource.getURI()));
         if (nextResource.isLoaded() && !info.getEditingDomain().isReadOnly(nextResource)) {
           try {
             nextResource.save(StateChartDiagramEditorUtil.getSaveOptions());
           } catch (IOException e) {
             fireElementStateChangeFailed(element);
             throw new CoreException(
                 new Status(
                     IStatus.ERROR,
                     StateChartDiagramEditorPlugin.ID,
                     EditorStatusCodes.RESOURCE_FAILURE,
                     e.getLocalizedMessage(),
                     null));
           }
         }
         monitor.worked(1);
       }
       monitor.done();
       info.setModificationStamp(computeModificationStamp(info));
     } catch (RuntimeException x) {
       fireElementStateChangeFailed(element);
       throw x;
     }
   } else {
     URI newResoruceURI;
     List<IFile> affectedFiles = null;
     if (element instanceof URIEditorInput) {
       newResoruceURI = ((URIEditorInput) element).getURI();
     } else {
       fireElementStateChangeFailed(element);
       throw new CoreException(
           new Status(
               IStatus.ERROR,
               StateChartDiagramEditorPlugin.ID,
               0,
               NLS.bind(
                   Messages.StateChartDocumentProvider_IncorrectInputError,
                   new Object[] {
                     element, "org.eclipse.emf.common.ui.URIEditorInput"
                   }), //$NON-NLS-1$
               null));
     }
     if (false == document instanceof IDiagramDocument) {
       fireElementStateChangeFailed(element);
       throw new CoreException(
           new Status(
               IStatus.ERROR,
               StateChartDiagramEditorPlugin.ID,
               0,
               "Incorrect document used: "
                   + document
                   + " instead of org.eclipse.gmf.runtime.diagram.ui.resources.editor.document.IDiagramDocument",
               null)); //$NON-NLS-1$ //$NON-NLS-2$
     }
     IDiagramDocument diagramDocument = (IDiagramDocument) document;
     final Resource newResource =
         diagramDocument.getEditingDomain().getResourceSet().createResource(newResoruceURI);
     final Diagram diagramCopy = (Diagram) EcoreUtil.copy(diagramDocument.getDiagram());
     try {
       new AbstractTransactionalCommand(
           diagramDocument.getEditingDomain(),
           NLS.bind(Messages.StateChartDocumentProvider_SaveAsOperation, diagramCopy.getName()),
           affectedFiles) {
         protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info)
             throws ExecutionException {
           newResource.getContents().add(diagramCopy);
           return CommandResult.newOKCommandResult();
         }
       }.execute(monitor, null);
       newResource.save(StateChartDiagramEditorUtil.getSaveOptions());
     } catch (ExecutionException e) {
       fireElementStateChangeFailed(element);
       throw new CoreException(
           new Status(
               IStatus.ERROR, StateChartDiagramEditorPlugin.ID, 0, e.getLocalizedMessage(), null));
     } catch (IOException e) {
       fireElementStateChangeFailed(element);
       throw new CoreException(
           new Status(
               IStatus.ERROR, StateChartDiagramEditorPlugin.ID, 0, e.getLocalizedMessage(), null));
     }
     newResource.unload();
   }
 }