Skip to content
This repository has been archived by the owner on May 13, 2024. It is now read-only.

Commit

Permalink
fix: servers toolbar actions state
Browse files Browse the repository at this point in the history
  • Loading branch information
le-yams committed Apr 30, 2024
1 parent 5dc89d9 commit 8674349
Showing 1 changed file with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,18 @@ public ServersTreePanel(ToolWindow toolWindow, OpenFGAServers servers) {

var toolbarDecorator = ToolbarDecorator.createDecorator(tree);

toolbarDecorator.setAddActionUpdater(updater -> isSelectedServerNode(NodeType.ROOT_NODE));
toolbarDecorator.setAddAction(this::addAction);

toolbarDecorator.setEditActionUpdater(updater -> getSelectedServerNode().isPresent());
toolbarDecorator.setEditActionUpdater(updater -> isSelectedServerNode(SERVER_NODE));
toolbarDecorator.setEditAction(this::editAction);

toolbarDecorator.setRemoveActionUpdater(updater -> getSelectedServerNode().isPresent());
toolbarDecorator.setRemoveActionUpdater(updater -> isSelectedServerNode(SERVER_NODE));
toolbarDecorator.setRemoveAction(this::removeAction);

toolbarDecorator.setMoveDownActionUpdater(updater -> isSelectedServerNode(SERVER_NODE));
toolbarDecorator.setMoveDownAction(this::moveDownAction);
toolbarDecorator.setMoveUpActionUpdater(updater -> isSelectedServerNode(SERVER_NODE));
toolbarDecorator.setMoveUpAction(this::moveUpAction);

add(toolbarDecorator.createPanel(), BorderLayout.CENTER);
Expand Down Expand Up @@ -163,4 +166,10 @@ private Optional<ServerNode> getSelectedServerNode() {
.findFirst()
.map(ServerNode.class::cast);
}

private boolean isSelectedServerNode(NodeType nodeType) {
return Arrays
.stream(tree.getSelectedNodes(TreeNode.class, node -> node.is(nodeType)))
.findAny().isPresent();
}
}

0 comments on commit 8674349

Please sign in to comment.