com.intellij.ide.structureView.StructureViewModel Java Examples

The following examples show how to use com.intellij.ide.structureView.StructureViewModel. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HaxeStructureViewFactory.java    From intellij-haxe with Apache License 2.0 6 votes vote down vote up
@Override
public StructureViewBuilder getStructureViewBuilder(final PsiFile psiFile) {
  if (!(psiFile instanceof HaxeFile)) {
    return null;
  }
  return new TreeBasedStructureViewBuilder() {
    @NotNull
    @Override
    public StructureViewModel createStructureViewModel(@Nullable Editor editor) {
      return new HaxeStructureViewModel(psiFile, editor);
    }

    @Override
    public boolean isRootNodeShown() {
      return false;
    }
  };
}
 
Example #2
Source File: CSharpStructureViewFactory.java    From consulo-csharp with Apache License 2.0 6 votes vote down vote up
@Nullable
@Override
public StructureViewBuilder getStructureViewBuilder(final PsiFile psiFile)
{
	if(psiFile instanceof CSharpFileImpl)
	{
		return new TreeBasedStructureViewBuilder()
		{
			@Nonnull
			@Override
			public StructureViewModel createStructureViewModel(@Nullable Editor editor)
			{
				return new CSharpStructureViewModel(psiFile, editor);
			}
		};
	}
	else
	{
		return null;
	}
}
 
Example #3
Source File: StructureAwareNavBarModelExtension.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nullable
@Override
@RequiredReadAction
public PsiElement getParent(@Nonnull PsiElement psiElement) {
  if (psiElement.getLanguage() == getLanguage()) {
    PsiFile containingFile = psiElement.getContainingFile();
    if (containingFile == null) {
      return null;
    }

    StructureViewModel model = buildStructureViewModel(containingFile, null);
    if (model != null) {
      PsiElement parentInModel = findParentInModel(model.getRoot(), psiElement);
      if(acceptParentFromModel(parentInModel)) {
        return parentInModel;
      }
    }
  }
  return super.getParent(psiElement);
}
 
Example #4
Source File: ProtoStructureViewFactory.java    From protobuf-jetbrains-plugin with Apache License 2.0 6 votes vote down vote up
@Nullable
@Override
public StructureViewBuilder getStructureViewBuilder(final PsiFile psiFile) {
    return new TreeBasedStructureViewBuilder() {
        @NotNull
        @Override
        public StructureViewModel createStructureViewModel(@Nullable Editor editor) {
            return new ProtoStructureViewModel((ProtoPsiFileRoot) psiFile, editor);
        }

        @Override
        public boolean isRootNodeShown() {
            return false;
        }
    };
}
 
Example #5
Source File: StructureAwareNavBarModelExtension.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
@RequiredReadAction
public PsiElement getLeafElement(@Nonnull DataContext dataContext) {
  if (UISettings.getInstance().getShowMembersInNavigationBar()) {
    PsiFile psiFile = dataContext.getData(CommonDataKeys.PSI_FILE);
    Editor editor = dataContext.getData(CommonDataKeys.EDITOR);
    if (psiFile == null || editor == null) return null;
    PsiElement psiElement = psiFile.findElementAt(editor.getCaretModel().getOffset());
    if (psiElement != null && psiElement.getLanguage() == getLanguage()) {
      StructureViewModel model = buildStructureViewModel(psiFile, editor);
      if (model != null) {
        Object currentEditorElement = model.getCurrentEditorElement();
        if (currentEditorElement instanceof PsiElement) {
          return ((PsiElement)currentEditorElement).getOriginalElement();
        }
      }
    }
  }
  return null;
}
 
