Eclipse Listener检测文件更改?

时间:2014-12-11 10:37:49

标签: java eclipse eclipse-plugin listener

我正在Eclipse中搜索一个侦听器,它将检测文件是否由第三方软件(如MKS)在外部进行更改。

我使用IResourceChangeListener并且它有效。但问题是,它还会侦听文件的其他更改。例如,当我删除标记时,它还会在收听后监听并执行我想要的代码。

是否有侦听器,只有在第三方软件更改(新打开/刷新)文件时才会侦听?

更新

我的代码:

public class Startup implements IStartup {

       IWorkspace workspace = ResourcesPlugin.getWorkspace();
       IResourceChangeListener listener = new IResourceChangeListener() {

        public void resourceChanged(IResourceChangeEvent event) {


               if(event.getType() == IResourceChangeEvent.POST_CHANGE && IResourceDelta.MARKERS!=0){  //Filtering listener


                System.out.println("Listener code should be implemented here");  


              }


               System.out.println("listener is working");  //This line always get executed. That means the listener is working


           }
       };



    @Override
    public void earlyStartup() {
       workspace.addResourceChangeListener(listener,IResourceChangeEvent.POST_CHANGE);

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


}

0 个答案:

没有答案