diff --git a/iped-app/resources/localization/iped-desktop-messages.properties b/iped-app/resources/localization/iped-desktop-messages.properties index 8a4504e69e..0590d6e4de 100644 --- a/iped-app/resources/localization/iped-desktop-messages.properties +++ b/iped-app/resources/localization/iped-desktop-messages.properties @@ -211,7 +211,11 @@ MenuClass.AddToGraph=Add to link analysis MenuClass.ChangeGalleryColCount=Change Gallery Column Count MenuClass.ChangeLayout=Change Vertical/Horizontal Layout MenuClass.CheckHighlighted=Check Highlighted items -MenuClass.CheckRecursivelyHighlighted=Check highlighted items and subitems +MenuClass.CheckAdvanced=Advanced Check... +MenuClass.CheckHighlightedAndSubItems=Check highlighted items and subitems +MenuClass.CheckHighlightedAndParent=Check highlighted and parent items +MenuClass.CheckHighlightedAndReferences=Check highlighted and reference items +MenuClass.CheckHighlightedAndReferencedBy=Check highlighted and "referenced by" items MenuClass.ClearSearches=Clear Search history MenuClass.ColorTheme=Color Theme MenuClass.CopyViewerImage=Take viewer screenshot @@ -254,7 +258,10 @@ MenuClass.SaveBookmarks=Save Bookmarks MenuClass.UiZoom=Change User Interface Zoom MenuClass.IconSize=Icons Size MenuClass.UnCheckHighlighted=Uncheck Highlighted items -MenuClass.UnCheckRecursivelyHighlighted=Uncheck highlighted items and subitems +MenuClass.UncheckHighlightedAndSubItems=Uncheck highlighted items and subitems +MenuClass.UncheckHighlightedAndParent=Uncheck highlighted and parent items +MenuClass.UncheckHighlightedAndReferences=Uncheck highlighted and reference items +MenuClass.UncheckHighlightedAndReferencedBy=Uncheck highlighted and "referenced by" items MenuListener.ChatNotFound=Parent chat not found MenuListener.Cols=Columns: MenuListener.ExportTree.Warn=Highlight 01 (one) tree node as export reference\! diff --git a/iped-app/resources/localization/iped-desktop-messages_de_DE.properties b/iped-app/resources/localization/iped-desktop-messages_de_DE.properties index 79a06db85b..0b665596d6 100644 --- a/iped-app/resources/localization/iped-desktop-messages_de_DE.properties +++ b/iped-app/resources/localization/iped-desktop-messages_de_DE.properties @@ -211,7 +211,11 @@ MenuClass.AddToGraph=Zur Link-Analyse hinzufügen MenuClass.ChangeGalleryColCount=Ändere Spaltenanzahl in der Galerie MenuClass.ChangeLayout=Ändere vertikales/horizontales Layout MenuClass.CheckHighlighted=Setze Haken bei markierten Elementen -MenuClass.CheckRecursivelyHighlighted=Setze Haken bei markierten Elementen und Unterelementen +MenuClass.CheckAdvanced=Advanced Check... [TBT] +MenuClass.CheckHighlightedAndSubItems=Setze Haken bei markierten Elementen und Unterelementen +MenuClass.CheckHighlightedAndParent=Check highlighted and parent items [TBT] +MenuClass.CheckHighlightedAndReferences=Check highlighted and reference items [TBT] +MenuClass.CheckHighlightedAndReferencedBy=Check highlighted and "referenced by" items [TBT] MenuClass.ClearSearches=Lösche Suchhistorie MenuClass.ColorTheme=Farbschema MenuClass.CopyViewerImage=Erstelle Bildschirmkopie vom Betrachter @@ -254,7 +258,10 @@ MenuClass.SaveBookmarks=Lesezeichen speichern MenuClass.UiZoom=Ändere Zoom der Benutzeroberfläche MenuClass.IconSize=Icon-Größe MenuClass.UnCheckHighlighted=markierte Elemente abwählen -MenuClass.UnCheckRecursivelyHighlighted=markierte Elemente und Unterelemente abwählen +MenuClass.UncheckHighlightedAndSubItems=markierte Elemente und Unterelemente abwählen +MenuClass.UncheckHighlightedAndParent=Uncheck highlighted and parent items [TBT] +MenuClass.UncheckHighlightedAndReferences=Uncheck highlighted and reference items [TBT] +MenuClass.UncheckHighlightedAndReferencedBy=Uncheck highlighted and "referenced by" items [TBT] MenuListener.ChatNotFound=übergeordneten Chat nicht gefunden MenuListener.Cols=Spalten: MenuListener.ExportTree.Warn=Markiere 01 (einen) Baumknoten als Exportreferenz\! diff --git a/iped-app/resources/localization/iped-desktop-messages_es_AR.properties b/iped-app/resources/localization/iped-desktop-messages_es_AR.properties index 51ffee2b71..0ae32a0990 100644 --- a/iped-app/resources/localization/iped-desktop-messages_es_AR.properties +++ b/iped-app/resources/localization/iped-desktop-messages_es_AR.properties @@ -211,7 +211,11 @@ MenuClass.AddToGraph=Añadir al análisis de enlaces MenuClass.ChangeGalleryColCount=Cambiar número de columnas de la galería MenuClass.ChangeLayout=Cambiar diseño vertical/horizontal MenuClass.CheckHighlighted=Comprobar elementos resaltados -MenuClass.CheckRecursivelyHighlighted=Comprobar elementos y subelementos resaltados +MenuClass.CheckAdvanced=Advanced Check... [TBT] +MenuClass.CheckHighlightedAndSubItems=Comprobar elementos y subelementos resaltados +MenuClass.CheckHighlightedAndParent=Check highlighted and parent items [TBT] +MenuClass.CheckHighlightedAndReferences=Check highlighted and reference items [TBT] +MenuClass.CheckHighlightedAndReferencedBy=Check highlighted and "referenced by" items [TBT] MenuClass.ClearSearches=Borrar historial de búsqueda MenuClass.ColorTheme=Tema de color MenuClass.CopyViewerImage=Tomar captura de pantalla del visor @@ -254,7 +258,10 @@ MenuClass.SaveBookmarks=Guardar marcadores en un archivo MenuClass.UiZoom=Cambiar zoom de interfaz de usuario MenuClass.IconSize=Tamaño del icono de las categorías MenuClass.UnCheckHighlighted=Desmarcar elementos resaltados -MenuClass.UnCheckRecursivelyHighlighted=Desmarcar elementos y subelementos resaltados +MenuClass.UncheckHighlightedAndSubItems=Desmarcar elementos y subelementos resaltados +MenuClass.UncheckHighlightedAndParent=Uncheck highlighted and parent items [TBT] +MenuClass.UncheckHighlightedAndReferences=Uncheck highlighted and reference items [TBT] +MenuClass.UncheckHighlightedAndReferencedBy=Uncheck highlighted and "referenced by" items [TBT] MenuListener.ChatNotFound=Chat principal no encontrado MenuListener.Cols=Columnas: MenuListener.ExportTree.Warn=¡Resalte 01 (un) nodo del árbol como referencia de exportación\! diff --git a/iped-app/resources/localization/iped-desktop-messages_fr_FR.properties b/iped-app/resources/localization/iped-desktop-messages_fr_FR.properties index 7ed824bdc6..b5fd73cc6d 100644 --- a/iped-app/resources/localization/iped-desktop-messages_fr_FR.properties +++ b/iped-app/resources/localization/iped-desktop-messages_fr_FR.properties @@ -211,7 +211,11 @@ MenuClass.AddToGraph=Ajouter à l''analyse de liens MenuClass.ChangeGalleryColCount=Modifier le nombre de colonnes de la galerie MenuClass.ChangeLayout=Changer la disposition Vertical/Horizontal MenuClass.CheckHighlighted=Vérifier les éléments en surbrillance -MenuClass.CheckRecursivelyHighlighted=Vérifier les sous-éléments et éléments en surbrillance +MenuClass.CheckAdvanced=Advanced Check... [TBT] +MenuClass.CheckHighlightedAndSubItems=Vérifier les sous-éléments et éléments en surbrillance +MenuClass.CheckHighlightedAndParent=Check highlighted and parent items [TBT] +MenuClass.CheckHighlightedAndReferences=Check highlighted and reference items [TBT] +MenuClass.CheckHighlightedAndReferencedBy=Check highlighted and "referenced by" items [TBT] MenuClass.ClearSearches=Supprimer l''historique des recherches MenuClass.ColorTheme=Couleur du Thème MenuClass.CopyViewerImage=Faire une capture d''écran de la visionneuse @@ -254,7 +258,10 @@ MenuClass.SaveBookmarks=Sauvegarder les favoris MenuClass.UiZoom=Réglage du zoom MenuClass.IconSize=Taille des icones MenuClass.UnCheckHighlighted=Décocher les éléments en surbrillance -MenuClass.UnCheckRecursivelyHighlighted=Décocher les éléments et sous-éléments en surbrillance +MenuClass.UncheckHighlightedAndSubItems=Décocher les éléments et sous-éléments en surbrillance +MenuClass.UncheckHighlightedAndParent=Uncheck highlighted and parent items [TBT] +MenuClass.UncheckHighlightedAndReferences=Uncheck highlighted and reference items [TBT] +MenuClass.UncheckHighlightedAndReferencedBy=Uncheck highlighted and "referenced by" items [TBT] MenuListener.ChatNotFound=Origine du chat non trouvé MenuListener.Cols=Colonnes : MenuListener.ExportTree.Warn=Selectionner 01 (un) nœud de l''arborescence comme référence d''export \! diff --git a/iped-app/resources/localization/iped-desktop-messages_it_IT.properties b/iped-app/resources/localization/iped-desktop-messages_it_IT.properties index a0747a92a6..933a9b1ace 100644 --- a/iped-app/resources/localization/iped-desktop-messages_it_IT.properties +++ b/iped-app/resources/localization/iped-desktop-messages_it_IT.properties @@ -211,7 +211,11 @@ MenuClass.AddToGraph=Aggiungi all''analisi dei collegamenti MenuClass.ChangeGalleryColCount=Cambia il numero di colonne della Galleria MenuClass.ChangeLayout=Cambia layout verticale/orizzontale MenuClass.CheckHighlighted=Seleziona gli elementi evidenziati -MenuClass.CheckRecursivelyHighlighted=Seleziona gli elementi evidenziati e i sotto-elementi +MenuClass.CheckAdvanced=Advanced Check... [TBT] +MenuClass.CheckHighlightedAndSubItems=Seleziona gli elementi evidenziati e i sotto-elementi +MenuClass.CheckHighlightedAndParent=Check highlighted and parent items [TBT] +MenuClass.CheckHighlightedAndReferences=Check highlighted and reference items [TBT] +MenuClass.CheckHighlightedAndReferencedBy=Check highlighted and "referenced by" items [TBT] MenuClass.ClearSearches=Cancella la cronologia di ricerca MenuClass.ColorTheme=Colore tema MenuClass.CopyViewerImage=Fai uno screenshot del Viewer @@ -254,7 +258,10 @@ MenuClass.SaveBookmarks=Salva Segnalibri MenuClass.UiZoom=Cambia lo zoom dell''interfaccia utente MenuClass.IconSize=Dimensione icona MenuClass.UnCheckHighlighted=Deseleziona elementi evidenziati -MenuClass.UnCheckRecursivelyHighlighted=Deseleziona gli elementi evidenziati e i sotto-elementi +MenuClass.UncheckHighlightedAndSubItems=Deseleziona gli elementi evidenziati e i sotto-elementi +MenuClass.UncheckHighlightedAndParent=Uncheck highlighted and parent items [TBT] +MenuClass.UncheckHighlightedAndReferences=Uncheck highlighted and reference items [TBT] +MenuClass.UncheckHighlightedAndReferencedBy=Uncheck highlighted and "referenced by" items [TBT] MenuListener.ChatNotFound=Chat d''origine non trovata MenuListener.Cols=Colonne: MenuListener.ExportTree.Warn=Evidenzia 01 (un) nodo dell''albero come riferimento all''esportazione\! diff --git a/iped-app/resources/localization/iped-desktop-messages_pt_BR.properties b/iped-app/resources/localization/iped-desktop-messages_pt_BR.properties index 6de2ea764f..59c92ad7e5 100644 --- a/iped-app/resources/localization/iped-desktop-messages_pt_BR.properties +++ b/iped-app/resources/localization/iped-desktop-messages_pt_BR.properties @@ -211,7 +211,11 @@ MenuClass.AddToGraph=Adicionar à análise de vínculos MenuClass.ChangeGalleryColCount=Alterar Nº Colunas da Galeria MenuClass.ChangeLayout=Alterar Disposição Vertical/Horizontal MenuClass.CheckHighlighted=Marcar itens destacados -MenuClass.CheckRecursivelyHighlighted=Marcar itens destacados e subitens +MenuClass.CheckAdvanced=Marcação avançada... +MenuClass.CheckHighlightedAndSubItems=Marcar itens destacados e subitens +MenuClass.CheckHighlightedAndParent=Marcar itens destacados e item pai +MenuClass.CheckHighlightedAndReferences=Marcar itens destacados e referências +MenuClass.CheckHighlightedAndReferencedBy=Marcar itens destacados e "referenciado por" MenuClass.ClearSearches=Limpar expressões pesquisadas MenuClass.ColorTheme=Tema de Cores MenuClass.CopyViewerImage=Copiar imagem do visualizador @@ -254,7 +258,10 @@ MenuClass.SaveBookmarks=Salvar marcadores MenuClass.UiZoom=Alterar Zoom da Interface MenuClass.IconSize=Tamanho dos Ícones MenuClass.UnCheckHighlighted=Remover marcação dos itens destacados -MenuClass.UnCheckRecursivelyHighlighted=Remover marcação dos itens destacados e subitens +MenuClass.UncheckHighlightedAndSubItems=Desmarcar itens destacados e subitens +MenuClass.UncheckHighlightedAndParent=Desmarcar itens destacados e item pai +MenuClass.UncheckHighlightedAndReferences=Desmarcar itens destacados e referências +MenuClass.UncheckHighlightedAndReferencedBy=Desmarcar itens destacados e "referenciado por" MenuListener.ChatNotFound=Chat pai não encontrado MenuListener.Cols=Colunas: MenuListener.ExportTree.Warn=Selecione 01 (um) nó na árvore de diretórios como base de exportação\! diff --git a/iped-app/src/main/java/iped/app/ui/App.java b/iped-app/src/main/java/iped/app/ui/App.java index 16cde7252c..2ca8c46a38 100644 --- a/iped-app/src/main/java/iped/app/ui/App.java +++ b/iped-app/src/main/java/iped/app/ui/App.java @@ -211,6 +211,7 @@ public class App extends JFrame implements WindowListener, IMultiSearchResultPro JButton searchButton, optionsButton, updateCaseData, helpButton, exportToZip; JCheckBox checkBox, recursiveTreeList, filterDuplicates; JTable resultsTable; + ResultTableListener resultTableListener; GalleryTable gallery; public HitsTable hitsTable; AppGraphAnalytics appGraphAnalytics; @@ -556,6 +557,7 @@ public void createGUI() { resultsModel = new ResultTableModel(); resultsTable = new JTable(resultsModel); + resultTableListener = new ResultTableListener(); resultsScroll = new JScrollPane(resultsTable); resultsTable.setFillsViewportHeight(true); resultsTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); @@ -778,9 +780,9 @@ protected void changed() { updateCaseData.addActionListener(appletListener); helpButton.addActionListener(appletListener); checkBox.addActionListener(appletListener); - resultsTable.getSelectionModel().addListSelectionListener(new ResultTableListener()); - resultsTable.addMouseListener(new ResultTableListener()); - resultsTable.addKeyListener(new ResultTableListener()); + resultsTable.getSelectionModel().addListSelectionListener(resultTableListener); + resultsTable.addMouseListener(resultTableListener); + resultsTable.addKeyListener(resultTableListener); duplicatesFilterer = new DuplicatesFilterer(); diff --git a/iped-app/src/main/java/iped/app/ui/BaseTableModel.java b/iped-app/src/main/java/iped/app/ui/BaseTableModel.java index 84110a2fdd..e8ea6a71bf 100644 --- a/iped-app/src/main/java/iped/app/ui/BaseTableModel.java +++ b/iped-app/src/main/java/iped/app/ui/BaseTableModel.java @@ -4,23 +4,30 @@ 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; +import org.apache.lucene.search.Query; import iped.app.ui.bookmarks.BookmarkIcon; +import iped.engine.search.IPEDSearcher; import iped.engine.search.LuceneSearchResult; import iped.engine.search.MultiSearchResult; import iped.engine.task.index.IndexItem; import iped.engine.util.Util; +import iped.properties.BasicProps; import iped.search.IMultiSearchResult; public abstract class BaseTableModel extends AbstractTableModel implements MouseListener, ListSelectionListener, SearchResultTableModel { private static final long serialVersionUID = 1L; + protected String sortResultsBy = BasicProps.NAME; + protected boolean cleanBeforeListItems; + protected LuceneSearchResult results = new LuceneSearchResult(0); protected int selectedIndex = -1; protected Document refDoc; @@ -138,5 +145,52 @@ public final void valueChanged(ListSelectionEvent evt) { public abstract void valueChanged(ListSelectionModel lsm); - public abstract void listItems(Document doc); + public abstract Query createQuery(Document doc); + + protected abstract void onListItemsResultsComplete(); + + public final void listItems(Document doc) { + + if (cleanBeforeListItems) { + results = new LuceneSearchResult(0); + fireTableDataChanged(); + } + + Query query = createQuery(doc); + + if (query != null) { + + try { + IPEDSearcher task = new IPEDSearcher(App.get().appCase, query, sortResultsBy); + task.setRewritequery(false); + results = MultiSearchResult.get(task.multiSearch(), App.get().appCase); + + final int length = results.getLength(); + + if (length > 0) { + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + onListItemsResultsComplete(); + } + }); + refDoc = doc; + } else { + refDoc = null; + } + + } catch (Exception e) { + results = new LuceneSearchResult(0); + refDoc = null; + e.printStackTrace(); + } + if (cleanBeforeListItems) { + fireTableDataChanged(); + } + } + + if (!cleanBeforeListItems) { + fireTableDataChanged(); + } + } } diff --git a/iped-app/src/main/java/iped/app/ui/BookmarksManager.java b/iped-app/src/main/java/iped/app/ui/BookmarksManager.java index 8fb2569acb..8eb83f83be 100644 --- a/iped-app/src/main/java/iped/app/ui/BookmarksManager.java +++ b/iped-app/src/main/java/iped/app/ui/BookmarksManager.java @@ -629,8 +629,8 @@ public void keyPressed(KeyEvent e) { } // Avoid conflict with keys that are used for item selection (space) and - // recursive item selection (R). - if (e.getKeyCode() == KeyEvent.VK_SPACE || e.getKeyCode() == 'R') { + // recursive item selection (R), parents (P), references (F) and referenced by (D) + if (e.getKeyCode() == KeyEvent.VK_SPACE || Arrays.asList('R', 'P', 'F', 'D').contains((char) e.getKeyCode())) { if (e.getSource() == list) { showMessage(Messages.getString("BookmarksManager.KeyStrokeAlert4")); e.consume(); diff --git a/iped-app/src/main/java/iped/app/ui/DuplicatesTableModel.java b/iped-app/src/main/java/iped/app/ui/DuplicatesTableModel.java index 994ad1e75d..8fcf5de06b 100644 --- a/iped-app/src/main/java/iped/app/ui/DuplicatesTableModel.java +++ b/iped-app/src/main/java/iped/app/ui/DuplicatesTableModel.java @@ -21,21 +21,28 @@ import java.awt.Rectangle; import javax.swing.ListSelectionModel; -import javax.swing.SwingUtilities; +import org.apache.commons.lang3.StringUtils; import org.apache.lucene.document.Document; +import org.apache.lucene.document.IntPoint; +import org.apache.lucene.index.Term; +import org.apache.lucene.search.BooleanClause; +import org.apache.lucene.search.BooleanClause.Occur; +import org.apache.lucene.search.BooleanQuery; +import org.apache.lucene.search.Query; +import org.apache.lucene.search.TermQuery; -import iped.engine.search.IPEDSearcher; -import iped.engine.search.LuceneSearchResult; -import iped.engine.search.MultiSearchResult; import iped.engine.task.index.IndexItem; import iped.properties.BasicProps; -import iped.search.IIPEDSearcher; public class DuplicatesTableModel extends BaseTableModel { private static final long serialVersionUID = 1L; + public DuplicatesTableModel() { + sortResultsBy = BasicProps.PATH; + } + @Override public Object getValueAt(int row, int col) { if (col == 3) { @@ -60,40 +67,27 @@ public void valueChanged(ListSelectionModel lsm) { } @Override - public void listItems(Document doc) { + public void onListItemsResultsComplete() { + App.get().duplicateDock.setTitleText(results.getLength() + Messages.getString("DuplicatesTableModel.Duplicates")); + } + @Override + public Query createQuery(Document doc) { String hash = doc.get(IndexItem.HASH); - if (hash == null || hash.trim().isEmpty()) - return; - - String textQuery = IndexItem.HASH + ":" + hash; + if (StringUtils.isBlank(hash)) { + return null; + } String id = doc.get(IndexItem.ID); String sourceUUID = doc.get(IndexItem.EVIDENCE_UUID); - textQuery += " && NOT (" + IndexItem.ID + ":" + id; - textQuery += " && " + IndexItem.EVIDENCE_UUID + ":" + sourceUUID + ")"; - - try { - IIPEDSearcher task = new IPEDSearcher(App.get().appCase, textQuery, BasicProps.PATH); - results = MultiSearchResult.get(task.multiSearch(), App.get().appCase); - - final int duplicates = results.getLength(); - - if (duplicates > 0) { - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - App.get().duplicateDock.setTitleText(duplicates + Messages.getString("DuplicatesTableModel.Duplicates")); - } - }); - } - - } catch (Exception e) { - results = new LuceneSearchResult(0); - e.printStackTrace(); - } + BooleanQuery.Builder queryBuilder = new BooleanQuery.Builder(); + queryBuilder.add(new TermQuery(new Term(IndexItem.HASH, hash.toLowerCase())), Occur.MUST); + queryBuilder.add(new BooleanClause(new BooleanQuery.Builder() + .add(IntPoint.newExactQuery(IndexItem.ID, Integer.parseInt(id)), Occur.MUST) + .add(new TermQuery(new Term(IndexItem.EVIDENCE_UUID, sourceUUID)), Occur.MUST) + .build(), Occur.MUST_NOT)); - fireTableDataChanged(); + return queryBuilder.build(); } } diff --git a/iped-app/src/main/java/iped/app/ui/MenuClass.java b/iped-app/src/main/java/iped/app/ui/MenuClass.java index 831c4567a1..1d3810f977 100644 --- a/iped-app/src/main/java/iped/app/ui/MenuClass.java +++ b/iped-app/src/main/java/iped/app/ui/MenuClass.java @@ -45,7 +45,8 @@ public class MenuClass extends JPopupMenu { private static final long serialVersionUID = 1L; - JMenuItem exportHighlighted, copyHighlighted, checkHighlighted, uncheckHighlighted, deepCheckHighlighted, deepUncheckHighlighted, readHighlighted, unreadHighlighted, exportChecked, copyChecked, saveBookmarks, loadBookmarks, + JMenuItem exportHighlighted, copyHighlighted, checkHighlighted, uncheckHighlighted, readHighlighted, unreadHighlighted, exportChecked, copyChecked, saveBookmarks, loadBookmarks, + checkHighlightedAndSubItems, uncheckHighlightedAndSubItems, checkHighlightedAndParent, uncheckHighlightedAndParent, checkHighlightedAndReferences, uncheckHighlightedAndReferences, checkHighlightedAndReferencedBy, uncheckHighlightedAndReferencedBy, changeGalleryColCount, defaultLayout, changeLayout, previewScreenshot, manageBookmarks, clearSearchHistory, importKeywords, navigateToParent, exportTerms, manageFilters, manageColumns, exportCheckedToZip, exportCheckedTreeToZip, exportTree, exportTreeChecked, similarDocs, openViewfile, createReport, resetColLayout, lastColLayout, saveColLayout, addToGraph, navigateToParentChat, pinFirstColumns, similarImagesCurrent, similarImagesExternal, similarFacesCurrent, similarFacesExternal, toggleTimelineView, uiZoom, catIconSize, savePanelsLayout, loadPanelsLayout; @@ -76,24 +77,55 @@ public MenuClass(IItem item) { uncheckHighlighted.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0)); this.add(uncheckHighlighted); - deepCheckHighlighted = new JMenuItem(Messages.getString("MenuClass.CheckRecursivelyHighlighted")); //$NON-NLS-1$ - deepCheckHighlighted.addActionListener(menuListener); - deepCheckHighlighted.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R, ActionEvent.CTRL_MASK)); - this.add(deepCheckHighlighted); - - deepUncheckHighlighted = new JMenuItem(Messages.getString("MenuClass.UnCheckRecursivelyHighlighted")); //$NON-NLS-1$ - deepUncheckHighlighted.addActionListener(menuListener); - deepUncheckHighlighted.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R, ActionEvent.ALT_MASK)); - this.add(deepUncheckHighlighted); - - /* - * readHighlighted = new JMenuItem("Marcar selecionados como lido"); - * readHighlighted.addActionListener(menuListener); this.add(readHighlighted); - * - * unreadHighlighted = new JMenuItem("Marcar selecionados como novo"); - * unreadHighlighted.addActionListener(menuListener); - * this.add(unreadHighlighted); - */ + JMenu submenu = new JMenu(Messages.getString("MenuClass.CheckAdvanced")); //$NON-NLS-1$ + this.add(submenu); + + checkHighlightedAndSubItems = new JMenuItem(Messages.getString("MenuClass.CheckHighlightedAndSubItems")); //$NON-NLS-1$ + checkHighlightedAndSubItems.addActionListener(menuListener); + checkHighlightedAndSubItems.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R, ActionEvent.CTRL_MASK)); + submenu.add(checkHighlightedAndSubItems); + + uncheckHighlightedAndSubItems = new JMenuItem(Messages.getString("MenuClass.UncheckHighlightedAndSubItems")); //$NON-NLS-1$ + uncheckHighlightedAndSubItems.addActionListener(menuListener); + uncheckHighlightedAndSubItems.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R, ActionEvent.ALT_MASK)); + submenu.add(uncheckHighlightedAndSubItems); + + submenu.addSeparator(); + + checkHighlightedAndParent = new JMenuItem(Messages.getString("MenuClass.CheckHighlightedAndParent")); //$NON-NLS-1$ + checkHighlightedAndParent.addActionListener(menuListener); + checkHighlightedAndParent.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_P, ActionEvent.CTRL_MASK)); + submenu.add(checkHighlightedAndParent); + + uncheckHighlightedAndParent = new JMenuItem(Messages.getString("MenuClass.UncheckHighlightedAndParent")); //$NON-NLS-1$ + uncheckHighlightedAndParent.addActionListener(menuListener); + uncheckHighlightedAndParent.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_P, ActionEvent.ALT_MASK)); + submenu.add(uncheckHighlightedAndParent); + + submenu.addSeparator(); + + checkHighlightedAndReferences = new JMenuItem(Messages.getString("MenuClass.CheckHighlightedAndReferences")); //$NON-NLS-1$ + checkHighlightedAndReferences.addActionListener(menuListener); + checkHighlightedAndReferences.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F, ActionEvent.CTRL_MASK)); + submenu.add(checkHighlightedAndReferences); + + uncheckHighlightedAndReferences = new JMenuItem(Messages.getString("MenuClass.UncheckHighlightedAndReferences")); //$NON-NLS-1$ + uncheckHighlightedAndReferences.addActionListener(menuListener); + uncheckHighlightedAndReferences.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F, ActionEvent.ALT_MASK)); + submenu.add(uncheckHighlightedAndReferences); + + submenu.addSeparator(); + + checkHighlightedAndReferencedBy = new JMenuItem(Messages.getString("MenuClass.CheckHighlightedAndReferencedBy")); //$NON-NLS-1$ + checkHighlightedAndReferencedBy.addActionListener(menuListener); + checkHighlightedAndReferencedBy.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_D, ActionEvent.CTRL_MASK)); + submenu.add(checkHighlightedAndReferencedBy); + + uncheckHighlightedAndReferencedBy = new JMenuItem(Messages.getString("MenuClass.UncheckHighlightedAndReferencedBy")); //$NON-NLS-1$ + uncheckHighlightedAndReferencedBy.addActionListener(menuListener); + uncheckHighlightedAndReferencedBy.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_D, ActionEvent.ALT_MASK)); + submenu.add(uncheckHighlightedAndReferencedBy); + this.addSeparator(); loadBookmarks = new JMenuItem(Messages.getString("MenuClass.LoadBookmarks")); //$NON-NLS-1$ @@ -113,7 +145,7 @@ public MenuClass(IItem item) { manageFilters.addActionListener(menuListener); this.add(manageFilters); - JMenu submenu = new JMenu(Messages.getString("MenuClass.ManageColumns")); //$NON-NLS-1$ + submenu = new JMenu(Messages.getString("MenuClass.ManageColumns")); //$NON-NLS-1$ this.add(submenu); manageColumns = new JMenuItem(Messages.getString("MenuClass.ManageVisibleCols")); //$NON-NLS-1$ diff --git a/iped-app/src/main/java/iped/app/ui/MenuListener.java b/iped-app/src/main/java/iped/app/ui/MenuListener.java index 8d8b274a65..d5348a5f19 100644 --- a/iped-app/src/main/java/iped/app/ui/MenuListener.java +++ b/iped-app/src/main/java/iped/app/ui/MenuListener.java @@ -24,8 +24,6 @@ import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; -import java.awt.event.KeyEvent; -import java.awt.event.KeyListener; import java.io.File; import java.util.ArrayList; import java.util.List; @@ -181,37 +179,36 @@ public void actionPerformed(ActionEvent e) { App.get().loadPanelLayout(); } else if (e.getSource() == menu.checkHighlighted) { - BookmarksController.get().setMultiSetting(true); - int col = App.get().resultsTable.convertColumnIndexToView(1); - for (Integer row : App.get().resultsTable.getSelectedRows()) { - App.get().resultsTable.setValueAt(true, row, col); - } - BookmarksController.get().setMultiSetting(false); - App.get().appCase.getMultiBookmarks().saveState(); - BookmarksController.get().updateUISelection(); + App.get().resultTableListener.itemSelection(true); } else if (e.getSource() == menu.uncheckHighlighted) { - BookmarksController.get().setMultiSetting(true); - int col = App.get().resultsTable.convertColumnIndexToView(1); - for (Integer row : App.get().resultsTable.getSelectedRows()) { - App.get().resultsTable.setValueAt(false, row, col); - } - BookmarksController.get().setMultiSetting(false); - App.get().appCase.getMultiBookmarks().saveState(); - BookmarksController.get().updateUISelection(); + App.get().resultTableListener.itemSelection(false); - } + } else if (e.getSource() == menu.checkHighlightedAndSubItems) { + App.get().resultTableListener.itemSelectionAndSubItems(true); + + } else if (e.getSource() == menu.uncheckHighlightedAndSubItems) { + App.get().resultTableListener.itemSelectionAndSubItems(false); - if (e.getSource() == menu.deepCheckHighlighted) { - KeyEvent keyCTRL_R_Pressed = new KeyEvent((Component) e.getSource(), KeyEvent.KEY_PRESSED, System.currentTimeMillis(), KeyEvent.CTRL_DOWN_MASK, KeyEvent.VK_R, KeyEvent.CHAR_UNDEFINED); - for (KeyListener kl : App.get().resultsTable.getListeners(KeyListener.class)) - kl.keyPressed(keyCTRL_R_Pressed); + } else if (e.getSource() == menu.checkHighlightedAndParent) { + App.get().resultTableListener.itemSelectionAndParent(true); - } else if (e.getSource() == menu.deepUncheckHighlighted) { - KeyEvent keyCTRL_R_Pressed = new KeyEvent((Component) e.getSource(), KeyEvent.KEY_PRESSED, System.currentTimeMillis(), KeyEvent.ALT_DOWN_MASK, KeyEvent.VK_R, KeyEvent.CHAR_UNDEFINED); - for (KeyListener kl : App.get().resultsTable.getListeners(KeyListener.class)) - kl.keyPressed(keyCTRL_R_Pressed); + } else if (e.getSource() == menu.uncheckHighlightedAndParent) { + App.get().resultTableListener.itemSelectionAndParent(false); + + } else if (e.getSource() == menu.checkHighlightedAndReferences) { + App.get().resultTableListener.itemSelectionAndReferences(true); + + } else if (e.getSource() == menu.uncheckHighlightedAndReferences) { + App.get().resultTableListener.itemSelectionAndReferences(false); + + } else if (e.getSource() == menu.checkHighlightedAndReferencedBy) { + App.get().resultTableListener.itemSelectionAndReferencedBy(true); + + } else if (e.getSource() == menu.uncheckHighlightedAndReferencedBy) { + App.get().resultTableListener.itemSelectionAndReferencedBy(false); } + if (e.getSource() == menu.readHighlighted) { BookmarksController.get().setMultiSetting(true); int col = App.get().resultsTable.convertColumnIndexToView(2); diff --git a/iped-app/src/main/java/iped/app/ui/ParentTableModel.java b/iped-app/src/main/java/iped/app/ui/ParentTableModel.java index cef3af6dc1..3f850be65b 100644 --- a/iped-app/src/main/java/iped/app/ui/ParentTableModel.java +++ b/iped-app/src/main/java/iped/app/ui/ParentTableModel.java @@ -21,19 +21,25 @@ import java.awt.Rectangle; import javax.swing.ListSelectionModel; -import javax.swing.SwingUtilities; import org.apache.lucene.document.Document; +import org.apache.lucene.document.IntPoint; +import org.apache.lucene.index.Term; +import org.apache.lucene.search.BooleanClause.Occur; +import org.apache.lucene.search.BooleanQuery; +import org.apache.lucene.search.Query; +import org.apache.lucene.search.TermQuery; + +import iped.properties.BasicProps; -import iped.engine.search.IPEDSearcher; -import iped.engine.search.LuceneSearchResult; -import iped.engine.search.MultiSearchResult; -import iped.engine.task.index.IndexItem; public class ParentTableModel extends BaseTableModel { private static final long serialVersionUID = 1L; + public ParentTableModel() { + } + @Override public void valueChanged(ListSelectionModel lsm) { App.get().getTextViewer().textTable.scrollRectToVisible(new Rectangle()); @@ -45,38 +51,24 @@ public void valueChanged(ListSelectionModel lsm) { } @Override - public void listItems(Document doc) { + public Query createQuery(Document doc) { - String textQuery = null; - String parentId = doc.get(IndexItem.PARENTID); - if (parentId != null) { - textQuery = IndexItem.ID + ":" + parentId; + String parentId = doc.get(BasicProps.PARENTID); + if (parentId == null) { + return null; } - String sourceUUID = doc.get(IndexItem.EVIDENCE_UUID); - textQuery += " && " + IndexItem.EVIDENCE_UUID + ":" + sourceUUID; + String sourceUUID = doc.get(BasicProps.EVIDENCE_UUID); - results = new LuceneSearchResult(0); + BooleanQuery.Builder queryBuilder = new BooleanQuery.Builder(); + queryBuilder.add(IntPoint.newExactQuery(BasicProps.ID, Integer.parseInt(parentId)), Occur.MUST); + queryBuilder.add(new TermQuery(new Term(BasicProps.EVIDENCE_UUID, sourceUUID)), Occur.MUST); - if (textQuery != null) { - try { - IPEDSearcher task = new IPEDSearcher(App.get().appCase, textQuery); - results = MultiSearchResult.get(task.multiSearch(), App.get().appCase); - - } catch (Exception e) { - e.printStackTrace(); - } - } - - if (results.getLength() > 0) { - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - App.get().parentDock.setTitleText(Messages.getString("ParentTableModel.ParentCount")); - } - }); - } + return queryBuilder.build(); + } - fireTableDataChanged(); + @Override + public void onListItemsResultsComplete() { + App.get().parentDock.setTitleText(Messages.getString("ParentTableModel.ParentCount")); } } diff --git a/iped-app/src/main/java/iped/app/ui/ReferencedByTableModel.java b/iped-app/src/main/java/iped/app/ui/ReferencedByTableModel.java index 339f11d6e4..d762a6bb8e 100644 --- a/iped-app/src/main/java/iped/app/ui/ReferencedByTableModel.java +++ b/iped-app/src/main/java/iped/app/ui/ReferencedByTableModel.java @@ -22,15 +22,18 @@ import java.util.stream.Collectors; import javax.swing.ListSelectionModel; -import javax.swing.SwingUtilities; +import org.apache.commons.lang3.StringUtils; import org.apache.lucene.document.Document; +import org.apache.lucene.search.BooleanClause.Occur; +import org.apache.lucene.search.BooleanQuery; +import org.apache.lucene.search.Query; import iped.data.IItem; -import iped.engine.search.IPEDSearcher; -import iped.engine.search.LuceneSearchResult; -import iped.engine.search.MultiSearchResult; +import iped.engine.search.QueryBuilder; import iped.engine.task.HashTask; +import iped.exception.ParseException; +import iped.exception.QueryNodeException; import iped.parsers.ares.AresParser; import iped.parsers.emule.KnownMetParser; import iped.parsers.shareaza.ShareazaLibraryDatParser; @@ -41,6 +44,10 @@ public class ReferencedByTableModel extends BaseTableModel { private static final long serialVersionUID = 1L; + public ReferencedByTableModel() { + cleanBeforeListItems = true; + } + @Override public void valueChanged(ListSelectionModel lsm) { int id = results.getLuceneIds()[selectedIndex]; @@ -68,46 +75,30 @@ public void valueChanged(ListSelectionModel lsm) { } @Override - public void listItems(Document doc) { + public Query createQuery(Document doc) { + BooleanQuery.Builder queryBuilder = new BooleanQuery.Builder(); + // hashes String md5 = doc.get(HashTask.HASH.MD5.toString()); String sha1 = doc.get(HashTask.HASH.SHA1.toString()); String sha256 = doc.get(HashTask.HASH.SHA256.toString()); String edonkey = doc.get(HashTask.HASH.EDONKEY.toString()); - String hashes = Arrays.asList(md5, sha1, sha256, edonkey).stream().filter(a -> a != null).collect(Collectors.joining(" ")); - - if (hashes.isEmpty()) { - results = new LuceneSearchResult(0); - refDoc = null; - } else { - String textQuery = ExtraProperties.LINKED_ITEMS + ":(" + hashes + ") "; - textQuery += ExtraProperties.SHARED_HASHES + ":(" + hashes + ")"; - + String hashes = Arrays.asList(md5, sha1, sha256, edonkey).stream().filter(StringUtils::isNotBlank).collect(Collectors.joining(" ")); + if (!hashes.isEmpty()) { + QueryBuilder b = new QueryBuilder(App.get().appCase); try { - IPEDSearcher task = new IPEDSearcher(App.get().appCase, textQuery, BasicProps.NAME); - results = MultiSearchResult.get(task.multiSearch(), App.get().appCase); - - final int length = results.getLength(); - - if (length > 0) { - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - App.get().referencedByDock.setTitleText(Messages.getString("ReferencedByTab.Title") + " " + length); - } - }); - refDoc = doc; - } else { - refDoc = null; - } - - } catch (Exception e) { - results = new LuceneSearchResult(0); - refDoc = null; + queryBuilder.add(b.getQuery(ExtraProperties.LINKED_ITEMS + ":(" + hashes + ") "), Occur.SHOULD); + queryBuilder.add(b.getQuery(ExtraProperties.SHARED_HASHES + ":(" + hashes + ")"), Occur.SHOULD); + } catch (ParseException | QueryNodeException e) { e.printStackTrace(); } } - fireTableDataChanged(); + return queryBuilder.build(); + } + + @Override + public void onListItemsResultsComplete() { + App.get().referencedByDock.setTitleText(Messages.getString("ReferencedByTab.Title") + " " + results.getLength()); } } diff --git a/iped-app/src/main/java/iped/app/ui/ReferencingTableModel.java b/iped-app/src/main/java/iped/app/ui/ReferencingTableModel.java index 8ea2e52b58..06af391441 100644 --- a/iped-app/src/main/java/iped/app/ui/ReferencingTableModel.java +++ b/iped-app/src/main/java/iped/app/ui/ReferencingTableModel.java @@ -18,20 +18,24 @@ */ package iped.app.ui; +import java.util.Arrays; +import java.util.Set; +import java.util.stream.Collectors; + import javax.swing.ListSelectionModel; -import javax.swing.SwingUtilities; +import org.apache.commons.lang3.StringUtils; import org.apache.lucene.document.Document; -import org.apache.lucene.index.Term; import org.apache.lucene.search.BooleanClause.Occur; import org.apache.lucene.search.BooleanQuery; import org.apache.lucene.search.Query; -import org.apache.lucene.search.TermQuery; +import org.apache.lucene.search.TermInSetQuery; +import org.apache.lucene.util.BytesRef; -import iped.engine.search.IPEDSearcher; -import iped.engine.search.LuceneSearchResult; -import iped.engine.search.MultiSearchResult; +import iped.engine.search.QueryBuilder; import iped.engine.task.HashTask; +import iped.exception.ParseException; +import iped.exception.QueryNodeException; import iped.parsers.ares.AresParser; import iped.parsers.emule.KnownMetParser; import iped.parsers.shareaza.ShareazaLibraryDatParser; @@ -42,6 +46,10 @@ public class ReferencingTableModel extends BaseTableModel { private static final long serialVersionUID = 1L; + public ReferencingTableModel() { + cleanBeforeListItems = true; + } + @Override public void valueChanged(ListSelectionModel lsm) { int id = results.getLuceneIds()[selectedIndex]; @@ -51,66 +59,47 @@ public void valueChanged(ListSelectionModel lsm) { } @Override - public void listItems(Document doc) { - - // clear table, searching for refs can take some time if they are thousands - results = new LuceneSearchResult(0); - fireTableDataChanged(); - - StringBuilder textQuery = null; - Query query = null; + public Query createQuery(Document doc) { + BooleanQuery.Builder queryBuilder = new BooleanQuery.Builder(); + // linkedItems queries String[] linkedItems = doc.getValues(ExtraProperties.LINKED_ITEMS); - if (linkedItems != null && linkedItems.length > 0) { - textQuery = new StringBuilder(); + if (linkedItems.length > 0) { + QueryBuilder b = new QueryBuilder(App.get().appCase); for (String q : linkedItems) { - textQuery.append("(").append(q).append(") "); - } - } else { - linkedItems = doc.getValues(ExtraProperties.SHARED_HASHES); - if (linkedItems != null && linkedItems.length > 0) { - String term; - String mediaType = doc.get(BasicProps.CONTENTTYPE); - if (KnownMetParser.EMULE_MIME_TYPE.equals(mediaType)) { - term = HashTask.HASH.EDONKEY.toString(); - } else if (AresParser.ARES_MIME_TYPE.equals(mediaType)) { - term = HashTask.HASH.SHA1.toString(); - } else if (ShareazaLibraryDatParser.LIBRARY_DAT_MIME_TYPE.equals(mediaType)) { - term = HashTask.HASH.MD5.toString(); - } else { - term = BasicProps.HASH; + try { + queryBuilder.add(b.getQuery(q), Occur.SHOULD); + } catch (ParseException | QueryNodeException e) { + e.printStackTrace(); } - BooleanQuery.Builder builder = new BooleanQuery.Builder(); - for (String hash : linkedItems) { - builder.add(new TermQuery(new Term(term, hash)), Occur.SHOULD); - } - query = builder.build(); } } - if (textQuery != null || query != null) { - try { - IPEDSearcher task = query != null ? new IPEDSearcher(App.get().appCase, query, BasicProps.NAME) : new IPEDSearcher(App.get().appCase, textQuery.toString(), BasicProps.NAME); - task.setRewritequery(false); - results = MultiSearchResult.get(task.multiSearch(), App.get().appCase); - - final int length = results.getLength(); - - if (length > 0) { - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - App.get().referencesDock.setTitleText(Messages.getString("ReferencesTab.Title") + " " + length); - } - }); - } - - } catch (Exception e) { - results = new LuceneSearchResult(0); - e.printStackTrace(); + // sharedHashes + String[] sharedHashes = doc.getValues(ExtraProperties.SHARED_HASHES); + if (sharedHashes.length > 0) { + String field; + String mediaType = doc.get(BasicProps.CONTENTTYPE); + if (KnownMetParser.EMULE_MIME_TYPE.equals(mediaType)) { + field = HashTask.HASH.EDONKEY.toString(); + } else if (AresParser.ARES_MIME_TYPE.equals(mediaType)) { + field = HashTask.HASH.SHA1.toString(); + } else if (ShareazaLibraryDatParser.LIBRARY_DAT_MIME_TYPE.equals(mediaType)) { + field = HashTask.HASH.MD5.toString(); + } else { + field = BasicProps.HASH; } + + Set hashes = Arrays.asList(sharedHashes).stream().filter(StringUtils::isNotBlank) + .map(h -> new BytesRef(h)).collect(Collectors.toSet()); + queryBuilder.add(new TermInSetQuery(field, hashes), Occur.SHOULD); } - fireTableDataChanged(); + return queryBuilder.build(); + } + + @Override + public void onListItemsResultsComplete() { + App.get().referencesDock.setTitleText(Messages.getString("ReferencesTab.Title") + " " + results.getLength()); } } diff --git a/iped-app/src/main/java/iped/app/ui/ResultTableListener.java b/iped-app/src/main/java/iped/app/ui/ResultTableListener.java index 24a8c9bd22..c1f041b5a8 100644 --- a/iped-app/src/main/java/iped/app/ui/ResultTableListener.java +++ b/iped-app/src/main/java/iped/app/ui/ResultTableListener.java @@ -19,6 +19,7 @@ package iped.app.ui; import java.awt.Component; +import java.awt.Dialog; import java.awt.Rectangle; import java.awt.Toolkit; import java.awt.datatransfer.Clipboard; @@ -30,13 +31,17 @@ import java.awt.event.MouseListener; import java.text.Collator; import java.util.List; +import java.util.concurrent.Executor; +import java.util.concurrent.Executors; import javax.swing.JTable; import javax.swing.RowSorter.SortKey; +import javax.swing.SwingUtilities; import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; -import javax.swing.table.TableColumnModel; +import org.apache.lucene.document.Document; +import org.apache.lucene.search.Query; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -45,9 +50,9 @@ import iped.data.IItemId; import iped.engine.search.IPEDSearcher; import iped.engine.search.MultiSearchResult; -import iped.properties.BasicProps; import iped.viewers.ATextViewer; import iped.viewers.components.HitsTableModel; +import iped.viewers.util.ProgressDialog; public class ResultTableListener implements ListSelectionListener, MouseListener, KeyListener { @@ -59,6 +64,8 @@ public class ResultTableListener implements ListSelectionListener, MouseListener private String lastKeyString = ""; //$NON-NLS-1$ private Collator collator = Collator.getInstance(); + private Executor executor = Executors.newSingleThreadExecutor(); + public ResultTableListener() { collator.setStrength(Collator.PRIMARY); } @@ -184,12 +191,6 @@ private void showContextMenu(IItemId itemId, MouseEvent evt) { IItemId id = getSelectedItemId(rowIndex); - TableColumnModel cm = resultsTable.getTableHeader().getColumnModel(); - int pos = 0; - for (int i = 0; i < colIndex; i++) { - pos += cm.getColumn(i).getWidth(); - } - String value = (String) resultsTable.getValueAt(rowIndex, colIndex); colIndex = resultsTable.convertColumnIndexToModel(colIndex); String field = ((ResultTableModel) resultsTable.getModel()).getColumnFieldName(colIndex); @@ -243,22 +244,45 @@ public void keyPressed(KeyEvent evt) { clipboard.setContents(selection, null); evt.consume(); } else if (evt.getKeyCode() == KeyEvent.VK_SPACE) { - itemSelection(); + itemSelectionToggle(); evt.consume(); } else if (evt.getKeyCode() == KeyEvent.VK_R && ((evt.getModifiersEx() & KeyEvent.CTRL_DOWN_MASK) != 0)) { - // Shortcut to Deep-Selection (Item plus sub-items) - recursiveItemSelection(true); + itemSelectionAndSubItems(true); evt.consume(); } else if (evt.getKeyCode() == KeyEvent.VK_R && ((evt.getModifiersEx() & KeyEvent.ALT_DOWN_MASK) != 0)) { - // Shortcut to Deep-Selection Remove (Item plus sub-items) - recursiveItemSelection(false); + itemSelectionAndSubItems(false); + evt.consume(); + } else if (evt.getKeyCode() == KeyEvent.VK_P && ((evt.getModifiersEx() & KeyEvent.CTRL_DOWN_MASK) != 0)) { + itemSelectionAndParent(true); + evt.consume(); + } else if (evt.getKeyCode() == KeyEvent.VK_P && ((evt.getModifiersEx() & KeyEvent.ALT_DOWN_MASK) != 0)) { + itemSelectionAndParent(false); + evt.consume(); + } else if (evt.getKeyCode() == KeyEvent.VK_D && ((evt.getModifiersEx() & KeyEvent.CTRL_DOWN_MASK) != 0)) { + itemSelectionAndReferencedBy(true); + evt.consume(); + } else if (evt.getKeyCode() == KeyEvent.VK_D && ((evt.getModifiersEx() & KeyEvent.ALT_DOWN_MASK) != 0)) { + itemSelectionAndReferencedBy(false); + evt.consume(); + } else if (evt.getKeyCode() == KeyEvent.VK_F && ((evt.getModifiersEx() & KeyEvent.CTRL_DOWN_MASK) != 0)) { + itemSelectionAndReferences(true); + evt.consume(); + } else if (evt.getKeyCode() == KeyEvent.VK_F && ((evt.getModifiersEx() & KeyEvent.ALT_DOWN_MASK) != 0)) { + itemSelectionAndReferences(false); evt.consume(); } else BookmarksManager.get().keyPressed(evt); } - public void itemSelection() { + private ProgressDialog createProgressDialog() { + ProgressDialog d = new ProgressDialog(App.get(), null, false, 200, Dialog.ModalityType.APPLICATION_MODAL); + d.setNote(Messages.getString("App.Wait")); //$NON-NLS-1$ + return d; + } + + public void itemSelectionToggle() { + int col = App.get().resultsTable.convertColumnIndexToView(1); int firstRow = App.get().resultsTable.getSelectedRow(); boolean value = true; @@ -266,20 +290,13 @@ public void itemSelection() { value = false; } - BookmarksController.get().setMultiSetting(true); - App.get().resultsTable.setUpdateSelectionOnSort(false); - int[] selectedRows = App.get().resultsTable.getSelectedRows(); - for (int i = 0; i < selectedRows.length; i++) { - if (i == selectedRows.length - 1) { - BookmarksController.get().setMultiSetting(false); - App.get().resultsTable.setUpdateSelectionOnSort(true); - } - App.get().resultsTable.setValueAt(value, selectedRows[i], col); - } + itemSelection(value); } - public void recursiveItemSelection(boolean value) { + public void itemSelection(boolean value) { + int col = App.get().resultsTable.convertColumnIndexToView(1); + BookmarksController.get().setMultiSetting(true); App.get().resultsTable.setUpdateSelectionOnSort(false); int[] selectedRows = App.get().resultsTable.getSelectedRows(); @@ -289,42 +306,78 @@ public void recursiveItemSelection(boolean value) { App.get().resultsTable.setUpdateSelectionOnSort(true); } App.get().resultsTable.setValueAt(value, selectedRows[i], col); - - int modelIndex = App.get().resultsTable.convertRowIndexToModel(selectedRows[i]); - selectAllSubitems(value, App.get().ipedResult.getItem(modelIndex)); } BookmarksController.get().updateUI(); App.get().subItemTable.repaint(); } - /** - * Perform selection of all subitems - * - * @param state - * - which state to set true or false - * @param rootID - * - parent of the selection - */ - private void selectAllSubitems(boolean state, IItemId rootID) { - try { - IItem item = App.get().appCase.getItemByItemId(rootID); - if (item.hasChildren() || item.isDir()) { // Filter subItems which have children or are directories. - logger.debug("Searching items with evidenceUUID {} id {}", item.getDataSource().getUUID(), item.getId()); - String query = BasicProps.EVIDENCE_UUID + ":" + item.getDataSource().getUUID() + " AND " + BasicProps.PARENTIDs + ":" + rootID.getId(); - IPEDSearcher task = new IPEDSearcher(App.get().appCase, query); - MultiSearchResult result = task.multiSearch(); - if (result.getLength() > 0) { - logger.debug("Found {} subitems of sourceId {} id {}", result.getLength(), rootID.getSourceId(), rootID.getId()); - for (IItemId subItem : result.getIterator()) { - App.get().appCase.getMultiBookmarks().setChecked((Boolean) state, subItem); + public void itemSelectionAndResultsByQuery(boolean value, BaseTableModel tableModel) { + ProgressDialog dialog = createProgressDialog(); + executor.execute(() -> { + try { + int col = App.get().resultsTable.convertColumnIndexToView(1); + BookmarksController.get().setMultiSetting(true); + App.get().resultsTable.setUpdateSelectionOnSort(false); + int[] selectedRows = App.get().resultsTable.getSelectedRows(); + dialog.setMaximum(selectedRows.length); + for (int i = 0; i < selectedRows.length; i++) { + + // item selection + if (i == selectedRows.length - 1) { + BookmarksController.get().setMultiSetting(false); + App.get().resultsTable.setUpdateSelectionOnSort(true); + } + App.get().resultsTable.setValueAt(value, selectedRows[i], col); + + // query results selection + int selectedIndex = App.get().resultsTable.convertRowIndexToModel(selectedRows[i]); + IItemId selectedItemId = App.get().ipedResult.getItem(selectedIndex); + final int selectedDocId = App.get().appCase.getLuceneId(selectedItemId); + Document selectedDoc = App.get().appCase.getSearcher().doc(selectedDocId); + Query query = tableModel.createQuery(selectedDoc); + if (query != null) { + IPEDSearcher task = new IPEDSearcher(App.get().appCase, query); + task.setRewritequery(false); + MultiSearchResult result = task.multiSearch(); + if (result.getLength() > 0) { + logger.debug("Found {} results of sourceId {} id {}", result.getLength(), selectedItemId.getSourceId(), selectedItemId.getId()); + for (IItemId subItem : result.getIterator()) { + App.get().appCase.getMultiBookmarks().setChecked((Boolean) value, subItem); + } + } + } + + dialog.setProgress(i); + if (dialog.isCanceled()) { + return; } } + } catch (Exception e) { + logger.error("Error selecting item and its query results", e); + } finally { + SwingUtilities.invokeLater(() -> { + dialog.close(); + BookmarksController.get().updateUI(); + App.get().subItemTable.repaint(); + }); } + }); + } - } catch (Exception e) { - logger.debug("Error :" + e.getLocalizedMessage()); - e.printStackTrace(); - } + public void itemSelectionAndSubItems(boolean value) { + itemSelectionAndResultsByQuery(value, App.get().subItemModel); + } + + public void itemSelectionAndParent(boolean value) { + itemSelectionAndResultsByQuery(value, App.get().parentItemModel); + } + + public void itemSelectionAndReferences(boolean value) { + itemSelectionAndResultsByQuery(value, App.get().referencesModel); + } + + public void itemSelectionAndReferencedBy(boolean value) { + itemSelectionAndResultsByQuery(value, App.get().referencedByModel); } /** diff --git a/iped-app/src/main/java/iped/app/ui/SubitemTableModel.java b/iped-app/src/main/java/iped/app/ui/SubitemTableModel.java index 3f47efb7bc..47c63bb1a0 100644 --- a/iped-app/src/main/java/iped/app/ui/SubitemTableModel.java +++ b/iped-app/src/main/java/iped/app/ui/SubitemTableModel.java @@ -21,14 +21,15 @@ import java.awt.Rectangle; import javax.swing.ListSelectionModel; -import javax.swing.SwingUtilities; import org.apache.lucene.document.Document; +import org.apache.lucene.document.IntPoint; +import org.apache.lucene.index.Term; +import org.apache.lucene.search.BooleanClause.Occur; +import org.apache.lucene.search.BooleanQuery; +import org.apache.lucene.search.Query; +import org.apache.lucene.search.TermQuery; -import iped.engine.search.IPEDSearcher; -import iped.engine.search.LuceneSearchResult; -import iped.engine.search.MultiSearchResult; -import iped.engine.task.index.IndexItem; import iped.properties.BasicProps; import iped.utils.LocalizedFormat; @@ -36,6 +37,9 @@ public class SubitemTableModel extends BaseTableModel { private static final long serialVersionUID = 1L; + public SubitemTableModel() { + } + @Override public void valueChanged(ListSelectionModel lsm) { App.get().getTextViewer().textTable.scrollRectToVisible(new Rectangle()); @@ -47,35 +51,20 @@ public void valueChanged(ListSelectionModel lsm) { } @Override - public void listItems(Document doc) { - - String parentId = doc.get(IndexItem.ID); - - String textQuery = IndexItem.PARENTID + ":" + parentId; + public Query createQuery(Document doc) { - String sourceUUID = doc.get(IndexItem.EVIDENCE_UUID); - textQuery += " && " + IndexItem.EVIDENCE_UUID + ":" + sourceUUID; + String id = doc.get(BasicProps.ID); + String sourceUUID = doc.get(BasicProps.EVIDENCE_UUID); - try { - IPEDSearcher task = new IPEDSearcher(App.get().appCase, textQuery, BasicProps.NAME); - results = MultiSearchResult.get(task.multiSearch(), App.get().appCase); + BooleanQuery.Builder queryBuilder = new BooleanQuery.Builder(); + queryBuilder.add(IntPoint.newExactQuery(BasicProps.PARENTID, Integer.parseInt(id)), Occur.MUST); + queryBuilder.add(new TermQuery(new Term(BasicProps.EVIDENCE_UUID, sourceUUID)), Occur.MUST); - final int sumSubitens = results.getLength(); - - if (sumSubitens > 0) { - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - App.get().subitemDock.setTitleText(LocalizedFormat.format(sumSubitens) + Messages.getString("SubitemTableModel.Subitens")); - } - }); - } - - } catch (Exception e) { - results = new LuceneSearchResult(0); - e.printStackTrace(); - } + return queryBuilder.build(); + } - fireTableDataChanged(); + @Override + public void onListItemsResultsComplete() { + App.get().subitemDock.setTitleText(LocalizedFormat.format(results.getLength()) + Messages.getString("SubitemTableModel.Subitens")); } }