Skip to content

Commit

Permalink
Add remove lines functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
LevelUp8 committed May 8, 2022
1 parent a748760 commit 6348301
Show file tree
Hide file tree
Showing 19 changed files with 208 additions and 135 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.kagu.edit</groupId>
<artifactId>jKagu</artifactId>
<version>5.0.0</version>
<version>6.0.0</version>
<name>jKagu</name>

<properties>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/kagu/edit/jkagu/HelloApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class HelloApplication extends Application {
public static final String APP_FXML_FILE_PATH = "hello-view.fxml";
public static final String APP_CSS_FILE_PATH = "style.css";
public static final String APP_CSS_DEFAULT_TEXT_FILE_PATH = "default-text.css";
public static final String APP_TITLE = "JKagu v5.0.0";
public static final String APP_TITLE = "JKagu v6.0.0";

public static HelloApplication helloApplication;
public HelloApplication()
Expand Down
19 changes: 8 additions & 11 deletions src/main/java/com/kagu/edit/jkagu/HelloController.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ public class HelloController implements Serializable, Initializable {
@FXML
public Button searchButton;

//-- Search single line functionality

//-- Search functionality

@FXML
public RadioButton useSelectedLines;
public ChoiceBox<String> selectedStrategyBox;

@FXML
public TextField searchField;
Expand All @@ -37,8 +39,6 @@ public class HelloController implements Serializable, Initializable {
public HBox searchFieldContainer;

//--- Search functionality query
@FXML
public RadioButton useAdvancedSelect;

@FXML
public HBox searchComboBoxContainer;
Expand All @@ -50,9 +50,6 @@ public class HelloController implements Serializable, Initializable {
@FXML
public HBox searchFromUntilContainer;

@FXML
public RadioButton useSelectedLinesMultiline;

@FXML
public TextField searchFieldFrom;

Expand Down Expand Up @@ -175,10 +172,10 @@ public void initialize(URL location, ResourceBundle resources) {

configurationList.add(new SwitchReplaceTemplateConfig(findReplaceBox, templateIncrementBox, findAndReplace, templateCounter, statusMessage, replaceWhere, caseSensitive));

SingleLineSearchContext singleLineSearchContext = new SingleLineSearchContext(useSelectedLines, searchField, searchFieldContainer);
MuliLineSearchContext muliLineSearchContext = new MuliLineSearchContext(useSelectedLinesMultiline, searchFieldFrom, searchFieldUntil, searchFromUntilContainer);
QuerySearchContext querySearchContext = new QuerySearchContext(useAdvancedSelect, searchComboBoxContainer, searchComboBox);
configurationList.add(new SearchContentConfig(singleLineSearchContext, querySearchContext, muliLineSearchContext, searchButton, observableList, initialList, searchField, statusMessage, caseSensitiveSearch));
SingleLineSearchContext singleLineSearchContext = new SingleLineSearchContext(searchField, searchFieldContainer);
MuliLineSearchContext muliLineSearchContext = new MuliLineSearchContext(searchFieldFrom, searchFieldUntil, searchFromUntilContainer);
QuerySearchContext querySearchContext = new QuerySearchContext(searchComboBoxContainer, searchComboBox);
configurationList.add(new SearchContentConfig(selectedStrategyBox, singleLineSearchContext, querySearchContext, muliLineSearchContext, searchButton, observableList, initialList, searchField, statusMessage, caseSensitiveSearch));

configurationList.add(new OpenFileConfig(progressBar, statusMessage, appendFile, listView, observableList, initialList));

Expand Down
54 changes: 27 additions & 27 deletions src/main/java/com/kagu/edit/jkagu/conf/HelpConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,34 +25,34 @@ public HelpConfig(MenuItem about, Stage primaryStage) {

@Override
public void configure() {
about.setOnAction( actionEvent ->
about.setOnAction(actionEvent ->
{
aboutLoader = new FXMLLoader(HelloApplication.class.getResource("help-popup.fxml"));
Scene scene = null;
try {
scene = new Scene(aboutLoader.load(), 300, 200);
} catch (IOException e) {
e.printStackTrace();
}
String cssFile = HelloApplication.class.getResource(APP_CSS_FILE_PATH).toString();
scene.getStylesheets().add(cssFile);

String selectedTheme = ViewThemeConfig.getSelectedTheme();
if ("DARK".equals(selectedTheme)) {
String cssFileTheme = HelloApplication.class.getResource("dark-theme.css").toString();
scene.getStylesheets().add(cssFileTheme);
} else if ("DEFAULT".equals(selectedTheme)) {
String cssFileTheme = HelloApplication.class.getResource("dark-theme.css").toString();
scene.getStylesheets().remove(cssFileTheme);
} else {
throw new IllegalStateException("The theme is not recognized: " + selectedTheme);
}

final Stage dialog = new Stage();
dialog.initModality(Modality.APPLICATION_MODAL);
dialog.initOwner(primaryStage);
dialog.setScene(scene);
dialog.show();
aboutLoader = new FXMLLoader(HelloApplication.class.getResource("help-popup.fxml"));
Scene scene = null;
try {
scene = new Scene(aboutLoader.load(), 300, 200);
} catch (IOException e) {
e.printStackTrace();
}
String cssFile = HelloApplication.class.getResource(APP_CSS_FILE_PATH).toString();
scene.getStylesheets().add(cssFile);

String selectedTheme = ViewThemeConfig.getSelectedTheme();
if ("DARK".equals(selectedTheme)) {
String cssFileTheme = HelloApplication.class.getResource("dark-theme.css").toString();
scene.getStylesheets().add(cssFileTheme);
} else if ("DEFAULT".equals(selectedTheme)) {
String cssFileTheme = HelloApplication.class.getResource("dark-theme.css").toString();
scene.getStylesheets().remove(cssFileTheme);
} else {
throw new IllegalStateException("The theme is not recognized: " + selectedTheme);
}

final Stage dialog = new Stage();
dialog.initModality(Modality.APPLICATION_MODAL);
dialog.initOwner(primaryStage);
dialog.setScene(scene);
dialog.show();
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,4 @@ private void saveTextToFile(String content, File file) {
}
}


}
117 changes: 69 additions & 48 deletions src/main/java/com/kagu/edit/jkagu/conf/SearchContentConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
import com.kagu.edit.jkagu.conf.model.QuerySearchContext;
import com.kagu.edit.jkagu.conf.model.Row;
import com.kagu.edit.jkagu.conf.model.SingleLineSearchContext;
import com.kagu.edit.jkagu.engine.actions.FilterByFromUntilString;
import com.kagu.edit.jkagu.engine.actions.FilterByQuery;
import com.kagu.edit.jkagu.engine.actions.FilterByString;
import com.kagu.edit.jkagu.engine.actions.*;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.control.*;
import javafx.scene.layout.HBox;
Expand All @@ -16,11 +15,6 @@

public class SearchContentConfig implements ComponentConf {

public static final String USE_SELECTED_LINES = "useSelectedLines";
public static final String USE_ADVANCED_SELECT = "useAdvancedSelect";
public static final String USE_SELECTED_LINES_MULTILINE = "useSelectedLinesMultiline";
private final RadioButton useSelectedLines;
private final ToggleGroup toggleGroup = new ToggleGroup();
private final Button searchButton;

private final ObservableList<Row> observableList;
Expand All @@ -38,8 +32,24 @@ public class SearchContentConfig implements ComponentConf {
private final HBox searchFromUntilContainer;
private final HBox searchComboBoxContainer;

private ChoiceBox<String> selectedStrategyBox;

public SearchContentConfig(SingleLineSearchContext singleLineSearchContext,
private static final String SELECT_LINE = "Select Line";
private static final String ADVANCED_SELECT = "Advanced Select";
private static final String SELECT_LINES = "Select Lines";
private static final String REMOVE_LINES = "Remove Lines";

private String currentSelected;

// string array
private static final String st[] = { SELECT_LINE,
ADVANCED_SELECT,
SELECT_LINES,
REMOVE_LINES};


public SearchContentConfig(ChoiceBox<String> selectedStrategyBox,
SingleLineSearchContext singleLineSearchContext,
QuerySearchContext querySearchContext,
MuliLineSearchContext muliLineSearchContext,
Button searchButton,
Expand All @@ -49,18 +59,14 @@ public SearchContentConfig(SingleLineSearchContext singleLineSearchContext,
Label statusMessage,
CheckBox caseSensitiveSearch) {

muliLineSearchContext.useSelectedLinesMultiline().setToggleGroup(toggleGroup);
singleLineSearchContext.useSelectedLines().setToggleGroup(toggleGroup);
querySearchContext.useAdvancedSelect().setToggleGroup(toggleGroup);
this.selectedStrategyBox = selectedStrategyBox;

this.searchButton = searchButton;
this.observableList = observableList;
this.initialList = initialList;
this.searchField = searchField;
this.statusMessage = statusMessage;

this.useSelectedLines = singleLineSearchContext.useSelectedLines();

this.caseSensitiveSearch = caseSensitiveSearch;

this.searchFieldFrom = muliLineSearchContext.searchFieldFrom();
Expand All @@ -82,45 +88,48 @@ public void configure() {

searchComboBox.setEditable(true);
searchComboBox.getItems().addAll(
"select row where row has 'A' 'B' 'C' --row must have this 3 words",
"select row+2 where row has 'AAA' --row + 2 rows below that have AAA",
"remove row where row has 'A' 'B' 'C' --row that does not have all 3 words",
"select row where row start 'AAA' --trimmed row must start with AAA",
"remove row where row end 'AAA' --trimmed row must not end with AAA",
"select row unique --get the unique rows");


toggleGroup.selectedToggleProperty()
.addListener((observable, oldVal, newVal) -> {
// System.out.println(newVal + " was selected");

Toggle t = toggleGroup.getSelectedToggle();
RadioButton rb = (RadioButton) t;

String radioButtonID = rb.getId();
switch (radioButtonID) {
case USE_SELECTED_LINES -> setupSingleLineSelect();
case USE_ADVANCED_SELECT -> setupQuerySelect();
case USE_SELECTED_LINES_MULTILINE -> setupMultiLineSelect();
default -> throw new UnsupportedOperationException("Not supported logic for: " + radioButtonID);
}
});
"select row where row has 'A' 'B' 'C' --row must have this 3 words",
"select row+2 where row has 'AAA' --row + 2 rows below that have AAA",
"remove row where row has 'A' 'B' 'C' --row that does not have all 3 words",
"select row where row start 'AAA' --trimmed row must start with AAA",
"remove row where row end 'AAA' --trimmed row must not end with AAA",
"select row unique --get the unique rows");


selectedStrategyBox.setItems(FXCollections.observableArrayList(st));

selectedStrategyBox.setValue(st[0]);
currentSelected = st[0];
setupSingleLineSelect();
// add a listener
selectedStrategyBox.getSelectionModel().selectedIndexProperty().addListener((ov, value, newValue) ->
{
// set the text for the label to the selected item
//l1.setText(st[new_value.intValue()] + " selected");
currentSelected = st[newValue.intValue()];

switch (currentSelected) {
case SELECT_LINE -> setupSingleLineSelect();
case ADVANCED_SELECT -> setupQuerySelect();
case SELECT_LINES, REMOVE_LINES -> setupMultiLine();
default -> throw new UnsupportedOperationException("Not supported logic for: " + currentSelected);
}
});



this.searchButton.setOnAction(e -> {
Toggle t = toggleGroup.getSelectedToggle();
RadioButton rb = (RadioButton) t;

String radioButtonID = rb.getId();
switch (radioButtonID) {
case USE_SELECTED_LINES -> singleLineSearch();
case USE_ADVANCED_SELECT -> querySearch();
case USE_SELECTED_LINES_MULTILINE -> multiLineSearch();
default -> throw new UnsupportedOperationException("Not supported logic for: " + radioButtonID);
switch (currentSelected) {
case SELECT_LINE -> singleLineSearch();
case ADVANCED_SELECT -> querySearch();
case SELECT_LINES -> multiLineSearch();
case REMOVE_LINES -> multilineRemove();
default -> throw new UnsupportedOperationException("Not supported logic for: " + currentSelected);
}

});

toggleGroup.selectToggle(useSelectedLines);
//toggleGroup.selectToggle(useSelectedLines);
}

private void setupQuerySelect() {
Expand All @@ -133,7 +142,7 @@ private void setupQuerySelect() {
this.caseSensitiveSearch.setSelected(true);
}

private void setupMultiLineSelect() {
private void setupMultiLine() {
this.caseSensitiveSearch.setDisable(true);
this.caseSensitiveSearch.setSelected(true);

Expand Down Expand Up @@ -165,6 +174,18 @@ private void multiLineSearch() {
}
}

private void multilineRemove() {
String fromText = searchFieldFrom.getText();
String untilText = searchFieldUntil.getText();
if (Utils.isStringNOTEmpty(fromText) && Utils.isStringNOTEmpty(untilText))
{
RemoveByFromUntilString removeByFromUntilString = new RemoveByFromUntilString(this.observableList, this.initialList, fromText, untilText, this.statusMessage);
removeByFromUntilString.execute();
} else {
this.statusMessage.setText("The remove fields are empty. Remove will not be performed!");
}
}

private void querySearch() {
//String query = searchField.getText();
String query = searchComboBox.getEditor().getText();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package com.kagu.edit.jkagu.conf.model;

import javafx.scene.control.RadioButton;

import javafx.scene.control.TextField;
import javafx.scene.layout.HBox;

public record MuliLineSearchContext(RadioButton useSelectedLinesMultiline,
TextField searchFieldFrom,
public record MuliLineSearchContext(TextField searchFieldFrom,
TextField searchFieldUntil,
HBox searchFromUntilContainer) {
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.kagu.edit.jkagu.conf.model;

import javafx.scene.control.ComboBox;
import javafx.scene.control.RadioButton;
import javafx.scene.layout.HBox;

public record QuerySearchContext (RadioButton useAdvancedSelect, HBox searchComboBoxContainer, ComboBox<String> searchComboBox) {}
public record QuerySearchContext (HBox searchComboBoxContainer, ComboBox<String> searchComboBox) {}
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package com.kagu.edit.jkagu.conf.model;

import javafx.scene.control.RadioButton;
import javafx.scene.control.TextField;
import javafx.scene.layout.HBox;

public record SingleLineSearchContext(RadioButton useSelectedLines,
TextField searchField,
public record SingleLineSearchContext(TextField searchField,
HBox searchFieldContainer) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,15 @@ public abstract class CaseSensitiveCommand extends Command {

/**
* If CaseSensitiveCommand then executeCaseSensitive() and executeCaseInsensitive() must be implemented
*
* @return
*/
@Override
public final boolean execute() {
if (caseSensitive.isSelected())
{
return executeCaseSensitive();
}
else
{
return executeCaseInsensitive();
if (caseSensitive.isSelected()) {
return executeCaseSensitive();
} else {
return executeCaseInsensitive();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,11 @@ public EditOneRow(ObservableList<Row> observableList, Row selectedRow, TextArea
@Override
public boolean execute() {

Long rowNumber = selectedRow.rowNumber();
Long rowNumber = selectedRow.rowNumber();
List<Row> replaced = observableList.stream()
.map(row -> {
if(rowNumber.equals(row.rowNumber()))
{
String forReplacement = editField.getText();
if (rowNumber.equals(row.rowNumber())) {
String forReplacement = editField.getText();
return new Row(row.rowNumber(), forReplacement);
}
return new Row(row.rowNumber(), row.content());
Expand Down
Loading

0 comments on commit 6348301

Please sign in to comment.