Java Code Examples for org.eclipse.core.resources.IResourceChangeEvent#getDelta()

The following examples show how to use org.eclipse.core.resources.IResourceChangeEvent#getDelta() . 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: 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 2
Source File: AbstractEditor.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void resourceChanged(IResourceChangeEvent e) {
    IResourceDelta delta = e.getDelta();
    final FileEditorInput fInput = (FileEditorInput) getEditorInput();
    final IFile file = fInput.getFile();
    if (delta != null) {
        delta = delta.findMember(file.getFullPath());
    }
    if (delta != null) {
        final int flags = delta.getFlags();
        if (delta.getKind() == IResourceDelta.REMOVED && (IResourceDelta.MOVED_TO & flags) != 0) {
            updateEditorInput(
                    new FileEditorInput(file.getWorkspace().getRoot().getFile(delta.getMovedToPath())));
        } else if (delta.getKind() == IResourceDelta.CHANGED) {
            if ((flags & IResourceDelta.CONTENT) != 0 || (flags & IResourceDelta.REPLACED) != 0) {
                if (!resourceChangeEventSkip) {
                    FileEditorInput newEditorInput = new FileEditorInput(delta.getResource().getAdapter(IFile.class));
                    Display.getDefault().asyncExec(() -> updateEditorInput(newEditorInput));
                }
            }
        }
    }
}
 
Example 3
Source File: SCTHotModelReplacementManager.java    From statecharts with Eclipse Public License 1.0 6 votes vote down vote up
public synchronized void resourceChanged(IResourceChangeEvent event) {
	if (event.getType() == IResourceChangeEvent.PRE_CLOSE)
		handleCloseEvent(event);

	IResourceDelta delta = event.getDelta();
	try {
		changedFiles.clear();
		if (delta != null)
			delta.accept(this);
		if (changedFiles.size() > 0) {
			handleHotModelReplacement();
		}

	} catch (CoreException e) {
		e.printStackTrace();
	}
}
 
Example 4
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 5
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 6
Source File: PlatformContentProvider.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_PLATFORMS)) != null) {
			viewer.getControl().getDisplay().asyncExec(new Runnable() {
				@Override
				public void run() {
					viewer.refresh();
				}
			});
			return;
		}
	}
}
 
Example 7
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 8
Source File: CodewindResourceChangeListener.java    From codewind-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void resourceChanged(IResourceChangeEvent event) {
	IResourceDelta delta = event.getDelta();

	CodewindResourceDeltaVisitor visitor = new CodewindResourceDeltaVisitor();

	try {

		// If the delta is null (as happens with some events), just pass the empty array
		// list below.
		if (delta != null) {
			delta.accept(visitor);
		}

		parent.handleResourceChanges(visitor.getResult());

	} catch (CoreException e1) {
		// TODO: Log me.
		e1.printStackTrace();
	}

}
 
Example 9
Source File: WebPageNameResourceChangeListener.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void resourceChanged(final IResourceChangeEvent event) {
    if (mainProcess != null && event.getDelta() != null) {
        try {
            event.getDelta().accept(resourceDeltaVisitor());
        } catch (final CoreException e) {
            BonitaStudioLog.error("Failed to update form reference name", e);
        }
    }
}
 
Example 10
Source File: ConfigEditor.java    From thym with Eclipse Public License 1.0 5 votes vote down vote up
public void resourceChanged(IResourceChangeEvent event) {
	IResourceDelta delta = event.getDelta();
	try {
		if (delta != null){
			delta.accept(this);
		}
	} catch (CoreException exception) {
		HybridCore.log(IStatus.ERROR, "Error when retrieving IResourceDelta", exception);
	}
}
 
Example 11
Source File: ExternalBreakpointWatcher.java    From goclipse with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void resourceChanged(IResourceChangeEvent event) {
	IResourceDelta delta = event.getDelta();
	if(delta == null) {
		return;
	}
	
	IResource res = delta.getResource();
	if(res instanceof IWorkspaceRoot && (delta.getFlags() & IResourceDelta.MARKERS) != 0) {
		
		IMarkerDelta[] markerDeltas = delta.getMarkerDeltas();
		for (IMarkerDelta markerDelta : markerDeltas) {
			int kind = markerDelta.getKind();
			
			if(markerDelta.isSubtypeOf(CBREAKPOINT_MARKER_TYPE)) {
				
				if (kind == IResourceDelta.ADDED) {
					addMarkerAnnotation(markerDelta.getMarker());
				}
				
				if (kind == IResourceDelta.REMOVED) {
					removeMarkerAnnotation(markerDelta.getMarker());
				}
				
				if (kind == IResourceDelta.CHANGED) {
					updateMarkerAnnotation(markerDelta.getMarker());
				}
				
			}
		}
	}
}
 
Example 12
Source File: DerivedSourceView.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void resourceChanged(IResourceChangeEvent event) {
	if (selectedSource == null || getWorkbenchPartSelection() == null) {
		return;
	}
	IResourceDelta delta = event.getDelta();
	if (delta != null) {
		IResourceDelta child = delta.findMember(selectedSource.getFullPath());
		if (child != null) {
			refreshJob.reschedule();
		}
	}
}
 
