Skip to content

Commit

Permalink
add persistence for credentials and bigtable instances
Browse files Browse the repository at this point in the history
  • Loading branch information
erikmafo committed Jan 6, 2019
1 parent 20f0068 commit dec1798
Show file tree
Hide file tree
Showing 42 changed files with 752 additions and 719 deletions.
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,4 @@ deploy:
draft: true
on:
branch: master
tags: true
condition: "$TRAVIS_TAG =~ ^v[0-9]+\.[0-9]+\.[0-9]+"
tags: true
14 changes: 12 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>com.erikmafo</groupId>
<artifactId>bigtableviewer</artifactId>
<version>0.1.2</version>
<version>0.1.3-SNAPSHOT</version>
<packaging>jar</packaging>
<name>bigtableviewer</name>

Expand Down Expand Up @@ -187,7 +187,7 @@
</dependency>
<dependency>
<groupId>com.google.cloud.bigtable</groupId>
<artifactId>bigtable-hbase-1.x</artifactId>
<artifactId>bigtable-hbase-1.x-shaded</artifactId>
<version>1.7.0</version>
</dependency>
<dependency>
Expand All @@ -196,6 +196,11 @@
<version>1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
Expand Down Expand Up @@ -231,5 +236,10 @@
<version>1.10.19</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>4.2.2</version>
</dependency>
</dependencies>
</project>
17 changes: 16 additions & 1 deletion src/main/java/com/erikmafo/btviewer/MainApp.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
package com.erikmafo.btviewer;
import com.erikmafo.btviewer.services.BigtableClient;
import com.erikmafo.btviewer.services.BigtableInstanceManager;
import com.erikmafo.btviewer.services.CredentialsManager;
import com.google.inject.Binder;
import com.google.inject.Guice;
import com.google.inject.Module;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
Expand All @@ -9,14 +15,16 @@
/**
* Created by erikmafo on 12.12.17.
*/
public class MainApp extends Application {
public class MainApp extends Application implements Module {

public static void main(String[] args) {
launch(args);
}

@Override
public void start(Stage primaryStage) throws Exception{
FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/main.fxml"));
loader.setControllerFactory(Guice.createInjector(this)::getInstance);
Parent root = loader.load();
primaryStage.setTitle("Bigtable viewer");
primaryStage.setScene(new Scene(root, 800, 700));
Expand All @@ -27,4 +35,11 @@ public void start(Stage primaryStage) throws Exception{
public void stop() throws Exception {
super.stop();
}

@Override
public void configure(Binder binder) {
binder.bind(BigtableClient.class).toInstance(new BigtableClient());
binder.bind(CredentialsManager.class).toInstance(new CredentialsManager());
binder.bind(BigtableInstanceManager.class).toInstance(new BigtableInstanceManager());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@

import com.erikmafo.btviewer.model.BigtableColumn;
import com.erikmafo.btviewer.model.BigtableRow;
import com.erikmafo.btviewer.services.BigtableResultScanner;
import javafx.application.Platform;
import javafx.beans.property.ReadOnlyObjectWrapper;
import javafx.collections.FXCollections;
import javafx.collections.ListChangeListener;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.geometry.Orientation;
import javafx.scene.Node;
import javafx.scene.control.*;
import javafx.scene.layout.GridPane;
import javafx.scene.input.ScrollEvent;
import javafx.scene.layout.VBox;

import java.io.IOException;
import java.util.*;
Expand All @@ -22,18 +23,19 @@
/**
* Created by erikmafo on 12.12.17.
*/
public class BigtableView extends GridPane {
public class BigtableTableView extends VBox {

public static final String ROWKEY = "rowkey";
private static final String ROWKEY = "rowkey";

@FXML
private TableView<BigtableRow> tableView;
private Button configureRowValueTypesButton;

private BigtableResultScanner scanner;
@FXML
private TableView<BigtableRow> tableView;

public BigtableView() {
public BigtableTableView() {

FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/bigtable_view.fxml"));
FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/bigtable_table_view.fxml"));
loader.setRoot(this);
loader.setController(this);

Expand All @@ -44,10 +46,7 @@ public BigtableView() {
}

tableView.getColumns().add(createRowKeyColumn());
tableView.setOnScroll(event -> {
ScrollBar bar = getVerticalScrollbar();
Platform.runLater(() -> addRows((int)bar.getMax()));
});
configureRowValueTypesButton.setVisible(false); // TODO: enable this feature
}

private ScrollBar getVerticalScrollbar() {
Expand All @@ -72,6 +71,19 @@ private ScrollBar getVerticalScrollbar() {
return tableColumn;
}

public int getMaxRows() {
ScrollBar bar = getVerticalScrollbar();
return (int)bar.getMax();
}

public void setOnConfigureRowValuesTypes(EventHandler<ActionEvent> eventHandler) {
configureRowValueTypesButton.setOnAction(eventHandler);
}

public void setOnScrollEvent(EventHandler<ScrollEvent> eventHandler) {
getVerticalScrollbar().setOnScroll(eventHandler);
}

public List<BigtableColumn> getColumns() {
return tableView.getColumns()
.stream()
Expand All @@ -82,24 +94,13 @@ public List<BigtableColumn> getColumns() {
.collect(Collectors.toList());
}

public void setBigtableScanner(BigtableResultScanner scanner)
{
if (this.scanner != null)
{
BigtableResultScanner prevScanner = this.scanner;
Platform.runLater(() ->
{
try {
prevScanner.close();
} catch (IOException e) {
e.printStackTrace();
}
});
}
this.scanner = scanner;
public void clear() {
tableView.getColumns().removeIf(t -> !t.getText().equals(ROWKEY));
setBigTableRows(FXCollections.observableArrayList());
Platform.runLater(() -> addRows(20));
}

public void add(BigtableRow row) {
tableView.getItems().add(row);
}

private void addColumn(String family, String qualifier) {
Expand All @@ -116,7 +117,6 @@ private void addColumn(String family, String qualifier) {
return new ReadOnlyObjectWrapper<>(bigtableRow.getCellValue(family, qualifier));
});


if (familyColumn == null) {
familyColumn = new TableColumn<>(family);
familyColumn.getColumns().add(qualifierColumn);
Expand All @@ -137,22 +137,4 @@ private void setBigTableRows(ObservableList<BigtableRow> bigtableRows) {
}
});
}

private void addRows(int maxRows) {
int count = 0;

BigtableRow row;
do {
try {
row = scanner.next();
if (row == null) {
break;
}
tableView.getItems().add(row);
count++;
} catch (IOException e) {
e.printStackTrace();
}
} while (count < maxRows);
}
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
package com.erikmafo.btviewer.components;
import com.erikmafo.btviewer.events.BigtableProjectTreeItemExpanded;
import com.erikmafo.btviewer.model.BigtableInstance;
import com.erikmafo.btviewer.model.BigtableTable;
import javafx.beans.property.ReadOnlyObjectProperty;
import javafx.beans.property.ReadOnlyStringProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.control.*;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.VBox;

import java.io.IOException;
import java.util.List;
import java.util.stream.Collectors;

public class BigtableTablesListView extends GridPane {
public class BigtableTablesListView extends VBox {

@FXML
private Button addInstanceButton;
Expand All @@ -26,9 +27,7 @@ public class BigtableTablesListView extends GridPane {

private SimpleObjectProperty<BigtableTable> selectedTableProperty;

private SimpleObjectProperty<BigtableInstance> selectedInstanceProperty = new SimpleObjectProperty<>();

private SimpleStringProperty selectedProjectProperty = new SimpleStringProperty();
private EventHandler<BigtableProjectTreeItemExpanded> treeItemExpandedEventHandler;

public BigtableTablesListView(){
FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/bigtable_tables_list_view.fxml"));
Expand Down Expand Up @@ -62,11 +61,15 @@ private static int countParents(TreeItem<String> treeItem) {
return 1 + countParents(treeItem.getParent());
}

public void setOnAddBigtableInstance(EventHandler<ActionEvent> eventHandler) {
public void setOnCreateNewBigtableInstance(EventHandler<ActionEvent> eventHandler) {
addInstanceButton.setOnAction(eventHandler);
}

public void addBigtableInstance(BigtableInstance instance, ChangeListener<Boolean> expandedListener) {
public void addBigtableInstances(List<BigtableInstance> bigtableInstances) {
bigtableInstances.forEach(this::addBigtableInstance);
}

public void addBigtableInstance(BigtableInstance instance) {

TreeItem<String> projectTreeItem = treeView.getRoot()
.getChildren()
Expand All @@ -75,7 +78,21 @@ public void addBigtableInstance(BigtableInstance instance, ChangeListener<Boolea
.orElse(null);

if (projectTreeItem == null) {
projectTreeItem = new TreeItem<>(instance.getProjectId());
final TreeItem<String> projectTreeItemFinal = new TreeItem<>(instance.getProjectId());

projectTreeItemFinal.expandedProperty().addListener(new ChangeListener<Boolean>() {
@Override
public void changed(ObservableValue<? extends Boolean> observableValue, Boolean wasExpanded, Boolean isExpanded) {
if (isExpanded && treeItemExpandedEventHandler != null) {
List<BigtableInstance> bigtableInstances = projectTreeItemFinal.getChildren()
.stream()
.map(i -> new BigtableInstance(instance.getProjectId(), i.getValue()))
.collect(Collectors.toList());
treeItemExpandedEventHandler.handle(new BigtableProjectTreeItemExpanded(bigtableInstances));
}
}
});
projectTreeItem = projectTreeItemFinal;
}

TreeItem<String> instanceTreeItem = new TreeItem<>(instance.getInstanceId());
Expand Down Expand Up @@ -103,21 +120,10 @@ public void addBigtableTables(List<BigtableTable> tables) {
instance.getChildren().add(new TreeItem<>(table.getTableId()));
}
});

}
}

private MenuItem getMenuItem(BigtableInstance instance) {
MenuItem menuItem = new MenuItem(instance.getInstanceId());
menuItem.setUserData(instance);
return menuItem;
}

public ReadOnlyObjectProperty<BigtableInstance> selectedInstanceProperty() {
return selectedInstanceProperty;
}

public ReadOnlyStringProperty selectedProjectProperty() {
return selectedProjectProperty;
public void setTreeItemExpandedEventHandler(EventHandler<BigtableProjectTreeItemExpanded> treeItemExpandedEventHandler) {
this.treeItemExpandedEventHandler = treeItemExpandedEventHandler;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.erikmafo.btviewer.model.CellDefinition;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.collections.transformation.SortedList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
Expand Down Expand Up @@ -32,7 +31,6 @@ public class BigtableValueTypesDialog extends DialogPane {
private BigtableValueTypesDialog() {

FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/bigtable_value_types_dialog.fxml"));

loader.setRoot(this);
loader.setController(this);

Expand Down
Loading

0 comments on commit dec1798

Please sign in to comment.