org.eclipse.core.resources.IResourceDelta Java Examples

The following examples show how to use org.eclipse.core.resources.IResourceDelta. 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: 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 #2
Source File: PydevGrouperVisitor.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * This will use the internal builders to traverse the delta. Note that the resource is always a valid
 * python file and is also always located in the pythonpath.
 */
@Override
protected void onVisitDelta(IResourceDelta delta) {
    //Note: removals happen now, additions and changes happen later (so that renames are
    //properly treated).

    switch (delta.getKind()) {
        case IResourceDelta.ADDED:
        case IResourceDelta.CHANGED:
            delayedVisits.add(delta);
            break;
        case IResourceDelta.REMOVED:
            IResource resource = delta.getResource();
            memo.put(PyDevBuilderVisitor.DOCUMENT_TIME, System.currentTimeMillis());
            visitRemovedResource(resource, null, monitor);
            break;
    }
}
 
Example #3
Source File: HierarchicalDataWorkspaceModelFactory.java    From dawnsci with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Returns the IHierarchicalDataModel. If one does not exists, this method
 * will create one and register a workspace listener.
 *
 * @return
 */
public static IHierarchicalDataModel getHierarchicalDataModel() {
	IHierarchicalDataModelGetFileModel getModel = new GetFileModelFactory();
	final HierarchicalDataModel model = new HierarchicalDataModel(getModel);

	IResourceChangeListener listener = new IResourceChangeListener() {

		@Override
		public void resourceChanged(IResourceChangeEvent event) {
			IResourceDelta delta = event.getDelta();
			if (delta != null) {
				try {
					delta.accept(new DeltaVisitor(model));
				} catch (CoreException e) {
					// our visitor does not throw CoreException
				}
			}
		}
	};
	IWorkspace workspace = ResourcesPlugin.getWorkspace();
	workspace.addResourceChangeListener(listener);

	return model;
}
 
Example #4
Source File: TypeScriptBuilder.java    From typescript.java with MIT License 6 votes vote down vote up
@Override
protected IProject[] build(int kind, Map<String, String> args, final IProgressMonitor monitor)
		throws CoreException {
	IProject project = this.getProject();
	if (!TypeScriptResourceUtil.isTypeScriptProject(project)) {
		return null;
	}

	IIDETypeScriptProject tsProject = TypeScriptResourceUtil.getTypeScriptProject(project);
	if (kind == FULL_BUILD) {
		fullBuild(tsProject, monitor);
	} else {
		IResourceDelta delta = getDelta(getProject());
		if (delta == null) {
			fullBuild(tsProject, monitor);
		} else {
			incrementalBuild(tsProject, delta, monitor);
		}
	}
	return null;
}
 
Example #5
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 #6
Source File: PluginContentProvider.java    From thym with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void resourceChanged(IResourceChangeEvent event) {
	IResourceDelta delta = event.getDelta();
	if (viewer == null || delta == null)
		return;
	IResourceDelta[] deltas = delta.getAffectedChildren();
	for (int i = 0; i < deltas.length; i++) {
		if (deltas[i].findMember(new Path(PlatformConstants.DIR_PLUGINS)) != null) {
			viewer.getControl().getDisplay().asyncExec(new Runnable() {
				@Override
				public void run() {
					viewer.refresh();
				}
			});
			return;
		}
	}
}
 
Example #7
Source File: XdsModel.java    From xds-ide with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void handleChangeResource(IResourceDelta rootDelta, IResource affectedResource, boolean isContentChanged) {
    if (DEBUG_PRINT_OF_THE_CHANGE_NOTIFICATIONS) System.out.println("Change resource : " + affectedResource); //$NON-NLS-1$
    if (workspaceRoot == affectedResource) { // ignore plain workspace changes
        return;
    }
    
    if (affectedResource instanceof IProject) {
        IProject p = (IProject)affectedResource;
        IXdsProject xdsProject = getXdsProjectBy(p);
        if (xdsProject == null) { // this will be the case when the project is re-opened
            refreshProject(p);
            postponeProjectForRebuild(affectedResource.getProject());
        }
    }
    else if (affectedResource instanceof IFile) {
        IXdsResource xdsElement = getWorkspaceXdsElement(affectedResource);
        if (xdsElement != null) {
            xdsElement.resourceChanged();
        }
    }
}
 
