Skip to content

Commit 4b79f42

Browse files
authored
Merge pull request #2 from Infosys/DocCount
Doc count
2 parents 14e4fcd + 9191aab commit 4b79f42

File tree

4 files changed

+68
-6
lines changed

4 files changed

+68
-6
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# CouchbaseLiteTester
2-
###### version 1.5
2+
###### version 1.6
33
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.
44

55
## Getting Started
@@ -88,6 +88,9 @@ mvn compile package
8888
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.
8989

9090
## Features
91+
###### version 1.6
92+
* Minor enhancements and bug fixes
93+
* Search displays matched doc counts
9194
###### version 1.5
9295
* Support to search documents (Advance Search) based on multiple keywords
9396
###### version 1.4

src/main/java/io/amrishraje/cblitetester/AdvanceSearchController.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
package io.amrishraje.cblitetester;
22

3+
import javafx.animation.KeyFrame;
4+
import javafx.animation.Timeline;
5+
import javafx.application.Platform;
36
import javafx.collections.transformation.FilteredList;
47
import javafx.event.ActionEvent;
58
import javafx.scene.control.*;
69
import javafx.stage.Stage;
10+
import javafx.util.Duration;
711
import org.ahocorasick.trie.Emit;
812
import org.ahocorasick.trie.Trie;
913
import org.slf4j.Logger;
@@ -12,6 +16,7 @@
1216
import java.util.Arrays;
1317
import java.util.Collection;
1418
import java.util.Map;
19+
import java.util.concurrent.atomic.AtomicInteger;
1520

1621
public class AdvanceSearchController {
1722

@@ -38,9 +43,26 @@ public void searchDocuments(ActionEvent event) {
3843
filteredData = mainController.getFilteredData();
3944
String lowerCaseFilter = searchTextBox.getText();
4045
String[] searchList = lowerCaseFilter.split(";");
46+
AtomicInteger docCount = new AtomicInteger();
47+
Timeline timeline = new Timeline(new KeyFrame(Duration.seconds(5), x -> mainController.docCountAnchorPane.setVisible(false)));
4148
filteredData.setPredicate(tableData -> {
42-
return containsWordsAhoCorasick(tableData.getValue(), searchList, matchWholeWords.isSelected());
49+
if (containsWordsAhoCorasick(tableData.getValue(), searchList, matchWholeWords.isSelected())) {
50+
docCount.getAndIncrement();
51+
return true;
52+
} else return false;
4353
});
54+
mainController.docCountLabel.setText(docCount.toString() + " documents matched");
55+
mainController.docCountLabel.setVisible(true);
56+
mainController.docCountLabel.setStyle("-fx-background: rgba(30,30,30);\n" +
57+
" -fx-text-fill: white;\n" +
58+
" -fx-background-color: rgba(30,30,30,0.8);\n" +
59+
" -fx-background-radius: 6px;\n" +
60+
" -fx-background-insets: 0;\n" +
61+
" -fx-padding: 0.667em 0.75em 0.667em 0.75em; /* 10px */\n" +
62+
" -fx-effect: dropshadow( three-pass-box , rgba(0,0,0,0.5) , 10, 0.0 , 0 , 3 );\n" +
63+
" -fx-font-size: 0.85em;");
64+
mainController.docCountAnchorPane.setVisible(true);
65+
Platform.runLater(timeline::play);
4466
Stage stage = (Stage) cancelButton.getScene().getWindow();
4567
stage.close();
4668
}

src/main/java/io/amrishraje/cblitetester/MainController.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
import com.couchbase.lite.CouchbaseLiteException;
1919
import com.google.gson.Gson;
2020
import com.google.gson.JsonObject;
21+
import javafx.animation.KeyFrame;
22+
import javafx.animation.Timeline;
2123
import javafx.application.Platform;
2224
import javafx.beans.property.SimpleStringProperty;
2325
import javafx.beans.value.ObservableValue;
@@ -40,6 +42,7 @@
4042
import javafx.scene.layout.AnchorPane;
4143
import javafx.stage.Stage;
4244
import javafx.util.Callback;
45+
import javafx.util.Duration;
4346
import okhttp3.OkHttpClient;
4447
import okhttp3.Request;
4548
import okhttp3.Response;
@@ -58,9 +61,11 @@
5861
import java.net.URL;
5962
import java.util.List;
6063
import java.util.*;
64+
import java.util.concurrent.atomic.AtomicInteger;
6165

6266
public class MainController implements Initializable {
6367
private static final Logger logger = LoggerFactory.getLogger(MainController.class);
68+
private final String version = "v1.6";
6469
public Button syncButton;
6570
public TextField userText;
6671
public PasswordField pwdText;
@@ -86,6 +91,8 @@ public class MainController implements Initializable {
8691
public ProgressBar progressBar;
8792
public Label progressText;
8893
public AnchorPane progressAnchorPane;
94+
public Label docCountLabel;
95+
public AnchorPane docCountAnchorPane;
8996
Properties properties = new Properties();
9097
Properties defaults = new Properties();
9198
@FXML
@@ -196,6 +203,8 @@ public void initialize(URL url, ResourceBundle resourceBundle) {
196203
}
197204
});
198205
replicationMode.setItems(FXCollections.observableArrayList("Pull", "Push", "Pull and Push"));
206+
//Setup About
207+
about.setText("CBLite Tester " + version + " by Amrish Raje" );
199208
}
200209

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

