Skip to content

Commit

Permalink
'#1866: Use a base class in related items TableModels to simplify code.
Browse files Browse the repository at this point in the history
  • Loading branch information
wladimirleite committed Sep 6, 2023
1 parent c94cf64 commit cb85d76
Show file tree
Hide file tree
Showing 6 changed files with 144 additions and 566 deletions.
113 changes: 113 additions & 0 deletions iped-app/src/main/java/iped/app/ui/BaseTableModel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
package iped.app.ui;

import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.event.ListSelectionListener;
import javax.swing.table.AbstractTableModel;

import org.apache.lucene.document.Document;

import iped.engine.search.LuceneSearchResult;
import iped.engine.search.MultiSearchResult;
import iped.engine.task.index.IndexItem;
import iped.search.IMultiSearchResult;

public abstract class BaseTableModel extends AbstractTableModel
implements MouseListener, ListSelectionListener, SearchResultTableModel {

private static final long serialVersionUID = 1L;

protected LuceneSearchResult results = new LuceneSearchResult(0);
protected int selectedIndex = -1;
protected Document refDoc;

public void clear() {
results = new LuceneSearchResult(0);
fireTableDataChanged();
}

@Override
public int getColumnCount() {
return 3;
}

@Override
public int getRowCount() {
return results.getLength();
}

@Override
public String getColumnName(int col) {
if (col == 2)
return IndexItem.NAME;

return "";
}

@Override
public boolean isCellEditable(int row, int col) {
return col == 1;
}

@Override
public Class<?> getColumnClass(int c) {
return c == 1 ? Boolean.class : String.class;
}

@Override
public void setValueAt(Object value, int row, int col) {
App.get().appCase.getMultiBookmarks().setChecked((Boolean) value,
App.get().appCase.getItemId(results.getLuceneIds()[row]));
BookmarksController.get().updateUISelection();
}

@Override
public Object getValueAt(int row, int col) {
switch (col) {
case 0:
return row + 1;

case 1:
return App.get().appCase.getMultiBookmarks()
.isChecked(App.get().appCase.getItemId(results.getLuceneIds()[row]));

case 2:
try {
Document doc = App.get().appCase.getSearcher().doc(results.getLuceneIds()[row]);
return doc.get(IndexItem.NAME);
} catch (Exception e) {
}
}
return "";
}

@Override
public void mouseClicked(MouseEvent arg0) {
}

@Override
public void mouseEntered(MouseEvent arg0) {
}

@Override
public void mouseExited(MouseEvent arg0) {
}

@Override
public void mousePressed(MouseEvent arg0) {
}

@Override
public void mouseReleased(MouseEvent evt) {
if (evt.getClickCount() == 2 && selectedIndex != -1) {
int docId = results.getLuceneIds()[selectedIndex];
ExternalFileOpen.open(docId);
}
}

@Override
public IMultiSearchResult getSearchResult() {
return MultiSearchResult.get(App.get().appCase, results);
}
}
108 changes: 7 additions & 101 deletions iped-app/src/main/java/iped/app/ui/DuplicatesTableModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,10 @@
package iped.app.ui;

import java.awt.Rectangle;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.ListSelectionModel;
import javax.swing.SwingUtilities;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.AbstractTableModel;

import org.apache.lucene.document.Document;

Expand All @@ -36,105 +32,22 @@
import iped.engine.task.index.IndexItem;
import iped.properties.BasicProps;
import iped.search.IIPEDSearcher;
import iped.search.IMultiSearchResult;

public class DuplicatesTableModel extends AbstractTableModel
implements MouseListener, ListSelectionListener, SearchResultTableModel {
public class DuplicatesTableModel extends BaseTableModel {

/**
*
*/
private static final long serialVersionUID = 1L;

LuceneSearchResult results = new LuceneSearchResult(0);
int selectedIndex = -1;

@Override
public int getColumnCount() {
return 3;
}

@Override
public int getRowCount() {
return results.getLength();
}

@Override
public String getColumnName(int col) {
if (col == 2)
return IndexItem.PATH;

return ""; //$NON-NLS-1$
}

@Override
public boolean isCellEditable(int row, int col) {
if (col == 1) {
return true;
} else {
return false;
}
}

@Override
public Class<?> getColumnClass(int c) {
if (c == 1) {
return Boolean.class;
} else {
return String.class;
}
}

@Override
public void setValueAt(Object value, int row, int col) {
App.get().appCase.getMultiBookmarks().setChecked((Boolean) value,
App.get().appCase.getItemId(results.getLuceneIds()[row]));
BookmarksController.get().updateUISelection();
}

@Override
public Object getValueAt(int row, int col) {
if (col == 0) {
return row + 1;

} else if (col == 1) {
return App.get().appCase.getMultiBookmarks()
.isChecked(App.get().appCase.getItemId(results.getLuceneIds()[row]));

} else {
if (col == 2) {
try {
Document doc = App.get().appCase.getSearcher().doc(results.getLuceneIds()[row]);
return doc.get(IndexItem.PATH);

} catch (Exception e) {
// e.printStackTrace();
}
return ""; //$NON-NLS-1$
}
}

@Override
public void mouseClicked(MouseEvent arg0) {
}

@Override
public void mouseEntered(MouseEvent arg0) {
}

@Override
public void mouseExited(MouseEvent arg0) {
}

@Override
public void mousePressed(MouseEvent arg0) {
}

@Override
public void mouseReleased(MouseEvent evt) {
if (evt.getClickCount() == 2 && selectedIndex != -1) {
int docId = results.getLuceneIds()[selectedIndex];
ExternalFileOpen.open(docId);
return "";
}
return super.getValueAt(row, col);
}

@Override
Expand Down Expand Up @@ -166,8 +79,8 @@ public void listDuplicates(Document doc) {
String id = doc.get(IndexItem.ID);
String sourceUUID = doc.get(IndexItem.EVIDENCE_UUID);

textQuery += " && NOT (" + IndexItem.ID + ":" + id; //$NON-NLS-1$ //$NON-NLS-2$
textQuery += " && " + IndexItem.EVIDENCE_UUID + ":" + sourceUUID + ")"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
textQuery += " && NOT (" + IndexItem.ID + ":" + id;
textQuery += " && " + IndexItem.EVIDENCE_UUID + ":" + sourceUUID + ")";

try {
IIPEDSearcher task = new IPEDSearcher(App.get().appCase, textQuery, BasicProps.PATH);
Expand All @@ -180,7 +93,7 @@ public void listDuplicates(Document doc) {
@Override
public void run() {
App.get().duplicateDock
.setTitleText(duplicates + Messages.getString("DuplicatesTableModel.Duplicates")); //$NON-NLS-1$
.setTitleText(duplicates + Messages.getString("DuplicatesTableModel.Duplicates"));
}
});
}
Expand All @@ -191,12 +104,5 @@ public void run() {
}

fireTableDataChanged();

}

@Override
public IMultiSearchResult getSearchResult() {
return MultiSearchResult.get(App.get().appCase, results);
}

}
Loading

0 comments on commit cb85d76

Please sign in to comment.