Skip to content

Commit

Permalink
Fixes #167: Make panes resizable.
Browse files Browse the repository at this point in the history
  • Loading branch information
erikmafo committed Aug 31, 2022
1 parent ea48453 commit 3c2581b
Showing 1 changed file with 25 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@
import com.google.inject.Provider;
import javafx.beans.property.ReadOnlyObjectProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.ContentDisplay;
import javafx.scene.control.ContextMenu;
import javafx.scene.control.MenuItem;
Expand All @@ -26,9 +24,6 @@

public class ProjectExplorerController {

@FXML
private Button addInstanceButton;

@FXML
private TreeView<TreeItemData> treeView;

Expand Down Expand Up @@ -93,7 +88,6 @@ protected void updateItem(@Nullable TreeItemData item, boolean empty) {
}
});
treeView.setVisible(true);
addInstanceButton.setOnAction(this::handleAddInstanceAction);
}

@NotNull
Expand All @@ -110,34 +104,41 @@ public ReadOnlyObjectProperty<BigtableTable> selectedTableProperty() {
public ContextMenu createContextMenu(@NotNull TreeItemData item){
ContextMenu menu = null;
if (item.isProject()) {
var addInstance = new MenuItem("Add instance");
addInstance.setGraphic(FontAwesomeUtil.create(FontAwesome.Glyph.PLUS));
addInstance.setOnAction(actionEvent ->
AddInstanceDialog
.displayAndAwaitResult(item.getProjectId())
.whenComplete(this::handleAddInstanceResult));
var removeProject = new MenuItem("Remove");
removeProject.setGraphic(FontAwesomeUtil.create(FontAwesome.Glyph.REMOVE));
removeProject.setOnAction(actionEvent -> {
removeProjectService.setProjectId(item.getProjectId());
removeProjectService.setOnSucceeded(event -> ((RootTreeItem)treeView.getRoot()).removeProject((item.getProjectId())));
removeProjectService.setOnFailed(event -> AlertUtil.displayError("Unable to remove project", event));
removeProjectService.restart();
});

menu = new ContextMenu(addInstance, removeProject);
menu = new ContextMenu(getAddInstanceMenuItem(item), getRemoveProjectMenuItem(item));
} else if (item.isInstance()) {
var refreshTables = new MenuItem("Refresh tables");
refreshTables.setGraphic(FontAwesomeUtil.create(FontAwesome.Glyph.REFRESH));
refreshTables.setOnAction(e -> ((InstanceTreeItem)item.getTreeItem()).loadChildren());
menu = new ContextMenu(refreshTables);
} else if (item.isRoot()) {
menu = new ContextMenu(getAddInstanceMenuItem(item));
}

return menu;
}

private void handleAddInstanceAction(ActionEvent ignore) {
AddInstanceDialog.displayAndAwaitResult().whenComplete(this::handleAddInstanceResult);
@NotNull
private MenuItem getRemoveProjectMenuItem(@NotNull TreeItemData item) {
var removeProject = new MenuItem("Remove");
removeProject.setGraphic(FontAwesomeUtil.create(FontAwesome.Glyph.REMOVE));
removeProject.setOnAction(actionEvent -> {
removeProjectService.setProjectId(item.getProjectId());
removeProjectService.setOnSucceeded(event -> ((RootTreeItem)treeView.getRoot()).removeProject((item.getProjectId())));
removeProjectService.setOnFailed(event -> AlertUtil.displayError("Unable to remove project", event));
removeProjectService.restart();
});
return removeProject;
}

@NotNull
private MenuItem getAddInstanceMenuItem(@NotNull TreeItemData item) {
var addInstance = new MenuItem("Add instance");
addInstance.setGraphic(FontAwesomeUtil.create(FontAwesome.Glyph.PLUS));
addInstance.setOnAction(actionEvent ->
AddInstanceDialog
.displayAndAwaitResult(item.getProjectId())
.whenComplete(this::handleAddInstanceResult));
return addInstance;
}

private void handleAddInstanceResult(@Nullable BigtableInstance instance, Throwable throwable) {
Expand Down

0 comments on commit 3c2581b

Please sign in to comment.