Example #8
Source File: ProblemManager.java    From typescript.java with MIT License 6 votes vote down vote up
private void handleResourceChanged(IResourceChangeEvent event) {
	IResourceDelta delta = event.getDelta();
	if (delta == null) {
		return;
	}

	// Find resourced whose problems changed and report them to listeners
	Set<IResource> changedResources = new HashSet<>();
	try {
		delta.accept(new ProblemMarkerDeltaVisitor(changedResources));
	} catch (CoreException e) {
		TypeScriptCorePlugin.logError(e);
	}
	if (!changedResources.isEmpty()) {
		notifyListeners(Collections.unmodifiableSet(changedResources));
	}
}
 
Example #9
Source File: SyncFileChangeListener.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
protected void handleSVNDir(IContainer svnDir, int kind) {
	if((kind & IResourceDelta.ALL_WITH_PHANTOMS)!=0) {
		if(kind==IResourceDelta.ADDED) {
			// should this dir be made team-private? If it contains Entries then yes!
			IFile entriesFile = svnDir.getFile(new Path(SVNConstants.SVN_ENTRIES));

			if (entriesFile.exists() &&  !svnDir.isTeamPrivateMember()) {
				try {
					svnDir.setTeamPrivateMember(true);			
					if(Policy.DEBUG_METAFILE_CHANGES) {
						System.out.println("[svn] found a new SVN meta folder, marking as team-private: " + svnDir.getFullPath()); //$NON-NLS-1$
					}
				} catch(CoreException e) {
					SVNProviderPlugin.log(SVNException.wrapException(svnDir, Policy.bind("SyncFileChangeListener.errorSettingTeamPrivateFlag"), e)); //$NON-NLS-1$
				}
			}
		}
	}
}
 
Example #10
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 #11
Source File: JavaWorkingSetUpdater.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void elementChanged(ElementChangedEvent event) {
	IWorkingSet[] workingSets;
	synchronized(fWorkingSets) {
		workingSets= fWorkingSets.toArray(new IWorkingSet[fWorkingSets.size()]);
	}
	for (int w= 0; w < workingSets.length; w++) {
		WorkingSetDelta workingSetDelta= new WorkingSetDelta(workingSets[w]);
		processJavaDelta(workingSetDelta, event.getDelta());
		IResourceDelta[] resourceDeltas= event.getDelta().getResourceDeltas();
		if (resourceDeltas != null) {
			for (int r= 0; r < resourceDeltas.length; r++) {
				processResourceDelta(workingSetDelta, resourceDeltas[r]);
			}
		}
		workingSetDelta.process();
	}
}
 
Example #12
Source File: TsvBuilder.java    From hybris-commerce-eclipse-plugin with Apache License 2.0 6 votes vote down vote up
@Override
protected IProject[] build(int kind, @SuppressWarnings("rawtypes") Map args, IProgressMonitor monitor)
		throws CoreException {
	//TODO find referenced extensions and their eclipse projects and return them
	if (kind == CLEAN_BUILD) {
		clean(monitor);
	}
	else if (kind == FULL_BUILD) {
		fullBuild(monitor);
	} else {
		IResourceDelta delta = getDelta(getProject());
		if (delta == null) {
			fullBuild(monitor);
		} else {
			incrementalBuild(delta, monitor);
		}
	}
	return null;
}
 
Example #13
Source File: ProblemMarkerManager.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public void resourceChanged(IResourceChangeEvent event) {
	HashSet<IResource> changedElements= new HashSet<IResource>();

	try {
		IResourceDelta delta= event.getDelta();
		if (delta != null)
			delta.accept(new ProjectErrorVisitor(changedElements));
	} catch (CoreException e) {
		JavaPlugin.log(e.getStatus());
	}

	if (!changedElements.isEmpty()) {
		boolean hasChanges= false;
		synchronized (this) {
			if (fResourcesWithMarkerChanges.isEmpty()) {
				fResourcesWithMarkerChanges= changedElements;
				hasChanges= true;
			} else {
				hasChanges= fResourcesWithMarkerChanges.addAll(changedElements);
			}
		}
		if (hasChanges) {
			fireChanges();
		}
	}
}
 
Example #14
Source File: ConfigEditor.java    From thym with Eclipse Public License 1.0 6 votes vote down vote up
public boolean visit(IResourceDelta delta) {
	if (delta == null
			|| !delta.getResource().equals(
					((FileEditorInput) getEditorInput()).getFile())){
		return true;
	}

	if (delta.getKind() == IResourceDelta.REMOVED) {
		if ((IResourceDelta.MOVED_TO & delta.getFlags()) == 0) {
			if (!isDirty())
				closeEditor();
		} else { 
			final IFile newFile = ResourcesPlugin.getWorkspace()
					.getRoot().getFile(delta.getMovedToPath());
			Display display = getSite().getShell().getDisplay();
			display.asyncExec(new Runnable() {
				public void run() {
					editorPart.setInput(new FileEditorInput(newFile));
				}
			});
		}
	}
	return false;
}
 
