org.eclipse.core.resources.IResourceChangeListener Java Examples

The following examples show how to use org.eclipse.core.resources.IResourceChangeListener. 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: ModelRefreshTests.java    From google-cloud-eclipse with Apache License 2.0 6 votes vote down vote up
/** Record and return the set of files altered when running the provided block. */
private static Set<IFile> recordChangedFilesDuring(IWorkspace workspace, ICoreRunnable block)
    throws CoreException {
  Set<IFile> changed = new LinkedHashSet<>();
  IResourceChangeListener listener =
      event -> {
        try {
          changed.addAll(ResourceUtils.getAffectedFiles(event.getDelta()).values());
        } catch (CoreException ex) {
          throw new RuntimeException(ex);
        }
      };
  workspace.addResourceChangeListener(listener);
  try {
    block.run(new NullProgressMonitor());
  } finally {
    workspace.removeResourceChangeListener(listener);
  }
  return changed;
}
 
Example #2
Source File: ApplicationWorkbenchWindowAdvisor.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
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 #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: ResourceUtils.java    From goclipse with Eclipse Public License 1.0 6 votes vote down vote up
public static void connectResourceListener(IResourceChangeListener listener, 
		RunnableX<CoreException> initialUpdate, ISchedulingRule opRule, IOwner owner) {
	try {
		getWorkspace().run(new IWorkspaceRunnable() {
			@Override
			public void run(IProgressMonitor monitor) throws CoreException {
				getWorkspace().addResourceChangeListener(listener, IResourceChangeEvent.POST_CHANGE);
				initialUpdate.run();
			}
		}, opRule, IWorkspace.AVOID_UPDATE, null);
		
	} catch (CoreException ce) {
		EclipseCore.logStatus(ce);
		// This really should not happen, but still try to recover by registering the listener.
		getWorkspace().addResourceChangeListener(listener, IResourceChangeEvent.POST_CHANGE);
	}
	owner.bind(() -> ResourcesPlugin.getWorkspace().removeResourceChangeListener(listener));
}
 
Example #5
Source File: AbstractStatsView.java    From eclipse-cs with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * {@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 #6
Source File: ProblemManager.java    From typescript.java with MIT License 5 votes vote down vote up
private ProblemManager() {
	this.resourceChangeListener = new IResourceChangeListener() {
		@Override
		public void resourceChanged(IResourceChangeEvent event) {
			handleResourceChanged(event);
		}
	};

	this.listeners = new CopyOnWriteArrayList<>();
}
 
Example #7
Source File: ProjectExplorerRefreshTest.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
private static void refresh(Runnable runnable) {
    AtomicBoolean resourceChanged = new AtomicBoolean();
    IResourceChangeListener listener = event -> {
        resourceChanged.set(true);
    };
    try {
        ResourcesPlugin.getWorkspace().addResourceChangeListener(listener);
        SWTBotUtils.waitUntil(refresh -> {
            refresh.run();
            return resourceChanged.get();
        }, runnable, "Resource change event not received");
    } finally {
        ResourcesPlugin.getWorkspace().removeResourceChangeListener(listener);
    }
}
 
Example #8
Source File: MarkerManager.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
private MarkerManager()
{
	IWorkspace workspace = ResourcesPlugin.getWorkspace();
	workspace.addResourceChangeListener(new IResourceChangeListener()
	{
		public void resourceChanged(IResourceChangeEvent event)
		{
			handleResourceChanged();
		}
	}, IResourceChangeEvent.PRE_BUILD);
}
 
Example #9
Source File: RepositoryCache.java    From textuml with Eclipse Public License 1.0 5 votes vote down vote up
public void start() {
    ResourcesPlugin.getWorkspace().addResourceChangeListener(new IResourceChangeListener() {

        public void resourceChanged(IResourceChangeEvent event) {
            workspaceGeneration++;
        }
    });
}
 
Example #10
Source File: SarosSessionTest.java    From saros with GNU General Public License v2.0 5 votes vote down vote up
private static IWorkspace createWorkspaceMock(final List<Object> workspaceListeners) {

    final IWorkspace workspace = createMock(IWorkspace.class);

    workspace.addResourceChangeListener(isA(IResourceChangeListener.class), anyInt());

    expectLastCall()
        .andStubAnswer(
            new IAnswer<Object>() {

              @Override
              public Object answer() throws Throwable {
                workspaceListeners.add(getCurrentArguments()[0]);
                return null;
              }
            });

    workspace.removeResourceChangeListener(isA(IResourceChangeListener.class));

    expectLastCall()
        .andStubAnswer(
            new IAnswer<Object>() {

              @Override
              public Object answer() throws Throwable {
                workspaceListeners.remove(getCurrentArguments()[0]);
                return null;
              }
            });

    replay(workspace);

    PowerMock.mockStaticPartial(ResourcesPlugin.class, "getWorkspace");
    ResourcesPlugin.getWorkspace();
    expectLastCall().andReturn(workspace).anyTimes();
    PowerMock.replay(ResourcesPlugin.class);

    return workspace;
  }
 
Example #11
Source File: ResourceManager.java    From gama with GNU General Public License v3.0 4 votes vote down vote up
public ResourceManager(final IResourceChangeListener delegate, final CommonViewer navigator) {
	this.viewer = navigator;
	viewer.addSelectionChangedListener(this);
	this.delegate = delegate;
	INSTANCE = this;
}