/*
 * @author max
 */
package com.intellij.lang.ant;

import com.intellij.ide.structureView.StructureViewBuilder;
import com.intellij.ide.structureView.StructureViewModel;
import com.intellij.ide.structureView.TreeBasedStructureViewBuilder;
import com.intellij.lang.PsiStructureViewFactory;
import com.intellij.lang.ant.config.impl.configuration.AntStructureViewTreeModel;
import com.intellij.lang.ant.psi.AntFile;
import com.intellij.psi.PsiFile;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class AntStructureViewBuilderFactory implements PsiStructureViewFactory {
  @Nullable
  public StructureViewBuilder getStructureViewBuilder(PsiFile psiFile) {
    final AntFile antFile = AntSupport.getAntFile(psiFile);
    if (antFile != null ) {
      return new TreeBasedStructureViewBuilder() {
        @NotNull
        public StructureViewModel createStructureViewModel() {
          return new AntStructureViewTreeModel(antFile);
        }
      };
    }
    return null;
  }

}
@@ -85,36 +85,17 @@
 ureView.
-StructureViewBuilder
+*
 ;%0Aimport
@@ -130,93 +130,92 @@
 iew.
-StructureViewModel;%0Aimport com.intellij.ide.structureView.TreeBasedStructureViewBuild
+impl.common.PsiTreeElementBase;%0Aimport com.intellij.ide.util.treeView.smartTree.Sort
 er;%0A
@@ -297,59 +297,64 @@
 ant.
-config.impl.configuration.AntStructureViewTreeModel
+psi.AntFile;%0Aimport com.intellij.lang.ant.psi.AntProject
 ;%0Aim
@@ -379,36 +379,38 @@
 lang.ant.psi.Ant
-File
+Target
 ;%0Aimport com.int
@@ -518,88 +518,289 @@
 e;%0A%0A
-public class AntStructureViewBuilderFactory implements PsiStructureViewFactory %7B
+import java.util.ArrayList;%0Aimport java.util.Collection;%0Aimport java.util.Collections;%0Aimport java.util.List;%0A%0Apublic class AntStructureViewBuilderFactory implements PsiStructureViewFactory %7B%0A  public static final String UNNAMED = AntBundle.message(%22unnamed.string.presentation%22);%0A
 %0A  @
@@ -1125,69 +1125,1114 @@
 new 
-AntStructureViewTreeModel(antFile);%0A        %7D%0A      %7D
+StructureViewModelBase(antFile, new AntFileTreeElement(antFile))%0A            .withSuitableClasses(AntFile.class, AntTarget.class);%0A        %7D%0A      %7D;%0A    %7D%0A    return null;%0A  %7D%0A%0A  static class AntFileTreeElement extends PsiTreeElementBase%3CAntFile%3E %7B%0A%0A    public AntFileTreeElement(AntFile antFile) %7B%0A      super(antFile);%0A    %7D%0A%0A    private AntProject getAntProject() %7B%0A      return getValue().getAntProject();%0A    %7D%0A%0A    public String getPresentableText() %7B%0A      final String name = getAntProject().getName();%0A      return name != null ? name : UNNAMED;%0A    %7D%0A%0A    @NotNull%0A    public Collection%3CStructureViewTreeElement%3E getChildrenBase() %7B%0A      List%3CStructureViewTreeElement%3E list = new ArrayList%3CStructureViewTreeElement%3E();%0A      for (AntTarget target : getAntProject().getTargets()) %7B%0A        list.add(new AntTargetTreeElement(target));%0A      %7D%0A      Collections.sort(list, Sorter.ALPHA_SORTER.getComparator());%0A      return list;%0A    %7D%0A  %7D%0A%0A  static class AntTargetTreeElement extends PsiTreeElementBase%3CAntTarget%3E %7B%0A%0A    public AntTargetTreeElement(AntTarget target) %7B%0A      super(target)
 ;%0A    %7D%0A
     
@@ -2227,31 +2227,356 @@
 ;%0A    %7D%0A
+%0A
     
-return null;%0A  %7D%0A
+public String getPresentableText() %7B%0A      final AntTarget value = getValue();%0A      final String name = value != null? value.getName() : null;%0A      return name != null ? name : UNNAMED;%0A    %7D%0A%0A    @NotNull%0A    public Collection%3CStructureViewTreeElement%3E getChildrenBase() %7B%0A      return new ArrayList%3CStructureViewTreeElement%3E();%0A    %7D%0A  %7D
 %0A%7D

replace some easy-to-refactor implementations of TextEditorBasedStructureViewModel with StructureViewModelBase