Skip to content

Commit

Permalink
#286: create new ColumnsManagerUI window to select properties before …
Browse files Browse the repository at this point in the history
…exporting to csv
  • Loading branch information
FelipeFcosta committed Feb 2, 2023
1 parent 5f2a2ac commit 5c5bf10
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 50 deletions.
2 changes: 1 addition & 1 deletion iped-app/src/main/java/iped/app/ui/AppMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class AppMain {
File casePath;

// configure to debug the analysis UI with some case
File testPath = null;// = new File("E:\\teste\\case-to-debug");
File testPath = new File("C:\\Users\\Felipe Costa\\Downloads\\caso_test\\debug_case\\processed_all_report");

boolean isMultiCase = false;
boolean nolog = false;
Expand Down
20 changes: 10 additions & 10 deletions iped-app/src/main/java/iped/app/ui/ColumnsManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,11 @@ private static final File getGlobalColsFile() {

private IPEDSource lastCase;

File moduleDir;
private static File moduleDir;
private File caseCols;

private static final String SELECTED_PROPERTIES_FILENAME = "data/reportProps.dat";

private File reportPropsFile;
public static final String SELECTED_PROPERTIES_FILENAME = "data/selectedProps.dat";
public static final String SELECTED_REPORT_PROPERTIES_FILENAME = "data/reportProps.dat";

String[] indexFields = null;

Expand Down Expand Up @@ -151,12 +150,13 @@ static class ColumnState implements Serializable {
ArrayList<String> visibleFields = new ArrayList<String>();
}

protected void saveReportSelectedProps() {
protected void saveSelectedProps(String propsFileName) {
File propsFile = new File(moduleDir, propsFileName);
try {
Set<String> reportPropsSet = new HashSet<>();
reportPropsSet.addAll(getSelectedProperties());
if (reportPropsSet.size() > 0) {
Util.writeObject(reportPropsSet, reportPropsFile.getAbsolutePath());
Util.writeObject(reportPropsSet, propsFile.getAbsolutePath());
}
} catch (Exception e1) {
e1.printStackTrace();
Expand Down Expand Up @@ -191,7 +191,6 @@ protected ColumnsManager() {
autoManageCols = analysisConfig.isAutoManageCols();

moduleDir = App.get().appCase.getAtomicSourceBySourceId(0).getModuleDir();
reportPropsFile = new File(moduleDir, SELECTED_PROPERTIES_FILENAME);

updateDinamicFields();

Expand Down Expand Up @@ -246,12 +245,13 @@ private void loadSavedCols() {
}
}

protected ArrayList<String> loadReportSelectedFields() {
public static ArrayList<String> loadSelectedFields(String propsFileName) {
Set<String> columnsReport = new HashSet<>();
ArrayList<String> selectedFields = null;
if (reportPropsFile.exists()) {
File propsFile = new File(moduleDir, propsFileName);
if (propsFile.exists()) {
try {
columnsReport = (Set<String>) Util.readObject(reportPropsFile.getAbsolutePath());
columnsReport = (Set<String>) Util.readObject(propsFile.getAbsolutePath());
} catch (ClassNotFoundException | IOException e) {
e.printStackTrace();
}
Expand Down
38 changes: 38 additions & 0 deletions iped-app/src/main/java/iped/app/ui/ColumnsSelectReportUI.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package iped.app.ui;

import java.util.Arrays;
import iped.engine.task.index.IndexItem;

public class ColumnsSelectReportUI extends ColumnsSelectUI {
private static ColumnsSelectReportUI instance;

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 };

public static ColumnsSelectReportUI getInstance() {
if (instance == null)
instance = new ColumnsSelectReportUI();
return instance;
}

@Override
public void dispose() {
super.dispose();
dialog.setVisible(false);
columnsManager = null;
instance = null;
}

protected ColumnsSelectReportUI() {
super();
saveFileName = ColumnsManager.SELECTED_REPORT_PROPERTIES_FILENAME;

loadedSelectedProperties = ColumnsManager.loadSelectedFields(saveFileName);
if (loadedSelectedProperties != null) {
columnsManager.enableOnlySelectedProperties(loadedSelectedProperties);
} else {
columnsManager.enableOnlySelectedProperties(Arrays.asList(basicReportProps));
}
updatePanelList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,20 @@
import javax.swing.JPanel;
import javax.swing.JScrollPane;

import iped.engine.task.index.IndexItem;
import iped.localization.LocalizedProperties;
import iped.utils.StringUtil;

public class ColumnsManagerReportUI extends ColumnsManagerUI {
public class ColumnsSelectUI extends ColumnsManagerUI {
private ColumnsManagerUI columnsManagerUI;
private static ColumnsManagerReportUI instance;
private static ColumnsSelectUI instance;
private JButton okButton = new JButton("OK");
ArrayList<String> loadedSelectedProperties;
private static boolean okButtonClicked;
protected String saveFileName;

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 };

public static ColumnsManagerReportUI getInstance() {
public static ColumnsSelectUI getInstance() {
if (instance == null)
instance = new ColumnsManagerReportUI();
instance = new ColumnsSelectUI();
return instance;
}

Expand All @@ -45,8 +43,14 @@ public void dispose() {
instance = null;
}

protected ColumnsManagerReportUI() {
public static boolean getOkButtonClicked() {
return okButtonClicked;
}

protected ColumnsSelectUI() {
super();
saveFileName = ColumnsManager.SELECTED_PROPERTIES_FILENAME;
okButtonClicked = false;
columnsManagerUI = ColumnsManagerUI.getInstance();

dialog.setTitle(Messages.getString("ReportDialog.PropertiesDialogTitle"));
Expand Down Expand Up @@ -83,13 +87,12 @@ public void windowClosing(WindowEvent e) {
dialog.getContentPane().add(panel);
dialog.setLocationRelativeTo(App.get());

loadedSelectedProperties = columnsManager.loadReportSelectedFields();
loadedSelectedProperties = ColumnsManager.loadSelectedFields(saveFileName);
if (loadedSelectedProperties != null) {
columnsManager.enableOnlySelectedProperties(loadedSelectedProperties);
} else {
columnsManager.enableOnlySelectedProperties(Arrays.asList(basicReportProps));
columnsManager.enableOnlySelectedProperties(new ArrayList<String>(Arrays.asList(ResultTableModel.fields)));
}

updatePanelList();
}

Expand All @@ -98,13 +101,18 @@ public void actionPerformed(ActionEvent e) {
if (e.getSource().equals(combo)) {
updatePanelList();
} else if (e.getSource().equals(okButton)) {
columnsManager.saveReportSelectedProps();
columnsManager.saveSelectedProps(saveFileName);
okButtonClicked = true;
dispose();
} else {
JCheckBox source = (JCheckBox) e.getSource();
String text = source.getText();
String nonLocalizedText = LocalizedProperties.getNonLocalizedField(source.getText());
boolean isSelected = source.isSelected();
columnsManager.allCheckBoxesState.put(text, isSelected);
if (columnsManager.getSelectedProperties().size() == 1 && !isSelected) {
updatePanelList();
return;
}
columnsManager.allCheckBoxesState.put(nonLocalizedText, isSelected);
}
}

Expand Down
14 changes: 9 additions & 5 deletions iped-app/src/main/java/iped/app/ui/CopyProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,15 @@
public class CopyProperties extends SwingWorker<Boolean, Integer> implements PropertyChangeListener {

ArrayList<Integer> uniqueIds;
ArrayList<String> fields;
ProgressMonitor progressMonitor;
File file;
int total;

public CopyProperties(File file, ArrayList<Integer> uniqueIds) {
public CopyProperties(File file, ArrayList<Integer> uniqueIds, ArrayList<String> fields) {
this.file = file;
this.uniqueIds = uniqueIds;
this.fields = fields;
this.total = uniqueIds.size();

progressMonitor = new ProgressMonitor(App.get(), "", "", 0, total); //$NON-NLS-1$ //$NON-NLS-2$
Expand All @@ -62,9 +64,11 @@ protected Boolean doInBackground() throws Exception {
byte[] utf8bom = { (byte) 0xEF, (byte) 0xBB, (byte) 0xBF };
fos.write(utf8bom);

ArrayList<String> fields = new ArrayList<String>();
for (String field : ResultTableModel.fields) {
fields.add(field);
if (fields == null || fields.isEmpty()) {
fields = new ArrayList<String>();
for (String field : ResultTableModel.fields) {
fields.add(field);
}
}

for (int col = 0; col < fields.size(); col++) {
Expand Down
49 changes: 31 additions & 18 deletions iped-app/src/main/java/iped/app/ui/MenuListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ private void setupFileChooser() {
}
}

private void setupColumnsSelector() {
ColumnsSelectUI columnsSelector = ColumnsSelectUI.getInstance();
columnsSelector.dialog.setModal(true);
columnsSelector.setVisible();
}

private class Filtro extends FileFilter {

@Override
Expand All @@ -102,7 +108,7 @@ public boolean accept(File f) {

@Override
public String getDescription() {
return "Comma Separeted Values (" + CSV + ")"; //$NON-NLS-1$ //$NON-NLS-2$
return "Comma Separated Values (" + CSV + ")"; //$NON-NLS-1$ //$NON-NLS-2$
}

}
Expand Down Expand Up @@ -200,15 +206,19 @@ public void actionPerformed(ActionEvent e) {
int luceneId = App.get().appCase.getLuceneId(item);
selectedIds.add(luceneId);
}
setupFileChooser();
fileChooser.setFileFilter(csvFilter);
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
if (fileChooser.showSaveDialog(App.get()) == JFileChooser.APPROVE_OPTION) {
File file = fileChooser.getSelectedFile();
if (!file.getName().endsWith(CSV)) {
file = new File(file.getAbsolutePath() + CSV);
setupColumnsSelector();
if (ColumnsSelectUI.getOkButtonClicked() == true) {
setupFileChooser();
fileChooser.setFileFilter(csvFilter);
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
if (fileChooser.showSaveDialog(App.get()) == JFileChooser.APPROVE_OPTION) {
File file = fileChooser.getSelectedFile();
if (!file.getName().endsWith(CSV)) {
file = new File(file.getAbsolutePath() + CSV);
}
ArrayList<String> loadedSelectedFields = ColumnsManager.loadSelectedFields(ColumnsManager.SELECTED_PROPERTIES_FILENAME);
(new CopyProperties(file, selectedIds, loadedSelectedFields)).execute();
}
(new CopyProperties(file, selectedIds)).execute();
}

} else if (e.getSource() == menu.copyChecked) {
Expand All @@ -219,17 +229,20 @@ public void actionPerformed(ActionEvent e) {
uniqueSelectedIds.add(docId);
}
});
setupFileChooser();
fileChooser.setFileFilter(csvFilter);
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
if (fileChooser.showSaveDialog(App.get()) == JFileChooser.APPROVE_OPTION) {
File file = fileChooser.getSelectedFile();
if (!file.getName().endsWith(CSV)) {
file = new File(file.getAbsolutePath() + CSV);
setupColumnsSelector();
if (ColumnsSelectUI.getOkButtonClicked() == true) {
setupFileChooser();
fileChooser.setFileFilter(csvFilter);
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
if (fileChooser.showSaveDialog(App.get()) == JFileChooser.APPROVE_OPTION) {
File file = fileChooser.getSelectedFile();
if (!file.getName().endsWith(CSV)) {
file = new File(file.getAbsolutePath() + CSV);
}
ArrayList<String> loadedSelectedFields = ColumnsManager.loadSelectedFields(ColumnsManager.SELECTED_PROPERTIES_FILENAME);
(new CopyProperties(file, uniqueSelectedIds, loadedSelectedFields)).execute();
}
(new CopyProperties(file, uniqueSelectedIds)).execute();
}

} else if (e.getSource() == menu.exportChecked) {
ArrayList<IItemId> uniqueSelectedIds = new ArrayList<IItemId>();
for (IPEDSource source : App.get().appCase.getAtomicSources()) {
Expand Down
2 changes: 1 addition & 1 deletion iped-app/src/main/java/iped/app/ui/ReportDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ public void actionPerformed(ActionEvent e) {
}

if (e.getSource() == propertiesButton) {
ColumnsManagerReportUI.getInstance().setVisible();
ColumnsSelectReportUI.getInstance().setVisible();
}

if (e.getSource() == keywordsButton) {
Expand Down

0 comments on commit 5c5bf10

Please sign in to comment.