org.eclipse.core.resources.IResourceDeltaVisitor Java Examples

The following examples show how to use org.eclipse.core.resources.IResourceDeltaVisitor. 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: WebPageNameResourceChangeListener.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
private IResourceDeltaVisitor resourceDeltaVisitor() {
    return delta -> {
        String name = delta.getResource().getName();
        WebPageRepositoryStore repositoryStore = repositoryAccessor
                .getRepositoryStore(WebPageRepositoryStore.class);
        if ((delta.getKind() == IResourceDelta.ADDED || delta.getKind() == IResourceDelta.CHANGED)
                && repositoryStore.getResource().getLocation().isPrefixOf(delta.getResource().getLocation())
                && delta.getResource() instanceof IFolder
                && delta.getResource().isSynchronized(IResource.DEPTH_INFINITE)
                && repositoryStore.getChild(name, false) != null) {
            WebPageFileStore pageFileStore = repositoryStore.getChild(name, false);
            IFile indexJsonFile = retrieveIndexJsonFile(repositoryStore);
            if (indexJsonFile.exists()) {
                try (InputStream is = indexJsonFile.getContents()) {
                    JSONObject jsonObject = new JSONObject(IoUtils.toString(is));
                    updateMatchingFormMapping(mainProcess, jsonObject, pageFileStore.getDisplayName());
                } catch (IOException | JSONException e) {
                    throw new RuntimeException(e);
                }
            }
        }
        return true;
    };
}
 
Example #2
Source File: ProjectFileChangeListener.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void resourceChanged(IResourceChangeEvent event) {
    try {
        if (event != null && event.getDelta() != null) {
            event.getDelta().accept(new IResourceDeltaVisitor() {

                @Override
                public boolean visit(IResourceDelta delta) throws CoreException {
                    IProject project = repository.getProject();
                    if (project.isAccessible()) {
                        IFile projectFile = project.getFile(".project");
                        final IResource resource = delta.getResource();
                        if (Objects.equals(resource, projectFile)) {
                            return checkVersion(project);
                        }
                    }
                    return true;
                }
            });
        }
    } catch (CoreException e) {
        BonitaStudioLog.error(e);
    }
}
 
Example #3
Source File: SearchResultUpdater.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
private void handleDelta(IResourceDelta d) {
    try {
        d.accept(new IResourceDeltaVisitor() {
            @Override
            public boolean visit(IResourceDelta delta) throws CoreException {
                switch (delta.getKind()) {
                    case IResourceDelta.ADDED:
                        return false;
                    case IResourceDelta.REMOVED:
                        IResource res = delta.getResource();
                        if (res instanceof IFile) {
                            Match[] matches = fResult.getMatches(res);
                            fResult.removeMatches(matches);
                        }
                        break;
                    case IResourceDelta.CHANGED:
                        // handle changed resource
                        break;
                }
                return true;
            }
        });
    } catch (CoreException e) {
        Log.log(e);
    }
}
 
Example #4
Source File: SearchResultUpdater.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
private void handleDelta(IResourceDelta d) {
    try {
        d.accept(new IResourceDeltaVisitor() {
            @Override
            public boolean visit(IResourceDelta delta) throws CoreException {
                switch (delta.getKind()) {
                    case IResourceDelta.ADDED:
                        return false;
                    case IResourceDelta.REMOVED:
                        IResource res = delta.getResource();
                        if (res instanceof IFile) {
                            Match[] matches = fResult.getMatches(res);
                            fResult.removeMatches(matches);
                        }
                        break;
                    case IResourceDelta.CHANGED:
                        // handle changed resource (remove existing matches and redo search in file).
                        break;
                }
                return true;
            }
        });
    } catch (CoreException e) {
        Log.log(e);
    }
}
 
