com.intellij.ide.structureView.StructureViewBuilder Java Examples

The following examples show how to use com.intellij.ide.structureView.StructureViewBuilder. 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: 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 #2
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 #3
Source File: CsvTableEditorSwingTest.java    From intellij-csv-validator with Apache License 2.0 6 votes vote down vote up
public void testBasics() {
    assertEquals(CsvTableEditor.EDITOR_NAME, fileEditor.getName());
    assertEquals(fileEditor, fileEditor.getCurrentLocation());
    assertInstanceOf(fileEditor.getState(FileEditorStateLevel.FULL), CsvTableEditorState.class);
    assertInstanceOf(fileEditor.getState(FileEditorStateLevel.NAVIGATION), CsvTableEditorState.class);
    assertInstanceOf(fileEditor.getState(FileEditorStateLevel.UNDO), CsvTableEditorState.class);

    CsvTableEditorState myState = new CsvTableEditorState();
    fileEditor.setState(myState);
    assertEquals(myState, fileEditor.getState(FileEditorStateLevel.FULL));

    assertEquals(false, fileEditor.isModified());
    assertEquals(true, fileEditor.isValid());
    assertEquals(null, fileEditor.getBackgroundHighlighter());

    StructureViewBuilder structureViewBuilder = StructureViewBuilder.PROVIDER.getStructureViewBuilder(myFixture.getFile().getFileType(), myFixture.getFile().getVirtualFile(), this.getProject());
    assertInstanceOf(fileEditor.getStructureViewBuilder(), structureViewBuilder.getClass());

    assertEquals(myFixture.getFile().getVirtualFile(), fileEditor.getFile());
    assertEquals(this.getProject(), fileEditor.getProject());
    assertNotNull(fileEditor.getDataHandler());
    assertNotNull(fileEditor.getComponent());
    assertEquals(fileEditor.getTable(), fileEditor.getPreferredFocusedComponent());
}
 
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: 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 #6
Source File: TemplateLanguageStructureViewBuilder.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
private StructureViewBuilder getBuilder(@Nonnull PsiFile psiFile, @Nonnull Language language) {
  FileViewProvider viewProvider = psiFile.getViewProvider();
  Language baseLanguage = viewProvider.getBaseLanguage();
  PsiFile psi = viewProvider.getPsi(language);
  if (psi == null) return null;
  if (language == baseLanguage) return createMainBuilder(psi);
  if (!isAcceptableBaseLanguageFile(psi)) return null;
  PsiStructureViewFactory factory = LanguageStructureViewBuilder.INSTANCE.forLanguage(language);
  return factory == null ? null : factory.getStructureViewBuilder(psi);
}
 
Example #7
Source File: XQueryStructureViewFactory.java    From intellij-xquery 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 com.intellij.ide.structureView.StructureViewModel createStructureViewModel(Editor editor) {
            return new XQueryStructureViewModel(psiFile).withSuitableClasses(
                    XQueryFunctionDecl.class, XQueryVarDecl.class, XQueryQueryBody.class
            );
        }
    };
}
 
Example #8
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 #9
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 #10
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 #11
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 #12
Source File: LanguageFileTypeStructureViewBuilderProvider.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
@Nullable
public StructureViewBuilder getStructureViewBuilder(@Nonnull final FileType fileType, @Nonnull final VirtualFile file, @Nonnull final Project project) {
  if (!(fileType instanceof LanguageFileType)) return null;

  final PsiFile psiFile = PsiManager.getInstance(project).findFile(file);
  if (psiFile == null) return null;

  final PsiStructureViewFactory factory = LanguageStructureViewBuilder.INSTANCE.forLanguage(psiFile.getLanguage());
  return factory == null ?  null : factory.getStructureViewBuilder(psiFile);
}
 
Example #13
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 #14
Source File: HttpFileEditor.java    From consulo with Apache License 2.0 5 votes vote down vote up
public StructureViewBuilder getStructureViewBuilder() {
  final TextEditor textEditor = myPanel.getFileEditor();
  if (textEditor != null) {
    return textEditor.getStructureViewBuilder();
  }
  return null;
}
 
Example #15
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 #16
Source File: DesktopTextEditorProvider.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public StructureViewBuilder getStructureViewBuilder() {
  VirtualFile file = FileDocumentManager.getInstance().getFile(myEditor.getDocument());
  if (file == null) return null;

  final Project project = myEditor.getProject();
  LOG.assertTrue(project != null);
  return StructureViewBuilder.PROVIDER.getStructureViewBuilder(file.getFileType(), file, project);
}
 
Example #17
Source File: DesktopTextEditorImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public StructureViewBuilder getStructureViewBuilder() {
  Document document = myComponent.getEditor().getDocument();
  VirtualFile file = FileDocumentManager.getInstance().getFile(document);
  if (file == null || !file.isValid()) return null;
  return StructureViewBuilder.PROVIDER.getStructureViewBuilder(file.getFileType(), file, myProject);
}
 
Example #18
Source File: LanguageStructureViewBuilder.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
public StructureViewBuilder getStructureViewBuilder(PsiFile file) {
  PsiStructureViewFactory factory = forLanguage(file.getLanguage());
  if (factory != null) {
    return factory.getStructureViewBuilder(file);
  }
  return null;
}
 
Example #19
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 #20
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 #21
Source File: StructureViewFactory.java    From reasonml-idea-plugin with MIT License 5 votes vote down vote up
@Nullable
@Override
public StructureViewBuilder getStructureViewBuilder(@NotNull PsiFile psiFile) {
    return new TreeBasedStructureViewBuilder() {
        @NotNull
        @Override
        public com.intellij.ide.structureView.StructureViewModel createStructureViewModel(@Nullable Editor editor) {
            return new StructureViewModel(psiFile);
        }
    };
}
 
Example #22
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 #23
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 #24
Source File: ElmStructureViewFactory.java    From elm-plugin with MIT License 5 votes vote down vote up
@Nullable
@Override
public StructureViewBuilder getStructureViewBuilder(PsiFile psiFile) {
    ElmFile elmFile = (ElmFile) psiFile;
    return new TreeBasedStructureViewBuilder() {
        @NotNull
        @Override
        public StructureViewModel createStructureViewModel(@Nullable Editor editor) {
            return new ElmStructureViewModel(elmFile);
        }
    };
}
 
Example #25
Source File: BuildStructureViewFactory.java    From intellij with Apache License 2.0 5 votes vote down vote up
@Override
@Nullable
public StructureViewBuilder getStructureViewBuilder(final PsiFile psiFile) {
  if (!(psiFile instanceof BuildFile)) {
    return null;
  }
  return new TreeBasedStructureViewBuilder() {
    @Override
    public StructureViewModel createStructureViewModel(@Nullable Editor editor) {
      return new BuildStructureViewModel((BuildFile) psiFile, editor);
    }
  };
}
 
Example #26
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;
        }
    };
}
 
Example #27
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 #28
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 #29
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 #30
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);
    }
  };
}