Java Code Examples for org.eclipse.core.resources.IResourceDelta#getKind()

The following examples show how to use org.eclipse.core.resources.IResourceDelta#getKind() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RestoreProjectListener.java    From thym with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void resourceChanged(IResourceChangeEvent event) {
	IResourceDelta[] projectDeltas = event.getDelta().getAffectedChildren();
	for (IResourceDelta delta : projectDeltas) {
		if((delta.getResource().getType() == IResource.PROJECT) && 
			(delta.getKind() == IResourceDelta.CHANGED || delta.getKind() == IResourceDelta.ADDED) 
				&& (delta.getFlags() & IResourceDelta.OPEN) != 0){
			IProject project = delta.getResource().getProject();
			if(project.isOpen()){
				HybridProject hybridProject  = HybridProject.getHybridProject(project);
				if(hybridProject != null ) {
					RestoreProjectJob job = new RestoreProjectJob(project);
					ISchedulingRule rule = ResourcesPlugin.getWorkspace().getRuleFactory().modifyRule(project);
					job.setRule(rule);
					job.schedule();
				}
			}
		}
	}
}
 
Example 2
Source File: HierarchicalDataWorkspaceModelFactory.java    From dawnsci with Eclipse Public License 1.0 6 votes vote down vote up
public boolean visit(IResourceDelta delta) {
	boolean clear = false;
	IResource resource = delta.getResource();

	if (resource instanceof IFile) {
		switch (delta.getKind()) {
		case IResourceDelta.ADDED:
		case IResourceDelta.REMOVED:
			clear = true;
			break;
		case IResourceDelta.CHANGED:
			int flags = delta.getFlags();
			if ((flags & (IResourceDelta.CONTENT | IResourceDelta.LOCAL_CHANGED)) != 0) {
				clear = true;
			}
		default:
			break;
		}
		if (clear) {
			model.clearFileCache((IFile) resource);
		}
	}
	return true;
}
 