Example #5
Source File: ResourceUtilsTest.java    From google-cloud-eclipse with Apache License 2.0 6 votes vote down vote up
private static IResourceDelta mockDelta() throws CoreException {
  // the actual ResourceDelta class includes a lot of internals
  IResourceDelta delta = mock(IResourceDelta.class);
  IResourceDelta[] empty = new IResourceDelta[0];

  when(delta.getAffectedChildren()).thenReturn(empty);
  doAnswer(
          invocation -> {
            IResourceDelta thisDelta = (IResourceDelta) invocation.getMock();
            IResourceDeltaVisitor visitor =
                invocation.getArgumentAt(0, IResourceDeltaVisitor.class);

            if (visitor.visit(thisDelta)) {
              for (IResourceDelta childDelta : thisDelta.getAffectedChildren()) {
                childDelta.accept(visitor);
              }
            }
            return null;
          })
      .when(delta)
      .accept(any(IResourceDeltaVisitor.class));

  return delta;
}
 
Example #6
Source File: ICEResourcePage.java    From ice with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void resourceChanged(IResourceChangeEvent event) {
	if (event.getType() == IResourceChangeEvent.POST_CHANGE) {
		try {
			event.getDelta().accept(new IResourceDeltaVisitor() {
				@Override
				public boolean visit(IResourceDelta delta)
						throws CoreException {
					for (ICEResource r : ICEResourcePage.this.resourceComponent
							.getResources()) {
						if (delta.getResource().getName().equals(
								(new File(r.getPath()).getName()))) {
							ICEResourcePage.this.update(r);
						}
					}
					return true;
				}
			});
		} catch (CoreException e) {
			e.printStackTrace();
		}
	}
}
 
Example #7
Source File: XtextBuilder.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * @param monitor the progress monitor to use for reporting progress to the user. It is the caller's responsibility
 *        to call done() on the given monitor. Accepts null, indicating that no progress should be
 *        reported and that the operation cannot be cancelled.
 */
protected void incrementalBuild(IResourceDelta delta, final IProgressMonitor monitor) throws CoreException {
	final SubMonitor progress = SubMonitor.convert(monitor, Messages.XtextBuilder_CollectingResources, 10);
	progress.subTask(Messages.XtextBuilder_CollectingResources);
	
	pollQueuedBuildData();

	final ToBeBuilt toBeBuilt = new ToBeBuilt();
	IResourceDeltaVisitor visitor = createDeltaVisitor(toBeBuiltComputer, toBeBuilt, progress);
	delta.accept(visitor);

	if (progress.isCanceled()) {
		throw new OperationCanceledException();
	}
	progress.worked(2);
	Task task = closedProjectsQueue.exhaust();
	try {
		addInfosFromTaskAndBuild(task, toBeBuilt, BuildType.INCREMENTAL, progress.split(8));
	} catch(Exception e) {
		task.reschedule();
		throw e;
	}
}
 
Example #8
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 #9
Source File: PlatformHolder.java    From hybris-commerce-eclipse-plugin with Apache License 2.0 6 votes vote down vote up
void workspaceChanged(IResourceChangeEvent event) {
	try {
		if (event.getType() == IResourceChangeEvent.PRE_DELETE || event.getType() == IResourceChangeEvent.PRE_CLOSE) {
			if (Platform.isPlatformProject((IProject)event.getResource())) {
				clear();
			}
		}
		else if (event.getType() == IResourceChangeEvent.POST_CHANGE) {
			event.getDelta().accept(new IResourceDeltaVisitor() {

				@Override
				public boolean visit(IResourceDelta delta) throws CoreException {
					if (delta.getKind() == IResourceDelta.ADDED
							&& delta.getResource().getType() == IResource.PROJECT) {
						projectAdded((IProject) delta.getResource());
					}
					return delta.getResource().getType() == IResource.ROOT;
				}

			});
		}
	} catch (CoreException e) {
		log.log(new Status(Status.ERROR, log.getBundle().getSymbolicName(), "Error when handling IResourceChangedEvent", e));
	}
}
 