Example 13
Source File: ProblemMarkerManager.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
@Override
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) {
        Log.log(e);
    }

    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: EclipseJDTClassProvider.java    From M2Doc with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void resourceChanged(IResourceChangeEvent event) {
    if (event != null) {
        final IResourceDelta delta = event.getDelta();
        for (IResourceDelta child : delta.getAffectedChildren()) {
            final IResource resource = child.getResource();
            if (resource != null) {
                final IProject project = resource.getProject();
                if (project != null) {
                    classLoaders.remove(project.getName());
                }
            }
        }
    }
}
 
Example 15
Source File: IDEMultiPageReportEditor.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * does when resource changed
 */
public void resourceChanged( IResourceChangeEvent event )
{
	IResourceDelta delta = event.getDelta( );
	try
	{
		if ( delta != null )
			delta.accept( this );
	}
	catch ( CoreException exception )
	{
		// What should be done here?
	}
}
 
Example 16
Source File: OpenProjectAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public void resourceChanged(IResourceChangeEvent event) {
	IResourceDelta delta = event.getDelta();
	if (delta != null) {
		IResourceDelta[] projDeltas = delta.getAffectedChildren(IResourceDelta.CHANGED);
		for (int i = 0; i < projDeltas.length; ++i) {
			IResourceDelta projDelta = projDeltas[i];
			if ((projDelta.getFlags() & IResourceDelta.OPEN) != 0) {
				setEnabled(hasClosedProjectsInWorkspace());
				return;
			}
		}
	}
}
 
Example 17
Source File: ProblemMarkerManager.java    From goclipse with Eclipse Public License 1.0 5 votes vote down vote up
@Override
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) {
		EclipseCore.logStatus(e);
	}

	if (!changedElements.isEmpty()) {
		boolean hasChanges= false;
		synchronized (this) {
			if (fResourcesWithMarkerChanges.isEmpty()) {
				fResourcesWithMarkerChanges= changedElements;
				hasChanges= true;
			} else {
				hasChanges= fResourcesWithMarkerChanges.addAll(changedElements);
			}
		}
		if (hasChanges) {
			fireChanges();
		}
	}
}
 
Example 18
Source File: FilterUpdater.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public void resourceChanged(IResourceChangeEvent event) {
	if (fViewer.getInput() == null) {
		return;
	}
	IResourceDelta delta= event.getDelta();
	if (delta == null)
		return;
	IResourceDelta[] projDeltas = delta.getAffectedChildren(IResourceDelta.CHANGED);
	for (int i= 0; i < projDeltas.length; i++) {
		IResourceDelta pDelta= projDeltas[i];
		if ((pDelta.getFlags() & IResourceDelta.DESCRIPTION) != 0) {
			IProject project= (IProject) pDelta.getResource();
			if (needsRefiltering(project)) {
				final Control ctrl= fViewer.getControl();
				if (ctrl != null && !ctrl.isDisposed()) {
					// async is needed due to bug 33783
					ctrl.getDisplay().asyncExec(new Runnable() {
						public void run() {
							if (!ctrl.isDisposed())
								fViewer.refresh(false);
						}
					});
				}
				return; // one refresh is good enough
			}
		}
	}
}
 
Example 19
Source File: ClientBundleResourceChangeListener.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
public void resourceChanged(IResourceChangeEvent event) {
  try {
    IResourceDelta delta = event.getDelta();
    if (delta != null) {
      visitResourceDelta(delta);
    }
  } catch (CoreException e) {
    GWTPluginLog.logError(e);
  }
}
 
Example 20
Source File: DeleteResourceShortcutListener.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
/**
 * @see org.eclipse.core.resources.IResourceChangeListener#resourceChanged(org.eclipse.core.resources.IResourceChangeEvent)
 */
public void resourceChanged(IResourceChangeEvent event) {
    IResourceDelta delta = event.getDelta();

    switch (delta.getKind()) {
    case IResourceDelta.REMOVED:
        break;
    case IResourceDelta.CHANGED:
        List<IConnectionPoint> deleted = new ArrayList<IConnectionPoint>();
        IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();

        IConnectionPointManager manager = CoreIOPlugin.getConnectionPointManager();
        IConnectionPoint[] projectShortcuts = manager.getConnectionPointCategory(CATEGORY_ID)
                .getConnectionPoints();
        WorkspaceConnectionPoint connectionPoint;
        for (IConnectionPoint shortcut : projectShortcuts) {
            connectionPoint = (WorkspaceConnectionPoint) shortcut;

            // see if the relative path matches the changed item
            IResourceDelta d = delta.findMember(connectionPoint.getPath());
            if (d != null && d.getKind() == IResourceDelta.REMOVED) {
                if (d.getMovedToPath() == null) {
                	IResource resource = d.getResource();
                	if (!(resource instanceof IProject) && resource.getProject().exists() && !resource.getProject().isOpen())
                	{
                		continue;
                	}
                	// the original container was deleted
                	deleted.add(shortcut);
                } else {
                    // the original container was moved
                    IPath newPath = d.getMovedToPath();
                    IContainer newContainer;
                    if (d.getResource() instanceof IProject) {
                        newContainer = root.getProject(newPath.toString());
                    } else {
                        newContainer = root.getFolder(newPath);
                    }
                    connectionPoint.setResource(newContainer);
                    connectionPoint.setName(newContainer.getName());
                }
            }
        }

        // if the item was deleted, remove it
        for (IConnectionPoint projectShortcut : deleted) {
            manager.removeConnectionPoint(projectShortcut);
        }
        break;
    }
}