Example #6
Source File: ViewStructureAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nullable
public static FileStructurePopup createPopup(@Nonnull Project project, @Nonnull FileEditor fileEditor) {
  PsiDocumentManager.getInstance(project).commitAllDocuments();
  StructureViewBuilder builder = fileEditor.getStructureViewBuilder();
  if (builder == null) return null;
  StructureView structureView;
  StructureViewModel treeModel;
  if (builder instanceof TreeBasedStructureViewBuilder) {
    structureView = null;
    treeModel = ((TreeBasedStructureViewBuilder)builder).createStructureViewModel(EditorUtil.getEditorEx(fileEditor));
  }
  else {
    structureView = builder.createStructureView(fileEditor, project);
    treeModel = createStructureViewModel(project, fileEditor, structureView);
  }
  if (treeModel instanceof PlaceHolder) {
    //noinspection unchecked
    ((PlaceHolder)treeModel).setPlace(TreeStructureUtil.PLACE);
  }
  FileStructurePopup popup = new FileStructurePopup(project, fileEditor, treeModel);
  if (structureView != null) Disposer.register(popup, structureView);
  return popup;
}
 
Example #7
Source File: TemplateLanguageStructureViewBuilder.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nullable
protected TreeBasedStructureViewBuilder createMainBuilder(@Nonnull PsiFile psi) {
  //noinspection deprecation
  StructureViewComposite.StructureViewDescriptor descriptor = createMainView(null, psi);
  if (descriptor == null) return null;
  return new TreeBasedStructureViewBuilder() {
    @Nonnull
    @Override
    public StructureViewModel createStructureViewModel(@Nullable Editor editor) {
      Disposer.register(descriptor.structureModel, descriptor.structureView);
      return descriptor.structureModel;
    }

    @Nonnull
    @Override
    public StructureView createStructureView(FileEditor fileEditor, @Nonnull Project project) {
      return descriptor.structureView;
    }
  };
}
 
Example #8
Source File: TemplateLanguageStructureViewBuilder.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
public static TemplateLanguageStructureViewBuilder create(@Nonnull PsiFile psiFile, @Nullable PairFunction<? super PsiFile, ? super Editor, ? extends StructureViewModel> modelFactory) {
  return new TemplateLanguageStructureViewBuilder(psiFile) {
    @Override
    protected TreeBasedStructureViewBuilder createMainBuilder(@Nonnull PsiFile psi) {
      return modelFactory == null ? null : new TreeBasedStructureViewBuilder() {
        @Override
        public boolean isRootNodeShown() {
          return false;
        }

        @Nonnull
        @Override
        public StructureViewModel createStructureViewModel(@Nullable Editor editor) {
          return modelFactory.fun(psi, editor);
        }
      };
    }
  };
}
 
Example #9
Source File: Bookmark.java    From consulo with Apache License 2.0 5 votes vote down vote up
public String getQualifiedName() {
  String presentableUrl = myFile.getPresentableUrl();
  if (myFile.isDirectory()) return presentableUrl;

  PsiDocumentManager.getInstance(myProject).commitAllDocuments();
  final PsiFile psiFile = PsiManager.getInstance(myProject).findFile(myFile);

  if (psiFile == null) return presentableUrl;

  StructureViewBuilder builder = LanguageStructureViewBuilder.INSTANCE.getStructureViewBuilder(psiFile);
  if (builder instanceof TreeBasedStructureViewBuilder) {
    StructureViewModel model = ((TreeBasedStructureViewBuilder)builder).createStructureViewModel(null);
    Object element;
    try {
      element = model.getCurrentEditorElement();
    }
    finally {
      model.dispose();
    }
    if (element instanceof NavigationItem) {
      ItemPresentation presentation = ((NavigationItem)element).getPresentation();
      if (presentation != null) {
        presentableUrl = ((NavigationItem)element).getName() + " " + presentation.getLocationString();
      }
    }
  }

  return IdeBundle.message("bookmark.file.X.line.Y", presentableUrl, getLine() + 1);
}
 
Example #10
Source File: ANTLRv4StructureViewFactory.java    From intellij-plugin-v4 with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Nullable
 @Override
 public StructureViewBuilder getStructureViewBuilder(final PsiFile psiFile) {
     return new TreeBasedStructureViewBuilder() {
@NotNull
@Override
public StructureViewModel createStructureViewModel(@Nullable Editor editor) {
	VirtualFile grammarFile = psiFile.getVirtualFile();
	if ( grammarFile==null || !grammarFile.getName().endsWith(".g4") ) {
		return new StructureViewModelBase(psiFile, new DummyViewTreeElement(psiFile));
	}
             return new ANTLRv4StructureViewModel((ANTLRv4FileRoot)psiFile);
}
     };
 }
 
