private void incrementalBuild(IProgressMonitor monitor) throws CoreException {
    IProject project = this.getProject();
    IResourceDelta delta = this.getDelta(project);
    ImmutableList<FileDelta> fileDeltas = ResourceDeltaVisitor.getFileDeltas(delta, project);

    if (!fileDeltas.isEmpty()) {
      this.clean(fileDeltas, monitor);
      this.build(fileDeltas, monitor);
    }
  }
Пример #2
0
        @Override
        public void resourceChanged(IResourceChangeEvent event) {
          IResourceDelta delta = event.getDelta();
          try {
            class ResourceDeltaVisitor implements IResourceDeltaVisitor {
              protected ResourceSet resourceSet = editingDomain.getResourceSet();
              protected Collection<Resource> changedResources = new ArrayList<Resource>();
              protected Collection<Resource> removedResources = new ArrayList<Resource>();

              public Collection<Resource> getChangedResources() {
                return changedResources;
              }

              public Collection<Resource> getRemovedResources() {
                return removedResources;
              }

              @Override
              public boolean visit(IResourceDelta delta) {
                if (delta.getResource().getType() == IResource.FILE) {
                  if (delta.getKind() == IResourceDelta.REMOVED
                      || delta.getKind() == IResourceDelta.CHANGED
                          && delta.getFlags() != IResourceDelta.MARKERS) {
                    Resource resource =
                        resourceSet.getResource(
                            URI.createPlatformResourceURI(delta.getFullPath().toString(), true),
                            false);
                    if (resource != null) {
                      if (delta.getKind() == IResourceDelta.REMOVED) {
                        removedResources.add(resource);
                      } else if (!savedResources.remove(resource)) {
                        changedResources.add(resource);
                      }
                    }
                  }
                }

                return true;
              }
            }

            final ResourceDeltaVisitor visitor = new ResourceDeltaVisitor();
            delta.accept(visitor);

            if (!visitor.getRemovedResources().isEmpty()) {
              getSite()
                  .getShell()
                  .getDisplay()
                  .asyncExec(
                      new Runnable() {
                        @Override
                        public void run() {
                          removedResources.addAll(visitor.getRemovedResources());
                          if (!isDirty()) {
                            getSite().getPage().closeEditor(RmapEditor.this, false);
                          }
                        }
                      });
            }

            if (!visitor.getChangedResources().isEmpty()) {
              getSite()
                  .getShell()
                  .getDisplay()
                  .asyncExec(
                      new Runnable() {
                        @Override
                        public void run() {
                          changedResources.addAll(visitor.getChangedResources());
                          if (getSite().getPage().getActiveEditor() == RmapEditor.this) {
                            handleActivate();
                          }
                        }
                      });
            }
          } catch (CoreException exception) {
            RmapEditorPlugin.INSTANCE.log(exception);
          }
        }
 /**
  * {@inheritDoc}
  *
  * @see
  *     org.eclipse.core.resources.mapping.ModelProvider#validateChange(org.eclipse.core.resources.IResourceDelta,
  *     org.eclipse.core.runtime.IProgressMonitor)
  */
 @Override
 public IStatus validateChange(IResourceDelta delta, IProgressMonitor monitor) {
   IStatus result = null;
   if (delta != null) {
     try {
       ResourceDeltaVisitor visitor = new ResourceDeltaVisitor();
       delta.accept(visitor);
       if (visitor.getProjectContainingSessionToSaveToDelete().size() == 1) {
         result =
             new ModelStatus(
                 IStatus.ERROR,
                 SiriusPlugin.ID,
                 ModelingModelProvider.MODELING_MODEL_PROVIDER_ID,
                 "This modeling project contains unsaved data. This data will be lost.");
       } else if (visitor.getProjectContainingSessionToSaveToDelete().size() > 1) {
         result =
             new ModelStatus(
                 IStatus.ERROR,
                 SiriusPlugin.ID,
                 ModelingModelProvider.MODELING_MODEL_PROVIDER_ID,
                 "Some modeling projects ("
                     + getProjectsName(visitor.getProjectContainingSessionToSaveToDelete())
                     + ") contain unsaved data. This data will be lost.");
       } else if (visitor.getMainRepresentationsFilesToDelete().size() == 1) {
         result =
             new ModelStatus(
                 IStatus.ERROR,
                 SiriusPlugin.ID,
                 ModelingModelProvider.MODELING_MODEL_PROVIDER_ID,
                 "Deletion of the main representations file of \""
                     + visitor.getMainRepresentationsFilesToDelete().get(0).getProject().getName()
                     + "\" will invalidate it.");
       } else if (visitor.getMainRepresentationsFilesToDelete().size() > 1) {
         result =
             new ModelStatus(
                 IStatus.ERROR,
                 SiriusPlugin.ID,
                 ModelingModelProvider.MODELING_MODEL_PROVIDER_ID,
                 "Deletion of the main representations files of some modeling projects ("
                     + getFilesProjectName(visitor.getMainRepresentationsFilesToDelete())
                     + ") will invalidate them.");
       } else if (visitor.getRepresentationsFileToAddOnValidModelingProject().size() == 1) {
         result =
             new ModelStatus(
                 IStatus.ERROR,
                 SiriusPlugin.ID,
                 ModelingModelProvider.MODELING_MODEL_PROVIDER_ID,
                 "Add another representations file to \""
                     + visitor
                         .getRepresentationsFileToAddOnValidModelingProject()
                         .get(0)
                         .getProject()
                         .getName()
                     + "\" may invalidate it.");
       } else if (visitor.getRepresentationsFileToAddOnValidModelingProject().size() > 1) {
         result =
             new ModelStatus(
                 IStatus.ERROR,
                 SiriusPlugin.ID,
                 ModelingModelProvider.MODELING_MODEL_PROVIDER_ID,
                 "Add another representations file to "
                     + getFilesProjectName(
                         visitor.getRepresentationsFileToAddOnValidModelingProject())
                     + " may invalidate them.");
       }
     } catch (CoreException e) {
       /* do nothing */
     }
   }
   if (result == null) {
     result = super.validateChange(delta, monitor);
   }
   return result;
 }
