/**
   * Sets a CoWolf-Marker to give IResource.
   *
   * @param sourceRes used in the marker message to show the user which resource was changed.
   * @param targetRes on that the marker should be set.
   */
  private void setMarker(final IResource sourceRes, final IResource targetRes) {

    WorkspaceJob job =
        new WorkspaceJob("Set marker to invalid models") {

          @Override
          public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {

            IMarker resMarker = targetRes.createMarker(COWOLF_PROBLEM);

            if (resMarker.exists()) {

              resMarker.setAttribute(
                  IMarker.MESSAGE,
                  "The associated source model ('"
                      + sourceRes.getName()
                      + "') was changed. It's recommended to perform a co-evolution.");
              resMarker.setAttribute(IMarker.PRIORITY, IMarker.PRIORITY_HIGH);
              resMarker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_WARNING);
            }

            return Status.OK_STATUS;
          }
        };

    job.setRule(targetRes);
    job.schedule();
  }
Exemple #2
0
  private IProject initializeWorkspace() {
    IEclipsePreferences node = new InstanceScope().getNode(ResourcesPlugin.PI_RESOURCES);
    node.putBoolean(ResourcesPlugin.PREF_AUTO_REFRESH, true);
    try {
      node.flush();
    } catch (BackingStoreException e) {
      e.printStackTrace();
    }

    WorkspaceJob job =
        new WorkspaceJob("init workspace") {

          @Override
          public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
            MyPart.this.project =
                TwitterContentUtil.getOrCreateTwitterDemoProject(workspace, monitor);
            return Status.OK_STATUS;
          }
        };

    job.setRule(workspace.getRoot());
    job.schedule();

    return TwitterContentUtil.getTwitterDemoProject(workspace);
  }
  /**
   * Deletes all CoWolf-Markers of given IResource.
   *
   * @param changedRes
   */
  private void deleteCoWolfMarkers(final IResource changedRes) {

    WorkspaceJob job =
        new WorkspaceJob("Delete CoWolf-Marker of the model") {

          @Override
          public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {

            changedRes.deleteMarkers(COWOLF_PROBLEM, false, IResource.DEPTH_ZERO);

            return Status.OK_STATUS;
          }
        };

    job.setRule(changedRes);
    job.schedule();
  }
  public static void updateProjectReferences(
      IIncludePathEntry[] newEntries,
      IIncludePathEntry[] oldEntries,
      final IProject project,
      SubProgressMonitor monitor) {
    try {
      boolean changedReferences = false;
      final IProjectDescription projectDescription = project.getDescription();
      List<IProject> referenced = new ArrayList<IProject>();
      List<String> referencedNames = new ArrayList<String>();
      IProject[] referencedProjects = projectDescription.getReferencedProjects();
      for (IProject refProject : referencedProjects) {
        referenced.add(refProject);
        referencedNames.add(refProject.getName());
      }

      for (IIncludePathEntry oldEntry : oldEntries) {
        if (oldEntry.getEntryKind() == IIncludePathEntry.IPE_PROJECT) {
          String projectName = oldEntry.getPath().lastSegment();
          if (!containsProject(newEntries, projectName)) {
            if (((IncludePathEntry) oldEntry).createdReference) {
              int index = referencedNames.indexOf(projectName);
              if (index >= 0) {
                changedReferences = true;
                referencedNames.remove(index);
                referenced.remove(index);
              }
            }
          }
        }
      }

      for (IIncludePathEntry newEntry : newEntries) {
        if (newEntry.getEntryKind() == IIncludePathEntry.IPE_PROJECT) {
          String projectName = newEntry.getPath().lastSegment();
          if (!containsProject(oldEntries, projectName)) {
            if (!referencedNames.contains(projectName)) {
              changedReferences = true;
              ((IncludePathEntry) newEntry).createdReference = true;
              referenced.add(ResourcesPlugin.getWorkspace().getRoot().getProject(projectName));
              referencedNames.add(projectName);
            }
          }
        }
      }
      if (changedReferences) {
        IProject[] referenceProjects =
            (IProject[]) referenced.toArray(new IProject[referenced.size()]);
        projectDescription.setReferencedProjects(referenceProjects);
        WorkspaceJob job =
            new WorkspaceJob(CoreMessages.getString("IncludePathEntry_2")) // $NON-NLS-1$
            {
              public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
                project.setDescription(projectDescription, monitor);
                return Status.OK_STATUS;
              }
            };
        job.setRule(project.getParent());
        job.schedule();
      }
    } catch (CoreException e) {
      PHPEplPlugin.logError(e);
    }
  }