Example #11
Source File: ComponentStructureView.java    From litho with Apache License 2.0 5 votes vote down vote up
private static StructureView createStructureView(
    LayoutSpecModel model, FileEditor selectedEditor, PsiFile selectedFile, Project project) {
  final StructureViewModel viewModel = ComponentTreeModel.create(selectedFile, model);
  final StructureView view =
      StructureViewFactory.getInstance(project)
          .createStructureView(selectedEditor, viewModel, project, true);
  Disposer.register(view, viewModel);
  return view;
}
 
Example #12
Source File: ThriftStructureViewFactory.java    From intellij-thrift with Apache License 2.0 5 votes vote down vote up
@Override
public StructureViewBuilder getStructureViewBuilder(final PsiFile psiFile) {
  return new TreeBasedStructureViewBuilder() {
    @NotNull
    public StructureViewModel createStructureViewModel(@Nullable Editor editor) {
      return new ThriftStructureViewModel(psiFile);
    }

    @Override
    public boolean isRootNodeShown() {
      return false;
    }
  };
}
 
Example #13
Source File: MethodUpDownUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static void addNavigationElements(Collection<PsiElement> array, PsiFile element) {
  StructureViewBuilder structureViewBuilder = LanguageStructureViewBuilder.INSTANCE.getStructureViewBuilder(element);
  if (structureViewBuilder instanceof TreeBasedStructureViewBuilder) {
    TreeBasedStructureViewBuilder builder = (TreeBasedStructureViewBuilder) structureViewBuilder;
    StructureViewModel model = builder.createStructureViewModel(null);
    try {
      addStructureViewElements(model.getRoot(), array, element);
    }
    finally {
      model.dispose();
    }
  }
}
 
Example #14
Source File: TemplateLanguageStructureViewBuilder.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
@Nonnull
public StructureViewModel createStructureViewModel(@Nullable Editor editor) {
  List<StructureViewComposite.StructureViewDescriptor> viewDescriptors = new ArrayList<>();
  PsiFile psiFile = ObjectUtils.notNull(PsiManager.getInstance(myProject).findFile(myVirtualFile));
  for (Language language : getLanguages(psiFile)) {
    StructureViewBuilder builder = getBuilder(psiFile, language);
    if (!(builder instanceof TreeBasedStructureViewBuilder)) continue;
    StructureViewModel model = ((TreeBasedStructureViewBuilder)builder).createStructureViewModel(editor);
    String title = language.getDisplayName();
    Image icon = ObjectUtils.notNull(LanguageUtil.getLanguageFileType(language), UnknownFileType.INSTANCE).getIcon();
    viewDescriptors.add(new StructureViewComposite.StructureViewDescriptor(title, model, icon));
  }
  return new StructureViewCompositeModel(psiFile, editor, viewDescriptors);
}
 
Example #15
Source File: BuckStructureViewFactory.java    From buck with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public StructureViewBuilder getStructureViewBuilder(final PsiFile psiFile) {
  return new TreeBasedStructureViewBuilder() {
    @NotNull
    @Override
    public StructureViewModel createStructureViewModel(@Nullable Editor editor) {
      return new BuckStructureViewModel(psiFile);
    }
  };
}
 
Example #16
Source File: ViewStructureAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public static StructureViewModel createStructureViewModel(@Nonnull Project project, @Nonnull FileEditor fileEditor, @Nonnull StructureView structureView) {
  StructureViewModel treeModel;
  VirtualFile virtualFile = fileEditor.getFile();
  if (structureView instanceof StructureViewComposite && virtualFile != null) {
    StructureViewComposite.StructureViewDescriptor[] views = ((StructureViewComposite)structureView).getStructureViews();
    PsiFile psiFile = ObjectUtils.notNull(PsiManager.getInstance(project).findFile(virtualFile));
    treeModel = new StructureViewCompositeModel(psiFile, EditorUtil.getEditorEx(fileEditor), Arrays.asList(views));
    Disposer.register(structureView, treeModel);
  }
  else {
    treeModel = structureView.getTreeModel();
  }
  return treeModel;
}
 