Example #10
Source File: XBookmarksPlugin.java    From xds-ide with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void resourceChanged(IResourceChangeEvent event) {
    if (event.getType() == IResourceChangeEvent.POST_CHANGE) {
        try {
            event.getDelta().accept(new IResourceDeltaVisitor() {
                @Override
                public boolean visit(IResourceDelta delta) throws CoreException {
                    IResource res = delta.getResource();
                    switch (delta.getKind()) {
                    case IResourceDelta.REMOVED:
                        XBookmarksUtils.removeBookmarksFrom(res);
                        break;
                    }
                    return true; // visit the children
                }
            });
        } catch (CoreException e) {}
    }
}
 
Example #11
Source File: FileEntry.java    From ice with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void resourceChanged(IResourceChangeEvent event) {
	if (project != null) {
		if (event.getType() == IResourceChangeEvent.POST_CHANGE) {
			try {
				event.getDelta().accept(new IResourceDeltaVisitor() {
					public boolean visit(IResourceDelta delta) throws CoreException {
						IProject p = delta.getResource().getProject();
						if (p != null && p.getName().equals(project.getName())) {
							generateAllowedValues();
							notifyListeners();
						}
						return true;
					}
				});
			} catch (CoreException e) {
				e.printStackTrace();
			}
		}
	}
}
 
Example #12
Source File: BibtexEntryView.java    From slr-toolkit with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Returns a list of newly added projects.
 * 
 * @param resourceDelta
 * @return List of newly added projects.
 */
private List<IProject> getAddedProjects(IResourceDelta resourceDelta) {
	final List<IProject> projects = new ArrayList<IProject>();
	try {
		resourceDelta.accept(new IResourceDeltaVisitor() {
			public boolean visit(IResourceDelta delta) throws CoreException {
				if (delta.getKind() == IResourceDelta.ADDED
						&& delta.getResource().getType() == IResource.PROJECT) {
					IProject project = (IProject) delta.getResource();
					projects.add(project);
					return false;
				}
				return delta.getResource().getType() == IResource.ROOT;
			}
		});
	} catch (CoreException e) {
		e.printStackTrace();
	}
	return projects;
}
 
Example #13
Source File: StatusCacheManager.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
public void resourceChanged(IResourceChangeEvent event) {	
	flushCache = false;
	try {
           event.getDelta().accept(new IResourceDeltaVisitor() {
               public boolean visit(IResourceDelta delta) throws CoreException {
               	IResource resource = delta.getResource();
               	if (resource.getType()==IResource.PROJECT) {
               		IProject project = (IProject)resource;
					if (!project.isAccessible()) {
						return false; // i.e., closed project
					}
					if (SVNWorkspaceRoot.isManagedBySubclipse(project)) {
						flushCache = true;
					}
					return false; // No need to check deeper than project.
               	}
                   return true;
               }
           });			
    } catch (CoreException e) {
      SVNProviderPlugin.log(e.getStatus());
    }
	if (flushCache) {
		statusCache.flushPendingStatuses();
	}
}
 
Example #14
Source File: FindBugs2Eclipse.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void resourceChanged(IResourceChangeEvent event) {
    if (event.getSource() instanceof IProject) {
        cleanClassClache((IProject) event.getSource());
    } else if (event.getResource() instanceof IProject) {
        cleanClassClache((IProject) event.getResource());
    } else if (event.getDelta() != null) {
        final Set<IProject> affectedProjects = new HashSet<>();
        final IResourceDelta delta = event.getDelta();
        try {
            delta.accept(new IResourceDeltaVisitor() {
                @Override
                public boolean visit(IResourceDelta d1) throws CoreException {
                    if (d1 == delta || d1.getFlags() == 0 || d1.getFlags() == IResourceDelta.MARKERS) {
                        return true;
                    }
                    IResource resource = d1.getResource();
                    if (resource instanceof IProject) {
                        affectedProjects.add((IProject) resource);
                        return false;
                    }
                    return true;
                }
            });
        } catch (CoreException e) {
            FindbugsPlugin.getDefault().logException(e, "Error traversing resource delta");
        }
        for (IProject iProject : affectedProjects) {
            cleanClassClache(iProject);
        }
    }
}
 
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: TeamPrivateListener.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Listen for file modifications
 * 
 * @see org.eclipse.core.resources.IResourceChangeListener#resourceChanged(org.eclipse.core.resources.IResourceChangeEvent)
 */