502513
if (tableData.getKey().toLowerCase().contains(lowerCaseFilter)) {
514+
docCount.getAndIncrement();
503515
return true; // Filter matches key.
504516
}
505517
return false; // Does not match.
506518
});
519+
docCountLabel.setText(docCount.toString() + " documents matched");
520+
docCountLabel.setVisible(true);
521+
docCountLabel.setStyle("-fx-background: rgba(30,30,30);\n" +
522+
" -fx-text-fill: white;\n" +
523+
" -fx-background-color: rgba(30,30,30,0.8);\n" +
524+
" -fx-background-radius: 6px;\n" +
525+
" -fx-background-insets: 0;\n" +
526+
" -fx-padding: 0.667em 0.75em 0.667em 0.75em; /* 10px */\n" +
527+
" -fx-effect: dropshadow( three-pass-box , rgba(0,0,0,0.5) , 10, 0.0 , 0 , 3 );\n" +
528+
" -fx-font-size: 0.85em;");
529+
docCountAnchorPane.setVisible(true);
530+
Platform.runLater(timeline::play);
507531
});
508532
dataTable.getColumns().setAll(docId, docValue);
509533
docId.setEditable(false);

src/main/resources/io/amrishraje/cblitetester/CBLiteScreen.fxml

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@
4141
<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">
4242
<tooltip>
4343
<Tooltip text="Sync with Sync Gateway" />
44-
</tooltip></Button>
44+
</tooltip>
45+
</Button>
4546
<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">
4647
<tooltip>
4748
<Tooltip text="Stop sync if continuous sync is running" />
@@ -50,19 +51,21 @@
5051
<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">
5152
<tooltip>
5253
<Tooltip text="Initialize DB and sync" />
53-
</tooltip></Button>
54+
</tooltip>
55+
</Button>
5456
<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">
5557
<tooltip>
5658
<Tooltip text="Delete local CBLite DB file" />
57-
</tooltip></Button>
59+
</tooltip>
60+
</Button>
5861
<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" />
5962
<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" />
6063
<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" />
6164
<Label fx:id="tableStatusLabel" maxWidth="300.0" prefHeight="30.0" prefWidth="200.0" textFill="WHITE" AnchorPane.leftAnchor="20.0" AnchorPane.topAnchor="380.0" />
6265
<Label layoutX="21.0" layoutY="211.0" text="Continuous Sync" textFill="WHITE" AnchorPane.leftAnchor="20.0" AnchorPane.topAnchor="165.0" />
6366
<ToggleSwitch fx:id="continuousToggle" layoutX="99.0" layoutY="211.0" onMouseClicked="#toggleContinuousMode" textFill="WHITE" AnchorPane.leftAnchor="110.0" AnchorPane.topAnchor="165.0" />
6467
<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" />
65-
<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" />
68+
<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" />
6669
<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" />
6770
</children>
6871
</AnchorPane>
@@ -97,6 +100,16 @@
97100
<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" />
98101
</children>
99102
</AnchorPane>
103+
<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">
104+
<children>
105+
<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" />
106+
</children>
107+
</AnchorPane>
108+
<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">
109+
<children>
110+
<Label fx:id="docCountLabel1" layoutX="9.0" layoutY="0.79998779296875" prefHeight="18.0" prefWidth="150.0" AnchorPane.leftAnchor="9.0" AnchorPane.topAnchor="10.0" />
111+
</children>
112+
</AnchorPane>
100113
</children>
101114
</AnchorPane>
102115
</children>

0 commit comments

Comments
 (0)