Example #15
Source File: RadlValidatingVisitorTest.java    From RADL with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void doesntValidateNonFile() throws CoreException {
  IResourceDelta delta = someResourceDelta();
  when(delta.getResource()).thenReturn(mock(IResource.class));

  visitor.visit(delta);

  verify(validator, never()).validate(any(InputStream.class), any(Collection.class));
}
 
Example #16
Source File: BundleMonitor.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
public boolean visit(IResourceDelta delta) throws CoreException
{
	// process project bundle files, but ignore user bundles since file watcher will take care of those
	if (isProjectBundleFile(delta))
	{
		this.processFile(delta);
	}
	else
	{
		if (delta.getKind() == IResourceDelta.CHANGED && (delta.getFlags() & IResourceDelta.CONTENT) != 0)
		{
			IResource resource = delta.getResource();

			if (resource != null)
			{
				IPath location = resource.getLocation();

				if (location != null)
				{
					File file = location.toFile();

					if (file != null)
					{
						this.reloadDependentScripts(file);
					}
				}
			}
		}
	}

	return true;
}
 
Example #17
Source File: DotGraphView.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void resourceChanged(final IResourceChangeEvent event) {
	if (event.getType() != IResourceChangeEvent.POST_BUILD && event
			.getType() != IResourceChangeEvent.POST_CHANGE) {
		return;
	}
	IResourceDelta rootDelta = event.getDelta();
	try {
		rootDelta.accept(resourceVisitor);
	} catch (CoreException e) {
		DotActivatorEx.logError(e);
	}
}
 
Example #18
Source File: XdsSourceBuilder.java    From xds-ide with Eclipse Public License 1.0 5 votes vote down vote up
private boolean isDeltaResourceTargetForXdsProject(
           final XdsProjectSettings xdsProjectSettings, IResourceDelta delta2Check) {
    if (!delta2Check.getResource().exists() || delta2Check.getResource()
               .getLocation() == null) return false;
    String changedResourcePath = delta2Check.getResource()
               .getLocation().toOSString();
       String changedResourceName = delta2Check
               .getProjectRelativePath().lastSegment();

       return isFileTargetForXdsProject(xdsProjectSettings, changedResourcePath, changedResourceName);
}
 
Example #19
Source File: DerivedFoldersChangeListener.java    From thym with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void resourceChanged(IResourceChangeEvent event) {
	for (IResourceDelta delta : event.getDelta().getAffectedChildren()) {
		//check if resource is hybrid project
		if(delta.getResource().getType() == IResource.PROJECT){
			HybridProject hybridProject = HybridProject.getHybridProject((IProject)delta.getResource());
			if(hybridProject != null){
				DerivedFoldersJob job = new DerivedFoldersJob(hybridProject);
				job.schedule();
			}
		}
	}
	
}
 
Example #20
Source File: ResourcesWatcher.java    From typescript.java with MIT License 5 votes vote down vote up
@Override
public void resourceChanged(IResourceChangeEvent event) {
	try {
		IResource resource = event.getResource();
		switch (event.getType()) {
		case IResourceChangeEvent.PRE_DELETE:
			if (resource != null) {
				switch (resource.getType()) {
				case IResource.PROJECT:
					// called when project is deleted.
					deleteProject((IProject) resource);
					break;
				}
			}
			break;
		case IResourceChangeEvent.PRE_CLOSE:
			if (resource != null) {
				switch (resource.getType()) {
				case IResource.PROJECT:
					// called when project is closed.
					closeProject((IProject) resource);
					break;
				}
			}
			break;
		case IResourceChangeEvent.POST_CHANGE:
			IResourceDelta delta = event.getDelta();
			if (delta != null) {
				delta.accept(this);
			}
			break;
		}
	} catch (Throwable e) {
		Trace.trace(Trace.SEVERE, "Error while TypeScript resource changed", e);
	}
}
 
Example #21
Source File: WorkspaceDiagnosticsHandler.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void resourceChanged(IResourceChangeEvent event) {
	try {
		IResourceDelta delta = event.getDelta();
		delta.accept(this);
	} catch (CoreException e) {
		JavaLanguageServerPlugin.logException("failed to send diagnostics", e);
	}

}
 