Example #17
Source File: StructureAwareNavBarModelExtension.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
@RequiredReadAction
public boolean processChildren(Object object, Object rootElement, Processor<Object> processor) {
  if (UISettings.getInstance().getShowMembersInNavigationBar()) {
    if (object instanceof PsiElement) {
      if (((PsiElement)object).getLanguage() == getLanguage()) {
        StructureViewModel model = buildStructureViewModel(((PsiElement)object).getContainingFile(), null);
        if (model != null) {
          return processStructureViewChildren(model.getRoot(), object, processor);
        }
      }
    }
  }
  return super.processChildren(object, rootElement, processor);
}
 
Example #18
Source File: FileStructureDialog.java    From consulo with Apache License 2.0 5 votes vote down vote up
public FileStructureDialog(StructureViewModel structureViewModel,
                           @Nullable Editor editor,
                           Project project,
                           Navigatable navigatable,
                           @Nonnull final Disposable auxDisposable,
                           final boolean applySortAndFilter) {
  super(project, true);
  myProject = project;
  myEditor = editor;
  myNavigatable = navigatable;
  myBaseTreeModel = structureViewModel;
  if (applySortAndFilter) {
    myTreeActionsOwner = new TreeStructureActionsOwner(myBaseTreeModel);
    myTreeModel = new TreeModelWrapper(structureViewModel, myTreeActionsOwner);
  }
  else {
    myTreeActionsOwner = null;
    myTreeModel = structureViewModel;
  }

  PsiFile psiFile = getPsiFile(project);

  final PsiElement psiElement = getCurrentElement(psiFile);

  //myDialog.setUndecorated(true);
  init();

  if (psiElement != null) {
    if (structureViewModel.shouldEnterElement(psiElement)) {
      myCommanderPanel.getBuilder().enterElement(psiElement, PsiUtilBase.getVirtualFile(psiElement));
    }
    else {
      myCommanderPanel.getBuilder().selectElement(psiElement, PsiUtilBase.getVirtualFile(psiElement));
    }
  }

  Disposer.register(myDisposable, auxDisposable);
}
 
Example #19
Source File: CppLanguage.java    From CppTools with Apache License 2.0 5 votes vote down vote up
@Nullable
public StructureViewBuilder getStructureViewBuilder(final PsiFile psiFile) {
  return new TreeBasedStructureViewBuilder() {
    @NotNull
    @Override
    public StructureViewModel createStructureViewModel(@Nullable Editor editor) {
      return createStructureViewModel(); // todo, new api Idea 14.1
    }

    public StructureViewModel createStructureViewModel() {
      return new CppStructureViewBuilder(psiFile);
    }
  };
}
 
Example #20
Source File: LatteStructureViewFactory.java    From intellij-latte with MIT License 5 votes vote down vote up
@Nullable
@Override
public StructureViewBuilder getStructureViewBuilder(final PsiFile psiFile) {
	return new TreeBasedStructureViewBuilder() {
		@NotNull
		@Override
		public StructureViewModel createStructureViewModel(@Nullable Editor editor) {
			return new LatteStructureViewModel(psiFile);
		}
	};
}
 
Example #21
Source File: HaskellStructureViewFactory.java    From intellij-haskforce with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public StructureViewBuilder getStructureViewBuilder(final PsiFile psiFile) {
    return new TreeBasedStructureViewBuilder() {
        @NotNull
        @Override
        public StructureViewModel createStructureViewModel(@Nullable Editor editor) {
            return new HaskellStructureViewModel(psiFile);
        }
    };
}
 
Example #22
Source File: SimpleStructureViewFactory.java    From intellij-sdk-docs with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public StructureViewBuilder getStructureViewBuilder(@NotNull final PsiFile psiFile) {
  return new TreeBasedStructureViewBuilder() {
    @NotNull
    @Override
    public StructureViewModel createStructureViewModel(@Nullable Editor editor) {
      return new SimpleStructureViewModel(psiFile);
    }
  };
}
 
Example #23
Source File: GLSLStructureViewFactory.java    From glsl4idea with GNU Lesser General Public License v3.0 5 votes vote down vote up
public StructureViewBuilder getStructureViewBuilder(@NotNull final PsiFile psiFile) {
    return new TreeBasedStructureViewBuilder() {

        @NotNull
        @Override
        public StructureViewModel createStructureViewModel(Editor editor) {
            return new GLSLStructureViewModel(psiFile);
        }
    };
}
 
