From f6d6d34cded44045087246e83d2caf2906ff9be1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Berenguel?= Date: Mon, 12 Aug 2024 16:43:11 -0300 Subject: [PATCH 01/12] #1631: feature to select items and (subItems / parent / references / referencedBy) --- .../iped-desktop-messages.properties | 11 +- .../iped-desktop-messages_de_DE.properties | 11 +- .../iped-desktop-messages_es_AR.properties | 11 +- .../iped-desktop-messages_fr_FR.properties | 11 +- .../iped-desktop-messages_it_IT.properties | 11 +- .../iped-desktop-messages_pt_BR.properties | 11 +- iped-app/src/main/java/iped/app/ui/App.java | 8 +- .../src/main/java/iped/app/ui/MenuClass.java | 72 ++++-- .../main/java/iped/app/ui/MenuListener.java | 51 ++-- .../java/iped/app/ui/ResultTableListener.java | 234 +++++++++++++++++- 10 files changed, 362 insertions(+), 69 deletions(-) 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 2e93746f9a..b45ba63a74 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/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/ResultTableListener.java b/iped-app/src/main/java/iped/app/ui/ResultTableListener.java index 24a8c9bd22..2d31410485 100644 --- a/iped-app/src/main/java/iped/app/ui/ResultTableListener.java +++ b/iped-app/src/main/java/iped/app/ui/ResultTableListener.java @@ -29,7 +29,9 @@ import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.text.Collator; +import java.util.Arrays; import java.util.List; +import java.util.stream.Collectors; import javax.swing.JTable; import javax.swing.RowSorter.SortKey; @@ -37,6 +39,12 @@ import javax.swing.event.ListSelectionListener; import javax.swing.table.TableColumnModel; +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.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -44,8 +52,15 @@ import iped.data.IItem; import iped.data.IItemId; import iped.engine.search.IPEDSearcher; +import iped.engine.search.LuceneSearchResult; import iped.engine.search.MultiSearchResult; +import iped.engine.task.HashTask; +import iped.engine.task.index.IndexItem; +import iped.parsers.ares.AresParser; +import iped.parsers.emule.KnownMetParser; +import iped.parsers.shareaza.ShareazaLibraryDatParser; import iped.properties.BasicProps; +import iped.properties.ExtraProperties; import iped.viewers.ATextViewer; import iped.viewers.components.HitsTableModel; @@ -243,22 +258,39 @@ 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() { + public void itemSelectionToggle() { + int col = App.get().resultsTable.convertColumnIndexToView(1); int firstRow = App.get().resultsTable.getSelectedRow(); boolean value = true; @@ -266,6 +298,13 @@ public void itemSelection() { value = false; } + itemSelection(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(); @@ -276,9 +315,11 @@ public void itemSelection() { } App.get().resultsTable.setValueAt(value, selectedRows[i], col); } + BookmarksController.get().updateUI(); + App.get().subItemTable.repaint(); } - public void recursiveItemSelection(boolean value) { + public void itemSelectionAndSubItems(boolean value) { int col = App.get().resultsTable.convertColumnIndexToView(1); BookmarksController.get().setMultiSetting(true); App.get().resultsTable.setUpdateSelectionOnSort(false); @@ -297,6 +338,63 @@ public void recursiveItemSelection(boolean value) { App.get().subItemTable.repaint(); } + public void itemSelectionAndParent(boolean value) { + int col = App.get().resultsTable.convertColumnIndexToView(1); + 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); + + int modelIndex = App.get().resultsTable.convertRowIndexToModel(selectedRows[i]); + selectReferencedParent(value, App.get().ipedResult.getItem(modelIndex)); + } + BookmarksController.get().updateUI(); + App.get().subItemTable.repaint(); + } + + public void itemSelectionAndReferences(boolean value) { + int col = App.get().resultsTable.convertColumnIndexToView(1); + 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); + + int modelIndex = App.get().resultsTable.convertRowIndexToModel(selectedRows[i]); + selectReferencetems(value, App.get().ipedResult.getItem(modelIndex)); + } + BookmarksController.get().updateUI(); + App.get().subItemTable.repaint(); + } + + public void itemSelectionAndReferencedBy(boolean value) { + int col = App.get().resultsTable.convertColumnIndexToView(1); + 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); + + int modelIndex = App.get().resultsTable.convertRowIndexToModel(selectedRows[i]); + selectReferencedByItems(value, App.get().ipedResult.getItem(modelIndex)); + } + BookmarksController.get().updateUI(); + App.get().subItemTable.repaint(); + } + /** * Perform selection of all subitems * @@ -327,6 +425,128 @@ private void selectAllSubitems(boolean state, IItemId rootID) { } } + private void selectReferencedParent(boolean state, IItemId rootId) { + + try { + final int docId = App.get().appCase.getLuceneId(rootId); + Document doc = App.get().appCase.getSearcher().doc(docId); + + String parentId = doc.get(IndexItem.PARENTID); + if (parentId == null) { + return; + } + String sourceUUID = doc.get(IndexItem.EVIDENCE_UUID); + + String textQuery = IndexItem.ID + ":" + parentId + " && " + IndexItem.EVIDENCE_UUID + ":" + sourceUUID; + + IPEDSearcher task = new IPEDSearcher(App.get().appCase, textQuery, BasicProps.NAME); + LuceneSearchResult results = MultiSearchResult.get(task.multiSearch(), App.get().appCase); + + if (results.getLength() > 0) { + for (int resDocId : results.getLuceneIds()) { + App.get().appCase.getMultiBookmarks().setChecked((Boolean) state, App.get().appCase.getItemId(resDocId)); + } + } + + } catch (Exception e) { + logger.error("Error :" + e.getLocalizedMessage()); + e.printStackTrace(); + } + } + + private void selectReferencedByItems(boolean state, IItemId rootId) { + + try { + final int docId = App.get().appCase.getLuceneId(rootId); + Document doc = App.get().appCase.getSearcher().doc(docId); + + 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()) { + return; + } + + String textQuery = ExtraProperties.LINKED_ITEMS + ":(" + hashes + ") "; + textQuery += ExtraProperties.SHARED_HASHES + ":(" + hashes + ")"; + + IPEDSearcher task = new IPEDSearcher(App.get().appCase, textQuery, BasicProps.NAME); + LuceneSearchResult results = MultiSearchResult.get(task.multiSearch(), App.get().appCase); + + if (results.getLength() > 0) { + for (int resDocId : results.getLuceneIds()) { + App.get().appCase.getMultiBookmarks().setChecked((Boolean) state, + App.get().appCase.getItemId(resDocId)); + } + } + + } catch (Exception e) { + logger.error("Error :" + e.getLocalizedMessage()); + e.printStackTrace(); + } + } + + private void selectReferencetems(boolean state, IItemId rootId) { + try { + + final int docId = App.get().appCase.getLuceneId(rootId); + Document doc = App.get().appCase.getSearcher().doc(docId); + + StringBuilder textQuery = null; + Query query = null; + + String[] linkedItems = doc.getValues(ExtraProperties.LINKED_ITEMS); + if (linkedItems != null && linkedItems.length > 0) { + textQuery = new StringBuilder(); + 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; + } + 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) { + + IPEDSearcher task = query != null ? new IPEDSearcher(App.get().appCase, query, BasicProps.NAME) + : new IPEDSearcher(App.get().appCase, textQuery.toString(), BasicProps.NAME); + task.setRewritequery(false); + LuceneSearchResult results = MultiSearchResult.get(task.multiSearch(), App.get().appCase); + + if (results.getLength() > 0) { + for (int resDocId : results.getLuceneIds()) { + App.get().appCase.getMultiBookmarks().setChecked((Boolean) state, + App.get().appCase.getItemId(resDocId)); + } + } + } + } catch (Exception e) { + logger.error("Error :" + e.getLocalizedMessage()); + e.printStackTrace(); + } + } + /** * Add a simple "type-to-find" feature to the table. It works on the currently * sorted column, if it uses a String comparator, so it will not work on numeric From 5f353d1c85ae24b03be6f74495959aa5a2b246a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Berenguel?= Date: Mon, 12 Aug 2024 17:06:31 -0300 Subject: [PATCH 02/12] #1631: avoid conflict with keys that are used for item selection --- iped-app/src/main/java/iped/app/ui/BookmarksManager.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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(); From edd5f6f07b67197d5e35aba9c90f541778af2063 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Berenguel?= Date: Mon, 12 Aug 2024 17:59:39 -0300 Subject: [PATCH 03/12] #1631: remove unsed code --- .../src/main/java/iped/app/ui/ResultTableListener.java | 7 ------- 1 file changed, 7 deletions(-) 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 2d31410485..3063214eaa 100644 --- a/iped-app/src/main/java/iped/app/ui/ResultTableListener.java +++ b/iped-app/src/main/java/iped/app/ui/ResultTableListener.java @@ -37,7 +37,6 @@ import javax.swing.RowSorter.SortKey; 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.index.Term; @@ -199,12 +198,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); From 01393092f3eed5ab32faf867c8c2fa753141c536 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Berenguel?= Date: Mon, 12 Aug 2024 18:01:48 -0300 Subject: [PATCH 04/12] #1631: run selection in background with dialog for slow selections --- .../java/iped/app/ui/ResultTableListener.java | 161 +++++++++++++----- 1 file changed, 114 insertions(+), 47 deletions(-) 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 3063214eaa..7549212190 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; @@ -31,10 +32,13 @@ import java.text.Collator; import java.util.Arrays; import java.util.List; +import java.util.concurrent.Executor; +import java.util.concurrent.Executors; import java.util.stream.Collectors; import javax.swing.JTable; import javax.swing.RowSorter.SortKey; +import javax.swing.SwingUtilities; import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; @@ -62,6 +66,7 @@ import iped.properties.ExtraProperties; import iped.viewers.ATextViewer; import iped.viewers.components.HitsTableModel; +import iped.viewers.util.ProgressDialog; public class ResultTableListener implements ListSelectionListener, MouseListener, KeyListener { @@ -73,6 +78,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); } @@ -282,6 +289,12 @@ public void keyPressed(KeyEvent evt) { } + private ProgressDialog createProgressDialog() { + ProgressDialog d = new ProgressDialog(App.get(), null, true, 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); @@ -313,63 +326,107 @@ public void itemSelection(boolean value) { } public void itemSelectionAndSubItems(boolean value) { - int col = App.get().resultsTable.convertColumnIndexToView(1); - 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); - int modelIndex = App.get().resultsTable.convertRowIndexToModel(selectedRows[i]); - selectAllSubitems(value, App.get().ipedResult.getItem(modelIndex)); - } - BookmarksController.get().updateUI(); - App.get().subItemTable.repaint(); + 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++) { + if (i == selectedRows.length - 1) { + BookmarksController.get().setMultiSetting(false); + 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)); + dialog.setProgress(i); + if (dialog.isCanceled()) { + return; + } + } + } finally { + SwingUtilities.invokeLater(() -> { + dialog.close(); + BookmarksController.get().updateUI(); + App.get().subItemTable.repaint(); + }); + } + }); } public void itemSelectionAndParent(boolean value) { - int col = App.get().resultsTable.convertColumnIndexToView(1); - 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); + 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(); + 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); - int modelIndex = App.get().resultsTable.convertRowIndexToModel(selectedRows[i]); - selectReferencedParent(value, App.get().ipedResult.getItem(modelIndex)); - } - BookmarksController.get().updateUI(); - App.get().subItemTable.repaint(); + int modelIndex = App.get().resultsTable.convertRowIndexToModel(selectedRows[i]); + selectReferencedParent(value, App.get().ipedResult.getItem(modelIndex)); + dialog.setProgress(i); + if (dialog.isCanceled()) { + return; + } + } + } finally { + SwingUtilities.invokeLater(() -> { + dialog.close(); + BookmarksController.get().updateUI(); + App.get().subItemTable.repaint(); + }); + } + }); } public void itemSelectionAndReferences(boolean value) { - int col = App.get().resultsTable.convertColumnIndexToView(1); - 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); + 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(); + 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); - int modelIndex = App.get().resultsTable.convertRowIndexToModel(selectedRows[i]); - selectReferencetems(value, App.get().ipedResult.getItem(modelIndex)); - } - BookmarksController.get().updateUI(); - App.get().subItemTable.repaint(); + int modelIndex = App.get().resultsTable.convertRowIndexToModel(selectedRows[i]); + selectReferencetems(value, App.get().ipedResult.getItem(modelIndex)); + dialog.setProgress(i); + if (dialog.isCanceled()) { + return; + } + } + } finally { + SwingUtilities.invokeLater(() -> { + dialog.close(); + BookmarksController.get().updateUI(); + App.get().subItemTable.repaint(); + }); + } + }); } public void itemSelectionAndReferencedBy(boolean value) { + ProgressDialog dialog = createProgressDialog(); + executor.execute(() -> { + try { int col = App.get().resultsTable.convertColumnIndexToView(1); BookmarksController.get().setMultiSetting(true); App.get().resultsTable.setUpdateSelectionOnSort(false); @@ -383,9 +440,19 @@ public void itemSelectionAndReferencedBy(boolean value) { int modelIndex = App.get().resultsTable.convertRowIndexToModel(selectedRows[i]); selectReferencedByItems(value, App.get().ipedResult.getItem(modelIndex)); + dialog.setProgress(i); + if (dialog.isCanceled()) { + return; + } } - BookmarksController.get().updateUI(); - App.get().subItemTable.repaint(); + } finally { + SwingUtilities.invokeLater(() -> { + dialog.close(); + BookmarksController.get().updateUI(); + App.get().subItemTable.repaint(); + }); + } +}); } /** From c9b0415af583a1b2f871600620d029842e71a14e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Berenguel?= Date: Mon, 12 Aug 2024 21:31:33 -0300 Subject: [PATCH 05/12] #1631: fixes in dialog --- .../java/iped/app/ui/ResultTableListener.java | 51 ++++++++++--------- 1 file changed, 27 insertions(+), 24 deletions(-) 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 7549212190..0e0812559b 100644 --- a/iped-app/src/main/java/iped/app/ui/ResultTableListener.java +++ b/iped-app/src/main/java/iped/app/ui/ResultTableListener.java @@ -290,7 +290,7 @@ public void keyPressed(KeyEvent evt) { } private ProgressDialog createProgressDialog() { - ProgressDialog d = new ProgressDialog(App.get(), null, true, 200, Dialog.ModalityType.APPLICATION_MODAL); + ProgressDialog d = new ProgressDialog(App.get(), null, false, 200, Dialog.ModalityType.APPLICATION_MODAL); d.setNote(Messages.getString("App.Wait")); //$NON-NLS-1$ return d; } @@ -367,6 +367,7 @@ public void itemSelectionAndParent(boolean value) { 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++) { if (i == selectedRows.length - 1) { BookmarksController.get().setMultiSetting(false); @@ -399,6 +400,7 @@ public void itemSelectionAndReferences(boolean value) { 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++) { if (i == selectedRows.length - 1) { BookmarksController.get().setMultiSetting(false); @@ -427,33 +429,34 @@ public void itemSelectionAndReferencedBy(boolean value) { 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(); - 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); + 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++) { + if (i == selectedRows.length - 1) { + BookmarksController.get().setMultiSetting(false); + App.get().resultsTable.setUpdateSelectionOnSort(true); + } + App.get().resultsTable.setValueAt(value, selectedRows[i], col); - int modelIndex = App.get().resultsTable.convertRowIndexToModel(selectedRows[i]); - selectReferencedByItems(value, App.get().ipedResult.getItem(modelIndex)); - dialog.setProgress(i); - if (dialog.isCanceled()) { - return; + int modelIndex = App.get().resultsTable.convertRowIndexToModel(selectedRows[i]); + selectReferencedByItems(value, App.get().ipedResult.getItem(modelIndex)); + dialog.setProgress(i); + if (dialog.isCanceled()) { + return; + } + } + } finally { + SwingUtilities.invokeLater(() -> { + dialog.close(); + BookmarksController.get().updateUI(); + App.get().subItemTable.repaint(); + }); } - } - } finally { - SwingUtilities.invokeLater(() -> { - dialog.close(); - BookmarksController.get().updateUI(); - App.get().subItemTable.repaint(); }); } -}); - } /** * Perform selection of all subitems From 0fde4bab5e7f74237eb2ad40830b1d3ff1f53f13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Berenguel?= Date: Fri, 16 Aug 2024 01:02:21 -0300 Subject: [PATCH 06/12] #1631: Consider ufed:id in ReferencedBy table and selection --- .../main/java/iped/app/ui/ReferencedByTableModel.java | 9 ++++++++- .../src/main/java/iped/app/ui/ResultTableListener.java | 9 +++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) 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..ddc1e5cc17 100644 --- a/iped-app/src/main/java/iped/app/ui/ReferencedByTableModel.java +++ b/iped-app/src/main/java/iped/app/ui/ReferencedByTableModel.java @@ -19,11 +19,13 @@ package iped.app.ui; import java.util.Arrays; +import java.util.Objects; 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 iped.data.IItem; @@ -74,7 +76,12 @@ public void listItems(Document doc) { 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(" ")); + String ufedId = doc.get(ExtraProperties.UFED_META_PREFIX + "id"); + if (StringUtils.isNotBlank(ufedId)) { + ufedId = "\"" + ufedId + "\""; + } + + String hashes = Arrays.asList(md5, sha1, sha256, edonkey).stream().filter(Objects::nonNull).collect(Collectors.joining(" ")); if (hashes.isEmpty()) { results = new LuceneSearchResult(0); 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 0e0812559b..5289a6dd89 100644 --- a/iped-app/src/main/java/iped/app/ui/ResultTableListener.java +++ b/iped-app/src/main/java/iped/app/ui/ResultTableListener.java @@ -32,6 +32,7 @@ import java.text.Collator; import java.util.Arrays; import java.util.List; +import java.util.Objects; import java.util.concurrent.Executor; import java.util.concurrent.Executors; import java.util.stream.Collectors; @@ -42,6 +43,7 @@ import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; +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; @@ -527,8 +529,11 @@ private void selectReferencedByItems(boolean state, IItemId rootId) { 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(" ")); + String ufedId = doc.get(ExtraProperties.UFED_META_PREFIX + "id"); + if (StringUtils.isNotBlank(ufedId)) { + ufedId = "\"" + ufedId + "\""; + } + String hashes = Arrays.asList(md5, sha1, sha256, edonkey).stream().filter(Objects::nonNull).collect(Collectors.joining(" ")); if (hashes.isEmpty()) { return; From 5e48fdb4d5513697175f56884a976a844df9cff8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Berenguel?= Date: Wed, 21 Aug 2024 22:17:04 -0300 Subject: [PATCH 07/12] #1631: missing ufedId in "referenced by" query --- iped-app/src/main/java/iped/app/ui/ReferencedByTableModel.java | 2 +- iped-app/src/main/java/iped/app/ui/ResultTableListener.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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 ddc1e5cc17..bec56124a0 100644 --- a/iped-app/src/main/java/iped/app/ui/ReferencedByTableModel.java +++ b/iped-app/src/main/java/iped/app/ui/ReferencedByTableModel.java @@ -81,7 +81,7 @@ public void listItems(Document doc) { ufedId = "\"" + ufedId + "\""; } - String hashes = Arrays.asList(md5, sha1, sha256, edonkey).stream().filter(Objects::nonNull).collect(Collectors.joining(" ")); + String hashes = Arrays.asList(md5, sha1, sha256, edonkey, ufedId).stream().filter(Objects::nonNull).collect(Collectors.joining(" ")); if (hashes.isEmpty()) { results = new LuceneSearchResult(0); 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 5289a6dd89..e5ee5664bf 100644 --- a/iped-app/src/main/java/iped/app/ui/ResultTableListener.java +++ b/iped-app/src/main/java/iped/app/ui/ResultTableListener.java @@ -533,7 +533,7 @@ private void selectReferencedByItems(boolean state, IItemId rootId) { if (StringUtils.isNotBlank(ufedId)) { ufedId = "\"" + ufedId + "\""; } - String hashes = Arrays.asList(md5, sha1, sha256, edonkey).stream().filter(Objects::nonNull).collect(Collectors.joining(" ")); + String hashes = Arrays.asList(md5, sha1, sha256, edonkey, ufedId).stream().filter(Objects::nonNull).collect(Collectors.joining(" ")); if (hashes.isEmpty()) { return; From 356e99e534e11def066dab5cbe289dfeac359ddf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Berenguel?= Date: Sat, 5 Oct 2024 22:01:11 -0300 Subject: [PATCH 08/12] #1631: reuse the code for query build in dockingControl panels for selections --- .../main/java/iped/app/ui/BaseTableModel.java | 56 +++- .../iped/app/ui/DuplicatesTableModel.java | 60 ++-- .../java/iped/app/ui/ParentTableModel.java | 56 ++-- .../iped/app/ui/ReferencedByTableModel.java | 66 ++-- .../iped/app/ui/ReferencingTableModel.java | 103 +++---- .../java/iped/app/ui/ResultTableListener.java | 290 ++---------------- .../java/iped/app/ui/SubitemTableModel.java | 51 ++- 7 files changed, 222 insertions(+), 460 deletions(-) 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/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/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 bec56124a0..ff508fe2ff 100644 --- a/iped-app/src/main/java/iped/app/ui/ReferencedByTableModel.java +++ b/iped-app/src/main/java/iped/app/ui/ReferencedByTableModel.java @@ -19,19 +19,20 @@ package iped.app.ui; import java.util.Arrays; -import java.util.Objects; +import java.util.List; 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 org.apache.lucene.search.TermInSetQuery; +import org.apache.lucene.util.BytesRef; import iped.data.IItem; -import iped.engine.search.IPEDSearcher; -import iped.engine.search.LuceneSearchResult; -import iped.engine.search.MultiSearchResult; import iped.engine.task.HashTask; import iped.parsers.ares.AresParser; import iped.parsers.emule.KnownMetParser; @@ -43,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]; @@ -70,51 +75,26 @@ 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 ufedId = doc.get(ExtraProperties.UFED_META_PREFIX + "id"); - if (StringUtils.isNotBlank(ufedId)) { - ufedId = "\"" + ufedId + "\""; + List hashes = Arrays.asList(md5, sha1, sha256, edonkey).stream().filter(StringUtils::isNotBlank) + .map(h -> new BytesRef(h)).collect(Collectors.toList()); + if (!hashes.isEmpty()) { + queryBuilder.add(new TermInSetQuery(ExtraProperties.LINKED_ITEMS, hashes), Occur.SHOULD); + queryBuilder.add(new TermInSetQuery(ExtraProperties.SHARED_HASHES, hashes), Occur.SHOULD); } - String hashes = Arrays.asList(md5, sha1, sha256, edonkey, ufedId).stream().filter(Objects::nonNull).collect(Collectors.joining(" ")); - - if (hashes.isEmpty()) { - results = new LuceneSearchResult(0); - refDoc = null; - } else { - String textQuery = ExtraProperties.LINKED_ITEMS + ":(" + hashes + ") "; - textQuery += ExtraProperties.SHARED_HASHES + ":(" + hashes + ")"; - - 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; - e.printStackTrace(); - } - } + return queryBuilder.build(); + } - fireTableDataChanged(); + @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 e5ee5664bf..57c08398ae 100644 --- a/iped-app/src/main/java/iped/app/ui/ResultTableListener.java +++ b/iped-app/src/main/java/iped/app/ui/ResultTableListener.java @@ -30,12 +30,9 @@ import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.text.Collator; -import java.util.Arrays; import java.util.List; -import java.util.Objects; import java.util.concurrent.Executor; import java.util.concurrent.Executors; -import java.util.stream.Collectors; import javax.swing.JTable; import javax.swing.RowSorter.SortKey; @@ -43,13 +40,8 @@ import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; -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.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -57,15 +49,7 @@ import iped.data.IItem; import iped.data.IItemId; import iped.engine.search.IPEDSearcher; -import iped.engine.search.LuceneSearchResult; import iped.engine.search.MultiSearchResult; -import iped.engine.task.HashTask; -import iped.engine.task.index.IndexItem; -import iped.parsers.ares.AresParser; -import iped.parsers.emule.KnownMetParser; -import iped.parsers.shareaza.ShareazaLibraryDatParser; -import iped.properties.BasicProps; -import iped.properties.ExtraProperties; import iped.viewers.ATextViewer; import iped.viewers.components.HitsTableModel; import iped.viewers.util.ProgressDialog; @@ -327,8 +311,7 @@ public void itemSelection(boolean value) { App.get().subItemTable.repaint(); } - public void itemSelectionAndSubItems(boolean value) { - + public void itemSelectionAndResultsByQuery(boolean value, BaseTableModel tableModel) { ProgressDialog dialog = createProgressDialog(); executor.execute(() -> { try { @@ -338,118 +321,38 @@ public void itemSelectionAndSubItems(boolean value) { int[] selectedRows = App.get().resultsTable.getSelectedRows(); dialog.setMaximum(selectedRows.length); 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); - - int modelIndex = App.get().resultsTable.convertRowIndexToModel(selectedRows[i]); - selectAllSubitems(value, App.get().ipedResult.getItem(modelIndex)); - dialog.setProgress(i); - if (dialog.isCanceled()) { - return; - } - } - } finally { - SwingUtilities.invokeLater(() -> { - dialog.close(); - BookmarksController.get().updateUI(); - App.get().subItemTable.repaint(); - }); - } - }); - } - public void itemSelectionAndParent(boolean value) { - 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); - int modelIndex = App.get().resultsTable.convertRowIndexToModel(selectedRows[i]); - selectReferencedParent(value, App.get().ipedResult.getItem(modelIndex)); - dialog.setProgress(i); - if (dialog.isCanceled()) { - return; - } - } - } finally { - SwingUtilities.invokeLater(() -> { - dialog.close(); - BookmarksController.get().updateUI(); - App.get().subItemTable.repaint(); - }); - } - }); - } - - public void itemSelectionAndReferences(boolean value) { - 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++) { - if (i == selectedRows.length - 1) { - BookmarksController.get().setMultiSetting(false); - App.get().resultsTable.setUpdateSelectionOnSort(true); - } - App.get().resultsTable.setValueAt(value, selectedRows[i], col); - - int modelIndex = App.get().resultsTable.convertRowIndexToModel(selectedRows[i]); - selectReferencetems(value, App.get().ipedResult.getItem(modelIndex)); - dialog.setProgress(i); - if (dialog.isCanceled()) { - return; - } - } - } finally { - SwingUtilities.invokeLater(() -> { - dialog.close(); - BookmarksController.get().updateUI(); - App.get().subItemTable.repaint(); - }); - } - }); - } - - public void itemSelectionAndReferencedBy(boolean value) { - 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++) { - if (i == selectedRows.length - 1) { - BookmarksController.get().setMultiSetting(false); - App.get().resultsTable.setUpdateSelectionOnSort(true); + // 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); + 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); + } + } } - App.get().resultsTable.setValueAt(value, selectedRows[i], col); - int modelIndex = App.get().resultsTable.convertRowIndexToModel(selectedRows[i]); - selectReferencedByItems(value, App.get().ipedResult.getItem(modelIndex)); 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(); @@ -460,159 +363,20 @@ public void itemSelectionAndReferencedBy(boolean value) { }); } - /** - * 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); - } - } - } - - } catch (Exception e) { - logger.debug("Error :" + e.getLocalizedMessage()); - e.printStackTrace(); - } + public void itemSelectionAndSubItems(boolean value) { + itemSelectionAndResultsByQuery(value, App.get().subItemModel); } - private void selectReferencedParent(boolean state, IItemId rootId) { - - try { - final int docId = App.get().appCase.getLuceneId(rootId); - Document doc = App.get().appCase.getSearcher().doc(docId); - - String parentId = doc.get(IndexItem.PARENTID); - if (parentId == null) { - return; - } - String sourceUUID = doc.get(IndexItem.EVIDENCE_UUID); - - String textQuery = IndexItem.ID + ":" + parentId + " && " + IndexItem.EVIDENCE_UUID + ":" + sourceUUID; - - IPEDSearcher task = new IPEDSearcher(App.get().appCase, textQuery, BasicProps.NAME); - LuceneSearchResult results = MultiSearchResult.get(task.multiSearch(), App.get().appCase); - - if (results.getLength() > 0) { - for (int resDocId : results.getLuceneIds()) { - App.get().appCase.getMultiBookmarks().setChecked((Boolean) state, App.get().appCase.getItemId(resDocId)); - } - } - - } catch (Exception e) { - logger.error("Error :" + e.getLocalizedMessage()); - e.printStackTrace(); - } + public void itemSelectionAndParent(boolean value) { + itemSelectionAndResultsByQuery(value, App.get().parentItemModel); } - private void selectReferencedByItems(boolean state, IItemId rootId) { - - try { - final int docId = App.get().appCase.getLuceneId(rootId); - Document doc = App.get().appCase.getSearcher().doc(docId); - - 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 ufedId = doc.get(ExtraProperties.UFED_META_PREFIX + "id"); - if (StringUtils.isNotBlank(ufedId)) { - ufedId = "\"" + ufedId + "\""; - } - String hashes = Arrays.asList(md5, sha1, sha256, edonkey, ufedId).stream().filter(Objects::nonNull).collect(Collectors.joining(" ")); - - if (hashes.isEmpty()) { - return; - } - - String textQuery = ExtraProperties.LINKED_ITEMS + ":(" + hashes + ") "; - textQuery += ExtraProperties.SHARED_HASHES + ":(" + hashes + ")"; - - IPEDSearcher task = new IPEDSearcher(App.get().appCase, textQuery, BasicProps.NAME); - LuceneSearchResult results = MultiSearchResult.get(task.multiSearch(), App.get().appCase); - - if (results.getLength() > 0) { - for (int resDocId : results.getLuceneIds()) { - App.get().appCase.getMultiBookmarks().setChecked((Boolean) state, - App.get().appCase.getItemId(resDocId)); - } - } - - } catch (Exception e) { - logger.error("Error :" + e.getLocalizedMessage()); - e.printStackTrace(); - } + public void itemSelectionAndReferences(boolean value) { + itemSelectionAndResultsByQuery(value, App.get().referencesModel); } - private void selectReferencetems(boolean state, IItemId rootId) { - try { - - final int docId = App.get().appCase.getLuceneId(rootId); - Document doc = App.get().appCase.getSearcher().doc(docId); - - StringBuilder textQuery = null; - Query query = null; - - String[] linkedItems = doc.getValues(ExtraProperties.LINKED_ITEMS); - if (linkedItems != null && linkedItems.length > 0) { - textQuery = new StringBuilder(); - 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; - } - 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) { - - IPEDSearcher task = query != null ? new IPEDSearcher(App.get().appCase, query, BasicProps.NAME) - : new IPEDSearcher(App.get().appCase, textQuery.toString(), BasicProps.NAME); - task.setRewritequery(false); - LuceneSearchResult results = MultiSearchResult.get(task.multiSearch(), App.get().appCase); - - if (results.getLength() > 0) { - for (int resDocId : results.getLuceneIds()) { - App.get().appCase.getMultiBookmarks().setChecked((Boolean) state, - App.get().appCase.getItemId(resDocId)); - } - } - } - } catch (Exception e) { - logger.error("Error :" + e.getLocalizedMessage()); - e.printStackTrace(); - } + 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")); } } From 137cbcab30797d126fe572e1a414dc0dfb249ad7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Berenguel?= Date: Thu, 10 Oct 2024 11:33:37 -0300 Subject: [PATCH 09/12] #1631: use text query for referenced items --- .../iped/app/ui/ReferencedByTableModel.java | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) 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 ff508fe2ff..d762a6bb8e 100644 --- a/iped-app/src/main/java/iped/app/ui/ReferencedByTableModel.java +++ b/iped-app/src/main/java/iped/app/ui/ReferencedByTableModel.java @@ -19,7 +19,6 @@ package iped.app.ui; import java.util.Arrays; -import java.util.List; import java.util.stream.Collectors; import javax.swing.ListSelectionModel; @@ -29,11 +28,12 @@ import org.apache.lucene.search.BooleanClause.Occur; import org.apache.lucene.search.BooleanQuery; import org.apache.lucene.search.Query; -import org.apache.lucene.search.TermInSetQuery; -import org.apache.lucene.util.BytesRef; import iped.data.IItem; +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; @@ -83,11 +83,15 @@ public Query createQuery(Document doc) { String sha1 = doc.get(HashTask.HASH.SHA1.toString()); String sha256 = doc.get(HashTask.HASH.SHA256.toString()); String edonkey = doc.get(HashTask.HASH.EDONKEY.toString()); - List hashes = Arrays.asList(md5, sha1, sha256, edonkey).stream().filter(StringUtils::isNotBlank) - .map(h -> new BytesRef(h)).collect(Collectors.toList()); + String hashes = Arrays.asList(md5, sha1, sha256, edonkey).stream().filter(StringUtils::isNotBlank).collect(Collectors.joining(" ")); if (!hashes.isEmpty()) { - queryBuilder.add(new TermInSetQuery(ExtraProperties.LINKED_ITEMS, hashes), Occur.SHOULD); - queryBuilder.add(new TermInSetQuery(ExtraProperties.SHARED_HASHES, hashes), Occur.SHOULD); + QueryBuilder b = new QueryBuilder(App.get().appCase); + try { + 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(); + } } return queryBuilder.build(); From 14c8f4ddfa450d6c5910e9201325bc32e517b645 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Berenguel?= Date: Fri, 25 Oct 2024 00:16:38 -0300 Subject: [PATCH 10/12] #1631: handle non text query in selections --- iped-app/src/main/java/iped/app/ui/ResultTableListener.java | 1 + 1 file changed, 1 insertion(+) 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 57c08398ae..c1f041b5a8 100644 --- a/iped-app/src/main/java/iped/app/ui/ResultTableListener.java +++ b/iped-app/src/main/java/iped/app/ui/ResultTableListener.java @@ -337,6 +337,7 @@ public void itemSelectionAndResultsByQuery(boolean value, BaseTableModel tableMo 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()); From 79fb12cd4472bf76e8e8bc786a469ed97375d8c5 Mon Sep 17 00:00:00 2001 From: tc-wleite Date: Sat, 23 Nov 2024 10:49:39 -0300 Subject: [PATCH 11/12] '#1631: Minor adjustment in pt_BR "UnCheckHighlighted" menu text. --- .../localization/iped-desktop-messages_pt_BR.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 59c92ad7e5..9987a24cee 100644 --- a/iped-app/resources/localization/iped-desktop-messages_pt_BR.properties +++ b/iped-app/resources/localization/iped-desktop-messages_pt_BR.properties @@ -257,7 +257,7 @@ MenuClass.ResetLayout=Restaurar Layout Padrão MenuClass.SaveBookmarks=Salvar marcadores MenuClass.UiZoom=Alterar Zoom da Interface MenuClass.IconSize=Tamanho dos Ícones -MenuClass.UnCheckHighlighted=Remover marcação dos itens destacados +MenuClass.UnCheckHighlighted=Desmarcar dos itens destacados MenuClass.UncheckHighlightedAndSubItems=Desmarcar itens destacados e subitens MenuClass.UncheckHighlightedAndParent=Desmarcar itens destacados e item pai MenuClass.UncheckHighlightedAndReferences=Desmarcar itens destacados e referências From 77e32dc29305314785489c32b0b8ffd5269cde29 Mon Sep 17 00:00:00 2001 From: tc-wleite Date: Sat, 23 Nov 2024 11:00:37 -0300 Subject: [PATCH 12/12] '#1631: Fix previous commit. --- .../localization/iped-desktop-messages_pt_BR.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 9987a24cee..538f7e80ad 100644 --- a/iped-app/resources/localization/iped-desktop-messages_pt_BR.properties +++ b/iped-app/resources/localization/iped-desktop-messages_pt_BR.properties @@ -257,7 +257,7 @@ MenuClass.ResetLayout=Restaurar Layout Padrão MenuClass.SaveBookmarks=Salvar marcadores MenuClass.UiZoom=Alterar Zoom da Interface MenuClass.IconSize=Tamanho dos Ícones -MenuClass.UnCheckHighlighted=Desmarcar dos itens destacados +MenuClass.UnCheckHighlighted=Desmarcar itens destacados MenuClass.UncheckHighlightedAndSubItems=Desmarcar itens destacados e subitens MenuClass.UncheckHighlightedAndParent=Desmarcar itens destacados e item pai MenuClass.UncheckHighlightedAndReferences=Desmarcar itens destacados e referências