Skip to content

Commit

Permalink
Merge 59d9a4a into 514e894
Browse files Browse the repository at this point in the history
  • Loading branch information
JeridiOmar authored May 11, 2023
2 parents 514e894 + 59d9a4a commit b07d376
Show file tree
Hide file tree
Showing 9 changed files with 110 additions and 87 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,14 @@ private void showFindDialog(InlineCssTextArea richTextArea) {
matchCountLabel.textProperty().bind(Bindings.createStringBinding(() -> {
String s = "";
int resultCount = this.searchResult.getResultCount();
int currentIndex = this.searchResult.getCurrentSearchIndex();
if (currentIndex >= 0) {
s += "#" + (currentIndex + 1) + "/";
}
s += resultCount + " ";
s += Configuration.langBundle.getString("matches_found") + ".";
s += Configuration.langBundle.getString("matches_found");
return s;
}, this.searchResult.resultCountProperty()));
}, this.searchResult.resultCountProperty(),this.searchResult.getCurrentSearchIndexProperty()));
} else {
this.searchResult.resetSearch();
matchCountLabel.setVisible(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@
import application.configuration.AppSettings;
import application.configuration.Configuration;
import components.interviewPanel.search.ButtonSearchType;
import components.interviewPanel.search.SearchButtonHandler;
import components.modelisationSpace.appCommand.ScrollPaneCommandFactory;
import components.modelisationSpace.hooks.ModelisationSpaceHook;
import components.modelisationSpace.hooks.ModelisationSpaceHookNotifier;
import components.modelisationSpace.moment.controllers.RootMomentController;
import components.modelisationSpace.search.MomentSearchHandler;
import javafx.beans.binding.Bindings;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.embed.swing.SwingFXUtils;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
Expand All @@ -20,15 +18,12 @@
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Node;
import javafx.scene.SnapshotParameters;
import javafx.scene.control.*;
import javafx.scene.image.WritableImage;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.scene.input.TransferMode;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.transform.Scale;
import javafx.stage.Modality;
import models.RootMoment;
Expand All @@ -40,8 +35,6 @@
import utils.dragAndDrop.DragStore;
import utils.scrollOnDragPane.ScrollOnDragPane;

import javax.imageio.ImageIO;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.Objects;
Expand Down Expand Up @@ -196,7 +189,7 @@ private void showFindDialog() {
Dialog<String> dialog = new Dialog<>();
dialog.initModality(Modality.WINDOW_MODAL);
dialog.getDialogPane().getStylesheets().add(Objects.requireNonNull(getClass().getResource("/css/application.css")).toExternalForm());
dialog.getDialogPane().setPrefWidth(750);
dialog.getDialogPane().setPrefWidth(1000);
dialog.setResizable(true);
dialog.setTitle(Configuration.langBundle.getString("find_moment"));
dialog.setHeaderText(Configuration.langBundle.getString("find_moment"));
Expand Down Expand Up @@ -244,27 +237,27 @@ private void showFindDialog() {
}
});

RadioButton property_name_choice = new RadioButton(Configuration.langBundle.getString("property_name"));
property_name_choice.setToggleGroup(toggleGroup);
property_name_choice.setOnAction(e -> {
if (property_name_choice.isSelected()) {
this.searchProperties.setChoicePropertyName();
RadioButton property_choice = new RadioButton(Configuration.langBundle.getString("property_name"));
property_choice.setToggleGroup(toggleGroup);
property_choice.setOnAction(e -> {
if (property_choice.isSelected()) {
this.searchProperties.setChoiceProperty();
if (!findTextField.getText().isEmpty()) {
this.launchSearch(findTextField.getText(), matchCountLabel);
}
}
});

RadioButton property_value_choice = new RadioButton(Configuration.langBundle.getString("property_value"));
property_value_choice.setToggleGroup(toggleGroup);
property_value_choice.setOnAction(e -> {
if (property_value_choice.isSelected()) {
this.searchProperties.setChoicePropertyValue();
if (!findTextField.getText().isEmpty()) {
this.launchSearch(findTextField.getText(), matchCountLabel);
}
}
});
// RadioButton property_value_choice = new RadioButton(Configuration.langBundle.getString("property_value"));
// property_value_choice.setToggleGroup(toggleGroup);
// property_value_choice.setOnAction(e -> {
// if (property_value_choice.isSelected()) {
// this.searchProperties.setChoicePropertyValue();
// if (!findTextField.getText().isEmpty()) {
// this.launchSearch(findTextField.getText(), matchCountLabel);
// }
// }
// });


RadioButton all_choice = new RadioButton(Configuration.langBundle.getString("all"));
Expand All @@ -277,35 +270,37 @@ private void showFindDialog() {
}
}
});

all_choice.setStyle("-fx-font-weight: bold;");

Label choicesLabel = new Label(Configuration.langBundle.getString("search_in"));
// Create an HBox container and add the RadioButtons to it
HBox choicesHbox = new HBox(10); // 10 is the spacing between the controls
choicesHbox.setPadding(new Insets(10)); // Set some padding around the container
choicesHbox.getChildren().
addAll(choicesLabel, moment_name_choice, category_name_choice, property_name_choice, property_value_choice, all_choice);
addAll(choicesLabel, moment_name_choice, category_name_choice, property_choice, all_choice);
// Set up the grid pane
HBox gridPane = new HBox();
gridPane.setSpacing(15);
gridPane.setAlignment(Pos.BASELINE_CENTER);
gridPane.getChildren().add(findLabel);
gridPane.getChildren().add(findTextField);
gridPane.getChildren().add(matchCountLabel);
gridPane.getChildren().
addAll(choicesLabel, all_choice, moment_name_choice, category_name_choice, property_choice);
//create vbox
VBox vBox = new VBox(20);
vBox.getChildren().add(choicesHbox);
vBox.getChildren().add(gridPane);
// VBox vBox = new VBox(20);
// vBox.getChildren().add(choicesHbox);
// vBox.getChildren().add(gridPane);

dialog.getDialogPane().setContent(vBox);
dialog.getDialogPane().setContent(gridPane);

Button findPreviousButton = (Button) dialog.getDialogPane().lookupButton(findPreviousButtonType);
Button findNextButton = (Button) dialog.getDialogPane().lookupButton(findNextButtonType);
Button closeButton = (Button) dialog.getDialogPane().lookupButton(closeButtonType);
//Init Buttons on disabled
findNextButton.setDisable(true);
findPreviousButton.setDisable(true);
moment_name_choice.fire();
all_choice.fire();

// handle search result label
findTextField.textProperty().addListener((obs, oldText, newText) -> {
Expand Down Expand Up @@ -361,10 +356,14 @@ private void launchSearch(String query, Label matchCountLabel) {
matchCountLabel.textProperty().bind(Bindings.createStringBinding(() -> {
String s = "";
int resultCount = this.searchResult.getResultCount();
int currentIndex = this.searchResult.getCurrentSearchIndex();
if (currentIndex >= 0) {
s += "#" + (currentIndex + 1) + "/";
}
s += resultCount + " ";
s += Configuration.langBundle.getString("matches_found") + ".";
s += Configuration.langBundle.getString("matches_found");
return s;
}, this.searchResult.resultCountProperty()));
}, this.searchResult.resultCountProperty(),this.searchResult.getCurrentSearchIndexProperty()));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,14 @@
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.util.Duration;
import models.ConcreteCategory;
import models.Moment;
import models.SchemaCategory;
import models.SchemaProperty;
import models.*;
import utils.GlobalVariables;
import utils.ResourceLoader;
import utils.autoSuggestion.strategies.SuggestionStrategy;
import utils.autoSuggestion.strategies.SuggestionStrategyCategory;

import java.net.URL;
import java.util.HashMap;
import java.util.ResourceBundle;

public class SchemaTreeCategoryController extends SchemaTreeCellController {
Expand Down Expand Up @@ -64,8 +62,20 @@ public void initialize(URL url, ResourceBundle resourceBundle) {
this.navigationBox.getChildren().add(this.rightNavigation);
this.navigationBox.setPadding(new Insets(7.5, 0, 0, 0));

this.complementaryInfoTooltip = new Tooltip(Configuration.langBundle.getString("complementary_info_toolbox"));
// this.complementaryInfoTooltip = new Tooltip("Navigate to nb : "+(Math.floorMod(this.currentNavigationIndex - 1, this.category.getCurrentInterviewUses())+1));
//this.complementaryInfoTooltip = new Tooltip(Configuration.langBundle.getString("complementary_info_toolbox"));
this.complementaryInfoTooltip = new Tooltip();
this.complementaryInfoTooltip.textProperty().bind(Bindings.createStringBinding(() -> {
StringBuilder s = new StringBuilder();
HashMap<Interview, Integer> usesMap = this.category.getUsesMap();
for (Interview interview : usesMap.keySet()) {
if (usesMap.get(interview) > 0) {
s.append(usesMap.get(interview)).append(" ").append(Configuration.langBundle.getString(usesMap.get(interview) == 1 ? "use" : "uses")).append(" -> ").append(interview.getTitle()).append("\n");
}
}
return s.toString();

}, this.category.currentInterviewUsesProperty()));
// this.complementaryInfoTooltip = new Tooltip("Navigate to nb : "+(Math.floorMod(this.currentNavigationIndex - 1, this.category.getCurrentInterviewUses())+1));

complementaryInfoTooltip.setShowDelay(new Duration(0));
this.complementaryInfo.setTooltip(complementaryInfoTooltip);
Expand Down Expand Up @@ -268,7 +278,7 @@ private void setupNavigationToolTip() {
String s = "";
int currentInterviewUses = this.category.getCurrentInterviewUses();
if (currentInterviewUses > 0) {
s = Configuration.langBundle.getString("navigation_tooltip") + (this.calculateLeftIndex(this.currentNavigationIndex.get(), this.category.getCurrentInterviewUses()) + 1);
s = Configuration.langBundle.getString("navigation_tooltip_navigate") + " #" + (this.calculateLeftIndex(this.currentNavigationIndex.get(), this.category.getCurrentInterviewUses()) + 1 + " " + Configuration.langBundle.getString("navigation_tooltip_interview"));
}
return s;

Expand All @@ -277,7 +287,7 @@ private void setupNavigationToolTip() {
String s = "";
int currentInterviewUses = this.category.getCurrentInterviewUses();
if (currentInterviewUses > 0) {
s = Configuration.langBundle.getString("navigation_tooltip") + (this.calculateRightIndex(this.currentNavigationIndex.get(), this.category.getCurrentInterviewUses()) + 1);
s = Configuration.langBundle.getString("navigation_tooltip_navigate") + " #" + (this.calculateRightIndex(this.currentNavigationIndex.get(), this.category.getCurrentInterviewUses()) + 1) + " " + Configuration.langBundle.getString("navigation_tooltip_interview");
}
return s;

Expand Down
4 changes: 4 additions & 0 deletions src/main/java/models/SchemaCategory.java
Original file line number Diff line number Diff line change
Expand Up @@ -205,4 +205,8 @@ public void removeFromControllers(ConcreteCategoryController Controller) {
this.nbUsesInInterviews.putIfAbsent(t1, 0);
this.currentInterviewUses.set(this.nbUsesInInterviews.get(t1));
};

public HashMap<Interview, Integer> getUsesMap() {
return this.nbUsesInInterviews;
}
}
34 changes: 19 additions & 15 deletions src/main/java/utils/MomentSearch.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Locale;

public class MomentSearch {
private String currentSearchWord;
Expand Down Expand Up @@ -49,19 +50,20 @@ public void resetSearch() {
}

public void countOccurrences(String search, SearchProperties searchProperties) {
search=search.trim().toUpperCase(Locale.ROOT);
this.currentSearchWord = search;
this.resetSearch();
int count = 0;
int lastIndex = 0;
HashMap<Moment, Node> interviewNodes = GlobalVariables.nodeViews.getCurrentInterviewNodes().getInterviewNodesMap();
search=search.trim();
search = search.trim();
//by moment Name search
if (searchProperties.isMoment_name_choice()) {
for (Moment moment : interviewNodes.keySet()) {
if(this.searchResult.contains(interviewNodes.get(moment))){
if (this.searchResult.contains(interviewNodes.get(moment))) {
continue;
}
if (moment.getName().contains(search)) {
if (moment.getName().trim().toUpperCase(Locale.ROOT).contains(search)) {
this.searchResult.add(interviewNodes.get(moment));
count++;
}
Expand All @@ -70,11 +72,11 @@ public void countOccurrences(String search, SearchProperties searchProperties) {
//By category name
if (searchProperties.isCategory_name_choice()) {
for (Moment moment : interviewNodes.keySet()) {
if(this.searchResult.contains(interviewNodes.get(moment))){
if (this.searchResult.contains(interviewNodes.get(moment))) {
continue;
}
for (ConcreteCategory category : moment.getCategories()) {
if ((!this.searchResult.contains(interviewNodes.get(moment))) && category.getSchemaCategory().getName().contains(search)) {
if ((!this.searchResult.contains(interviewNodes.get(moment))) && category.getSchemaCategory().getName().trim().toUpperCase(Locale.ROOT).contains(search)) {
this.searchResult.add(interviewNodes.get(moment));
count++;
break;//because we return all moment that have atleast one category with matching name
Expand All @@ -84,14 +86,14 @@ public void countOccurrences(String search, SearchProperties searchProperties) {
}

//By property names
if (searchProperties.isProperty_name_choice()) {
if (searchProperties.isProperty_choice()) {
for (Moment moment : interviewNodes.keySet()) {
if(this.searchResult.contains(interviewNodes.get(moment))){
if (this.searchResult.contains(interviewNodes.get(moment))) {
continue;
}
for (ConcreteCategory category : moment.getCategories()) {
for (ConcreteProperty property : category.propertiesProperty()) {
if ((!this.searchResult.contains(interviewNodes.get(moment))) && property.getName().contains(search)) {
if ((!this.searchResult.contains(interviewNodes.get(moment))) && property.getName().trim().toUpperCase(Locale.ROOT).contains(search)) {
this.searchResult.add(interviewNodes.get(moment));
count++;
break;//because we return all moment that have atleast one category with matching name
Expand All @@ -100,17 +102,14 @@ public void countOccurrences(String search, SearchProperties searchProperties) {

}
}
}

//By property Values
if (searchProperties.isProperty_value_choice()) {
//By property Values
for (Moment moment : interviewNodes.keySet()) {
if(this.searchResult.contains(interviewNodes.get(moment))){
if (this.searchResult.contains(interviewNodes.get(moment))) {
continue;
}
for (ConcreteCategory category : moment.getCategories()) {
for (ConcreteProperty property : category.propertiesProperty()) {
if ((!this.searchResult.contains(interviewNodes.get(moment))) && property.getValue().contains(search)) {
if ((!this.searchResult.contains(interviewNodes.get(moment))) && property.getValue().trim().toUpperCase(Locale.ROOT).contains(search)) {
this.searchResult.add(interviewNodes.get(moment));
count++;
break;//because we return all moment that have atleast one category with matching name
Expand Down Expand Up @@ -155,5 +154,10 @@ public boolean hasPrevious() {
public boolean isEmpty() {
return this.resultCount.get() == 0;
}

public int getCurrentSearchIndex(){
return this.resultPosition.get();
}
public SimpleIntegerProperty getCurrentSearchIndexProperty(){
return this.resultPosition;
}
}
Loading

0 comments on commit b07d376

Please sign in to comment.