Plugin Toolbar development
I have problems getting a good toolbar up and running and somehow could not find good extensive resources on the Toolbar API.
The base of my toolbar should kinda be built up like the Gradle Toolbar:
only difference is that it will have multiple tabs,
otherwise it should have an action bar with three buttons:
RunAction runAction = new RunAction();
TestAction testAction = new TestAction();
UploadAction uploadAction = new UploadAction();
ActionGroup actions = new ActionGroup() {
@Override
public AnAction @NotNull [] getChildren(@Nullable AnActionEvent e) {
return new AnAction[]{runAction, testAction, uploadAction};
}
};
ActionToolbarImpl actionToolbar = new ActionToolbarImpl(ActionPlaces.TOOLBAR, actions, true);
After that it should have this tree view of custom data/panels I will set up later on.
The problem is I am not sure which classes are appropriate to use, I tried this approach so far:
JBScrollPane -> getViewport() -> SimpleTree
not sure if there are other JTree classes to use instead and I am not sure how to add items to that SimpleTree, could it be just like JTree?
Then next to add them all to the toolbar I use
toolWindow.getContentManager().addContent
combined with a JPanel, though I tried it out with SimpleToolWindowPanel but that didnt work somehow and I also could not find resources on that.
I tried to orientate using the UI Inspector on the Gradle toolbar as thats what I kinda want at the end.
Its structured like this:
ExternalProjectsViewImpl
- ActionToolbarImpl
// some buttons and separator
- JBScrollPane
- JBViewPort
- ExternalProjectTree
I tried to replicate that but that also didnt work
thats my current non working stage:
@Override
public void createToolWindowContent(@NotNull Project project, @NotNull ToolWindow toolWindow) {
// get list of selected organization then create multiple
ContentFactory factory = ContentFactory.getInstance();
ContentManager manager = toolWindow.getContentManager();
SimpleToolWindowPanel panel = new SimpleToolWindowPanel(true);
RunAction runAction = new RunAction();
TestAction testAction = new TestAction();
UploadAction uploadAction = new UploadAction();
ActionGroup actions = new ActionGroup() {
@Override
public AnAction @NotNull [] getChildren(@Nullable AnActionEvent e) {
return new AnAction[]{runAction, testAction, uploadAction};
}
};
ActionToolbarImpl actionToolbar = new ActionToolbarImpl(ActionPlaces.TOOLBAR, actions, true);
actionToolbar.setTargetComponent(panel);
JBScrollPane courses = new JBScrollPane();
SimpleTree tree = new SimpleTree();
courses.getViewport().add(tree);
panel.add(actionToolbar);
panel.add(courses);
manager.addContent(factory.createContent(panel, "Test", false));
}
its kinda based like the Gradle toolbar:
but my buttons seem kinda bugged as they have Integer limit locations
and are nowhere to find, the Tree seems fine though, but I tried testing
with Nodes on the Tree which also didnt work, but I might added them wrongly
Thanks for any help and reach out if you need more information :D
Please sign in to leave a comment.
Hi,
It's unclear what the problems are. If you want to implement something similar to the Gradle tool window, I suggest checking its implementation: `org.jetbrains.plugins.gradle.ui.GradleToolWindowFactory` or other similar implementations. Here are the tips on exploring the platform code and finding example implementations: https://plugins.jetbrains.com/docs/intellij/explore-api.html. The same about trees - I suggest checking how the APIs are used in the platform and trying to follow it.
See also https://plugins.jetbrains.com/docs/intellij/tool-windows.html.
If you still have problems with the implementation, please be more specific about the issues. E.g., it is unclear what "doesn't work" means. Also, if something doesn't work, a minimal reproducible example will help diagnosing the issue.
ok thanks,
just fixed it while looking into more methods of SimpleToolWindowPanel and noticing there is a #setToolbar method as well, which is for adding the actions.
Thanks for linking the correct documentations.