Resource Change Plugin for eclipse

江枫思渺然 提交于 2019-12-13 03:17:36

问题


I created an RCP application which detects resource change in its own view by extending CommonNavigator.

public abstract class NavigatorView extends CommonNavigator  implements
    IResourceChangeListener {
public void createPartControl(Composite parent) {
 super.createPartControl(parent);
 hookResourceChangeCommand(); // my resource tracking function.
 }
}

But now I need to create a plugin for this which detects resource change in project explorer in eclipse itself. I cannot create a view now and I need to detect already existing view. How should I do it ?


回答1:


Please completely remove the view that you created. You should not do anything in the UI, if you want to track resource changes, as resources are part of the workspace concept, and the workspace is generally headless (that is without UI).

Instead use the code below (taken from the resource change listener tutorial):

IWorkspace workspace = ResourcesPlugin.getWorkspace();
   IResourceChangeListener listener = new IResourceChangeListener() {
      public void resourceChanged(IResourceChangeEvent event) {
         System.out.println("Something changed!");
      }
   };
   workspace.addResourceChangeListener(listener);

   //... some time later one ...
   workspace.removeResourceChangeListener(listener);


来源:https://stackoverflow.com/questions/14165214/resource-change-plugin-for-eclipse

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!