Example #24
Source File: SampleStructureViewFactory.java    From jetbrains-plugin-sample with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Nullable
@Override
public StructureViewBuilder getStructureViewBuilder(final PsiFile psiFile) {
	return new TreeBasedStructureViewBuilder() {
		@NotNull
		@Override
		public StructureViewModel createStructureViewModel(@Nullable Editor editor) {
			return new SampleStructureViewModel((SamplePSIFileRoot)psiFile);
		}
	};
}
 
Example #25
Source File: BashStructureViewModelTest.java    From BashSupport with Apache License 2.0 5 votes vote down vote up
@Test
public void testStructureView() throws Exception {
    VirtualFile file = configure();
    Assert.assertNotNull(file);

    MyTest myTest = new MyTest() {
        public void test(StructureViewComponent component) {
            StructureViewModel tree = component.getTreeModel();
            Assert.assertNotNull(tree);

            StructureViewTreeElement root = tree.getRoot();
            Assert.assertNotNull(root);

            TreeElement[] children = root.getChildren();
            Assert.assertEquals(1, children.length);

            TreeElement firstChild = children[0];
            Assert.assertNotNull(firstChild);

            Assert.assertEquals("a()", firstChild.getPresentation().getPresentableText());

            Assert.assertNotNull(firstChild.getChildren());
            Assert.assertEquals(0, firstChild.getChildren().length);
        }
    };

    doTest(myTest);
}
 
Example #26
Source File: CsvStructureViewFactory.java    From intellij-csv-validator with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public StructureViewBuilder getStructureViewBuilder(final PsiFile psiFile) {
    return new TreeBasedStructureViewBuilder() {
        @NotNull
        @Override
        public StructureViewModel createStructureViewModel(@Nullable Editor editor) {
            return new CsvStructureViewModel(psiFile);
        }
    };
}
 
Example #27
Source File: WeaveStructureViewBuilderFactory.java    From mule-intellij-plugins with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public StructureViewBuilder getStructureViewBuilder(final PsiFile psiFile) {
    return new TreeBasedStructureViewBuilder() {
        @NotNull
        @Override
        public StructureViewModel createStructureViewModel(@Nullable Editor editor) {
            return new WeaveStructureViewModel(psiFile, editor, new WeaveDocumentStructureView((WeaveFile) psiFile));
        }
    };
}
 
Example #28
Source File: FusionStructureViewBuilderFactory.java    From intellij-neos with GNU General Public License v3.0 5 votes vote down vote up
@Nullable
@Override
public StructureViewBuilder getStructureViewBuilder(final PsiFile psiFile) {
    final FusionFile fusionFile = (FusionFile) psiFile;
    return new TreeBasedStructureViewBuilder() {
        @NotNull
        @Override
        public StructureViewModel createStructureViewModel(@Nullable Editor editor) {
            return new FusionStructureViewModel(editor, fusionFile);
        }
    };
}
 
Example #29
Source File: JSGraphQLEndpointPsiStructureViewFactory.java    From js-graphql-intellij-plugin with MIT License 5 votes vote down vote up
@Nullable
@Override
public StructureViewBuilder getStructureViewBuilder(PsiFile psiFile) {
    return new TreeBasedStructureViewBuilder() {
        @NotNull
        public StructureViewModel createStructureViewModel(@Nullable Editor editor) {
            return new JSGraphQLEndpointStructureViewModel(psiFile, editor);
        }

        public boolean isRootNodeShown() {
            return false;
        }
    };
}
 
Example #30
Source File: GraphQLPsiStructureViewFactory.java    From js-graphql-intellij-plugin with MIT License 5 votes vote down vote up
@Nullable
@Override
public StructureViewBuilder getStructureViewBuilder(@NotNull PsiFile psiFile) {
    return new TreeBasedStructureViewBuilder() {
        @NotNull
        public StructureViewModel createStructureViewModel(@Nullable Editor editor) {
            return new GraphQLStructureViewModel(psiFile, editor);
        }

        public boolean isRootNodeShown() {
            return false;
        }
    };
}