Example #22
Source File: XdsModelManager.java    From xds-ide with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected boolean handleResourceChanged(IResourceDelta rootDelta, IResourceDelta delta, IResource affectedResource) {
	XdsModel model =  doGetModel();
	boolean isContentChanged = isContentChanged(delta);
       model.handleChangeResource(rootDelta, affectedResource, isContentChanged);
	return super.handleResourceChanged(rootDelta, delta, affectedResource);
}
 
Example #23
Source File: XdsResourceChangeListener.java    From xds-ide with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * TODO : use this method to improve performance of the resource change listening.
 * @param delta
 * @return
 */
@SuppressWarnings("unused")
private boolean hasModula2Projects(IResourceDelta delta) {
	IResourceDelta[] affectedProjects = delta.getAffectedChildren();
	return Arrays.stream(affectedProjects)
			.map(rd -> rd.getResource().getProject())
			.filter(p -> NatureUtils.hasModula2Nature(p))
			.findAny().isPresent();
}
 
Example #24
Source File: TsvBuilder.java    From hybris-commerce-eclipse-plugin with Apache License 2.0 5 votes vote down vote up
@Override
public boolean visit(final IResourceDelta delta) throws CoreException {
	switch (delta.getKind()) {
	case IResourceDelta.ADDED:
	case IResourceDelta.CHANGED:
		return visit(delta.getResource());
	}
	return true;
}
 
Example #25
Source File: StartupJob.java    From CodeCheckerEclipsePlugin with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Runs this job on UI thread.
 * @param monitor ProgressBar
 * @return Return Status.
 */
public IStatus runInUIThread(IProgressMonitor monitor) {
    CcGlobalConfiguration.getInstance();
    
    try { // TODO: find a better solution...
        Thread.sleep(WAIT_TIME);
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        Logger.log(IStatus.ERROR, e.getMessage());
        Logger.log(IStatus.INFO, Logger.getStackTrace(e));
    }

    Logger.log(IStatus.INFO, "adding addResourceChangeListener ");
    ResourcesPlugin.getWorkspace().addResourceChangeListener(new ResourceChangeListener(),
            IResourceChangeEvent.POST_BUILD |
            IResourceDelta.OPEN | IResourceChangeEvent.PRE_DELETE);
    
    ICommandService commandService = (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);
    commandService.addExecutionListener(new ISaveCommandExecutionListener());

    // check all open projects
    for (IProject project : ResourcesPlugin.getWorkspace().getRoot().getProjects()) {
        projectOpened(project);
    }
    Logger.log(IStatus.INFO, "CodeChecker reports had been parsed.");

    // check all open windows
    IWorkbench wb = PlatformUI.getWorkbench();
    for (IWorkbenchWindow win : wb.getWorkbenchWindows()) {
        addListenerToWorkbenchWindow(win);
    }
    return Status.OK_STATUS;
}
 
Example #26
Source File: DefaultResourceChangeToIssueProcessor.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
protected void processMarkerDelta(final IResourceDelta delta) {
	final IMarkerDelta[] markerDeltas = getSortedMarkerDelta(delta);
	
	for (final IMarkerDelta markerDelta : markerDeltas) {
		final Object elementID = markerDelta
				.getAttribute(SCTMarkerType.SEMANTIC_ELEMENT_ID);
		if (elementID == null) {
			continue;
		}
		dispatchMarkerDelta(markerDelta, elementID.toString());
	}
}
 
Example #27
Source File: BusinessDataViewer.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
private boolean updateTopControl(IResourceDelta delta) {
    if (updated) {
        return false;
    }
    if (delta.getKind() != IResourceDelta.CHANGED
            && BusinessObjectModelFileStore.BOM_FILENAME.equals(delta.getResource().getName())) {
        Display.getDefault().syncExec(() -> updateTopControl());
        updated = true;
        return false;
    }
    return true;
}
 
Example #28
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 #29
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 #30
Source File: PyDevDeltaCounter.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Overridden so that we don't load the document on this visitor (there is no need for that).
 */
@Override
protected void onVisitDelta(IResourceDelta delta) {
    switch (delta.getKind()) {
        case IResourceDelta.ADDED:
            visitAddedResource(null, null, monitor);
            break;
        case IResourceDelta.CHANGED:
            visitChangedResource(null, null, monitor);
            break;
        case IResourceDelta.REMOVED:
            visitRemovedResource(null, null, monitor);
            break;
    }
}