From 2917d1611d59985d03f94c73bfd837ed81f3d015 Mon Sep 17 00:00:00 2001 From: "patrick.pdb" Date: Thu, 16 Nov 2023 11:26:18 -0300 Subject: [PATCH] '#1973 Improves code adding the method addSelection to replace redundant code. --- .../main/java/iped/geo/impl/AppMapPanel.java | 31 ++++++++++--------- .../main/java/iped/geo/impl/MapViewer.java | 16 +--------- 2 files changed, 18 insertions(+), 29 deletions(-) diff --git a/iped-geo/src/main/java/iped/geo/impl/AppMapPanel.java b/iped-geo/src/main/java/iped/geo/impl/AppMapPanel.java index 6ba32077fb..a4ccd84c3f 100644 --- a/iped-geo/src/main/java/iped/geo/impl/AppMapPanel.java +++ b/iped-geo/src/main/java/iped/geo/impl/AppMapPanel.java @@ -315,20 +315,7 @@ private void syncSelectedItems() { for (int i = 0; i < selected.length; i++) { int rowModel = resultsTable.convertRowIndexToModel(selected[i]); IItemId item = results.getItem(rowModel); - - if (kmlResult != null && kmlResult.getGPSItems().containsKey(item)) { - List subitems = kmlResult.getGPSItems().get(item); - if (subitems == null) { - String gid = "marker_" + item.getSourceId() + "_" + item.getId(); //$NON-NLS-1$ //$NON-NLS-2$ - selecoes.put(gid, true); - } else { - for (Integer subitem : subitems) { - String gid = "marker_" + item.getSourceId() + "_" + item.getId() + "_" //$NON-NLS-1$ //$NON-NLS-2$ - + subitem; - selecoes.put(gid, true); - } - } - } + addSelection(selecoes, item); } mapViewer.updateMapLeadCursor(); @@ -336,6 +323,22 @@ private void syncSelectedItems() { browserCanvas.sendSelection(selecoes); } + public void addSelection(HashMap selecoes, IItemId item) { + if (kmlResult != null && kmlResult.getGPSItems().containsKey(item)) { + List subitems = kmlResult.getGPSItems().get(item); + if (subitems == null) { + String gid = "marker_" + item.getSourceId() + "_" + item.getId(); //$NON-NLS-1$ //$NON-NLS-2$ + selecoes.put(gid, true); + } else { + for (Integer subitem : subitems) { + String gid = "marker_" + item.getSourceId() + "_" + item.getId() + "_" //$NON-NLS-1$ //$NON-NLS-2$ + + subitem; + selecoes.put(gid, true); + } + } + } + } + @Override public void accept(Object[] result) { KMLResult kmlResult = (KMLResult) result[0]; diff --git a/iped-geo/src/main/java/iped/geo/impl/MapViewer.java b/iped-geo/src/main/java/iped/geo/impl/MapViewer.java index 285c631d4c..b96263afa6 100644 --- a/iped-geo/src/main/java/iped/geo/impl/MapViewer.java +++ b/iped-geo/src/main/java/iped/geo/impl/MapViewer.java @@ -2,7 +2,6 @@ import java.util.HashMap; import java.util.Iterator; -import java.util.List; import java.util.Map.Entry; import javax.swing.JPanel; @@ -218,20 +217,7 @@ public void run() { int rowModel = resultsTable.convertRowIndexToModel(i); IItemId item = results.getItem(rowModel); - - if (mapaPanel.kmlResult != null && mapaPanel.kmlResult.getGPSItems().containsKey(item)) { - List subitems = mapaPanel.kmlResult.getGPSItems().get(item); - if (subitems == null) { - String gid = "marker_" + item.getSourceId() + "_" + item.getId(); //$NON-NLS-1$ //$NON-NLS-2$ - selecoes.put(gid, selected); - } else { - for (Integer subitem : subitems) { - String gid = "marker_" + item.getSourceId() + "_" + item.getId() + "_" //$NON-NLS-1$ //$NON-NLS-2$ - + subitem; - selecoes.put(gid, selected); - } - } - } + mapaPanel.addSelection(selecoes, item); } catch (Exception e) { e.printStackTrace(); }