Пример #4
0
        public void resourceChanged(IResourceChangeEvent event) {
          // Only listening to these.
          // if (event.getType() == IResourceDelta.POST_CHANGE)
          {
            IResourceDelta delta = event.getDelta();
            try {
              class ResourceDeltaVisitor implements IResourceDeltaVisitor {
                protected ResourceSet resourceSet = editingDomain.getResourceSet();

                protected Collection changedResources = new ArrayList();

                protected Collection removedResources = new ArrayList();

                public boolean visit(IResourceDelta delta) {
                  if (delta.getFlags() != IResourceDelta.MARKERS
                      && delta.getResource().getType() == IResource.FILE) {
                    if ((delta.getKind() & (IResourceDelta.CHANGED | IResourceDelta.REMOVED))
                        != 0) {
                      Resource resource =
                          resourceSet.getResource(
                              URI.createURI(delta.getFullPath().toString()), false);
                      if (resource != null) {
                        if ((delta.getKind() & IResourceDelta.REMOVED) != 0) {
                          removedResources.add(resource);
                        } else {
                          changedResources.add(resource);
                        }
                      }
                    }
                  }

                  return true;
                }

                public Collection getChangedResources() {
                  return changedResources;
                }

                public Collection getRemovedResources() {
                  return removedResources;
                }
              }

              ResourceDeltaVisitor visitor = new ResourceDeltaVisitor();
              delta.accept(visitor);

              if (!visitor.getRemovedResources().isEmpty()) {
                removedResources.addAll(visitor.getRemovedResources());
                if (!isDirty()) {
                  getSite()
                      .getShell()
                      .getDisplay()
                      .asyncExec(
                          new Runnable() {
                            public void run() {
                              getSite().getPage().closeEditor(GenfwEditor.this, false);
                              GenfwEditor.this.dispose();
                            }
                          });
                }
              }

              if (!visitor.getChangedResources().isEmpty()) {
                changedResources.addAll(visitor.getChangedResources());
              }
            } catch (CoreException exception) {
              GenfwEditorPlugin.INSTANCE.log(exception);
            }
          }
        }