Skip to content

Commit

Permalink
#52: make IdInSource and Path required report html properties
Browse files Browse the repository at this point in the history
  • Loading branch information
FelipeFcosta committed Feb 13, 2023
1 parent 3f69cd3 commit 74216c1
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 15 deletions.
37 changes: 27 additions & 10 deletions iped-app/src/main/java/iped/app/ui/columns/ColumnsManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import org.apache.lucene.document.Document;
import org.apache.tika.metadata.Message;
import org.neo4j.internal.kernel.api.security.AccessMode.Static;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -113,7 +114,7 @@ private static final File getGlobalColsFile() {

private boolean autoManageCols;

protected Map<String, Boolean> allCheckBoxesState = new HashMap<>();
protected Map<String, CheckBoxState> allCheckBoxesState = new HashMap<>();

public static ColumnsManager getInstance() {
if (instance == null)
Expand Down Expand Up @@ -145,6 +146,21 @@ public static class ColumnState implements Serializable {
public ArrayList<String> visibleFields = new ArrayList<String>();
}

public static class CheckBoxState {
boolean isSelected;
boolean isEnabled;

public CheckBoxState(boolean isSelected) {
this.isSelected = isSelected;
this.isEnabled = true;
}

public CheckBoxState(boolean isSelected, boolean isEnabled) {
this.isSelected = isSelected;
this.isEnabled = isEnabled;
}
};

protected ColumnsManager() {
allCheckBoxesState = new HashMap<>();

Expand Down Expand Up @@ -398,39 +414,40 @@ else if (f.startsWith(EvtxParser.EVTX_METADATA_PREFIX)) {
private void initializeAllCheckBoxesState() {
for (int i = 0; i < fieldGroups.length; i++) {
List<String> fieldNames = Arrays.asList(fieldGroups[i]);
fieldNames.forEach(f -> allCheckBoxesState.putIfAbsent(LocalizedProperties.getNonLocalizedField(f), false));
fieldNames.forEach(
f -> allCheckBoxesState.putIfAbsent(LocalizedProperties.getNonLocalizedField(f), new CheckBoxState(false)));
}
}

public List<String> getSelectedProperties() {
List<String> selectedProperties = new ArrayList<>();
for (Map.Entry<String, Boolean> hmEntry : allCheckBoxesState.entrySet()) {
for (Map.Entry<String, CheckBoxState> hmEntry : allCheckBoxesState.entrySet()) {
String fieldName = hmEntry.getKey();
Boolean checkBoxState = hmEntry.getValue();
if (checkBoxState == true) {
Boolean isCheckBoxSelected = hmEntry.getValue().isSelected;
if (isCheckBoxSelected == true) {
selectedProperties.add(LocalizedProperties.getNonLocalizedField(fieldName));
}
}
return selectedProperties;
}

protected void enableOnlySelectedProperties(List<String> props) {
for (Map.Entry<String, Boolean> hmEntry : allCheckBoxesState.entrySet()) {
for (Map.Entry<String, CheckBoxState> hmEntry : allCheckBoxesState.entrySet()) {
String nonLocalizedKey = LocalizedProperties.getNonLocalizedField(hmEntry.getKey());
if (props.contains(nonLocalizedKey)) {
allCheckBoxesState.put(nonLocalizedKey, true);
allCheckBoxesState.put(nonLocalizedKey, new CheckBoxState(true));
} else {
allCheckBoxesState.put(nonLocalizedKey, false);
allCheckBoxesState.put(nonLocalizedKey, new CheckBoxState(false));
}
}
}

protected void enableAllProperties() {
allCheckBoxesState.replaceAll((name, state) -> state = true);
allCheckBoxesState.replaceAll((name, state) -> state = new CheckBoxState(true));
}

protected void disableAllProperties() {
allCheckBoxesState.replaceAll((name, state) -> state = false);
allCheckBoxesState.replaceAll((name, state) -> state = new CheckBoxState(false));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@

import iped.app.ui.App;
import iped.app.ui.Messages;
import iped.app.ui.columns.ColumnsManager.CheckBoxState;
import iped.engine.task.index.IndexItem;
import iped.localization.LocalizedProperties;
import iped.properties.BasicProps;

public class ColumnsSelectReportUI extends ColumnsSelectUI {
private static ColumnsSelectReportUI instance;
Expand Down Expand Up @@ -74,6 +76,7 @@ protected ColumnsSelectReportUI() {
} else {
columnsManager.enableOnlySelectedProperties(Arrays.asList(basicReportProps));
}
disableRequiredProperties();
updatePanelList();
}

Expand All @@ -82,6 +85,7 @@ public void actionPerformed(ActionEvent e) {
super.actionPerformed(e);
if (e.getSource().equals(clearButton)) {
columnsManager.disableAllProperties();
disableRequiredProperties();
updatePanelList();
} else if (e.getSource() instanceof JCheckBox || e.getSource().equals(selectVisibleButton)) {
if (columnsManager.getSelectedProperties().size() > PROPERTIES_LIMIT_NUM) {
Expand All @@ -90,7 +94,7 @@ public void actionPerformed(ActionEvent e) {
String nonLocalizedText = LocalizedProperties.getNonLocalizedField(source.getText());
JOptionPane.showMessageDialog(dialog, Messages.getString("ColumnsManager.LimitReachedMessage", PROPERTIES_LIMIT_NUM),
Messages.getString("ColumnsManager.LimitReachedTitle"), JOptionPane.ERROR_MESSAGE);
columnsManager.allCheckBoxesState.put(nonLocalizedText, false);
columnsManager.allCheckBoxesState.put(nonLocalizedText, new CheckBoxState(false));
} else {
JOptionPane.showMessageDialog(dialog, Messages.getString("ColumnsManager.LimitReachedVisibleMessage", PROPERTIES_LIMIT_NUM),
Messages.getString("ColumnsManager.LimitReachedTitle"), JOptionPane.ERROR_MESSAGE);
Expand All @@ -101,4 +105,9 @@ public void actionPerformed(ActionEvent e) {
}
}
}

public void disableRequiredProperties() {
columnsManager.allCheckBoxesState.put(IndexItem.ID_IN_SOURCE, new CheckBoxState(true, false));
columnsManager.allCheckBoxesState.put(BasicProps.PATH, new CheckBoxState(true, false));
}
}
10 changes: 6 additions & 4 deletions iped-app/src/main/java/iped/app/ui/columns/ColumnsSelectUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import iped.app.ui.App;
import iped.app.ui.Messages;
import iped.app.ui.ResultTableModel;
import iped.app.ui.columns.ColumnsManager.CheckBoxState;
import iped.localization.LocalizedProperties;
import iped.utils.StringUtil;

Expand Down Expand Up @@ -127,7 +128,7 @@ public void actionPerformed(ActionEvent e) {
JCheckBox source = (JCheckBox) e.getSource();
String nonLocalizedText = LocalizedProperties.getNonLocalizedField(source.getText());
boolean isSelected = source.isSelected();
columnsManager.allCheckBoxesState.put(nonLocalizedText, isSelected);
columnsManager.allCheckBoxesState.put(nonLocalizedText, new CheckBoxState(isSelected));
}

if (columnsManager.getSelectedProperties().size() == 0) {
Expand All @@ -149,9 +150,10 @@ protected void updatePanelList() {
if (filter.isEmpty() || fieldName.toLowerCase().indexOf(filter) >= 0) {
JCheckBox check = new JCheckBox();
check.setText(fieldName);
Boolean checkBoxState = columnsManager.allCheckBoxesState.get(LocalizedProperties.getNonLocalizedField(fieldName));
if (checkBoxState != null && checkBoxState == true)
check.setSelected(true);
CheckBoxState checkBoxState = columnsManager.allCheckBoxesState.get(LocalizedProperties.getNonLocalizedField(fieldName));
if (checkBoxState.isSelected)
check.setSelected(checkBoxState.isSelected);
check.setEnabled(checkBoxState.isEnabled);
check.addActionListener(this);
listPanel.add(check);
}
Expand Down

0 comments on commit 74216c1

Please sign in to comment.