Java Code Examples for org.eclipse.core.resources.IResourceChangeEvent

The following examples show how to use org.eclipse.core.resources.IResourceChangeEvent. These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
@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 2
Source Project: APICloud-Studio   Source File: SendPingJob.java    License: GNU General Public License v3.0 6 votes vote down vote up
public void resourceChanged(IResourceChangeEvent event)
{
	if (event.getType() == IResourceChangeEvent.PRE_DELETE)
	{
		// check if it is a studio project and then send the ping out
		try
		{
			IProject project = event.getResource().getProject();
			IProjectDescription description = project.getDescription();
			String[] natures = description.getNatureIds();
			if (!ArrayUtil.isEmpty(natures))
			{
				// just checking the primary nature
				String projectType = STUDIO_NATURE_MAP.get(natures[0]);
				if (!StringUtil.isEmpty(projectType))
				{
					sendProjectDeleteEvent(project, projectType);
				}
			}
		}
		catch (Exception e)
		{
			UsagePlugin.logError(e);
		}
	}
}
 
Example 3
Source Project: gemfirexd-oss   Source File: DerbyServerUtils.java    License: Apache License 2.0 6 votes vote down vote up
public void resourceChanged(IResourceChangeEvent event){
   if(event.getType()==IResourceChangeEvent.PRE_CLOSE){
   	try{
   		if(event.getResource().getProject().isNatureEnabled(CommonNames.DERBY_NATURE)){
   			if(getRunning(event.getResource().getProject())){
   				stopDerbyServer(event.getResource().getProject());
   			}
   		}
   	}catch(SWTException swe){
   		//The SWTException is thrown during the Shell creation
   		//Logger.log("Exception shutting down "+swe,IStatus.ERROR);
   		//e.printStackTrace();
   	}catch(Exception e){
   		Logger.log("Exception shutting down "+e,IStatus.ERROR);
   	}
   }
}
 
Example 4
Source Project: typescript.java   Source File: ProblemManager.java    License: 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
public void resourceChanged(IResourceChangeEvent event)
{
	if (event.getType() == IResourceChangeEvent.PRE_DELETE)
	{
		handleProjectDeleteEvent((IProject) event.getResource());
	}
	else
	{
		try
		{
			event.getDelta().accept(this);
		}
		catch (CoreException e)
		{
			IdeLog.logError(ScriptingActivator.getDefault(),
					Messages.BundleMonitor_Error_Processing_Resource_Change, e);
		}
	}
}
 
Example 6
Source Project: gama   Source File: ImageViewer.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
public void resourceChanged(final IResourceChangeEvent event) {
	final IResourceDelta delta = event.getDelta().findMember(imageFile.getFullPath());
	if (delta != null) {
		// file deleted -- close the editor
		if (delta.getKind() == IResourceDelta.REMOVED) {
			final Runnable r = () -> getSite().getPage().closeEditor(ImageViewer.this, false);
			getSite().getShell().getDisplay().asyncExec(r);
		}
		// file changed -- reload image
		else if (delta.getKind() == IResourceDelta.CHANGED) {
			final int flags = delta.getFlags();
			if ((flags & IResourceDelta.CONTENT) != 0 || (flags & IResourceDelta.LOCAL_CHANGED) != 0) {
				startImageLoad();
			}
		}
	}
}
 
Example 7
Source Project: gama   Source File: CloseResourceAction.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * Handles a resource changed event by updating the enablement if one of the selected projects is opened or closed.
 */
@Override
public synchronized void resourceChanged(final IResourceChangeEvent event) {
	// Warning: code duplicated in OpenResourceAction
	final List<? extends IResource> sel = getSelectedResources();
	// don't bother looking at delta if selection not applicable
	if (selectionIsOfType(IResource.PROJECT)) {
		final IResourceDelta delta = event.getDelta();
		if (delta != null) {
			final IResourceDelta[] projDeltas = delta.getAffectedChildren(IResourceDelta.CHANGED);
			for (final IResourceDelta projDelta : projDeltas) {
				if ((projDelta.getFlags() & IResourceDelta.OPEN) != 0) {
					if (sel.contains(projDelta.getResource())) {
						selectionChanged(getStructuredSelection());
						return;
					}
				}
			}
		}
	}
}
 
Example 8
Source Project: thym   Source File: RestoreProjectListener.java    License: 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 9
Source Project: thym   Source File: PluginContentProvider.java    License: 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 10
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 11
Source Project: gemfirexd-oss   Source File: DerbyServerUtils.java    License: Apache License 2.0 6 votes vote down vote up
public void resourceChanged(IResourceChangeEvent event){
   if(event.getType()==IResourceChangeEvent.PRE_CLOSE){
   	try{
   		if(event.getResource().getProject().isNatureEnabled(CommonNames.DERBY_NATURE)){
   			if(getRunning(event.getResource().getProject())){
   				stopDerbyServer(event.getResource().getProject());
   			}
   		}
   	}catch(SWTException swe){
   		//The SWTException is thrown during the Shell creation
   		//Logger.log("Exception shutting down "+swe,IStatus.ERROR);
   		//e.printStackTrace();
   	}catch(Exception e){
   		Logger.log("Exception shutting down "+e,IStatus.ERROR);
   	}
   }
}
 