public void resourceChanged(IResourceChangeEvent event) {		
	try {
		event.getDelta().accept(new IResourceDeltaVisitor() {
			public boolean visit(IResourceDelta delta) throws CoreException {
				IResource resource = delta.getResource();
				int type = resource.getType();

				if(type==IResource.FOLDER) {
					if (delta.getKind() != IResourceDelta.ADDED)
						return true;
					if (provider.isAdminDirectory(resource.getName())) {
						if (handleSVNDir((IContainer)resource)) {
							return false;
						}
					}
					return true;
				}				
				else if (type==IResource.PROJECT) {
					IProject project = (IProject)resource;
					if (!project.isAccessible()) {
						return false;
					}
					if (!SVNWorkspaceRoot.isManagedBySubclipse(project)) {
						return false; // not a svn handled project
					}
				}
				return true;
			}
		});
	} catch (CoreException e) {
		SVNProviderPlugin.log(e.getStatus());
	}			
}
 
Example #17
Source File: ResourceCache.java    From depan with Apache License 2.0 5 votes vote down vote up
@Override
public void resourceChanged(IResourceChangeEvent event) {
  try {
    IResourceDeltaVisitor visitor = new ForgetResources();
    event.getDelta().accept(visitor);
  } catch (CoreException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
  }
}
 
Example #18
Source File: PubspecChangeListener.java    From dartboard with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void resourceChanged(IResourceChangeEvent event) {
	if (event.getType() == IResourceChangeEvent.POST_CHANGE) {
		try {
			event.getDelta().accept(new IResourceDeltaVisitor() {

				@Override
				public boolean visit(IResourceDelta delta) throws CoreException {
					IResource resource = delta.getResource();
					if (resource.getType() == IResource.FILE && GlobalConstants.PUBSPEC_YAML.equals(resource.getName())
							&& (delta.getKind() == ADDED || isContentChanged(delta))) {
						for (IPubService abstractPubService : pubServices) {
							// At this point, resource is the pubspec.yaml
							if (abstractPubService.test(resource.getProject())) {
								abstractPubService.get(resource.getProject());
								break;
							}
						}
					}
					return true;
				}
			});
		} catch (CoreException e) {
			LOG.log(DartLog.createError(e.getMessage(), e));
		}
	}
}
 
Example #19
Source File: ProjectOpenedOrClosedListener.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
private IResourceDeltaVisitor createVisitor(final Set<IProject> accumutor) {
	return new IResourceDeltaVisitor() {
		@Override
		public boolean visit(IResourceDelta delta) throws CoreException {
			return visitResourceDelta(delta, accumutor);
		}
	};
}
 
Example #20
Source File: PreviewEditorImpl.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
protected void handleResourceChanged ( final IResourceChangeEvent event )
{
    try
    {
        event.getDelta ().accept ( new IResourceDeltaVisitor () {

            @Override
            public boolean visit ( final IResourceDelta delta ) throws CoreException
            {
                return handleResource ( delta );
            }
        } );
    }
    catch ( final CoreException e )
    {
        StatusManager.getManager ().handle ( e.getStatus () );
    }

    if ( this.needReload )
    {
        this.needReload = false;

        getSite ().getShell ().getDisplay ().asyncExec ( new Runnable () {

            @Override
            public void run ()
            {
                reload ();
            }
        } );
    }
}
 
Example #21
Source File: ProjectStateChangeListener.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
private IResourceDeltaVisitor projectCollector(final Set<IProject> accumutor) {
	return new IResourceDeltaVisitor() {
		@Override
		public boolean visit(IResourceDelta delta) throws CoreException {
			return collectAffectedProjects(delta, accumutor);
		}
	};
}
 
