English 中文(简体)
Eclipse Plugin, 我怎么能知道IResourceDeltaVisitor何时结束处理树苗?
原标题:Eclipse Plugin, How can I know when IResourceDeltaVisitor ends processing tree nodes?

I wrote an Eclipse Plugin that basically allow a programmer to select a Java source from the Project Explorer and by selecting the corresponding DropDown menu option it will creates an interface .java file based on the one selected. Everything works fine, but now I need to program the update part of the job. The update requierement is simple, I need to listen for changes and identify that the sources that have the interface generated have been modified and recreate the interface file. To do this I wrote a class that implements IResourceChangeListener interface. That class looks like:

public class DTOChangeListener implements IResourceChangeListener {
    private List<UpdatedUnit> updatedUnits;



    public DTOChangeListener() {
        super();
        this.updatedUnits=new ArrayList<UpdatedUnit>();
    }

    @Override
    public void resourceChanged(IResourceChangeEvent event) {
        try{
            if(event.getType() == IResourceChangeEvent.POST_CHANGE){
                  event.getDelta().accept(this.buildVisitor());
            }
        }catch(CoreException ex){
               ex.printStackTrace();
        }

    }

    protected IResourceDeltaVisitor buildVisitor(){
        IResourceDeltaVisitor result=new IResourceDeltaVisitor() {

        @Override
        public boolean visit(IResourceDelta resDelta) throws CoreException    {
               String resName=resDelta.getResource().getName();
               if(resName==null || resName.equals("")){
                     return true;
               }
               String[] splits=resName.split("\.");
               String name = splits[0];
               if(name.contains("PropertyAccess")){
                    return false;
               }
               String interfaceName=name + "PropertyAccess";
               String interfaceFile=interfaceName + ".java";
               IResource res=resDelta.getResource();
               if((res instanceof IFolder) || (res instanceof IProject)){
               // Avoid Folder & Project Nodes
                   return true;
               }
               IProject project=res.getProject();
               if(project!=null){
                  if(project.isNatureEnabled("org.eclipse.jdt.core.javanature")){
                     IJavaElement element=JavaCore.create(res);
                     if(element instanceof ICompilationUnit){
                        ICompilationUnit unit=(ICompilationUnit)element;
                        IPath path=res.getProjectRelativePath().removeLastSegments(1);
                        IResource propertyAccess=project.findMember(path.append(interfaceFile));
                        if(propertyAccess!=null){
                           UpdatedUnit updatedUnit=new UpdatedUnit(project, path, unit);
                           updatedUnits.add(updatedUnit);
                           return false;
                        }
                     }
                  }
               }
               return true;
        }
      };
      return result;
    }

    public List<UpdatedUnit> getUpdatedUnits() {
           return updatedUnits;
    }
}

我在工作空间加上名单,现在的问题是:

How can I know when the updatedUnits List is completed in order to proccess the list with my own code? One posible answer to this question would be, don t worry, the:

event.getData().accept(this.buildVisitor());

will block until proccessing of the visitor finish. but at least is not documented like it would.

Any ideas would be appreciated. Thanks in Advance.

Daniel

最佳回答

Unless it sdocument to not/2005/4, it/2005/4.

问题回答

暂无回答




相关问题
In Eclipse, why doesn t "Show In" appear for non-Java files?

If I have a *java file open, I can right click on the source, scroll down to "Show In (Alt-Shift-W)", and select Navigator. If I have an *xml, *jsp, or pretty much anything besides a Java source ...

Eclipse: Hover broken in debug perspective

Since upgrading Eclipse (Galileo build 20090920-1017), hover in debug no longer displays a variable s value. Instead, hover behaves as if I were in normal Java perspective: alt text http://...

Eclipse smart quotes - like in Textmate

Happy Friday — Does anyone know if eclipse has the notion of smart quotes like Textmate. The way it works is to select some words and quote them by simply hitting the " key? I m a newbie here so be ...

Indentation guide for the eclipse editor

Is there a setting or plugin for eclipse that can show indentation guides in the editor? Something like the Codekana plugin for visual studio (not so fancy is also OK). Important that it works with ...

Adding jar from Eclipse plugin runtime tab

I want to add .jar files for plugin from the Runtime tab of manifest file. When I use the Add... button, I can see only sub-directories of the plugin project. So if I want to add same .jar file to ...

How to copy multiple projects into single folder in eclipse

I have two projects, Project1 and Project2. Now i want to copy this projects into eclipse workspace but i want these projects to be in a single folder like below. Eclipse Workspace -> Project -> ...

Java: Finding out what is using all the memory

I have a java application that runs out of memory, but I have no idea which code is allocating the memory. Is there an application with which I can check this? I use Eclipse.

热门标签