Skip to content

Commit

Permalink
feature: add filter and search to the validation result table
Browse files Browse the repository at this point in the history
- The validation results can now be searched and filtered by severity.
  • Loading branch information
Wandmalfarbe committed Aug 11, 2023
1 parent 53b978d commit 48ea841
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 2 deletions.
39 changes: 39 additions & 0 deletions src/main/java/de/pascalwagler/epubcheckfx/model/Severity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package de.pascalwagler.epubcheckfx.model;

import atlantafx.base.theme.Styles;
import de.pascalwagler.epubcheckfx.ui.Translatable;
import lombok.Getter;
import org.kordamp.ikonli.Ikon;
import org.kordamp.ikonli.material2.Material2OutlinedAL;

public enum Severity implements Translatable {


SUPPRESSED(com.adobe.epubcheck.messages.Severity.SUPPRESSED, Material2OutlinedAL.INFO, Styles.TEXT_SUBTLE, "severity.suppressed"),

USAGE(com.adobe.epubcheck.messages.Severity.USAGE, Material2OutlinedAL.INFO, Styles.TEXT_MUTED, "severity.usage"),

INFO(com.adobe.epubcheck.messages.Severity.INFO, Material2OutlinedAL.INFO, Styles.ACCENT, "severity.info"),

WARNING(com.adobe.epubcheck.messages.Severity.WARNING, Material2OutlinedAL.ERROR_OUTLINE, Styles.WARNING, "severity.warning"),

ERROR(com.adobe.epubcheck.messages.Severity.ERROR, Material2OutlinedAL.ERROR_OUTLINE, Styles.DANGER, "severity.error"),

FATAL(com.adobe.epubcheck.messages.Severity.FATAL, Material2OutlinedAL.ERROR_OUTLINE, Styles.DANGER, "severity.fatal");

Severity(com.adobe.epubcheck.messages.Severity ebubcheckSeverity, Ikon icon, String colorStyleClass, String i18nKey) {
this.ebubcheckSeverity = ebubcheckSeverity;
this.icon = icon;
this.colorStyleClass = colorStyleClass;
this.i18nKey = i18nKey;
}

@Getter
private final com.adobe.epubcheck.messages.Severity ebubcheckSeverity;
@Getter
private final Ikon icon;
@Getter
private final String colorStyleClass;
@Getter
private final String i18nKey;
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import javafx.beans.property.Property;
import javafx.beans.property.SimpleObjectProperty;
import javafx.collections.ObservableList;
import javafx.collections.transformation.FilteredList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.geometry.Insets;
Expand All @@ -33,6 +35,7 @@
import java.nio.file.Files;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.function.Predicate;

@Slf4j
public class MainContentController implements Initializable {
Expand All @@ -58,6 +61,11 @@ public class MainContentController implements Initializable {
@FXML
private ComboBox<EpubProfile> epubProfile;

@FXML
private TextField resultTableSearchFilter;
@FXML
private ComboBox<de.pascalwagler.epubcheckfx.model.Severity> resultTableSeverityFilter;

@FXML
private ComboBox<ExportFormat> exportFormat;

Expand All @@ -80,6 +88,8 @@ public class MainContentController implements Initializable {
@Setter
private InfoPanelController infoPanelController;

private FilteredList<CheckMessage> filteredErrorList;

private static final File tempDirectory = new File(System.getProperty("java.io.tmpdir"), "EPUBCheckFX");

@Override
Expand All @@ -95,14 +105,60 @@ public void initialize(URL location, ResourceBundle resourceBundle) {
throw new RuntimeException(e);
}
initValidationResultTable();
initSeverityFilter();
initExportFormat();
initEpubProfile();
epubcheckVersion.setText("EPUBCheck Version " + EpubCheck.version() + " - (Built " + EpubCheck.buildDate() + ")");
}

private Predicate<CheckMessage> tableFilterPredicate(String search, Severity severity) {
String searchLower = search.toLowerCase();
return checkMessage -> {

boolean matchesLine = checkMessage.getLine() != null && checkMessage.getLine().toString().contains(searchLower);
boolean matchesColumn = checkMessage.getColumn() != null && checkMessage.getColumn().toString().contains(searchLower);

boolean matchesSearchString =
"".equals(search) // Special case: The empty search matches always.
|| checkMessage.getMessageId().toString().toLowerCase().contains(searchLower)
|| checkMessage.getMessage().toLowerCase().contains(searchLower)
|| checkMessage.getSeverity().toString().contains(searchLower)
|| checkMessage.getPath().contains(searchLower)
|| matchesLine
|| matchesColumn;
return matchesSearchString && isGreaterOrEqualSeverity(checkMessage.getSeverity(), severity);
};
}

private boolean isGreaterOrEqualSeverity(Severity a, Severity b) {
return a.toInt() >= b.toInt();
}

public void clearFilter(ActionEvent actionEvent) {
resultTableSearchFilter.setText("");
resultTableSeverityFilter.getSelectionModel().select(de.pascalwagler.epubcheckfx.model.Severity.INFO);
}

private void initValidationResultTable() {

Property<ObservableList<CheckMessage>> authorListProperty = new SimpleObjectProperty<>(customReport.errorList);
resultTableSearchFilter.textProperty().addListener((observable, oldValue, newValue) -> {
log.info("search changed from " + oldValue + " to " + newValue);
if (Objects.equals(oldValue, newValue)) {
return;
}
filteredErrorList.setPredicate(tableFilterPredicate(newValue, resultTableSeverityFilter.getValue().getEbubcheckSeverity()));
});

resultTableSeverityFilter.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> {
log.info("severity changed from " + oldValue + " to " + newValue);
if (Objects.equals(oldValue, newValue)) {
return;
}
filteredErrorList.setPredicate(tableFilterPredicate(resultTableSearchFilter.getText(), newValue.getEbubcheckSeverity()));
});

filteredErrorList = customReport.errorList.filtered(checkMessage -> true);
Property<ObservableList<CheckMessage>> authorListProperty = new SimpleObjectProperty<>(filteredErrorList);
validationResultTable.itemsProperty().bind(authorListProperty);

messageId.setCellValueFactory(new PropertyValueFactory<>("messageId"));
Expand All @@ -125,6 +181,20 @@ private TableCell<CheckMessage, String> createWrappingTableCell(TableColumn<Chec
return cell;
}

private void initSeverityFilter() {
resultTableSeverityFilter.setCellFactory(listView -> new TranslatableListCell<>(resourceBundle));
resultTableSeverityFilter.getItems().addAll(
de.pascalwagler.epubcheckfx.model.Severity.SUPPRESSED,
de.pascalwagler.epubcheckfx.model.Severity.USAGE,
de.pascalwagler.epubcheckfx.model.Severity.INFO,
de.pascalwagler.epubcheckfx.model.Severity.WARNING,
de.pascalwagler.epubcheckfx.model.Severity.ERROR,
de.pascalwagler.epubcheckfx.model.Severity.FATAL
);
resultTableSeverityFilter.setButtonCell(resultTableSeverityFilter.getCellFactory().call(null));
resultTableSeverityFilter.getSelectionModel().select(de.pascalwagler.epubcheckfx.model.Severity.INFO);
}

private void initExportFormat() {
exportFormat.setCellFactory(listView -> new TranslatableListCell<>(resourceBundle));
exportFormat.getItems().addAll(
Expand Down
18 changes: 17 additions & 1 deletion src/main/resources/fxml/MainContent.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,21 @@
<padding>
<Insets top="10.0"/>
</padding>
<HBox alignment="BASELINE_CENTER" prefHeight="0.0" prefWidth="200.0" spacing="10.0">
<padding>
<Insets bottom="10.0"/>
</padding>
<children>
<TextField fx:id="resultTableSearchFilter" promptText="%result_table.filter.search" HBox.hgrow="ALWAYS"/>
<Label text="%result_table.column_severity"/>
<ComboBox fx:id="resultTableSeverityFilter"/>
<Button mnemonicParsing="false" onAction="#clearFilter" text="%result_table.filter.clear">
<graphic>
<FontIcon iconLiteral="mdoal-clear" iconSize="64"/>
</graphic>
</Button>
</children>
</HBox>
<TableView fx:id="validationResultTable" styleClass="striped" VBox.vgrow="ALWAYS">
<columnResizePolicy>
<TableView fx:constant="CONSTRAINED_RESIZE_POLICY"/>
Expand Down Expand Up @@ -67,11 +82,12 @@
</VBox>
</center>
<bottom>
<HBox alignment="BOTTOM_LEFT" prefHeight="0.0" prefWidth="200.0" spacing="10.0"
<HBox alignment="BASELINE_CENTER" prefHeight="0.0" prefWidth="200.0" spacing="10.0"
BorderPane.alignment="CENTER_LEFT">
<children>
<Label fx:id="epubcheckVersion" text="Input"/>
<Pane prefHeight="0" prefWidth="0" HBox.hgrow="ALWAYS"/>
<Label text="%export_format"/>
<ComboBox fx:id="exportFormat"/>
<Button mnemonicParsing="false" onAction="#export" text="%export">
<graphic>
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/i18n/LangBundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ result_tab.validation=Validation Results
result_tab.metadata=Metadata
result_tab.info=General Information

result_table.filter.search=Search
result_table.filter.clear=Clear Filter
result_table.column_message_id=Message Id
result_table.column_severity=Severity
result_table.column_message=Message
Expand All @@ -30,6 +32,7 @@ info_table.column_resource=Resource
info_table.column_value=Value

export=Export
export_format=Export Format
export_format.html=HTML
export_format.markdown=Markdown (Table)
export_format.markdown_list=Markdown (List)
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/i18n/LangBundle_de.properties
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ result_tab.validation=Validierungsergebnisse
result_tab.metadata=Metadaten
result_tab.info=Allgemeine Information

result_table.filter.search=Suche
result_table.filter.clear=Filter Löschen
result_table.column_message_id=Nachricht-Id
result_table.column_severity=Schweregrad
result_table.column_message=Nachricht
Expand All @@ -30,6 +32,7 @@ info_table.column_resource=Ressource
info_table.column_value=Wert

export=Exportieren
export_format=Export-Format
export_format.html=HTML
export_format.json=JSON
export_format.markdown=Markdown (Tabelle)
Expand Down

0 comments on commit 48ea841

Please sign in to comment.