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 28, 2022
1 parent 99ba69f commit b1a5157
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import javafx.beans.property.SimpleObjectProperty;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.geometry.NodeOrientation;
import javafx.scene.control.Button;
import javafx.scene.control.ContentDisplay;
import javafx.scene.control.ContextMenu;
Expand All @@ -24,9 +25,6 @@

public class ProjectExplorerController {

@FXML
private Button addInstanceButton;

@FXML
private TreeView<TreeItemData> treeView;

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

@NotNull
Expand All @@ -108,31 +105,38 @@ public ReadOnlyObjectProperty<BigtableTable> selectedTableProperty() {
public ContextMenu createContextMenu(@NotNull TreeItemData item){
ContextMenu menu = null;
if (item.isProject()) {
var addInstance = new MenuItem("Add instance");
addInstance.setOnAction(actionEvent ->
AddInstanceDialog
.displayAndAwaitResult(item.getProjectId())
.whenComplete(this::handleAddInstanceResult));
var removeProject = new MenuItem("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.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.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.setOnAction(actionEvent ->
AddInstanceDialog
.displayAndAwaitResult(item.getProjectId())
.whenComplete(this::handleAddInstanceResult));
return addInstance;
}

private void handleAddInstanceResult(@Nullable BigtableInstance instance, Throwable throwable) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

public enum CellTimestampDisplayMode {

NONE("None"),
DATE_TIME("DateTime"),
MILLIS("Millis"),
MICROS("Micros");
NONE("Hide timestamps"),
DATE_TIME("Timestamps as date time"),
MILLIS("Timestamps as millis"),
MICROS("Timestamps as micros");

private final String displayValue;

Expand Down
7 changes: 7 additions & 0 deletions src/main/resources/css/global.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.has-spacing {
-fx-spacing: 10px;
}

* {
-fx-font-family: 'Verdana';
}
10 changes: 6 additions & 4 deletions src/main/resources/css/main.css
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
@import "global.css";

.pane-view {
-fx-padding: 10 10 10 10;
}

.has-spacing {
-fx-spacing: 10px;
.split-pane {
-fx-box-border: transparent, -fx-background;
}

* {
-fx-font-family: 'Verdana';
.main-content {
-fx-padding: 10 0 0 0;
}

1 change: 1 addition & 0 deletions src/main/resources/css/project_explorer.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import "global.css";
22 changes: 9 additions & 13 deletions src/main/resources/fxml/main.fxml
Original file line number Diff line number Diff line change
@@ -1,27 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.geometry.Insets?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.control.SplitPane?>
<BorderPane xmlns:fx="http://javafx.com/fxml"
fx:controller="com.erikmafo.btviewer.ui.MainController"
stylesheets="/css/main.css"
styleClass="pane-view">
stylesheets="/css/main.css">
<top>
<VBox>
<BorderPane.margin>
<Insets bottom="10"/>
</BorderPane.margin>
<fx:include fx:id="menuBar" source="bigtable_menu_bar.fxml"/>
</VBox>
</top>
<left>
<fx:include fx:id="projectExplorer" source="project_explorer.fxml"/>
</left>
<center>
<fx:include fx:id="queryResultView" source="query_result_view.fxml"/>
<SplitPane orientation="HORIZONTAL">
<fx:include fx:id="projectExplorer" styleClass="projects" source="project_explorer.fxml"/>
<SplitPane orientation="VERTICAL" styleClass="main-content">
<fx:include fx:id="queryResultView" source="query_result_view.fxml"/>
<fx:include fx:id="queryBox" source="query_box.fxml"/>
</SplitPane>
</SplitPane>
</center>
<bottom>
<fx:include fx:id="queryBox" source="query_box.fxml"/>
</bottom>
</BorderPane>
9 changes: 5 additions & 4 deletions src/main/resources/fxml/project_explorer.fxml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.TreeView?>
<?import javafx.scene.layout.VBox?>

<VBox xmlns:fx="http://javafx.com/fxml"
fx:controller="com.erikmafo.btviewer.ui.projectexplorer.ProjectExplorerController"
stylesheets="/css/main.css"
stylesheets="/css/project_explorer.css"
styleClass="has-spacing">
<Button fx:id="addInstanceButton" styleClass="btn">Add Instance</Button>
<TreeView fx:id="treeView" visible="false" VBox.vgrow="ALWAYS"/>
<TreeView fx:id="treeView"
visible="false"
VBox.vgrow="ALWAYS"/>
</VBox>
8 changes: 4 additions & 4 deletions src/main/resources/fxml/query_result_view.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
<?import javafx.scene.layout.Region?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.control.ChoiceBox?>
<?import javafx.scene.control.Label?>
<VBox xmlns:fx="http://javafx.com/fxml"
fx:controller="com.erikmafo.btviewer.ui.queryresult.QueryResultViewController"
fx:id="vBox"
Expand All @@ -17,12 +16,13 @@
onAction="#handleTableSettingsButtonPressed"
mnemonicParsing="false"
text="Table Settings"
styleClass="btn"/>
styleClass="btn btn-sm btn-default"/>
<Region HBox.hgrow="ALWAYS"/>

<HBox styleClass="has-spacing">
<Label>Timestamp display: </Label>
<ChoiceBox fx:id="timestampDisplayModeChoiceBox"/>
<ChoiceBox
fx:id="timestampDisplayModeChoiceBox"
styleClass="btn btn-sm btn-default"/>
</HBox>
</HBox>
<TreeTableView fx:id="tableView"
Expand Down

0 comments on commit b1a5157

Please sign in to comment.