Example #22
Source File: N4JSAllContainersState.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Handles the given {@link IResourceChangeEvent} and updates the project state (cache of available projects and
 * project descriptions) accordingly.
 *
 * If the event contains a {@link IResourceDelta}, this method traverses the resource delta tree and invokes
 * {@link #updateProjectState(IResourceDelta)} accordingly.
 */
private void updateProjectState(IResourceChangeEvent event) {
	if (event.getDelta() != null) {
		IResourceDelta eventDelta = event.getDelta();
		try {
			AtomicBoolean mustClear = new AtomicBoolean(false);
			// traverse all resource deltas to a depth of 2 (projects and their direct children)
			eventDelta.accept(new IResourceDeltaVisitor() {
				@Override
				public boolean visit(IResourceDelta delta) throws CoreException {
					final IResource resource = delta.getResource();
					if (resource == null) {
						return true;
					}
					final IPath path = resource.getFullPath();
					final int pathLength = path.segmentCount();

					if (pathLength <= 2) {
						if (updateProjectState(delta)) {
							mustClear.set(true);
							return false;
						}
					}
					// only traverse the children of project-deltas (e.g. project description files)
					return pathLength == 0 || resource instanceof IProject;
				}
			});
			if (mustClear.get()) {
				projectsHelper.clearProjectCache();
			}
		} catch (CoreException e) {
			LOGGER.error("Failed to process IResourceDelta", e);
		}
	}
}
 
Example #23
Source File: XdsResourceChangeListener.java    From xds-ide with Eclipse Public License 1.0 4 votes vote down vote up
protected VisitResult doVisit(IResourceChangeEvent event) {
		final VisitResult visitResult = new VisitResult();
		IResourceDelta delta = event.getDelta();
        try {
            if (delta != null) { // it can be null for project removals
//            	printDelta(delta);
                beginDeltaProcessing(delta);
                delta.accept(new IResourceDeltaVisitor() {
                    @Override
                    public boolean visit(IResourceDelta childDelta) throws CoreException {
                        IResource affectedResource = childDelta.getResource();
                        if (!(affectedResource instanceof IWorkspaceRoot)) {
                            if (!NatureUtils.hasNature(affectedResource.getProject(), NatureIdRegistry.MODULA2_SOURCE_PROJECT_NATURE_ID)) {
                                return false; // DONT visit children of non-XDS nature project
                            }
                            
                            if (ResourceUtils.isInsideFolder(SpecialFolderNames.SETTINGS_DIR_NAME, affectedResource) ||
                            	ResourceUtils.isInsideFolder(SpecialFolderNames.EXTERNAL_DEPENDENCIES_DIR_NAME, affectedResource)) {
                                return false; // DONT visit children of .settings and .mnt directories
                            }
                            
                            boolean isChildrenShouldBeVisited;
                            switch (childDelta.getKind()) {
                            case IResourceDelta.ADDED:
                                isChildrenShouldBeVisited = handleResourceAdded(delta, childDelta, affectedResource);
                                visitResult.addedResourceDeltas.add(childDelta);
                                break;
                            case IResourceDelta.REMOVED:
                                isChildrenShouldBeVisited = handleResourceRemoved(delta, childDelta, affectedResource);
                            	visitResult.removedResourceDeltas.add(childDelta);
                                break;
                            case IResourceDelta.CHANGED:
                            	isChildrenShouldBeVisited = handleResourceChanged(delta, childDelta, affectedResource);
                            	visitResult.changedResourceDeltas.add(childDelta);
                                break;
                            default:
                            	isChildrenShouldBeVisited = true;
                                break;
                            }
                            return isChildrenShouldBeVisited;
                        }
                        return true;
                    }
                });
            } else {
            	boolean isPreDeleteEvent = event.getType() == IResourceChangeEvent.PRE_DELETE;
                if (isPreDeleteEvent || event.getType() == IResourceChangeEvent.PRE_CLOSE) {
                    IResource resource = event.getResource();
                    if (resource instanceof IProject) {
                        IProject project = (IProject)resource;
                        if (NatureUtils.hasNature(project, NatureIdRegistry.MODULA2_SOURCE_PROJECT_NATURE_ID)) {
                            handleProjectRemoved(delta, project, isPreDeleteEvent);
                            visitResult.removedResourceDeltas.add(delta);
                        }
                    }
            		
            	}
            }
        } catch (CoreException e) {
            LogHelper.logError(e);
        }
        finally{
        	endDeltaProcessing(delta);
        }
        return visitResult;
	}
 
Example #24
Source File: ResourceEvent.java    From scava with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public String toString() {

	StringBuilder builder = new StringBuilder();

	try {
		changeEvent.getDelta().accept(new IResourceDeltaVisitor() {

			@Override
			public boolean visit(IResourceDelta delta) {

				switch (delta.getKind()) {
				case IResourceDelta.ADDED:
					builder.append("ADDED: " + delta.getResource() + "\n");
					break;
				case IResourceDelta.REMOVED:
					builder.append("REMOVED: " + delta.getResource() + "\n");
					break;
				case IResourceDelta.CHANGED:

					System.out.println("==============================");
					System.out.println("\t" + changeEvent.getSource());
					System.out.println("\t" + delta.getResource().getFileExtension());
					// System.out.println("\t"+delt);
					System.out.println("\t" + delta.getResource().getType());
					System.out.println("\t" + delta.getResource().getName());
					System.out.println("\t" + changeEvent.getResource());
					System.out.println("==============================");
					builder.append("CHANGED: " + delta.getResource() + "\n");
					break;
				}
				builder.append(" + " + delta.getFullPath() + " + ");

				return true;
			}
		});
	} catch (CoreException e) {
		e.printStackTrace();
	}
	return "Date: " + date + " VertexType: " + VertexType.RESOURCE_EVENT + " --- " + builder;
}
 
Example #25
Source File: RelaunchInBackgroundAction.java    From Pydev with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public void resourceChanged(final IResourceChangeEvent event) {
    //Handle cases where the view was closed...
    if (view == null) {
        stopListening();
        return;
    }

    PyUnitView pyUnitView = view.get();
    if (pyUnitView == null) {
        stopListening();
        return;
    }

    final boolean[] run = new boolean[] { false };
    try {
        event.getDelta().accept(new IResourceDeltaVisitor() {

            @Override
            public boolean visit(IResourceDelta delta) {
                switch (delta.getKind()) {
                    case IResourceDelta.CHANGED:
                        IResource resource = delta.getResource();
                        if (resource instanceof IFile) {

                            //Check if a source file was changed (i.e.: don't get .pyc, .class, etc).
                            if (PythonPathHelper.isValidSourceFile((IFile) resource)) {
                                int flags = delta.getFlags();
                                if ((flags & IResourceDelta.CONTENT) != 0) {
                                    //Uncomment to debug...
                                    //System.out.println("----------------------");
                                    //System.out.println("----------------------");
                                    //System.out.println("----------------------");
                                    //System.out.println("----------------------");
                                    //System.out.println(event.getResource());
                                    //System.out.println(event.getBuildKind());
                                    //System.out.println(event.getSource());
                                    //System.out.println(resource+" "+resource.getModificationStamp());
                                    run[0] = true;
                                }
                            }
                        }
                        break;
                }
                return true;
            }
        });
    } catch (CoreException e) {
        Log.log(e);
    }

    if (run[0]) {
        //Ok, we've the view, let's relaunch the current launch (if any)
        PyUnitTestRun currentTestRun = pyUnitView.getCurrentTestRun();
        if (currentTestRun != null) {
            relaunchJob.setTestToRun(currentTestRun);
            relaunchJob.schedule(200); //Give some time to handle more changes...
        }
    }
}