Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# CouchbaseLiteTester
###### version 1.5
###### version 1.6
This app provides a UI to create a local Couchbase Lite DB and Sync Data to the DB from a Couchbase Sync Gateway. It provides features to search for documents in the CBLite DB, selectively sync certain channels and supports both Pull and Push replication.

## Getting Started
Expand Down Expand Up @@ -88,6 +88,9 @@ mvn compile package
This will create a distributable JAR file in build folder. Package an appropriate defaults.xml file along with your jar file with appropriate environments setup.

## Features
###### version 1.6
* Minor enhancements and bug fixes
* Search displays matched doc counts
###### version 1.5
* Support to search documents (Advance Search) based on multiple keywords
###### version 1.4
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package io.amrishraje.cblitetester;

import javafx.animation.KeyFrame;
import javafx.animation.Timeline;
import javafx.application.Platform;
import javafx.collections.transformation.FilteredList;
import javafx.event.ActionEvent;
import javafx.scene.control.*;
import javafx.stage.Stage;
import javafx.util.Duration;
import org.ahocorasick.trie.Emit;
import org.ahocorasick.trie.Trie;
import org.slf4j.Logger;
Expand All @@ -12,6 +16,7 @@
import java.util.Arrays;
import java.util.Collection;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;

public class AdvanceSearchController {

Expand All @@ -38,9 +43,26 @@ public void searchDocuments(ActionEvent event) {
filteredData = mainController.getFilteredData();
String lowerCaseFilter = searchTextBox.getText();
String[] searchList = lowerCaseFilter.split(";");
AtomicInteger docCount = new AtomicInteger();
Timeline timeline = new Timeline(new KeyFrame(Duration.seconds(5), x -> mainController.docCountAnchorPane.setVisible(false)));
filteredData.setPredicate(tableData -> {
return containsWordsAhoCorasick(tableData.getValue(), searchList, matchWholeWords.isSelected());
if (containsWordsAhoCorasick(tableData.getValue(), searchList, matchWholeWords.isSelected())) {
docCount.getAndIncrement();
return true;
} else return false;
});
mainController.docCountLabel.setText(docCount.toString() + " documents matched");
mainController.docCountLabel.setVisible(true);
mainController.docCountLabel.setStyle("-fx-background: rgba(30,30,30);\n" +
" -fx-text-fill: white;\n" +
" -fx-background-color: rgba(30,30,30,0.8);\n" +
" -fx-background-radius: 6px;\n" +
" -fx-background-insets: 0;\n" +
" -fx-padding: 0.667em 0.75em 0.667em 0.75em; /* 10px */\n" +
" -fx-effect: dropshadow( three-pass-box , rgba(0,0,0,0.5) , 10, 0.0 , 0 , 3 );\n" +
" -fx-font-size: 0.85em;");
mainController.docCountAnchorPane.setVisible(true);
Platform.runLater(timeline::play);
Stage stage = (Stage) cancelButton.getScene().getWindow();
stage.close();
}
Expand Down
24 changes: 24 additions & 0 deletions src/main/java/io/amrishraje/cblitetester/MainController.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import com.couchbase.lite.CouchbaseLiteException;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import javafx.animation.KeyFrame;
import javafx.animation.Timeline;
import javafx.application.Platform;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.value.ObservableValue;
Expand All @@ -40,6 +42,7 @@
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;
import javafx.util.Callback;
import javafx.util.Duration;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
Expand All @@ -58,9 +61,11 @@
import java.net.URL;
import java.util.List;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;

public class MainController implements Initializable {
private static final Logger logger = LoggerFactory.getLogger(MainController.class);
private final String version = "v1.6";
public Button syncButton;
public TextField userText;
public PasswordField pwdText;
Expand All @@ -86,6 +91,8 @@ public class MainController implements Initializable {
public ProgressBar progressBar;
public Label progressText;
public AnchorPane progressAnchorPane;
public Label docCountLabel;
public AnchorPane docCountAnchorPane;
Properties properties = new Properties();
Properties defaults = new Properties();
@FXML
Expand Down Expand Up @@ -196,6 +203,8 @@ public void initialize(URL url, ResourceBundle resourceBundle) {
}
});
replicationMode.setItems(FXCollections.observableArrayList("Pull", "Push", "Pull and Push"));
//Setup About
about.setText("CBLite Tester " + version + " by Amrish Raje" );
}