Example 12
@Override
public void resourceChanged(final IResourceChangeEvent event) {
	if (workspace != null && workspace.isAutoBuilding()) {
		if (event.getType() == IResourceChangeEvent.POST_CHANGE) {
			try {
				final Set<IProject> toUpdate = findNewProjectsToBuild(event);
				scheduleBuildIfNecessary(toUpdate);
			} catch (CoreException e) {
				log.error(e.getMessage(), e);
			}
		} else if ((event.getType() == IResourceChangeEvent.PRE_CLOSE || event.getType() == IResourceChangeEvent.PRE_DELETE)) {
			if (event.getResource() instanceof IProject && (XtextProjectHelper.hasNature((IProject) event.getResource())
					|| event.getResource().isAccessible() && event.getResource().isHidden())) {
				scheduleRemoveProjectJob((IProject) event.getResource());
			}
		}
	}
}
 
Example 13
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 14
/**
 * Closes all project files on project close.
 */
public void resourceChanged(final IResourceChangeEvent event) {
	if (event.getType() == IResourceChangeEvent.PRE_CLOSE) {
		Display.getDefault().asyncExec(new Runnable() {
			public void run() {
				IWorkbenchPage[] pages = getSite().getWorkbenchWindow().getPages();
				for (int i = 0; i < pages.length; i++) {
					if (((FileEditorInput) editor.getEditorInput()).getFile().getProject()
					                .equals(event.getResource())) {
						IEditorPart editorPart = pages[i].findEditor(editor.getEditorInput());
						pages[i].closeEditor(editorPart, true);
					}
				}
			}
		});
	}
}
 
Example 15
public void addWorkplaceListener(){
	   IWorkspace workspace = ResourcesPlugin.getWorkspace(); 
	   workspace.addResourceChangeListener(new IResourceChangeListener() {
		
		public void resourceChanged(IResourceChangeEvent event) {
			//刷新项目导航视图
			Display.getDefault().syncExec(new Runnable() {		
				public void run() {
					IViewPart findView = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
							.findView("net.heartsome.cat.common.ui.navigator.view");
					if(null == findView){
						return ;
					}
					IAction refreshActionHandler = findView.getViewSite().getActionBars()
							.getGlobalActionHandler(ActionFactory.REFRESH.getId());
					if(null == refreshActionHandler){
						return;
					}
					refreshActionHandler.run();
				}
			});
		}
	});
}
 
Example 16
/**
 * 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 17
Source Project: gef   Source File: DotGraphView.java    License: Eclipse Public License 2.0 6 votes vote down vote up
private void toggleResourceListener() {
	IWorkspace workspace = ResourcesPlugin.getWorkspace();
	ISelectionService service = getSite().getWorkbenchWindow()
			.getSelectionService();
	if (listenToDotContent) {
		IWorkbenchPart activeEditor = PlatformUI.getWorkbench()
				.getActiveWorkbenchWindow().getActivePage()
				.getActiveEditor();
		checkActiveEditorAndUpdateGraph(activeEditor);
		workspace.addResourceChangeListener(resourceChangeListener,
				IResourceChangeEvent.POST_BUILD
						| IResourceChangeEvent.POST_CHANGE);
		service.addSelectionListener(selectionChangeListener);
	} else {
		workspace.removeResourceChangeListener(resourceChangeListener);
		service.removeSelectionListener(selectionChangeListener);
	}
}
 
Example 18
Source Project: thym   Source File: PlatformContentProvider.java    License: 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 19
Source Project: saros   Source File: SharedResourcesManager.java    License: GNU General Public License v2.0 6 votes vote down vote up
/** This method is called from Eclipse when changes to resource are detected */
@Override
public void resourceChanged(IResourceChangeEvent event) {

  /*
   * FIXME this is REAL GARBAGE ! This is sometimes set by the
   * IncomingProjectNegotiation. So when it is set every change in an
   * already shared project is just SILENTLY IGNORED !!!
   */
  if (fileReplacementInProgressObservable.isReplacementInProgress()) return;

  if (pause) {
    logPauseWarning(event);
    return;
  }

  // Creations, deletions, modifications of files and folders.
  if (event.getType() == IResourceChangeEvent.POST_CHANGE) {
    handlePostChange(event);
  } else {
    log.warn("cannot handle event type : " + event);
  }
}
 