Example 3
Source File: XtextBuilder.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Creates a visitor that is used to traverse the information that is obtained from {@link #getDelta(IProject)}. It
 * accumulates its findings in the given <code>toBeBuilt</code>.
 */
protected IResourceDeltaVisitor createDeltaVisitor(ToBeBuiltComputer toBeBuiltComputer, ToBeBuilt toBeBuilt,
		final SubMonitor progress) {
	IResourceDeltaVisitor visitor = new IResourceDeltaVisitor() {
		@Override
		public boolean visit(IResourceDelta delta) throws CoreException {
			if (progress.isCanceled())
				throw new OperationCanceledException();
			if (delta.getResource() instanceof IProject) {
				return true;
			}
			if (delta.getResource() instanceof IStorage) {
				if (delta.getKind() == IResourceDelta.REMOVED) {
					return toBeBuiltComputer.removeStorage(null, toBeBuilt, (IStorage) delta.getResource());
				} else if (delta.getKind() == IResourceDelta.ADDED || delta.getKind() == IResourceDelta.CHANGED) {
					return toBeBuiltComputer.updateStorage(null, toBeBuilt, (IStorage) delta.getResource());
				}
			}
			return true;
		}
	};
	return visitor;
}
 
Example 4
Source File: ProjectOpenedOrClosedListener.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * @since 2.17
 */
protected boolean visitResourceDelta(IResourceDelta delta, final Set<IProject> accumulator) {
	if (delta.getResource() instanceof IWorkspaceRoot)
		return true;
	if (delta.getResource() instanceof IProject) {
		IProject project = (IProject) delta.getResource();
		if ((delta.getKind() & IResourceDelta.CHANGED) != 0 && project.isOpen()) {
			if ((delta.getFlags() & IResourceDelta.OPEN) != 0) {
				accumulator.add(project);
			}
			if ((delta.getFlags() & IResourceDelta.DESCRIPTION) != 0) {
				if ((delta.findMember(new Path(".project")) != null) && XtextProjectHelper.hasNature(project)
						&& XtextProjectHelper.hasBuilder(project))
					accumulator.add(project);
				else if (!XtextProjectHelper.hasNature(project)) {
					scheduleRemoveProjectJobIfNecessary(project, delta);
				}
			}
		}
	}
	return false;
}
 
Example 5
Source File: SCTBuilder.java    From statecharts with Eclipse Public License 1.0 6 votes vote down vote up
public boolean visit(IResourceDelta delta) throws CoreException {
	IResource resource = delta.getResource();
	switch (delta.getKind()) {
	case IResourceDelta.ADDED:
		// handle added resource
		doIt(resource, buildSgens);
		break;
	case IResourceDelta.REMOVED:
		// handle removed resource
		break;
	case IResourceDelta.CHANGED:
		// handle changed resource
		doIt(resource, buildSgens);
		break;
	}
	// return true to continue visiting children.
	return true;
}
 
Example 6
Source File: UIResourceChangeRegistry.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
private boolean hasContentsChanged(final IResourceDelta delta) {
  int _kind = delta.getKind();
  boolean _equals = (_kind == IResourceDelta.CHANGED);
  if (_equals) {
    return ((delta.getFlags() & UIResourceChangeRegistry.HAS_CONTENTS_CHANGED_FLAGS) != 0);
  } else {
    return false;
  }
}
 
Example 7
Source File: ProblemMarkerManager.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public boolean visit(IResourceDelta delta) throws CoreException {
    IResource res = delta.getResource();
    if (res instanceof IProject && delta.getKind() == IResourceDelta.CHANGED) {
        IProject project = (IProject) res;
        if (!project.isAccessible()) {
            // only track open projects
            return false;
        }
    }
    checkInvalidate(delta, res);
    return true;
}
 
Example 8
Source File: FileContentNotifierBridge.java    From saros with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void resourceChanged(IResourceChangeEvent event) {
  if (event.getDelta() == null) return;

  Deque<IResourceDelta> stack = new LinkedList<IResourceDelta>();

  stack.addAll(Arrays.asList(event.getDelta().getAffectedChildren()));

  while (!stack.isEmpty()) {
    IResourceDelta delta = stack.pop();
    stack.addAll(Arrays.asList(delta.getAffectedChildren()));

    if (delta.getResource().getType() == IResource.FILE) {

      // TODO check the Eclipse API to ignore more events
      if (delta.getKind() == IResourceDelta.NO_CHANGE) continue;

      if ((delta.getKind() == IResourceDelta.CHANGED)
          && (delta.getFlags() == IResourceDelta.MARKERS)) continue;

      final IFile file = delta.getResource().getAdapter(IFile.class);

      for (IFileContentChangedListener listener : fileContentChangedListeners)
        listener.fileContentChanged(ResourceAdapterFactory.create(file));
    }
  }
}
 
Example 9
Source File: ResourceUtils.java    From goclipse with Eclipse Public License 1.0 5 votes vote down vote up
protected static String deltaKindToString(IResourceDelta delta) {
	switch (delta.getKind()) {
	case IResourceDelta.ADDED: return "+";
	case IResourceDelta.REMOVED: return "-";
	case IResourceDelta.CHANGED: return "*";
	case IResourceDelta.ADDED_PHANTOM: return "%+%";
	case IResourceDelta.REMOVED_PHANTOM: return "%-%";
	default:
		throw assertFail();
	}
}
 
Example 10
Source File: ProblemManager.java    From typescript.java with MIT License 5 votes vote down vote up
private void checkInvalidate(IResourceDelta delta, IResource resource) {
	int kind = delta.getKind();
	if (kind == IResourceDelta.REMOVED || kind == IResourceDelta.ADDED
			|| (kind == IResourceDelta.CHANGED && isProblemDelta(delta))) {

		// Invalidate the resource and all its ancestors
		for (IResource r = resource; r != null; r = r.getParent()) {
			boolean added = changedResources.add(r);
			if (!added) {
				break;
			}
		}
	}
}
 
Example 11
Source File: ResourceChangeReporter.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean visit(final IResourceDelta delta) {
	if (!DEBUG.IS_ON()) { return false; }
	final IResource res = delta.getResource();
	switch (delta.getKind()) {
		case IResourceDelta.ADDED:
			DEBUG.OUT("Resource " + res.getFullPath() + " was added.");
			break;
		case IResourceDelta.REMOVED:
			DEBUG.OUT("Resource " + res.getFullPath() + " was removed.");
			break;
		case IResourceDelta.CHANGED:
			DEBUG.OUT("Resource " + delta.getFullPath() + " has changed.");
			final int flags = delta.getFlags();
			if ((flags & IResourceDelta.CONTENT) != 0) {
				DEBUG.OUT("--> Content Change");
			}
			if ((flags & IResourceDelta.REPLACED) != 0) {
				DEBUG.OUT("--> Content Replaced");
			}
			if ((flags & IResourceDelta.MARKERS) != 0) {
				DEBUG.OUT("--> Marker Change");
				// final IMarkerDelta[] markers = delta.getMarkerDeltas();
				// if interested in markers, check these deltas
			}
			break;
	}
	return true; // visit the children
}
 
Example 12
Source File: JavaWorkingSetUpdater.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void processResourceDelta(WorkingSetDelta result, IResourceDelta delta) {
	IResource resource= delta.getResource();
	int type= resource.getType();
	int index= result.indexOf(resource);
	int kind= delta.getKind();
	int flags= delta.getFlags();
	if (kind == IResourceDelta.CHANGED && type == IResource.PROJECT && index != -1) {
		if ((flags & IResourceDelta.OPEN) != 0) {
			result.set(index, resource);
		}
	}
	if (index != -1 && kind == IResourceDelta.REMOVED) {
		if ((flags & IResourceDelta.MOVED_TO) != 0) {
			result.set(index,
				ResourcesPlugin.getWorkspace().getRoot().findMember(delta.getMovedToPath()));
		} else {
			result.remove(index);
		}
	}

	// Don't dive into closed or opened projects
	if (projectGotClosedOrOpened(resource, kind, flags))
		return;

	IResourceDelta[] children= delta.getAffectedChildren();
	for (int i= 0; i < children.length; i++) {
		processResourceDelta(result, children[i]);
	}
}
 
Example 13
Source File: N4JSAllContainersState.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Indicates whether the resource change represented by the given {@code delta} does affect this container state.
 *
 * Note that this method will only be invoked until a container-state-affecting delta is found. Thus, it is not
 * suitable for listening for all resource changes that may occur in the workspace.
 */
@Override
protected boolean isAffectingContainerState(IResourceDelta delta) {
	if (delta.getKind() == IResourceDelta.ADDED || delta.getKind() == IResourceDelta.REMOVED) {
		String fileExtension = delta.getFullPath().getFileExtension();
		if (null != fileExtension && fileExtensionTypeHelper.isTypable(fileExtension)) {
			return true;
		}
		if (IN4JSProject.PACKAGE_JSON.equals(delta.getFullPath().lastSegment())) {
			return true;
		}

		if (delta.getResource() instanceof IProject) {
			return true;
		}
		if (delta.getResource() instanceof IFolder && isSourceContainerModification(delta)) {
			return true;
		}
		return false;
	} else if (delta.getKind() == IResourceDelta.CHANGED && delta.getResource() instanceof IProject) {
		if ((delta.getFlags() & IResourceDelta.DESCRIPTION) != 0) {
			return true;
		}
		if ((delta.getFlags() & IResourceDelta.OPEN) != 0) {
			return true;
		}
		return false;
	}
	if (packageJSONFileHasBeenChanged(delta)) {
		return true;
	}
	return false;
}
 
Example 14
Source File: ProblemMarkerManager.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
private void checkInvalidate(IResourceDelta delta, IResource resource)
{
	int kind = delta.getKind();
	if (kind == IResourceDelta.REMOVED || kind == IResourceDelta.ADDED
			|| (kind == IResourceDelta.CHANGED && isErrorDelta(delta)))
	{
		// invalidate the resource and all parents
		while (resource.getType() != IResource.ROOT && fChangedElements.add(resource))
		{
			resource = resource.getParent();
		}
	}
}
 
Example 15
Source File: ExtLibDesignElementLookup.java    From XPagesExtensionLibrary with Apache License 2.0 5 votes vote down vote up
public void resourceChanged(IResourceChangeEvent event) {
            // @TODO: need to filter resource events!
            try {
                IResourceDeltaVisitor visitor = new IResourceDeltaVisitor() {
                    
                    boolean keepVisiting = true;
                    
                    public boolean visit(IResourceDelta delta) {
                        
                        if (!keepVisiting || null == designerProject)
                            return false;
                        
                        int k = delta.getKind();
                        if ( ! (IResourceDelta.ADDED == k || 
                                IResourceDelta.REMOVED == k || 
                                IResourceDelta.CHANGED == k) )  // an update could be a name change
                           return true;

//                       if ((delta.getFlags() ...?
                       IResource resource = delta.getResource();
                       if (resource.getType() == IResource.FILE && resource.getProject().equals(designerProject.getProject())) {
                           String resExt = resource.getFileExtension();
                           String typeExt = extForType(); 
                           if (typeExt.length() > 0 && resExt.length() > 0 &&
                               typeExt.equalsIgnoreCase(resExt)) {
                               keepVisiting = false;
                               updateDesignElements();
                           }
                       }
                       return keepVisiting;
                    }
                 };
                 
                 event.getDelta().accept(visitor);
            }
            catch(Exception e) {
                ExtLibToolingLogger.EXT_LIB_TOOLING_LOGGER.error(e, e.toString());            }
        }
 
Example 16
Source File: BuildscriptGenerator.java    From cmake4eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public boolean visit(IResourceDelta delta) {
  switch (delta.getKind()) {
  case IResourceDelta.CHANGED:
    IResource resource = delta.getResource();
    if (resource.getType() == IResource.FILE && resource.getName().equals("CMakeLists.txt")) {
      hasChanges= true;
      return false;
    }
  }
  return true;
}
 
Example 17
Source File: ResourceDeltaVisitor.java    From saros with GNU General Public License v2.0 4 votes vote down vote up
@Override
public boolean visit(final IResourceDelta delta) throws CoreException {

  final IResource resource = delta.getResource();

  if (resource.getType() == IResource.ROOT) return true;

  if (!session.isShared(ResourceAdapterFactory.create(resource))) return true;

  if (resource.getType() != IResource.PROJECT) {
    isModifyingResources = true;
    return false;
  }

  if (delta.getKind() == IResourceDelta.REMOVED) {

    if ((delta.getFlags() & IResourceDelta.MOVED_TO) != 0) isMovingProject = true;
    else isDeletingProject = true;

    return false;
  }

  return true;
}
 
Example 18
Source File: PydevInternalResourceDeltaVisitor.java    From Pydev with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Visits the resource delta tree determining which files to rebuild (*.py).
 *
 * Subclasses should only reimplement visitChanged, visitAdded and visitRemoved. This method will not be called
 * in the structure provided by pydev.
 *
 * @see org.eclipse.core.resources.IResourceDeltaVisitor#visit(org.eclipse.core.resources.IResourceDelta)
 */
@Override
public boolean visit(IResourceDelta delta) throws CoreException {
    if (delta == null) {
        return true;
    }

    final IResource resource = delta.getResource();

    if (resource == null) {
        return true;
    }

    int type = resource.getType();

    //related bug https://sourceforge.net/tracker/index.php?func=detail&aid=1238850&group_id=85796&atid=577329

    //the team-support plugins of eclipse use the IResource
    //method setTeamPrivateMember to indicate resources
    //that are only in the project for the team-stuff (e.g. .svn or
    //.cvs or _darcs directories).
    if (resource.isTeamPrivateMember()) {
        return true;
    }

    if (type == IResource.FOLDER) {
        switch (delta.getKind()) {
            case IResourceDelta.REMOVED:
                memo.put(PyDevBuilderVisitor.DOCUMENT_TIME, System.currentTimeMillis());
                visitRemovedResource(resource, null, monitor);
                break;
            //for folders, we don't have to do anything if added or changed (we just treat their children, that should
            //resolve for modules -- we do, however have to treat __init__.py differently).
        }

    } else if (type == IResource.FILE) {
        String ext = resource.getFileExtension();
        if (ext == null) { //resource.getFileExtension() may return null if it has none.
            if (resource instanceof IFile) {
                CorePlugin.markAsPyDevFileIfDetected((IFile) resource);
            }
            return true;
        }

        //only analyze projects with the python nature...
        IProject project = resource.getProject();
        PythonNature nature = PythonNature.getPythonNature(project);

        if (project != null && nature != null) {
            //we just want to make the visit if it is a valid python file and it is in the pythonpath
            if (PythonPathHelper.isValidSourceFile("." + ext)) {
                onVisitDelta(delta);

            } else if (ext.equals("pyc")) {
                if (delta.getKind() == IResourceDelta.ADDED) {
                    handleAddedPycFiles(resource, nature);
                }
            }
        }
    }

    return true;
}
 
Example 19
Source File: UIResourceChangeRegistryTest.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
public static String toReadableString(final IResourceDelta delta) {
  StringConcatenation _builder = new StringConcatenation();
  IPath _fullPath = delta.getFullPath();
  _builder.append(_fullPath);
  _builder.append(" ");
  String _switchResult = null;
  int _kind = delta.getKind();
  switch (_kind) {
    case IResourceDelta.ADDED:
      _switchResult = "ADDED";
      break;
    case IResourceDelta.REMOVED:
      _switchResult = "REMOVED";
      break;
    case IResourceDelta.CHANGED:
      _switchResult = "CHANGED";
      break;
  }
  _builder.append(_switchResult);
  _builder.append(" ");
  Pair<Integer, String> _mappedTo = Pair.<Integer, String>of(Integer.valueOf(IResourceDelta.CONTENT), "CONTENT");
  Pair<Integer, String> _mappedTo_1 = Pair.<Integer, String>of(Integer.valueOf(IResourceDelta.DERIVED_CHANGED), "DERIVED_CHANGED");
  Pair<Integer, String> _mappedTo_2 = Pair.<Integer, String>of(Integer.valueOf(IResourceDelta.DESCRIPTION), "DESCRIPTION");
  Pair<Integer, String> _mappedTo_3 = Pair.<Integer, String>of(Integer.valueOf(IResourceDelta.ENCODING), "ENCODING");
  Pair<Integer, String> _mappedTo_4 = Pair.<Integer, String>of(Integer.valueOf(IResourceDelta.LOCAL_CHANGED), "LOCAL_CHANGED");
  Pair<Integer, String> _mappedTo_5 = Pair.<Integer, String>of(Integer.valueOf(IResourceDelta.OPEN), "OPEN");
  Pair<Integer, String> _mappedTo_6 = Pair.<Integer, String>of(Integer.valueOf(IResourceDelta.MOVED_TO), "MOVED_TO");
  Pair<Integer, String> _mappedTo_7 = Pair.<Integer, String>of(Integer.valueOf(IResourceDelta.MOVED_FROM), "MOVED_FROM");
  Pair<Integer, String> _mappedTo_8 = Pair.<Integer, String>of(Integer.valueOf(IResourceDelta.COPIED_FROM), "COPIED_FROM");
  Pair<Integer, String> _mappedTo_9 = Pair.<Integer, String>of(Integer.valueOf(IResourceDelta.TYPE), "TYPE");
  Pair<Integer, String> _mappedTo_10 = Pair.<Integer, String>of(Integer.valueOf(IResourceDelta.SYNC), "SYNC");
  Pair<Integer, String> _mappedTo_11 = Pair.<Integer, String>of(Integer.valueOf(IResourceDelta.MARKERS), "MARKERS");
  Pair<Integer, String> _mappedTo_12 = Pair.<Integer, String>of(Integer.valueOf(IResourceDelta.REPLACED), "REPLACED");
  final Function1<Pair<Integer, String>, String> _function = (Pair<Integer, String> it) -> {
    String _xifexpression = null;
    if (((delta.getFlags() & (it.getKey()).intValue()) != 0)) {
      _xifexpression = it.getValue();
    } else {
      _xifexpression = null;
    }
    return _xifexpression;
  };
  String _join = IterableExtensions.join(IterableExtensions.<String>filterNull(ListExtensions.<Pair<Integer, String>, String>map(Collections.<Pair<Integer, String>>unmodifiableList(CollectionLiterals.<Pair<Integer, String>>newArrayList(_mappedTo, _mappedTo_1, _mappedTo_2, _mappedTo_3, _mappedTo_4, _mappedTo_5, _mappedTo_6, _mappedTo_7, _mappedTo_8, _mappedTo_9, _mappedTo_10, _mappedTo_11, _mappedTo_12)), _function)), ",");
  _builder.append(_join);
  _builder.append(" {");
  _builder.newLineIfNotEmpty();
  {
    IResourceDelta[] _affectedChildren = delta.getAffectedChildren();
    for(final IResourceDelta child : _affectedChildren) {
      _builder.append("\t");
      String _readableString = UIResourceChangeRegistryTest.TestUiResourceChangeRegistry.toReadableString(child);
      _builder.append(_readableString, "\t");
      _builder.newLineIfNotEmpty();
    }
  }
  _builder.append("}");
  _builder.newLine();
  return _builder.toString();
}
 
Example 20
Source File: UIResourceChangeRegistry.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
private boolean hasExistsChanged(final IResourceDelta delta) {
  return ((delta.getKind() == IResourceDelta.ADDED) || (delta.getKind() == IResourceDelta.REMOVED));
}