@FXML
Expand Down Expand Up @@ -492,6 +501,8 @@ public ObservableValue<String> call(TableColumn.CellDataFeatures<Map.Entry<Strin
// items = FXCollections.observableArrayList(cbLiteDataMap.entrySet());
// filteredData = new FilteredList<>(items, p -> true);
tableSearchText.textProperty().addListener((observable, oldValue, newValue) -> {
AtomicInteger docCount = new AtomicInteger();
Timeline timeline = new Timeline(new KeyFrame(Duration.seconds(5),x -> docCountAnchorPane.setVisible(false)));
filteredData.setPredicate(tableData -> {
// If filter text is empty, display all persons.
if (newValue == null || newValue.isEmpty()) {
Expand All @@ -500,10 +511,23 @@ public ObservableValue<String> call(TableColumn.CellDataFeatures<Map.Entry<Strin
String lowerCaseFilter = newValue.toLowerCase();

if (tableData.getKey().toLowerCase().contains(lowerCaseFilter)) {
docCount.getAndIncrement();
return true; // Filter matches key.
}
return false; // Does not match.
});
docCountLabel.setText(docCount.toString() + " documents matched");
docCountLabel.setVisible(true);
docCountLabel.setStyle("-fx-background: rgba(30,30,30);\n" +
" -fx-text-fill: white;\n" +
" -fx-background-color: rgba(30,30,30,0.8);\n" +
" -fx-background-radius: 6px;\n" +
" -fx-background-insets: 0;\n" +
" -fx-padding: 0.667em 0.75em 0.667em 0.75em; /* 10px */\n" +
" -fx-effect: dropshadow( three-pass-box , rgba(0,0,0,0.5) , 10, 0.0 , 0 , 3 );\n" +
" -fx-font-size: 0.85em;");
docCountAnchorPane.setVisible(true);
Platform.runLater(timeline::play);
});
dataTable.getColumns().setAll(docId, docValue);
docId.setEditable(false);
Expand Down
21 changes: 17 additions & 4 deletions src/main/resources/io/amrishraje/cblitetester/CBLiteScreen.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
<Button fx:id="syncButton" layoutX="50.0" layoutY="152.0" mnemonicParsing="false" onAction="#startSync" prefWidth="100.0" text="Sync" AnchorPane.leftAnchor="20.0" AnchorPane.topAnchor="195.0">
<tooltip>
<Tooltip text="Sync with Sync Gateway" />
</tooltip></Button>
</tooltip>
</Button>
<Button fx:id="stopSync" disable="true" layoutX="134.0" layoutY="150.0" mnemonicParsing="false" onAction="#stopContinuousSync" prefWidth="100.0" text="Stop Sync" AnchorPane.rightAnchor="20.0" AnchorPane.topAnchor="195.0">
<tooltip>
<Tooltip text="Stop sync if continuous sync is running" />
Expand All @@ -50,19 +51,21 @@
<Button fx:id="initSync" layoutX="22.0" layoutY="236.0" mnemonicParsing="false" onAction="#initSync" prefHeight="25.0" prefWidth="100.0" text="Initialize" AnchorPane.leftAnchor="20.0" AnchorPane.topAnchor="230.0">
<tooltip>
<Tooltip text="Initialize DB and sync" />
</tooltip></Button>
</tooltip>
</Button>
<Button fx:id="deleteSync" layoutX="129.0" layoutY="236.0" mnemonicParsing="false" onAction="#deleteDB" prefHeight="25.0" prefWidth="100.0" text="Delete" AnchorPane.rightAnchor="20.0" AnchorPane.topAnchor="230.0">
<tooltip>
<Tooltip text="Delete local CBLite DB file" />
</tooltip></Button>
</tooltip>
</Button>
<Button fx:id="reloadTable" layoutX="4.0" layoutY="494.0" mnemonicParsing="false" onAction="#reloadTable" text="Reload Table" AnchorPane.bottomAnchor="50.0" AnchorPane.leftAnchor="20.0" AnchorPane.rightAnchor="20.0" />
<Button fx:id="settingsButton" layoutX="84.0" layoutY="536.0" mnemonicParsing="false" onAction="#openSettings" text="Settings" AnchorPane.bottomAnchor="10.0" AnchorPane.leftAnchor="20.0" AnchorPane.rightAnchor="20.0" />
<Label fx:id="statusLabel" layoutX="20.0" layoutY="281.0" maxWidth="300.0" prefHeight="100.0" prefWidth="200.0" textFill="WHITE" wrapText="true" AnchorPane.leftAnchor="20.0" AnchorPane.topAnchor="270.0" />
<Label fx:id="tableStatusLabel" maxWidth="300.0" prefHeight="30.0" prefWidth="200.0" textFill="WHITE" AnchorPane.leftAnchor="20.0" AnchorPane.topAnchor="380.0" />
<Label layoutX="21.0" layoutY="211.0" text="Continuous Sync" textFill="WHITE" AnchorPane.leftAnchor="20.0" AnchorPane.topAnchor="165.0" />
<ToggleSwitch fx:id="continuousToggle" layoutX="99.0" layoutY="211.0" onMouseClicked="#toggleContinuousMode" textFill="WHITE" AnchorPane.leftAnchor="110.0" AnchorPane.topAnchor="165.0" />
<CheckComboBox fx:id="channelsComboBoxList" layoutX="21.0" layoutY="131.0" onMouseEntered="#setUpChannels" title="Sync Channels | Default: All" AnchorPane.leftAnchor="20.0" AnchorPane.rightAnchor="20.0" AnchorPane.topAnchor="90.0" />
<Hyperlink fx:id="about" layoutX="22.0" layoutY="490.0" onAction="#openAboutPage" text="About CBLiteTester" textFill="WHITE" AnchorPane.bottomAnchor="90.0" AnchorPane.leftAnchor="20.0" AnchorPane.rightAnchor="20.0" />
<Hyperlink fx:id="about" layoutX="22.0" layoutY="490.0" onAction="#openAboutPage" textFill="WHITE" AnchorPane.bottomAnchor="90.0" AnchorPane.leftAnchor="20.0" AnchorPane.rightAnchor="20.0" />
<ComboBox fx:id="replicationMode" layoutX="23.0" layoutY="132.0" prefWidth="150.0" promptText="Replication Mode | Default: Pull" visibleRowCount="3" AnchorPane.leftAnchor="20.0" AnchorPane.rightAnchor="20.0" AnchorPane.topAnchor="130.0" />
</children>
</AnchorPane>
Expand Down Expand Up @@ -97,6 +100,16 @@
<Label fx:id="progressText" layoutX="10.0" layoutY="0.79998779296875" text="Loading data, please wait..." visible="false" AnchorPane.leftAnchor="20.0" AnchorPane.topAnchor="10.0" />
</children>
</AnchorPane>
<AnchorPane fx:id="docCountAnchorPane" blendMode="SRC_ATOP" layoutX="360.0" layoutY="468.0" prefHeight="42.0" prefWidth="168.0" visible="false" AnchorPane.bottomAnchor="40.0" AnchorPane.leftAnchor="410.0">
<children>
<Label fx:id="docCountLabel" layoutX="9.0" layoutY="0.79998779296875" prefHeight="18.0" prefWidth="150.0" text="Documents Matched: " visible="false" AnchorPane.leftAnchor="9.0" AnchorPane.topAnchor="10.0" />
</children>
</AnchorPane>
<AnchorPane fx:id="docCountAnchorPane1" blendMode="SRC_ATOP" layoutX="420.0" layoutY="528.0" prefHeight="42.0" prefWidth="168.0" visible="false" AnchorPane.bottomAnchor="120.0" AnchorPane.leftAnchor="450.0">
<children>
<Label fx:id="docCountLabel1" layoutX="9.0" layoutY="0.79998779296875" prefHeight="18.0" prefWidth="150.0" AnchorPane.leftAnchor="9.0" AnchorPane.topAnchor="10.0" />
</children>
</AnchorPane>
</children>
</AnchorPane>
</children>
Expand Down