Skip to content

Commit

Permalink
#52: save selected props after clicking ok, and always load from file…
Browse files Browse the repository at this point in the history
… if exists
  • Loading branch information
FelipeFcosta committed Jan 19, 2023
1 parent 55406f3 commit d57e2e0
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 11 deletions.
14 changes: 14 additions & 0 deletions iped-app/src/main/java/iped/app/ui/ColumnsManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,20 @@ private void loadSavedCols() {
}
}

protected ArrayList<String> loadReportSelectedFields() {
ColumnsReport cr = new ColumnsReport();
ArrayList<String> selectedFields = null;
if (reportCols.exists()) {
try {
cr = (ColumnsReport) Util.readObject(reportCols.getAbsolutePath());
} catch (ClassNotFoundException | IOException e) {
e.printStackTrace();
}
selectedFields = (ArrayList<String>) cr.selectedCols.clone();
}
return selectedFields;
}

public void updateDinamicCols() {
if (!autoManageCols)
return;
Expand Down
38 changes: 31 additions & 7 deletions iped-app/src/main/java/iped/app/ui/ColumnsManagerReportUI.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package iped.app.ui;

import java.awt.BorderLayout;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.ActionEvent;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
Expand All @@ -10,8 +13,10 @@

import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JPanel;
import javax.swing.JRootPane;
import javax.swing.JScrollPane;

import iped.engine.task.index.IndexItem;
Expand All @@ -21,6 +26,7 @@
public class ColumnsManagerReportUI extends ColumnsManagerUI {
private ColumnsManagerUI columnsManagerUI;
private static ColumnsManagerReportUI instance;
private JButton okButton = new JButton("OK");

private static final String[] basicReportProps = { IndexItem.NAME, IndexItem.PATH, IndexItem.TYPE, IndexItem.LENGTH, IndexItem.CREATED,
IndexItem.MODIFIED, IndexItem.ACCESSED, IndexItem.DELETED, IndexItem.CARVED, IndexItem.HASH, IndexItem.ID_IN_SOURCE };
Expand All @@ -37,19 +43,27 @@ public void dispose() {
columnsManager = null;
columnsManagerUI = null;
instance = null;
selectOnlyBasicProperties();
}

protected ColumnsManagerReportUI() {
super();
dialog.getContentPane().remove(panel);
columnsManagerUI = ColumnsManagerUI.getInstance();

dialog.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
dispose();
}
});

dialog.getContentPane().remove(panel);
autoManage.removeActionListener(columnsManagerUI);

Box topPanel = Box.createVerticalBox();
topPanel.add(showColsLabel);
topPanel.add(combo);
topPanel.add(textFieldNameFilter);
okButton.addActionListener(this);
combo.addActionListener(this);

panel = new JPanel(new BorderLayout());
Expand All @@ -60,11 +74,19 @@ protected ColumnsManagerReportUI() {
scrollList.getVerticalScrollBar().setUnitIncrement(10);
panel.add(scrollList, BorderLayout.CENTER);

JPanel bPanel = new JPanel(new BorderLayout());
bPanel.add(okButton, BorderLayout.EAST);
panel.add(bPanel, BorderLayout.SOUTH);

dialog.getContentPane().add(panel);
dialog.setLocationRelativeTo(App.get());

// initial selected properties are the basics
selectOnlyBasicProperties();
ArrayList<String> selectedFields = columnsManager.loadReportSelectedFields();
if (selectedFields != null) {
selectProperties(selectedFields);
} else {
selectProperties(Arrays.asList(basicReportProps));
}

updatePanelList();
}
Expand All @@ -73,12 +95,14 @@ protected ColumnsManagerReportUI() {
public void actionPerformed(ActionEvent e) {
if (e.getSource().equals(combo)) {
updatePanelList();
} else if (e.getSource().equals(okButton)) {
columnsManager.saveReportColumns();
dispose();
} else {
JCheckBox source = (JCheckBox) e.getSource();
String text = source.getText();
boolean isSelected = source.isSelected();
columnsManager.updateCol(text, isSelected);
columnsManager.saveReportColumns();
}
}

Expand All @@ -105,11 +129,11 @@ protected void updatePanelList() {
dialog.repaint();
}

private void selectOnlyBasicProperties() {
private void selectProperties(List<String> props) {
for (Map.Entry<String, JCheckBox> hmEntry : columnsCheckBoxes.entrySet()) {
JCheckBox check = hmEntry.getValue();
String key = hmEntry.getKey();
if (Arrays.asList(basicReportProps).contains(key)) {
if (props.contains(LocalizedProperties.getNonLocalizedField(key))) {
check.setSelected(true);
} else {
check.setSelected(false);
Expand Down
8 changes: 4 additions & 4 deletions iped-app/src/main/java/iped/app/ui/ColumnsManagerUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class ColumnsManagerUI implements ActionListener {
protected final JPanel listPanel;
protected JPanel panel = new JPanel(new BorderLayout());

protected static ColumnsManager columnsManager = ColumnsManager.getInstance();
protected static ColumnsManager columnsManager;
private static ColumnsManagerUI instance;

protected static Map<String, JCheckBox> columnsCheckBoxes;
Expand All @@ -66,7 +66,7 @@ public void setVisible() {
}

protected ColumnsManagerUI() {

columnsManager = ColumnsManager.getInstance();
columnsCheckBoxes = new HashMap<>();

dialog.setBounds(new Rectangle(400, 400));
Expand Down Expand Up @@ -148,7 +148,7 @@ protected void updatePanelList() {
check.setSelected(true);
check.addActionListener(this);
listPanel.add(check);
columnsCheckBoxes.put(fieldName, check);
columnsCheckBoxes.put(LocalizedProperties.getNonLocalizedField(fieldName), check);
}
}
dialog.revalidate();
Expand Down Expand Up @@ -203,7 +203,7 @@ public List<String> getSelectedProperties() {
for (Map.Entry<String, JCheckBox> hmEntry : columnsCheckBoxes.entrySet()) {
JCheckBox check = hmEntry.getValue();
if (check.isSelected()) {
selectedColumns.add(check.getText());
selectedColumns.add(LocalizedProperties.getNonLocalizedField(check.getText()));
}
}
return selectedColumns;
Expand Down

0 comments on commit d57e2e0

Please sign in to comment.