Package com.dmarcotte.handlebars.structure

Source Code of com.dmarcotte.handlebars.structure.HbStructureViewFactory

package com.dmarcotte.handlebars.structure;

import com.dmarcotte.handlebars.HbLanguage;
import com.dmarcotte.handlebars.file.HbFileType;
import com.dmarcotte.handlebars.psi.HbPsiFile;
import com.intellij.ide.structureView.StructureView;
import com.intellij.ide.structureView.StructureViewBuilder;
import com.intellij.ide.structureView.StructureViewModel;
import com.intellij.ide.structureView.TreeBasedStructureViewBuilder;
import com.intellij.ide.structureView.impl.StructureViewComposite;
import com.intellij.ide.structureView.impl.TemplateLanguageStructureViewBuilder;
import com.intellij.lang.PsiStructureViewFactory;
import com.intellij.openapi.fileEditor.FileEditor;
import com.intellij.psi.PsiFile;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class HbStructureViewFactory implements PsiStructureViewFactory {
  @Nullable
  @Override
  public StructureViewBuilder getStructureViewBuilder(final PsiFile psiFile) {
    return new TemplateLanguageStructureViewBuilder(psiFile) {
      @Override
      protected StructureViewComposite.StructureViewDescriptor createMainView(FileEditor fileEditor, final PsiFile mainFile) {
        if (!psiFile.isValid()) return null;

        final StructureViewBuilder builder = new TreeBasedStructureViewBuilder() {
          @NotNull
          @Override
          public StructureViewModel createStructureViewModel() {
            return new HbStructureViewModel((HbPsiFile) mainFile);
          }
        };

        StructureView structureView = builder.createStructureView(fileEditor, psiFile.getProject());

        return new StructureViewComposite.StructureViewDescriptor(
          HbLanguage.INSTANCE.getDisplayName(), structureView, HbFileType.INSTANCE.getIcon());
      }
    };
  }
}
TOP

Related Classes of com.dmarcotte.handlebars.structure.HbStructureViewFactory

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.