Example 20
@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 21
@Override
public ResourceDeltaToIssueResult process(IResourceChangeEvent event, Resource connectedResource,
		Multimap<String, SCTIssue> visibleIssues) {
	final IFile file = WorkspaceSynchronizer.getFile(connectedResource);
	if (file == null) {
	    return null;
	}
	final IResourceDelta deltaForFile = getDeltaForFile(event, file);
	if (deltaForFile == null) {
		return null;
	}
	currentIssues = HashMultimap.create(visibleIssues);
	changedIssuesElementIDs = Sets.newHashSet();
	
	if ((IResourceDelta.CHANGED == deltaForFile.getKind()) && ((deltaForFile.getFlags() & IResourceDelta.MARKERS) != 0)) {
		processMarkerDelta(deltaForFile);
	}
	return new ResourceDeltaToIssueResult(currentIssues,changedIssuesElementIDs);
}
 
Example 22
Source Project: dartboard   Source File: PubspecChangeListener.java    License: 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 23
/**
 * {@inheritDoc}
 *
 * @see org.eclipse.ui.IWorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
 */
@Override
public void createPartControl(Composite parent) {

  mMainComposite = parent;

  // create and register the workspace focus listener
  mFocusListener = new ISelectionListener() {
    @Override
    public void selectionChanged(IWorkbenchPart part, ISelection selection) {
      AbstractStatsView.this.focusSelectionChanged(part, selection);
    }
  };

  getSite().getPage().addSelectionListener(mFocusListener);
  focusSelectionChanged(getSite().getPage().getActivePart(), getSite().getPage().getSelection());

  // create and register the listener for resource changes
  mResourceListener = new IResourceChangeListener() {
    @Override
    public void resourceChanged(IResourceChangeEvent event) {

      IMarkerDelta[] markerDeltas = event.findMarkerDeltas(CheckstyleMarker.MARKER_ID, true);

      if (markerDeltas.length > 0) {
        refresh();
      }
    }
  };

  ResourcesPlugin.getWorkspace().addResourceChangeListener(mResourceListener);

  makeActions();
  initActionBars(getViewSite().getActionBars());
}
 
Example 24
@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 25
protected IResourceDelta getDeltaForFile(final IResourceChangeEvent event, final IFile file) {
	final String[] segments = file.getFullPath().segments();
	IResourceDelta currentDelta = event.getDelta();
	for (final String segment : segments) {
		final IResourceDelta matchingDelta = currentDelta.findMember(new Path(segment));
		if (matchingDelta != null) {
			currentDelta = matchingDelta;
			continue;
		}
		return null;
	}
	return currentDelta;
}
 
Example 26
Source Project: n4js   Source File: N4JSAllContainersState.java    License: 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 27
Source Project: n4js   Source File: ProjectStateChangeListener.java    License: Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void resourceChanged(final IResourceChangeEvent event) {
	IWorkspace workspace = getWorkspace();
	if (workspace != null) {
		if (event.getType() == IResourceChangeEvent.POST_CHANGE) {
			try {
				final Set<IProject> affectedProjects = Sets.newLinkedHashSet();
				event.getDelta().accept(projectCollector(affectedProjects));
				if (!affectedProjects.isEmpty()) {
					ToBeBuilt toBeBuilt = new ToBeBuilt();
					Set<URI> toBeUpdated = toBeBuilt.getToBeUpdated();
					Set<String> projectNames = new LinkedHashSet<>();
					for (IProject project : affectedProjects) {
						IFile file = project.getFile(N4JSGlobals.PACKAGE_JSON);
						if (file.exists()) {
							projectNames.add(project.getName());
							toBeUpdated.add(URI.createPlatformResourceURI(file.getFullPath().toString(), true));
						}

					}
					packageJsonQueue.enqueue(projectNames, toBeBuilt, false);
					syncIndexJob.schedule();
				}
			} catch (CoreException e) {
				LOGGER.error(e.getMessage(), e);
			}
		}
	}
	super.resourceChanged(event);
}
 
Example 28
/** Initializes a new {@link WorkspaceRepositoriesProvider}. */
public WorkspaceRepositoriesProvider() {
	workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
	changeListeners = new HashSet<>();

	ResourcesPlugin.getWorkspace().addResourceChangeListener(this::resourceChanged,
			IResourceChangeEvent.POST_CHANGE);

	GitProjectData.addRepositoryChangeListener(this::repositoryChanged);
}
 
Example 29
Source Project: tlaplus   Source File: ProblemViewResourceListener.java    License: MIT License 5 votes vote down vote up
public void postWorkbenchWindowOpen() {
	// Check if there have been any markers set already
	showOrHideProblemView();
	
	// ...and listen for new markers
	final IWorkspace workspace = ResourcesPlugin.getWorkspace();
	workspace.addResourceChangeListener(this, IResourceChangeEvent.POST_BUILD);
}
 
Example 30
@Override
public void resourceChanged(IResourceChangeEvent event) {
    if(isDisposed()) {
        return;
    }
    updated = false;
    try {
        if (event.getDelta() != null) {
            event.getDelta().accept(this::updateTopControl);
        }
    } catch (final CoreException e) {
        throw new RuntimeException(e);
    }
}