From 67ff3ee7cdfdbccee50c1d7c0875b087c9d89cc8 Mon Sep 17 00:00:00 2001 From: sidheshenator Date: Wed, 24 Jun 2015 15:30:11 -0400 Subject: [PATCH 01/56] Text FileReport added to databse. Logger format changed --- Core/src/org/sleuthkit/autopsy/casemodule/Case.java | 11 ++++++++++- Core/src/org/sleuthkit/autopsy/coreutils/Logger.java | 2 +- .../org/sleuthkit/autopsy/report/FileReportText.java | 7 +++++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/Case.java b/Core/src/org/sleuthkit/autopsy/casemodule/Case.java index db1250ebf7..759c431a52 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/Case.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/Case.java @@ -25,6 +25,8 @@ import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; import java.io.IOException; +import java.nio.file.InvalidPathException; +import java.nio.file.Paths; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.GregorianCalendar; @@ -1163,7 +1165,14 @@ public class Case implements SleuthkitCase.ErrorObserver { * @throws TskCoreException */ public void addReport(String localPath, String srcModuleName, String reportName) throws TskCoreException { - Report report = this.db.addReport(localPath, srcModuleName, reportName); + String normalizedLocalPath; + try { + normalizedLocalPath = Paths.get(localPath).normalize().toString(); + } catch (InvalidPathException ex) { + logger.log(Level.WARNING, "Invalid local path provided: " + localPath, ex); + normalizedLocalPath = localPath; + } + Report report = this.db.addReport(normalizedLocalPath, srcModuleName, reportName); try { Case.pcs.firePropertyChange(Events.REPORT_ADDED.toString(), null, report); } catch (Exception ex) { diff --git a/Core/src/org/sleuthkit/autopsy/coreutils/Logger.java b/Core/src/org/sleuthkit/autopsy/coreutils/Logger.java index 494c86cf7f..8ae2480883 100644 --- a/Core/src/org/sleuthkit/autopsy/coreutils/Logger.java +++ b/Core/src/org/sleuthkit/autopsy/coreutils/Logger.java @@ -79,7 +79,7 @@ public final class Logger extends java.util.logging.Logger { + record.getSourceMethodName() + "\n" + record.getLevel() + ": " + this.formatMessage(record) + "\n" - + record.getThrown().toString() + ": " + + record.getThrown().toString() + ":\n" + StackTrace + "\n"; } else { diff --git a/Core/src/org/sleuthkit/autopsy/report/FileReportText.java b/Core/src/org/sleuthkit/autopsy/report/FileReportText.java index 2dd7e8b676..d7eac93477 100755 --- a/Core/src/org/sleuthkit/autopsy/report/FileReportText.java +++ b/Core/src/org/sleuthkit/autopsy/report/FileReportText.java @@ -30,7 +30,9 @@ import java.util.logging.Level; import org.sleuthkit.autopsy.coreutils.Logger; import org.openide.util.NbBundle; +import org.sleuthkit.autopsy.casemodule.Case; import org.sleuthkit.datamodel.AbstractFile; +import org.sleuthkit.datamodel.TskCoreException; /** * A Tab-delimited text report of the files in the case. @@ -68,8 +70,13 @@ import org.sleuthkit.datamodel.AbstractFile; if (out != null) { try { out.close(); + Case.getCurrentCase().addReport(reportPath, NbBundle.getMessage(this.getClass(), + "FileReportText.getName.text"), ""); } catch (IOException ex) { logger.log(Level.WARNING, "Could not close output writer when ending report.", ex); //NON-NLS + } catch (TskCoreException ex) { + String errorMessage = String.format("Error adding %s to case as a report", reportPath); //NON-NLS + logger.log(Level.SEVERE, errorMessage, ex); } } } From 9b021d5adbc17c43a840e234565e4a7fd185cad4 Mon Sep 17 00:00:00 2001 From: Sidhesh Mhatre Date: Wed, 24 Jun 2015 15:42:45 -0400 Subject: [PATCH 02/56] Throw TskCoreException if localPath is invalid --- Core/src/org/sleuthkit/autopsy/casemodule/Case.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/Case.java b/Core/src/org/sleuthkit/autopsy/casemodule/Case.java index 759c431a52..f763c708a4 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/Case.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/Case.java @@ -1169,8 +1169,9 @@ public class Case implements SleuthkitCase.ErrorObserver { try { normalizedLocalPath = Paths.get(localPath).normalize().toString(); } catch (InvalidPathException ex) { - logger.log(Level.WARNING, "Invalid local path provided: " + localPath, ex); - normalizedLocalPath = localPath; + String errorMsg = "Invalid local path provided: " + localPath; // NON-NLS + logger.log(Level.WARNING, errorMsg, ex); + throw new TskCoreException(errorMsg); } Report report = this.db.addReport(normalizedLocalPath, srcModuleName, reportName); try { From 10f66173a02a6269a0d3bcbc1fa1f1cadf50d40f Mon Sep 17 00:00:00 2001 From: Sidhesh Mhatre Date: Wed, 24 Jun 2015 16:19:16 -0400 Subject: [PATCH 03/56] Not logging invalidpathException --- Core/src/org/sleuthkit/autopsy/casemodule/Case.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/Case.java b/Core/src/org/sleuthkit/autopsy/casemodule/Case.java index f763c708a4..298435eeb0 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/Case.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/Case.java @@ -1170,8 +1170,7 @@ public class Case implements SleuthkitCase.ErrorObserver { normalizedLocalPath = Paths.get(localPath).normalize().toString(); } catch (InvalidPathException ex) { String errorMsg = "Invalid local path provided: " + localPath; // NON-NLS - logger.log(Level.WARNING, errorMsg, ex); - throw new TskCoreException(errorMsg); + throw new TskCoreException(errorMsg, ex); } Report report = this.db.addReport(normalizedLocalPath, srcModuleName, reportName); try { From e1e5e78bd040c91bab9a0243fe1150c0ee7d5f38 Mon Sep 17 00:00:00 2001 From: jmillman Date: Tue, 16 Jun 2015 11:14:44 -0400 Subject: [PATCH 04/56] make new DeleteFollowUpTag action; use Set instead of List to prevent duplicate files in groups --- .../actions/DeleteFollowUpTag.java | 86 +++++++++++++++++++ .../imagegallery/datamodel/DrawableDB.java | 10 +-- .../imagegallery/grouping/DrawableGroup.java | 4 +- .../imagegallery/grouping/GroupManager.java | 30 ++++--- .../imagegallery/gui/DrawableViewBase.java | 55 ++++++------ 5 files changed, 138 insertions(+), 47 deletions(-) create mode 100644 ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/DeleteFollowUpTag.java diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/DeleteFollowUpTag.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/DeleteFollowUpTag.java new file mode 100644 index 0000000000..0399b545ed --- /dev/null +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/DeleteFollowUpTag.java @@ -0,0 +1,86 @@ +/* + * Autopsy Forensic Browser + * + * Copyright 2015 Basis Technology Corp. + * Contact: carrier sleuthkit org + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.sleuthkit.autopsy.imagegallery.actions; + +import java.util.Collections; +import java.util.List; +import java.util.logging.Level; +import javafx.event.ActionEvent; +import org.controlsfx.control.action.Action; +import org.sleuthkit.autopsy.coreutils.Logger; +import org.sleuthkit.autopsy.imagegallery.FileUpdateEvent; +import org.sleuthkit.autopsy.imagegallery.ImageGalleryController; +import org.sleuthkit.autopsy.imagegallery.TagUtils; +import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableAttribute; +import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableFile; +import org.sleuthkit.autopsy.imagegallery.grouping.GroupKey; +import org.sleuthkit.autopsy.ingest.IngestServices; +import org.sleuthkit.autopsy.ingest.ModuleDataEvent; +import org.sleuthkit.datamodel.BlackboardArtifact; +import org.sleuthkit.datamodel.ContentTag; +import org.sleuthkit.datamodel.SleuthkitCase; +import org.sleuthkit.datamodel.TagName; +import org.sleuthkit.datamodel.TskCoreException; + +/** + * + */ +public class DeleteFollowUpTag extends Action { + + private static final Logger LOGGER = Logger.getLogger(DeleteFollowUpTag.class.getName()); + private final long fileID; + private final DrawableFile file; + + public DeleteFollowUpTag(DrawableFile file) { + super("Delete Follow Up Tag"); + this.file = file; + this.fileID = file.getId(); + + setEventHandler((ActionEvent t) -> { + deleteFollowupTag(); + }); + } + + /** + * + * @param fileID1 the value of fileID1 + * + * @throws IllegalStateException + */ + private void deleteFollowupTag() throws IllegalStateException { + + final ImageGalleryController controller = ImageGalleryController.getDefault(); + final SleuthkitCase sleuthKitCase = controller.getSleuthKitCase(); + try { + // remove file from old category group + controller.getGroupManager().removeFromGroup(new GroupKey(DrawableAttribute.TAGS, TagUtils.getFollowUpTagName()), fileID); + + List contentTagsByContent = sleuthKitCase.getContentTagsByContent(file); + for (ContentTag ct : contentTagsByContent) { + if (ct.getName().getDisplayName().equals(TagUtils.getFollowUpTagName().getDisplayName())) { + sleuthKitCase.deleteContentTag(ct); + } + } + IngestServices.getInstance().fireModuleDataEvent(new ModuleDataEvent("TagAction", BlackboardArtifact.ARTIFACT_TYPE.TSK_TAG_FILE)); //NON-NLS + controller.getGroupManager().handleFileUpdate(FileUpdateEvent.newUpdateEvent(Collections.singleton(fileID), DrawableAttribute.TAGS)); + } catch (TskCoreException ex) { + LOGGER.log(Level.SEVERE, "Failed to delete follow up tag.", ex); + } + } +} diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableDB.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableDB.java index a5f91bb9d3..ac1f6c99eb 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableDB.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableDB.java @@ -698,7 +698,7 @@ public final class DrawableDB { public Boolean isGroupAnalyzed(GroupKey gk) { dbReadLock(); try { - List fileIDsInGroup = getFileIDsInGroup(gk); + Set fileIDsInGroup = getFileIDsInGroup(gk); try { // In testing, this method appears to be a lot faster than doing one large select statement @@ -747,10 +747,10 @@ public final class DrawableDB { * * @throws TskCoreException */ - public List findAllFileIdsWhere(String sqlWhereClause) throws TskCoreException { + public Set findAllFileIdsWhere(String sqlWhereClause) throws TskCoreException { Statement statement = null; ResultSet rs = null; - List ret = new ArrayList<>(); + Set ret = new HashSet<>(); dbReadLock(); try { statement = con.createStatement(); @@ -984,7 +984,7 @@ public final class DrawableDB { } } - public List getFileIDsInGroup(GroupKey groupKey) throws TskCoreException { + public Set getFileIDsInGroup(GroupKey groupKey) throws TskCoreException { if (groupKey.getAttribute().isDBColumn) { switch (groupKey.getAttribute().attrName) { @@ -994,7 +994,7 @@ public final class DrawableDB { return groupManager.getFileIDsWithTag((TagName) groupKey.getValue()); } } - List files = new ArrayList<>(); + Set files = new HashSet<>(); dbReadLock(); try { PreparedStatement statement = getGroupStatment(groupKey.getAttribute()); diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/DrawableGroup.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/DrawableGroup.java index e6d1f3dad8..b59a1b8edd 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/DrawableGroup.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/DrawableGroup.java @@ -18,8 +18,8 @@ */ package org.sleuthkit.autopsy.imagegallery.grouping; -import java.util.List; import java.util.Objects; +import java.util.Set; import java.util.logging.Level; import javafx.beans.property.ReadOnlyBooleanWrapper; import javafx.collections.FXCollections; @@ -70,7 +70,7 @@ public class DrawableGroup implements Comparable { return groupKey.getValueDisplayName(); } - DrawableGroup(GroupKey groupKey, List filesInGroup, boolean seen) { + DrawableGroup(GroupKey groupKey, Set filesInGroup, boolean seen) { this.groupKey = groupKey; this.fileIDs.setAll(filesInGroup); this.seen.set(seen); diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/GroupManager.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/GroupManager.java index ec35f6bb60..68e1044dbc 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/GroupManager.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/GroupManager.java @@ -40,6 +40,7 @@ import javafx.beans.property.ReadOnlyDoubleWrapper; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javax.swing.SortOrder; +import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.concurrent.BasicThreadFactory; import org.netbeans.api.progress.ProgressHandle; @@ -241,8 +242,9 @@ public class GroupManager implements FileUpdateEvent.FileUpdateListener { * * @return the new DrawableGroup for the given key */ - public DrawableGroup makeGroup(GroupKey groupKey, List files) { - List newFiles = files == null ? new ArrayList<>() : files; + public DrawableGroup makeGroup(GroupKey groupKey, Set files) { + + Set newFiles = ObjectUtils.defaultIfNull(files, new HashSet()); final boolean groupSeen = db.isGroupSeen(groupKey); DrawableGroup g = new DrawableGroup(groupKey, newFiles, groupSeen); @@ -303,7 +305,7 @@ public class GroupManager implements FileUpdateEvent.FileUpdateListener { } } - public synchronized void populateAnalyzedGroup(final GroupKey groupKey, List filesInGroup) { + public synchronized void populateAnalyzedGroup(final GroupKey groupKey, Set filesInGroup) { populateAnalyzedGroup(groupKey, filesInGroup, null); } @@ -314,7 +316,7 @@ public class GroupManager implements FileUpdateEvent.FileUpdateListener { * @param groupKey * @param filesInGroup */ - private synchronized > void populateAnalyzedGroup(final GroupKey groupKey, List filesInGroup, ReGroupTask task) { + private synchronized > void populateAnalyzedGroup(final GroupKey groupKey, Set filesInGroup, ReGroupTask task) { /* if this is not part of a regroup task or it is but the task is not * cancelled... @@ -352,7 +354,7 @@ public class GroupManager implements FileUpdateEvent.FileUpdateListener { * this * group if they are all analyzed */ - public List checkAnalyzed(final GroupKey groupKey) { + public Set checkAnalyzed(final GroupKey groupKey) { try { /* for attributes other than path we can't be sure a group is fully * analyzed because we don't know all the files that will be a part @@ -464,7 +466,7 @@ public class GroupManager implements FileUpdateEvent.FileUpdateListener { } - public List getFileIDsInGroup(GroupKey groupKey) throws TskCoreException { + public Set getFileIDsInGroup(GroupKey groupKey) throws TskCoreException { switch (groupKey.getAttribute().attrName) { //these cases get special treatment case CATEGORY: @@ -481,12 +483,12 @@ public class GroupManager implements FileUpdateEvent.FileUpdateListener { // @@@ This was kind of slow in the profiler. Maybe we should cache it. // Unless the list of file IDs is necessary, use countFilesWithCategory() to get the counts. - public List getFileIDsWithCategory(Category category) throws TskCoreException { + public Set getFileIDsWithCategory(Category category) throws TskCoreException { try { if (category == Category.ZERO) { - List files = new ArrayList<>(); + Set files = new HashSet<>(); TagName[] tns = {Category.FOUR.getTagName(), Category.THREE.getTagName(), Category.TWO.getTagName(), Category.ONE.getTagName(), Category.FIVE.getTagName()}; for (TagName tn : tns) { List contentTags = Case.getCurrentCase().getServices().getTagsManager().getContentTagsByTagName(tn); @@ -500,7 +502,7 @@ public class GroupManager implements FileUpdateEvent.FileUpdateListener { return db.findAllFileIdsWhere("obj_id NOT IN (" + StringUtils.join(files, ',') + ")"); } else { - List files = new ArrayList<>(); + Set files = new HashSet<>(); List contentTags = Case.getCurrentCase().getServices().getTagsManager().getContentTagsByTagName(category.getTagName()); for (ContentTag ct : contentTags) { if (ct.getContent() instanceof AbstractFile && db.isInDB(ct.getContent().getId())) { @@ -516,9 +518,9 @@ public class GroupManager implements FileUpdateEvent.FileUpdateListener { } } - public List getFileIDsWithTag(TagName tagName) throws TskCoreException { + public Set getFileIDsWithTag(TagName tagName) throws TskCoreException { try { - List files = new ArrayList<>(); + Set files = new HashSet<>(); List contentTags = Case.getCurrentCase().getServices().getTagsManager().getContentTagsByTagName(tagName); for (ContentTag ct : contentTags) { if (ct.getContent() instanceof AbstractFile && db.isInDB(ct.getContent().getId())) { @@ -636,7 +638,7 @@ public class GroupManager implements FileUpdateEvent.FileUpdateListener { // It may be that this was the last unanalyzed file in the group, so test // whether the group is now fully analyzed. //TODO: use method in groupmanager ? - List checkAnalyzed = checkAnalyzed(gk); + Set checkAnalyzed = checkAnalyzed(gk); if (checkAnalyzed != null) { // => the group is analyzed, so add it to the ui populateAnalyzedGroup(gk, checkAnalyzed); } @@ -674,7 +676,7 @@ public class GroupManager implements FileUpdateEvent.FileUpdateListener { } else { //if there wasn't already a group check if there should be one now //TODO: use method in groupmanager ? - List checkAnalyzed = checkAnalyzed(gk); + Set checkAnalyzed = checkAnalyzed(gk); if (checkAnalyzed != null) { // => the group is analyzed, so add it to the ui populateAnalyzedGroup(gk, checkAnalyzed); } @@ -759,7 +761,7 @@ public class GroupManager implements FileUpdateEvent.FileUpdateListener { //check if this group is analyzed final GroupKey groupKey = new GroupKey<>(groupBy, val); - List checkAnalyzed = checkAnalyzed(groupKey); + Set checkAnalyzed = checkAnalyzed(groupKey); if (checkAnalyzed != null) { // != null => the group is analyzed, so add it to the ui // makeGroup will create the group and add it to the map groupMap, but does not diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableViewBase.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableViewBase.java index 23164f41fb..e866742505 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableViewBase.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableViewBase.java @@ -22,8 +22,6 @@ package org.sleuthkit.autopsy.imagegallery.gui; import com.google.common.eventbus.Subscribe; import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; -import java.util.List; import java.util.Objects; import java.util.logging.Level; import javafx.application.Platform; @@ -64,21 +62,16 @@ import org.sleuthkit.autopsy.directorytree.ExternalViewerAction; import org.sleuthkit.autopsy.directorytree.ExtractAction; import org.sleuthkit.autopsy.directorytree.NewWindowViewAction; import org.sleuthkit.autopsy.imagegallery.FileIDSelectionModel; -import org.sleuthkit.autopsy.imagegallery.FileUpdateEvent; import org.sleuthkit.autopsy.imagegallery.ImageGalleryController; import org.sleuthkit.autopsy.imagegallery.ImageGalleryTopComponent; import org.sleuthkit.autopsy.imagegallery.TagUtils; import org.sleuthkit.autopsy.imagegallery.actions.AddDrawableTagAction; import org.sleuthkit.autopsy.imagegallery.actions.CategorizeAction; +import org.sleuthkit.autopsy.imagegallery.actions.DeleteFollowUpTag; import org.sleuthkit.autopsy.imagegallery.actions.SwingMenuItemAdapter; import org.sleuthkit.autopsy.imagegallery.datamodel.CategoryChangeEvent; import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableAttribute; import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableFile; -import org.sleuthkit.autopsy.imagegallery.grouping.GroupKey; -import org.sleuthkit.autopsy.ingest.IngestServices; -import org.sleuthkit.autopsy.ingest.ModuleDataEvent; -import org.sleuthkit.datamodel.BlackboardArtifact; -import org.sleuthkit.datamodel.ContentTag; import org.sleuthkit.datamodel.TagName; import org.sleuthkit.datamodel.TskCoreException; @@ -272,28 +265,38 @@ public abstract class DrawableViewBase extends AnchorPane implements DrawableVie LOGGER.log(Level.SEVERE, "Failed to add follow up tag. Could not load TagName.", ex); } } else { - //TODO: convert this to an action! - final ImageGalleryController controller = ImageGalleryController.getDefault(); - try { - // remove file from old category group - controller.getGroupManager().removeFromGroup(new GroupKey(DrawableAttribute.TAGS, TagUtils.getFollowUpTagName()), fileID); - - List contentTagsByContent = Case.getCurrentCase().getServices().getTagsManager().getContentTagsByContent(file); - for (ContentTag ct : contentTagsByContent) { - if (ct.getName().getDisplayName().equals(TagUtils.getFollowUpTagName().getDisplayName())) { - Case.getCurrentCase().getServices().getTagsManager().deleteContentTag(ct); - } - } - IngestServices.getInstance().fireModuleDataEvent(new ModuleDataEvent("TagAction", BlackboardArtifact.ARTIFACT_TYPE.TSK_TAG_FILE)); //NON-NLS - controller.getGroupManager().handleFileUpdate(FileUpdateEvent.newUpdateEvent(Collections.singleton(fileID), DrawableAttribute.TAGS)); - } catch (TskCoreException ex) { - LOGGER.log(Level.SEVERE, "Failed to delete follow up tag.", ex); - } + new DeleteFollowUpTag(file).handle(t); +// deleteFollowupTag(fileID); } - }); } +// /** +// * +// * @param fileID1 the value of fileID1 +// * +// * @throws IllegalStateException +// */ +// private void deleteFollowupTag(final Long fileID1) throws IllegalStateException { +// //TODO: convert this to an action! +// final ImageGalleryController controller = ImageGalleryController.getDefault(); +// try { +// // remove file from old category group +// controller.getGroupManager().removeFromGroup(new GroupKey(DrawableAttribute.TAGS, TagUtils.getFollowUpTagName()), fileID1); +// +// List contentTagsByContent = controller.getSleuthKitCase().getContentTagsByContent(file); +// for (ContentTag ct : contentTagsByContent) { +// if (ct.getName().getDisplayName().equals(TagUtils.getFollowUpTagName().getDisplayName())) { +// controller.getSleuthKitCase().deleteContentTag(ct); +// } +// } +// IngestServices.getInstance().fireModuleDataEvent(new ModuleDataEvent("TagAction", BlackboardArtifact.ARTIFACT_TYPE.TSK_TAG_FILE)); //NON-NLS +// controller.getGroupManager().handleFileUpdate(FileUpdateEvent.newUpdateEvent(Collections.singleton(fileID1), DrawableAttribute.TAGS)); +// } catch (TskCoreException ex) { +// LOGGER.log(Level.SEVERE, "Failed to delete follow up tag.", ex); +// } +// } + @Override public DrawableFile getFile() { if (fileID != null) { From edfe858dd869e7ab4ed17abf91de25a6a9725c93 Mon Sep 17 00:00:00 2001 From: jmillman Date: Tue, 16 Jun 2015 12:51:06 -0400 Subject: [PATCH 05/56] cleanup Follow Up tag and Category TagNames (prevent short name version from being added, by removing commas) --- .../imagegallery/ImageGalleryController.java | 1 + .../autopsy/imagegallery/TagUtils.java | 31 +++++++++++-------- .../actions/DeleteFollowUpTag.java | 2 ++ .../imagegallery/datamodel/Category.java | 19 +++++++----- .../datamodel/CategoryManager.java | 2 ++ 5 files changed, 35 insertions(+), 20 deletions(-) diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java index b93f362dae..8864ddc264 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java @@ -371,6 +371,7 @@ public final class ImageGalleryController { historyManager.clear(); }); Category.clearTagNames(); + TagUtils.clearFollowUpTagName(); Toolbar.getDefault().reset(); groupManager.clear(); diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/TagUtils.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/TagUtils.java index b5eb4cfc25..8e9e8cfc98 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/TagUtils.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/TagUtils.java @@ -20,10 +20,12 @@ package org.sleuthkit.autopsy.imagegallery; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Set; import java.util.logging.Level; +import java.util.stream.Collectors; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.scene.control.MenuItem; @@ -43,34 +45,36 @@ import org.sleuthkit.datamodel.TskCoreException; */ public class TagUtils { - private static final String follow_Up = "Follow Up"; + private static final String FOLLOW_UP = "Follow Up"; private static TagName followUpTagName; + /** + * Use when closing a case to make sure everything is re-initialized in the + * next case. + */ + public static void clearFollowUpTagName() { + followUpTagName = null; + } + private final static List listeners = new ArrayList<>(); synchronized public static TagName getFollowUpTagName() throws TskCoreException { if (followUpTagName == null) { - followUpTagName = getTagName(follow_Up); + followUpTagName = getTagName(FOLLOW_UP); } return followUpTagName; } static public Collection getNonCategoryTagNames() { - List nonCatTagNames = new ArrayList<>(); - List allTagNames; try { - allTagNames = Case.getCurrentCase().getServices().getTagsManager().getAllTagNames(); - for (TagName tn : allTagNames) { - if (tn.getDisplayName().startsWith(Category.CATEGORY_PREFIX) == false) { - nonCatTagNames.add(tn); - } - } + return Case.getCurrentCase().getServices().getTagsManager().getAllTagNames().stream() + .filter(Category::isCategoryTagName) + .collect(Collectors.toSet()); } catch (TskCoreException | IllegalStateException ex) { Logger.getLogger(TagUtils.class.getName()).log(Level.WARNING, "couldn't access case", ex); } - - return nonCatTagNames; + return Collections.emptySet(); } synchronized static public TagName getTagName(String displayName) throws TskCoreException { @@ -94,7 +98,7 @@ public class TagUtils { } public static void fireChange(Collection ids) { - Set listenersCopy = new HashSet(listeners); + Set listenersCopy = new HashSet<>(listeners); synchronized (listeners) { listenersCopy.addAll(listeners); } @@ -132,6 +136,7 @@ public class TagUtils { } public static interface TagListener { + public void handleTagsChanged(Collection ids); } } diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/DeleteFollowUpTag.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/DeleteFollowUpTag.java index 0399b545ed..0fe88de953 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/DeleteFollowUpTag.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/DeleteFollowUpTag.java @@ -78,6 +78,8 @@ public class DeleteFollowUpTag extends Action { } } IngestServices.getInstance().fireModuleDataEvent(new ModuleDataEvent("TagAction", BlackboardArtifact.ARTIFACT_TYPE.TSK_TAG_FILE)); //NON-NLS + + //make sure rest of ui hears category change. controller.getGroupManager().handleFileUpdate(FileUpdateEvent.newUpdateEvent(Collections.singleton(fileID), DrawableAttribute.TAGS)); } catch (TskCoreException ex) { LOGGER.log(Level.SEVERE, "Failed to delete follow up tag.", ex); diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/Category.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/Category.java index 780e851876..4839537731 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/Category.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/Category.java @@ -34,16 +34,17 @@ import org.sleuthkit.datamodel.TskCoreException; */ public enum Category implements Comparable { - ZERO(Color.LIGHTGREY, 0, "CAT-0, Uncategorized"), - ONE(Color.RED, 1, "CAT-1, Child Exploitation (Illegal)"), - TWO(Color.ORANGE, 2, "CAT-2, Child Exploitation (Non-Illegal/Age Difficult)"), - THREE(Color.YELLOW, 3, "CAT-3, CGI/Animation (Child Exploitive)"), - FOUR(Color.BISQUE, 4, "CAT-4, Exemplar/Comparison (Internal Use Only)"), - FIVE(Color.GREEN, 5, "CAT-5, Non-pertinent"); + ZERO(Color.LIGHTGREY, 0, "CAT-0: Uncategorized"), + ONE(Color.RED, 1, "CAT-1: Child Exploitation (Illegal)"), + TWO(Color.ORANGE, 2, "CAT-2: Child Exploitation (Non-Illegal/Age Difficult)"), + THREE(Color.YELLOW, 3, "CAT-3: CGI/Animation (Child Exploitive)"), + FOUR(Color.BISQUE, 4, "CAT-4: Exemplar/Comparison (Internal Use Only)"), + FIVE(Color.GREEN, 5, "CAT-5: Non-pertinent"); /** map from displayName to enum value */ private static final Map nameMap - = Stream.of(values()).collect(Collectors.toMap(Category::getDisplayName, + = Stream.of(values()).collect(Collectors.toMap( + Category::getDisplayName, Function.identity())); public static final String CATEGORY_PREFIX = "CAT-"; @@ -65,6 +66,10 @@ public enum Category implements Comparable { Category.FIVE.tagName = null; } + public static boolean isCategoryTagName(TagName tName) { + return nameMap.containsKey(tName.getDisplayName()); + } + private TagName tagName; private final Color color; diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/CategoryManager.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/CategoryManager.java index 699af41bbb..f6e0404c6e 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/CategoryManager.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/CategoryManager.java @@ -26,6 +26,7 @@ import java.util.Collection; import java.util.concurrent.atomic.LongAdder; import java.util.logging.Level; import org.sleuthkit.autopsy.coreutils.Logger; +import org.sleuthkit.autopsy.imagegallery.TagUtils; /** * Provides a cached view of the number of files per category, and fires @@ -75,6 +76,7 @@ public class CategoryManager { this.db = db; categoryCounts.invalidateAll(); Category.clearTagNames(); + TagUtils.clearFollowUpTagName(); } /** From d587e1c53e6e72de5a447f4e0fe24590c17aacdf Mon Sep 17 00:00:00 2001 From: jmillman Date: Tue, 16 Jun 2015 16:53:16 -0400 Subject: [PATCH 06/56] clean up and refactor code related to Tagging and actions; move away from singleton by injecting controller rather than using getDefault(); use EventBus in DrawableTagsManager (used to be TagUtils) requires equal and hashcode method implemented on TagName --- .../imagegallery/DrawableTagsManager.java | 161 ++++++++++++++++++ .../imagegallery/ImageGalleryController.java | 14 +- .../ImageGalleryTopComponent.java | 3 +- .../autopsy/imagegallery/TagUtils.java | 142 --------------- .../autopsy/imagegallery/TagsChangeEvent.java | 41 +++++ .../actions/AddDrawableTagAction.java | 45 ++--- .../imagegallery/actions/AddTagAction.java | 9 +- .../actions/CategorizeAction.java | 41 +++-- ...eFollowUpTag.java => DeleteTagAction.java} | 42 +++-- .../imagegallery/datamodel/Category.java | 19 --- .../datamodel/CategoryChangeEvent.java | 10 +- .../datamodel/CategoryManager.java | 29 +++- .../imagegallery/datamodel/DrawableDB.java | 15 +- .../imagegallery/grouping/GroupKey.java | 2 +- .../imagegallery/grouping/GroupManager.java | 36 ++-- .../imagegallery/gui/DrawableTile.java | 7 +- .../imagegallery/gui/DrawableView.java | 12 +- .../imagegallery/gui/DrawableViewBase.java | 62 +++---- .../autopsy/imagegallery/gui/GroupPane.java | 39 +++-- .../autopsy/imagegallery/gui/GuiUtils.java | 62 +++++++ .../imagegallery/gui/MetaDataPane.java | 20 ++- .../imagegallery/gui/SlideShowView.java | 12 +- .../autopsy/imagegallery/gui/Toolbar.java | 28 +-- 23 files changed, 494 insertions(+), 357 deletions(-) create mode 100644 ImageGallery/src/org/sleuthkit/autopsy/imagegallery/DrawableTagsManager.java delete mode 100644 ImageGallery/src/org/sleuthkit/autopsy/imagegallery/TagUtils.java create mode 100644 ImageGallery/src/org/sleuthkit/autopsy/imagegallery/TagsChangeEvent.java rename ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/{DeleteFollowUpTag.java => DeleteTagAction.java} (66%) create mode 100644 ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/GuiUtils.java diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/DrawableTagsManager.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/DrawableTagsManager.java new file mode 100644 index 0000000000..3c1dd42de3 --- /dev/null +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/DrawableTagsManager.java @@ -0,0 +1,161 @@ +/* + * Autopsy Forensic Browser + * + * Copyright 2013 Basis Technology Corp. + * Contact: carrier sleuthkit org + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.sleuthkit.autopsy.imagegallery; + +import com.google.common.eventbus.EventBus; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.logging.Level; +import java.util.stream.Collectors; +import org.sleuthkit.autopsy.casemodule.services.TagsManager; +import org.sleuthkit.autopsy.coreutils.Logger; +import org.sleuthkit.autopsy.imagegallery.datamodel.Category; +import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableFile; +import org.sleuthkit.datamodel.ContentTag; +import org.sleuthkit.datamodel.TagName; +import org.sleuthkit.datamodel.TskCoreException; + +/** + * Manages Tags, Tagging, and the relationship between Categories and Tags in + * the autopsy Db. delegates some, work to the backing {@link TagsManager}. + */ +public class DrawableTagsManager { + + private static final String FOLLOW_UP = "Follow Up"; + + private TagsManager autopsyTagsManager; + + /** Used to distribute {@link TagsChangeEvent}s */ + private final EventBus tagsEventBus = new EventBus("Tags Event Bus"); + + /** The tag name corresponging to the "built-in" tag "Follow Up" */ + private TagName followUpTagName; + + public DrawableTagsManager(TagsManager autopsyTagsManager) { + this.autopsyTagsManager = autopsyTagsManager; + + } + + /** + * assign a new TagsManager to back this one, ie when the current case + * changes + * + * @param autopsyTagsManager + */ + public synchronized void setAutopsyTagsManager(TagsManager autopsyTagsManager) { + this.autopsyTagsManager = autopsyTagsManager; + clearFollowUpTagName(); + } + + /** + * Use when closing a case to make sure everything is re-initialized in the + * next case. + */ + public synchronized void clearFollowUpTagName() { + followUpTagName = null; + } + + /** + * fire a CategoryChangeEvent with the given fileIDs + * + * @param fileIDs + */ + public final void fireChange(Collection fileIDs) { + tagsEventBus.post(new TagsChangeEvent(fileIDs)); + } + + /** + * register an object to receive CategoryChangeEvents + * + * @param listner + */ + public void registerListener(Object listner) { + tagsEventBus.register(listner); + } + + /** + * unregister an object from receiving CategoryChangeEvents + * + * @param listener + */ + public void unregisterListener(Object listener) { + tagsEventBus.unregister(listener); + } + + /** + * get the (cached) follow up TagName + * + * @return + * + * @throws TskCoreException + */ + synchronized public TagName getFollowUpTagName() throws TskCoreException { + if (followUpTagName == null) { + followUpTagName = getTagName(FOLLOW_UP); + } + return followUpTagName; + } + + public Collection getNonCategoryTagNames() { + try { + return autopsyTagsManager.getAllTagNames().stream() + .filter(Category::isCategoryTagName) + .collect(Collectors.toSet()); + } catch (TskCoreException | IllegalStateException ex) { + Logger.getLogger(DrawableTagsManager.class.getName()).log(Level.WARNING, "couldn't access case", ex); + } + return Collections.emptySet(); + } + + public synchronized TagName getTagName(String displayName) throws TskCoreException { + try { + for (TagName tn : autopsyTagsManager.getAllTagNames()) { + if (displayName.equals(tn.getDisplayName())) { + return tn; + } + } + try { + return autopsyTagsManager.addTagName(displayName); + } catch (TagsManager.TagNameAlreadyExistsException ex) { + throw new TskCoreException("tagame exists but wasn't found", ex); + } + } catch (IllegalStateException ex) { + Logger.getLogger(DrawableTagsManager.class.getName()).log(Level.SEVERE, "Case was closed out from underneath", ex); + throw new TskCoreException("Case was closed out from underneath", ex); + } + } + + public synchronized TagName getTagName(Category cat) { + try { + return getTagName(cat.getDisplayName()); + } catch (TskCoreException ex) { + return null; + } + } + + public void addContentTag(DrawableFile file, TagName tagName, String comment) throws TskCoreException { + autopsyTagsManager.addContentTag(file, tagName, comment); + } + + public List getContentTagsByTagName(TagName t) throws TskCoreException { + return autopsyTagsManager.getContentTagsByTagName(t); + } + +} diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java index 8864ddc264..ae7a169e96 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java @@ -126,7 +126,8 @@ public final class ImageGalleryController { private final GroupManager groupManager = new GroupManager(this); private final HashSetManager hashSetManager = new HashSetManager(); - private final CategoryManager categoryManager = new CategoryManager(); + private final CategoryManager categoryManager = new CategoryManager(this); + private final DrawableTagsManager tagsManager = new DrawableTagsManager(null); private StackPane fullUIStackPane; @@ -344,7 +345,7 @@ public final class ImageGalleryController { * @param theNewCase the case to configure the controller for */ public synchronized void setCase(Case theNewCase) { - this.db = DrawableDB.getDrawableDB(ImageGalleryModule.getModuleOutputDir(theNewCase), getSleuthKitCase()); + this.db = DrawableDB.getDrawableDB(ImageGalleryModule.getModuleOutputDir(theNewCase), this); setListeningEnabled(ImageGalleryModule.isEnabledforCase(theNewCase)); setStale(ImageGalleryModule.isDrawableDBStale(theNewCase)); @@ -356,6 +357,7 @@ public final class ImageGalleryController { groupManager.setDB(db); hashSetManager.setDb(db); categoryManager.setDb(db); + tagsManager.setAutopsyTagsManager(theNewCase.getServices().getTagsManager()); SummaryTablePane.getDefault().refresh(); } @@ -371,9 +373,9 @@ public final class ImageGalleryController { historyManager.clear(); }); Category.clearTagNames(); - TagUtils.clearFollowUpTagName(); + tagsManager.clearFollowUpTagName(); - Toolbar.getDefault().reset(); + Toolbar.getDefault(this).reset(); groupManager.clear(); if (db != null) { db.closeDBCon(); @@ -489,6 +491,10 @@ public final class ImageGalleryController { return categoryManager; } + public DrawableTagsManager getTagsManager() { + return tagsManager; + } + // @@@ REVIEW IF THIS SHOLD BE STATIC... //TODO: concept seems like the controller deal with how much work to do at a given time // @@@ review this class for synchronization issues (i.e. reset and cancel being called, add, etc.) diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryTopComponent.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryTopComponent.java index 6aa431fb4c..e5c2bb3bd6 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryTopComponent.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryTopComponent.java @@ -34,7 +34,6 @@ import org.openide.util.NbBundle.Messages; import org.openide.windows.Mode; import org.openide.windows.TopComponent; import org.openide.windows.WindowManager; -import org.sleuthkit.autopsy.casemodule.Case; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.imagegallery.gui.GroupPane; import org.sleuthkit.autopsy.imagegallery.gui.MetaDataPane; @@ -145,7 +144,7 @@ public final class ImageGalleryTopComponent extends TopComponent implements Expl fullUIStack.getChildren().add(borderPane); splitPane = new SplitPane(); borderPane.setCenter(splitPane); - borderPane.setTop(Toolbar.getDefault()); + borderPane.setTop(Toolbar.getDefault(controller)); borderPane.setBottom(new StatusBar(controller)); metaDataTable = new MetaDataPane(controller); diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/TagUtils.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/TagUtils.java deleted file mode 100644 index 8e9e8cfc98..0000000000 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/TagUtils.java +++ /dev/null @@ -1,142 +0,0 @@ -/* - * Autopsy Forensic Browser - * - * Copyright 2013 Basis Technology Corp. - * Contact: carrier sleuthkit org - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.sleuthkit.autopsy.imagegallery; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.logging.Level; -import java.util.stream.Collectors; -import javafx.event.ActionEvent; -import javafx.event.EventHandler; -import javafx.scene.control.MenuItem; -import javafx.scene.control.SplitMenuButton; -import javafx.scene.image.ImageView; -import org.sleuthkit.autopsy.casemodule.Case; -import org.sleuthkit.autopsy.casemodule.services.TagsManager; -import org.sleuthkit.autopsy.coreutils.Logger; -import org.sleuthkit.autopsy.imagegallery.actions.AddDrawableTagAction; -import org.sleuthkit.autopsy.imagegallery.datamodel.Category; -import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableAttribute; -import org.sleuthkit.datamodel.TagName; -import org.sleuthkit.datamodel.TskCoreException; - -/** - * Contains static methods for dealing with Tags in ImageGallery - */ -public class TagUtils { - - private static final String FOLLOW_UP = "Follow Up"; - - private static TagName followUpTagName; - - /** - * Use when closing a case to make sure everything is re-initialized in the - * next case. - */ - public static void clearFollowUpTagName() { - followUpTagName = null; - } - - private final static List listeners = new ArrayList<>(); - - synchronized public static TagName getFollowUpTagName() throws TskCoreException { - if (followUpTagName == null) { - followUpTagName = getTagName(FOLLOW_UP); - } - return followUpTagName; - } - - static public Collection getNonCategoryTagNames() { - try { - return Case.getCurrentCase().getServices().getTagsManager().getAllTagNames().stream() - .filter(Category::isCategoryTagName) - .collect(Collectors.toSet()); - } catch (TskCoreException | IllegalStateException ex) { - Logger.getLogger(TagUtils.class.getName()).log(Level.WARNING, "couldn't access case", ex); - } - return Collections.emptySet(); - } - - synchronized static public TagName getTagName(String displayName) throws TskCoreException { - try { - final TagsManager tagsManager = Case.getCurrentCase().getServices().getTagsManager(); - - for (TagName tn : tagsManager.getAllTagNames()) { - if (displayName.equals(tn.getDisplayName())) { - return tn; - } - } - try { - return tagsManager.addTagName(displayName); - } catch (TagsManager.TagNameAlreadyExistsException ex) { - throw new TskCoreException("tagame exists but wasn't found", ex); - } - } catch (IllegalStateException ex) { - Logger.getLogger(TagUtils.class.getName()).log(Level.SEVERE, "Case was closed out from underneath", ex); - throw new TskCoreException("Case was closed out from underneath", ex); - } - } - - public static void fireChange(Collection ids) { - Set listenersCopy = new HashSet<>(listeners); - synchronized (listeners) { - listenersCopy.addAll(listeners); - } - for (TagListener list : listenersCopy) { - list.handleTagsChanged(ids); - } - } - - public static void registerListener(TagListener aThis) { - synchronized (listeners) { - listeners.add(aThis); - } - } - - public static void unregisterListener(TagListener aThis) { - synchronized (listeners) { - listeners.remove(aThis); - } - } - - /** - * @param tn the value of tn - */ - static public MenuItem createSelTagMenuItem(final TagName tn, final SplitMenuButton tagSelectedMenuButton) { - final MenuItem menuItem = new MenuItem(tn.getDisplayName(), new ImageView(DrawableAttribute.TAGS.getIcon())); - menuItem.setOnAction(new EventHandler() { - @Override - public void handle(ActionEvent t) { - AddDrawableTagAction.getInstance().addTag(tn, ""); - tagSelectedMenuButton.setText(tn.getDisplayName()); - tagSelectedMenuButton.setOnAction(this); - } - }); - return menuItem; - } - - public static interface TagListener { - - public void handleTagsChanged(Collection ids); - } -} diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/TagsChangeEvent.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/TagsChangeEvent.java new file mode 100644 index 0000000000..0647a18456 --- /dev/null +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/TagsChangeEvent.java @@ -0,0 +1,41 @@ +/* + * Autopsy Forensic Browser + * + * Copyright 2015 Basis Technology Corp. + * Contact: carrier sleuthkit org + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.sleuthkit.autopsy.imagegallery; + +import java.util.Collection; +import java.util.Collections; +import javax.annotation.concurrent.Immutable; + +/** + * + */ +@Immutable +public class TagsChangeEvent { + + private final Collection fileIDs; + + public Collection getFileIDs() { + return Collections.unmodifiableCollection(fileIDs); + } + + public TagsChangeEvent(Collection fileIDs) { + this.fileIDs = fileIDs; + } + +} diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/AddDrawableTagAction.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/AddDrawableTagAction.java index a098e1a1c9..394f348466 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/AddDrawableTagAction.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/AddDrawableTagAction.java @@ -27,7 +27,6 @@ import javafx.scene.control.Menu; import javax.swing.JOptionPane; import javax.swing.SwingWorker; import org.openide.util.Utilities; -import org.sleuthkit.autopsy.casemodule.Case; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.imagegallery.FileIDSelectionModel; import org.sleuthkit.autopsy.imagegallery.FileUpdateEvent; @@ -45,50 +44,41 @@ import org.sleuthkit.datamodel.TskCoreException; * diverged from autopsy action, make this extend from controlsfx Action */ public class AddDrawableTagAction extends AddTagAction { - + private static final Logger LOGGER = Logger.getLogger(AddDrawableTagAction.class.getName()); - // This class is a singleton to support multi-selection of nodes, since - // org.openide.nodes.NodeOp.findActions(Node[] nodes) will only pick up an Action if every - // node in the array returns a reference to the same action object from Node.getActions(boolean). - private static AddDrawableTagAction instance; - - public static synchronized AddDrawableTagAction getInstance() { - if (null == instance) { - instance = new AddDrawableTagAction(); - } - return instance; + private final ImageGalleryController controller; + + public AddDrawableTagAction(ImageGalleryController controller) { + this.controller = controller; } - - private AddDrawableTagAction() { - } - + public Menu getPopupMenu() { - return new TagMenu(); + return new TagMenu(controller); } - + @Override protected String getActionDisplayName() { return Utilities.actionsGlobalContext().lookupAll(AbstractFile.class).size() > 1 ? "Tag Files" : "Tag File"; } - + @Override public void addTag(TagName tagName, String comment) { Set selectedFiles = new HashSet<>(FileIDSelectionModel.getInstance().getSelected()); addTagsToFiles(tagName, comment, selectedFiles); } - + @Override - public void addTagsToFiles(TagName tagName, String comment, Set selectedFiles){ + public void addTagsToFiles(TagName tagName, String comment, Set selectedFiles) { new SwingWorker() { - + @Override protected Void doInBackground() throws Exception { for (Long fileID : selectedFiles) { try { - DrawableFile file = ImageGalleryController.getDefault().getFileFromId(fileID); + DrawableFile file = controller.getFileFromId(fileID); LOGGER.log(Level.INFO, "tagging {0} with {1} and comment {2}", new Object[]{file.getName(), tagName.getDisplayName(), comment}); - Case.getCurrentCase().getServices().getTagsManager().addContentTag(file, tagName, comment); + controller.getTagsManager().addContentTag(file, tagName, comment); } catch (IllegalStateException ex) { LOGGER.log(Level.SEVERE, "Case was closed out from underneath Updatefile task", ex); } catch (TskCoreException ex) { @@ -97,14 +87,12 @@ public class AddDrawableTagAction extends AddTagAction { } //make sure rest of ui hears category change. - ImageGalleryController.getDefault().getGroupManager().handleFileUpdate(FileUpdateEvent.newUpdateEvent(Collections.singleton(fileID), DrawableAttribute.TAGS)); - + controller.getGroupManager().handleFileUpdate(FileUpdateEvent.newUpdateEvent(Collections.singleton(fileID), DrawableAttribute.TAGS)); } - refreshDirectoryTree(); return null; } - + @Override protected void done() { super.done(); @@ -114,7 +102,6 @@ public class AddDrawableTagAction extends AddTagAction { LOGGER.log(Level.SEVERE, "unexpected exception while tagging files", ex); } } - }.execute(); } } diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/AddTagAction.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/AddTagAction.java index 42cd0ecfd1..94fd9f070a 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/AddTagAction.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/AddTagAction.java @@ -30,6 +30,7 @@ import org.sleuthkit.autopsy.actions.GetTagNameDialog; import org.sleuthkit.autopsy.casemodule.Case; import org.sleuthkit.autopsy.casemodule.services.TagsManager; import org.sleuthkit.autopsy.coreutils.Logger; +import org.sleuthkit.autopsy.imagegallery.ImageGalleryController; import org.sleuthkit.autopsy.imagegallery.datamodel.Category; import org.sleuthkit.autopsy.ingest.IngestServices; import org.sleuthkit.autopsy.ingest.ModuleDataEvent; @@ -43,7 +44,7 @@ import org.sleuthkit.datamodel.TskCoreException; * * //TODO: this class started as a cut and paste from * org.sleuthkit.autopsy.actions.AddTagAction and needs to be - * refactor or reintegrated to the AddTagAction hierarchy of Autopysy. + * refactored or reintegrated to the AddTagAction hierarchy of Autopysy. */ abstract class AddTagAction { @@ -86,7 +87,7 @@ abstract class AddTagAction { // to be reworked. protected class TagMenu extends Menu { - TagMenu() { + TagMenu(ImageGalleryController controller) { super(getActionDisplayName()); // Get the current set of tag names. @@ -147,9 +148,9 @@ abstract class AddTagAction { GetTagNameAndCommentDialog.TagNameAndComment tagNameAndComment = GetTagNameAndCommentDialog.doDialog(); if (null != tagNameAndComment) { if (tagNameAndComment.getTagName().getDisplayName().startsWith(Category.CATEGORY_PREFIX)) { - new CategorizeAction().addTag(tagNameAndComment.getTagName(), tagNameAndComment.getComment()); + new CategorizeAction(controller).addTag(tagNameAndComment.getTagName(), tagNameAndComment.getComment()); } else { - AddDrawableTagAction.getInstance().addTag(tagNameAndComment.getTagName(), tagNameAndComment.getComment()); + new AddDrawableTagAction(controller).addTag(tagNameAndComment.getTagName(), tagNameAndComment.getComment()); } refreshDirectoryTree(); } diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/CategorizeAction.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/CategorizeAction.java index 79a04f535d..358516694e 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/CategorizeAction.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/CategorizeAction.java @@ -29,16 +29,18 @@ import javafx.scene.control.MenuItem; import javafx.scene.input.KeyCode; import javafx.scene.input.KeyCodeCombination; import javax.swing.JOptionPane; -import org.sleuthkit.autopsy.casemodule.Case; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.imagegallery.FileIDSelectionModel; import org.sleuthkit.autopsy.imagegallery.FileUpdateEvent; import org.sleuthkit.autopsy.imagegallery.ImageGalleryController; import org.sleuthkit.autopsy.imagegallery.datamodel.Category; +import org.sleuthkit.autopsy.imagegallery.datamodel.CategoryManager; import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableAttribute; import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableFile; import org.sleuthkit.autopsy.imagegallery.grouping.GroupKey; +import org.sleuthkit.autopsy.imagegallery.grouping.GroupManager; import org.sleuthkit.datamodel.ContentTag; +import org.sleuthkit.datamodel.SleuthkitCase; import org.sleuthkit.datamodel.TagName; import org.sleuthkit.datamodel.TskCoreException; @@ -54,13 +56,13 @@ public class CategorizeAction extends AddTagAction { private final ImageGalleryController controller; - public CategorizeAction() { + public CategorizeAction(ImageGalleryController controller) { super(); - this.controller = ImageGalleryController.getDefault(); + this.controller = controller; } - static public Menu getPopupMenu() { - return new CategoryMenu(); + public Menu getPopupMenu() { + return new CategoryMenu(controller); } @Override @@ -90,7 +92,7 @@ public class CategorizeAction extends AddTagAction { */ static private class CategoryMenu extends Menu { - CategoryMenu() { + CategoryMenu(ImageGalleryController controller) { super("Categorize"); // Each category get an item in the sub-menu. Selecting one of these menu items adds @@ -99,8 +101,8 @@ public class CategorizeAction extends AddTagAction { MenuItem categoryItem = new MenuItem(cat.getDisplayName()); categoryItem.setOnAction((ActionEvent t) -> { - final CategorizeAction categorizeAction = new CategorizeAction(); - categorizeAction.addTag(cat.getTagName(), NO_COMMENT); + final CategorizeAction categorizeAction = new CategorizeAction(controller); + categorizeAction.addTag(controller.getCategoryManager().getTagName(cat), NO_COMMENT); }); categoryItem.setAccelerator(new KeyCodeCombination(KeyCode.getKeyCode(Integer.toString(cat.getCategoryNumber())))); getItems().add(categoryItem); @@ -123,29 +125,34 @@ public class CategorizeAction extends AddTagAction { @Override public void run() { + final GroupManager groupManager = controller.getGroupManager(); + final SleuthkitCase sleuthKitCase = controller.getSleuthKitCase(); + final CategoryManager categoryManager = controller.getCategoryManager(); + try { DrawableFile file = controller.getFileFromId(fileID); //drawable db Category oldCat = file.getCategory(); + // remove file from old category group - controller.getGroupManager().removeFromGroup(new GroupKey(DrawableAttribute.CATEGORY, oldCat), fileID); //memory + groupManager.removeFromGroup(new GroupKey(DrawableAttribute.CATEGORY, oldCat), fileID); //memory //remove old category tag if necessary - List allContentTags = Case.getCurrentCase().getServices().getTagsManager().getContentTagsByContent(file); //tsk db + List allContentTags = sleuthKitCase.getContentTagsByContent(file); //tsk db + for (ContentTag ct : allContentTags) { //this is bad: treating tags as categories as long as their names start with prefix //TODO: abandon using tags for categories and instead add a new column to DrawableDB if (ct.getName().getDisplayName().startsWith(Category.CATEGORY_PREFIX)) { - Case.getCurrentCase().getServices().getTagsManager().deleteContentTag(ct); //tsk db - controller.getCategoryManager().decrementCategoryCount(Category.fromDisplayName(ct.getName().getDisplayName())); //memory/drawable db + sleuthKitCase.deleteContentTag(ct); //tsk db + categoryManager.decrementCategoryCount(Category.fromDisplayName(ct.getName().getDisplayName())); //memory/drawable db } - } - controller.getCategoryManager().incrementCategoryCount(Category.fromDisplayName(tagName.getDisplayName())); //memory/drawable db - if (tagName != Category.ZERO.getTagName()) { // no tags for cat-0 - Case.getCurrentCase().getServices().getTagsManager().addContentTag(file, tagName, comment); //tsk db + categoryManager.incrementCategoryCount(Category.fromDisplayName(tagName.getDisplayName())); //memory/drawable db + if (tagName != categoryManager.getTagName(Category.ZERO)) { // no tags for cat-0 + controller.getTagsManager().addContentTag(file, tagName, comment); //tsk db } //make sure rest of ui hears category change. - controller.getGroupManager().handleFileUpdate(FileUpdateEvent.newUpdateEvent(Collections.singleton(fileID), DrawableAttribute.CATEGORY)); //memory/ui + groupManager.handleFileUpdate(FileUpdateEvent.newUpdateEvent(Collections.singleton(fileID), DrawableAttribute.CATEGORY)); //memory/ui } catch (TskCoreException ex) { LOGGER.log(Level.SEVERE, "Error categorizing result", ex); diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/DeleteFollowUpTag.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/DeleteTagAction.java similarity index 66% rename from ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/DeleteFollowUpTag.java rename to ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/DeleteTagAction.java index 0fe88de953..38a8e40256 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/DeleteFollowUpTag.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/DeleteTagAction.java @@ -19,17 +19,16 @@ package org.sleuthkit.autopsy.imagegallery.actions; import java.util.Collections; -import java.util.List; import java.util.logging.Level; import javafx.event.ActionEvent; import org.controlsfx.control.action.Action; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.imagegallery.FileUpdateEvent; import org.sleuthkit.autopsy.imagegallery.ImageGalleryController; -import org.sleuthkit.autopsy.imagegallery.TagUtils; import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableAttribute; import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableFile; import org.sleuthkit.autopsy.imagegallery.grouping.GroupKey; +import org.sleuthkit.autopsy.imagegallery.grouping.GroupManager; import org.sleuthkit.autopsy.ingest.IngestServices; import org.sleuthkit.autopsy.ingest.ModuleDataEvent; import org.sleuthkit.datamodel.BlackboardArtifact; @@ -39,21 +38,26 @@ import org.sleuthkit.datamodel.TagName; import org.sleuthkit.datamodel.TskCoreException; /** + * Action to delete the follow up tag a + * * */ -public class DeleteFollowUpTag extends Action { +public class DeleteTagAction extends Action { - private static final Logger LOGGER = Logger.getLogger(DeleteFollowUpTag.class.getName()); + private static final Logger LOGGER = Logger.getLogger(DeleteTagAction.class.getName()); private final long fileID; private final DrawableFile file; + private final ImageGalleryController controller; + private final ContentTag tag; - public DeleteFollowUpTag(DrawableFile file) { + public DeleteTagAction(ImageGalleryController controller, DrawableFile file, ContentTag tag) { super("Delete Follow Up Tag"); + this.controller = controller; this.file = file; this.fileID = file.getId(); - + this.tag = tag; setEventHandler((ActionEvent t) -> { - deleteFollowupTag(); + deleteTag(); }); } @@ -63,24 +67,26 @@ public class DeleteFollowUpTag extends Action { * * @throws IllegalStateException */ - private void deleteFollowupTag() throws IllegalStateException { + private void deleteTag() throws IllegalStateException { - final ImageGalleryController controller = ImageGalleryController.getDefault(); final SleuthkitCase sleuthKitCase = controller.getSleuthKitCase(); + final GroupManager groupManager = controller.getGroupManager(); + try { // remove file from old category group - controller.getGroupManager().removeFromGroup(new GroupKey(DrawableAttribute.TAGS, TagUtils.getFollowUpTagName()), fileID); - - List contentTagsByContent = sleuthKitCase.getContentTagsByContent(file); - for (ContentTag ct : contentTagsByContent) { - if (ct.getName().getDisplayName().equals(TagUtils.getFollowUpTagName().getDisplayName())) { - sleuthKitCase.deleteContentTag(ct); - } - } + groupManager.removeFromGroup(new GroupKey(DrawableAttribute.TAGS, tag.getName()), fileID); + sleuthKitCase.deleteContentTag(tag); +// +// List contentTagsByContent = sleuthKitCase.getContentTagsByContent(file); +// for (ContentTag ct : contentTagsByContent) { +// if (ct.getName().getDisplayName().equals(tagsManager.getFollowUpTagName().getDisplayName())) { +// sleuthKitCase.deleteContentTag(ct); +// } +// } IngestServices.getInstance().fireModuleDataEvent(new ModuleDataEvent("TagAction", BlackboardArtifact.ARTIFACT_TYPE.TSK_TAG_FILE)); //NON-NLS //make sure rest of ui hears category change. - controller.getGroupManager().handleFileUpdate(FileUpdateEvent.newUpdateEvent(Collections.singleton(fileID), DrawableAttribute.TAGS)); + groupManager.handleFileUpdate(FileUpdateEvent.newUpdateEvent(Collections.singleton(fileID), DrawableAttribute.TAGS)); } catch (TskCoreException ex) { LOGGER.log(Level.SEVERE, "Failed to delete follow up tag.", ex); } diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/Category.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/Category.java index 4839537731..0ded98426f 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/Category.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/Category.java @@ -20,14 +20,10 @@ package org.sleuthkit.autopsy.imagegallery.datamodel; import java.util.Map; import java.util.function.Function; -import java.util.logging.Level; import java.util.stream.Collectors; import java.util.stream.Stream; import javafx.scene.paint.Color; -import org.sleuthkit.autopsy.coreutils.Logger; -import org.sleuthkit.autopsy.imagegallery.TagUtils; import org.sleuthkit.datamodel.TagName; -import org.sleuthkit.datamodel.TskCoreException; /** * Enum to represent the six categories in the DHs image categorization scheme. @@ -101,19 +97,4 @@ public enum Category implements Comparable { return displayName; } - /** - * get the TagName used to store this Category in the main autopsy db. - * - * @return the TagName used for this Category - */ - public TagName getTagName() { - if (tagName == null) { - try { - tagName = TagUtils.getTagName(displayName); - } catch (TskCoreException ex) { - Logger.getLogger(Category.class.getName()).log(Level.SEVERE, "failed to get TagName for " + displayName, ex); - } - } - return tagName; - } } diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/CategoryChangeEvent.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/CategoryChangeEvent.java index f53acac5f5..9896325e09 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/CategoryChangeEvent.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/CategoryChangeEvent.java @@ -29,16 +29,16 @@ import javax.annotation.concurrent.Immutable; @Immutable public class CategoryChangeEvent { - private final Collection ids; + private final Collection fileIDs; /** * @return the fileIDs of the files whose categories have changed */ - public Collection getIds() { - return Collections.unmodifiableCollection(ids); + public Collection getFileIDs() { + return Collections.unmodifiableCollection(fileIDs); } - public CategoryChangeEvent(Collection ids) { - this.ids = ids; + public CategoryChangeEvent(Collection fileIDs) { + this.fileIDs = fileIDs; } } diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/CategoryManager.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/CategoryManager.java index f6e0404c6e..08ba1b17a5 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/CategoryManager.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/CategoryManager.java @@ -26,7 +26,8 @@ import java.util.Collection; import java.util.concurrent.atomic.LongAdder; import java.util.logging.Level; import org.sleuthkit.autopsy.coreutils.Logger; -import org.sleuthkit.autopsy.imagegallery.TagUtils; +import org.sleuthkit.autopsy.imagegallery.ImageGalleryController; +import org.sleuthkit.datamodel.TagName; /** * Provides a cached view of the number of files per category, and fires @@ -43,6 +44,7 @@ import org.sleuthkit.autopsy.imagegallery.TagUtils; public class CategoryManager { private static final java.util.logging.Logger LOGGER = Logger.getLogger(CategoryManager.class.getName()); + private final ImageGalleryController controller; /** * the DrawableDB that backs the category counts cache. The counts are @@ -63,6 +65,20 @@ public class CategoryManager { */ private final LoadingCache categoryCounts = CacheBuilder.newBuilder().build(CacheLoader.from(this::getCategoryCountHelper)); + /** + * cached TagNames corresponding to Categories, looked up from + * autopsyTagManager at initial request or if invalidated by case change. + */ + private final LoadingCache catTagNameMap = CacheBuilder.newBuilder().build(CacheLoader.from(cat + -> getController().getTagsManager().getTagName(cat))); + + public CategoryManager(ImageGalleryController controller) { + this.controller = controller; + } + + private ImageGalleryController getController() { + return controller; + } /** * assign a new db. the counts cache is invalidated and all subsequent db @@ -75,8 +91,8 @@ public class CategoryManager { public void setDb(DrawableDB db) { this.db = db; categoryCounts.invalidateAll(); + catTagNameMap.invalidateAll(); Category.clearTagNames(); - TagUtils.clearFollowUpTagName(); } /** @@ -171,4 +187,13 @@ public class CategoryManager { categoryEventBus.unregister(listener); } + /** + * get the TagName used to store this Category in the main autopsy db. + * + * @return the TagName used for this Category + */ + public TagName getTagName(Category cat) { + return catTagNameMap.getUnchecked(cat); + + } } diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableDB.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableDB.java index ac1f6c99eb..b043bf126d 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableDB.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableDB.java @@ -47,6 +47,7 @@ import org.openide.util.Exceptions; import org.sleuthkit.autopsy.casemodule.Case; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.imagegallery.FileUpdateEvent; +import org.sleuthkit.autopsy.imagegallery.ImageGalleryController; import org.sleuthkit.autopsy.imagegallery.ImageGalleryModule; import org.sleuthkit.autopsy.imagegallery.grouping.GroupKey; import org.sleuthkit.autopsy.imagegallery.grouping.GroupManager; @@ -147,6 +148,7 @@ public final class DrawableDB { } } private final SleuthkitCase tskCase; + private final ImageGalleryController controller; //////////////general database logic , mostly borrowed from sleuthkitcase /** @@ -195,9 +197,10 @@ public final class DrawableDB { * * @throws SQLException if there is problem creating or configuring the db */ - private DrawableDB(Path dbPath, SleuthkitCase tskCase) throws SQLException, ExceptionInInitializerError, IOException { + private DrawableDB(Path dbPath, ImageGalleryController controller) throws SQLException, ExceptionInInitializerError, IOException { this.dbPath = dbPath; - this.tskCase = tskCase; + this.controller = controller; + this.tskCase = controller.getSleuthKitCase(); Files.createDirectories(dbPath.getParent()); if (initializeDBSchema()) { updateFileStmt = prepareStatement( @@ -286,10 +289,10 @@ public final class DrawableDB { * * @return */ - public static DrawableDB getDrawableDB(Path dbPath, SleuthkitCase tskCase) { + public static DrawableDB getDrawableDB(Path dbPath, ImageGalleryController controller) { try { - return new DrawableDB(dbPath.resolve("drawable.db"), tskCase); + return new DrawableDB(dbPath.resolve("drawable.db"), controller); } catch (SQLException ex) { LOGGER.log(Level.SEVERE, "sql error creating database connection", ex); return null; @@ -1055,7 +1058,7 @@ public final class DrawableDB { public List> getFilesWithCategory(Category cat) throws TskCoreException, IllegalArgumentException { try { List> files = new ArrayList<>(); - List contentTags = Case.getCurrentCase().getServices().getTagsManager().getContentTagsByTagName(cat.getTagName()); + List contentTags = tskCase.getContentTagsByTagName(controller.getTagsManager().getTagName(cat)); for (ContentTag ct : contentTags) { if (ct.getContent() instanceof AbstractFile) { files.add(DrawableFile.create((AbstractFile) ct.getContent(), isFileAnalyzed(ct.getContent().getId()), @@ -1240,7 +1243,7 @@ public final class DrawableDB { */ public long getCategoryCount(Category cat) { try { - return Case.getCurrentCase().getServices().getTagsManager().getContentTagsByTagName(cat.getTagName()).stream() + return tskCase.getContentTagsByTagName(controller.getTagsManager().getTagName(cat)).stream() .map(ContentTag::getContent) .map(Content::getId) .filter(this::isInDB) diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/GroupKey.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/GroupKey.java index 789cac7375..cd41534078 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/GroupKey.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/GroupKey.java @@ -56,7 +56,7 @@ public class GroupKey> implements Comparable @Override public String toString() { - return "GroupKey: " + getAttribute() + " = " + getValue(); + return "GroupKey: " + getAttribute().attrName + " = " + getValue(); } @Override diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/GroupManager.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/GroupManager.java index 68e1044dbc..dab1f9743f 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/GroupManager.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/GroupManager.java @@ -34,6 +34,7 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.logging.Level; import java.util.stream.Collectors; +import java.util.stream.Stream; import javafx.application.Platform; import javafx.beans.property.ReadOnlyDoubleProperty; import javafx.beans.property.ReadOnlyDoubleWrapper; @@ -51,10 +52,10 @@ import org.sleuthkit.autopsy.coreutils.LoggedTask; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.coreutils.ThreadConfined; import org.sleuthkit.autopsy.coreutils.ThreadConfined.ThreadType; +import org.sleuthkit.autopsy.imagegallery.DrawableTagsManager; import org.sleuthkit.autopsy.imagegallery.FileUpdateEvent; import org.sleuthkit.autopsy.imagegallery.ImageGalleryController; import org.sleuthkit.autopsy.imagegallery.ImageGalleryModule; -import org.sleuthkit.autopsy.imagegallery.TagUtils; import org.sleuthkit.autopsy.imagegallery.datamodel.Category; import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableAttribute; import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableDB; @@ -486,31 +487,34 @@ public class GroupManager implements FileUpdateEvent.FileUpdateListener { public Set getFileIDsWithCategory(Category category) throws TskCoreException { try { + final DrawableTagsManager tagsManager = controller.getTagsManager(); if (category == Category.ZERO) { + List< TagName> tns = Stream.of(Category.ONE, Category.TWO, Category.THREE, Category.FOUR, Category.FIVE) + .map(tagsManager::getTagName) + .collect(Collectors.toList()); Set files = new HashSet<>(); - TagName[] tns = {Category.FOUR.getTagName(), Category.THREE.getTagName(), Category.TWO.getTagName(), Category.ONE.getTagName(), Category.FIVE.getTagName()}; for (TagName tn : tns) { - List contentTags = Case.getCurrentCase().getServices().getTagsManager().getContentTagsByTagName(tn); - for (ContentTag ct : contentTags) { - if (ct.getContent() instanceof AbstractFile && db.isInDB(ct.getContent().getId())) { - files.add(ct.getContent().getId()); - } + if (tn != null) { + List contentTags = tagsManager.getContentTagsByTagName(tn); + files.addAll(contentTags.stream() + .filter(ct -> ct.getContent() instanceof AbstractFile) + .filter(ct -> db.isInDB(ct.getContent().getId())) + .map(ct -> ct.getContent().getId()) + .collect(Collectors.toSet())); } } return db.findAllFileIdsWhere("obj_id NOT IN (" + StringUtils.join(files, ',') + ")"); } else { - Set files = new HashSet<>(); - List contentTags = Case.getCurrentCase().getServices().getTagsManager().getContentTagsByTagName(category.getTagName()); - for (ContentTag ct : contentTags) { - if (ct.getContent() instanceof AbstractFile && db.isInDB(ct.getContent().getId())) { - files.add(ct.getContent().getId()); - } - } + List contentTags = tagsManager.getContentTagsByTagName(tagsManager.getTagName(category)); + return contentTags.stream() + .filter(ct -> ct.getContent() instanceof AbstractFile) + .filter(ct -> db.isInDB(ct.getContent().getId())) + .map(ct -> ct.getContent().getId()) + .collect(Collectors.toSet()); - return files; } } catch (TskCoreException ex) { LOGGER.log(Level.WARNING, "TSK error getting files in Category:" + category.getDisplayName(), ex); @@ -688,7 +692,7 @@ public class GroupManager implements FileUpdateEvent.FileUpdateListener { controller.getCategoryManager().fireChange(fileIDs); if (evt.getChangedAttribute() == DrawableAttribute.TAGS) { - TagUtils.fireChange(fileIDs); + controller.getTagsManager().fireChange(fileIDs); } break; } diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableTile.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableTile.java index 80f16a3d7a..75332ba158 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableTile.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableTile.java @@ -32,7 +32,6 @@ import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.coreutils.ThreadConfined; import org.sleuthkit.autopsy.coreutils.ThreadConfined.ThreadType; import org.sleuthkit.autopsy.imagegallery.FXMLConstructor; -import org.sleuthkit.autopsy.imagegallery.TagUtils; import static org.sleuthkit.autopsy.imagegallery.gui.DrawableViewBase.globalSelectionModel; /** @@ -43,7 +42,7 @@ import static org.sleuthkit.autopsy.imagegallery.gui.DrawableViewBase.globalSele * * TODO: refactor this to extend from {@link Control}? -jm */ -public class DrawableTile extends DrawableViewBase implements TagUtils.TagListener { +public class DrawableTile extends DrawableViewBase { private static final DropShadow LAST_SELECTED_EFFECT = new DropShadow(10, Color.BLUE); @@ -73,8 +72,8 @@ public class DrawableTile extends DrawableViewBase implements TagUtils.TagListen setCacheHint(CacheHint.SPEED); nameLabel.prefWidthProperty().bind(imageView.fitWidthProperty()); - imageView.fitHeightProperty().bind(Toolbar.getDefault().sizeSliderValue()); - imageView.fitWidthProperty().bind(Toolbar.getDefault().sizeSliderValue()); + imageView.fitHeightProperty().bind(Toolbar.getDefault(getController()).sizeSliderValue()); + imageView.fitWidthProperty().bind(Toolbar.getDefault(getController()).sizeSliderValue()); globalSelectionModel.lastSelectedProperty().addListener((observable, oldValue, newValue) -> { try { diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableView.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableView.java index 8f91cdf932..ed0453ec0b 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableView.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableView.java @@ -1,7 +1,6 @@ package org.sleuthkit.autopsy.imagegallery.gui; import com.google.common.eventbus.Subscribe; -import java.util.Collection; import java.util.logging.Level; import javafx.application.Platform; import javafx.scene.layout.Border; @@ -13,7 +12,8 @@ import javafx.scene.layout.Region; import javafx.scene.paint.Color; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.coreutils.ThreadConfined; -import org.sleuthkit.autopsy.imagegallery.TagUtils; +import org.sleuthkit.autopsy.imagegallery.ImageGalleryController; +import org.sleuthkit.autopsy.imagegallery.TagsChangeEvent; import org.sleuthkit.autopsy.imagegallery.datamodel.Category; import org.sleuthkit.autopsy.imagegallery.datamodel.CategoryChangeEvent; import org.sleuthkit.autopsy.imagegallery.datamodel.CategoryManager; @@ -25,7 +25,7 @@ import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableFile; * } to have there {@link DrawableView#handleCategoryChanged(org.sleuthkit.autopsy.imagegallery.datamodel.CategoryChangeEvent) * } method invoked */ -public interface DrawableView extends TagUtils.TagListener { +public interface DrawableView { //TODO: do this all in css? -jm static final int CAT_BORDER_WIDTH = 10; @@ -67,8 +67,10 @@ public interface DrawableView extends TagUtils.TagListener { @Subscribe void handleCategoryChanged(CategoryChangeEvent evt); - @Override - void handleTagsChanged(Collection ids); + @Subscribe + void handleTagsChanged(TagsChangeEvent evt); + + ImageGalleryController getController(); default boolean hasHashHit() { try { diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableViewBase.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableViewBase.java index e866742505..7f29af775e 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableViewBase.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableViewBase.java @@ -64,10 +64,10 @@ import org.sleuthkit.autopsy.directorytree.NewWindowViewAction; import org.sleuthkit.autopsy.imagegallery.FileIDSelectionModel; import org.sleuthkit.autopsy.imagegallery.ImageGalleryController; import org.sleuthkit.autopsy.imagegallery.ImageGalleryTopComponent; -import org.sleuthkit.autopsy.imagegallery.TagUtils; +import org.sleuthkit.autopsy.imagegallery.TagsChangeEvent; import org.sleuthkit.autopsy.imagegallery.actions.AddDrawableTagAction; import org.sleuthkit.autopsy.imagegallery.actions.CategorizeAction; -import org.sleuthkit.autopsy.imagegallery.actions.DeleteFollowUpTag; +import org.sleuthkit.autopsy.imagegallery.actions.DeleteTagAction; import org.sleuthkit.autopsy.imagegallery.actions.SwingMenuItemAdapter; import org.sleuthkit.autopsy.imagegallery.datamodel.CategoryChangeEvent; import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableAttribute; @@ -138,6 +138,7 @@ public abstract class DrawableViewBase extends AnchorPane implements DrawableVie */ final private GroupPane groupPane; private boolean registered = false; + private final ImageGalleryController controller; GroupPane getGroupPane() { return groupPane; @@ -145,6 +146,7 @@ public abstract class DrawableViewBase extends AnchorPane implements DrawableVie protected DrawableViewBase(GroupPane groupPane) { this.groupPane = groupPane; + this.controller = groupPane.getController(); globalSelectionModel.getSelected().addListener((Observable observable) -> { updateSelectionState(); }); @@ -194,9 +196,9 @@ public abstract class DrawableViewBase extends AnchorPane implements DrawableVie private ContextMenu buildContextMenu() { final ArrayList menuItems = new ArrayList<>(); - menuItems.add(CategorizeAction.getPopupMenu()); + menuItems.add(new CategorizeAction(controller).getPopupMenu()); - menuItems.add(AddDrawableTagAction.getInstance().getPopupMenu()); + menuItems.add(new AddDrawableTagAction(controller).getPopupMenu()); final MenuItem extractMenuItem = new MenuItem("Extract File(s)"); extractMenuItem.setOnAction((ActionEvent t) -> { @@ -260,43 +262,16 @@ public abstract class DrawableViewBase extends AnchorPane implements DrawableVie if (followUpToggle.isSelected() == true) { globalSelectionModel.clearAndSelect(fileID); try { - AddDrawableTagAction.getInstance().addTag(TagUtils.getFollowUpTagName(), ""); + new AddDrawableTagAction(controller).addTag(ImageGalleryController.getDefault().getTagsManager().getFollowUpTagName(), ""); } catch (TskCoreException ex) { LOGGER.log(Level.SEVERE, "Failed to add follow up tag. Could not load TagName.", ex); } } else { - new DeleteFollowUpTag(file).handle(t); -// deleteFollowupTag(fileID); + new DeleteTagAction(controller, file).handle(t); } }); } -// /** -// * -// * @param fileID1 the value of fileID1 -// * -// * @throws IllegalStateException -// */ -// private void deleteFollowupTag(final Long fileID1) throws IllegalStateException { -// //TODO: convert this to an action! -// final ImageGalleryController controller = ImageGalleryController.getDefault(); -// try { -// // remove file from old category group -// controller.getGroupManager().removeFromGroup(new GroupKey(DrawableAttribute.TAGS, TagUtils.getFollowUpTagName()), fileID1); -// -// List contentTagsByContent = controller.getSleuthKitCase().getContentTagsByContent(file); -// for (ContentTag ct : contentTagsByContent) { -// if (ct.getName().getDisplayName().equals(TagUtils.getFollowUpTagName().getDisplayName())) { -// controller.getSleuthKitCase().deleteContentTag(ct); -// } -// } -// IngestServices.getInstance().fireModuleDataEvent(new ModuleDataEvent("TagAction", BlackboardArtifact.ARTIFACT_TYPE.TSK_TAG_FILE)); //NON-NLS -// controller.getGroupManager().handleFileUpdate(FileUpdateEvent.newUpdateEvent(Collections.singleton(fileID1), DrawableAttribute.TAGS)); -// } catch (TskCoreException ex) { -// LOGGER.log(Level.SEVERE, "Failed to delete follow up tag.", ex); -// } -// } - @Override public DrawableFile getFile() { if (fileID != null) { @@ -315,7 +290,7 @@ public abstract class DrawableViewBase extends AnchorPane implements DrawableVie } protected boolean hasFollowUp() throws TskCoreException { - String followUpTagName = TagUtils.getFollowUpTagName().getDisplayName(); + String followUpTagName = ImageGalleryController.getDefault().getTagsManager().getFollowUpTagName().getDisplayName(); Collection tagNames = DrawableAttribute.TAGS.getValue(getFile()); return tagNames.stream().anyMatch((tn) -> tn.getDisplayName().equals(followUpTagName)); } @@ -326,8 +301,8 @@ public abstract class DrawableViewBase extends AnchorPane implements DrawableVie } @Override - synchronized public void handleTagsChanged(Collection ids) { - if (fileID != null && ids.contains(fileID)) { + synchronized public void handleTagsChanged(TagsChangeEvent evnt) { + if (fileID != null && evnt.getFileIDs().contains(fileID)) { updateFollowUpIcon(); } } @@ -354,8 +329,8 @@ public abstract class DrawableViewBase extends AnchorPane implements DrawableVie if (this.fileID == null || Case.isCaseOpen() == false) { if (registered == true) { - ImageGalleryController.getDefault().getCategoryManager().unregisterListener(this); - TagUtils.unregisterListener(this); + getController().getCategoryManager().unregisterListener(this); + getController().getTagsManager().unregisterListener(this); registered = false; } file = null; @@ -364,8 +339,8 @@ public abstract class DrawableViewBase extends AnchorPane implements DrawableVie }); } else { if (registered == false) { - ImageGalleryController.getDefault().getCategoryManager().registerListener(this); - TagUtils.registerListener(this); + getController().getCategoryManager().registerListener(this); + getController().getTagsManager().registerListener(this); registered = true; } file = null; @@ -411,8 +386,13 @@ public abstract class DrawableViewBase extends AnchorPane implements DrawableVie @Subscribe @Override synchronized public void handleCategoryChanged(CategoryChangeEvent evt) { - if (evt.getIds().contains(getFileID())) { + if (evt.getFileIDs().contains(getFileID())) { updateCategoryBorder(); } } + + @Override + public ImageGalleryController getController() { + return controller; + } } diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/GroupPane.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/GroupPane.java index 30dcf743fb..09042abaf4 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/GroupPane.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/GroupPane.java @@ -100,11 +100,11 @@ import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.coreutils.ThreadConfined; import org.sleuthkit.autopsy.coreutils.ThreadConfined.ThreadType; import org.sleuthkit.autopsy.directorytree.ExtractAction; +import org.sleuthkit.autopsy.imagegallery.DrawableTagsManager; import org.sleuthkit.autopsy.imagegallery.FXMLConstructor; import org.sleuthkit.autopsy.imagegallery.FileIDSelectionModel; import org.sleuthkit.autopsy.imagegallery.ImageGalleryController; import org.sleuthkit.autopsy.imagegallery.ImageGalleryTopComponent; -import org.sleuthkit.autopsy.imagegallery.TagUtils; import org.sleuthkit.autopsy.imagegallery.actions.AddDrawableTagAction; import org.sleuthkit.autopsy.imagegallery.actions.Back; import org.sleuthkit.autopsy.imagegallery.actions.CategorizeAction; @@ -277,7 +277,7 @@ public class GroupPane extends BorderPane implements GroupView { @Override public void handle(ActionEvent t) { Set fileIdSet = new HashSet<>(getGrouping().fileIds()); - new CategorizeAction().addTagsToFiles(cat.getTagName(), "", fileIdSet); + new CategorizeAction(controller).addTagsToFiles(controller.getTagsManager().getTagName(cat), "", fileIdSet); grpCatSplitMenu.setText(cat.getDisplayName()); grpCatSplitMenu.setOnAction(this); @@ -292,7 +292,7 @@ public class GroupPane extends BorderPane implements GroupView { @Override public void handle(ActionEvent t) { Set fileIdSet = new HashSet<>(getGrouping().fileIds()); - AddDrawableTagAction.getInstance().addTagsToFiles(tn, "", fileIdSet); + new AddDrawableTagAction(controller).addTagsToFiles(tn, "", fileIdSet); grpTagSplitMenu.setText(tn.getDisplayName()); grpTagSplitMenu.setOnAction(this); @@ -340,8 +340,8 @@ public class GroupPane extends BorderPane implements GroupView { flashAnimation.setAutoReverse(true); //configure gridView cell properties - gridView.cellHeightProperty().bind(Toolbar.getDefault().sizeSliderValue().add(75)); - gridView.cellWidthProperty().bind(Toolbar.getDefault().sizeSliderValue().add(75)); + gridView.cellHeightProperty().bind(Toolbar.getDefault(controller).sizeSliderValue().add(75)); + gridView.cellWidthProperty().bind(Toolbar.getDefault(controller).sizeSliderValue().add(75)); gridView.setCellFactory((GridView param) -> new DrawableCell()); //configure toolbar properties @@ -349,8 +349,8 @@ public class GroupPane extends BorderPane implements GroupView { spacer.setMinWidth(Region.USE_PREF_SIZE); try { - grpTagSplitMenu.setText(TagUtils.getFollowUpTagName().getDisplayName()); - grpTagSplitMenu.setOnAction(createGrpTagMenuItem(TagUtils.getFollowUpTagName()).getOnAction()); + grpTagSplitMenu.setText(getController().getTagsManager().getFollowUpTagName().getDisplayName()); + grpTagSplitMenu.setOnAction(createGrpTagMenuItem(getController().getTagsManager().getFollowUpTagName()).getOnAction()); } catch (TskCoreException tskCoreException) { LOGGER.log(Level.WARNING, "failed to load FollowUpTagName", tskCoreException); } @@ -358,8 +358,8 @@ public class GroupPane extends BorderPane implements GroupView { grpTagSplitMenu.showingProperty().addListener((ObservableValue ov, Boolean t, Boolean t1) -> { if (t1) { ArrayList selTagMenues = new ArrayList<>(); - for (final TagName tn : TagUtils.getNonCategoryTagNames()) { - MenuItem menuItem = TagUtils.createSelTagMenuItem(tn, grpTagSplitMenu); + for (final TagName tn : getController().getTagsManager().getNonCategoryTagNames()) { + MenuItem menuItem = GuiUtils.createSelTagMenuItem(tn, grpTagSplitMenu, controller); selTagMenues.add(menuItem); } grpTagSplitMenu.getItems().setAll(selTagMenues); @@ -419,9 +419,8 @@ public class GroupPane extends BorderPane implements GroupView { private ContextMenu buildContextMenu() { ArrayList menuItems = new ArrayList<>(); - menuItems.add(CategorizeAction.getPopupMenu()); - - menuItems.add(AddDrawableTagAction.getInstance().getPopupMenu()); + menuItems.add(new CategorizeAction(controller).getPopupMenu()); + menuItems.add(new AddDrawableTagAction(controller).getPopupMenu()); Collection menuProviders = Lookup.getDefault().lookupAll(ContextMenuActionsProvider.class); @@ -653,6 +652,10 @@ public class GroupPane extends BorderPane implements GroupView { } } + ImageGalleryController getController() { + return controller; + } + private class DrawableCell extends GridCell { private final DrawableTile tile = new DrawableTile(GroupPane.this); @@ -751,27 +754,27 @@ public class GroupPane extends BorderPane implements GroupView { switch (t.getCode()) { case NUMPAD0: case DIGIT0: - new CategorizeAction().addTag(Category.ZERO.getTagName(), ""); + new CategorizeAction(controller).addTag(controller.getTagsManager().getTagName(Category.ZERO), ""); break; case NUMPAD1: case DIGIT1: - new CategorizeAction().addTag(Category.ONE.getTagName(), ""); + new CategorizeAction(controller).addTag(controller.getTagsManager().getTagName(Category.ONE), ""); break; case NUMPAD2: case DIGIT2: - new CategorizeAction().addTag(Category.TWO.getTagName(), ""); + new CategorizeAction(controller).addTag(controller.getTagsManager().getTagName(Category.TWO), ""); break; case NUMPAD3: case DIGIT3: - new CategorizeAction().addTag(Category.THREE.getTagName(), ""); + new CategorizeAction(controller).addTag(controller.getTagsManager().getTagName(Category.THREE), ""); break; case NUMPAD4: case DIGIT4: - new CategorizeAction().addTag(Category.FOUR.getTagName(), ""); + new CategorizeAction(controller).addTag(controller.getTagsManager().getTagName(Category.FOUR), ""); break; case NUMPAD5: case DIGIT5: - new CategorizeAction().addTag(Category.FIVE.getTagName(), ""); + new CategorizeAction(controller).addTag(controller.getTagsManager().getTagName(Category.FIVE), ""); break; } } diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/GuiUtils.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/GuiUtils.java new file mode 100644 index 0000000000..4a2a84fd46 --- /dev/null +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/GuiUtils.java @@ -0,0 +1,62 @@ +/* + * Autopsy Forensic Browser + * + * Copyright 2015 Basis Technology Corp. + * Contact: carrier sleuthkit org + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.sleuthkit.autopsy.imagegallery.gui; + +import javafx.event.ActionEvent; +import javafx.event.EventHandler; +import javafx.scene.control.MenuItem; +import javafx.scene.control.SplitMenuButton; +import javafx.scene.image.ImageView; +import org.sleuthkit.autopsy.imagegallery.ImageGalleryController; +import org.sleuthkit.autopsy.imagegallery.actions.AddDrawableTagAction; +import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableAttribute; +import org.sleuthkit.datamodel.TagName; + +/** + * Static utility methods for working with GUI components + */ +public class GuiUtils { + + /** + * make a new menu item that when clicked, tags the selected files with the + * given tagname + * + * @param tagName + * @param tagSelectedMenuButton + * @param controller + * + * @return + */ + public static MenuItem createSelTagMenuItem(final TagName tagName, final SplitMenuButton tagSelectedMenuButton, ImageGalleryController controller) { + final MenuItem menuItem = new MenuItem(tagName.getDisplayName(), new ImageView(DrawableAttribute.TAGS.getIcon())); + menuItem.setOnAction(new EventHandler() { + @Override + public void handle(ActionEvent t) { + new AddDrawableTagAction(controller).addTag(tagName, ""); + tagSelectedMenuButton.setText(tagName.getDisplayName()); + tagSelectedMenuButton.setOnAction(this); + } + }); + return menuItem; + } + + private GuiUtils() { + } + +} diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/MetaDataPane.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/MetaDataPane.java index b4319ac815..f9f6115d67 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/MetaDataPane.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/MetaDataPane.java @@ -45,7 +45,7 @@ import javafx.util.Pair; import org.apache.commons.lang3.StringUtils; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.imagegallery.ImageGalleryController; -import org.sleuthkit.autopsy.imagegallery.TagUtils; +import org.sleuthkit.autopsy.imagegallery.TagsChangeEvent; import org.sleuthkit.autopsy.imagegallery.datamodel.Category; import org.sleuthkit.autopsy.imagegallery.datamodel.CategoryChangeEvent; import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableAttribute; @@ -56,12 +56,17 @@ import org.sleuthkit.datamodel.TskCoreException; /** * Shows details of the selected file. */ -public class MetaDataPane extends AnchorPane implements TagUtils.TagListener, DrawableView { +public class MetaDataPane extends AnchorPane implements DrawableView { private static final Logger LOGGER = Logger.getLogger(MetaDataPane.class.getName()); private final ImageGalleryController controller; + @Override + public ImageGalleryController getController() { + return controller; + } + private Long fileID; @FXML @@ -92,8 +97,8 @@ public class MetaDataPane extends AnchorPane implements TagUtils.TagListener, Dr assert imageView != null : "fx:id=\"imageView\" was not injected: check your FXML file 'MetaDataPane.fxml'."; assert tableView != null : "fx:id=\"tableView\" was not injected: check your FXML file 'MetaDataPane.fxml'."; assert valueColumn != null : "fx:id=\"valueColumn\" was not injected: check your FXML file 'MetaDataPane.fxml'."; - TagUtils.registerListener(this); - ImageGalleryController.getDefault().getCategoryManager().registerListener(this); + getController().getTagsManager().registerListener(this); + getController().getCategoryManager().registerListener(this); tableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY); tableView.setPlaceholder(new Label("Select a file to show its details here.")); @@ -224,14 +229,15 @@ public class MetaDataPane extends AnchorPane implements TagUtils.TagListener, Dr @Subscribe @Override public void handleCategoryChanged(CategoryChangeEvent evt) { - if (getFile() != null && evt.getIds().contains(getFileID())) { + if (getFile() != null && evt.getFileIDs().contains(getFileID())) { updateUI(); } } @Override - public void handleTagsChanged(Collection ids) { - if (getFile() != null && ids.contains(getFileID())) { + @Subscribe + public void handleTagsChanged(TagsChangeEvent evt) { + if (getFile() != null && evt.getFileIDs().contains(getFileID())) { updateUI(); } } diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/SlideShowView.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/SlideShowView.java index 88467e1973..7977eb0219 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/SlideShowView.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/SlideShowView.java @@ -48,9 +48,9 @@ import org.openide.util.Exceptions; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.coreutils.ThreadConfined; import org.sleuthkit.autopsy.coreutils.ThreadConfined.ThreadType; +import org.sleuthkit.autopsy.imagegallery.DrawableTagsManager; import org.sleuthkit.autopsy.imagegallery.FXMLConstructor; import org.sleuthkit.autopsy.imagegallery.FileIDSelectionModel; -import org.sleuthkit.autopsy.imagegallery.TagUtils; import org.sleuthkit.autopsy.imagegallery.actions.CategorizeAction; import org.sleuthkit.autopsy.imagegallery.datamodel.Category; import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableAttribute; @@ -66,7 +66,7 @@ import org.sleuthkit.datamodel.TskCoreException; * GroupPane. TODO: Extract a subclass for video files in slideshow mode-jm * TODO: reduce coupling to GroupPane */ -public class SlideShowView extends DrawableViewBase implements TagUtils.TagListener { +public class SlideShowView extends DrawableViewBase { private static final Logger LOGGER = Logger.getLogger(SlideShowView.class.getName()); @@ -127,7 +127,7 @@ public class SlideShowView extends DrawableViewBase implements TagUtils.TagListe tagSplitButton.setOnAction((ActionEvent t) -> { try { - TagUtils.createSelTagMenuItem(TagUtils.getFollowUpTagName(), tagSplitButton).getOnAction().handle(t); + GuiUtils.createSelTagMenuItem(getController().getTagsManager().getFollowUpTagName(), tagSplitButton, getController()).getOnAction().handle(t); } catch (TskCoreException ex) { Exceptions.printStackTrace(ex); } @@ -137,8 +137,8 @@ public class SlideShowView extends DrawableViewBase implements TagUtils.TagListe tagSplitButton.showingProperty().addListener((ObservableValue ov, Boolean t, Boolean t1) -> { if (t1) { ArrayList selTagMenues = new ArrayList<>(); - for (final TagName tn : TagUtils.getNonCategoryTagNames()) { - MenuItem menuItem = TagUtils.createSelTagMenuItem(tn, tagSplitButton); + for (final TagName tn : getController().getTagsManager().getNonCategoryTagNames()) { + MenuItem menuItem = GuiUtils.createSelTagMenuItem(tn, tagSplitButton, getController()); selTagMenues.add(menuItem); } tagSplitButton.getItems().setAll(selTagMenues); @@ -347,7 +347,7 @@ public class SlideShowView extends DrawableViewBase implements TagUtils.TagListe public void changed(ObservableValue ov, Boolean t, Boolean t1) { if (t1) { FileIDSelectionModel.getInstance().clearAndSelect(getFileID()); - new CategorizeAction().addTag(cat.getTagName(), ""); + new CategorizeAction(getController()).addTag(getController().getTagsManager().getTagName(cat), ""); } } } diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/Toolbar.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/Toolbar.java index bf62f89084..2131ff73fc 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/Toolbar.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/Toolbar.java @@ -41,10 +41,10 @@ import javafx.scene.image.ImageView; import javafx.scene.layout.HBox; import javax.swing.SortOrder; import org.openide.util.Exceptions; +import org.sleuthkit.autopsy.imagegallery.DrawableTagsManager; import org.sleuthkit.autopsy.imagegallery.FXMLConstructor; import org.sleuthkit.autopsy.imagegallery.FileIDSelectionModel; import org.sleuthkit.autopsy.imagegallery.ImageGalleryController; -import org.sleuthkit.autopsy.imagegallery.TagUtils; import org.sleuthkit.autopsy.imagegallery.ThumbnailCache; import org.sleuthkit.autopsy.imagegallery.actions.CategorizeAction; import org.sleuthkit.autopsy.imagegallery.datamodel.Category; @@ -105,6 +105,7 @@ public class Toolbar extends ToolBar { ImageGalleryController.getDefault().getGroupManager().regroup(groupByBox.getSelectionModel().getSelectedItem(), sortByBox.getSelectionModel().getSelectedItem(), getSortOrder(), false); }; + private ImageGalleryController controller; synchronized public SortOrder getSortOrder() { return orderProperty.get(); @@ -117,9 +118,9 @@ public class Toolbar extends ToolBar { return sizeSlider.valueProperty(); } - static synchronized public Toolbar getDefault() { + static synchronized public Toolbar getDefault(ImageGalleryController controller) { if (instance == null) { - instance = new Toolbar(); + instance = new Toolbar(controller); } return instance; } @@ -151,7 +152,7 @@ public class Toolbar extends ToolBar { tagSelectedMenuButton.setOnAction((ActionEvent t) -> { try { - TagUtils.createSelTagMenuItem(TagUtils.getFollowUpTagName(), tagSelectedMenuButton).getOnAction().handle(t); + GuiUtils.createSelTagMenuItem(getController().getTagsManager().getFollowUpTagName(), tagSelectedMenuButton, getController()).getOnAction().handle(t); } catch (TskCoreException ex) { Exceptions.printStackTrace(ex); } @@ -161,22 +162,22 @@ public class Toolbar extends ToolBar { tagSelectedMenuButton.showingProperty().addListener((ObservableValue ov, Boolean t, Boolean t1) -> { if (t1) { ArrayList selTagMenues = new ArrayList<>(); - for (final TagName tn : TagUtils.getNonCategoryTagNames()) { - MenuItem menuItem = TagUtils.createSelTagMenuItem(tn, tagSelectedMenuButton); + for (final TagName tn : getController().getTagsManager().getNonCategoryTagNames()) { + MenuItem menuItem = GuiUtils.createSelTagMenuItem(tn, tagSelectedMenuButton, getController()); selTagMenues.add(menuItem); } tagSelectedMenuButton.getItems().setAll(selTagMenues); } }); - catSelectedMenuButton.setOnAction(createSelCatMenuItem(Category.FIVE, catSelectedMenuButton).getOnAction()); + catSelectedMenuButton.setOnAction(createSelCatMenuItem(Category.FIVE, catSelectedMenuButton, getController()).getOnAction()); catSelectedMenuButton.setText(Category.FIVE.getDisplayName()); catSelectedMenuButton.setGraphic(new ImageView(DrawableAttribute.CATEGORY.getIcon())); catSelectedMenuButton.showingProperty().addListener((ObservableValue ov, Boolean t, Boolean t1) -> { if (t1) { ArrayList categoryMenues = new ArrayList<>(); for (final Category cat : Category.values()) { - MenuItem menuItem = createSelCatMenuItem(cat, catSelectedMenuButton); + MenuItem menuItem = createSelCatMenuItem(cat, catSelectedMenuButton, getController()); categoryMenues.add(menuItem); } catSelectedMenuButton.getItems().setAll(categoryMenues); @@ -221,20 +222,25 @@ public class Toolbar extends ToolBar { }); } - private Toolbar() { + private Toolbar(ImageGalleryController controller) { + this.controller = controller; FXMLConstructor.construct(this, "Toolbar.fxml"); } - private static MenuItem createSelCatMenuItem(Category cat, final SplitMenuButton catSelectedMenuButton) { + private static MenuItem createSelCatMenuItem(Category cat, final SplitMenuButton catSelectedMenuButton, ImageGalleryController controller) { final MenuItem menuItem = new MenuItem(cat.getDisplayName(), new ImageView(DrawableAttribute.CATEGORY.getIcon())); menuItem.setOnAction(new EventHandler() { @Override public void handle(ActionEvent t) { - new CategorizeAction().addTag(cat.getTagName(), ""); + new CategorizeAction(controller).addTag(controller.getTagsManager().getTagName(cat), ""); catSelectedMenuButton.setText(cat.getDisplayName()); catSelectedMenuButton.setOnAction(this); } }); return menuItem; } + + private ImageGalleryController getController() { + return controller; + } } From 16fe7db1e77baf08aeb53295400361fd56688519 Mon Sep 17 00:00:00 2001 From: jmillman Date: Wed, 17 Jun 2015 15:51:15 -0400 Subject: [PATCH 07/56] make sure all code is using the correct TagsManager (DrawableTagsManager) from controller; more cleanup --- .../imagegallery/DrawableTagsManager.java | 49 +++++++++++++++++-- .../imagegallery/ImageGalleryController.java | 39 ++++++++------- .../actions/AddDrawableTagAction.java | 3 +- .../imagegallery/actions/AddTagAction.java | 23 ++------- .../actions/CategorizeAction.java | 3 +- ...tion.java => DeleteFollowUpTagAction.java} | 43 ++++++++-------- .../imagegallery/datamodel/DrawableDB.java | 4 +- .../imagegallery/datamodel/DrawableFile.java | 10 ++-- .../imagegallery/grouping/GroupManager.java | 33 ++++++++++--- .../imagegallery/gui/DrawableViewBase.java | 16 +++--- 10 files changed, 134 insertions(+), 89 deletions(-) rename ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/{DeleteTagAction.java => DeleteFollowUpTagAction.java} (69%) diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/DrawableTagsManager.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/DrawableTagsManager.java index 3c1dd42de3..7ba9ceb842 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/DrawableTagsManager.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/DrawableTagsManager.java @@ -28,6 +28,10 @@ import org.sleuthkit.autopsy.casemodule.services.TagsManager; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.imagegallery.datamodel.Category; import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableFile; +import org.sleuthkit.autopsy.ingest.IngestServices; +import org.sleuthkit.autopsy.ingest.ModuleDataEvent; +import org.sleuthkit.datamodel.BlackboardArtifact; +import org.sleuthkit.datamodel.Content; import org.sleuthkit.datamodel.ContentTag; import org.sleuthkit.datamodel.TagName; import org.sleuthkit.datamodel.TskCoreException; @@ -45,7 +49,7 @@ public class DrawableTagsManager { /** Used to distribute {@link TagsChangeEvent}s */ private final EventBus tagsEventBus = new EventBus("Tags Event Bus"); - /** The tag name corresponging to the "built-in" tag "Follow Up" */ + /** The tag name corresponding to the "built-in" tag "Follow Up" */ private TagName followUpTagName; public DrawableTagsManager(TagsManager autopsyTagsManager) { @@ -113,7 +117,7 @@ public class DrawableTagsManager { return followUpTagName; } - public Collection getNonCategoryTagNames() { + synchronized public Collection getNonCategoryTagNames() { try { return autopsyTagsManager.getAllTagNames().stream() .filter(Category::isCategoryTagName) @@ -124,6 +128,20 @@ public class DrawableTagsManager { return Collections.emptySet(); } + /** + * Gets content tags count by content. + * + * @param The content of interest. + * + * @return A list, possibly empty, of the tags that have been applied to the + * artifact. + * + * @throws TskCoreException + */ + public synchronized List getContentTagsByContent(Content content) throws TskCoreException { + return autopsyTagsManager.getContentTagsByContent(content); + } + public synchronized TagName getTagName(String displayName) throws TskCoreException { try { for (TagName tn : autopsyTagsManager.getAllTagNames()) { @@ -150,12 +168,35 @@ public class DrawableTagsManager { } } - public void addContentTag(DrawableFile file, TagName tagName, String comment) throws TskCoreException { + synchronized public void addContentTag(DrawableFile file, TagName tagName, String comment) throws TskCoreException { autopsyTagsManager.addContentTag(file, tagName, comment); } - public List getContentTagsByTagName(TagName t) throws TskCoreException { + synchronized public List getContentTagsByTagName(TagName t) throws TskCoreException { return autopsyTagsManager.getContentTagsByTagName(t); } + /** + * Fire the ModuleDataEvent that we use as a place holder for a real Tag + * Event. This is used to refresh the autopsy tag tree and the ui in + * ImageGallery + * + * + * Note: this is a hack. In an ideal world, TagsManager would fire + * events so that the directory tree would refresh. But, we haven't + * had a chance to add that so, we fire these events and the tree + * refreshes based on them. + */ + static public void fireTagsChangedEvent() { + + IngestServices.getInstance().fireModuleDataEvent(new ModuleDataEvent("TagAction", BlackboardArtifact.ARTIFACT_TYPE.TSK_TAG_FILE)); //NON-NLS + } + + public synchronized List getAllTagNames() throws TskCoreException { + return autopsyTagsManager.getAllTagNames(); + } + + public synchronized List getTagNamesInUse() throws TskCoreException { + return autopsyTagsManager.getTagNamesInUse(); + } } diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java index ae7a169e96..4bed46a023 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java @@ -21,6 +21,7 @@ package org.sleuthkit.autopsy.imagegallery; import java.beans.PropertyChangeEvent; import java.util.ArrayList; import java.util.List; +import java.util.Objects; import java.util.concurrent.BlockingQueue; import java.util.concurrent.LinkedBlockingQueue; import java.util.logging.Level; @@ -134,6 +135,7 @@ public final class ImageGalleryController { private StackPane centralStackPane; private Node infoOverlay; + private SleuthkitCase sleuthKitCase; public ReadOnlyBooleanProperty getMetaDataCollapsed() { return metaDataCollapsed.getReadOnlyProperty(); @@ -345,20 +347,25 @@ public final class ImageGalleryController { * @param theNewCase the case to configure the controller for */ public synchronized void setCase(Case theNewCase) { - this.db = DrawableDB.getDrawableDB(ImageGalleryModule.getModuleOutputDir(theNewCase), this); + if (Objects.nonNull(theNewCase)) { + this.sleuthKitCase = theNewCase.getSleuthkitCase(); + this.db = DrawableDB.getDrawableDB(ImageGalleryModule.getModuleOutputDir(theNewCase), this); - setListeningEnabled(ImageGalleryModule.isEnabledforCase(theNewCase)); - setStale(ImageGalleryModule.isDrawableDBStale(theNewCase)); + setListeningEnabled(ImageGalleryModule.isEnabledforCase(theNewCase)); + setStale(ImageGalleryModule.isDrawableDBStale(theNewCase)); - // if we add this line icons are made as files are analyzed rather than on demand. - // db.addUpdatedFileListener(IconCache.getDefault()); - restartWorker(); - historyManager.clear(); - groupManager.setDB(db); - hashSetManager.setDb(db); - categoryManager.setDb(db); - tagsManager.setAutopsyTagsManager(theNewCase.getServices().getTagsManager()); - SummaryTablePane.getDefault().refresh(); + // if we add this line icons are made as files are analyzed rather than on demand. + // db.addUpdatedFileListener(IconCache.getDefault()); + restartWorker(); + historyManager.clear(); + groupManager.setDB(db); + hashSetManager.setDb(db); + categoryManager.setDb(db); + tagsManager.setAutopsyTagsManager(theNewCase.getServices().getTagsManager()); + SummaryTablePane.getDefault().refresh(); + } else { + reset(); + } } /** @@ -558,12 +565,8 @@ public final class ImageGalleryController { } } - public SleuthkitCase getSleuthKitCase() throws IllegalStateException { - if (Case.isCaseOpen()) { - return Case.getCurrentCase().getSleuthkitCase(); - } else { - throw new IllegalStateException("No Case is open!"); - } + public synchronized SleuthkitCase getSleuthKitCase() { + return sleuthKitCase; } /** diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/AddDrawableTagAction.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/AddDrawableTagAction.java index 394f348466..9d5c5f277b 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/AddDrawableTagAction.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/AddDrawableTagAction.java @@ -28,6 +28,7 @@ import javax.swing.JOptionPane; import javax.swing.SwingWorker; import org.openide.util.Utilities; import org.sleuthkit.autopsy.coreutils.Logger; +import org.sleuthkit.autopsy.imagegallery.DrawableTagsManager; import org.sleuthkit.autopsy.imagegallery.FileIDSelectionModel; import org.sleuthkit.autopsy.imagegallery.FileUpdateEvent; import org.sleuthkit.autopsy.imagegallery.ImageGalleryController; @@ -89,7 +90,7 @@ public class AddDrawableTagAction extends AddTagAction { //make sure rest of ui hears category change. controller.getGroupManager().handleFileUpdate(FileUpdateEvent.newUpdateEvent(Collections.singleton(fileID), DrawableAttribute.TAGS)); } - refreshDirectoryTree(); + DrawableTagsManager.fireTagsChangedEvent(); return null; } diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/AddTagAction.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/AddTagAction.java index 94fd9f070a..11fac7a403 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/AddTagAction.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/AddTagAction.java @@ -27,14 +27,11 @@ import javafx.scene.control.MenuItem; import javax.swing.SwingUtilities; import org.sleuthkit.autopsy.actions.GetTagNameAndCommentDialog; import org.sleuthkit.autopsy.actions.GetTagNameDialog; -import org.sleuthkit.autopsy.casemodule.Case; import org.sleuthkit.autopsy.casemodule.services.TagsManager; import org.sleuthkit.autopsy.coreutils.Logger; +import org.sleuthkit.autopsy.imagegallery.DrawableTagsManager; import org.sleuthkit.autopsy.imagegallery.ImageGalleryController; import org.sleuthkit.autopsy.imagegallery.datamodel.Category; -import org.sleuthkit.autopsy.ingest.IngestServices; -import org.sleuthkit.autopsy.ingest.ModuleDataEvent; -import org.sleuthkit.datamodel.BlackboardArtifact; import org.sleuthkit.datamodel.TagName; import org.sleuthkit.datamodel.TskCoreException; @@ -48,16 +45,6 @@ import org.sleuthkit.datamodel.TskCoreException; */ abstract class AddTagAction { - @SuppressWarnings("deprecation") - protected void refreshDirectoryTree() { - - /* Note: this is a hack. In an ideal world, TagsManager would fire - * events so that the directory tree would refresh. But, we haven't - * had a chance to add that so, we fire these events and the tree - * refreshes based on them. - */ - IngestServices.getInstance().fireModuleDataEvent(new ModuleDataEvent("TagAction", BlackboardArtifact.ARTIFACT_TYPE.TSK_TAG_FILE)); //NON-NLS - } protected static final String NO_COMMENT = ""; /** @@ -91,7 +78,7 @@ abstract class AddTagAction { super(getActionDisplayName()); // Get the current set of tag names. - TagsManager tagsManager = Case.getCurrentCase().getServices().getTagsManager(); + DrawableTagsManager tagsManager = controller.getTagsManager(); List tagNames = null; try { tagNames = tagsManager.getAllTagNames(); @@ -112,7 +99,7 @@ abstract class AddTagAction { MenuItem tagNameItem = new MenuItem(tagName.getDisplayName()); tagNameItem.setOnAction((ActionEvent t) -> { addTag(tagName, NO_COMMENT); - refreshDirectoryTree(); + DrawableTagsManager.fireTagsChangedEvent(); }); quickTagMenu.getItems().add(tagNameItem); } @@ -133,7 +120,7 @@ abstract class AddTagAction { TagName tagName = GetTagNameDialog.doDialog(); if (tagName != null) { addTag(tagName, NO_COMMENT); - refreshDirectoryTree(); + } }); }); @@ -152,7 +139,7 @@ abstract class AddTagAction { } else { new AddDrawableTagAction(controller).addTag(tagNameAndComment.getTagName(), tagNameAndComment.getComment()); } - refreshDirectoryTree(); + } }); }); diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/CategorizeAction.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/CategorizeAction.java index 358516694e..b3bb065644 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/CategorizeAction.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/CategorizeAction.java @@ -30,6 +30,7 @@ import javafx.scene.input.KeyCode; import javafx.scene.input.KeyCodeCombination; import javax.swing.JOptionPane; import org.sleuthkit.autopsy.coreutils.Logger; +import org.sleuthkit.autopsy.imagegallery.DrawableTagsManager; import org.sleuthkit.autopsy.imagegallery.FileIDSelectionModel; import org.sleuthkit.autopsy.imagegallery.FileUpdateEvent; import org.sleuthkit.autopsy.imagegallery.ImageGalleryController; @@ -159,7 +160,7 @@ public class CategorizeAction extends AddTagAction { JOptionPane.showMessageDialog(null, "Unable to categorize " + fileID + ".", "Categorizing Error", JOptionPane.ERROR_MESSAGE); } - refreshDirectoryTree(); + DrawableTagsManager.fireTagsChangedEvent(); } } } diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/DeleteTagAction.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/DeleteFollowUpTagAction.java similarity index 69% rename from ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/DeleteTagAction.java rename to ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/DeleteFollowUpTagAction.java index 38a8e40256..6a1a54c30d 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/DeleteTagAction.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/DeleteFollowUpTagAction.java @@ -19,19 +19,18 @@ package org.sleuthkit.autopsy.imagegallery.actions; import java.util.Collections; +import java.util.List; import java.util.logging.Level; import javafx.event.ActionEvent; import org.controlsfx.control.action.Action; import org.sleuthkit.autopsy.coreutils.Logger; +import org.sleuthkit.autopsy.imagegallery.DrawableTagsManager; import org.sleuthkit.autopsy.imagegallery.FileUpdateEvent; import org.sleuthkit.autopsy.imagegallery.ImageGalleryController; import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableAttribute; import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableFile; import org.sleuthkit.autopsy.imagegallery.grouping.GroupKey; import org.sleuthkit.autopsy.imagegallery.grouping.GroupManager; -import org.sleuthkit.autopsy.ingest.IngestServices; -import org.sleuthkit.autopsy.ingest.ModuleDataEvent; -import org.sleuthkit.datamodel.BlackboardArtifact; import org.sleuthkit.datamodel.ContentTag; import org.sleuthkit.datamodel.SleuthkitCase; import org.sleuthkit.datamodel.TagName; @@ -39,23 +38,19 @@ import org.sleuthkit.datamodel.TskCoreException; /** * Action to delete the follow up tag a - * - * */ -public class DeleteTagAction extends Action { +public class DeleteFollowUpTagAction extends Action { - private static final Logger LOGGER = Logger.getLogger(DeleteTagAction.class.getName()); + private static final Logger LOGGER = Logger.getLogger(DeleteFollowUpTagAction.class.getName()); private final long fileID; private final DrawableFile file; private final ImageGalleryController controller; - private final ContentTag tag; - public DeleteTagAction(ImageGalleryController controller, DrawableFile file, ContentTag tag) { + public DeleteFollowUpTagAction(ImageGalleryController controller, DrawableFile file) { super("Delete Follow Up Tag"); this.controller = controller; this.file = file; this.fileID = file.getId(); - this.tag = tag; setEventHandler((ActionEvent t) -> { deleteTag(); }); @@ -63,27 +58,28 @@ public class DeleteTagAction extends Action { /** * - * @param fileID1 the value of fileID1 * - * @throws IllegalStateException + * */ - private void deleteTag() throws IllegalStateException { + private void deleteTag() { final SleuthkitCase sleuthKitCase = controller.getSleuthKitCase(); final GroupManager groupManager = controller.getGroupManager(); + final DrawableTagsManager tagsManager = controller.getTagsManager(); try { + final TagName followUpTagName = tagsManager.getFollowUpTagName(); // remove file from old category group - groupManager.removeFromGroup(new GroupKey(DrawableAttribute.TAGS, tag.getName()), fileID); - sleuthKitCase.deleteContentTag(tag); -// -// List contentTagsByContent = sleuthKitCase.getContentTagsByContent(file); -// for (ContentTag ct : contentTagsByContent) { -// if (ct.getName().getDisplayName().equals(tagsManager.getFollowUpTagName().getDisplayName())) { -// sleuthKitCase.deleteContentTag(ct); -// } -// } - IngestServices.getInstance().fireModuleDataEvent(new ModuleDataEvent("TagAction", BlackboardArtifact.ARTIFACT_TYPE.TSK_TAG_FILE)); //NON-NLS + groupManager.removeFromGroup(new GroupKey(DrawableAttribute.TAGS, followUpTagName), fileID); + + List contentTagsByContent = sleuthKitCase.getContentTagsByContent(file); + for (ContentTag ct : contentTagsByContent) { + if (ct.getName().getDisplayName().equals(followUpTagName.getDisplayName())) { + sleuthKitCase.deleteContentTag(ct); + } + } + + DrawableTagsManager.fireTagsChangedEvent(); //make sure rest of ui hears category change. groupManager.handleFileUpdate(FileUpdateEvent.newUpdateEvent(Collections.singleton(fileID), DrawableAttribute.TAGS)); @@ -91,4 +87,5 @@ public class DeleteTagAction extends Action { LOGGER.log(Level.SEVERE, "Failed to delete follow up tag.", ex); } } + } diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableDB.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableDB.java index b043bf126d..49b0818e3b 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableDB.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableDB.java @@ -1058,7 +1058,7 @@ public final class DrawableDB { public List> getFilesWithCategory(Category cat) throws TskCoreException, IllegalArgumentException { try { List> files = new ArrayList<>(); - List contentTags = tskCase.getContentTagsByTagName(controller.getTagsManager().getTagName(cat)); + List contentTags = controller.getTagsManager().getContentTagsByTagName(controller.getTagsManager().getTagName(cat)); for (ContentTag ct : contentTags) { if (ct.getContent() instanceof AbstractFile) { files.add(DrawableFile.create((AbstractFile) ct.getContent(), isFileAnalyzed(ct.getContent().getId()), @@ -1145,7 +1145,7 @@ public final class DrawableDB { * in. * * - * //TODO: why does this go to the SKC? don't we already have this in =fo + * //TODO: why does this go to the SKC? don't we already have this info * in the drawable db? */ @Nonnull diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableFile.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableFile.java index 78bb8c6401..bd4c84dd5e 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableFile.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableFile.java @@ -170,19 +170,16 @@ public abstract class DrawableFile extends AbstractFile public Set getTagNames() { try { - List contentTagsByContent = Case.getCurrentCase().getServices().getTagsManager().getContentTagsByContent(this); - return contentTagsByContent.stream() + return getSleuthkitCase().getContentTagsByContent(this).stream() .map(Tag::getName) .collect(Collectors.toSet()); - } catch (TskCoreException ex) { Logger.getAnonymousLogger().log(Level.WARNING, "problem looking up " + DrawableAttribute.TAGS.getDisplayName() + " for " + file.getName(), ex); - return Collections.emptySet(); } catch (IllegalStateException ex) { Logger.getAnonymousLogger().log(Level.WARNING, "there is no case open; failed to look up " + DrawableAttribute.TAGS.getDisplayName() + " for " + file.getName()); - return Collections.emptySet(); } + return Collections.emptySet(); } @Deprecated @@ -275,7 +272,8 @@ public abstract class DrawableFile extends AbstractFile public void updateCategory() { try { - List contentTagsByContent = Case.getCurrentCase().getServices().getTagsManager().getContentTagsByContent(this); + + List contentTagsByContent = getSleuthkitCase().getContentTagsByContent(this); Category cat = null; for (ContentTag ct : contentTagsByContent) { if (ct.getName().getDisplayName().startsWith(Category.CATEGORY_PREFIX)) { diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/GroupManager.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/GroupManager.java index dab1f9743f..221c7ef4d1 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/GroupManager.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/GroupManager.java @@ -40,6 +40,9 @@ import javafx.beans.property.ReadOnlyDoubleProperty; import javafx.beans.property.ReadOnlyDoubleWrapper; import javafx.collections.FXCollections; import javafx.collections.ObservableList; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import javax.annotation.concurrent.GuardedBy; import javax.swing.SortOrder; import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.StringUtils; @@ -80,11 +83,12 @@ public class GroupManager implements FileUpdateEvent.FileUpdateListener { private DrawableDB db; private final ImageGalleryController controller; + /** * map from {@link GroupKey}s to {@link DrawableGroup}s. All groups (even - * not - * fully analyzed or not visible groups could be in this map + * not fully analyzed or not visible groups could be in this map */ + @GuardedBy("this") private final Map, DrawableGroup> groupMap = new HashMap<>(); /** @@ -153,7 +157,7 @@ public class GroupManager implements FileUpdateEvent.FileUpdateListener { Set> resultSet = new HashSet<>(); for (Comparable val : groupBy.getValue(file)) { if (groupBy == DrawableAttribute.TAGS) { - if (((TagName) val).getDisplayName().startsWith(Category.CATEGORY_PREFIX) == false) { + if (Category.isCategoryTagName((TagName) val) == false) { resultSet.add(new GroupKey(groupBy, val)); } } else { @@ -189,9 +193,24 @@ public class GroupManager implements FileUpdateEvent.FileUpdateListener { * or * null if no group exists for that key. */ - public DrawableGroup getGroupForKey(GroupKey groupKey) { + @Nullable + public DrawableGroup getGroupForKey(@Nonnull GroupKey groupKey) { synchronized (groupMap) { + if (groupKey.getAttribute() == DrawableAttribute.TAGS) { + + System.out.println(groupKey); +// @SuppressWarnings("unchecked") +// GroupKey tagKey = (GroupKey) groupKey; +// +// return groupMap.keySet().stream() +// .filter((GroupKey t) -> t.getAttribute() == DrawableAttribute.TAGS) +// .map((GroupKey t) -> (GroupKey) t) +// .filter(t -> tagKey.getValue().getDisplayName().equals(t.getValue().getDisplayName())) +// .findFirst().map(groupMap::get).orElse(null); + + } //else { return groupMap.get(groupKey); +// } } } @@ -443,7 +462,7 @@ public class GroupManager implements FileUpdateEvent.FileUpdateListener { values = (List) Arrays.asList(Category.values()); break; case TAGS: - values = (List) Case.getCurrentCase().getServices().getTagsManager().getTagNamesInUse().stream() + values = (List) controller.getTagsManager().getTagNamesInUse().stream() .filter(t -> t.getDisplayName().startsWith(Category.CATEGORY_PREFIX) == false) .collect(Collectors.toList()); break; @@ -525,14 +544,12 @@ public class GroupManager implements FileUpdateEvent.FileUpdateListener { public Set getFileIDsWithTag(TagName tagName) throws TskCoreException { try { Set files = new HashSet<>(); - List contentTags = Case.getCurrentCase().getServices().getTagsManager().getContentTagsByTagName(tagName); + List contentTags = controller.getTagsManager().getContentTagsByTagName(tagName); for (ContentTag ct : contentTags) { if (ct.getContent() instanceof AbstractFile && db.isInDB(ct.getContent().getId())) { - files.add(ct.getContent().getId()); } } - return files; } catch (TskCoreException ex) { LOGGER.log(Level.WARNING, "TSK error getting files with Tag:" + tagName.getDisplayName(), ex); diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableViewBase.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableViewBase.java index 7f29af775e..52ac70def0 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableViewBase.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableViewBase.java @@ -67,7 +67,7 @@ import org.sleuthkit.autopsy.imagegallery.ImageGalleryTopComponent; import org.sleuthkit.autopsy.imagegallery.TagsChangeEvent; import org.sleuthkit.autopsy.imagegallery.actions.AddDrawableTagAction; import org.sleuthkit.autopsy.imagegallery.actions.CategorizeAction; -import org.sleuthkit.autopsy.imagegallery.actions.DeleteTagAction; +import org.sleuthkit.autopsy.imagegallery.actions.DeleteFollowUpTagAction; import org.sleuthkit.autopsy.imagegallery.actions.SwingMenuItemAdapter; import org.sleuthkit.autopsy.imagegallery.datamodel.CategoryChangeEvent; import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableAttribute; @@ -257,17 +257,17 @@ public abstract class DrawableViewBase extends AnchorPane implements DrawableVie @SuppressWarnings("deprecation") protected void initialize() { - followUpToggle.setOnAction((ActionEvent t) -> { - + followUpToggle.setOnAction((ActionEvent event) -> { if (followUpToggle.isSelected() == true) { - globalSelectionModel.clearAndSelect(fileID); try { - new AddDrawableTagAction(controller).addTag(ImageGalleryController.getDefault().getTagsManager().getFollowUpTagName(), ""); + final TagName followUpTagName = controller.getTagsManager().getFollowUpTagName(); + globalSelectionModel.clearAndSelect(fileID); + new AddDrawableTagAction(controller).addTag(followUpTagName, ""); } catch (TskCoreException ex) { - LOGGER.log(Level.SEVERE, "Failed to add follow up tag. Could not load TagName.", ex); + LOGGER.log(Level.SEVERE, "Failed to add Follow Up tag. Could not load TagName.", ex); } } else { - new DeleteTagAction(controller, file).handle(t); + new DeleteFollowUpTagAction(controller, file).handle(event); } }); } @@ -290,7 +290,7 @@ public abstract class DrawableViewBase extends AnchorPane implements DrawableVie } protected boolean hasFollowUp() throws TskCoreException { - String followUpTagName = ImageGalleryController.getDefault().getTagsManager().getFollowUpTagName().getDisplayName(); + String followUpTagName = getController().getTagsManager().getFollowUpTagName().getDisplayName(); Collection tagNames = DrawableAttribute.TAGS.getValue(getFile()); return tagNames.stream().anyMatch((tn) -> tn.getDisplayName().equals(followUpTagName)); } From 255219689199ede0ee5e8e98eea3ae0ab5d1ce65 Mon Sep 17 00:00:00 2001 From: jmillman Date: Wed, 17 Jun 2015 15:54:34 -0400 Subject: [PATCH 08/56] more cleanup of Categories/Tags and listening to autopsy generated "Tag Events" -remove unused code from Category.java -use Category.isCategoryTagName instead of .getDisplayName().startsWith(Category.CATEGORY_PREFIX) -regroup when notified of Tag Change from autopsy --- .../imagegallery/DrawableTagsManager.java | 3 +- .../imagegallery/ImageGalleryController.java | 229 +++++++++--------- .../imagegallery/actions/AddTagAction.java | 4 +- .../actions/CategorizeAction.java | 4 +- .../imagegallery/datamodel/Category.java | 29 +-- .../datamodel/CategoryManager.java | 1 - .../imagegallery/datamodel/DrawableFile.java | 22 +- .../imagegallery/grouping/GroupManager.java | 17 +- .../imagegallery/gui/DrawableView.java | 32 +-- .../imagegallery/gui/MetaDataPane.java | 18 +- 10 files changed, 181 insertions(+), 178 deletions(-) diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/DrawableTagsManager.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/DrawableTagsManager.java index 7ba9ceb842..2639de7617 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/DrawableTagsManager.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/DrawableTagsManager.java @@ -22,6 +22,7 @@ import com.google.common.eventbus.EventBus; import java.util.Collection; import java.util.Collections; import java.util.List; +import java.util.Objects; import java.util.logging.Level; import java.util.stream.Collectors; import org.sleuthkit.autopsy.casemodule.services.TagsManager; @@ -111,7 +112,7 @@ public class DrawableTagsManager { * @throws TskCoreException */ synchronized public TagName getFollowUpTagName() throws TskCoreException { - if (followUpTagName == null) { + if (Objects.isNull(followUpTagName)) { followUpTagName = getTagName(FOLLOW_UP); } return followUpTagName; diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java index 4bed46a023..11fd505ba6 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java @@ -20,6 +20,7 @@ package org.sleuthkit.autopsy.imagegallery; import java.beans.PropertyChangeEvent; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.Objects; import java.util.concurrent.BlockingQueue; @@ -57,7 +58,6 @@ import org.sleuthkit.autopsy.casemodule.Case; import org.sleuthkit.autopsy.coreutils.History; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.coreutils.ThreadConfined; -import org.sleuthkit.autopsy.imagegallery.datamodel.Category; import org.sleuthkit.autopsy.imagegallery.datamodel.CategoryManager; import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableDB; import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableFile; @@ -68,6 +68,7 @@ import org.sleuthkit.autopsy.imagegallery.gui.NoGroupsDialog; import org.sleuthkit.autopsy.imagegallery.gui.SummaryTablePane; import org.sleuthkit.autopsy.imagegallery.gui.Toolbar; import org.sleuthkit.autopsy.ingest.IngestManager; +import org.sleuthkit.autopsy.ingest.ModuleDataEvent; import org.sleuthkit.datamodel.AbstractFile; import org.sleuthkit.datamodel.BlackboardArtifact; import org.sleuthkit.datamodel.BlackboardAttribute; @@ -83,25 +84,25 @@ import org.sleuthkit.datamodel.TskData; * control. */ public final class ImageGalleryController { - + private static final Logger LOGGER = Logger.getLogger(ImageGalleryController.class.getName()); - + private final Region infoOverLayBackground = new Region() { { setBackground(new Background(new BackgroundFill(Color.GREY, CornerRadii.EMPTY, Insets.EMPTY))); setOpacity(.4); } }; - + private static ImageGalleryController instance; - + public static synchronized ImageGalleryController getDefault() { if (instance == null) { instance = new ImageGalleryController(); } return instance; } - + private final History historyManager = new History<>(); /** @@ -109,75 +110,75 @@ public final class ImageGalleryController { * not listen to speed up ingest */ private final SimpleBooleanProperty listeningEnabled = new SimpleBooleanProperty(false); - + private final ReadOnlyIntegerWrapper queueSizeProperty = new ReadOnlyIntegerWrapper(0); - + private final ReadOnlyBooleanWrapper regroupDisabled = new ReadOnlyBooleanWrapper(false); - + @ThreadConfined(type = ThreadConfined.ThreadType.JFX) private final ReadOnlyBooleanWrapper stale = new ReadOnlyBooleanWrapper(false); - + private final ReadOnlyBooleanWrapper metaDataCollapsed = new ReadOnlyBooleanWrapper(false); - + private final FileIDSelectionModel selectionModel = FileIDSelectionModel.getInstance(); - + private DBWorkerThread dbWorkerThread; - + private DrawableDB db; - + private final GroupManager groupManager = new GroupManager(this); private final HashSetManager hashSetManager = new HashSetManager(); private final CategoryManager categoryManager = new CategoryManager(this); private final DrawableTagsManager tagsManager = new DrawableTagsManager(null); - + private StackPane fullUIStackPane; - + private StackPane centralStackPane; - + private Node infoOverlay; private SleuthkitCase sleuthKitCase; - + public ReadOnlyBooleanProperty getMetaDataCollapsed() { return metaDataCollapsed.getReadOnlyProperty(); } - + public void setMetaDataCollapsed(Boolean metaDataCollapsed) { this.metaDataCollapsed.set(metaDataCollapsed); } - + private GroupViewState getViewState() { return historyManager.getCurrentState(); } - + public ReadOnlyBooleanProperty regroupDisabled() { return regroupDisabled.getReadOnlyProperty(); } - + public ReadOnlyObjectProperty viewState() { return historyManager.currentState(); } - + public synchronized FileIDSelectionModel getSelectionModel() { - + return selectionModel; } - + public GroupManager getGroupManager() { return groupManager; } - + public DrawableDB getDatabase() { return db; } - + synchronized public void setListeningEnabled(boolean enabled) { listeningEnabled.set(enabled); } - + synchronized boolean isListeningEnabled() { return listeningEnabled.get(); } - + @ThreadConfined(type = ThreadConfined.ThreadType.ANY) void setStale(Boolean b) { Platform.runLater(() -> { @@ -187,18 +188,18 @@ public final class ImageGalleryController { new PerCaseProperties(Case.getCurrentCase()).setConfigSetting(ImageGalleryModule.getModuleName(), PerCaseProperties.STALE, b.toString()); } } - + public ReadOnlyBooleanProperty stale() { return stale.getReadOnlyProperty(); } - + @ThreadConfined(type = ThreadConfined.ThreadType.JFX) boolean isStale() { return stale.get(); } - + private ImageGalleryController() { - + listeningEnabled.addListener((observable, oldValue, newValue) -> { //if we just turned on listening and a case is open and that case is not up to date if (newValue && !oldValue && Case.existsCurrentCase() && ImageGalleryModule.isDrawableDBStale(Case.getCurrentCase())) { @@ -206,28 +207,28 @@ public final class ImageGalleryController { queueDBWorkerTask(new CopyAnalyzedFiles()); } }); - + groupManager.getAnalyzedGroups().addListener((Observable o) -> { if (Case.isCaseOpen()) { checkForGroups(); } }); - + groupManager.getUnSeenGroups().addListener((Observable observable) -> { //if there are unseen groups and none being viewed if (groupManager.getUnSeenGroups().isEmpty() == false && (getViewState() == null || getViewState().getGroup() == null)) { advance(GroupViewState.tile(groupManager.getUnSeenGroups().get(0))); } }); - + viewState().addListener((Observable observable) -> { selectionModel.clearSelection(); }); - + regroupDisabled.addListener((Observable observable) -> { checkForGroups(); }); - + IngestManager.getInstance().addIngestModuleEventListener((PropertyChangeEvent evt) -> { Platform.runLater(this::updateRegroupDisabled); }); @@ -236,27 +237,27 @@ public final class ImageGalleryController { }); // metaDataCollapsed.bind(Toolbar.getDefault().showMetaDataProperty()); } - + public ReadOnlyBooleanProperty getCanAdvance() { return historyManager.getCanAdvance(); } - + public ReadOnlyBooleanProperty getCanRetreat() { return historyManager.getCanRetreat(); } - + public void advance(GroupViewState newState) { historyManager.advance(newState); } - + public GroupViewState advance() { return historyManager.advance(); } - + public GroupViewState retreat() { return historyManager.retreat(); } - + private void updateRegroupDisabled() { regroupDisabled.set(getFileUpdateQueueSizeProperty().get() > 0 || IngestManager.getInstance().isIngestRunning()); } @@ -278,7 +279,7 @@ public final class ImageGalleryController { new NoGroupsDialog("No groups are fully analyzed yet, but ingest is still ongoing. Please Wait.", new ProgressIndicator())); } - + } else if (getFileUpdateQueueSizeProperty().get() > 0) { replaceNotification(fullUIStackPane, new NoGroupsDialog("No groups are fully analyzed yet, but image / video data is still being populated. Please Wait.", @@ -292,19 +293,19 @@ public final class ImageGalleryController { replaceNotification(fullUIStackPane, new NoGroupsDialog("There are no images/videos in the added datasources.")); } - + } else if (!groupManager.isRegrouping()) { replaceNotification(centralStackPane, new NoGroupsDialog("There are no fully analyzed groups to display:" + " the current Group By setting resulted in no groups, " + "or no groups are fully analyzed but ingest is not running.")); } - + } else { clearNotification(); } } - + private void clearNotification() { //remove the ingest spinner if (fullUIStackPane != null) { @@ -315,27 +316,27 @@ public final class ImageGalleryController { centralStackPane.getChildren().remove(infoOverlay); } } - + private void replaceNotification(StackPane stackPane, Node newNode) { clearNotification(); - + infoOverlay = new StackPane(infoOverLayBackground, newNode); if (stackPane != null) { stackPane.getChildren().add(infoOverlay); } } - + private void restartWorker() { if (dbWorkerThread != null) { // Keep using the same worker thread if one exists return; } dbWorkerThread = new DBWorkerThread(); - + getFileUpdateQueueSizeProperty().addListener((Observable o) -> { Platform.runLater(this::updateRegroupDisabled); }); - + Thread th = new Thread(dbWorkerThread); th.setDaemon(false); // we want it to go away when it is done th.start(); @@ -350,7 +351,7 @@ public final class ImageGalleryController { if (Objects.nonNull(theNewCase)) { this.sleuthKitCase = theNewCase.getSleuthkitCase(); this.db = DrawableDB.getDrawableDB(ImageGalleryModule.getModuleOutputDir(theNewCase), this); - + setListeningEnabled(ImageGalleryModule.isEnabledforCase(theNewCase)); setStale(ImageGalleryModule.isDrawableDBStale(theNewCase)); @@ -362,7 +363,9 @@ public final class ImageGalleryController { hashSetManager.setDb(db); categoryManager.setDb(db); tagsManager.setAutopsyTagsManager(theNewCase.getServices().getTagsManager()); + tagsManager.registerListener(groupManager); SummaryTablePane.getDefault().refresh(); + } else { reset(); } @@ -379,9 +382,9 @@ public final class ImageGalleryController { Platform.runLater(() -> { historyManager.clear(); }); - Category.clearTagNames(); tagsManager.clearFollowUpTagName(); - + tagsManager.unregisterListener(groupManager); + Toolbar.getDefault(this).reset(); groupManager.clear(); if (db != null) { @@ -403,21 +406,21 @@ public final class ImageGalleryController { } dbWorkerThread.addTask(innerTask); } - + public DrawableFile getFileFromId(Long fileID) throws TskCoreException { return db.getFileFromID(fileID); } - + public void setStacks(StackPane fullUIStack, StackPane centralStack) { fullUIStackPane = fullUIStack; this.centralStackPane = centralStack; Platform.runLater(this::checkForGroups); } - + public ReadOnlyIntegerProperty getFileUpdateQueueSizeProperty() { return queueSizeProperty.getReadOnlyProperty(); } - + public ReadOnlyDoubleProperty regroupProgress() { return groupManager.regroupProgress(); } @@ -436,6 +439,10 @@ public final class ImageGalleryController { case CONTENT_CHANGED: //TODO: do we need to do anything here? -jm case DATA_ADDED: + ModuleDataEvent oldValue = (ModuleDataEvent) evt.getOldValue(); + if ("TagAction".equals(oldValue.getModuleName()) && oldValue.getArtifactType() == BlackboardArtifact.ARTIFACT_TYPE.TSK_TAG_FILE) { + getTagsManager().fireChange(Collections.singleton(-1L)); + } /* we could listen to DATA events and progressivly * update files, and get data from DataSource ingest * modules, but given that most modules don't post new @@ -489,15 +496,15 @@ public final class ImageGalleryController { } }); } - + public HashSetManager getHashSetManager() { return hashSetManager; } - + public CategoryManager getCategoryManager() { return categoryManager; } - + public DrawableTagsManager getTagsManager() { return tagsManager; } @@ -538,7 +545,7 @@ public final class ImageGalleryController { queueSizeProperty.set(workQueue.size()); }); } - + @Override public void run() { @@ -549,22 +556,22 @@ public final class ImageGalleryController { } try { InnerTask it = workQueue.take(); - + if (it.cancelled == false) { it.run(); } - + Platform.runLater(() -> { queueSizeProperty.set(workQueue.size()); }); - + } catch (InterruptedException ex) { Exceptions.printStackTrace(ex); } } } } - + public synchronized SleuthkitCase getSleuthKitCase() { return sleuthKitCase; } @@ -573,55 +580,55 @@ public final class ImageGalleryController { * Abstract base class for task to be done on {@link DBWorkerThread} */ static public abstract class InnerTask implements Runnable { - + public double getProgress() { return progress.get(); } - + public final void updateProgress(Double workDone) { this.progress.set(workDone); } - + public String getMessage() { return message.get(); } - + public final void updateMessage(String Status) { this.message.set(Status); } SimpleObjectProperty state = new SimpleObjectProperty<>(Worker.State.READY); SimpleDoubleProperty progress = new SimpleDoubleProperty(this, "pregress"); SimpleStringProperty message = new SimpleStringProperty(this, "status"); - + public SimpleDoubleProperty progressProperty() { return progress; } - + public SimpleStringProperty messageProperty() { return message; } - + public Worker.State getState() { return state.get(); } - + protected void updateState(Worker.State newState) { state.set(newState); } - + public ReadOnlyObjectProperty stateProperty() { return new ReadOnlyObjectWrapper<>(state.get()); } - + protected InnerTask() { } - + protected volatile boolean cancelled = false; - + public void cancel() { updateState(Worker.State.CANCELLED); } - + protected boolean isCancelled() { return getState() == Worker.State.CANCELLED; } @@ -631,25 +638,25 @@ public final class ImageGalleryController { * Abstract base class for tasks associated with a file in the database */ static public abstract class FileTask extends InnerTask { - + private final AbstractFile file; - + public AbstractFile getFile() { return file; } - + public FileTask(AbstractFile f) { super(); this.file = f; } - + } /** * task that updates one file in database with results from ingest */ private class UpdateFileTask extends FileTask { - + public UpdateFileTask(AbstractFile f) { super(f); } @@ -676,7 +683,7 @@ public final class ImageGalleryController { * task that updates one file in database with results from ingest */ private class RemoveFileTask extends FileTask { - + public RemoveFileTask(AbstractFile f) { super(f); } @@ -695,7 +702,7 @@ public final class ImageGalleryController { Logger.getLogger(RemoveFileTask.class.getName()).log(Level.SEVERE, "Case was closed out from underneath RemoveFile task"); } } - + } } @@ -707,16 +714,16 @@ public final class ImageGalleryController { * adds them to the Drawable DB */ private class CopyAnalyzedFiles extends InnerTask { - + final private String DRAWABLE_QUERY = "name LIKE '%." + StringUtils.join(ImageGalleryModule.getAllSupportedExtensions(), "' or name LIKE '%.") + "'"; - + private ProgressHandle progressHandle = ProgressHandleFactory.createHandle("populating analyzed image/video database"); - + @Override public void run() { progressHandle.start(); updateMessage("populating analyzed image/video database"); - + try { //grab all files with supported extension or detected mime types final List files = getSleuthKitCase().findAllFilesWhere(DRAWABLE_QUERY + " or tsk_files.obj_id in (select tsk_files.obj_id from tsk_files , blackboard_artifacts, blackboard_attributes" @@ -726,7 +733,7 @@ public final class ImageGalleryController { + " and blackboard_attributes.attribute_type_id = " + BlackboardAttribute.ATTRIBUTE_TYPE.TSK_FILE_TYPE_SIG.getTypeID() + " and blackboard_attributes.value_text in ('" + StringUtils.join(ImageGalleryModule.getSupportedMimes(), "','") + "'))"); progressHandle.switchToDeterminate(files.size()); - + updateProgress(0.0); //do in transaction @@ -740,7 +747,7 @@ public final class ImageGalleryController { } final Boolean hasMimeType = ImageGalleryModule.hasSupportedMimeType(f); final boolean known = f.getKnown() == TskData.FileKnown.KNOWN; - + if (known) { db.removeFile(f.getId(), tr); //remove known files } else { @@ -760,38 +767,38 @@ public final class ImageGalleryController { } } } - + units++; final int prog = units; progressHandle.progress(f.getName(), units); updateProgress(prog - 1 / (double) files.size()); updateMessage(f.getName()); } - + progressHandle.finish(); - + progressHandle = ProgressHandleFactory.createHandle("commiting image/video database"); updateMessage("commiting image/video database"); updateProgress(1.0); - + progressHandle.start(); db.commitTransaction(tr, true); - + } catch (TskCoreException ex) { Logger.getLogger(CopyAnalyzedFiles.class.getName()).log(Level.WARNING, "failed to transfer all database contents", ex); } catch (IllegalStateException ex) { Logger.getLogger(CopyAnalyzedFiles.class.getName()).log(Level.SEVERE, "Case was closed out from underneath CopyDataSource task", ex); } - + progressHandle.finish(); - + updateMessage( ""); updateProgress( -1.0); setStale(false); } - + } /** @@ -802,7 +809,7 @@ public final class ImageGalleryController { * netbeans and ImageGallery progress/status */ class PrePopulateDataSourceFiles extends InnerTask { - + private final Content dataSource; /** @@ -812,7 +819,7 @@ public final class ImageGalleryController { */ // (name like '.jpg' or name like '.png' ...) private final String DRAWABLE_QUERY = "(name LIKE '%." + StringUtils.join(ImageGalleryModule.getAllSupportedExtensions(), "' or name LIKE '%.") + "') "; - + private ProgressHandle progressHandle = ProgressHandleFactory.createHandle("prepopulating image/video database"); /** @@ -838,7 +845,7 @@ public final class ImageGalleryController { final List files; try { List fsObjIds = new ArrayList<>(); - + String fsQuery; if (dataSource instanceof Image) { Image image = (Image) dataSource; @@ -852,7 +859,7 @@ public final class ImageGalleryController { else { fsQuery = "(fs_obj_id IS NULL) "; } - + files = getSleuthKitCase().findAllFilesWhere(fsQuery + " and " + DRAWABLE_QUERY); progressHandle.switchToDeterminate(files.size()); @@ -870,21 +877,21 @@ public final class ImageGalleryController { final int prog = units; progressHandle.progress(f.getName(), units); } - + progressHandle.finish(); progressHandle = ProgressHandleFactory.createHandle("commiting image/video database"); - + progressHandle.start(); db.commitTransaction(tr, false); - + } catch (TskCoreException ex) { Logger.getLogger(PrePopulateDataSourceFiles.class.getName()).log(Level.WARNING, "failed to transfer all database contents", ex); } catch (IllegalStateException | NullPointerException ex) { Logger.getLogger(PrePopulateDataSourceFiles.class.getName()).log(Level.WARNING, "Case was closed out from underneath prepopulating database"); } - + progressHandle.finish(); } } - + } diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/AddTagAction.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/AddTagAction.java index 11fac7a403..5284b7eb71 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/AddTagAction.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/AddTagAction.java @@ -95,7 +95,7 @@ abstract class AddTagAction { // a tag with the associated tag name. if (null != tagNames && !tagNames.isEmpty()) { for (final TagName tagName : tagNames) { - if (tagName.getDisplayName().startsWith(Category.CATEGORY_PREFIX) == false) { + if (Category.isNotCategoryTagName(tagName)) { MenuItem tagNameItem = new MenuItem(tagName.getDisplayName()); tagNameItem.setOnAction((ActionEvent t) -> { addTag(tagName, NO_COMMENT); @@ -134,7 +134,7 @@ abstract class AddTagAction { SwingUtilities.invokeLater(() -> { GetTagNameAndCommentDialog.TagNameAndComment tagNameAndComment = GetTagNameAndCommentDialog.doDialog(); if (null != tagNameAndComment) { - if (tagNameAndComment.getTagName().getDisplayName().startsWith(Category.CATEGORY_PREFIX)) { + if (Category.isCategoryTagName(tagNameAndComment.getTagName())) { new CategorizeAction(controller).addTag(tagNameAndComment.getTagName(), tagNameAndComment.getComment()); } else { new AddDrawableTagAction(controller).addTag(tagNameAndComment.getTagName(), tagNameAndComment.getComment()); diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/CategorizeAction.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/CategorizeAction.java index b3bb065644..1b84b005bf 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/CategorizeAction.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/CategorizeAction.java @@ -141,9 +141,7 @@ public class CategorizeAction extends AddTagAction { List allContentTags = sleuthKitCase.getContentTagsByContent(file); //tsk db for (ContentTag ct : allContentTags) { - //this is bad: treating tags as categories as long as their names start with prefix - //TODO: abandon using tags for categories and instead add a new column to DrawableDB - if (ct.getName().getDisplayName().startsWith(Category.CATEGORY_PREFIX)) { + if (Category.isCategoryTagName(ct.getName())) { sleuthKitCase.deleteContentTag(ct); //tsk db categoryManager.decrementCategoryCount(Category.fromDisplayName(ct.getName().getDisplayName())); //memory/drawable db } diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/Category.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/Category.java index 0ded98426f..ee6a46098e 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/Category.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/Category.java @@ -43,30 +43,25 @@ public enum Category implements Comparable { Category::getDisplayName, Function.identity())); - public static final String CATEGORY_PREFIX = "CAT-"; - public static Category fromDisplayName(String displayName) { return nameMap.get(displayName); } - /** - * Use when closing a case to make sure everything is re-initialized in the - * next case. - */ - public static void clearTagNames() { - Category.ZERO.tagName = null; - Category.ONE.tagName = null; - Category.TWO.tagName = null; - Category.THREE.tagName = null; - Category.FOUR.tagName = null; - Category.FIVE.tagName = null; - } - public static boolean isCategoryTagName(TagName tName) { - return nameMap.containsKey(tName.getDisplayName()); + return isCategoryName(tName.getDisplayName()); } - private TagName tagName; + public static boolean isNotCategoryTagName(TagName tName) { + return isNotCategoryName(tName.getDisplayName()); + } + + public static boolean isCategoryName(String tName) { + return nameMap.containsKey(tName); + } + + public static boolean isNotCategoryName(String tName) { + return nameMap.containsKey(tName) == false; + } private final Color color; diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/CategoryManager.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/CategoryManager.java index 08ba1b17a5..0197c3c847 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/CategoryManager.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/CategoryManager.java @@ -92,7 +92,6 @@ public class CategoryManager { this.db = db; categoryCounts.invalidateAll(); catTagNameMap.invalidateAll(); - Category.clearTagNames(); } /** diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableFile.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableFile.java index bd4c84dd5e..4d3de0d553 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableFile.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableFile.java @@ -46,7 +46,6 @@ import static org.sleuthkit.datamodel.BlackboardAttribute.TSK_BLACKBOARD_ATTRIBU import static org.sleuthkit.datamodel.BlackboardAttribute.TSK_BLACKBOARD_ATTRIBUTE_VALUE_TYPE.LONG; import static org.sleuthkit.datamodel.BlackboardAttribute.TSK_BLACKBOARD_ATTRIBUTE_VALUE_TYPE.STRING; import org.sleuthkit.datamodel.Content; -import org.sleuthkit.datamodel.ContentTag; import org.sleuthkit.datamodel.ContentVisitor; import org.sleuthkit.datamodel.SleuthkitItemVisitor; import org.sleuthkit.datamodel.Tag; @@ -111,7 +110,6 @@ public abstract class DrawableFile extends AbstractFile super(file.getSleuthkitCase(), file.getId(), file.getAttrType(), file.getAttrId(), file.getName(), file.getType(), file.getMetaAddr(), (int) file.getMetaSeq(), file.getDirType(), file.getMetaType(), null, new Integer(0).shortValue(), file.getSize(), file.getCtime(), file.getCrtime(), file.getAtime(), file.getMtime(), new Integer(0).shortValue(), file.getUid(), file.getGid(), file.getMd5Hash(), file.getKnown(), file.getParentPath()); this.analyzed = new SimpleBooleanProperty(analyzed); this.file = file; - } public abstract boolean isVideo(); @@ -272,20 +270,14 @@ public abstract class DrawableFile extends AbstractFile public void updateCategory() { try { + category.set(getSleuthkitCase().getContentTagsByContent(this).stream() + .map(Tag::getName).filter(Category::isCategoryTagName) + .findFirst() + .map(TagName::getDisplayName) + .map(Category::fromDisplayName) + .orElse(Category.ZERO) + ); - List contentTagsByContent = getSleuthkitCase().getContentTagsByContent(this); - Category cat = null; - for (ContentTag ct : contentTagsByContent) { - if (ct.getName().getDisplayName().startsWith(Category.CATEGORY_PREFIX)) { - cat = Category.fromDisplayName(ct.getName().getDisplayName()); - break; - } - } - if (cat == null) { - category.set(Category.ZERO); - } else { - category.set(cat); - } } catch (TskCoreException ex) { Logger.getLogger(DrawableFile.class.getName()).log(Level.WARNING, "problem looking up category for file " + this.getName(), ex); } catch (IllegalStateException ex) { diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/GroupManager.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/GroupManager.java index 221c7ef4d1..cd02ba9c0a 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/GroupManager.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/GroupManager.java @@ -18,6 +18,7 @@ */ package org.sleuthkit.autopsy.imagegallery.grouping; +import com.google.common.eventbus.Subscribe; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; @@ -59,6 +60,7 @@ import org.sleuthkit.autopsy.imagegallery.DrawableTagsManager; import org.sleuthkit.autopsy.imagegallery.FileUpdateEvent; import org.sleuthkit.autopsy.imagegallery.ImageGalleryController; import org.sleuthkit.autopsy.imagegallery.ImageGalleryModule; +import org.sleuthkit.autopsy.imagegallery.TagsChangeEvent; import org.sleuthkit.autopsy.imagegallery.datamodel.Category; import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableAttribute; import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableDB; @@ -157,7 +159,7 @@ public class GroupManager implements FileUpdateEvent.FileUpdateListener { Set> resultSet = new HashSet<>(); for (Comparable val : groupBy.getValue(file)) { if (groupBy == DrawableAttribute.TAGS) { - if (Category.isCategoryTagName((TagName) val) == false) { + if (Category.isNotCategoryTagName((TagName) val)) { resultSet.add(new GroupKey(groupBy, val)); } } else { @@ -463,7 +465,7 @@ public class GroupManager implements FileUpdateEvent.FileUpdateListener { break; case TAGS: values = (List) controller.getTagsManager().getTagNamesInUse().stream() - .filter(t -> t.getDisplayName().startsWith(Category.CATEGORY_PREFIX) == false) + .filter(Category::isNotCategoryTagName) .collect(Collectors.toList()); break; case ANALYZED: @@ -590,7 +592,7 @@ public class GroupManager implements FileUpdateEvent.FileUpdateListener { * @param sortOrder * @param force true to force a full db query regroup */ - public > void regroup(final DrawableAttribute groupBy, final GroupSortBy sortBy, final SortOrder sortOrder, Boolean force) { + public synchronized > void regroup(final DrawableAttribute groupBy, final GroupSortBy sortBy, final SortOrder sortOrder, Boolean force) { if (!Case.isCaseOpen()) { return; @@ -633,6 +635,15 @@ public class GroupManager implements FileUpdateEvent.FileUpdateListener { return regroupProgress.getReadOnlyProperty(); } + @Subscribe + public void handleAutopsyTagChange(TagsChangeEvent evt) { + if (groupBy == DrawableAttribute.TAGS + && evt.getFileIDs().size() == 1 + && evt.getFileIDs().contains(-1L)) { + regroup(groupBy, sortBy, sortOrder, Boolean.TRUE); + } + } + /** * handle {@link FileUpdateEvent} sent from Db when files are * inserted/updated diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableView.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableView.java index ed0453ec0b..93dbae801e 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableView.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableView.java @@ -84,21 +84,25 @@ public interface DrawableView { } static Border getCategoryBorder(Category category) { - switch (category) { - case ONE: - return CAT1_BORDER; - case TWO: - return CAT2_BORDER; - case THREE: - return CAT3_BORDER; - case FOUR: - return CAT4_BORDER; - case FIVE: - return CAT5_BORDER; - case ZERO: - default: - return CAT0_BORDER; + if (category != null) { + switch (category) { + case ONE: + return CAT1_BORDER; + case TWO: + return CAT2_BORDER; + case THREE: + return CAT3_BORDER; + case FOUR: + return CAT4_BORDER; + case FIVE: + return CAT5_BORDER; + case ZERO: + default: + return CAT0_BORDER; + } + } else { + return CAT0_BORDER; } } diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/MetaDataPane.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/MetaDataPane.java index f9f6115d67..4ab6fff208 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/MetaDataPane.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/MetaDataPane.java @@ -92,6 +92,7 @@ public class MetaDataPane extends AnchorPane implements DrawableView { } @FXML + @SuppressWarnings("unchecked") void initialize() { assert attributeColumn != null : "fx:id=\"attributeColumn\" was not injected: check your FXML file 'MetaDataPane.fxml'."; assert imageView != null : "fx:id=\"imageView\" was not injected: check your FXML file 'MetaDataPane.fxml'."; @@ -121,14 +122,12 @@ public class MetaDataPane extends AnchorPane implements DrawableView { attributeColumn.setPrefWidth(USE_COMPUTED_SIZE); valueColumn.setCellValueFactory((p) -> { - if (p.getValue().getKey() == DrawableAttribute.TAGS) { - return new SimpleStringProperty(((Collection) p.getValue().getValue()).stream() - .map(TagName::getDisplayName) - .filter((String t) -> t.startsWith(Category.CATEGORY_PREFIX) == false) - .collect(Collectors.joining(" ; ", "", ""))); - } else { - return new SimpleStringProperty(StringUtils.join((Iterable) p.getValue().getValue(), " ; ")); - } + return (p.getValue().getKey() == DrawableAttribute.TAGS) + ? new SimpleStringProperty(((Collection) p.getValue().getValue()).stream() + .map(TagName::getDisplayName) + .filter(Category::isNotCategoryName) + .collect(Collectors.joining(" ; "))) + : new SimpleStringProperty(StringUtils.join((Iterable) p.getValue().getValue(), " ; ")); }); valueColumn.setPrefWidth(USE_COMPUTED_SIZE); valueColumn.setCellFactory((p) -> new TableCell, ? extends Object>, String>() { @@ -150,9 +149,6 @@ public class MetaDataPane extends AnchorPane implements DrawableView { controller.getSelectionModel().lastSelectedProperty().addListener((observable, oldFileID, newFileID) -> { setFile(newFileID); }); - -// MetaDataPane.this.visibleProperty().bind(controller.getMetaDataCollapsed().not()); -// MetaDataPane.this.managedProperty().bind(controller.getMetaDataCollapsed().not()); } @Override From 6353d3cc0f809b69f8cbe46b022430565e6391d6 Mon Sep 17 00:00:00 2001 From: jmillman Date: Wed, 17 Jun 2015 17:42:00 -0400 Subject: [PATCH 09/56] more work to keep autopsy and ImageGallery tags in sync add setFiles method to DrawableGroup; don't clear groups from GroupMap except for CaseChange; reuse groups via setFiles method when regrouping reselect group in navpanel after regroup --- .../imagegallery/DrawableTagsManager.java | 2 +- .../imagegallery/grouping/DrawableGroup.java | 25 +++++++-- .../imagegallery/grouping/GroupManager.java | 56 ++++++++----------- .../imagegallery/gui/navpanel/NavPanel.java | 6 ++ 4 files changed, 50 insertions(+), 39 deletions(-) diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/DrawableTagsManager.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/DrawableTagsManager.java index 2639de7617..149c7fd888 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/DrawableTagsManager.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/DrawableTagsManager.java @@ -1,7 +1,7 @@ /* * Autopsy Forensic Browser * - * Copyright 2013 Basis Technology Corp. + * Copyright 2013-15 Basis Technology Corp. * Contact: carrier sleuthkit org * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/DrawableGroup.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/DrawableGroup.java index b59a1b8edd..386ae51d65 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/DrawableGroup.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/DrawableGroup.java @@ -134,7 +134,7 @@ public class DrawableGroup implements Comparable { ((DrawableGroup) obj).groupKey); } - synchronized public void addFile(Long f) { + synchronized void addFile(Long f) { invalidateHashSetHitsCount(); if (fileIDs.contains(f) == false) { fileIDs.add(f); @@ -142,7 +142,21 @@ public class DrawableGroup implements Comparable { } } - synchronized public void removeFile(Long f) { + synchronized void setFiles(Set newFileIds) { + invalidateHashSetHitsCount(); + boolean filesRemoved = fileIDs.removeIf((Long t) -> newFileIds.contains(t) == false); + if (filesRemoved) { + seen.set(false); + } + for (Long f : newFileIds) { + if (fileIDs.contains(f) == false) { + fileIDs.add(f); + seen.set(false); + } + } + } + + synchronized void removeFile(Long f) { invalidateHashSetHitsCount(); if (fileIDs.removeAll(f)) { seen.set(false); @@ -151,11 +165,13 @@ public class DrawableGroup implements Comparable { // By default, sort by group key name @Override - public int compareTo(DrawableGroup other) { + public int compareTo(DrawableGroup other + ) { return this.groupKey.getValueDisplayName().compareTo(other.groupKey.getValueDisplayName()); } - void setSeen(boolean isSeen) { + void setSeen(boolean isSeen + ) { this.seen.set(isSeen); } @@ -166,4 +182,5 @@ public class DrawableGroup implements Comparable { public boolean isSeen() { return seen.get(); } + } diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/GroupManager.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/GroupManager.java index cd02ba9c0a..a79b8e3b48 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/GroupManager.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/GroupManager.java @@ -198,21 +198,7 @@ public class GroupManager implements FileUpdateEvent.FileUpdateListener { @Nullable public DrawableGroup getGroupForKey(@Nonnull GroupKey groupKey) { synchronized (groupMap) { - if (groupKey.getAttribute() == DrawableAttribute.TAGS) { - - System.out.println(groupKey); -// @SuppressWarnings("unchecked") -// GroupKey tagKey = (GroupKey) groupKey; -// -// return groupMap.keySet().stream() -// .filter((GroupKey t) -> t.getAttribute() == DrawableAttribute.TAGS) -// .map((GroupKey t) -> (GroupKey) t) -// .filter(t -> tagKey.getValue().getDisplayName().equals(t.getValue().getDisplayName())) -// .findFirst().map(groupMap::get).orElse(null); - - } //else { return groupMap.get(groupKey); -// } } } @@ -255,7 +241,8 @@ public class GroupManager implements FileUpdateEvent.FileUpdateListener { /** * make and return a new group with the given key and files. If a group - * already existed for that key, it will be replaced. + * already existed for that key, it will be updated to contain the given + * files. * * NOTE: this is the only API for making a new group. * @@ -265,28 +252,33 @@ public class GroupManager implements FileUpdateEvent.FileUpdateListener { * @return the new DrawableGroup for the given key */ public DrawableGroup makeGroup(GroupKey groupKey, Set files) { - - Set newFiles = ObjectUtils.defaultIfNull(files, new HashSet()); - final boolean groupSeen = db.isGroupSeen(groupKey); - DrawableGroup g = new DrawableGroup(groupKey, newFiles, groupSeen); - - g.seenProperty().addListener((observable, oldSeen, newSeen) -> { - markGroupSeen(g, newSeen); - }); synchronized (groupMap) { - groupMap.put(groupKey, g); + if (groupMap.containsKey(groupKey)) { + DrawableGroup group = groupMap.get(groupKey); + group.setFiles(ObjectUtils.defaultIfNull(files, Collections.emptySet())); + return group; + } else { + final boolean groupSeen = db.isGroupSeen(groupKey); + DrawableGroup group = new DrawableGroup(groupKey, files, groupSeen); + group.seenProperty().addListener((observable, oldSeen, newSeen) -> { + markGroupSeen(group, newSeen); + }); + groupMap.put(groupKey, group); + return group; + } } - return g; } /** - * 'mark' the given group as seen. This removes it from the queue of groups + * 'mark' the given group as seen. This removes it from the queue of + * groups * to review, and is persisted in the drawable db. * * @param group the {@link DrawableGroup} to mark as seen */ @ThreadConfined(type = ThreadType.JFX) - public void markGroupSeen(DrawableGroup group, boolean seen) { + public void markGroupSeen(DrawableGroup group, boolean seen + ) { db.markGroupSeen(group.getGroupKey(), seen); group.setSeen(seen); if (seen) { @@ -314,9 +306,6 @@ public class GroupManager implements FileUpdateEvent.FileUpdateListener { // If we're grouping by category, we don't want to remove empty groups. if (groupKey.getAttribute() != DrawableAttribute.CATEGORY) { if (group.fileIds().isEmpty()) { - synchronized (groupMap) { - groupMap.remove(groupKey, group); - } Platform.runLater(() -> { analyzedGroups.remove(group); unSeenGroups.remove(group); @@ -624,6 +613,7 @@ public class GroupManager implements FileUpdateEvent.FileUpdateListener { FXCollections.sort(analyzedGroups, sortBy.getGrpComparator(sortOrder)); }); } + } /** @@ -723,6 +713,7 @@ public class GroupManager implements FileUpdateEvent.FileUpdateListener { controller.getTagsManager().fireChange(fileIDs); } break; + } } @@ -768,14 +759,11 @@ public class GroupManager implements FileUpdateEvent.FileUpdateListener { unSeenGroups.clear(); } }); - synchronized (groupMap) { - groupMap.clear(); - } // Get the list of group keys final List vals = findValuesForAttribute(groupBy); - // Make a list of each group + // Make a list of each group final List groups = new ArrayList<>(); groupProgress.start(vals.size()); diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/navpanel/NavPanel.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/navpanel/NavPanel.java index 09b025d75e..482ff66f7c 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/navpanel/NavPanel.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/navpanel/NavPanel.java @@ -155,6 +155,7 @@ public class NavPanel extends TabPane { initNavTree(); controller.getGroupManager().getAnalyzedGroups().addListener((ListChangeListener.Change change) -> { + TreeItem selectedItem = activeTreeProperty.get().getSelectionModel().getSelectedItem(); boolean wasPermuted = false; while (change.next()) { for (DrawableGroup g : change.getAddedSubList()) { @@ -175,6 +176,11 @@ public class NavPanel extends TabPane { if (wasPermuted) { rebuildTrees(); + } + if (selectedItem != null) { + Platform.runLater(() -> { + setFocusedGroup(selectedItem.getValue().getGroup()); + }); } }); From 34eb72655167cdd16b24fe4e5b05106f1131652a Mon Sep 17 00:00:00 2001 From: jmillman Date: Thu, 18 Jun 2015 11:39:16 -0400 Subject: [PATCH 10/56] refactor in GroupManager, to make logic and flow cleaner split FileUpdateEvent handlers to seperate update and removed methods name DbWorkerThread, Thread --- .../autopsy/imagegallery/FileUpdateEvent.java | 5 +- .../imagegallery/ImageGalleryController.java | 222 ++++++------ .../imagegallery/actions/NextUnseenGroup.java | 1 + .../imagegallery/datamodel/DrawableDB.java | 2 +- .../imagegallery/grouping/DrawableGroup.java | 6 +- .../imagegallery/grouping/GroupManager.java | 323 +++++++----------- .../imagegallery/gui/navpanel/NavPanel.java | 4 +- 7 files changed, 238 insertions(+), 325 deletions(-) diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/FileUpdateEvent.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/FileUpdateEvent.java index 038ac4bafb..c2803a5090 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/FileUpdateEvent.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/FileUpdateEvent.java @@ -19,6 +19,7 @@ package org.sleuthkit.autopsy.imagegallery; import java.util.Collection; +import java.util.Collections; import java.util.EventListener; import java.util.HashSet; import java.util.Set; @@ -43,7 +44,7 @@ public class FileUpdateEvent { } public Collection getFileIDs() { - return fileIDs; + return Collections.unmodifiableCollection(fileIDs); } public DrawableAttribute getChangedAttribute() { @@ -86,5 +87,7 @@ public class FileUpdateEvent { public static interface FileUpdateListener extends EventListener { public void handleFileUpdate(FileUpdateEvent evt); + + public void handleFileRemoved(FileUpdateEvent evt); } } diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java index 11fd505ba6..e649afbc39 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java @@ -84,25 +84,25 @@ import org.sleuthkit.datamodel.TskData; * control. */ public final class ImageGalleryController { - + private static final Logger LOGGER = Logger.getLogger(ImageGalleryController.class.getName()); - + private final Region infoOverLayBackground = new Region() { { setBackground(new Background(new BackgroundFill(Color.GREY, CornerRadii.EMPTY, Insets.EMPTY))); setOpacity(.4); } }; - + private static ImageGalleryController instance; - + public static synchronized ImageGalleryController getDefault() { if (instance == null) { instance = new ImageGalleryController(); } return instance; } - + private final History historyManager = new History<>(); /** @@ -110,75 +110,75 @@ public final class ImageGalleryController { * not listen to speed up ingest */ private final SimpleBooleanProperty listeningEnabled = new SimpleBooleanProperty(false); - + private final ReadOnlyIntegerWrapper queueSizeProperty = new ReadOnlyIntegerWrapper(0); - + private final ReadOnlyBooleanWrapper regroupDisabled = new ReadOnlyBooleanWrapper(false); - + @ThreadConfined(type = ThreadConfined.ThreadType.JFX) private final ReadOnlyBooleanWrapper stale = new ReadOnlyBooleanWrapper(false); - + private final ReadOnlyBooleanWrapper metaDataCollapsed = new ReadOnlyBooleanWrapper(false); - + private final FileIDSelectionModel selectionModel = FileIDSelectionModel.getInstance(); - + private DBWorkerThread dbWorkerThread; - + private DrawableDB db; - + private final GroupManager groupManager = new GroupManager(this); private final HashSetManager hashSetManager = new HashSetManager(); private final CategoryManager categoryManager = new CategoryManager(this); private final DrawableTagsManager tagsManager = new DrawableTagsManager(null); - + private StackPane fullUIStackPane; - + private StackPane centralStackPane; - + private Node infoOverlay; private SleuthkitCase sleuthKitCase; - + public ReadOnlyBooleanProperty getMetaDataCollapsed() { return metaDataCollapsed.getReadOnlyProperty(); } - + public void setMetaDataCollapsed(Boolean metaDataCollapsed) { this.metaDataCollapsed.set(metaDataCollapsed); } - + private GroupViewState getViewState() { return historyManager.getCurrentState(); } - + public ReadOnlyBooleanProperty regroupDisabled() { return regroupDisabled.getReadOnlyProperty(); } - + public ReadOnlyObjectProperty viewState() { return historyManager.currentState(); } - + public synchronized FileIDSelectionModel getSelectionModel() { - + return selectionModel; } - + public GroupManager getGroupManager() { return groupManager; } - + public DrawableDB getDatabase() { return db; } - + synchronized public void setListeningEnabled(boolean enabled) { listeningEnabled.set(enabled); } - + synchronized boolean isListeningEnabled() { return listeningEnabled.get(); } - + @ThreadConfined(type = ThreadConfined.ThreadType.ANY) void setStale(Boolean b) { Platform.runLater(() -> { @@ -188,18 +188,18 @@ public final class ImageGalleryController { new PerCaseProperties(Case.getCurrentCase()).setConfigSetting(ImageGalleryModule.getModuleName(), PerCaseProperties.STALE, b.toString()); } } - + public ReadOnlyBooleanProperty stale() { return stale.getReadOnlyProperty(); } - + @ThreadConfined(type = ThreadConfined.ThreadType.JFX) boolean isStale() { return stale.get(); } - + private ImageGalleryController() { - + listeningEnabled.addListener((observable, oldValue, newValue) -> { //if we just turned on listening and a case is open and that case is not up to date if (newValue && !oldValue && Case.existsCurrentCase() && ImageGalleryModule.isDrawableDBStale(Case.getCurrentCase())) { @@ -207,28 +207,28 @@ public final class ImageGalleryController { queueDBWorkerTask(new CopyAnalyzedFiles()); } }); - + groupManager.getAnalyzedGroups().addListener((Observable o) -> { if (Case.isCaseOpen()) { checkForGroups(); } }); - + groupManager.getUnSeenGroups().addListener((Observable observable) -> { //if there are unseen groups and none being viewed if (groupManager.getUnSeenGroups().isEmpty() == false && (getViewState() == null || getViewState().getGroup() == null)) { advance(GroupViewState.tile(groupManager.getUnSeenGroups().get(0))); } }); - + viewState().addListener((Observable observable) -> { selectionModel.clearSelection(); }); - + regroupDisabled.addListener((Observable observable) -> { checkForGroups(); }); - + IngestManager.getInstance().addIngestModuleEventListener((PropertyChangeEvent evt) -> { Platform.runLater(this::updateRegroupDisabled); }); @@ -237,27 +237,27 @@ public final class ImageGalleryController { }); // metaDataCollapsed.bind(Toolbar.getDefault().showMetaDataProperty()); } - + public ReadOnlyBooleanProperty getCanAdvance() { return historyManager.getCanAdvance(); } - + public ReadOnlyBooleanProperty getCanRetreat() { return historyManager.getCanRetreat(); } - + public void advance(GroupViewState newState) { historyManager.advance(newState); } - + public GroupViewState advance() { return historyManager.advance(); } - + public GroupViewState retreat() { return historyManager.retreat(); } - + private void updateRegroupDisabled() { regroupDisabled.set(getFileUpdateQueueSizeProperty().get() > 0 || IngestManager.getInstance().isIngestRunning()); } @@ -279,7 +279,7 @@ public final class ImageGalleryController { new NoGroupsDialog("No groups are fully analyzed yet, but ingest is still ongoing. Please Wait.", new ProgressIndicator())); } - + } else if (getFileUpdateQueueSizeProperty().get() > 0) { replaceNotification(fullUIStackPane, new NoGroupsDialog("No groups are fully analyzed yet, but image / video data is still being populated. Please Wait.", @@ -293,19 +293,19 @@ public final class ImageGalleryController { replaceNotification(fullUIStackPane, new NoGroupsDialog("There are no images/videos in the added datasources.")); } - + } else if (!groupManager.isRegrouping()) { replaceNotification(centralStackPane, new NoGroupsDialog("There are no fully analyzed groups to display:" + " the current Group By setting resulted in no groups, " + "or no groups are fully analyzed but ingest is not running.")); } - + } else { clearNotification(); } } - + private void clearNotification() { //remove the ingest spinner if (fullUIStackPane != null) { @@ -316,28 +316,28 @@ public final class ImageGalleryController { centralStackPane.getChildren().remove(infoOverlay); } } - + private void replaceNotification(StackPane stackPane, Node newNode) { clearNotification(); - + infoOverlay = new StackPane(infoOverLayBackground, newNode); if (stackPane != null) { stackPane.getChildren().add(infoOverlay); } } - + private void restartWorker() { if (dbWorkerThread != null) { // Keep using the same worker thread if one exists return; } dbWorkerThread = new DBWorkerThread(); - + getFileUpdateQueueSizeProperty().addListener((Observable o) -> { Platform.runLater(this::updateRegroupDisabled); }); - - Thread th = new Thread(dbWorkerThread); + + Thread th = new Thread(dbWorkerThread, "DB-Worker-Thread"); th.setDaemon(false); // we want it to go away when it is done th.start(); } @@ -351,7 +351,7 @@ public final class ImageGalleryController { if (Objects.nonNull(theNewCase)) { this.sleuthKitCase = theNewCase.getSleuthkitCase(); this.db = DrawableDB.getDrawableDB(ImageGalleryModule.getModuleOutputDir(theNewCase), this); - + setListeningEnabled(ImageGalleryModule.isEnabledforCase(theNewCase)); setStale(ImageGalleryModule.isDrawableDBStale(theNewCase)); @@ -365,7 +365,7 @@ public final class ImageGalleryController { tagsManager.setAutopsyTagsManager(theNewCase.getServices().getTagsManager()); tagsManager.registerListener(groupManager); SummaryTablePane.getDefault().refresh(); - + } else { reset(); } @@ -384,7 +384,7 @@ public final class ImageGalleryController { }); tagsManager.clearFollowUpTagName(); tagsManager.unregisterListener(groupManager); - + Toolbar.getDefault(this).reset(); groupManager.clear(); if (db != null) { @@ -406,21 +406,21 @@ public final class ImageGalleryController { } dbWorkerThread.addTask(innerTask); } - + public DrawableFile getFileFromId(Long fileID) throws TskCoreException { return db.getFileFromID(fileID); } - + public void setStacks(StackPane fullUIStack, StackPane centralStack) { fullUIStackPane = fullUIStack; this.centralStackPane = centralStack; Platform.runLater(this::checkForGroups); } - + public ReadOnlyIntegerProperty getFileUpdateQueueSizeProperty() { return queueSizeProperty.getReadOnlyProperty(); } - + public ReadOnlyDoubleProperty regroupProgress() { return groupManager.regroupProgress(); } @@ -496,15 +496,15 @@ public final class ImageGalleryController { } }); } - + public HashSetManager getHashSetManager() { return hashSetManager; } - + public CategoryManager getCategoryManager() { return categoryManager; } - + public DrawableTagsManager getTagsManager() { return tagsManager; } @@ -545,7 +545,7 @@ public final class ImageGalleryController { queueSizeProperty.set(workQueue.size()); }); } - + @Override public void run() { @@ -556,22 +556,22 @@ public final class ImageGalleryController { } try { InnerTask it = workQueue.take(); - + if (it.cancelled == false) { it.run(); } - + Platform.runLater(() -> { queueSizeProperty.set(workQueue.size()); }); - + } catch (InterruptedException ex) { Exceptions.printStackTrace(ex); } } } } - + public synchronized SleuthkitCase getSleuthKitCase() { return sleuthKitCase; } @@ -580,55 +580,55 @@ public final class ImageGalleryController { * Abstract base class for task to be done on {@link DBWorkerThread} */ static public abstract class InnerTask implements Runnable { - + public double getProgress() { return progress.get(); } - + public final void updateProgress(Double workDone) { this.progress.set(workDone); } - + public String getMessage() { return message.get(); } - + public final void updateMessage(String Status) { this.message.set(Status); } SimpleObjectProperty state = new SimpleObjectProperty<>(Worker.State.READY); SimpleDoubleProperty progress = new SimpleDoubleProperty(this, "pregress"); SimpleStringProperty message = new SimpleStringProperty(this, "status"); - + public SimpleDoubleProperty progressProperty() { return progress; } - + public SimpleStringProperty messageProperty() { return message; } - + public Worker.State getState() { return state.get(); } - + protected void updateState(Worker.State newState) { state.set(newState); } - + public ReadOnlyObjectProperty stateProperty() { return new ReadOnlyObjectWrapper<>(state.get()); } - + protected InnerTask() { } - + protected volatile boolean cancelled = false; - + public void cancel() { updateState(Worker.State.CANCELLED); } - + protected boolean isCancelled() { return getState() == Worker.State.CANCELLED; } @@ -638,25 +638,25 @@ public final class ImageGalleryController { * Abstract base class for tasks associated with a file in the database */ static public abstract class FileTask extends InnerTask { - + private final AbstractFile file; - + public AbstractFile getFile() { return file; } - + public FileTask(AbstractFile f) { super(); this.file = f; } - + } /** * task that updates one file in database with results from ingest */ private class UpdateFileTask extends FileTask { - + public UpdateFileTask(AbstractFile f) { super(f); } @@ -683,7 +683,7 @@ public final class ImageGalleryController { * task that updates one file in database with results from ingest */ private class RemoveFileTask extends FileTask { - + public RemoveFileTask(AbstractFile f) { super(f); } @@ -702,7 +702,7 @@ public final class ImageGalleryController { Logger.getLogger(RemoveFileTask.class.getName()).log(Level.SEVERE, "Case was closed out from underneath RemoveFile task"); } } - + } } @@ -714,16 +714,16 @@ public final class ImageGalleryController { * adds them to the Drawable DB */ private class CopyAnalyzedFiles extends InnerTask { - + final private String DRAWABLE_QUERY = "name LIKE '%." + StringUtils.join(ImageGalleryModule.getAllSupportedExtensions(), "' or name LIKE '%.") + "'"; - + private ProgressHandle progressHandle = ProgressHandleFactory.createHandle("populating analyzed image/video database"); - + @Override public void run() { progressHandle.start(); updateMessage("populating analyzed image/video database"); - + try { //grab all files with supported extension or detected mime types final List files = getSleuthKitCase().findAllFilesWhere(DRAWABLE_QUERY + " or tsk_files.obj_id in (select tsk_files.obj_id from tsk_files , blackboard_artifacts, blackboard_attributes" @@ -733,7 +733,7 @@ public final class ImageGalleryController { + " and blackboard_attributes.attribute_type_id = " + BlackboardAttribute.ATTRIBUTE_TYPE.TSK_FILE_TYPE_SIG.getTypeID() + " and blackboard_attributes.value_text in ('" + StringUtils.join(ImageGalleryModule.getSupportedMimes(), "','") + "'))"); progressHandle.switchToDeterminate(files.size()); - + updateProgress(0.0); //do in transaction @@ -747,7 +747,7 @@ public final class ImageGalleryController { } final Boolean hasMimeType = ImageGalleryModule.hasSupportedMimeType(f); final boolean known = f.getKnown() == TskData.FileKnown.KNOWN; - + if (known) { db.removeFile(f.getId(), tr); //remove known files } else { @@ -767,38 +767,38 @@ public final class ImageGalleryController { } } } - + units++; final int prog = units; progressHandle.progress(f.getName(), units); updateProgress(prog - 1 / (double) files.size()); updateMessage(f.getName()); } - + progressHandle.finish(); - + progressHandle = ProgressHandleFactory.createHandle("commiting image/video database"); updateMessage("commiting image/video database"); updateProgress(1.0); - + progressHandle.start(); db.commitTransaction(tr, true); - + } catch (TskCoreException ex) { Logger.getLogger(CopyAnalyzedFiles.class.getName()).log(Level.WARNING, "failed to transfer all database contents", ex); } catch (IllegalStateException ex) { Logger.getLogger(CopyAnalyzedFiles.class.getName()).log(Level.SEVERE, "Case was closed out from underneath CopyDataSource task", ex); } - + progressHandle.finish(); - + updateMessage( ""); updateProgress( -1.0); setStale(false); } - + } /** @@ -809,7 +809,7 @@ public final class ImageGalleryController { * netbeans and ImageGallery progress/status */ class PrePopulateDataSourceFiles extends InnerTask { - + private final Content dataSource; /** @@ -819,7 +819,7 @@ public final class ImageGalleryController { */ // (name like '.jpg' or name like '.png' ...) private final String DRAWABLE_QUERY = "(name LIKE '%." + StringUtils.join(ImageGalleryModule.getAllSupportedExtensions(), "' or name LIKE '%.") + "') "; - + private ProgressHandle progressHandle = ProgressHandleFactory.createHandle("prepopulating image/video database"); /** @@ -845,7 +845,7 @@ public final class ImageGalleryController { final List files; try { List fsObjIds = new ArrayList<>(); - + String fsQuery; if (dataSource instanceof Image) { Image image = (Image) dataSource; @@ -859,7 +859,7 @@ public final class ImageGalleryController { else { fsQuery = "(fs_obj_id IS NULL) "; } - + files = getSleuthKitCase().findAllFilesWhere(fsQuery + " and " + DRAWABLE_QUERY); progressHandle.switchToDeterminate(files.size()); @@ -877,21 +877,21 @@ public final class ImageGalleryController { final int prog = units; progressHandle.progress(f.getName(), units); } - + progressHandle.finish(); progressHandle = ProgressHandleFactory.createHandle("commiting image/video database"); - + progressHandle.start(); db.commitTransaction(tr, false); - + } catch (TskCoreException ex) { Logger.getLogger(PrePopulateDataSourceFiles.class.getName()).log(Level.WARNING, "failed to transfer all database contents", ex); } catch (IllegalStateException | NullPointerException ex) { Logger.getLogger(PrePopulateDataSourceFiles.class.getName()).log(Level.WARNING, "Case was closed out from underneath prepopulating database"); } - + progressHandle.finish(); } } - + } diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/NextUnseenGroup.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/NextUnseenGroup.java index ab8ef06401..550581d8b2 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/NextUnseenGroup.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/NextUnseenGroup.java @@ -51,6 +51,7 @@ public class NextUnseenGroup extends Action { this.controller = controller; setGraphic(new ImageView(ADVANCE)); + //TODO: do we need both these listeners? controller.getGroupManager().getAnalyzedGroups().addListener((Observable observable) -> { Platform.runLater(this::updateButton); diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableDB.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableDB.java index 49b0818e3b..9dfbbdc239 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableDB.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableDB.java @@ -656,7 +656,7 @@ public final class DrawableDB { private void fireRemovedFiles(Collection fileIDs) { for (FileUpdateEvent.FileUpdateListener listener : updateListeners) { - listener.handleFileUpdate(FileUpdateEvent.newRemovedEvent(fileIDs)); + listener.handleFileRemoved(FileUpdateEvent.newRemovedEvent(fileIDs)); } } diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/DrawableGroup.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/DrawableGroup.java index 386ae51d65..0ad8b2640e 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/DrawableGroup.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/DrawableGroup.java @@ -165,13 +165,11 @@ public class DrawableGroup implements Comparable { // By default, sort by group key name @Override - public int compareTo(DrawableGroup other - ) { + public int compareTo(DrawableGroup other) { return this.groupKey.getValueDisplayName().compareTo(other.groupKey.getValueDisplayName()); } - void setSeen(boolean isSeen - ) { + void setSeen(boolean isSeen) { this.seen.set(isSeen); } diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/GroupManager.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/GroupManager.java index a79b8e3b48..2027dae724 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/GroupManager.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/GroupManager.java @@ -1,7 +1,7 @@ /* * Autopsy Forensic Browser * - * Copyright 2013-4 Basis Technology Corp. + * Copyright 2013-15 Basis Technology Corp. * Contact: carrier sleuthkit org * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -25,10 +25,12 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; +import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Set; import java.util.TreeSet; import java.util.concurrent.ExecutorService; @@ -41,12 +43,14 @@ import javafx.beans.property.ReadOnlyDoubleProperty; import javafx.beans.property.ReadOnlyDoubleWrapper; import javafx.collections.FXCollections; import javafx.collections.ObservableList; +import javafx.collections.transformation.SortedList; import javax.annotation.Nonnull; import javax.annotation.Nullable; import javax.annotation.concurrent.GuardedBy; import javax.swing.SortOrder; import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.Validate; import org.apache.commons.lang3.concurrent.BasicThreadFactory; import org.netbeans.api.progress.ProgressHandle; import org.netbeans.api.progress.ProgressHandleFactory; @@ -98,16 +102,12 @@ public class GroupManager implements FileUpdateEvent.FileUpdateListener { */ @ThreadConfined(type = ThreadType.JFX) private final ObservableList analyzedGroups = FXCollections.observableArrayList(); + private final SortedList unmodifiableAnalyzedGroups = new SortedList<>(analyzedGroups); - private final ObservableList publicAnalyzedGroupsWrapper = FXCollections.unmodifiableObservableList(analyzedGroups); - /** - * list of unseen groups - */ + /** list of unseen groups */ @ThreadConfined(type = ThreadType.JFX) private final ObservableList unSeenGroups = FXCollections.observableArrayList(); - -// private final SortedList sortedUnSeenGroups = new SortedList<>(unSeenGroups); - private final ObservableList publicSortedUnseenGroupsWrapper = FXCollections.unmodifiableObservableList(unSeenGroups); + private final SortedList unmodifiableUnSeenGroups = new SortedList<>(unSeenGroups); private ReGroupTask groupByTask; @@ -117,7 +117,7 @@ public class GroupManager implements FileUpdateEvent.FileUpdateListener { private volatile DrawableAttribute groupBy = DrawableAttribute.PATH; private volatile SortOrder sortOrder = SortOrder.ASCENDING; - private ReadOnlyDoubleWrapper regroupProgress = new ReadOnlyDoubleWrapper(); + private final ReadOnlyDoubleWrapper regroupProgress = new ReadOnlyDoubleWrapper(); public void setDB(DrawableDB db) { this.db = db; @@ -125,13 +125,15 @@ public class GroupManager implements FileUpdateEvent.FileUpdateListener { regroup(groupBy, sortBy, sortOrder, Boolean.TRUE); } + @SuppressWarnings("ReturnOfCollectionOrArrayField") public ObservableList getAnalyzedGroups() { - return publicAnalyzedGroupsWrapper; + return unmodifiableAnalyzedGroups; } @ThreadConfined(type = ThreadType.JFX) + @SuppressWarnings("ReturnOfCollectionOrArrayField") public ObservableList getUnSeenGroups() { - return publicSortedUnseenGroupsWrapper; + return unmodifiableUnSeenGroups; } /** @@ -239,36 +241,6 @@ public class GroupManager implements FileUpdateEvent.FileUpdateListener { } } - /** - * make and return a new group with the given key and files. If a group - * already existed for that key, it will be updated to contain the given - * files. - * - * NOTE: this is the only API for making a new group. - * - * @param groupKey the groupKey that uniquely identifies this group - * @param files a list of fileids that are members of this group - * - * @return the new DrawableGroup for the given key - */ - public DrawableGroup makeGroup(GroupKey groupKey, Set files) { - synchronized (groupMap) { - if (groupMap.containsKey(groupKey)) { - DrawableGroup group = groupMap.get(groupKey); - group.setFiles(ObjectUtils.defaultIfNull(files, Collections.emptySet())); - return group; - } else { - final boolean groupSeen = db.isGroupSeen(groupKey); - DrawableGroup group = new DrawableGroup(groupKey, files, groupSeen); - group.seenProperty().addListener((observable, oldSeen, newSeen) -> { - markGroupSeen(group, newSeen); - }); - groupMap.put(groupKey, group); - return group; - } - } - } - /** * 'mark' the given group as seen. This removes it from the queue of * groups @@ -277,15 +249,13 @@ public class GroupManager implements FileUpdateEvent.FileUpdateListener { * @param group the {@link DrawableGroup} to mark as seen */ @ThreadConfined(type = ThreadType.JFX) - public void markGroupSeen(DrawableGroup group, boolean seen - ) { + public void markGroupSeen(DrawableGroup group, boolean seen) { db.markGroupSeen(group.getGroupKey(), seen); group.setSeen(seen); if (seen) { unSeenGroups.removeAll(group); } else if (unSeenGroups.contains(group) == false) { unSeenGroups.add(group); - FXCollections.sort(unSeenGroups, sortBy.getGrpComparator(sortOrder)); } } @@ -297,7 +267,7 @@ public class GroupManager implements FileUpdateEvent.FileUpdateListener { * @param groupKey the value of groupKey * @param fileID the value of file */ - public synchronized void removeFromGroup(GroupKey groupKey, final Long fileID) { + public synchronized DrawableGroup removeFromGroup(GroupKey groupKey, final Long fileID) { //get grouping this file would be in final DrawableGroup group = getGroupForKey(groupKey); if (group != null) { @@ -311,74 +281,10 @@ public class GroupManager implements FileUpdateEvent.FileUpdateListener { unSeenGroups.remove(group); }); } - } else { } } - } - public synchronized void populateAnalyzedGroup(final GroupKey groupKey, Set filesInGroup) { - populateAnalyzedGroup(groupKey, filesInGroup, null); - } - - /** - * create a group with the given GroupKey and file ids and add it to the - * analyzed group list. - * - * @param groupKey - * @param filesInGroup - */ - private synchronized > void populateAnalyzedGroup(final GroupKey groupKey, Set filesInGroup, ReGroupTask task) { - - /* if this is not part of a regroup task or it is but the task is not - * cancelled... - * - * this allows us to stop if a regroup task has been cancelled (e.g. the - * user picked a different group by attribute, while the current task - * was still running) */ - if (task == null || (task.isCancelled() == false)) { - DrawableGroup g = makeGroup(groupKey, filesInGroup); - populateAnalyzedGroup(g, task); - } - } - - private synchronized void populateAnalyzedGroup(final DrawableGroup g, ReGroupTask task) { - - if (task == null || (task.isCancelled() == false)) { - final boolean groupSeen = db.isGroupSeen(g.getGroupKey()); - - Platform.runLater(() -> { - if (analyzedGroups.contains(g) == false) { - analyzedGroups.add(g); - } - markGroupSeen(g, groupSeen); - - }); - } - } - - /** - * check if the group for the given groupkey is analyzed - * - * @param groupKey - * - * @return null if this group is not analyzed or a list of file ids in - * this - * group if they are all analyzed - */ - public Set checkAnalyzed(final GroupKey groupKey) { - try { - /* for attributes other than path we can't be sure a group is fully - * analyzed because we don't know all the files that will be a part - * of that group */ - if ((groupKey.getAttribute() != DrawableAttribute.PATH) || db.isGroupAnalyzed(groupKey)) { - return getFileIDsInGroup(groupKey); - } else { - return null; - } - } catch (TskCoreException ex) { - LOGGER.log(Level.SEVERE, "failed to get files for group: " + groupKey.getAttribute().attrName.toString() + " = " + groupKey.getValue(), ex); - return null; - } + return group; } /** @@ -595,9 +501,6 @@ public class GroupManager implements FileUpdateEvent.FileUpdateListener { if (groupByTask != null) { groupByTask.cancel(true); } - Platform.runLater(() -> { - FXCollections.sort(unSeenGroups, sortBy.getGrpComparator(sortOrder)); - }); groupByTask = new ReGroupTask(groupBy, sortBy, sortOrder); Platform.runLater(() -> { @@ -605,15 +508,14 @@ public class GroupManager implements FileUpdateEvent.FileUpdateListener { }); regroupExecutor.submit(groupByTask); } else { - // just resort the list of groups + // resort the list of groups setSortBy(sortBy); setSortOrder(sortOrder); Platform.runLater(() -> { - FXCollections.sort(unSeenGroups, sortBy.getGrpComparator(sortOrder)); - FXCollections.sort(analyzedGroups, sortBy.getGrpComparator(sortOrder)); + unmodifiableAnalyzedGroups.setComparator(sortBy.getGrpComparator(sortOrder)); + unmodifiableUnSeenGroups.setComparator(sortBy.getGrpComparator(sortOrder)); }); } - } /** @@ -634,86 +536,114 @@ public class GroupManager implements FileUpdateEvent.FileUpdateListener { } } + @Override + synchronized public void handleFileRemoved(FileUpdateEvent evt) { + Validate.isTrue(evt.getUpdateType() == FileUpdateEvent.UpdateType.REMOVE); + + for (final long fileId : evt.getFileIDs()) { + //get grouping(s) this file would be in + Set> groupsForFile = getGroupKeysForFileID(fileId); + + for (GroupKey gk : groupsForFile) { + DrawableGroup g = removeFromGroup(gk, fileId); + + if (g == null) { + // It may be that this was the last unanalyzed file in the group, so test + // whether the group is now fully analyzed. + popuplateIfAnalyzed(gk, null); + } + } + } + } + /** * handle {@link FileUpdateEvent} sent from Db when files are * inserted/updated * - * TODO: why isn't this just two methods! - * * @param evt */ @Override synchronized public void handleFileUpdate(FileUpdateEvent evt) { - final Collection fileIDs = evt.getFileIDs(); - switch (evt.getUpdateType()) { - case REMOVE: - for (final long fileId : fileIDs) { - //get grouping(s) this file would be in - Set> groupsForFile = getGroupKeysForFileID(fileId); + Validate.isTrue(evt.getUpdateType() == FileUpdateEvent.UpdateType.UPDATE); + Collection fileIDs = evt.getFileIDs(); + /** + * TODO: is there a way to optimize this to avoid quering to db + * so much. the problem is that as a new files are analyzed they + * might be in new groups( if we are grouping by say make or + * model) -jm + */ + for (long fileId : fileIDs) { - for (GroupKey gk : groupsForFile) { - removeFromGroup(gk, fileId); + controller.getHashSetManager().invalidateHashSetsForFile(fileId); - DrawableGroup g = getGroupForKey(gk); + //get grouping(s) this file would be in + Set> groupsForFile = getGroupKeysForFileID(fileId); - if (g == null) { - // It may be that this was the last unanalyzed file in the group, so test - // whether the group is now fully analyzed. - //TODO: use method in groupmanager ? - Set checkAnalyzed = checkAnalyzed(gk); - if (checkAnalyzed != null) { // => the group is analyzed, so add it to the ui - populateAnalyzedGroup(gk, checkAnalyzed); + for (GroupKey gk : groupsForFile) { + DrawableGroup g = getGroupForKey(gk); + + if (g == null) { + //if there wasn't already a group check if there should be one now + popuplateIfAnalyzed(gk, null); + } else { + //if there is aleady a group that was previously deemed fully analyzed, then add this newly analyzed file to it. + g.addFile(fileId); + } + } + } + + //we fire this event for all files so that the category counts get updated during initial db population + controller.getCategoryManager().fireChange(fileIDs); + + if (evt.getChangedAttribute() == DrawableAttribute.TAGS) { + controller.getTagsManager().fireChange(fileIDs); + } + } + + private void popuplateIfAnalyzed(GroupKey groupKey, ReGroupTask task) { + + if (Objects.nonNull(task) && (task.isCancelled())) { + /* if this method call is part of a ReGroupTask and that task is + * cancelled, no-op + * + * this allows us to stop if a regroup task has been cancelled (e.g. + * the user picked a different group by attribute, while the + * current task was still running) */ + } else { // no task or un-cancelled task + if ((groupKey.getAttribute() != DrawableAttribute.PATH) || db.isGroupAnalyzed(groupKey)) { + /* for attributes other than path we can't be sure a group is + * fully analyzed because we don't know all the files that + * will be a part of that group */ + + try { + Set fileIDs = getFileIDsInGroup(groupKey); + if (Objects.nonNull(fileIDs)) { + DrawableGroup group; + final boolean groupSeen = db.isGroupSeen(groupKey); + synchronized (groupMap) { + if (groupMap.containsKey(groupKey)) { + group = groupMap.get(groupKey); + group.setFiles(ObjectUtils.defaultIfNull(fileIDs, Collections.emptySet())); + } else { + + group = new DrawableGroup(groupKey, fileIDs, groupSeen); + group.seenProperty().addListener((observable, oldSeen, newSeen) -> { + markGroupSeen(group, newSeen); + }); + groupMap.put(groupKey, group); } } - } - } - - break; - case UPDATE: - - /** - * TODO: is there a way to optimize this to avoid quering to db - * so much. the problem is that as a new files are analyzed they - * might be in new groups( if we are grouping by say make or - * model) - * - * TODO: Should this be a InnerTask so it can be done by the - * WorkerThread? Is it already done by worker thread because - * handlefileUpdate is invoked through call on db in UpdateTask - * innertask? -jm - */ - for (final long fileId : fileIDs) { - - controller.getHashSetManager().invalidateHashSetsForFile(fileId); - - //get grouping(s) this file would be in - Set> groupsForFile = getGroupKeysForFileID(fileId); - - for (GroupKey gk : groupsForFile) { - DrawableGroup g = getGroupForKey(gk); - - if (g != null) { - //if there is aleady a group that was previously deemed fully analyzed, then add this newly analyzed file to it. - g.addFile(fileId); - } else { - //if there wasn't already a group check if there should be one now - //TODO: use method in groupmanager ? - Set checkAnalyzed = checkAnalyzed(gk); - if (checkAnalyzed != null) { // => the group is analyzed, so add it to the ui - populateAnalyzedGroup(gk, checkAnalyzed); + Platform.runLater(() -> { + if (analyzedGroups.contains(group) == false) { + analyzedGroups.add(group); } - } + markGroupSeen(group, groupSeen); + }); } + } catch (TskCoreException ex) { + LOGGER.log(Level.SEVERE, "failed to get files for group: " + groupKey.getAttribute().attrName.toString() + " = " + groupKey.getValue(), ex); } - - //we fire this event for all files so that the category counts get updated during initial db population - controller.getCategoryManager().fireChange(fileIDs); - - if (evt.getChangedAttribute() == DrawableAttribute.TAGS) { - controller.getTagsManager().fireChange(fileIDs); - } - break; - + } } } @@ -755,17 +685,16 @@ public class GroupManager implements FileUpdateEvent.FileUpdateListener { groupProgress = ProgressHandleFactory.createHandle("regrouping files by " + groupBy.attrName.toString() + " sorted by " + sortBy.name() + " in " + sortOrder.toString() + " order", this); Platform.runLater(() -> { analyzedGroups.clear(); - synchronized (unSeenGroups) { - unSeenGroups.clear(); - } + unSeenGroups.clear(); + + final Comparator grpComparator = sortBy.getGrpComparator(sortOrder); + unmodifiableAnalyzedGroups.setComparator(grpComparator); + unmodifiableUnSeenGroups.setComparator(grpComparator); }); // Get the list of group keys final List vals = findValuesForAttribute(groupBy); - // Make a list of each group - final List groups = new ArrayList<>(); - groupProgress.start(vals.size()); int p = 0; @@ -778,25 +707,7 @@ public class GroupManager implements FileUpdateEvent.FileUpdateListener { updateMessage("regrouping files by " + groupBy.attrName.toString() + " : " + val); updateProgress(p, vals.size()); groupProgress.progress("regrouping files by " + groupBy.attrName.toString() + " : " + val, p); - //check if this group is analyzed - final GroupKey groupKey = new GroupKey<>(groupBy, val); - - Set checkAnalyzed = checkAnalyzed(groupKey); - if (checkAnalyzed != null) { // != null => the group is analyzed, so add it to the ui - - // makeGroup will create the group and add it to the map groupMap, but does not - // update anything else - DrawableGroup g = makeGroup(groupKey, checkAnalyzed); - groups.add(g); - } - } - - // Sort the group list - Collections.sort(groups, sortBy.getGrpComparator(sortOrder)); - - // Officially add all groups in order - for (DrawableGroup g : groups) { - populateAnalyzedGroup(g, ReGroupTask.this); + popuplateIfAnalyzed(new GroupKey(groupBy, val), this); } updateProgress(1, 1); diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/navpanel/NavPanel.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/navpanel/NavPanel.java index 482ff66f7c..efc855e8ca 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/navpanel/NavPanel.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/navpanel/NavPanel.java @@ -171,13 +171,14 @@ public class NavPanel extends TabPane { if (change.wasPermutated()) { // Handle this afterward wasPermuted = true; + break; } } if (wasPermuted) { rebuildTrees(); } - if (selectedItem != null) { + if (selectedItem != null && selectedItem.getValue().getGroup() != null) { Platform.runLater(() -> { setFocusedGroup(selectedItem.getValue().getGroup()); }); @@ -268,7 +269,6 @@ public class NavPanel extends TabPane { } private static List groupingToPath(DrawableGroup g) { - if (g.groupKey.getAttribute() == DrawableAttribute.PATH) { String path = g.groupKey.getValueDisplayName(); From aec6c222e8b083917cecc11184a814231f878917 Mon Sep 17 00:00:00 2001 From: jmillman Date: Thu, 18 Jun 2015 13:51:37 -0400 Subject: [PATCH 11/56] rename method; add synchronization; remove singletonness from SummaryTablePane --- .../imagegallery/DrawableTagsManager.java | 4 ++-- .../imagegallery/ImageGalleryController.java | 4 +--- .../ImageGalleryTopComponent.java | 2 +- .../actions/AddDrawableTagAction.java | 2 +- .../imagegallery/actions/AddTagAction.java | 2 +- .../actions/CategorizeAction.java | 2 +- .../actions/DeleteFollowUpTagAction.java | 2 +- .../datamodel/CategoryManager.java | 21 +++++++++++++------ .../imagegallery/gui/SummaryTablePane.java | 18 ++++++---------- 9 files changed, 29 insertions(+), 28 deletions(-) diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/DrawableTagsManager.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/DrawableTagsManager.java index 149c7fd888..7e0303fe4d 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/DrawableTagsManager.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/DrawableTagsManager.java @@ -78,7 +78,7 @@ public class DrawableTagsManager { } /** - * fire a CategoryChangeEvent with the given fileIDs + * fire a TagsChangeEvent with the given fileIDs * * @param fileIDs */ @@ -188,7 +188,7 @@ public class DrawableTagsManager { * had a chance to add that so, we fire these events and the tree * refreshes based on them. */ - static public void fireTagsChangedEvent() { + static public void refreshTagsInAutopsy() { IngestServices.getInstance().fireModuleDataEvent(new ModuleDataEvent("TagAction", BlackboardArtifact.ARTIFACT_TYPE.TSK_TAG_FILE)); //NON-NLS } diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java index e649afbc39..6c54db8185 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java @@ -65,7 +65,6 @@ import org.sleuthkit.autopsy.imagegallery.datamodel.HashSetManager; import org.sleuthkit.autopsy.imagegallery.grouping.GroupManager; import org.sleuthkit.autopsy.imagegallery.grouping.GroupViewState; import org.sleuthkit.autopsy.imagegallery.gui.NoGroupsDialog; -import org.sleuthkit.autopsy.imagegallery.gui.SummaryTablePane; import org.sleuthkit.autopsy.imagegallery.gui.Toolbar; import org.sleuthkit.autopsy.ingest.IngestManager; import org.sleuthkit.autopsy.ingest.ModuleDataEvent; @@ -364,8 +363,6 @@ public final class ImageGalleryController { categoryManager.setDb(db); tagsManager.setAutopsyTagsManager(theNewCase.getServices().getTagsManager()); tagsManager.registerListener(groupManager); - SummaryTablePane.getDefault().refresh(); - } else { reset(); } @@ -442,6 +439,7 @@ public final class ImageGalleryController { ModuleDataEvent oldValue = (ModuleDataEvent) evt.getOldValue(); if ("TagAction".equals(oldValue.getModuleName()) && oldValue.getArtifactType() == BlackboardArtifact.ARTIFACT_TYPE.TSK_TAG_FILE) { getTagsManager().fireChange(Collections.singleton(-1L)); + getCategoryManager().invalidateCaches(); } /* we could listen to DATA events and progressivly * update files, and get data from DataSource ingest diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryTopComponent.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryTopComponent.java index e5c2bb3bd6..850230cb88 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryTopComponent.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryTopComponent.java @@ -150,7 +150,7 @@ public final class ImageGalleryTopComponent extends TopComponent implements Expl metaDataTable = new MetaDataPane(controller); navPanel = new NavPanel(controller); - leftPane = new VBox(navPanel, SummaryTablePane.getDefault()); + leftPane = new VBox(navPanel, new SummaryTablePane(controller)); SplitPane.setResizableWithParent(leftPane, Boolean.FALSE); SplitPane.setResizableWithParent(groupPane, Boolean.TRUE); SplitPane.setResizableWithParent(metaDataTable, Boolean.FALSE); diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/AddDrawableTagAction.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/AddDrawableTagAction.java index 9d5c5f277b..e88c51f12b 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/AddDrawableTagAction.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/AddDrawableTagAction.java @@ -90,7 +90,7 @@ public class AddDrawableTagAction extends AddTagAction { //make sure rest of ui hears category change. controller.getGroupManager().handleFileUpdate(FileUpdateEvent.newUpdateEvent(Collections.singleton(fileID), DrawableAttribute.TAGS)); } - DrawableTagsManager.fireTagsChangedEvent(); + DrawableTagsManager.refreshTagsInAutopsy(); return null; } diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/AddTagAction.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/AddTagAction.java index 5284b7eb71..abc441fb61 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/AddTagAction.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/AddTagAction.java @@ -99,7 +99,7 @@ abstract class AddTagAction { MenuItem tagNameItem = new MenuItem(tagName.getDisplayName()); tagNameItem.setOnAction((ActionEvent t) -> { addTag(tagName, NO_COMMENT); - DrawableTagsManager.fireTagsChangedEvent(); + DrawableTagsManager.refreshTagsInAutopsy(); }); quickTagMenu.getItems().add(tagNameItem); } diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/CategorizeAction.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/CategorizeAction.java index 1b84b005bf..27f599cafe 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/CategorizeAction.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/CategorizeAction.java @@ -158,7 +158,7 @@ public class CategorizeAction extends AddTagAction { JOptionPane.showMessageDialog(null, "Unable to categorize " + fileID + ".", "Categorizing Error", JOptionPane.ERROR_MESSAGE); } - DrawableTagsManager.fireTagsChangedEvent(); + DrawableTagsManager.refreshTagsInAutopsy(); } } } diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/DeleteFollowUpTagAction.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/DeleteFollowUpTagAction.java index 6a1a54c30d..bba6d5e4dc 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/DeleteFollowUpTagAction.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/DeleteFollowUpTagAction.java @@ -79,7 +79,7 @@ public class DeleteFollowUpTagAction extends Action { } } - DrawableTagsManager.fireTagsChangedEvent(); + DrawableTagsManager.refreshTagsInAutopsy(); //make sure rest of ui hears category change. groupManager.handleFileUpdate(FileUpdateEvent.newUpdateEvent(Collections.singleton(fileID), DrawableAttribute.TAGS)); diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/CategoryManager.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/CategoryManager.java index 0197c3c847..f8b0e6beb1 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/CategoryManager.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/CategoryManager.java @@ -23,6 +23,7 @@ import com.google.common.cache.LoadingCache; import com.google.common.eventbus.EventBus; import com.google.common.eventbus.Subscribe; import java.util.Collection; +import java.util.Collections; import java.util.concurrent.atomic.LongAdder; import java.util.logging.Level; import org.sleuthkit.autopsy.coreutils.Logger; @@ -44,6 +45,7 @@ import org.sleuthkit.datamodel.TagName; public class CategoryManager { private static final java.util.logging.Logger LOGGER = Logger.getLogger(CategoryManager.class.getName()); + private final ImageGalleryController controller; /** @@ -88,10 +90,17 @@ public class CategoryManager { * * @param db */ - public void setDb(DrawableDB db) { + synchronized public void setDb(DrawableDB db) { this.db = db; categoryCounts.invalidateAll(); catTagNameMap.invalidateAll(); + fireChange(Collections.singleton(-1L)); + } + + synchronized public void invalidateCaches() { + categoryCounts.invalidateAll(); + catTagNameMap.invalidateAll(); + fireChange(Collections.singleton(-1L)); } /** @@ -101,7 +110,7 @@ public class CategoryManager { * * @return the long the number of files with the given Category */ - public long getCategoryCount(Category cat) { + synchronized public long getCategoryCount(Category cat) { if (cat == Category.ZERO) { // Keeping track of the uncategorized files is a bit tricky while ingest // is going on, so always use the list of file IDs we already have along with the @@ -119,7 +128,7 @@ public class CategoryManager { * * @param cat the Category to increment */ - public void incrementCategoryCount(Category cat) { + synchronized public void incrementCategoryCount(Category cat) { if (cat != Category.ZERO) { categoryCounts.getUnchecked(cat).increment(); } @@ -131,7 +140,7 @@ public class CategoryManager { * * @param cat the Category to decrement */ - public void decrementCategoryCount(Category cat) { + synchronized public void decrementCategoryCount(Category cat) { if (cat != Category.ZERO) { categoryCounts.getUnchecked(cat).decrement(); } @@ -147,7 +156,7 @@ public class CategoryManager { * @return a LongAdder whose value is set to the number of file with the * given Category */ - private LongAdder getCategoryCountHelper(Category cat) { + synchronized private LongAdder getCategoryCountHelper(Category cat) { LongAdder longAdder = new LongAdder(); longAdder.decrement(); try { @@ -191,7 +200,7 @@ public class CategoryManager { * * @return the TagName used for this Category */ - public TagName getTagName(Category cat) { + synchronized public TagName getTagName(Category cat) { return catTagNameMap.getUnchecked(cat); } diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/SummaryTablePane.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/SummaryTablePane.java index 6692bf873f..2710020c45 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/SummaryTablePane.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/SummaryTablePane.java @@ -43,8 +43,6 @@ import org.sleuthkit.autopsy.imagegallery.datamodel.CategoryChangeEvent; */ public class SummaryTablePane extends AnchorPane { - private static SummaryTablePane instance; - @FXML private TableColumn, String> catColumn; @@ -53,6 +51,7 @@ public class SummaryTablePane extends AnchorPane { @FXML private TableView> tableView; + private final ImageGalleryController controller; @FXML void initialize() { @@ -74,19 +73,14 @@ public class SummaryTablePane extends AnchorPane { tableView.getColumns().setAll(Arrays.asList(catColumn, countColumn)); -// //register for category events - ImageGalleryController.getDefault().getCategoryManager().registerListener(this); + //register for category events + controller.getCategoryManager().registerListener(this); } - private SummaryTablePane() { + public SummaryTablePane(ImageGalleryController controller) { + this.controller = controller; FXMLConstructor.construct(this, "SummaryTablePane.fxml"); - } - public static synchronized SummaryTablePane getDefault() { - if (instance == null) { - instance = new SummaryTablePane(); - } - return instance; } /** @@ -101,7 +95,7 @@ public class SummaryTablePane extends AnchorPane { final ObservableList> data = FXCollections.observableArrayList(); if (Case.isCaseOpen()) { for (Category cat : Category.values()) { - data.add(new Pair<>(cat, ImageGalleryController.getDefault().getCategoryManager().getCategoryCount(cat))); + data.add(new Pair<>(cat, controller.getCategoryManager().getCategoryCount(cat))); } } Platform.runLater(() -> { From 9bdaab4f031e6b67982c762f0752d115ada74227 Mon Sep 17 00:00:00 2001 From: jmillman Date: Thu, 18 Jun 2015 15:20:02 -0400 Subject: [PATCH 12/56] more tag/category autopsy integeration update CategoryCounts, FollowUp and Category border on general Tag Event use most severe category if multiple categories are present for a file enforce category ordering via enum declaration order --- .../imagegallery/datamodel/Category.java | 9 +++++--- .../imagegallery/datamodel/DrawableFile.java | 7 +++--- .../imagegallery/gui/DrawableView.java | 22 +++++++++++-------- .../imagegallery/gui/DrawableViewBase.java | 6 ++--- .../imagegallery/gui/MetaDataPane.java | 4 ++-- .../imagegallery/gui/SummaryTablePane.java | 5 +---- 6 files changed, 28 insertions(+), 25 deletions(-) diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/Category.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/Category.java index ee6a46098e..aed95afec6 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/Category.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/Category.java @@ -28,14 +28,17 @@ import org.sleuthkit.datamodel.TagName; /** * Enum to represent the six categories in the DHs image categorization scheme. */ -public enum Category implements Comparable { +public enum Category { - ZERO(Color.LIGHTGREY, 0, "CAT-0: Uncategorized"), + /* This order of declaration is required so that Enum's compareTo method + * preserves the fact that lower category numbers are first/most sever, + * except 0 which is last */ ONE(Color.RED, 1, "CAT-1: Child Exploitation (Illegal)"), TWO(Color.ORANGE, 2, "CAT-2: Child Exploitation (Non-Illegal/Age Difficult)"), THREE(Color.YELLOW, 3, "CAT-3: CGI/Animation (Child Exploitive)"), FOUR(Color.BISQUE, 4, "CAT-4: Exemplar/Comparison (Internal Use Only)"), - FIVE(Color.GREEN, 5, "CAT-5: Non-pertinent"); + FIVE(Color.GREEN, 5, "CAT-5: Non-pertinent"), + ZERO(Color.LIGHTGREY, 0, "CAT-0: Uncategorized"); /** map from displayName to enum value */ private static final Map nameMap diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableFile.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableFile.java index 4d3de0d553..3890ca577a 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableFile.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableFile.java @@ -268,22 +268,21 @@ public abstract class DrawableFile extends AbstractFile return category; } - public void updateCategory() { + /** set the category property to the most severe one found */ + private void updateCategory() { try { category.set(getSleuthkitCase().getContentTagsByContent(this).stream() .map(Tag::getName).filter(Category::isCategoryTagName) - .findFirst() .map(TagName::getDisplayName) .map(Category::fromDisplayName) + .sorted().findFirst() //sort by severity and take the first .orElse(Category.ZERO) ); - } catch (TskCoreException ex) { Logger.getLogger(DrawableFile.class.getName()).log(Level.WARNING, "problem looking up category for file " + this.getName(), ex); } catch (IllegalStateException ex) { // We get here many times if the case is closed during ingest, so don't print out a ton of warnings. } - } public abstract Image getThumbnail(); diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableView.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableView.java index 93dbae801e..99d8671a63 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableView.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableView.java @@ -108,15 +108,19 @@ public interface DrawableView { @ThreadConfined(type = ThreadConfined.ThreadType.ANY) default Category updateCategoryBorder() { - final Category category = getFile().getCategory(); - final Border border = hasHashHit() && (category == Category.ZERO) - ? HASH_BORDER - : getCategoryBorder(category); + if (getFile() != null) { + final Category category = getFile().getCategory(); + final Border border = hasHashHit() && (category == Category.ZERO) + ? HASH_BORDER + : getCategoryBorder(category); - Platform.runLater(() -> { - getCategoryBorderRegion().setBorder(border); - getCategoryBorderRegion().requestLayout(); - }); - return category; + Platform.runLater(() -> { + getCategoryBorderRegion().setBorder(border); + getCategoryBorderRegion().requestLayout(); + }); + return category; + } else { + return Category.ZERO; + } } } diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableViewBase.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableViewBase.java index 52ac70def0..38c48c2951 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableViewBase.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableViewBase.java @@ -2,7 +2,7 @@ /* * Autopsy Forensic Browser * - * Copyright 2013-14 Basis Technology Corp. + * Copyright 2013-15 Basis Technology Corp. * Contact: carrier sleuthkit org * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -302,7 +302,7 @@ public abstract class DrawableViewBase extends AnchorPane implements DrawableVie @Override synchronized public void handleTagsChanged(TagsChangeEvent evnt) { - if (fileID != null && evnt.getFileIDs().contains(fileID)) { + if (fileID != null && (evnt.getFileIDs().contains(fileID) || evnt.getFileIDs().contains(-1L))) { updateFollowUpIcon(); } } @@ -386,7 +386,7 @@ public abstract class DrawableViewBase extends AnchorPane implements DrawableVie @Subscribe @Override synchronized public void handleCategoryChanged(CategoryChangeEvent evt) { - if (evt.getFileIDs().contains(getFileID())) { + if (evt.getFileIDs().contains(getFileID()) || evt.getFileIDs().contains(-1L)) { updateCategoryBorder(); } } diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/MetaDataPane.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/MetaDataPane.java index 4ab6fff208..4f4cace550 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/MetaDataPane.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/MetaDataPane.java @@ -225,7 +225,7 @@ public class MetaDataPane extends AnchorPane implements DrawableView { @Subscribe @Override public void handleCategoryChanged(CategoryChangeEvent evt) { - if (getFile() != null && evt.getFileIDs().contains(getFileID())) { + if (getFile() != null && (evt.getFileIDs().contains(-1L) || evt.getFileIDs().contains(getFileID()))) { updateUI(); } } @@ -233,7 +233,7 @@ public class MetaDataPane extends AnchorPane implements DrawableView { @Override @Subscribe public void handleTagsChanged(TagsChangeEvent evt) { - if (getFile() != null && evt.getFileIDs().contains(getFileID())) { + if (getFile() != null && (evt.getFileIDs().contains(-1L) || evt.getFileIDs().contains(getFileID()))) { updateUI(); } } diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/SummaryTablePane.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/SummaryTablePane.java index 2710020c45..955cf0760f 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/SummaryTablePane.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/SummaryTablePane.java @@ -75,6 +75,7 @@ public class SummaryTablePane extends AnchorPane { //register for category events controller.getCategoryManager().registerListener(this); + handleCategoryChanged(null); } public SummaryTablePane(ImageGalleryController controller) { @@ -88,10 +89,6 @@ public class SummaryTablePane extends AnchorPane { */ @Subscribe public void handleCategoryChanged(CategoryChangeEvent evt) { - refresh(); - } - - public void refresh() { final ObservableList> data = FXCollections.observableArrayList(); if (Case.isCaseOpen()) { for (Category cat : Category.values()) { From 762037c649593efc4b90345f564037311446dc54 Mon Sep 17 00:00:00 2001 From: jmillman Date: Thu, 18 Jun 2015 16:57:28 -0400 Subject: [PATCH 13/56] new Tag event system --- .../imagegallery/DrawableTagsManager.java | 148 +++++++++++------- .../imagegallery/ImageGalleryController.java | 30 +++- .../actions/CategorizeAction.java | 1 + .../actions/DeleteFollowUpTagAction.java | 70 ++++----- .../imagegallery/datamodel/Category.java | 3 + .../imagegallery/grouping/GroupManager.java | 6 +- .../imagegallery/gui/DrawableViewBase.java | 15 +- 7 files changed, 163 insertions(+), 110 deletions(-) diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/DrawableTagsManager.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/DrawableTagsManager.java index 7e0303fe4d..add7065742 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/DrawableTagsManager.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/DrawableTagsManager.java @@ -45,6 +45,7 @@ public class DrawableTagsManager { private static final String FOLLOW_UP = "Follow Up"; + private Object autopsyTagsManagerLock = new Object(); private TagsManager autopsyTagsManager; /** Used to distribute {@link TagsChangeEvent}s */ @@ -64,26 +65,21 @@ public class DrawableTagsManager { * * @param autopsyTagsManager */ - public synchronized void setAutopsyTagsManager(TagsManager autopsyTagsManager) { - this.autopsyTagsManager = autopsyTagsManager; - clearFollowUpTagName(); + public void setAutopsyTagsManager(TagsManager autopsyTagsManager) { + synchronized (autopsyTagsManager) { + this.autopsyTagsManager = autopsyTagsManager; + clearFollowUpTagName(); + } } /** * Use when closing a case to make sure everything is re-initialized in the * next case. */ - public synchronized void clearFollowUpTagName() { - followUpTagName = null; - } - - /** - * fire a TagsChangeEvent with the given fileIDs - * - * @param fileIDs - */ - public final void fireChange(Collection fileIDs) { - tagsEventBus.post(new TagsChangeEvent(fileIDs)); + public void clearFollowUpTagName() { + synchronized (autopsyTagsManager) { + followUpTagName = null; + } } /** @@ -111,22 +107,26 @@ public class DrawableTagsManager { * * @throws TskCoreException */ - synchronized public TagName getFollowUpTagName() throws TskCoreException { - if (Objects.isNull(followUpTagName)) { - followUpTagName = getTagName(FOLLOW_UP); + public TagName getFollowUpTagName() throws TskCoreException { + synchronized (autopsyTagsManager) { + if (Objects.isNull(followUpTagName)) { + followUpTagName = getTagName(FOLLOW_UP); + } + return followUpTagName; } - return followUpTagName; } - synchronized public Collection getNonCategoryTagNames() { - try { - return autopsyTagsManager.getAllTagNames().stream() - .filter(Category::isCategoryTagName) - .collect(Collectors.toSet()); - } catch (TskCoreException | IllegalStateException ex) { - Logger.getLogger(DrawableTagsManager.class.getName()).log(Level.WARNING, "couldn't access case", ex); + public Collection getNonCategoryTagNames() { + synchronized (autopsyTagsManager) { + try { + return autopsyTagsManager.getAllTagNames().stream() + .filter(Category::isCategoryTagName) + .collect(Collectors.toSet()); + } catch (TskCoreException | IllegalStateException ex) { + Logger.getLogger(DrawableTagsManager.class.getName()).log(Level.WARNING, "couldn't access case", ex); + } + return Collections.emptySet(); } - return Collections.emptySet(); } /** @@ -139,29 +139,33 @@ public class DrawableTagsManager { * * @throws TskCoreException */ - public synchronized List getContentTagsByContent(Content content) throws TskCoreException { - return autopsyTagsManager.getContentTagsByContent(content); - } - - public synchronized TagName getTagName(String displayName) throws TskCoreException { - try { - for (TagName tn : autopsyTagsManager.getAllTagNames()) { - if (displayName.equals(tn.getDisplayName())) { - return tn; - } - } - try { - return autopsyTagsManager.addTagName(displayName); - } catch (TagsManager.TagNameAlreadyExistsException ex) { - throw new TskCoreException("tagame exists but wasn't found", ex); - } - } catch (IllegalStateException ex) { - Logger.getLogger(DrawableTagsManager.class.getName()).log(Level.SEVERE, "Case was closed out from underneath", ex); - throw new TskCoreException("Case was closed out from underneath", ex); + public List getContentTagsByContent(Content content) throws TskCoreException { + synchronized (autopsyTagsManager) { + return autopsyTagsManager.getContentTagsByContent(content); } } - public synchronized TagName getTagName(Category cat) { + public TagName getTagName(String displayName) throws TskCoreException { + synchronized (autopsyTagsManager) { + try { + for (TagName tn : autopsyTagsManager.getAllTagNames()) { + if (displayName.equals(tn.getDisplayName())) { + return tn; + } + } + try { + return autopsyTagsManager.addTagName(displayName); + } catch (TagsManager.TagNameAlreadyExistsException ex) { + throw new TskCoreException("tagame exists but wasn't found", ex); + } + } catch (IllegalStateException ex) { + Logger.getLogger(DrawableTagsManager.class.getName()).log(Level.SEVERE, "Case was closed out from underneath", ex); + throw new TskCoreException("Case was closed out from underneath", ex); + } + } + } + + public TagName getTagName(Category cat) { try { return getTagName(cat.getDisplayName()); } catch (TskCoreException ex) { @@ -169,12 +173,18 @@ public class DrawableTagsManager { } } - synchronized public void addContentTag(DrawableFile file, TagName tagName, String comment) throws TskCoreException { - autopsyTagsManager.addContentTag(file, tagName, comment); + public void addContentTag(DrawableFile file, TagName tagName, String comment) throws TskCoreException { + ContentTag addContentTag; + synchronized (autopsyTagsManager) { + addContentTag = autopsyTagsManager.addContentTag(file, tagName, comment); + } + fireTagAdded(addContentTag); } - synchronized public List getContentTagsByTagName(TagName t) throws TskCoreException { - return autopsyTagsManager.getContentTagsByTagName(t); + public List getContentTagsByTagName(TagName t) throws TskCoreException { + synchronized (autopsyTagsManager) { + return autopsyTagsManager.getContentTagsByTagName(t); + } } /** @@ -189,15 +199,43 @@ public class DrawableTagsManager { * refreshes based on them. */ static public void refreshTagsInAutopsy() { - IngestServices.getInstance().fireModuleDataEvent(new ModuleDataEvent("TagAction", BlackboardArtifact.ARTIFACT_TYPE.TSK_TAG_FILE)); //NON-NLS } - public synchronized List getAllTagNames() throws TskCoreException { - return autopsyTagsManager.getAllTagNames(); + public List getAllTagNames() throws TskCoreException { + synchronized (autopsyTagsManager) { + return autopsyTagsManager.getAllTagNames(); + } } - public synchronized List getTagNamesInUse() throws TskCoreException { - return autopsyTagsManager.getTagNamesInUse(); + public List getTagNamesInUse() throws TskCoreException { + synchronized (autopsyTagsManager) { + return autopsyTagsManager.getTagNamesInUse(); + } } + + public void fireTagAdded(ContentTag newTag) { + tagsEventBus.post(new TagsChangeEvent(Collections.singleton(newTag.getContent().getId()))); + } + + public void fireTagDeleted(ContentTag oldTag) { + tagsEventBus.post(new TagsChangeEvent(Collections.singleton(oldTag.getContent().getId()))); + } +// +// /** +// * fire a TagsChangeEvent with the given fileIDs +// * +// * @param fileIDs +// */ +// public final void fireChange(Collection fileIDs) { +// tagsEventBus.post(new TagsChangeEvent(fileIDs)); +// } + + public void deleteContentTag(ContentTag ct) throws TskCoreException { + synchronized (autopsyTagsManager) { + autopsyTagsManager.deleteContentTag(ct); + } + fireTagDeleted(ct); + } + } diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java index 6c54db8185..046c88bc7a 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java @@ -58,7 +58,10 @@ import org.sleuthkit.autopsy.casemodule.Case; import org.sleuthkit.autopsy.coreutils.History; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.coreutils.ThreadConfined; +import org.sleuthkit.autopsy.imagegallery.actions.CategorizeAction; +import org.sleuthkit.autopsy.imagegallery.datamodel.Category; import org.sleuthkit.autopsy.imagegallery.datamodel.CategoryManager; +import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableAttribute; import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableDB; import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableFile; import org.sleuthkit.autopsy.imagegallery.datamodel.HashSetManager; @@ -67,11 +70,11 @@ import org.sleuthkit.autopsy.imagegallery.grouping.GroupViewState; import org.sleuthkit.autopsy.imagegallery.gui.NoGroupsDialog; import org.sleuthkit.autopsy.imagegallery.gui.Toolbar; import org.sleuthkit.autopsy.ingest.IngestManager; -import org.sleuthkit.autopsy.ingest.ModuleDataEvent; import org.sleuthkit.datamodel.AbstractFile; import org.sleuthkit.datamodel.BlackboardArtifact; import org.sleuthkit.datamodel.BlackboardAttribute; import org.sleuthkit.datamodel.Content; +import org.sleuthkit.datamodel.ContentTag; import org.sleuthkit.datamodel.FileSystem; import org.sleuthkit.datamodel.Image; import org.sleuthkit.datamodel.SleuthkitCase; @@ -436,11 +439,6 @@ public final class ImageGalleryController { case CONTENT_CHANGED: //TODO: do we need to do anything here? -jm case DATA_ADDED: - ModuleDataEvent oldValue = (ModuleDataEvent) evt.getOldValue(); - if ("TagAction".equals(oldValue.getModuleName()) && oldValue.getArtifactType() == BlackboardArtifact.ARTIFACT_TYPE.TSK_TAG_FILE) { - getTagsManager().fireChange(Collections.singleton(-1L)); - getCategoryManager().invalidateCaches(); - } /* we could listen to DATA events and progressivly * update files, and get data from DataSource ingest * modules, but given that most modules don't post new @@ -491,6 +489,26 @@ public final class ImageGalleryController { setStale(true); } break; + case CONTENT_TAG_ADDED: + ContentTag newTag = (ContentTag) evt.getNewValue(); + if (Category.isCategoryTagName(newTag.getName())) { + new CategorizeAction(ImageGalleryController.this).addTag(newTag.getName(), ""); + } else { + getTagsManager().fireTagAdded(newTag); + } + break; + case CONTENT_TAG_DELETED: + ContentTag oldTag = (ContentTag) evt.getOldValue(); + final long fileID = oldTag.getContent().getId(); + if (getDatabase().isInDB(fileID)) { + if (Category.isCategoryTagName(oldTag.getName())) { + getCategoryManager().decrementCategoryCount(Category.fromTagName(oldTag.getName())); + getGroupManager().handleFileUpdate(FileUpdateEvent.newUpdateEvent(Collections.singleton(fileID), DrawableAttribute.CATEGORY)); + } else { + getTagsManager().fireTagDeleted(oldTag); + } + } + break; } }); } diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/CategorizeAction.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/CategorizeAction.java index 27f599cafe..8918934a6e 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/CategorizeAction.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/CategorizeAction.java @@ -161,4 +161,5 @@ public class CategorizeAction extends AddTagAction { DrawableTagsManager.refreshTagsInAutopsy(); } } + } diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/DeleteFollowUpTagAction.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/DeleteFollowUpTagAction.java index bba6d5e4dc..98fdc316ad 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/DeleteFollowUpTagAction.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/DeleteFollowUpTagAction.java @@ -22,6 +22,7 @@ import java.util.Collections; import java.util.List; import java.util.logging.Level; import javafx.event.ActionEvent; +import javax.swing.SwingWorker; import org.controlsfx.control.action.Action; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.imagegallery.DrawableTagsManager; @@ -43,49 +44,40 @@ public class DeleteFollowUpTagAction extends Action { private static final Logger LOGGER = Logger.getLogger(DeleteFollowUpTagAction.class.getName()); private final long fileID; - private final DrawableFile file; - private final ImageGalleryController controller; - public DeleteFollowUpTagAction(ImageGalleryController controller, DrawableFile file) { + public DeleteFollowUpTagAction(final ImageGalleryController controller, final DrawableFile file) { super("Delete Follow Up Tag"); - this.controller = controller; - this.file = file; this.fileID = file.getId(); setEventHandler((ActionEvent t) -> { - deleteTag(); + new SwingWorker() { + + @Override + protected Void doInBackground() throws Exception { + final SleuthkitCase sleuthKitCase = controller.getSleuthKitCase(); + final GroupManager groupManager = controller.getGroupManager(); + final DrawableTagsManager tagsManager = controller.getTagsManager(); + + try { + final TagName followUpTagName = tagsManager.getFollowUpTagName(); + // remove file from old category group + groupManager.removeFromGroup(new GroupKey(DrawableAttribute.TAGS, followUpTagName), fileID); + + List contentTagsByContent = tagsManager.getContentTagsByContent(file); + for (ContentTag ct : contentTagsByContent) { + if (ct.getName().getDisplayName().equals(followUpTagName.getDisplayName())) { + tagsManager.deleteContentTag(ct); + } + } + + DrawableTagsManager.refreshTagsInAutopsy(); + //make sure rest of ui hears category change. + groupManager.handleFileUpdate(FileUpdateEvent.newUpdateEvent(Collections.singleton(fileID), DrawableAttribute.TAGS)); + } catch (TskCoreException ex) { + LOGGER.log(Level.SEVERE, "Failed to delete follow up tag.", ex); + } + return null; + } + }.execute(); }); } - - /** - * - * - * - */ - private void deleteTag() { - - final SleuthkitCase sleuthKitCase = controller.getSleuthKitCase(); - final GroupManager groupManager = controller.getGroupManager(); - final DrawableTagsManager tagsManager = controller.getTagsManager(); - - try { - final TagName followUpTagName = tagsManager.getFollowUpTagName(); - // remove file from old category group - groupManager.removeFromGroup(new GroupKey(DrawableAttribute.TAGS, followUpTagName), fileID); - - List contentTagsByContent = sleuthKitCase.getContentTagsByContent(file); - for (ContentTag ct : contentTagsByContent) { - if (ct.getName().getDisplayName().equals(followUpTagName.getDisplayName())) { - sleuthKitCase.deleteContentTag(ct); - } - } - - DrawableTagsManager.refreshTagsInAutopsy(); - - //make sure rest of ui hears category change. - groupManager.handleFileUpdate(FileUpdateEvent.newUpdateEvent(Collections.singleton(fileID), DrawableAttribute.TAGS)); - } catch (TskCoreException ex) { - LOGGER.log(Level.SEVERE, "Failed to delete follow up tag.", ex); - } - } - } diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/Category.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/Category.java index aed95afec6..00750c4ba9 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/Category.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/Category.java @@ -49,6 +49,9 @@ public enum Category { public static Category fromDisplayName(String displayName) { return nameMap.get(displayName); } + public static Category fromTagName(TagName tagName) { + return nameMap.get(tagName.getDisplayName()); + } public static boolean isCategoryTagName(TagName tName) { return isCategoryName(tName.getDisplayName()); diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/GroupManager.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/GroupManager.java index 2027dae724..51a99bd5f7 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/GroupManager.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/GroupManager.java @@ -595,9 +595,9 @@ public class GroupManager implements FileUpdateEvent.FileUpdateListener { //we fire this event for all files so that the category counts get updated during initial db population controller.getCategoryManager().fireChange(fileIDs); - if (evt.getChangedAttribute() == DrawableAttribute.TAGS) { - controller.getTagsManager().fireChange(fileIDs); - } +// if (evt.getChangedAttribute() == DrawableAttribute.TAGS) { +// controller.getTagsManager().fireChange(fileIDs); +// } } private void popuplateIfAnalyzed(GroupKey groupKey, ReGroupTask task) { diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableViewBase.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableViewBase.java index 38c48c2951..93026d688d 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableViewBase.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableViewBase.java @@ -300,13 +300,6 @@ public abstract class DrawableViewBase extends AnchorPane implements DrawableVie return fileID; } - @Override - synchronized public void handleTagsChanged(TagsChangeEvent evnt) { - if (fileID != null && (evnt.getFileIDs().contains(fileID) || evnt.getFileIDs().contains(-1L))) { - updateFollowUpIcon(); - } - } - synchronized protected void updateFollowUpIcon() { if (file != null) { try { @@ -383,6 +376,14 @@ public abstract class DrawableViewBase extends AnchorPane implements DrawableVie return imageBorder; } + @Subscribe + @Override + synchronized public void handleTagsChanged(TagsChangeEvent evnt) { + if (fileID != null && (evnt.getFileIDs().contains(fileID) || evnt.getFileIDs().contains(-1L))) { + updateFollowUpIcon(); + } + } + @Subscribe @Override synchronized public void handleCategoryChanged(CategoryChangeEvent evt) { From 78bab47b34c444b7d033c33eeddcc214ae58114e Mon Sep 17 00:00:00 2001 From: jmillman Date: Thu, 18 Jun 2015 17:00:05 -0400 Subject: [PATCH 14/56] more granular synchronization in DrawableTagsManager --- .../casemodule/services/TagsManager.java | 1 + .../imagegallery/DrawableTagsManager.java | 34 +++++++------------ 2 files changed, 13 insertions(+), 22 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/services/TagsManager.java b/Core/src/org/sleuthkit/autopsy/casemodule/services/TagsManager.java index 01daae9fba..f94976b572 100755 --- a/Core/src/org/sleuthkit/autopsy/casemodule/services/TagsManager.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/services/TagsManager.java @@ -404,6 +404,7 @@ public class TagsManager implements Closeable { getExistingTagNames(); } + Case.getPropertyChangeSupport().firePropertyChange(Case.Events.BLACKBOARD_ARTIFACT_TAG_DELETED.toString(), tag, null); tskCase.deleteBlackboardArtifactTag(tag); try { Case.getCurrentCase().notifyBlackBoardArtifactTagDeleted(tag); diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/DrawableTagsManager.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/DrawableTagsManager.java index add7065742..13455d2fb1 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/DrawableTagsManager.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/DrawableTagsManager.java @@ -45,7 +45,7 @@ public class DrawableTagsManager { private static final String FOLLOW_UP = "Follow Up"; - private Object autopsyTagsManagerLock = new Object(); + final private Object autopsyTagsManagerLock = new Object(); private TagsManager autopsyTagsManager; /** Used to distribute {@link TagsChangeEvent}s */ @@ -66,7 +66,7 @@ public class DrawableTagsManager { * @param autopsyTagsManager */ public void setAutopsyTagsManager(TagsManager autopsyTagsManager) { - synchronized (autopsyTagsManager) { + synchronized (autopsyTagsManagerLock) { this.autopsyTagsManager = autopsyTagsManager; clearFollowUpTagName(); } @@ -77,7 +77,7 @@ public class DrawableTagsManager { * next case. */ public void clearFollowUpTagName() { - synchronized (autopsyTagsManager) { + synchronized (autopsyTagsManagerLock) { followUpTagName = null; } } @@ -108,7 +108,7 @@ public class DrawableTagsManager { * @throws TskCoreException */ public TagName getFollowUpTagName() throws TskCoreException { - synchronized (autopsyTagsManager) { + synchronized (autopsyTagsManagerLock) { if (Objects.isNull(followUpTagName)) { followUpTagName = getTagName(FOLLOW_UP); } @@ -117,7 +117,7 @@ public class DrawableTagsManager { } public Collection getNonCategoryTagNames() { - synchronized (autopsyTagsManager) { + synchronized (autopsyTagsManagerLock) { try { return autopsyTagsManager.getAllTagNames().stream() .filter(Category::isCategoryTagName) @@ -140,13 +140,13 @@ public class DrawableTagsManager { * @throws TskCoreException */ public List getContentTagsByContent(Content content) throws TskCoreException { - synchronized (autopsyTagsManager) { + synchronized (autopsyTagsManagerLock) { return autopsyTagsManager.getContentTagsByContent(content); } } public TagName getTagName(String displayName) throws TskCoreException { - synchronized (autopsyTagsManager) { + synchronized (autopsyTagsManagerLock) { try { for (TagName tn : autopsyTagsManager.getAllTagNames()) { if (displayName.equals(tn.getDisplayName())) { @@ -175,14 +175,14 @@ public class DrawableTagsManager { public void addContentTag(DrawableFile file, TagName tagName, String comment) throws TskCoreException { ContentTag addContentTag; - synchronized (autopsyTagsManager) { + synchronized (autopsyTagsManagerLock) { addContentTag = autopsyTagsManager.addContentTag(file, tagName, comment); } fireTagAdded(addContentTag); } public List getContentTagsByTagName(TagName t) throws TskCoreException { - synchronized (autopsyTagsManager) { + synchronized (autopsyTagsManagerLock) { return autopsyTagsManager.getContentTagsByTagName(t); } } @@ -203,13 +203,13 @@ public class DrawableTagsManager { } public List getAllTagNames() throws TskCoreException { - synchronized (autopsyTagsManager) { + synchronized (autopsyTagsManagerLock) { return autopsyTagsManager.getAllTagNames(); } } public List getTagNamesInUse() throws TskCoreException { - synchronized (autopsyTagsManager) { + synchronized (autopsyTagsManagerLock) { return autopsyTagsManager.getTagNamesInUse(); } } @@ -221,21 +221,11 @@ public class DrawableTagsManager { public void fireTagDeleted(ContentTag oldTag) { tagsEventBus.post(new TagsChangeEvent(Collections.singleton(oldTag.getContent().getId()))); } -// -// /** -// * fire a TagsChangeEvent with the given fileIDs -// * -// * @param fileIDs -// */ -// public final void fireChange(Collection fileIDs) { -// tagsEventBus.post(new TagsChangeEvent(fileIDs)); -// } public void deleteContentTag(ContentTag ct) throws TskCoreException { - synchronized (autopsyTagsManager) { + synchronized (autopsyTagsManagerLock) { autopsyTagsManager.deleteContentTag(ct); } fireTagDeleted(ct); } - } From 929f8c9c9c018979d4d6bde6d7d4c30d12f5fc2a Mon Sep 17 00:00:00 2001 From: jmillman Date: Fri, 19 Jun 2015 10:22:18 -0400 Subject: [PATCH 15/56] Tag Events - created new Case.Event enum values for BlackBoard/Content tags added/deleted - created new PropertyChangeEvent subclasses for BlackBoard/Content tags added/deleted - replaced ModuleDataEvent hack with new Tag Events - removed [in] from javadocs, other minor cleanup --- .../sleuthkit/autopsy/casemodule/Case.java | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/Case.java b/Core/src/org/sleuthkit/autopsy/casemodule/Case.java index b4c61305b2..30216d3140 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/Case.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/Case.java @@ -547,6 +547,59 @@ public class Case implements SleuthkitCase.ErrorObserver { } } + /** + * Notifies the UI that a new ContentTag has been added. + * + * @param newTag new ContentTag added + */ + public void notifyContentTagAdded(ContentTag newTag) { + notify(new ContentTagAddedEvent(newTag)); + } + + /** + * Notifies the UI that a ContentTag has been deleted. + * + * @param deletedTag ContentTag deleted + */ + public void notifyContentTagDeleted(ContentTag deletedTag) { + notify(new ContentTagDeletedEvent(deletedTag)); + } + + /** + * Notifies the UI that a new BlackboardArtifactTag has been added. + * + * @param newTag new BlackboardArtifactTag added + */ + public void notifyBlackBoardArtifactTagAdded(BlackboardArtifactTag newTag) { + notify(new BlackBoardArtifactTagAddedEvent(newTag)); + } + + /** + * Notifies the UI that a BlackboardArtifactTag has been. + * + * @param deletedTag BlackboardArtifactTag deleted + */ + public void notifyBlackBoardArtifactTagDeleted(BlackboardArtifactTag deletedTag) { + notify(new BlackBoardArtifactTagDeletedEvent(deletedTag)); + } + + /** + * Notifies the UI about a Case level event. + * + * @param propertyChangeEvent the event to distribute + */ + private void notify(final PropertyChangeEvent propertyChangeEvent) { + try { + pcs.firePropertyChange(propertyChangeEvent); + } catch (Exception e) { + logger.log(Level.SEVERE, "Case threw exception", e); //NON-NLS + MessageNotifyUtil.Notify.show(NbBundle.getMessage(this.getClass(), "Case.moduleErr"), + NbBundle.getMessage(this.getClass(), + "Case.changeCase.errListenToCaseUpdates.msg"), + MessageNotifyUtil.MessageType.ERROR); + } + } + /** * @return The Services object for this case. */ From 22868333a0491fb55d83499cc3f0b889b8b99c9f Mon Sep 17 00:00:00 2001 From: jmillman Date: Fri, 19 Jun 2015 13:53:53 -0400 Subject: [PATCH 16/56] use new Autopsy Tag events, don't fire extra events from ig, but listen to events from autopsy --- .../imagegallery/DrawableTagsManager.java | 82 ++++++++----------- .../imagegallery/ImageGalleryController.java | 30 +++---- .../autopsy/imagegallery/TagsChangeEvent.java | 41 ---------- .../actions/AddDrawableTagAction.java | 9 +- .../imagegallery/actions/AddTagAction.java | 7 +- .../actions/CategorizeAction.java | 27 +++--- .../actions/DeleteFollowUpTagAction.java | 7 +- .../imagegallery/datamodel/Category.java | 12 --- .../datamodel/CategoryChangeEvent.java | 14 +++- .../datamodel/CategoryManager.java | 69 +++++++++++++++- .../imagegallery/datamodel/DrawableFile.java | 2 +- .../imagegallery/grouping/GroupManager.java | 64 +++++++++------ .../imagegallery/gui/DrawableView.java | 8 +- .../imagegallery/gui/DrawableViewBase.java | 18 ++-- .../imagegallery/gui/MetaDataPane.java | 18 ++-- 15 files changed, 208 insertions(+), 200 deletions(-) delete mode 100644 ImageGallery/src/org/sleuthkit/autopsy/imagegallery/TagsChangeEvent.java diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/DrawableTagsManager.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/DrawableTagsManager.java index 13455d2fb1..0bbc4b9d5a 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/DrawableTagsManager.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/DrawableTagsManager.java @@ -27,11 +27,11 @@ import java.util.logging.Level; import java.util.stream.Collectors; import org.sleuthkit.autopsy.casemodule.services.TagsManager; import org.sleuthkit.autopsy.coreutils.Logger; +import org.sleuthkit.autopsy.events.ContentTagAddedEvent; +import org.sleuthkit.autopsy.events.ContentTagDeletedEvent; import org.sleuthkit.autopsy.imagegallery.datamodel.Category; +import org.sleuthkit.autopsy.imagegallery.datamodel.CategoryManager; import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableFile; -import org.sleuthkit.autopsy.ingest.IngestServices; -import org.sleuthkit.autopsy.ingest.ModuleDataEvent; -import org.sleuthkit.datamodel.BlackboardArtifact; import org.sleuthkit.datamodel.Content; import org.sleuthkit.datamodel.ContentTag; import org.sleuthkit.datamodel.TagName; @@ -59,6 +59,32 @@ public class DrawableTagsManager { } + /** + * register an object to receive CategoryChangeEvents + * + * @param listner + */ + public void registerListener(Object listner) { + tagsEventBus.register(listner); + } + + /** + * unregister an object from receiving CategoryChangeEvents + * + * @param listener + */ + public void unregisterListener(Object listener) { + tagsEventBus.unregister(listener); + } + + public void fireTagAddedEvent(ContentTagAddedEvent event) { + tagsEventBus.post(event); + } + + public void fireTagDeletedEvent(ContentTagDeletedEvent event) { + tagsEventBus.post(event); + } + /** * assign a new TagsManager to back this one, ie when the current case * changes @@ -82,24 +108,6 @@ public class DrawableTagsManager { } } - /** - * register an object to receive CategoryChangeEvents - * - * @param listner - */ - public void registerListener(Object listner) { - tagsEventBus.register(listner); - } - - /** - * unregister an object from receiving CategoryChangeEvents - * - * @param listener - */ - public void unregisterListener(Object listener) { - tagsEventBus.unregister(listener); - } - /** * get the (cached) follow up TagName * @@ -120,7 +128,7 @@ public class DrawableTagsManager { synchronized (autopsyTagsManagerLock) { try { return autopsyTagsManager.getAllTagNames().stream() - .filter(Category::isCategoryTagName) + .filter(CategoryManager::isCategoryTagName) .collect(Collectors.toSet()); } catch (TskCoreException | IllegalStateException ex) { Logger.getLogger(DrawableTagsManager.class.getName()).log(Level.WARNING, "couldn't access case", ex); @@ -173,12 +181,10 @@ public class DrawableTagsManager { } } - public void addContentTag(DrawableFile file, TagName tagName, String comment) throws TskCoreException { - ContentTag addContentTag; + public ContentTag addContentTag(DrawableFile file, TagName tagName, String comment) throws TskCoreException { synchronized (autopsyTagsManagerLock) { - addContentTag = autopsyTagsManager.addContentTag(file, tagName, comment); + return autopsyTagsManager.addContentTag(file, tagName, comment); } - fireTagAdded(addContentTag); } public List getContentTagsByTagName(TagName t) throws TskCoreException { @@ -187,21 +193,6 @@ public class DrawableTagsManager { } } - /** - * Fire the ModuleDataEvent that we use as a place holder for a real Tag - * Event. This is used to refresh the autopsy tag tree and the ui in - * ImageGallery - * - * - * Note: this is a hack. In an ideal world, TagsManager would fire - * events so that the directory tree would refresh. But, we haven't - * had a chance to add that so, we fire these events and the tree - * refreshes based on them. - */ - static public void refreshTagsInAutopsy() { - IngestServices.getInstance().fireModuleDataEvent(new ModuleDataEvent("TagAction", BlackboardArtifact.ARTIFACT_TYPE.TSK_TAG_FILE)); //NON-NLS - } - public List getAllTagNames() throws TskCoreException { synchronized (autopsyTagsManagerLock) { return autopsyTagsManager.getAllTagNames(); @@ -214,18 +205,9 @@ public class DrawableTagsManager { } } - public void fireTagAdded(ContentTag newTag) { - tagsEventBus.post(new TagsChangeEvent(Collections.singleton(newTag.getContent().getId()))); - } - - public void fireTagDeleted(ContentTag oldTag) { - tagsEventBus.post(new TagsChangeEvent(Collections.singleton(oldTag.getContent().getId()))); - } - public void deleteContentTag(ContentTag ct) throws TskCoreException { synchronized (autopsyTagsManagerLock) { autopsyTagsManager.deleteContentTag(ct); } - fireTagDeleted(ct); } } diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java index 046c88bc7a..6c6bd7c789 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java @@ -20,7 +20,6 @@ package org.sleuthkit.autopsy.imagegallery; import java.beans.PropertyChangeEvent; import java.util.ArrayList; -import java.util.Collections; import java.util.List; import java.util.Objects; import java.util.concurrent.BlockingQueue; @@ -58,10 +57,9 @@ import org.sleuthkit.autopsy.casemodule.Case; import org.sleuthkit.autopsy.coreutils.History; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.coreutils.ThreadConfined; -import org.sleuthkit.autopsy.imagegallery.actions.CategorizeAction; -import org.sleuthkit.autopsy.imagegallery.datamodel.Category; +import org.sleuthkit.autopsy.events.ContentTagAddedEvent; +import org.sleuthkit.autopsy.events.ContentTagDeletedEvent; import org.sleuthkit.autopsy.imagegallery.datamodel.CategoryManager; -import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableAttribute; import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableDB; import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableFile; import org.sleuthkit.autopsy.imagegallery.datamodel.HashSetManager; @@ -74,7 +72,6 @@ import org.sleuthkit.datamodel.AbstractFile; import org.sleuthkit.datamodel.BlackboardArtifact; import org.sleuthkit.datamodel.BlackboardAttribute; import org.sleuthkit.datamodel.Content; -import org.sleuthkit.datamodel.ContentTag; import org.sleuthkit.datamodel.FileSystem; import org.sleuthkit.datamodel.Image; import org.sleuthkit.datamodel.SleuthkitCase; @@ -366,6 +363,8 @@ public final class ImageGalleryController { categoryManager.setDb(db); tagsManager.setAutopsyTagsManager(theNewCase.getServices().getTagsManager()); tagsManager.registerListener(groupManager); + tagsManager.registerListener(categoryManager); + } else { reset(); } @@ -384,6 +383,7 @@ public final class ImageGalleryController { }); tagsManager.clearFollowUpTagName(); tagsManager.unregisterListener(groupManager); + tagsManager.unregisterListener(categoryManager); Toolbar.getDefault(this).reset(); groupManager.clear(); @@ -490,23 +490,15 @@ public final class ImageGalleryController { } break; case CONTENT_TAG_ADDED: - ContentTag newTag = (ContentTag) evt.getNewValue(); - if (Category.isCategoryTagName(newTag.getName())) { - new CategorizeAction(ImageGalleryController.this).addTag(newTag.getName(), ""); - } else { - getTagsManager().fireTagAdded(newTag); + final ContentTagAddedEvent tagAddedEvent = (ContentTagAddedEvent) evt; + if (getDatabase().isInDB((tagAddedEvent).getAddedTag().getContent().getId())) { + getTagsManager().fireTagAddedEvent(tagAddedEvent); } break; case CONTENT_TAG_DELETED: - ContentTag oldTag = (ContentTag) evt.getOldValue(); - final long fileID = oldTag.getContent().getId(); - if (getDatabase().isInDB(fileID)) { - if (Category.isCategoryTagName(oldTag.getName())) { - getCategoryManager().decrementCategoryCount(Category.fromTagName(oldTag.getName())); - getGroupManager().handleFileUpdate(FileUpdateEvent.newUpdateEvent(Collections.singleton(fileID), DrawableAttribute.CATEGORY)); - } else { - getTagsManager().fireTagDeleted(oldTag); - } + final ContentTagDeletedEvent tagDeletedEvent = (ContentTagDeletedEvent) evt; + if (getDatabase().isInDB((tagDeletedEvent).getDeletedTag().getContent().getId())) { + getTagsManager().fireTagDeletedEvent(tagDeletedEvent); } break; } diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/TagsChangeEvent.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/TagsChangeEvent.java deleted file mode 100644 index 0647a18456..0000000000 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/TagsChangeEvent.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Autopsy Forensic Browser - * - * Copyright 2015 Basis Technology Corp. - * Contact: carrier sleuthkit org - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.sleuthkit.autopsy.imagegallery; - -import java.util.Collection; -import java.util.Collections; -import javax.annotation.concurrent.Immutable; - -/** - * - */ -@Immutable -public class TagsChangeEvent { - - private final Collection fileIDs; - - public Collection getFileIDs() { - return Collections.unmodifiableCollection(fileIDs); - } - - public TagsChangeEvent(Collection fileIDs) { - this.fileIDs = fileIDs; - } - -} diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/AddDrawableTagAction.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/AddDrawableTagAction.java index e88c51f12b..be9343f4de 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/AddDrawableTagAction.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/AddDrawableTagAction.java @@ -18,7 +18,6 @@ */ package org.sleuthkit.autopsy.imagegallery.actions; -import java.util.Collections; import java.util.HashSet; import java.util.Set; import java.util.concurrent.ExecutionException; @@ -28,11 +27,8 @@ import javax.swing.JOptionPane; import javax.swing.SwingWorker; import org.openide.util.Utilities; import org.sleuthkit.autopsy.coreutils.Logger; -import org.sleuthkit.autopsy.imagegallery.DrawableTagsManager; import org.sleuthkit.autopsy.imagegallery.FileIDSelectionModel; -import org.sleuthkit.autopsy.imagegallery.FileUpdateEvent; import org.sleuthkit.autopsy.imagegallery.ImageGalleryController; -import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableAttribute; import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableFile; import org.sleuthkit.datamodel.AbstractFile; import org.sleuthkit.datamodel.TagName; @@ -87,10 +83,9 @@ public class AddDrawableTagAction extends AddTagAction { JOptionPane.showMessageDialog(null, "Unable to tag " + fileID + ".", "Tagging Error", JOptionPane.ERROR_MESSAGE); } - //make sure rest of ui hears category change. - controller.getGroupManager().handleFileUpdate(FileUpdateEvent.newUpdateEvent(Collections.singleton(fileID), DrawableAttribute.TAGS)); +// //make sure rest of ui hears category change. +// controller.getGroupManager().handleFileUpdate(FileUpdateEvent.newUpdateEvent(Collections.singleton(fileID), DrawableAttribute.TAGS)); } - DrawableTagsManager.refreshTagsInAutopsy(); return null; } diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/AddTagAction.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/AddTagAction.java index abc441fb61..615b9b7f7d 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/AddTagAction.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/AddTagAction.java @@ -31,7 +31,7 @@ import org.sleuthkit.autopsy.casemodule.services.TagsManager; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.imagegallery.DrawableTagsManager; import org.sleuthkit.autopsy.imagegallery.ImageGalleryController; -import org.sleuthkit.autopsy.imagegallery.datamodel.Category; +import org.sleuthkit.autopsy.imagegallery.datamodel.CategoryManager; import org.sleuthkit.datamodel.TagName; import org.sleuthkit.datamodel.TskCoreException; @@ -95,11 +95,10 @@ abstract class AddTagAction { // a tag with the associated tag name. if (null != tagNames && !tagNames.isEmpty()) { for (final TagName tagName : tagNames) { - if (Category.isNotCategoryTagName(tagName)) { + if (CategoryManager.isNotCategoryTagName(tagName)) { MenuItem tagNameItem = new MenuItem(tagName.getDisplayName()); tagNameItem.setOnAction((ActionEvent t) -> { addTag(tagName, NO_COMMENT); - DrawableTagsManager.refreshTagsInAutopsy(); }); quickTagMenu.getItems().add(tagNameItem); } @@ -134,7 +133,7 @@ abstract class AddTagAction { SwingUtilities.invokeLater(() -> { GetTagNameAndCommentDialog.TagNameAndComment tagNameAndComment = GetTagNameAndCommentDialog.doDialog(); if (null != tagNameAndComment) { - if (Category.isCategoryTagName(tagNameAndComment.getTagName())) { + if (CategoryManager.isCategoryTagName(tagNameAndComment.getTagName())) { new CategorizeAction(controller).addTag(tagNameAndComment.getTagName(), tagNameAndComment.getComment()); } else { new AddDrawableTagAction(controller).addTag(tagNameAndComment.getTagName(), tagNameAndComment.getComment()); diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/CategorizeAction.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/CategorizeAction.java index 8918934a6e..067a5cf967 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/CategorizeAction.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/CategorizeAction.java @@ -18,7 +18,6 @@ */ package org.sleuthkit.autopsy.imagegallery.actions; -import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -32,7 +31,6 @@ import javax.swing.JOptionPane; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.imagegallery.DrawableTagsManager; import org.sleuthkit.autopsy.imagegallery.FileIDSelectionModel; -import org.sleuthkit.autopsy.imagegallery.FileUpdateEvent; import org.sleuthkit.autopsy.imagegallery.ImageGalleryController; import org.sleuthkit.autopsy.imagegallery.datamodel.Category; import org.sleuthkit.autopsy.imagegallery.datamodel.CategoryManager; @@ -41,7 +39,6 @@ import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableFile; import org.sleuthkit.autopsy.imagegallery.grouping.GroupKey; import org.sleuthkit.autopsy.imagegallery.grouping.GroupManager; import org.sleuthkit.datamodel.ContentTag; -import org.sleuthkit.datamodel.SleuthkitCase; import org.sleuthkit.datamodel.TagName; import org.sleuthkit.datamodel.TskCoreException; @@ -87,6 +84,10 @@ public class CategorizeAction extends AddTagAction { } } + public void enforceOneCat(TagName name, String string) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + /** * Instances of this class implement a context menu user interface for * selecting a category @@ -127,8 +128,8 @@ public class CategorizeAction extends AddTagAction { @Override public void run() { final GroupManager groupManager = controller.getGroupManager(); - final SleuthkitCase sleuthKitCase = controller.getSleuthKitCase(); final CategoryManager categoryManager = controller.getCategoryManager(); + final DrawableTagsManager tagsManager = controller.getTagsManager(); try { DrawableFile file = controller.getFileFromId(fileID); //drawable db @@ -138,27 +139,27 @@ public class CategorizeAction extends AddTagAction { groupManager.removeFromGroup(new GroupKey(DrawableAttribute.CATEGORY, oldCat), fileID); //memory //remove old category tag if necessary - List allContentTags = sleuthKitCase.getContentTagsByContent(file); //tsk db + List allContentTags = tagsManager.getContentTagsByContent(file); //tsk db + //JMTODO: move this to CategoryManager for (ContentTag ct : allContentTags) { - if (Category.isCategoryTagName(ct.getName())) { - sleuthKitCase.deleteContentTag(ct); //tsk db - categoryManager.decrementCategoryCount(Category.fromDisplayName(ct.getName().getDisplayName())); //memory/drawable db + if (CategoryManager.isCategoryTagName(ct.getName())) { + tagsManager.deleteContentTag(ct); //tsk db +// categoryManager.decrementCategoryCount(Category.fromDisplayName(ct.getName().getDisplayName())); //memory/drawable db } } - categoryManager.incrementCategoryCount(Category.fromDisplayName(tagName.getDisplayName())); //memory/drawable db +// categoryManager.incrementCategoryCount(Category.fromDisplayName(tagName.getDisplayName())); //memory/drawable db if (tagName != categoryManager.getTagName(Category.ZERO)) { // no tags for cat-0 - controller.getTagsManager().addContentTag(file, tagName, comment); //tsk db + tagsManager.addContentTag(file, tagName, comment); //tsk db } - //make sure rest of ui hears category change. - groupManager.handleFileUpdate(FileUpdateEvent.newUpdateEvent(Collections.singleton(fileID), DrawableAttribute.CATEGORY)); //memory/ui +// //make sure rest of ui hears category change. +// groupManager.handleFileUpdate(FileUpdateEvent.newUpdateEvent(Collections.singleton(fileID), DrawableAttribute.CATEGORY)); //memory/ui } catch (TskCoreException ex) { LOGGER.log(Level.SEVERE, "Error categorizing result", ex); JOptionPane.showMessageDialog(null, "Unable to categorize " + fileID + ".", "Categorizing Error", JOptionPane.ERROR_MESSAGE); } - DrawableTagsManager.refreshTagsInAutopsy(); } } diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/DeleteFollowUpTagAction.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/DeleteFollowUpTagAction.java index 98fdc316ad..aab8a9c827 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/DeleteFollowUpTagAction.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/DeleteFollowUpTagAction.java @@ -18,7 +18,6 @@ */ package org.sleuthkit.autopsy.imagegallery.actions; -import java.util.Collections; import java.util.List; import java.util.logging.Level; import javafx.event.ActionEvent; @@ -26,14 +25,12 @@ import javax.swing.SwingWorker; import org.controlsfx.control.action.Action; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.imagegallery.DrawableTagsManager; -import org.sleuthkit.autopsy.imagegallery.FileUpdateEvent; import org.sleuthkit.autopsy.imagegallery.ImageGalleryController; import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableAttribute; import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableFile; import org.sleuthkit.autopsy.imagegallery.grouping.GroupKey; import org.sleuthkit.autopsy.imagegallery.grouping.GroupManager; import org.sleuthkit.datamodel.ContentTag; -import org.sleuthkit.datamodel.SleuthkitCase; import org.sleuthkit.datamodel.TagName; import org.sleuthkit.datamodel.TskCoreException; @@ -53,7 +50,6 @@ public class DeleteFollowUpTagAction extends Action { @Override protected Void doInBackground() throws Exception { - final SleuthkitCase sleuthKitCase = controller.getSleuthKitCase(); final GroupManager groupManager = controller.getGroupManager(); final DrawableTagsManager tagsManager = controller.getTagsManager(); @@ -69,9 +65,8 @@ public class DeleteFollowUpTagAction extends Action { } } - DrawableTagsManager.refreshTagsInAutopsy(); //make sure rest of ui hears category change. - groupManager.handleFileUpdate(FileUpdateEvent.newUpdateEvent(Collections.singleton(fileID), DrawableAttribute.TAGS)); +// groupManager.handleFileUpdate(FileUpdateEvent.newUpdateEvent(Collections.singleton(fileID), DrawableAttribute.TAGS)); } catch (TskCoreException ex) { LOGGER.log(Level.SEVERE, "Failed to delete follow up tag.", ex); } diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/Category.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/Category.java index 00750c4ba9..8999fff2f1 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/Category.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/Category.java @@ -23,7 +23,6 @@ import java.util.function.Function; import java.util.stream.Collectors; import java.util.stream.Stream; import javafx.scene.paint.Color; -import org.sleuthkit.datamodel.TagName; /** * Enum to represent the six categories in the DHs image categorization scheme. @@ -49,17 +48,6 @@ public enum Category { public static Category fromDisplayName(String displayName) { return nameMap.get(displayName); } - public static Category fromTagName(TagName tagName) { - return nameMap.get(tagName.getDisplayName()); - } - - public static boolean isCategoryTagName(TagName tName) { - return isCategoryName(tName.getDisplayName()); - } - - public static boolean isNotCategoryTagName(TagName tName) { - return isNotCategoryName(tName.getDisplayName()); - } public static boolean isCategoryName(String tName) { return nameMap.containsKey(tName); diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/CategoryChangeEvent.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/CategoryChangeEvent.java index 9896325e09..3868864737 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/CategoryChangeEvent.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/CategoryChangeEvent.java @@ -30,6 +30,16 @@ import javax.annotation.concurrent.Immutable; public class CategoryChangeEvent { private final Collection fileIDs; + private final Category newCategory; + + public CategoryChangeEvent(Collection fileIDs, Category newCategory) { + this.fileIDs = fileIDs; + this.newCategory = newCategory; + } + + public Category getNewCategory() { + return newCategory; + } /** * @return the fileIDs of the files whose categories have changed @@ -37,8 +47,4 @@ public class CategoryChangeEvent { public Collection getFileIDs() { return Collections.unmodifiableCollection(fileIDs); } - - public CategoryChangeEvent(Collection fileIDs) { - this.fileIDs = fileIDs; - } } diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/CategoryManager.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/CategoryManager.java index f8b0e6beb1..b6a11d2b25 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/CategoryManager.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/CategoryManager.java @@ -24,11 +24,17 @@ import com.google.common.eventbus.EventBus; import com.google.common.eventbus.Subscribe; import java.util.Collection; import java.util.Collections; +import java.util.List; import java.util.concurrent.atomic.LongAdder; import java.util.logging.Level; import org.sleuthkit.autopsy.coreutils.Logger; +import org.sleuthkit.autopsy.events.ContentTagAddedEvent; +import org.sleuthkit.autopsy.events.ContentTagDeletedEvent; +import org.sleuthkit.autopsy.imagegallery.DrawableTagsManager; import org.sleuthkit.autopsy.imagegallery.ImageGalleryController; +import org.sleuthkit.datamodel.ContentTag; import org.sleuthkit.datamodel.TagName; +import org.sleuthkit.datamodel.TskCoreException; /** * Provides a cached view of the number of files per category, and fires @@ -94,13 +100,13 @@ public class CategoryManager { this.db = db; categoryCounts.invalidateAll(); catTagNameMap.invalidateAll(); - fireChange(Collections.singleton(-1L)); + fireChange(Collections.emptyList(), null); } synchronized public void invalidateCaches() { categoryCounts.invalidateAll(); catTagNameMap.invalidateAll(); - fireChange(Collections.singleton(-1L)); + fireChange(Collections.emptyList(), null); } /** @@ -173,8 +179,8 @@ public class CategoryManager { * * @param fileIDs */ - public void fireChange(Collection fileIDs) { - categoryEventBus.post(new CategoryChangeEvent(fileIDs)); + public void fireChange(Collection fileIDs, Category newCategory) { + categoryEventBus.post(new CategoryChangeEvent(fileIDs, newCategory)); } /** @@ -204,4 +210,59 @@ public class CategoryManager { return catTagNameMap.getUnchecked(cat); } + + public static Category fromTagName(TagName tagName) { + return Category.fromDisplayName(tagName.getDisplayName()); + } + + public static boolean isCategoryTagName(TagName tName) { + return Category.isCategoryName(tName.getDisplayName()); + } + + public static boolean isNotCategoryTagName(TagName tName) { + return Category.isNotCategoryName(tName.getDisplayName()); + + } + + public void handleTagAdded(ContentTagAddedEvent event) { + ContentTag addedTag = event.getAddedTag(); + if (isCategoryTagName(addedTag.getName())) { + final DrawableTagsManager tagsManager = controller.getTagsManager(); + try { + //remove old category tag(s) if necessary + List allContentTags = tagsManager.getContentTagsByContent(addedTag.getContent()); + + for (ContentTag ct : allContentTags) { + if (ct.getId() != addedTag.getId() + && CategoryManager.isCategoryTagName(ct.getName())) { + try { + tagsManager.deleteContentTag(ct); + } catch (TskCoreException tskException) { + LOGGER.log(Level.SEVERE, "Failed to delete content tag. Unable to maintain categories in a consistent state.", tskException); + } + } + } + } catch (TskCoreException tskException) { + LOGGER.log(Level.SEVERE, "Failed to get content tags for content. Unable to maintain category in a consistent state.", tskException); + } + Category newCat = CategoryManager.fromTagName(addedTag.getName()); + if (newCat != Category.ZERO) { + incrementCategoryCount(newCat); + } + + fireChange(Collections.singleton(addedTag.getId()), newCat); + } + } + + public void handleTagDeleted(ContentTagDeletedEvent event) { + ContentTag deleted = event.getDeletedTag(); + if (isCategoryTagName(deleted.getName())) { + + Category deletedCat = CategoryManager.fromTagName(deleted.getName()); + if (deletedCat != Category.ZERO) { + decrementCategoryCount(deletedCat); + } + fireChange(Collections.singleton(deleted.getId()), null); + } + } } diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableFile.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableFile.java index 3890ca577a..79ea49f879 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableFile.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableFile.java @@ -272,7 +272,7 @@ public abstract class DrawableFile extends AbstractFile private void updateCategory() { try { category.set(getSleuthkitCase().getContentTagsByContent(this).stream() - .map(Tag::getName).filter(Category::isCategoryTagName) + .map(Tag::getName).filter(CategoryManager::isCategoryTagName) .map(TagName::getDisplayName) .map(Category::fromDisplayName) .sorted().findFirst() //sort by severity and take the first diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/GroupManager.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/GroupManager.java index 51a99bd5f7..733baf2813 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/GroupManager.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/GroupManager.java @@ -60,12 +60,14 @@ import org.sleuthkit.autopsy.coreutils.LoggedTask; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.coreutils.ThreadConfined; import org.sleuthkit.autopsy.coreutils.ThreadConfined.ThreadType; +import org.sleuthkit.autopsy.events.ContentTagAddedEvent; +import org.sleuthkit.autopsy.events.ContentTagDeletedEvent; import org.sleuthkit.autopsy.imagegallery.DrawableTagsManager; import org.sleuthkit.autopsy.imagegallery.FileUpdateEvent; import org.sleuthkit.autopsy.imagegallery.ImageGalleryController; import org.sleuthkit.autopsy.imagegallery.ImageGalleryModule; -import org.sleuthkit.autopsy.imagegallery.TagsChangeEvent; import org.sleuthkit.autopsy.imagegallery.datamodel.Category; +import org.sleuthkit.autopsy.imagegallery.datamodel.CategoryManager; import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableAttribute; import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableDB; import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableFile; @@ -161,7 +163,7 @@ public class GroupManager implements FileUpdateEvent.FileUpdateListener { Set> resultSet = new HashSet<>(); for (Comparable val : groupBy.getValue(file)) { if (groupBy == DrawableAttribute.TAGS) { - if (Category.isNotCategoryTagName((TagName) val)) { + if (CategoryManager.isNotCategoryTagName((TagName) val)) { resultSet.add(new GroupKey(groupBy, val)); } } else { @@ -282,6 +284,10 @@ public class GroupManager implements FileUpdateEvent.FileUpdateListener { }); } } + } else { //group == null + // It may be that this was the last unanalyzed file in the group, so test + // whether the group is now fully analyzed. + popuplateIfAnalyzed(groupKey, null); } return group; @@ -360,7 +366,7 @@ public class GroupManager implements FileUpdateEvent.FileUpdateListener { break; case TAGS: values = (List) controller.getTagsManager().getTagNamesInUse().stream() - .filter(Category::isNotCategoryTagName) + .filter(CategoryManager::isNotCategoryTagName) .collect(Collectors.toList()); break; case ANALYZED: @@ -528,14 +534,31 @@ public class GroupManager implements FileUpdateEvent.FileUpdateListener { } @Subscribe - public void handleAutopsyTagChange(TagsChangeEvent evt) { - if (groupBy == DrawableAttribute.TAGS - && evt.getFileIDs().size() == 1 - && evt.getFileIDs().contains(-1L)) { - regroup(groupBy, sortBy, sortOrder, Boolean.TRUE); + public void handleTagAdded(ContentTagAddedEvent evt) { + final GroupKey groupKey = new GroupKey<>(DrawableAttribute.TAGS, evt.getAddedTag().getName()); + final long fileID = evt.getAddedTag().getContent().getId(); + DrawableGroup g = getGroupForKey(groupKey); + addFileToGroup(g, groupKey, fileID); + + } + + private void addFileToGroup(DrawableGroup g, final GroupKey groupKey, final long fileID) { + if (g == null) { + //if there wasn't already a group check if there should be one now + popuplateIfAnalyzed(groupKey, null); + } else { + //if there is aleady a group that was previously deemed fully analyzed, then add this newly analyzed file to it. + g.addFile(fileID); } } + @Subscribe + public void handleTagDeleted(ContentTagDeletedEvent evt) { + final GroupKey groupKey = new GroupKey<>(DrawableAttribute.TAGS, evt.getDeletedTag().getName()); + final long fileID = evt.getDeletedTag().getContent().getId(); + DrawableGroup g = removeFromGroup(groupKey, fileID); + } + @Override synchronized public void handleFileRemoved(FileUpdateEvent evt) { Validate.isTrue(evt.getUpdateType() == FileUpdateEvent.UpdateType.REMOVE); @@ -545,13 +568,7 @@ public class GroupManager implements FileUpdateEvent.FileUpdateListener { Set> groupsForFile = getGroupKeysForFileID(fileId); for (GroupKey gk : groupsForFile) { - DrawableGroup g = removeFromGroup(gk, fileId); - - if (g == null) { - // It may be that this was the last unanalyzed file in the group, so test - // whether the group is now fully analyzed. - popuplateIfAnalyzed(gk, null); - } + removeFromGroup(gk, fileId); } } } @@ -578,29 +595,21 @@ public class GroupManager implements FileUpdateEvent.FileUpdateListener { //get grouping(s) this file would be in Set> groupsForFile = getGroupKeysForFileID(fileId); - for (GroupKey gk : groupsForFile) { DrawableGroup g = getGroupForKey(gk); - - if (g == null) { - //if there wasn't already a group check if there should be one now - popuplateIfAnalyzed(gk, null); - } else { - //if there is aleady a group that was previously deemed fully analyzed, then add this newly analyzed file to it. - g.addFile(fileId); - } + addFileToGroup(g, gk, fileId); } } //we fire this event for all files so that the category counts get updated during initial db population - controller.getCategoryManager().fireChange(fileIDs); + controller.getCategoryManager().fireChange(fileIDs, null); // if (evt.getChangedAttribute() == DrawableAttribute.TAGS) { // controller.getTagsManager().fireChange(fileIDs); // } } - private void popuplateIfAnalyzed(GroupKey groupKey, ReGroupTask task) { + private DrawableGroup popuplateIfAnalyzed(GroupKey groupKey, ReGroupTask task) { if (Objects.nonNull(task) && (task.isCancelled())) { /* if this method call is part of a ReGroupTask and that task is @@ -609,6 +618,7 @@ public class GroupManager implements FileUpdateEvent.FileUpdateListener { * this allows us to stop if a regroup task has been cancelled (e.g. * the user picked a different group by attribute, while the * current task was still running) */ + } else { // no task or un-cancelled task if ((groupKey.getAttribute() != DrawableAttribute.PATH) || db.isGroupAnalyzed(groupKey)) { /* for attributes other than path we can't be sure a group is @@ -639,12 +649,14 @@ public class GroupManager implements FileUpdateEvent.FileUpdateListener { } markGroupSeen(group, groupSeen); }); + return group; } } catch (TskCoreException ex) { LOGGER.log(Level.SEVERE, "failed to get files for group: " + groupKey.getAttribute().attrName.toString() + " = " + groupKey.getValue(), ex); } } } + return null; } /** diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableView.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableView.java index 99d8671a63..9b442273d1 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableView.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableView.java @@ -12,8 +12,9 @@ import javafx.scene.layout.Region; import javafx.scene.paint.Color; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.coreutils.ThreadConfined; +import org.sleuthkit.autopsy.events.ContentTagAddedEvent; +import org.sleuthkit.autopsy.events.ContentTagDeletedEvent; import org.sleuthkit.autopsy.imagegallery.ImageGalleryController; -import org.sleuthkit.autopsy.imagegallery.TagsChangeEvent; import org.sleuthkit.autopsy.imagegallery.datamodel.Category; import org.sleuthkit.autopsy.imagegallery.datamodel.CategoryChangeEvent; import org.sleuthkit.autopsy.imagegallery.datamodel.CategoryManager; @@ -68,7 +69,10 @@ public interface DrawableView { void handleCategoryChanged(CategoryChangeEvent evt); @Subscribe - void handleTagsChanged(TagsChangeEvent evt); + void handleTagAdded(ContentTagAddedEvent evt); + + @Subscribe + void handleTagDeleted(ContentTagDeletedEvent evt); ImageGalleryController getController(); diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableViewBase.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableViewBase.java index 93026d688d..ea88d2dfbb 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableViewBase.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableViewBase.java @@ -61,10 +61,11 @@ import org.sleuthkit.autopsy.datamodel.FileNode; import org.sleuthkit.autopsy.directorytree.ExternalViewerAction; import org.sleuthkit.autopsy.directorytree.ExtractAction; import org.sleuthkit.autopsy.directorytree.NewWindowViewAction; +import org.sleuthkit.autopsy.events.ContentTagAddedEvent; +import org.sleuthkit.autopsy.events.ContentTagDeletedEvent; import org.sleuthkit.autopsy.imagegallery.FileIDSelectionModel; import org.sleuthkit.autopsy.imagegallery.ImageGalleryController; import org.sleuthkit.autopsy.imagegallery.ImageGalleryTopComponent; -import org.sleuthkit.autopsy.imagegallery.TagsChangeEvent; import org.sleuthkit.autopsy.imagegallery.actions.AddDrawableTagAction; import org.sleuthkit.autopsy.imagegallery.actions.CategorizeAction; import org.sleuthkit.autopsy.imagegallery.actions.DeleteFollowUpTagAction; @@ -378,16 +379,21 @@ public abstract class DrawableViewBase extends AnchorPane implements DrawableVie @Subscribe @Override - synchronized public void handleTagsChanged(TagsChangeEvent evnt) { - if (fileID != null && (evnt.getFileIDs().contains(fileID) || evnt.getFileIDs().contains(-1L))) { - updateFollowUpIcon(); - } + public void handleTagAdded(ContentTagAddedEvent evt) { + + updateFollowUpIcon(); + } + + @Subscribe + @Override + public void handleTagDeleted(ContentTagDeletedEvent evt) { + updateFollowUpIcon(); } @Subscribe @Override synchronized public void handleCategoryChanged(CategoryChangeEvent evt) { - if (evt.getFileIDs().contains(getFileID()) || evt.getFileIDs().contains(-1L)) { + if (fileID != null && evt.getFileIDs().contains(getFileID())) { updateCategoryBorder(); } } diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/MetaDataPane.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/MetaDataPane.java index 4f4cace550..0681d29eb9 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/MetaDataPane.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/MetaDataPane.java @@ -44,8 +44,9 @@ import javafx.scene.text.Text; import javafx.util.Pair; import org.apache.commons.lang3.StringUtils; import org.sleuthkit.autopsy.coreutils.Logger; +import org.sleuthkit.autopsy.events.ContentTagAddedEvent; +import org.sleuthkit.autopsy.events.ContentTagDeletedEvent; import org.sleuthkit.autopsy.imagegallery.ImageGalleryController; -import org.sleuthkit.autopsy.imagegallery.TagsChangeEvent; import org.sleuthkit.autopsy.imagegallery.datamodel.Category; import org.sleuthkit.autopsy.imagegallery.datamodel.CategoryChangeEvent; import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableAttribute; @@ -225,16 +226,23 @@ public class MetaDataPane extends AnchorPane implements DrawableView { @Subscribe @Override public void handleCategoryChanged(CategoryChangeEvent evt) { - if (getFile() != null && (evt.getFileIDs().contains(-1L) || evt.getFileIDs().contains(getFileID()))) { + if (getFile() != null && evt.getFileIDs().contains(getFileID())) { updateUI(); } } @Override - @Subscribe - public void handleTagsChanged(TagsChangeEvent evt) { - if (getFile() != null && (evt.getFileIDs().contains(-1L) || evt.getFileIDs().contains(getFileID()))) { + public void handleTagAdded(ContentTagAddedEvent evt) { + if (getFile() != null && evt.getAddedTag().getContent().getId() == getFileID()) { updateUI(); } } + + @Override + public void handleTagDeleted(ContentTagDeletedEvent evt) { + if (getFile() != null && evt.getDeletedTag().getContent().getId() == getFileID()) { + updateUI(); + } + } + } From 13ad8aaaeb07bcdb55cf209f55e0d0ffd2d6829d Mon Sep 17 00:00:00 2001 From: jmillman Date: Fri, 19 Jun 2015 17:20:35 -0400 Subject: [PATCH 17/56] remove uneeded notification code; let event handlers do it all. optionalize DrawableView --- Core/nbproject/project.xml | 1 + .../actions/AddDrawableTagAction.java | 3 - .../actions/CategorizeAction.java | 33 +- .../actions/DeleteFollowUpTagAction.java | 11 +- .../datamodel/CategoryManager.java | 3 +- .../imagegallery/grouping/GroupManager.java | 26 +- .../imagegallery/gui/DrawableTile.java | 16 +- .../imagegallery/gui/DrawableView.java | 13 +- .../imagegallery/gui/DrawableViewBase.java | 301 ++++++++++-------- .../imagegallery/gui/MetaDataPane.java | 114 ++++--- .../imagegallery/gui/SlideShowView.java | 81 +++-- 11 files changed, 341 insertions(+), 261 deletions(-) diff --git a/Core/nbproject/project.xml b/Core/nbproject/project.xml index ac5f32a1ac..463e1c1903 100644 --- a/Core/nbproject/project.xml +++ b/Core/nbproject/project.xml @@ -192,6 +192,7 @@ org.sleuthkit.autopsy.coreutils org.sleuthkit.autopsy.datamodel org.sleuthkit.autopsy.directorytree + org.sleuthkit.autopsy.events org.sleuthkit.autopsy.externalresults org.sleuthkit.autopsy.filesearch org.sleuthkit.autopsy.ingest diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/AddDrawableTagAction.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/AddDrawableTagAction.java index be9343f4de..3c115d9134 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/AddDrawableTagAction.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/AddDrawableTagAction.java @@ -82,9 +82,6 @@ public class AddDrawableTagAction extends AddTagAction { LOGGER.log(Level.SEVERE, "Error tagging result", ex); JOptionPane.showMessageDialog(null, "Unable to tag " + fileID + ".", "Tagging Error", JOptionPane.ERROR_MESSAGE); } - -// //make sure rest of ui hears category change. -// controller.getGroupManager().handleFileUpdate(FileUpdateEvent.newUpdateEvent(Collections.singleton(fileID), DrawableAttribute.TAGS)); } return null; } diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/CategorizeAction.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/CategorizeAction.java index 067a5cf967..afe2b3bb5d 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/CategorizeAction.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/CategorizeAction.java @@ -19,7 +19,6 @@ package org.sleuthkit.autopsy.imagegallery.actions; import java.util.HashSet; -import java.util.List; import java.util.Set; import java.util.logging.Level; import javafx.event.ActionEvent; @@ -34,11 +33,7 @@ import org.sleuthkit.autopsy.imagegallery.FileIDSelectionModel; import org.sleuthkit.autopsy.imagegallery.ImageGalleryController; import org.sleuthkit.autopsy.imagegallery.datamodel.Category; import org.sleuthkit.autopsy.imagegallery.datamodel.CategoryManager; -import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableAttribute; import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableFile; -import org.sleuthkit.autopsy.imagegallery.grouping.GroupKey; -import org.sleuthkit.autopsy.imagegallery.grouping.GroupManager; -import org.sleuthkit.datamodel.ContentTag; import org.sleuthkit.datamodel.TagName; import org.sleuthkit.datamodel.TskCoreException; @@ -127,33 +122,25 @@ public class CategorizeAction extends AddTagAction { @Override public void run() { - final GroupManager groupManager = controller.getGroupManager(); final CategoryManager categoryManager = controller.getCategoryManager(); final DrawableTagsManager tagsManager = controller.getTagsManager(); try { DrawableFile file = controller.getFileFromId(fileID); //drawable db - Category oldCat = file.getCategory(); - // remove file from old category group - groupManager.removeFromGroup(new GroupKey(DrawableAttribute.CATEGORY, oldCat), fileID); //memory - - //remove old category tag if necessary - List allContentTags = tagsManager.getContentTagsByContent(file); //tsk db - - //JMTODO: move this to CategoryManager - for (ContentTag ct : allContentTags) { - if (CategoryManager.isCategoryTagName(ct.getName())) { - tagsManager.deleteContentTag(ct); //tsk db -// categoryManager.decrementCategoryCount(Category.fromDisplayName(ct.getName().getDisplayName())); //memory/drawable db - } - } -// categoryManager.incrementCategoryCount(Category.fromDisplayName(tagName.getDisplayName())); //memory/drawable db if (tagName != categoryManager.getTagName(Category.ZERO)) { // no tags for cat-0 tagsManager.addContentTag(file, tagName, comment); //tsk db + } else { + tagsManager.getContentTagsByContent(file).stream() + .filter(tag -> CategoryManager.isCategoryTagName(tag.getName())) + .forEach((ct) -> { + try { + tagsManager.deleteContentTag(ct); + } catch (TskCoreException ex) { + LOGGER.log(Level.SEVERE, "Error removing old categories result", ex); + } + }); } -// //make sure rest of ui hears category change. -// groupManager.handleFileUpdate(FileUpdateEvent.newUpdateEvent(Collections.singleton(fileID), DrawableAttribute.CATEGORY)); //memory/ui } catch (TskCoreException ex) { LOGGER.log(Level.SEVERE, "Error categorizing result", ex); diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/DeleteFollowUpTagAction.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/DeleteFollowUpTagAction.java index aab8a9c827..74082fcd1c 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/DeleteFollowUpTagAction.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/DeleteFollowUpTagAction.java @@ -26,10 +26,7 @@ import org.controlsfx.control.action.Action; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.imagegallery.DrawableTagsManager; import org.sleuthkit.autopsy.imagegallery.ImageGalleryController; -import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableAttribute; import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableFile; -import org.sleuthkit.autopsy.imagegallery.grouping.GroupKey; -import org.sleuthkit.autopsy.imagegallery.grouping.GroupManager; import org.sleuthkit.datamodel.ContentTag; import org.sleuthkit.datamodel.TagName; import org.sleuthkit.datamodel.TskCoreException; @@ -50,23 +47,17 @@ public class DeleteFollowUpTagAction extends Action { @Override protected Void doInBackground() throws Exception { - final GroupManager groupManager = controller.getGroupManager(); final DrawableTagsManager tagsManager = controller.getTagsManager(); try { final TagName followUpTagName = tagsManager.getFollowUpTagName(); - // remove file from old category group - groupManager.removeFromGroup(new GroupKey(DrawableAttribute.TAGS, followUpTagName), fileID); - + List contentTagsByContent = tagsManager.getContentTagsByContent(file); for (ContentTag ct : contentTagsByContent) { if (ct.getName().getDisplayName().equals(followUpTagName.getDisplayName())) { tagsManager.deleteContentTag(ct); } } - - //make sure rest of ui hears category change. -// groupManager.handleFileUpdate(FileUpdateEvent.newUpdateEvent(Collections.singleton(fileID), DrawableAttribute.TAGS)); } catch (TskCoreException ex) { LOGGER.log(Level.SEVERE, "Failed to delete follow up tag.", ex); } diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/CategoryManager.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/CategoryManager.java index b6a11d2b25..466278f588 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/CategoryManager.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/CategoryManager.java @@ -224,6 +224,7 @@ public class CategoryManager { } + @Subscribe public void handleTagAdded(ContentTagAddedEvent event) { ContentTag addedTag = event.getAddedTag(); if (isCategoryTagName(addedTag.getName())) { @@ -253,7 +254,7 @@ public class CategoryManager { fireChange(Collections.singleton(addedTag.getId()), newCat); } } - + @Subscribe public void handleTagDeleted(ContentTagDeletedEvent event) { ContentTag deleted = event.getDeletedTag(); if (isCategoryTagName(deleted.getName())) { diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/GroupManager.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/GroupManager.java index 733baf2813..9ac899742c 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/GroupManager.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/GroupManager.java @@ -279,8 +279,12 @@ public class GroupManager implements FileUpdateEvent.FileUpdateListener { if (groupKey.getAttribute() != DrawableAttribute.CATEGORY) { if (group.fileIds().isEmpty()) { Platform.runLater(() -> { - analyzedGroups.remove(group); - unSeenGroups.remove(group); + if (analyzedGroups.contains(group)) { + analyzedGroups.remove(group); + } + if (unSeenGroups.contains(group)) { + unSeenGroups.remove(group); + } }); } } @@ -535,10 +539,12 @@ public class GroupManager implements FileUpdateEvent.FileUpdateListener { @Subscribe public void handleTagAdded(ContentTagAddedEvent evt) { - final GroupKey groupKey = new GroupKey<>(DrawableAttribute.TAGS, evt.getAddedTag().getName()); - final long fileID = evt.getAddedTag().getContent().getId(); - DrawableGroup g = getGroupForKey(groupKey); - addFileToGroup(g, groupKey, fileID); + if (groupBy == DrawableAttribute.TAGS || groupBy == DrawableAttribute.CATEGORY) { + final GroupKey groupKey = new GroupKey<>(DrawableAttribute.TAGS, evt.getAddedTag().getName()); + final long fileID = evt.getAddedTag().getContent().getId(); + DrawableGroup g = getGroupForKey(groupKey); + addFileToGroup(g, groupKey, fileID); + } } @@ -554,9 +560,11 @@ public class GroupManager implements FileUpdateEvent.FileUpdateListener { @Subscribe public void handleTagDeleted(ContentTagDeletedEvent evt) { - final GroupKey groupKey = new GroupKey<>(DrawableAttribute.TAGS, evt.getDeletedTag().getName()); - final long fileID = evt.getDeletedTag().getContent().getId(); - DrawableGroup g = removeFromGroup(groupKey, fileID); + if (groupBy == DrawableAttribute.TAGS || groupBy == DrawableAttribute.CATEGORY) { + final GroupKey groupKey = new GroupKey<>(DrawableAttribute.TAGS, evt.getDeletedTag().getName()); + final long fileID = evt.getDeletedTag().getContent().getId(); + DrawableGroup g = removeFromGroup(groupKey, fileID); + } } @Override diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableTile.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableTile.java index 75332ba158..96f05dd9c1 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableTile.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableTile.java @@ -33,6 +33,7 @@ import org.sleuthkit.autopsy.coreutils.ThreadConfined; import org.sleuthkit.autopsy.coreutils.ThreadConfined.ThreadType; import org.sleuthkit.autopsy.imagegallery.FXMLConstructor; import static org.sleuthkit.autopsy.imagegallery.gui.DrawableViewBase.globalSelectionModel; +import org.sleuthkit.datamodel.AbstractContent; /** * GUI component that represents a single image as a tile with an icon, a label, @@ -109,15 +110,20 @@ public class DrawableTile extends DrawableViewBase { @Override protected Runnable getContentUpdateRunnable() { - Image image = getFile().getThumbnail(); + if (getFile().isPresent()) { + Image image = getFile().get().getThumbnail(); - return () -> { - imageView.setImage(image); - }; + return () -> { + imageView.setImage(image); + }; + } else { + return () -> { //no-op + }; + } } @Override protected String getTextForLabel() { - return getFile().getName(); + return getFile().map(AbstractContent::getName).orElse(""); } } diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableView.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableView.java index 9b442273d1..e4e6faf1de 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableView.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableView.java @@ -1,6 +1,8 @@ package org.sleuthkit.autopsy.imagegallery.gui; import com.google.common.eventbus.Subscribe; +import java.util.Collection; +import java.util.Optional; import java.util.logging.Level; import javafx.application.Platform; import javafx.scene.layout.Border; @@ -51,11 +53,11 @@ public interface DrawableView { Region getCategoryBorderRegion(); - DrawableFile getFile(); + Optional> getFile(); void setFile(final Long fileID); - Long getFileID(); + Optional getFileID(); /** * update the visual representation of the category of the assigned file. @@ -78,7 +80,10 @@ public interface DrawableView { default boolean hasHashHit() { try { - return getFile().getHashHitSetNames().isEmpty() == false; + return getFile().map(DrawableFile::getHashHitSetNames) + .map((Collection t) -> t.isEmpty() == false) + .orElse(false); + } catch (NullPointerException ex) { // I think this happens when we're in the process of removing images from the view while // also trying to update it? @@ -113,7 +118,7 @@ public interface DrawableView { @ThreadConfined(type = ThreadConfined.ThreadType.ANY) default Category updateCategoryBorder() { if (getFile() != null) { - final Category category = getFile().getCategory(); + final Category category = getFile().map(DrawableFile::getCategory).orElse(Category.ZERO); final Border border = hasHashHit() && (category == Category.ZERO) ? HASH_BORDER : getCategoryBorder(category); diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableViewBase.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableViewBase.java index ea88d2dfbb..a1ee32a108 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableViewBase.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableViewBase.java @@ -23,6 +23,8 @@ import com.google.common.eventbus.Subscribe; import java.util.ArrayList; import java.util.Collection; import java.util.Objects; +import static java.util.Objects.nonNull; +import java.util.Optional; import java.util.logging.Level; import javafx.application.Platform; import javafx.beans.Observable; @@ -130,9 +132,33 @@ public abstract class DrawableViewBase extends AnchorPane implements DrawableVie static private ContextMenu contextMenu; - private DrawableFile file; + volatile private Optional> fileOpt = Optional.empty(); - private Long fileID; + volatile private Optional fileIDOpt = Optional.empty(); + + @Override + public Optional getFileID() { + return fileIDOpt; + } + + @Override + public Optional> getFile() { + if (fileIDOpt.isPresent()) { + if (fileOpt.isPresent() && fileOpt.get().getId() == fileIDOpt.get()) { + return fileOpt; + } else { + try { + fileOpt = Optional.of(ImageGalleryController.getDefault().getFileFromId(fileIDOpt.get())); + } catch (TskCoreException ex) { + Logger.getAnonymousLogger().log(Level.WARNING, "failed to get DrawableFile for obj_id" + fileIDOpt.get(), ex); + fileOpt = Optional.empty(); + } + return fileOpt; + } + } else { + return Optional.empty(); + } + } /** * the groupPane this {@link DrawableViewBase} is embedded in @@ -158,43 +184,44 @@ public abstract class DrawableViewBase extends AnchorPane implements DrawableVie @Override public void handle(MouseEvent t) { + getFile().ifPresent(file -> { + final long fileID = file.getId(); + switch (t.getButton()) { + case PRIMARY: + if (t.getClickCount() == 1) { + if (t.isControlDown()) { - switch (t.getButton()) { - case PRIMARY: - if (t.getClickCount() == 1) { - if (t.isControlDown()) { - globalSelectionModel.toggleSelection(fileID); - } else { - groupPane.makeSelection(t.isShiftDown(), fileID); + globalSelectionModel.toggleSelection(fileID); + } else { + groupPane.makeSelection(t.isShiftDown(), fileID); + } + } else if (t.getClickCount() > 1) { + groupPane.activateSlideShowViewer(fileID); } - } else if (t.getClickCount() > 1) { - groupPane.activateSlideShowViewer(fileID); - } - break; - case SECONDARY: - - if (t.getClickCount() == 1) { - if (globalSelectionModel.isSelected(fileID) == false) { - groupPane.makeSelection(false, fileID); + break; + case SECONDARY: + if (t.getClickCount() == 1) { + if (globalSelectionModel.isSelected(fileID) == false) { + groupPane.makeSelection(false, fileID); + } } - } + if (contextMenu != null) { + contextMenu.hide(); + } + final ContextMenu groupContextMenu = groupPane.getContextMenu(); + if (groupContextMenu != null) { + groupContextMenu.hide(); + } + contextMenu = buildContextMenu(file); + contextMenu.show(DrawableViewBase.this, t.getScreenX(), t.getScreenY()); + break; + } + }); - if (contextMenu != null) { - contextMenu.hide(); - } - final ContextMenu groupContextMenu = groupPane.getContextMenu(); - if (groupContextMenu != null) { - groupContextMenu.hide(); - } - contextMenu = buildContextMenu(); - contextMenu.show(DrawableViewBase.this, t.getScreenX(), t.getScreenY()); - - break; - } t.consume(); } - private ContextMenu buildContextMenu() { + private ContextMenu buildContextMenu(DrawableFile file) { final ArrayList menuItems = new ArrayList<>(); menuItems.add(new CategorizeAction(controller).getPopupMenu()); @@ -213,13 +240,13 @@ public abstract class DrawableViewBase extends AnchorPane implements DrawableVie MenuItem contentViewer = new MenuItem("Show Content Viewer"); contentViewer.setOnAction((ActionEvent t) -> { SwingUtilities.invokeLater(() -> { - new NewWindowViewAction("Show Content Viewer", new FileNode(getFile().getAbstractFile())).actionPerformed(null); + new NewWindowViewAction("Show Content Viewer", new FileNode(file.getAbstractFile())).actionPerformed(null); }); }); menuItems.add(contentViewer); MenuItem externalViewer = new MenuItem("Open in External Viewer"); - final ExternalViewerAction externalViewerAction = new ExternalViewerAction("Open in External Viewer", new FileNode(getFile().getAbstractFile())); + final ExternalViewerAction externalViewerAction = new ExternalViewerAction("Open in External Viewer", new FileNode(file.getAbstractFile())); externalViewer.setDisable(externalViewerAction.isEnabled() == false); externalViewer.setOnAction((ActionEvent t) -> { @@ -259,116 +286,106 @@ public abstract class DrawableViewBase extends AnchorPane implements DrawableVie @SuppressWarnings("deprecation") protected void initialize() { followUpToggle.setOnAction((ActionEvent event) -> { - if (followUpToggle.isSelected() == true) { - try { - final TagName followUpTagName = controller.getTagsManager().getFollowUpTagName(); - globalSelectionModel.clearAndSelect(fileID); - new AddDrawableTagAction(controller).addTag(followUpTagName, ""); - } catch (TskCoreException ex) { - LOGGER.log(Level.SEVERE, "Failed to add Follow Up tag. Could not load TagName.", ex); + getFile().ifPresent(file -> { + if (followUpToggle.isSelected() == true) { + try { + final TagName followUpTagName = controller.getTagsManager().getFollowUpTagName(); + globalSelectionModel.clearAndSelect(file.getId()); + new AddDrawableTagAction(controller).addTag(followUpTagName, ""); + } catch (TskCoreException ex) { + LOGGER.log(Level.SEVERE, "Failed to add Follow Up tag. Could not load TagName.", ex); + } + } else { + new DeleteFollowUpTagAction(controller, file).handle(event); } - } else { - new DeleteFollowUpTagAction(controller, file).handle(event); - } + }); }); } - @Override - public DrawableFile getFile() { - if (fileID != null) { - if (file == null || file.getId() != fileID) { - try { - file = ImageGalleryController.getDefault().getFileFromId(fileID); - } catch (TskCoreException ex) { - LOGGER.log(Level.WARNING, "failed to get DrawableFile for obj_id" + fileID, ex); - file = null; - } - } - return file; - } else { - return null; - } - } - - protected boolean hasFollowUp() throws TskCoreException { - String followUpTagName = getController().getTagsManager().getFollowUpTagName().getDisplayName(); - Collection tagNames = DrawableAttribute.TAGS.getValue(getFile()); - return tagNames.stream().anyMatch((tn) -> tn.getDisplayName().equals(followUpTagName)); - } - - @Override - synchronized public Long getFileID() { - return fileID; - } - - synchronized protected void updateFollowUpIcon() { - if (file != null) { + protected boolean hasFollowUp() { + if (getFile().isPresent()) { try { - boolean hasFollowUp = hasFollowUp(); - Platform.runLater(() -> { - followUpImageView.setImage(hasFollowUp ? followUpIcon : followUpGray); - followUpToggle.setSelected(hasFollowUp); - }); + TagName followUpTagName = getController().getTagsManager().getFollowUpTagName(); + Collection tagNames = DrawableAttribute.TAGS.getValue(getFile().get()); + return tagNames.stream().anyMatch((tn) -> tn.equals(followUpTagName)); } catch (TskCoreException ex) { - LOGGER.log(Level.SEVERE, "Failed to get follow up status for file.", ex); + LOGGER.log(Level.WARNING, "failed to get follow up tag name ", ex); + return true; } + } else { + return false; } } @Override - synchronized public void setFile(final Long fileID) { - if (Objects.equals(fileID, this.fileID) == false) { - this.fileID = fileID; - disposeContent(); - - if (this.fileID == null || Case.isCaseOpen() == false) { - if (registered == true) { - getController().getCategoryManager().unregisterListener(this); - getController().getTagsManager().unregisterListener(this); - registered = false; - } - file = null; - Platform.runLater(() -> { - clearContent(); - }); - } else { - if (registered == false) { - getController().getCategoryManager().registerListener(this); - getController().getTagsManager().registerListener(this); - registered = true; - } - file = null; - getFile(); - updateSelectionState(); - updateCategoryBorder(); - updateFollowUpIcon(); - updateUI(); - Platform.runLater(getContentUpdateRunnable()); + public void setFile(final Long newFileID) { + if (fileIDOpt.isPresent()) { + if (Objects.equals(newFileID, fileIDOpt.get()) == false) { + setFileHelper(newFileID); } + } else { + if (nonNull(newFileID)) { + setFileHelper(newFileID); + } + } + } + + private void setFileHelper(final Long newFileID) { + fileIDOpt = Optional.ofNullable(newFileID); + disposeContent(); + + if (fileIDOpt.isPresent() == false || Case.isCaseOpen() == false) { + if (registered == true) { + getController().getCategoryManager().unregisterListener(this); + getController().getTagsManager().unregisterListener(this); + registered = false; + } + fileOpt = Optional.empty(); + Platform.runLater(() -> { + clearContent(); + }); + } else { + if (registered == false) { + getController().getCategoryManager().registerListener(this); + getController().getTagsManager().registerListener(this); + registered = true; + } + fileOpt = Optional.empty(); + + updateSelectionState(); + updateCategoryBorder(); + updateFollowUpIcon(); + updateUI(); + Platform.runLater(getContentUpdateRunnable()); } } private void updateUI() { - final boolean isVideo = getFile().isVideo(); - final boolean hasHashSetHits = hasHashHit(); - final String text = getTextForLabel(); + getFile().ifPresent(file -> { + final boolean isVideo = file.isVideo(); + final boolean hasHashSetHits = hasHashHit(); + final String text = getTextForLabel(); - Platform.runLater(() -> { - fileTypeImageView.setImage(isVideo ? videoIcon : null); - hashHitImageView.setImage(hasHashSetHits ? hashHitIcon : null); - nameLabel.setText(text); - nameLabel.setTooltip(new Tooltip(text)); + Platform.runLater(() -> { + fileTypeImageView.setImage(isVideo ? videoIcon : null); + hashHitImageView.setImage(hasHashSetHits ? hashHitIcon : null); + nameLabel.setText(text); + nameLabel.setTooltip(new Tooltip(text)); + }); }); + } /** * update the visual representation of the selection state of this * DrawableView */ - synchronized protected void updateSelectionState() { - final boolean selected = globalSelectionModel.isSelected(getFileID()); - Platform.runLater(() -> { - setBorder(selected ? SELECTED_BORDER : UNSELECTED_BORDER); + protected void updateSelectionState() { + getFile().ifPresent(file -> { + final boolean selected = globalSelectionModel.isSelected(file.getId()); + Platform.runLater(() -> { + setBorder(selected ? SELECTED_BORDER : UNSELECTED_BORDER); + }); }); } @@ -380,22 +397,54 @@ public abstract class DrawableViewBase extends AnchorPane implements DrawableVie @Subscribe @Override public void handleTagAdded(ContentTagAddedEvent evt) { + fileIDOpt.ifPresent(fileID -> { + try { + if (fileID == evt.getAddedTag().getContent().getId() + && evt.getAddedTag().getName() == getController().getTagsManager().getFollowUpTagName()) { - updateFollowUpIcon(); + Platform.runLater(() -> { + followUpImageView.setImage(followUpIcon); + followUpToggle.setSelected(true); + }); + } + } catch (TskCoreException ex) { + LOGGER.log(Level.SEVERE, "Failed to get follow up status for file.", ex); + } + }); } @Subscribe @Override public void handleTagDeleted(ContentTagDeletedEvent evt) { - updateFollowUpIcon(); + + fileIDOpt.ifPresent(fileID -> { + try { + if (fileID == evt.getDeletedTag().getContent().getId() + && evt.getDeletedTag().getName() == controller.getTagsManager().getFollowUpTagName()) { + updateFollowUpIcon(); + } + } catch (TskCoreException ex) { + LOGGER.log(Level.SEVERE, "Failed to get follow up status for file.", ex); + } + }); + } + + private void updateFollowUpIcon() { + boolean hasFollowUp = hasFollowUp(); + Platform.runLater(() -> { + followUpImageView.setImage(hasFollowUp ? followUpIcon : followUpGray); + followUpToggle.setSelected(hasFollowUp); + }); } @Subscribe @Override - synchronized public void handleCategoryChanged(CategoryChangeEvent evt) { - if (fileID != null && evt.getFileIDs().contains(getFileID())) { - updateCategoryBorder(); - } + public void handleCategoryChanged(CategoryChangeEvent evt) { + fileIDOpt.ifPresent(fileID -> { + if (evt.getFileIDs().contains(fileID)) { + updateCategoryBorder(); + } + }); } @Override diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/MetaDataPane.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/MetaDataPane.java index 0681d29eb9..87bd64491f 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/MetaDataPane.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/MetaDataPane.java @@ -22,6 +22,9 @@ import com.google.common.eventbus.Subscribe; import java.io.IOException; import java.util.Arrays; import java.util.Collection; +import java.util.Objects; +import static java.util.Objects.nonNull; +import java.util.Optional; import java.util.logging.Level; import java.util.stream.Collectors; import javafx.application.Platform; @@ -68,8 +71,6 @@ public class MetaDataPane extends AnchorPane implements DrawableView { return controller; } - private Long fileID; - @FXML private ImageView imageView; @@ -85,13 +86,6 @@ public class MetaDataPane extends AnchorPane implements DrawableView { @FXML private BorderPane imageBorder; - private DrawableFile file; - - @Override - public Long getFileID() { - return fileID; - } - @FXML @SuppressWarnings("unchecked") void initialize() { @@ -152,29 +146,52 @@ public class MetaDataPane extends AnchorPane implements DrawableView { }); } + volatile private Optional> fileOpt = Optional.empty(); + + volatile private Optional fileIDOpt = Optional.empty(); + @Override - public DrawableFile getFile() { - if (fileID != null) { - if (file == null || file.getId() != fileID) { - try { - file = controller.getFileFromId(fileID); - } catch (TskCoreException ex) { - LOGGER.log(Level.WARNING, "failed to get DrawableFile for obj_id" + fileID, ex); - return null; - } - } - } else { - return null; - } - return file; + public Optional getFileID() { + return fileIDOpt; } @Override - public void setFile(Long fileID) { - this.fileID = fileID; + public Optional> getFile() { + if (fileIDOpt.isPresent()) { + if (fileOpt.isPresent() && fileOpt.get().getId() == fileIDOpt.get()) { + return fileOpt; + } else { + try { + fileOpt = Optional.of(ImageGalleryController.getDefault().getFileFromId(fileIDOpt.get())); + } catch (TskCoreException ex) { + Logger.getAnonymousLogger().log(Level.WARNING, "failed to get DrawableFile for obj_id" + fileIDOpt.get(), ex); + fileOpt = Optional.empty(); + } + return fileOpt; + } + } else { + return Optional.empty(); + } + } - if (fileID == null) { + @Override + public void setFile(Long newFileID) { + if (fileIDOpt.isPresent()) { + if (Objects.equals(newFileID, fileIDOpt.get()) == false) { + setFileHelper(newFileID); + } + } else { + if (nonNull(newFileID)) { + setFileHelper(newFileID); + } + } + setFileHelper(newFileID); + } + + private void setFileHelper(Long newFileID) { + fileIDOpt = Optional.of(newFileID); + if (newFileID == null) { Platform.runLater(() -> { imageView.setImage(null); tableView.getItems().clear(); @@ -182,12 +199,7 @@ public class MetaDataPane extends AnchorPane implements DrawableView { }); } else { - try { - file = controller.getFileFromId(fileID); - updateUI(); - } catch (TskCoreException ex) { - LOGGER.log(Level.WARNING, "Failed to get drawable file from ID", ex); - } + updateUI(); } } @@ -206,15 +218,18 @@ public class MetaDataPane extends AnchorPane implements DrawableView { } public void updateUI() { - final Image icon = getFile().getThumbnail(); - final ObservableList, ? extends Object>> attributesList = getFile().getAttributesList(); + getFile().ifPresent(file -> { + final Image icon = file.getThumbnail(); + final ObservableList, ? extends Object>> attributesList = file.getAttributesList(); - Platform.runLater(() -> { - imageView.setImage(icon); - tableView.getItems().setAll(attributesList); + Platform.runLater(() -> { + imageView.setImage(icon); + tableView.getItems().setAll(attributesList); + }); + + updateCategoryBorder(); }); - updateCategoryBorder(); } @Override @@ -226,23 +241,28 @@ public class MetaDataPane extends AnchorPane implements DrawableView { @Subscribe @Override public void handleCategoryChanged(CategoryChangeEvent evt) { - if (getFile() != null && evt.getFileIDs().contains(getFileID())) { - updateUI(); - } + getFileID().ifPresent(fileID -> { + if (evt.getFileIDs().contains(fileID)) { + updateUI(); + } + }); } @Override public void handleTagAdded(ContentTagAddedEvent evt) { - if (getFile() != null && evt.getAddedTag().getContent().getId() == getFileID()) { - updateUI(); - } + handleTagChanged(evt.getAddedTag().getContent().getId()); } @Override public void handleTagDeleted(ContentTagDeletedEvent evt) { - if (getFile() != null && evt.getDeletedTag().getContent().getId() == getFileID()) { - updateUI(); - } + handleTagChanged(evt.getDeletedTag().getContent().getId()); } + private void handleTagChanged(Long tagFileID) { + getFileID().ifPresent(fileID -> { + if (Objects.equals(tagFileID, fileID)) { + updateUI(); + } + }); + } } diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/SlideShowView.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/SlideShowView.java index 7977eb0219..ab74554b39 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/SlideShowView.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/SlideShowView.java @@ -19,6 +19,7 @@ package org.sleuthkit.autopsy.imagegallery.gui; import java.util.ArrayList; +import java.util.function.Function; import java.util.logging.Level; import javafx.application.Platform; import javafx.beans.Observable; @@ -48,14 +49,15 @@ import org.openide.util.Exceptions; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.coreutils.ThreadConfined; import org.sleuthkit.autopsy.coreutils.ThreadConfined.ThreadType; -import org.sleuthkit.autopsy.imagegallery.DrawableTagsManager; import org.sleuthkit.autopsy.imagegallery.FXMLConstructor; import org.sleuthkit.autopsy.imagegallery.FileIDSelectionModel; import org.sleuthkit.autopsy.imagegallery.actions.CategorizeAction; import org.sleuthkit.autopsy.imagegallery.datamodel.Category; import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableAttribute; +import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableFile; import org.sleuthkit.autopsy.imagegallery.datamodel.ImageFile; import org.sleuthkit.autopsy.imagegallery.datamodel.VideoFile; +import static org.sleuthkit.autopsy.imagegallery.gui.DrawableView.CAT_BORDER_WIDTH; import static org.sleuthkit.autopsy.imagegallery.gui.DrawableView.HASH_BORDER; import static org.sleuthkit.autopsy.imagegallery.gui.DrawableView.getCategoryBorder; import org.sleuthkit.datamodel.TagName; @@ -235,9 +237,9 @@ public class SlideShowView extends DrawableViewBase { @Override synchronized public void setFile(final Long fileID) { super.setFile(fileID); - if (this.getFileID() != null) { - getGroupPane().makeSelection(false, this.getFileID()); - } + getFileID().ifPresent((Long id) -> { + getGroupPane().makeSelection(false, id); + }); } @Override @@ -254,24 +256,33 @@ public class SlideShowView extends DrawableViewBase { @Override protected Runnable getContentUpdateRunnable() { - if (getFile().isVideo()) { - return () -> { - imageBorder.setCenter(MediaControl.create((VideoFile) getFile())); - }; - } else { - ImageView imageView = new ImageView(((ImageFile) getFile()).getFullSizeImage()); - imageView.setPreserveRatio(true); - imageView.fitWidthProperty().bind(imageBorder.widthProperty().subtract(CAT_BORDER_WIDTH * 2)); - imageView.fitHeightProperty().bind(this.heightProperty().subtract(CAT_BORDER_WIDTH * 4).subtract(footer.heightProperty()).subtract(toolBar.heightProperty())); - return () -> { - imageBorder.setCenter(imageView); - }; - } + + return getFile().map(new Function, Runnable>() { + + @Override + public Runnable apply(DrawableFile file) { + + if (file.isVideo()) { + return () -> { + imageBorder.setCenter(MediaControl.create((VideoFile) file)); + }; + } else { + ImageView imageView = new ImageView(((ImageFile) file).getFullSizeImage()); + imageView.setPreserveRatio(true); + imageView.fitWidthProperty().bind(imageBorder.widthProperty().subtract(CAT_BORDER_WIDTH * 2)); + imageView.fitHeightProperty().bind(heightProperty().subtract(CAT_BORDER_WIDTH * 4).subtract(footer.heightProperty()).subtract(toolBar.heightProperty())); + return () -> { + imageBorder.setCenter(imageView); + }; + } + } + }).orElse(() -> { + }); } @Override protected String getTextForLabel() { - return getFile().getName() + " " + getSupplementalText(); + return getFile().map(file -> file.getName() + " " + getSupplementalText()).orElse(""); } @ThreadConfined(type = ThreadType.JFX) @@ -302,18 +313,19 @@ public class SlideShowView extends DrawableViewBase { @Override @ThreadConfined(type = ThreadType.ANY) public Category updateCategoryBorder() { - final Category category = getFile().getCategory(); - final Border border = hasHashHit() && (category == Category.ZERO) - ? HASH_BORDER - : getCategoryBorder(category); - ToggleButton toggleForCategory = getToggleForCategory(category); + return getFile().map(file -> { + final Category category = file.getCategory(); + final Border border1 = hasHashHit() && (category == Category.ZERO) + ? HASH_BORDER + : getCategoryBorder(category); + ToggleButton toggleForCategory = getToggleForCategory(category); + Platform.runLater(() -> { + getCategoryBorderRegion().setBorder(border1); + toggleForCategory.setSelected(true); + }); + return category; + }).orElse(Category.ZERO); - Platform.runLater(() -> { - getCategoryBorderRegion().setBorder(border); - toggleForCategory.setSelected(true); - }); - - return category; } private ToggleButton getToggleForCategory(Category category) { @@ -345,10 +357,13 @@ public class SlideShowView extends DrawableViewBase { @Override public void changed(ObservableValue ov, Boolean t, Boolean t1) { - if (t1) { - FileIDSelectionModel.getInstance().clearAndSelect(getFileID()); - new CategorizeAction(getController()).addTag(getController().getTagsManager().getTagName(cat), ""); - } + getFileID().ifPresent(fileID -> { + if (t1) { + FileIDSelectionModel.getInstance().clearAndSelect(fileID); + new CategorizeAction(getController()).addTag(getController().getTagsManager().getTagName(cat), ""); + } + }); + } } } From f1000486b79557d475334435a62e92d858d6344c Mon Sep 17 00:00:00 2001 From: jmillman Date: Mon, 22 Jun 2015 13:33:07 -0400 Subject: [PATCH 18/56] fix bugs updating tags/categpries in slideshowview and metadata pane make new abstract base calss DrawableUIBase and move fileid and file object access to it. --- .../actions/DeleteFollowUpTagAction.java | 2 - .../datamodel/CategoryManager.java | 4 +- .../imagegallery/gui/DrawableTile.java | 7 +- ...bleViewBase.java => DrawableTileBase.java} | 121 +++++------------- .../imagegallery/gui/DrawableUIBase.java | 97 ++++++++++++++ .../imagegallery/gui/DrawableView.java | 18 +-- .../imagegallery/gui/MetaDataPane.java | 70 ++-------- .../imagegallery/gui/SlideShowView.java | 23 ++-- 8 files changed, 161 insertions(+), 181 deletions(-) rename ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/{DrawableViewBase.java => DrawableTileBase.java} (79%) create mode 100644 ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableUIBase.java diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/DeleteFollowUpTagAction.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/DeleteFollowUpTagAction.java index 74082fcd1c..934a3fb258 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/DeleteFollowUpTagAction.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/DeleteFollowUpTagAction.java @@ -37,11 +37,9 @@ import org.sleuthkit.datamodel.TskCoreException; public class DeleteFollowUpTagAction extends Action { private static final Logger LOGGER = Logger.getLogger(DeleteFollowUpTagAction.class.getName()); - private final long fileID; public DeleteFollowUpTagAction(final ImageGalleryController controller, final DrawableFile file) { super("Delete Follow Up Tag"); - this.fileID = file.getId(); setEventHandler((ActionEvent t) -> { new SwingWorker() { diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/CategoryManager.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/CategoryManager.java index 466278f588..4d2591aa1e 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/CategoryManager.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/CategoryManager.java @@ -251,7 +251,7 @@ public class CategoryManager { incrementCategoryCount(newCat); } - fireChange(Collections.singleton(addedTag.getId()), newCat); + fireChange(Collections.singleton(addedTag.getContent().getId()), newCat); } } @Subscribe @@ -263,7 +263,7 @@ public class CategoryManager { if (deletedCat != Category.ZERO) { decrementCategoryCount(deletedCat); } - fireChange(Collections.singleton(deleted.getId()), null); + fireChange(Collections.singleton(deleted.getContent().getId()), null); } } } diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableTile.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableTile.java index 96f05dd9c1..86a0b2ddee 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableTile.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableTile.java @@ -32,7 +32,7 @@ import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.coreutils.ThreadConfined; import org.sleuthkit.autopsy.coreutils.ThreadConfined.ThreadType; import org.sleuthkit.autopsy.imagegallery.FXMLConstructor; -import static org.sleuthkit.autopsy.imagegallery.gui.DrawableViewBase.globalSelectionModel; +import static org.sleuthkit.autopsy.imagegallery.gui.DrawableTileBase.globalSelectionModel; import org.sleuthkit.datamodel.AbstractContent; /** @@ -43,7 +43,7 @@ import org.sleuthkit.datamodel.AbstractContent; * * TODO: refactor this to extend from {@link Control}? -jm */ -public class DrawableTile extends DrawableViewBase { +public class DrawableTile extends DrawableTileBase { private static final DropShadow LAST_SELECTED_EFFECT = new DropShadow(10, Color.BLUE); @@ -67,7 +67,6 @@ public class DrawableTile extends DrawableViewBase { assert imageBorder != null : "fx:id=\"imageAnchor\" was not injected: check your FXML file 'DrawableTile.fxml'."; assert imageView != null : "fx:id=\"imageView\" was not injected: check your FXML file 'DrawableTile.fxml'."; assert nameLabel != null : "fx:id=\"nameLabel\" was not injected: check your FXML file 'DrawableTile.fxml'."; - //set up properties and binding setCache(true); setCacheHint(CacheHint.SPEED); @@ -87,9 +86,11 @@ public class DrawableTile extends DrawableViewBase { public DrawableTile(GroupPane gp) { super(gp); + FXMLConstructor.construct(this, "DrawableTile.fxml"); } + @Override @ThreadConfined(type = ThreadType.JFX) protected void clearContent() { diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableViewBase.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableTileBase.java similarity index 79% rename from ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableViewBase.java rename to ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableTileBase.java index a1ee32a108..80c73b1ae9 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableViewBase.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableTileBase.java @@ -22,8 +22,6 @@ package org.sleuthkit.autopsy.imagegallery.gui; import com.google.common.eventbus.Subscribe; import java.util.ArrayList; import java.util.Collection; -import java.util.Objects; -import static java.util.Objects.nonNull; import java.util.Optional; import java.util.logging.Level; import javafx.application.Platform; @@ -39,7 +37,6 @@ import javafx.scene.control.Tooltip; import javafx.scene.image.Image; import javafx.scene.image.ImageView; import javafx.scene.input.MouseEvent; -import javafx.scene.layout.AnchorPane; import javafx.scene.layout.Border; import javafx.scene.layout.BorderPane; import javafx.scene.layout.BorderStroke; @@ -66,13 +63,11 @@ import org.sleuthkit.autopsy.directorytree.NewWindowViewAction; import org.sleuthkit.autopsy.events.ContentTagAddedEvent; import org.sleuthkit.autopsy.events.ContentTagDeletedEvent; import org.sleuthkit.autopsy.imagegallery.FileIDSelectionModel; -import org.sleuthkit.autopsy.imagegallery.ImageGalleryController; import org.sleuthkit.autopsy.imagegallery.ImageGalleryTopComponent; import org.sleuthkit.autopsy.imagegallery.actions.AddDrawableTagAction; import org.sleuthkit.autopsy.imagegallery.actions.CategorizeAction; import org.sleuthkit.autopsy.imagegallery.actions.DeleteFollowUpTagAction; import org.sleuthkit.autopsy.imagegallery.actions.SwingMenuItemAdapter; -import org.sleuthkit.autopsy.imagegallery.datamodel.CategoryChangeEvent; import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableAttribute; import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableFile; import org.sleuthkit.datamodel.TagName; @@ -84,9 +79,9 @@ import org.sleuthkit.datamodel.TskCoreException; * of {@link DrawableView}s should implement the interface directly * */ -public abstract class DrawableViewBase extends AnchorPane implements DrawableView { +public abstract class DrawableTileBase extends DrawableUIBase { - private static final Logger LOGGER = Logger.getLogger(DrawableViewBase.class.getName()); + private static final Logger LOGGER = Logger.getLogger(DrawableTileBase.class.getName()); private static final Border UNSELECTED_BORDER = new Border(new BorderStroke(Color.GRAY, BorderStrokeStyle.SOLID, new CornerRadii(2), new BorderWidths(3))); @@ -99,6 +94,7 @@ public abstract class DrawableViewBase extends AnchorPane implements DrawableVie protected static final Image followUpGray = new Image("org/sleuthkit/autopsy/imagegallery/images/flag_gray.png"); protected static final FileIDSelectionModel globalSelectionModel = FileIDSelectionModel.getInstance(); + private static ContextMenu contextMenu; /** * displays the icon representing video files @@ -130,50 +126,16 @@ public abstract class DrawableViewBase extends AnchorPane implements DrawableVie @FXML protected BorderPane imageBorder; - static private ContextMenu contextMenu; - - volatile private Optional> fileOpt = Optional.empty(); - - volatile private Optional fileIDOpt = Optional.empty(); - - @Override - public Optional getFileID() { - return fileIDOpt; - } - - @Override - public Optional> getFile() { - if (fileIDOpt.isPresent()) { - if (fileOpt.isPresent() && fileOpt.get().getId() == fileIDOpt.get()) { - return fileOpt; - } else { - try { - fileOpt = Optional.of(ImageGalleryController.getDefault().getFileFromId(fileIDOpt.get())); - } catch (TskCoreException ex) { - Logger.getAnonymousLogger().log(Level.WARNING, "failed to get DrawableFile for obj_id" + fileIDOpt.get(), ex); - fileOpt = Optional.empty(); - } - return fileOpt; - } - } else { - return Optional.empty(); - } - } - /** - * the groupPane this {@link DrawableViewBase} is embedded in + * the groupPane this {@link DrawableTileBase} is embedded in */ final private GroupPane groupPane; - private boolean registered = false; - private final ImageGalleryController controller; + volatile private boolean registered = false; - GroupPane getGroupPane() { - return groupPane; - } + protected DrawableTileBase(GroupPane groupPane) { + super(groupPane.getController()); - protected DrawableViewBase(GroupPane groupPane) { this.groupPane = groupPane; - this.controller = groupPane.getController(); globalSelectionModel.getSelected().addListener((Observable observable) -> { updateSelectionState(); }); @@ -213,7 +175,7 @@ public abstract class DrawableViewBase extends AnchorPane implements DrawableVie groupContextMenu.hide(); } contextMenu = buildContextMenu(file); - contextMenu.show(DrawableViewBase.this, t.getScreenX(), t.getScreenY()); + contextMenu.show(DrawableTileBase.this, t.getScreenX(), t.getScreenY()); break; } }); @@ -224,9 +186,9 @@ public abstract class DrawableViewBase extends AnchorPane implements DrawableVie private ContextMenu buildContextMenu(DrawableFile file) { final ArrayList menuItems = new ArrayList<>(); - menuItems.add(new CategorizeAction(controller).getPopupMenu()); + menuItems.add(new CategorizeAction(getController()).getPopupMenu()); - menuItems.add(new AddDrawableTagAction(controller).getPopupMenu()); + menuItems.add(new AddDrawableTagAction(getController()).getPopupMenu()); final MenuItem extractMenuItem = new MenuItem("Extract File(s)"); extractMenuItem.setOnAction((ActionEvent t) -> { @@ -274,6 +236,10 @@ public abstract class DrawableViewBase extends AnchorPane implements DrawableVie }); } + GroupPane getGroupPane() { + return groupPane; + } + @ThreadConfined(type = ThreadType.UI) protected abstract void clearContent(); @@ -283,31 +249,29 @@ public abstract class DrawableViewBase extends AnchorPane implements DrawableVie protected abstract String getTextForLabel(); - @SuppressWarnings("deprecation") protected void initialize() { followUpToggle.setOnAction((ActionEvent event) -> { getFile().ifPresent(file -> { if (followUpToggle.isSelected() == true) { try { - final TagName followUpTagName = controller.getTagsManager().getFollowUpTagName(); globalSelectionModel.clearAndSelect(file.getId()); - new AddDrawableTagAction(controller).addTag(followUpTagName, ""); + new AddDrawableTagAction(getController()).addTag(getController().getTagsManager().getFollowUpTagName(), ""); } catch (TskCoreException ex) { LOGGER.log(Level.SEVERE, "Failed to add Follow Up tag. Could not load TagName.", ex); } } else { - new DeleteFollowUpTagAction(controller, file).handle(event); + new DeleteFollowUpTagAction(getController(), file).handle(event); } }); }); } protected boolean hasFollowUp() { - if (getFile().isPresent()) { + if (getFileID().isPresent()) { try { TagName followUpTagName = getController().getTagsManager().getFollowUpTagName(); - Collection tagNames = DrawableAttribute.TAGS.getValue(getFile().get()); - return tagNames.stream().anyMatch((tn) -> tn.equals(followUpTagName)); + return DrawableAttribute.TAGS.getValue(getFile().get()).stream() + .anyMatch(followUpTagName::equals); } catch (TskCoreException ex) { LOGGER.log(Level.WARNING, "failed to get follow up tag name ", ex); return true; @@ -318,29 +282,17 @@ public abstract class DrawableViewBase extends AnchorPane implements DrawableVie } @Override - public void setFile(final Long newFileID) { - if (fileIDOpt.isPresent()) { - if (Objects.equals(newFileID, fileIDOpt.get()) == false) { - setFileHelper(newFileID); - } - } else { - if (nonNull(newFileID)) { - setFileHelper(newFileID); - } - } - } - - private void setFileHelper(final Long newFileID) { - fileIDOpt = Optional.ofNullable(newFileID); + protected void setFileHelper(final Long newFileID) { + setFileIDOpt(Optional.ofNullable(newFileID)); disposeContent(); - if (fileIDOpt.isPresent() == false || Case.isCaseOpen() == false) { + if (getFileID().isPresent() == false || Case.isCaseOpen() == false) { if (registered == true) { getController().getCategoryManager().unregisterListener(this); getController().getTagsManager().unregisterListener(this); registered = false; } - fileOpt = Optional.empty(); + setFileOpt(Optional.empty()); Platform.runLater(() -> { clearContent(); }); @@ -350,10 +302,10 @@ public abstract class DrawableViewBase extends AnchorPane implements DrawableVie getController().getTagsManager().registerListener(this); registered = true; } - fileOpt = Optional.empty(); + setFileOpt(Optional.empty()); updateSelectionState(); - updateCategoryBorder(); + updateCategory(); updateFollowUpIcon(); updateUI(); Platform.runLater(getContentUpdateRunnable()); @@ -397,10 +349,10 @@ public abstract class DrawableViewBase extends AnchorPane implements DrawableVie @Subscribe @Override public void handleTagAdded(ContentTagAddedEvent evt) { - fileIDOpt.ifPresent(fileID -> { + getFileID().ifPresent(fileID -> { try { if (fileID == evt.getAddedTag().getContent().getId() - && evt.getAddedTag().getName() == getController().getTagsManager().getFollowUpTagName()) { + && evt.getAddedTag().getName().equals(getController().getTagsManager().getFollowUpTagName())) { Platform.runLater(() -> { followUpImageView.setImage(followUpIcon); @@ -417,10 +369,10 @@ public abstract class DrawableViewBase extends AnchorPane implements DrawableVie @Override public void handleTagDeleted(ContentTagDeletedEvent evt) { - fileIDOpt.ifPresent(fileID -> { + getFileID().ifPresent(fileID -> { try { if (fileID == evt.getDeletedTag().getContent().getId() - && evt.getDeletedTag().getName() == controller.getTagsManager().getFollowUpTagName()) { + && evt.getDeletedTag().getName().equals(getController().getTagsManager().getFollowUpTagName())) { updateFollowUpIcon(); } } catch (TskCoreException ex) { @@ -436,19 +388,4 @@ public abstract class DrawableViewBase extends AnchorPane implements DrawableVie followUpToggle.setSelected(hasFollowUp); }); } - - @Subscribe - @Override - public void handleCategoryChanged(CategoryChangeEvent evt) { - fileIDOpt.ifPresent(fileID -> { - if (evt.getFileIDs().contains(fileID)) { - updateCategoryBorder(); - } - }); - } - - @Override - public ImageGalleryController getController() { - return controller; - } } diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableUIBase.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableUIBase.java new file mode 100644 index 0000000000..ec794eabae --- /dev/null +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableUIBase.java @@ -0,0 +1,97 @@ +/* + * Autopsy Forensic Browser + * + * Copyright 2015 Basis Technology Corp. + * Contact: carrier sleuthkit org + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.sleuthkit.autopsy.imagegallery.gui; + +import java.util.Objects; +import static java.util.Objects.nonNull; +import java.util.Optional; +import java.util.logging.Level; +import javafx.scene.layout.AnchorPane; +import org.sleuthkit.autopsy.coreutils.Logger; +import org.sleuthkit.autopsy.imagegallery.ImageGalleryController; +import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableFile; +import org.sleuthkit.datamodel.TskCoreException; + +/** + * + */ +abstract public class DrawableUIBase extends AnchorPane implements DrawableView { + + private final ImageGalleryController controller; + + volatile private Optional> fileOpt = Optional.empty(); + + volatile private Optional fileIDOpt = Optional.empty(); + + public DrawableUIBase(ImageGalleryController controller) { + this.controller = controller; + } + + @Override + public ImageGalleryController getController() { + return controller; + } + + @Override + public Optional getFileID() { + return fileIDOpt; + } + + void setFileIDOpt(Optional fileIDOpt) { + this.fileIDOpt = fileIDOpt; + } + + void setFileOpt(Optional> fileOpt) { + this.fileOpt = fileOpt; + } + + @Override + public Optional> getFile() { + if (fileIDOpt.isPresent()) { + if (fileOpt.isPresent() && fileOpt.get().getId() == fileIDOpt.get()) { + return fileOpt; + } else { + try { + fileOpt = Optional.of(getController().getFileFromId(fileIDOpt.get())); + } catch (TskCoreException ex) { + Logger.getAnonymousLogger().log(Level.WARNING, "failed to get DrawableFile for obj_id" + fileIDOpt.get(), ex); + fileOpt = Optional.empty(); + } + return fileOpt; + } + } else { + return Optional.empty(); + } + } + + protected abstract void setFileHelper(Long newFileID); + + @Override + public void setFile(Long newFileID) { + if (getFileID().isPresent()) { + if (Objects.equals(newFileID, getFileID().get()) == false) { + setFileHelper(newFileID); + } + } else if (nonNull(newFileID)) { + setFileHelper(newFileID); + } + } + + +} diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableView.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableView.java index e4e6faf1de..709679173e 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableView.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableView.java @@ -68,7 +68,13 @@ public interface DrawableView { * @param evt the CategoryChangeEvent to handle */ @Subscribe - void handleCategoryChanged(CategoryChangeEvent evt); + default void handleCategoryChanged(CategoryChangeEvent evt) { + getFileID().ifPresent(fileID -> { + if (evt.getFileIDs().contains(fileID)) { + updateCategory(); + } + }); + } @Subscribe void handleTagAdded(ContentTagAddedEvent evt); @@ -116,16 +122,12 @@ public interface DrawableView { } @ThreadConfined(type = ThreadConfined.ThreadType.ANY) - default Category updateCategoryBorder() { - if (getFile() != null) { + default Category updateCategory() { + if (getFile().isPresent()) { final Category category = getFile().map(DrawableFile::getCategory).orElse(Category.ZERO); - final Border border = hasHashHit() && (category == Category.ZERO) - ? HASH_BORDER - : getCategoryBorder(category); - + final Border border = hasHashHit() && (category == Category.ZERO) ? HASH_BORDER : getCategoryBorder(category); Platform.runLater(() -> { getCategoryBorderRegion().setBorder(border); - getCategoryBorderRegion().requestLayout(); }); return category; } else { diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/MetaDataPane.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/MetaDataPane.java index 87bd64491f..d89db4116c 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/MetaDataPane.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/MetaDataPane.java @@ -23,9 +23,7 @@ import java.io.IOException; import java.util.Arrays; import java.util.Collection; import java.util.Objects; -import static java.util.Objects.nonNull; import java.util.Optional; -import java.util.logging.Level; import java.util.stream.Collectors; import javafx.application.Platform; import javafx.beans.property.SimpleObjectProperty; @@ -39,7 +37,6 @@ import javafx.scene.control.TableColumn; import javafx.scene.control.TableView; import javafx.scene.image.Image; import javafx.scene.image.ImageView; -import javafx.scene.layout.AnchorPane; import javafx.scene.layout.BorderPane; import javafx.scene.layout.Region; import static javafx.scene.layout.Region.USE_COMPUTED_SIZE; @@ -53,24 +50,15 @@ import org.sleuthkit.autopsy.imagegallery.ImageGalleryController; import org.sleuthkit.autopsy.imagegallery.datamodel.Category; import org.sleuthkit.autopsy.imagegallery.datamodel.CategoryChangeEvent; import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableAttribute; -import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableFile; import org.sleuthkit.datamodel.TagName; -import org.sleuthkit.datamodel.TskCoreException; /** * Shows details of the selected file. */ -public class MetaDataPane extends AnchorPane implements DrawableView { +public class MetaDataPane extends DrawableUIBase { private static final Logger LOGGER = Logger.getLogger(MetaDataPane.class.getName()); - private final ImageGalleryController controller; - - @Override - public ImageGalleryController getController() { - return controller; - } - @FXML private ImageView imageView; @@ -141,56 +129,14 @@ public class MetaDataPane extends AnchorPane implements DrawableView { tableView.getColumns().setAll(Arrays.asList(attributeColumn, valueColumn)); //listen for selection change - controller.getSelectionModel().lastSelectedProperty().addListener((observable, oldFileID, newFileID) -> { + getController().getSelectionModel().lastSelectedProperty().addListener((observable, oldFileID, newFileID) -> { setFile(newFileID); }); } - volatile private Optional> fileOpt = Optional.empty(); - - volatile private Optional fileIDOpt = Optional.empty(); - @Override - public Optional getFileID() { - return fileIDOpt; - } - - @Override - public Optional> getFile() { - if (fileIDOpt.isPresent()) { - if (fileOpt.isPresent() && fileOpt.get().getId() == fileIDOpt.get()) { - return fileOpt; - } else { - try { - fileOpt = Optional.of(ImageGalleryController.getDefault().getFileFromId(fileIDOpt.get())); - } catch (TskCoreException ex) { - Logger.getAnonymousLogger().log(Level.WARNING, "failed to get DrawableFile for obj_id" + fileIDOpt.get(), ex); - fileOpt = Optional.empty(); - } - return fileOpt; - } - } else { - return Optional.empty(); - } - } - - @Override - public void setFile(Long newFileID) { - - if (fileIDOpt.isPresent()) { - if (Objects.equals(newFileID, fileIDOpt.get()) == false) { - setFileHelper(newFileID); - } - } else { - if (nonNull(newFileID)) { - setFileHelper(newFileID); - } - } - setFileHelper(newFileID); - } - - private void setFileHelper(Long newFileID) { - fileIDOpt = Optional.of(newFileID); + synchronized protected void setFileHelper(Long newFileID) { + setFileIDOpt(Optional.ofNullable(newFileID)); if (newFileID == null) { Platform.runLater(() -> { imageView.setImage(null); @@ -204,7 +150,7 @@ public class MetaDataPane extends AnchorPane implements DrawableView { } public MetaDataPane(ImageGalleryController controller) { - this.controller = controller; + super(controller); FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("MetaDataPane.fxml")); fxmlLoader.setRoot(this); @@ -224,12 +170,12 @@ public class MetaDataPane extends AnchorPane implements DrawableView { Platform.runLater(() -> { imageView.setImage(icon); + tableView.getItems().clear(); tableView.getItems().setAll(attributesList); }); - updateCategoryBorder(); + updateCategory(); }); - } @Override @@ -248,11 +194,13 @@ public class MetaDataPane extends AnchorPane implements DrawableView { }); } + @Subscribe @Override public void handleTagAdded(ContentTagAddedEvent evt) { handleTagChanged(evt.getAddedTag().getContent().getId()); } + @Subscribe @Override public void handleTagDeleted(ContentTagDeletedEvent evt) { handleTagChanged(evt.getDeletedTag().getContent().getId()); diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/SlideShowView.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/SlideShowView.java index ab74554b39..99944d6d19 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/SlideShowView.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/SlideShowView.java @@ -58,8 +58,6 @@ import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableFile; import org.sleuthkit.autopsy.imagegallery.datamodel.ImageFile; import org.sleuthkit.autopsy.imagegallery.datamodel.VideoFile; import static org.sleuthkit.autopsy.imagegallery.gui.DrawableView.CAT_BORDER_WIDTH; -import static org.sleuthkit.autopsy.imagegallery.gui.DrawableView.HASH_BORDER; -import static org.sleuthkit.autopsy.imagegallery.gui.DrawableView.getCategoryBorder; import org.sleuthkit.datamodel.TagName; import org.sleuthkit.datamodel.TskCoreException; @@ -68,7 +66,7 @@ import org.sleuthkit.datamodel.TskCoreException; * GroupPane. TODO: Extract a subclass for video files in slideshow mode-jm * TODO: reduce coupling to GroupPane */ -public class SlideShowView extends DrawableViewBase { +public class SlideShowView extends DrawableTileBase { private static final Logger LOGGER = Logger.getLogger(SlideShowView.class.getName()); @@ -223,6 +221,7 @@ public class SlideShowView extends DrawableViewBase { SlideShowView(GroupPane gp) { super(gp); + FXMLConstructor.construct(this, "SlideShow.fxml"); } @@ -237,6 +236,7 @@ public class SlideShowView extends DrawableViewBase { @Override synchronized public void setFile(final Long fileID) { super.setFile(fileID); + getFileID().ifPresent((Long id) -> { getGroupPane().makeSelection(false, id); }); @@ -288,7 +288,7 @@ public class SlideShowView extends DrawableViewBase { @ThreadConfined(type = ThreadType.JFX) private void cycleSlideShowImage(int d) { stopVideo(); - if (getFileID() != null) { + if (getFileID().isPresent()) { int index = getGroupPane().getGrouping().fileIds().indexOf(getFileID()); final int size = getGroupPane().getGrouping().fileIds().size(); index = (index + d) % size; @@ -312,20 +312,17 @@ public class SlideShowView extends DrawableViewBase { @Override @ThreadConfined(type = ThreadType.ANY) - public Category updateCategoryBorder() { - return getFile().map(file -> { - final Category category = file.getCategory(); - final Border border1 = hasHashHit() && (category == Category.ZERO) - ? HASH_BORDER - : getCategoryBorder(category); + public Category updateCategory() { + if (getFile().isPresent()) { + final Category category = super.updateCategory(); ToggleButton toggleForCategory = getToggleForCategory(category); Platform.runLater(() -> { - getCategoryBorderRegion().setBorder(border1); toggleForCategory.setSelected(true); }); return category; - }).orElse(Category.ZERO); - + } else { + return Category.ZERO; + } } private ToggleButton getToggleForCategory(Category category) { From 6fa5b3b14c6e7f443e4b0b52df2647e69b07a16c Mon Sep 17 00:00:00 2001 From: jmillman Date: Mon, 22 Jun 2015 14:11:44 -0400 Subject: [PATCH 19/56] rename method in CategoryManager to be more descriptive; fix tag and category grouping when tags aer added / removed --- .../datamodel/CategoryManager.java | 6 ++-- .../imagegallery/grouping/GroupManager.java | 35 +++++++++++-------- .../imagegallery/gui/SlideShowView.java | 28 +++++++-------- 3 files changed, 38 insertions(+), 31 deletions(-) diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/CategoryManager.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/CategoryManager.java index 4d2591aa1e..3a1a81e72d 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/CategoryManager.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/CategoryManager.java @@ -211,7 +211,7 @@ public class CategoryManager { } - public static Category fromTagName(TagName tagName) { + public static Category categoryFromTagName(TagName tagName) { return Category.fromDisplayName(tagName.getDisplayName()); } @@ -246,7 +246,7 @@ public class CategoryManager { } catch (TskCoreException tskException) { LOGGER.log(Level.SEVERE, "Failed to get content tags for content. Unable to maintain category in a consistent state.", tskException); } - Category newCat = CategoryManager.fromTagName(addedTag.getName()); + Category newCat = CategoryManager.categoryFromTagName(addedTag.getName()); if (newCat != Category.ZERO) { incrementCategoryCount(newCat); } @@ -259,7 +259,7 @@ public class CategoryManager { ContentTag deleted = event.getDeletedTag(); if (isCategoryTagName(deleted.getName())) { - Category deletedCat = CategoryManager.fromTagName(deleted.getName()); + Category deletedCat = CategoryManager.categoryFromTagName(deleted.getName()); if (deletedCat != Category.ZERO) { decrementCategoryCount(deletedCat); } diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/GroupManager.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/GroupManager.java index 9ac899742c..90adfa76b8 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/GroupManager.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/GroupManager.java @@ -539,20 +539,25 @@ public class GroupManager implements FileUpdateEvent.FileUpdateListener { @Subscribe public void handleTagAdded(ContentTagAddedEvent evt) { - if (groupBy == DrawableAttribute.TAGS || groupBy == DrawableAttribute.CATEGORY) { - final GroupKey groupKey = new GroupKey<>(DrawableAttribute.TAGS, evt.getAddedTag().getName()); - final long fileID = evt.getAddedTag().getContent().getId(); - DrawableGroup g = getGroupForKey(groupKey); - addFileToGroup(g, groupKey, fileID); + GroupKey groupKey = null; + if (groupBy == DrawableAttribute.TAGS) { + groupKey = new GroupKey(DrawableAttribute.TAGS, evt.getAddedTag().getName()); + } else if (groupBy == DrawableAttribute.CATEGORY) { + groupKey = new GroupKey(DrawableAttribute.CATEGORY, CategoryManager.categoryFromTagName(evt.getAddedTag().getName())); } + final long fileID = evt.getAddedTag().getContent().getId(); + DrawableGroup g = getGroupForKey(groupKey); + addFileToGroup(g, groupKey, fileID); } + @SuppressWarnings("AssignmentToMethodParameter") private void addFileToGroup(DrawableGroup g, final GroupKey groupKey, final long fileID) { if (g == null) { //if there wasn't already a group check if there should be one now - popuplateIfAnalyzed(groupKey, null); - } else { + g = popuplateIfAnalyzed(groupKey, null); + } + if (g != null) { //if there is aleady a group that was previously deemed fully analyzed, then add this newly analyzed file to it. g.addFile(fileID); } @@ -560,11 +565,14 @@ public class GroupManager implements FileUpdateEvent.FileUpdateListener { @Subscribe public void handleTagDeleted(ContentTagDeletedEvent evt) { - if (groupBy == DrawableAttribute.TAGS || groupBy == DrawableAttribute.CATEGORY) { - final GroupKey groupKey = new GroupKey<>(DrawableAttribute.TAGS, evt.getDeletedTag().getName()); - final long fileID = evt.getDeletedTag().getContent().getId(); - DrawableGroup g = removeFromGroup(groupKey, fileID); + GroupKey groupKey = null; + if (groupBy == DrawableAttribute.TAGS) { + groupKey = new GroupKey(DrawableAttribute.TAGS, evt.getDeletedTag().getName()); + } else if (groupBy == DrawableAttribute.CATEGORY) { + groupKey = new GroupKey(DrawableAttribute.CATEGORY, CategoryManager.categoryFromTagName(evt.getDeletedTag().getName())); } + final long fileID = evt.getDeletedTag().getContent().getId(); + DrawableGroup g = removeFromGroup(groupKey, fileID); } @Override @@ -631,7 +639,7 @@ public class GroupManager implements FileUpdateEvent.FileUpdateListener { if ((groupKey.getAttribute() != DrawableAttribute.PATH) || db.isGroupAnalyzed(groupKey)) { /* for attributes other than path we can't be sure a group is * fully analyzed because we don't know all the files that - * will be a part of that group */ + * will be a part of that group,. just show them no matter what. */ try { Set fileIDs = getFileIDsInGroup(groupKey); @@ -643,9 +651,8 @@ public class GroupManager implements FileUpdateEvent.FileUpdateListener { group = groupMap.get(groupKey); group.setFiles(ObjectUtils.defaultIfNull(fileIDs, Collections.emptySet())); } else { - group = new DrawableGroup(groupKey, fileIDs, groupSeen); - group.seenProperty().addListener((observable, oldSeen, newSeen) -> { + group.seenProperty().addListener((o, oldSeen, newSeen) -> { markGroupSeen(group, newSeen); }); groupMap.put(groupKey, group); diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/SlideShowView.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/SlideShowView.java index 99944d6d19..d7d0f684ed 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/SlideShowView.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/SlideShowView.java @@ -25,6 +25,7 @@ import javafx.application.Platform; import javafx.beans.Observable; import javafx.beans.value.ChangeListener; import javafx.beans.value.ObservableValue; +import javafx.collections.ObservableList; import javafx.event.ActionEvent; import javafx.fxml.FXML; import javafx.scene.control.Button; @@ -282,24 +283,20 @@ public class SlideShowView extends DrawableTileBase { @Override protected String getTextForLabel() { - return getFile().map(file -> file.getName() + " " + getSupplementalText()).orElse(""); + return getFile().map(file -> file.getName()).orElse("") + " " + getSupplementalText(); } @ThreadConfined(type = ThreadType.JFX) - private void cycleSlideShowImage(int d) { + private void cycleSlideShowImage(int direction) { stopVideo(); - if (getFileID().isPresent()) { - int index = getGroupPane().getGrouping().fileIds().indexOf(getFileID()); - final int size = getGroupPane().getGrouping().fileIds().size(); - index = (index + d) % size; - if (index < 0) { - index += size; - } - setFile(getGroupPane().getGrouping().fileIds().get(index)); + final int groupSize = getGroupPane().getGrouping().fileIds().size(); + final Integer nextIndex = getFileID().map(fileID -> { + final int currentIndex = getGroupPane().getGrouping().fileIds().indexOf(fileID); + return (currentIndex + direction + groupSize) % groupSize; + }).orElse(0); + setFile(getGroupPane().getGrouping().fileIds().get(nextIndex) + ); - } else { - setFile(getGroupPane().getGrouping().fileIds().get(0)); - } } /** @@ -307,7 +304,10 @@ public class SlideShowView extends DrawableTileBase { * of y" */ private String getSupplementalText() { - return " ( " + (getGroupPane().getGrouping().fileIds().indexOf(getFileID()) + 1) + " of " + getGroupPane().getGrouping().fileIds().size() + " in group )"; + final ObservableList fileIds = getGroupPane().getGrouping().fileIds(); + return getFileID().map(fileID -> " ( " + (fileIds.indexOf(fileID) + 1) + " of " + fileIds.size() + " in group )") + .orElse(""); + } @Override From e4811246bab502595331fa9e198b1107a96b1e18 Mon Sep 17 00:00:00 2001 From: jmillman Date: Mon, 22 Jun 2015 15:11:16 -0400 Subject: [PATCH 20/56] reduce duplicate code --- .../imagegallery/ImageGalleryController.java | 4 +-- .../datamodel/CategoryManager.java | 4 +-- .../imagegallery/grouping/GroupManager.java | 12 +++---- .../imagegallery/gui/DrawableTileBase.java | 34 ++++++++++--------- .../imagegallery/gui/MetaDataPane.java | 17 +++++++--- 5 files changed, 40 insertions(+), 31 deletions(-) diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java index 6c6bd7c789..d81ff29938 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java @@ -491,13 +491,13 @@ public final class ImageGalleryController { break; case CONTENT_TAG_ADDED: final ContentTagAddedEvent tagAddedEvent = (ContentTagAddedEvent) evt; - if (getDatabase().isInDB((tagAddedEvent).getAddedTag().getContent().getId())) { + if (getDatabase().isInDB((tagAddedEvent).getTag().getContent().getId())) { getTagsManager().fireTagAddedEvent(tagAddedEvent); } break; case CONTENT_TAG_DELETED: final ContentTagDeletedEvent tagDeletedEvent = (ContentTagDeletedEvent) evt; - if (getDatabase().isInDB((tagDeletedEvent).getDeletedTag().getContent().getId())) { + if (getDatabase().isInDB((tagDeletedEvent).getTag().getContent().getId())) { getTagsManager().fireTagDeletedEvent(tagDeletedEvent); } break; diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/CategoryManager.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/CategoryManager.java index 3a1a81e72d..309173f153 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/CategoryManager.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/CategoryManager.java @@ -226,7 +226,7 @@ public class CategoryManager { @Subscribe public void handleTagAdded(ContentTagAddedEvent event) { - ContentTag addedTag = event.getAddedTag(); + ContentTag addedTag = event.getTag(); if (isCategoryTagName(addedTag.getName())) { final DrawableTagsManager tagsManager = controller.getTagsManager(); try { @@ -256,7 +256,7 @@ public class CategoryManager { } @Subscribe public void handleTagDeleted(ContentTagDeletedEvent event) { - ContentTag deleted = event.getDeletedTag(); + ContentTag deleted = event.getTag(); if (isCategoryTagName(deleted.getName())) { Category deletedCat = CategoryManager.categoryFromTagName(deleted.getName()); diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/GroupManager.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/GroupManager.java index 90adfa76b8..d7819c6d5e 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/GroupManager.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/GroupManager.java @@ -541,11 +541,11 @@ public class GroupManager implements FileUpdateEvent.FileUpdateListener { public void handleTagAdded(ContentTagAddedEvent evt) { GroupKey groupKey = null; if (groupBy == DrawableAttribute.TAGS) { - groupKey = new GroupKey(DrawableAttribute.TAGS, evt.getAddedTag().getName()); + groupKey = new GroupKey(DrawableAttribute.TAGS, evt.getTag().getName()); } else if (groupBy == DrawableAttribute.CATEGORY) { - groupKey = new GroupKey(DrawableAttribute.CATEGORY, CategoryManager.categoryFromTagName(evt.getAddedTag().getName())); + groupKey = new GroupKey(DrawableAttribute.CATEGORY, CategoryManager.categoryFromTagName(evt.getTag().getName())); } - final long fileID = evt.getAddedTag().getContent().getId(); + final long fileID = evt.getTag().getContent().getId(); DrawableGroup g = getGroupForKey(groupKey); addFileToGroup(g, groupKey, fileID); @@ -567,11 +567,11 @@ public class GroupManager implements FileUpdateEvent.FileUpdateListener { public void handleTagDeleted(ContentTagDeletedEvent evt) { GroupKey groupKey = null; if (groupBy == DrawableAttribute.TAGS) { - groupKey = new GroupKey(DrawableAttribute.TAGS, evt.getDeletedTag().getName()); + groupKey = new GroupKey(DrawableAttribute.TAGS, evt.getTag().getName()); } else if (groupBy == DrawableAttribute.CATEGORY) { - groupKey = new GroupKey(DrawableAttribute.CATEGORY, CategoryManager.categoryFromTagName(evt.getDeletedTag().getName())); + groupKey = new GroupKey(DrawableAttribute.CATEGORY, CategoryManager.categoryFromTagName(evt.getTag().getName())); } - final long fileID = evt.getDeletedTag().getContent().getId(); + final long fileID = evt.getTag().getContent().getId(); DrawableGroup g = removeFromGroup(groupKey, fileID); } diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableTileBase.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableTileBase.java index 80c73b1ae9..428bd0b5f4 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableTileBase.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableTileBase.java @@ -62,6 +62,7 @@ import org.sleuthkit.autopsy.directorytree.ExtractAction; import org.sleuthkit.autopsy.directorytree.NewWindowViewAction; import org.sleuthkit.autopsy.events.ContentTagAddedEvent; import org.sleuthkit.autopsy.events.ContentTagDeletedEvent; +import org.sleuthkit.autopsy.events.TagEvent; import org.sleuthkit.autopsy.imagegallery.FileIDSelectionModel; import org.sleuthkit.autopsy.imagegallery.ImageGalleryTopComponent; import org.sleuthkit.autopsy.imagegallery.actions.AddDrawableTagAction; @@ -70,6 +71,7 @@ import org.sleuthkit.autopsy.imagegallery.actions.DeleteFollowUpTagAction; import org.sleuthkit.autopsy.imagegallery.actions.SwingMenuItemAdapter; import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableAttribute; import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableFile; +import org.sleuthkit.datamodel.ContentTag; import org.sleuthkit.datamodel.TagName; import org.sleuthkit.datamodel.TskCoreException; @@ -349,36 +351,36 @@ public abstract class DrawableTileBase extends DrawableUIBase { @Subscribe @Override public void handleTagAdded(ContentTagAddedEvent evt) { - getFileID().ifPresent(fileID -> { - try { - if (fileID == evt.getAddedTag().getContent().getId() - && evt.getAddedTag().getName().equals(getController().getTagsManager().getFollowUpTagName())) { - Platform.runLater(() -> { - followUpImageView.setImage(followUpIcon); - followUpToggle.setSelected(true); - }); - } - } catch (TskCoreException ex) { - LOGGER.log(Level.SEVERE, "Failed to get follow up status for file.", ex); - } + handleTagEvent(evt, () -> { + Platform.runLater(() -> { + followUpImageView.setImage(followUpIcon); + followUpToggle.setSelected(true); + }); }); } @Subscribe @Override public void handleTagDeleted(ContentTagDeletedEvent evt) { + handleTagEvent(evt, this::updateFollowUpIcon); + } + void handleTagEvent(TagEvent evt, Runnable runnable) { getFileID().ifPresent(fileID -> { try { - if (fileID == evt.getDeletedTag().getContent().getId() - && evt.getDeletedTag().getName().equals(getController().getTagsManager().getFollowUpTagName())) { - updateFollowUpIcon(); + final TagName followUpTagName = getController().getTagsManager().getFollowUpTagName(); + final ContentTag deletedTag = evt.getTag(); + + if (fileID == deletedTag.getContent().getId() + && deletedTag.getName().equals(followUpTagName)) { + runnable.run(); } } catch (TskCoreException ex) { - LOGGER.log(Level.SEVERE, "Failed to get follow up status for file.", ex); + LOGGER.log(Level.SEVERE, "Failed to get followup tag name. Unable to update follow up status for file. ", ex); } }); + } private void updateFollowUpIcon() { diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/MetaDataPane.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/MetaDataPane.java index d89db4116c..780513d16a 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/MetaDataPane.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/MetaDataPane.java @@ -46,10 +46,12 @@ import org.apache.commons.lang3.StringUtils; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.events.ContentTagAddedEvent; import org.sleuthkit.autopsy.events.ContentTagDeletedEvent; +import org.sleuthkit.autopsy.events.TagEvent; import org.sleuthkit.autopsy.imagegallery.ImageGalleryController; import org.sleuthkit.autopsy.imagegallery.datamodel.Category; import org.sleuthkit.autopsy.imagegallery.datamodel.CategoryChangeEvent; import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableAttribute; +import org.sleuthkit.datamodel.ContentTag; import org.sleuthkit.datamodel.TagName; /** @@ -197,19 +199,24 @@ public class MetaDataPane extends DrawableUIBase { @Subscribe @Override public void handleTagAdded(ContentTagAddedEvent evt) { - handleTagChanged(evt.getAddedTag().getContent().getId()); + handleTagEvent(evt, this::updateUI); } @Subscribe @Override public void handleTagDeleted(ContentTagDeletedEvent evt) { - handleTagChanged(evt.getDeletedTag().getContent().getId()); + handleTagEvent(evt, this::updateUI); } - private void handleTagChanged(Long tagFileID) { + /** + * + * @param tagFileID the value of tagEvent + * @param runnable the value of runnable + */ + void handleTagEvent(TagEvent tagEvent, final Runnable runnable) { getFileID().ifPresent(fileID -> { - if (Objects.equals(tagFileID, fileID)) { - updateUI(); + if (Objects.equals(tagEvent.getTag().getContent().getId(), fileID)) { + runnable.run(); } }); } From 617a4959a03056453e18e36fcacae628163d2acd Mon Sep 17 00:00:00 2001 From: jmillman Date: Mon, 22 Jun 2015 15:22:14 -0400 Subject: [PATCH 21/56] move DrawableView and GroupPane to a new package --- .../ImageGalleryTopComponent.java | 4 +- .../autopsy/imagegallery/gui/GroupView.java | 8 --- .../gui/{ => drawableviews}/DrawableTile.fxml | 0 .../gui/{ => drawableviews}/DrawableTile.java | 5 +- .../{ => drawableviews}/DrawableTileBase.java | 2 +- .../{ => drawableviews}/DrawableUIBase.java | 2 +- .../gui/{ => drawableviews}/DrawableView.java | 2 +- .../gui/{ => drawableviews}/GroupPane.fxml | 0 .../gui/{ => drawableviews}/GroupPane.java | 6 +- .../gui/{ => drawableviews}/MetaDataPane.fxml | 0 .../gui/{ => drawableviews}/MetaDataPane.java | 32 +++++----- .../gui/{ => drawableviews}/SlideShow.fxml | 0 .../{ => drawableviews}/SlideShowView.java | 63 ++++++++++--------- 13 files changed, 62 insertions(+), 62 deletions(-) delete mode 100644 ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/GroupView.java rename ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/{ => drawableviews}/DrawableTile.fxml (100%) rename ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/{ => drawableviews}/DrawableTile.java (95%) rename ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/{ => drawableviews}/DrawableTileBase.java (99%) rename ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/{ => drawableviews}/DrawableUIBase.java (97%) rename ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/{ => drawableviews}/DrawableView.java (98%) rename ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/{ => drawableviews}/GroupPane.fxml (100%) rename ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/{ => drawableviews}/GroupPane.java (99%) rename ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/{ => drawableviews}/MetaDataPane.fxml (100%) rename ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/{ => drawableviews}/MetaDataPane.java (98%) rename ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/{ => drawableviews}/SlideShow.fxml (100%) rename ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/{ => drawableviews}/SlideShowView.java (95%) diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryTopComponent.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryTopComponent.java index 850230cb88..658e523be9 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryTopComponent.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryTopComponent.java @@ -35,8 +35,8 @@ import org.openide.windows.Mode; import org.openide.windows.TopComponent; import org.openide.windows.WindowManager; import org.sleuthkit.autopsy.coreutils.Logger; -import org.sleuthkit.autopsy.imagegallery.gui.GroupPane; -import org.sleuthkit.autopsy.imagegallery.gui.MetaDataPane; +import org.sleuthkit.autopsy.imagegallery.gui.drawableviews.GroupPane; +import org.sleuthkit.autopsy.imagegallery.gui.drawableviews.MetaDataPane; import org.sleuthkit.autopsy.imagegallery.gui.StatusBar; import org.sleuthkit.autopsy.imagegallery.gui.SummaryTablePane; import org.sleuthkit.autopsy.imagegallery.gui.Toolbar; diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/GroupView.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/GroupView.java deleted file mode 100644 index 73d2f3373c..0000000000 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/GroupView.java +++ /dev/null @@ -1,8 +0,0 @@ - -package org.sleuthkit.autopsy.imagegallery.gui; - - - -public interface GroupView { - -} diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableTile.fxml b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/DrawableTile.fxml similarity index 100% rename from ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableTile.fxml rename to ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/DrawableTile.fxml diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableTile.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/DrawableTile.java similarity index 95% rename from ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableTile.java rename to ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/DrawableTile.java index 86a0b2ddee..86eed0a814 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableTile.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/DrawableTile.java @@ -16,7 +16,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.sleuthkit.autopsy.imagegallery.gui; +package org.sleuthkit.autopsy.imagegallery.gui.drawableviews; import java.util.Objects; import java.util.logging.Level; @@ -32,7 +32,8 @@ import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.coreutils.ThreadConfined; import org.sleuthkit.autopsy.coreutils.ThreadConfined.ThreadType; import org.sleuthkit.autopsy.imagegallery.FXMLConstructor; -import static org.sleuthkit.autopsy.imagegallery.gui.DrawableTileBase.globalSelectionModel; +import org.sleuthkit.autopsy.imagegallery.gui.Toolbar; +import static org.sleuthkit.autopsy.imagegallery.gui.drawableviews.DrawableTileBase.globalSelectionModel; import org.sleuthkit.datamodel.AbstractContent; /** diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableTileBase.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/DrawableTileBase.java similarity index 99% rename from ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableTileBase.java rename to ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/DrawableTileBase.java index 428bd0b5f4..ed12891589 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableTileBase.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/DrawableTileBase.java @@ -17,7 +17,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.sleuthkit.autopsy.imagegallery.gui; +package org.sleuthkit.autopsy.imagegallery.gui.drawableviews; import com.google.common.eventbus.Subscribe; import java.util.ArrayList; diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableUIBase.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/DrawableUIBase.java similarity index 97% rename from ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableUIBase.java rename to ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/DrawableUIBase.java index ec794eabae..0657385aff 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableUIBase.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/DrawableUIBase.java @@ -16,7 +16,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.sleuthkit.autopsy.imagegallery.gui; +package org.sleuthkit.autopsy.imagegallery.gui.drawableviews; import java.util.Objects; import static java.util.Objects.nonNull; diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableView.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/DrawableView.java similarity index 98% rename from ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableView.java rename to ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/DrawableView.java index 709679173e..6b9a532e86 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableView.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/DrawableView.java @@ -1,4 +1,4 @@ -package org.sleuthkit.autopsy.imagegallery.gui; +package org.sleuthkit.autopsy.imagegallery.gui.drawableviews; import com.google.common.eventbus.Subscribe; import java.util.Collection; diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/GroupPane.fxml b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/GroupPane.fxml similarity index 100% rename from ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/GroupPane.fxml rename to ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/GroupPane.fxml diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/GroupPane.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/GroupPane.java similarity index 99% rename from ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/GroupPane.java rename to ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/GroupPane.java index 09042abaf4..266b578f46 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/GroupPane.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/GroupPane.java @@ -16,8 +16,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.sleuthkit.autopsy.imagegallery.gui; +package org.sleuthkit.autopsy.imagegallery.gui.drawableviews; +import org.sleuthkit.autopsy.imagegallery.gui.drawableviews.SlideShowView; +import org.sleuthkit.autopsy.imagegallery.gui.drawableviews.DrawableTile; import com.google.common.collect.ImmutableMap; import java.util.ArrayList; import java.util.Arrays; @@ -116,6 +118,8 @@ import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableAttribute; import org.sleuthkit.autopsy.imagegallery.grouping.DrawableGroup; import org.sleuthkit.autopsy.imagegallery.grouping.GroupViewMode; import org.sleuthkit.autopsy.imagegallery.grouping.GroupViewState; +import org.sleuthkit.autopsy.imagegallery.gui.GuiUtils; +import org.sleuthkit.autopsy.imagegallery.gui.Toolbar; import org.sleuthkit.datamodel.TagName; import org.sleuthkit.datamodel.TskCoreException; diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/MetaDataPane.fxml b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/MetaDataPane.fxml similarity index 100% rename from ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/MetaDataPane.fxml rename to ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/MetaDataPane.fxml diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/MetaDataPane.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/MetaDataPane.java similarity index 98% rename from ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/MetaDataPane.java rename to ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/MetaDataPane.java index 780513d16a..4814357a68 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/MetaDataPane.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/MetaDataPane.java @@ -16,7 +16,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.sleuthkit.autopsy.imagegallery.gui; +package org.sleuthkit.autopsy.imagegallery.gui.drawableviews; import com.google.common.eventbus.Subscribe; import java.io.IOException; @@ -76,6 +76,20 @@ public class MetaDataPane extends DrawableUIBase { @FXML private BorderPane imageBorder; + public MetaDataPane(ImageGalleryController controller) { + super(controller); + + FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("MetaDataPane.fxml")); + fxmlLoader.setRoot(this); + fxmlLoader.setController(this); + + try { + fxmlLoader.load(); + } catch (IOException exception) { + throw new RuntimeException(exception); + } + } + @FXML @SuppressWarnings("unchecked") void initialize() { @@ -137,7 +151,7 @@ public class MetaDataPane extends DrawableUIBase { } @Override - synchronized protected void setFileHelper(Long newFileID) { + protected synchronized void setFileHelper(Long newFileID) { setFileIDOpt(Optional.ofNullable(newFileID)); if (newFileID == null) { Platform.runLater(() -> { @@ -151,20 +165,6 @@ public class MetaDataPane extends DrawableUIBase { } } - public MetaDataPane(ImageGalleryController controller) { - super(controller); - - FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("MetaDataPane.fxml")); - fxmlLoader.setRoot(this); - fxmlLoader.setController(this); - - try { - fxmlLoader.load(); - } catch (IOException exception) { - throw new RuntimeException(exception); - } - } - public void updateUI() { getFile().ifPresent(file -> { final Image icon = file.getThumbnail(); diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/SlideShow.fxml b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/SlideShow.fxml similarity index 100% rename from ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/SlideShow.fxml rename to ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/SlideShow.fxml diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/SlideShowView.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/SlideShowView.java similarity index 95% rename from ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/SlideShowView.java rename to ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/SlideShowView.java index d7d0f684ed..2b29e57d39 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/SlideShowView.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/SlideShowView.java @@ -16,7 +16,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.sleuthkit.autopsy.imagegallery.gui; +package org.sleuthkit.autopsy.imagegallery.gui.drawableviews; import java.util.ArrayList; import java.util.function.Function; @@ -58,13 +58,16 @@ import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableAttribute; import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableFile; import org.sleuthkit.autopsy.imagegallery.datamodel.ImageFile; import org.sleuthkit.autopsy.imagegallery.datamodel.VideoFile; -import static org.sleuthkit.autopsy.imagegallery.gui.DrawableView.CAT_BORDER_WIDTH; +import org.sleuthkit.autopsy.imagegallery.gui.GuiUtils; +import org.sleuthkit.autopsy.imagegallery.gui.MediaControl; +import static org.sleuthkit.autopsy.imagegallery.gui.drawableviews.DrawableView.CAT_BORDER_WIDTH; import org.sleuthkit.datamodel.TagName; import org.sleuthkit.datamodel.TskCoreException; /** * Displays the files of a group one at a time. Designed to be embedded in a * GroupPane. TODO: Extract a subclass for video files in slideshow mode-jm + * * TODO: reduce coupling to GroupPane */ public class SlideShowView extends DrawableTileBase { @@ -73,40 +76,36 @@ public class SlideShowView extends DrawableTileBase { @FXML private ToggleButton cat0Toggle; - + @FXML + private ToggleButton cat1Toggle; @FXML private ToggleButton cat2Toggle; + @FXML + private ToggleButton cat3Toggle; + @FXML + private ToggleButton cat4Toggle; + @FXML + private ToggleButton cat5Toggle; @FXML private SplitMenuButton tagSplitButton; - @FXML - private ToggleButton cat3Toggle; - @FXML private Region spring; - @FXML private Button leftButton; - - @FXML - private ToggleButton cat4Toggle; - - @FXML - private ToggleButton cat5Toggle; - - @FXML - private ToggleButton cat1Toggle; - @FXML private Button rightButton; - @FXML private ToolBar toolBar; - @FXML private BorderPane footer; + SlideShowView(GroupPane gp) { + super(gp); + FXMLConstructor.construct(this, "SlideShow.fxml"); + } + @FXML @Override protected void initialize() { @@ -145,6 +144,8 @@ public class SlideShowView extends DrawableTileBase { tagSplitButton.getItems().setAll(selTagMenues); } }); + + //configure category toggles cat0Toggle.setBorder(new Border(new BorderStroke(Category.ZERO.getColor(), BorderStrokeStyle.SOLID, new CornerRadii(1), new BorderWidths(1)))); cat1Toggle.setBorder(new Border(new BorderStroke(Category.ONE.getColor(), BorderStrokeStyle.SOLID, new CornerRadii(1), new BorderWidths(1)))); cat2Toggle.setBorder(new Border(new BorderStroke(Category.TWO.getColor(), BorderStrokeStyle.SOLID, new CornerRadii(1), new BorderWidths(1)))); @@ -176,9 +177,7 @@ public class SlideShowView extends DrawableTileBase { //set up key listener equivalents of buttons addEventFilter(KeyEvent.KEY_PRESSED, (KeyEvent t) -> { - if (t.getEventType() == KeyEvent.KEY_PRESSED) { - switch (t.getCode()) { case LEFT: cycleSlideShowImage(-1); @@ -220,20 +219,14 @@ public class SlideShowView extends DrawableTileBase { } } - SlideShowView(GroupPane gp) { - super(gp); - - FXMLConstructor.construct(this, "SlideShow.fxml"); - - } - - @ThreadConfined(type = ThreadType.UI) + @ThreadConfined(type = ThreadType.JFX) public void stopVideo() { if (imageBorder.getCenter() instanceof MediaControl) { ((MediaControl) imageBorder.getCenter()).stopVideo(); } } + /** {@inheritDoc } */ @Override synchronized public void setFile(final Long fileID) { super.setFile(fileID); @@ -255,6 +248,7 @@ public class SlideShowView extends DrawableTileBase { imageBorder.setCenter(null); } + /** {@inheritDoc } */ @Override protected Runnable getContentUpdateRunnable() { @@ -281,11 +275,20 @@ public class SlideShowView extends DrawableTileBase { }); } + /** {@inheritDoc } */ @Override protected String getTextForLabel() { return getFile().map(file -> file.getName()).orElse("") + " " + getSupplementalText(); } + /** + * cycle the image displayed in thes SlideShowview, to the next/previous one + * in the group. + * + * @param direction the direction to cycle: + * -1 => left / back + * 1 => right / forward + */ @ThreadConfined(type = ThreadType.JFX) private void cycleSlideShowImage(int direction) { stopVideo(); @@ -296,7 +299,6 @@ public class SlideShowView extends DrawableTileBase { }).orElse(0); setFile(getGroupPane().getGrouping().fileIds().get(nextIndex) ); - } /** @@ -310,6 +312,7 @@ public class SlideShowView extends DrawableTileBase { } + /** {@inheritDoc } */ @Override @ThreadConfined(type = ThreadType.ANY) public Category updateCategory() { From 6434d9e8b94b9a161ee49f977cc75cb9b878bc5c Mon Sep 17 00:00:00 2001 From: jmillman Date: Mon, 22 Jun 2015 15:23:36 -0400 Subject: [PATCH 22/56] remove unneeded interface --- .../imagegallery/gui/drawableviews/GroupPane.java | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/GroupPane.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/GroupPane.java index 266b578f46..b95e5d51f6 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/GroupPane.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/GroupPane.java @@ -18,8 +18,6 @@ */ package org.sleuthkit.autopsy.imagegallery.gui.drawableviews; -import org.sleuthkit.autopsy.imagegallery.gui.drawableviews.SlideShowView; -import org.sleuthkit.autopsy.imagegallery.gui.drawableviews.DrawableTile; import com.google.common.collect.ImmutableMap; import java.util.ArrayList; import java.util.Arrays; @@ -102,7 +100,6 @@ import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.coreutils.ThreadConfined; import org.sleuthkit.autopsy.coreutils.ThreadConfined.ThreadType; import org.sleuthkit.autopsy.directorytree.ExtractAction; -import org.sleuthkit.autopsy.imagegallery.DrawableTagsManager; import org.sleuthkit.autopsy.imagegallery.FXMLConstructor; import org.sleuthkit.autopsy.imagegallery.FileIDSelectionModel; import org.sleuthkit.autopsy.imagegallery.ImageGalleryController; @@ -130,13 +127,13 @@ import org.sleuthkit.datamodel.TskCoreException; * * * TODO: Extract the The GridView instance to a separate class analogous to the - * SlideShow. Move selection model into controlsfx GridView and submit pull + * SlideShow. + * + * TODO: Move selection model into controlsfx GridView and submit pull * request to them. * https://bitbucket.org/controlsfx/controlsfx/issue/4/add-a-multipleselectionmodel-to-gridview - * - * */ -public class GroupPane extends BorderPane implements GroupView { +public class GroupPane extends BorderPane { private static final Logger LOGGER = Logger.getLogger(GroupPane.class.getName()); From 376c6c4a3316babd8c4691644229789f89694d59 Mon Sep 17 00:00:00 2001 From: jmillman Date: Mon, 22 Jun 2015 15:42:48 -0400 Subject: [PATCH 23/56] move classes to better packages; remove FileUpdateEvent --- .../autopsy/imagegallery/FileUpdateEvent.java | 93 ------------------- .../imagegallery/ImageGalleryController.java | 5 +- .../imagegallery/actions/AddTagAction.java | 2 +- .../actions/CategorizeAction.java | 2 +- .../actions/DeleteFollowUpTagAction.java | 2 +- .../imagegallery/actions/NextUnseenGroup.java | 2 +- .../datamodel/CategoryChangeEvent.java | 50 ---------- .../datamodel/CategoryManager.java | 34 ++++++- .../imagegallery/datamodel/DrawableDB.java | 39 ++------ .../{ => datamodel}/DrawableTagsManager.java | 3 +- .../datamodel/HashSetManager.java | 1 + .../grouping/DrawableGroup.java | 2 +- .../{ => datamodel}/grouping/GroupKey.java | 2 +- .../grouping/GroupManager.java | 30 ++---- .../{ => datamodel}/grouping/GroupSortBy.java | 2 +- .../datamodel/grouping/GroupViewMode.java | 7 ++ .../grouping/GroupViewState.java | 2 +- .../imagegallery/grouping/GroupViewMode.java | 7 -- .../imagegallery/gui/SortByListCell.java | 2 +- .../imagegallery/gui/SummaryTablePane.java | 3 +- .../autopsy/imagegallery/gui/Toolbar.java | 4 +- .../gui/drawableviews/DrawableView.java | 3 +- .../gui/drawableviews/GroupPane.java | 6 +- .../gui/drawableviews/MetaDataPane.java | 4 +- .../gui/navpanel/GroupTreeCell.java | 2 +- .../gui/navpanel/GroupTreeItem.java | 2 +- .../imagegallery/gui/navpanel/NavPanel.java | 4 +- .../imagegallery/gui/navpanel/TreeNode.java | 2 +- 28 files changed, 88 insertions(+), 229 deletions(-) delete mode 100644 ImageGallery/src/org/sleuthkit/autopsy/imagegallery/FileUpdateEvent.java delete mode 100644 ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/CategoryChangeEvent.java rename ImageGallery/src/org/sleuthkit/autopsy/imagegallery/{ => datamodel}/DrawableTagsManager.java (98%) rename ImageGallery/src/org/sleuthkit/autopsy/imagegallery/{ => datamodel}/grouping/DrawableGroup.java (98%) rename ImageGallery/src/org/sleuthkit/autopsy/imagegallery/{ => datamodel}/grouping/GroupKey.java (97%) rename ImageGallery/src/org/sleuthkit/autopsy/imagegallery/{ => datamodel}/grouping/GroupManager.java (96%) rename ImageGallery/src/org/sleuthkit/autopsy/imagegallery/{ => datamodel}/grouping/GroupSortBy.java (99%) create mode 100644 ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/GroupViewMode.java rename ImageGallery/src/org/sleuthkit/autopsy/imagegallery/{ => datamodel}/grouping/GroupViewState.java (97%) delete mode 100644 ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/GroupViewMode.java diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/FileUpdateEvent.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/FileUpdateEvent.java deleted file mode 100644 index c2803a5090..0000000000 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/FileUpdateEvent.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Autopsy Forensic Browser - * - * Copyright 2013 Basis Technology Corp. - * Contact: carrier sleuthkit org - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.sleuthkit.autopsy.imagegallery; - -import java.util.Collection; -import java.util.Collections; -import java.util.EventListener; -import java.util.HashSet; -import java.util.Set; -import javax.annotation.concurrent.Immutable; -import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableAttribute; - -/** represents a change in the database for one or more files. */ -@Immutable -public class FileUpdateEvent { - - /** the obj_ids of affected files */ - private final Set fileIDs; - - /** the attribute that was modified */ - private final DrawableAttribute changedAttribute; - - /** the type of update ( updated/removed) */ - private final UpdateType updateType; - - public UpdateType getUpdateType() { - return updateType; - } - - public Collection getFileIDs() { - return Collections.unmodifiableCollection(fileIDs); - } - - public DrawableAttribute getChangedAttribute() { - return changedAttribute; - } - - public static FileUpdateEvent newRemovedEvent(Collection updatedFiles) { - return new FileUpdateEvent(updatedFiles, UpdateType.REMOVE, null); - } - - /** - * - * @param updatedFiles the files that have been added or changed in the - * database - * @param changedAttribute the attribute that was changed for the files, or - * null if this represents new files - * - * @return a new FileUpdateEvent - */ - public static FileUpdateEvent newUpdateEvent(Collection updatedFiles, DrawableAttribute changedAttribute) { - return new FileUpdateEvent(updatedFiles, UpdateType.UPDATE, changedAttribute); - } - - private FileUpdateEvent(Collection updatedFiles, UpdateType updateType, DrawableAttribute changedAttribute) { - this.fileIDs = new HashSet<>(updatedFiles); - this.updateType = updateType; - this.changedAttribute = changedAttribute; - } - - static public enum UpdateType { - - /** files have been added or updated in the db */ - UPDATE, - /** files have been removed - * from the db */ - REMOVE; - } - - /** Interface for listening to FileUpdateEvents */ - public static interface FileUpdateListener extends EventListener { - - public void handleFileUpdate(FileUpdateEvent evt); - - public void handleFileRemoved(FileUpdateEvent evt); - } -} diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java index d81ff29938..44fa8950a3 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java @@ -18,6 +18,7 @@ */ package org.sleuthkit.autopsy.imagegallery; +import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableTagsManager; import java.beans.PropertyChangeEvent; import java.util.ArrayList; import java.util.List; @@ -63,8 +64,8 @@ import org.sleuthkit.autopsy.imagegallery.datamodel.CategoryManager; import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableDB; import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableFile; import org.sleuthkit.autopsy.imagegallery.datamodel.HashSetManager; -import org.sleuthkit.autopsy.imagegallery.grouping.GroupManager; -import org.sleuthkit.autopsy.imagegallery.grouping.GroupViewState; +import org.sleuthkit.autopsy.imagegallery.datamodel.grouping.GroupManager; +import org.sleuthkit.autopsy.imagegallery.datamodel.grouping.GroupViewState; import org.sleuthkit.autopsy.imagegallery.gui.NoGroupsDialog; import org.sleuthkit.autopsy.imagegallery.gui.Toolbar; import org.sleuthkit.autopsy.ingest.IngestManager; diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/AddTagAction.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/AddTagAction.java index 615b9b7f7d..cefa7aad60 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/AddTagAction.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/AddTagAction.java @@ -29,7 +29,7 @@ import org.sleuthkit.autopsy.actions.GetTagNameAndCommentDialog; import org.sleuthkit.autopsy.actions.GetTagNameDialog; import org.sleuthkit.autopsy.casemodule.services.TagsManager; import org.sleuthkit.autopsy.coreutils.Logger; -import org.sleuthkit.autopsy.imagegallery.DrawableTagsManager; +import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableTagsManager; import org.sleuthkit.autopsy.imagegallery.ImageGalleryController; import org.sleuthkit.autopsy.imagegallery.datamodel.CategoryManager; import org.sleuthkit.datamodel.TagName; diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/CategorizeAction.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/CategorizeAction.java index afe2b3bb5d..518a49b87a 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/CategorizeAction.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/CategorizeAction.java @@ -28,7 +28,7 @@ import javafx.scene.input.KeyCode; import javafx.scene.input.KeyCodeCombination; import javax.swing.JOptionPane; import org.sleuthkit.autopsy.coreutils.Logger; -import org.sleuthkit.autopsy.imagegallery.DrawableTagsManager; +import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableTagsManager; import org.sleuthkit.autopsy.imagegallery.FileIDSelectionModel; import org.sleuthkit.autopsy.imagegallery.ImageGalleryController; import org.sleuthkit.autopsy.imagegallery.datamodel.Category; diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/DeleteFollowUpTagAction.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/DeleteFollowUpTagAction.java index 934a3fb258..fb729807c0 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/DeleteFollowUpTagAction.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/DeleteFollowUpTagAction.java @@ -24,7 +24,7 @@ import javafx.event.ActionEvent; import javax.swing.SwingWorker; import org.controlsfx.control.action.Action; import org.sleuthkit.autopsy.coreutils.Logger; -import org.sleuthkit.autopsy.imagegallery.DrawableTagsManager; +import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableTagsManager; import org.sleuthkit.autopsy.imagegallery.ImageGalleryController; import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableFile; import org.sleuthkit.datamodel.ContentTag; diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/NextUnseenGroup.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/NextUnseenGroup.java index 550581d8b2..6a68810457 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/NextUnseenGroup.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/NextUnseenGroup.java @@ -28,7 +28,7 @@ import javafx.scene.image.ImageView; import org.controlsfx.control.action.Action; import org.sleuthkit.autopsy.coreutils.ThreadConfined; import org.sleuthkit.autopsy.imagegallery.ImageGalleryController; -import org.sleuthkit.autopsy.imagegallery.grouping.GroupViewState; +import org.sleuthkit.autopsy.imagegallery.datamodel.grouping.GroupViewState; /** * Marks the currently fisplayed group as "seen" and advances to the next unseen diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/CategoryChangeEvent.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/CategoryChangeEvent.java deleted file mode 100644 index 3868864737..0000000000 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/CategoryChangeEvent.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Autopsy Forensic Browser - * - * Copyright 2015 Basis Technology Corp. - * Contact: carrier sleuthkit org - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.sleuthkit.autopsy.imagegallery.datamodel; - -import java.util.Collection; -import java.util.Collections; -import javax.annotation.concurrent.Immutable; - -/** - * Event broadcast to various UI componenets when one or more files' category - * has been changed - */ -@Immutable -public class CategoryChangeEvent { - - private final Collection fileIDs; - private final Category newCategory; - - public CategoryChangeEvent(Collection fileIDs, Category newCategory) { - this.fileIDs = fileIDs; - this.newCategory = newCategory; - } - - public Category getNewCategory() { - return newCategory; - } - - /** - * @return the fileIDs of the files whose categories have changed - */ - public Collection getFileIDs() { - return Collections.unmodifiableCollection(fileIDs); - } -} diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/CategoryManager.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/CategoryManager.java index 309173f153..f84f759d37 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/CategoryManager.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/CategoryManager.java @@ -27,11 +27,13 @@ import java.util.Collections; import java.util.List; import java.util.concurrent.atomic.LongAdder; import java.util.logging.Level; +import javax.annotation.concurrent.Immutable; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.events.ContentTagAddedEvent; import org.sleuthkit.autopsy.events.ContentTagDeletedEvent; -import org.sleuthkit.autopsy.imagegallery.DrawableTagsManager; import org.sleuthkit.autopsy.imagegallery.ImageGalleryController; +import org.sleuthkit.autopsy.imagegallery.datamodel.Category; +import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableDB; import org.sleuthkit.datamodel.ContentTag; import org.sleuthkit.datamodel.TagName; import org.sleuthkit.datamodel.TskCoreException; @@ -254,6 +256,7 @@ public class CategoryManager { fireChange(Collections.singleton(addedTag.getContent().getId()), newCat); } } + @Subscribe public void handleTagDeleted(ContentTagDeletedEvent event) { ContentTag deleted = event.getTag(); @@ -266,4 +269,33 @@ public class CategoryManager { fireChange(Collections.singleton(deleted.getContent().getId()), null); } } + + /** + * Event broadcast to various UI componenets when one or more files' + * category + * has been changed + */ + @Immutable + public static class CategoryChangeEvent { + + private final Collection fileIDs; + private final Category newCategory; + + public CategoryChangeEvent(Collection fileIDs, Category newCategory) { + super(); + this.fileIDs = fileIDs; + this.newCategory = newCategory; + } + + public Category getNewCategory() { + return newCategory; + } + + /** + * @return the fileIDs of the files whose categories have changed + */ + public Collection getFileIDs() { + return Collections.unmodifiableCollection(fileIDs); + } + } } diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableDB.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableDB.java index 9dfbbdc239..87fa001827 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableDB.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableDB.java @@ -46,13 +46,12 @@ import org.apache.commons.lang3.StringUtils; import org.openide.util.Exceptions; import org.sleuthkit.autopsy.casemodule.Case; import org.sleuthkit.autopsy.coreutils.Logger; -import org.sleuthkit.autopsy.imagegallery.FileUpdateEvent; import org.sleuthkit.autopsy.imagegallery.ImageGalleryController; import org.sleuthkit.autopsy.imagegallery.ImageGalleryModule; -import org.sleuthkit.autopsy.imagegallery.grouping.GroupKey; -import org.sleuthkit.autopsy.imagegallery.grouping.GroupManager; -import org.sleuthkit.autopsy.imagegallery.grouping.GroupSortBy; -import static org.sleuthkit.autopsy.imagegallery.grouping.GroupSortBy.GROUP_BY_VALUE; +import org.sleuthkit.autopsy.imagegallery.datamodel.grouping.GroupKey; +import org.sleuthkit.autopsy.imagegallery.datamodel.grouping.GroupManager; +import org.sleuthkit.autopsy.imagegallery.datamodel.grouping.GroupSortBy; +import static org.sleuthkit.autopsy.imagegallery.datamodel.grouping.GroupSortBy.GROUP_BY_VALUE; import org.sleuthkit.datamodel.AbstractFile; import org.sleuthkit.datamodel.BlackboardArtifact; import org.sleuthkit.datamodel.BlackboardAttribute; @@ -125,11 +124,6 @@ public final class DrawableDB { */ private final Map, PreparedStatement> groupStatementMap = new HashMap<>(); - /** - * list of observers to be notified if the database changes - */ - private final HashSet updateListeners = new HashSet<>(); - private GroupManager groupManager; private final Path dbPath; @@ -201,6 +195,7 @@ public final class DrawableDB { this.dbPath = dbPath; this.controller = controller; this.tskCase = controller.getSleuthKitCase(); + this.groupManager = controller.getGroupManager(); Files.createDirectories(dbPath.getParent()); if (initializeDBSchema()) { updateFileStmt = prepareStatement( @@ -644,22 +639,6 @@ public final class DrawableDB { tr.commit(notify); } - public void addUpdatedFileListener(FileUpdateEvent.FileUpdateListener l) { - updateListeners.add(l); - } - - private void fireUpdatedFiles(Collection fileIDs) { - for (FileUpdateEvent.FileUpdateListener listener : updateListeners) { - listener.handleFileUpdate(FileUpdateEvent.newUpdateEvent(fileIDs, null)); - } - } - - private void fireRemovedFiles(Collection fileIDs) { - for (FileUpdateEvent.FileUpdateListener listener : updateListeners) { - listener.handleFileRemoved(FileUpdateEvent.newRemovedEvent(fileIDs)); - } - } - public Boolean isFileAnalyzed(DrawableFile f) { return isFileAnalyzed(f.getId()); } @@ -1149,7 +1128,7 @@ public final class DrawableDB { * in the drawable db? */ @Nonnull - Set getHashSetsForFile(long fileID) { + public Set getHashSetsForFile(long fileID) { try { Set hashNames = new HashSet<>(); List arts = tskCase.getBlackboardArtifacts(BlackboardArtifact.ARTIFACT_TYPE.TSK_HASHSET_HIT, fileID); @@ -1312,8 +1291,10 @@ public final class DrawableDB { close(); if (notify) { - fireUpdatedFiles(updatedFiles); - fireRemovedFiles(removedFiles); + if (groupManager != null) { + groupManager.handleFileUpdate(updatedFiles); + groupManager.handleFileRemoved(removedFiles); + } } } catch (SQLException ex) { if (Case.isCaseOpen()) { diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/DrawableTagsManager.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableTagsManager.java similarity index 98% rename from ImageGallery/src/org/sleuthkit/autopsy/imagegallery/DrawableTagsManager.java rename to ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableTagsManager.java index 0bbc4b9d5a..57d7152967 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/DrawableTagsManager.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableTagsManager.java @@ -16,7 +16,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.sleuthkit.autopsy.imagegallery; +package org.sleuthkit.autopsy.imagegallery.datamodel; import com.google.common.eventbus.EventBus; import java.util.Collection; @@ -30,7 +30,6 @@ import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.events.ContentTagAddedEvent; import org.sleuthkit.autopsy.events.ContentTagDeletedEvent; import org.sleuthkit.autopsy.imagegallery.datamodel.Category; -import org.sleuthkit.autopsy.imagegallery.datamodel.CategoryManager; import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableFile; import org.sleuthkit.datamodel.Content; import org.sleuthkit.datamodel.ContentTag; diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/HashSetManager.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/HashSetManager.java index 1ca547c81e..1071a6ee0a 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/HashSetManager.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/HashSetManager.java @@ -4,6 +4,7 @@ import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; import com.google.common.cache.LoadingCache; import java.util.Set; +import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableDB; /** * Manages a cache of hashset hits as a map from fileID to hashset names. diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/DrawableGroup.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/DrawableGroup.java similarity index 98% rename from ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/DrawableGroup.java rename to ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/DrawableGroup.java index 0ad8b2640e..ac0493d75e 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/DrawableGroup.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/DrawableGroup.java @@ -16,7 +16,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.sleuthkit.autopsy.imagegallery.grouping; +package org.sleuthkit.autopsy.imagegallery.datamodel.grouping; import java.util.Objects; import java.util.Set; diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/GroupKey.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/GroupKey.java similarity index 97% rename from ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/GroupKey.java rename to ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/GroupKey.java index cd41534078..ce64bebaa3 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/GroupKey.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/GroupKey.java @@ -16,7 +16,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.sleuthkit.autopsy.imagegallery.grouping; +package org.sleuthkit.autopsy.imagegallery.datamodel.grouping; import java.util.Map; import java.util.Objects; diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/GroupManager.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/GroupManager.java similarity index 96% rename from ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/GroupManager.java rename to ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/GroupManager.java index d7819c6d5e..ad99d94407 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/GroupManager.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/GroupManager.java @@ -16,7 +16,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.sleuthkit.autopsy.imagegallery.grouping; +package org.sleuthkit.autopsy.imagegallery.datamodel.grouping; import com.google.common.eventbus.Subscribe; import java.sql.ResultSet; @@ -50,7 +50,6 @@ import javax.annotation.concurrent.GuardedBy; import javax.swing.SortOrder; import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.commons.lang3.Validate; import org.apache.commons.lang3.concurrent.BasicThreadFactory; import org.netbeans.api.progress.ProgressHandle; import org.netbeans.api.progress.ProgressHandleFactory; @@ -62,8 +61,6 @@ import org.sleuthkit.autopsy.coreutils.ThreadConfined; import org.sleuthkit.autopsy.coreutils.ThreadConfined.ThreadType; import org.sleuthkit.autopsy.events.ContentTagAddedEvent; import org.sleuthkit.autopsy.events.ContentTagDeletedEvent; -import org.sleuthkit.autopsy.imagegallery.DrawableTagsManager; -import org.sleuthkit.autopsy.imagegallery.FileUpdateEvent; import org.sleuthkit.autopsy.imagegallery.ImageGalleryController; import org.sleuthkit.autopsy.imagegallery.ImageGalleryModule; import org.sleuthkit.autopsy.imagegallery.datamodel.Category; @@ -71,6 +68,7 @@ import org.sleuthkit.autopsy.imagegallery.datamodel.CategoryManager; import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableAttribute; import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableDB; import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableFile; +import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableTagsManager; import org.sleuthkit.datamodel.AbstractFile; import org.sleuthkit.datamodel.BlackboardArtifact; import org.sleuthkit.datamodel.BlackboardAttribute; @@ -84,7 +82,7 @@ import org.sleuthkit.datamodel.TskCoreException; * extent {@link SleuthkitCase} ) to facilitate creation, retrieval, updating, * and sorting of {@link DrawableGroup}s. */ -public class GroupManager implements FileUpdateEvent.FileUpdateListener { +public class GroupManager { private static final Logger LOGGER = Logger.getLogger(GroupManager.class.getName()); @@ -123,7 +121,6 @@ public class GroupManager implements FileUpdateEvent.FileUpdateListener { public void setDB(DrawableDB db) { this.db = db; - db.addUpdatedFileListener(this); regroup(groupBy, sortBy, sortOrder, Boolean.TRUE); } @@ -575,11 +572,10 @@ public class GroupManager implements FileUpdateEvent.FileUpdateListener { DrawableGroup g = removeFromGroup(groupKey, fileID); } - @Override - synchronized public void handleFileRemoved(FileUpdateEvent evt) { - Validate.isTrue(evt.getUpdateType() == FileUpdateEvent.UpdateType.REMOVE); + @Subscribe + synchronized public void handleFileRemoved(Collection removedFileIDs) { - for (final long fileId : evt.getFileIDs()) { + for (final long fileId : removedFileIDs) { //get grouping(s) this file would be in Set> groupsForFile = getGroupKeysForFileID(fileId); @@ -595,17 +591,15 @@ public class GroupManager implements FileUpdateEvent.FileUpdateListener { * * @param evt */ - @Override - synchronized public void handleFileUpdate(FileUpdateEvent evt) { - Validate.isTrue(evt.getUpdateType() == FileUpdateEvent.UpdateType.UPDATE); - Collection fileIDs = evt.getFileIDs(); + @Subscribe + synchronized public void handleFileUpdate(Collection updatedFileIDs) { /** * TODO: is there a way to optimize this to avoid quering to db * so much. the problem is that as a new files are analyzed they * might be in new groups( if we are grouping by say make or * model) -jm */ - for (long fileId : fileIDs) { + for (long fileId : updatedFileIDs) { controller.getHashSetManager().invalidateHashSetsForFile(fileId); @@ -618,11 +612,7 @@ public class GroupManager implements FileUpdateEvent.FileUpdateListener { } //we fire this event for all files so that the category counts get updated during initial db population - controller.getCategoryManager().fireChange(fileIDs, null); - -// if (evt.getChangedAttribute() == DrawableAttribute.TAGS) { -// controller.getTagsManager().fireChange(fileIDs); -// } + controller.getCategoryManager().fireChange(updatedFileIDs, null); } private DrawableGroup popuplateIfAnalyzed(GroupKey groupKey, ReGroupTask task) { diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/GroupSortBy.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/GroupSortBy.java similarity index 99% rename from ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/GroupSortBy.java rename to ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/GroupSortBy.java index fa2b3e88d0..a7bdbb342e 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/GroupSortBy.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/GroupSortBy.java @@ -16,7 +16,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.sleuthkit.autopsy.imagegallery.grouping; +package org.sleuthkit.autopsy.imagegallery.datamodel.grouping; import java.util.Arrays; import java.util.Comparator; diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/GroupViewMode.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/GroupViewMode.java new file mode 100644 index 0000000000..17a970ca13 --- /dev/null +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/GroupViewMode.java @@ -0,0 +1,7 @@ +package org.sleuthkit.autopsy.imagegallery.datamodel.grouping; + +public enum GroupViewMode { + + TILE, SLIDE_SHOW + +} diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/GroupViewState.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/GroupViewState.java similarity index 97% rename from ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/GroupViewState.java rename to ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/GroupViewState.java index 4d4905a80a..86679340ab 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/GroupViewState.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/GroupViewState.java @@ -16,7 +16,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.sleuthkit.autopsy.imagegallery.grouping; +package org.sleuthkit.autopsy.imagegallery.datamodel.grouping; import java.util.Objects; import java.util.Optional; diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/GroupViewMode.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/GroupViewMode.java deleted file mode 100644 index 5506223429..0000000000 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/GroupViewMode.java +++ /dev/null @@ -1,7 +0,0 @@ -package org.sleuthkit.autopsy.imagegallery.grouping; - -public enum GroupViewMode { - - TILE, SLIDE_SHOW - -} diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/SortByListCell.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/SortByListCell.java index 22985ff341..c9845fff3a 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/SortByListCell.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/SortByListCell.java @@ -20,7 +20,7 @@ package org.sleuthkit.autopsy.imagegallery.gui; import javafx.scene.control.ListCell; import javafx.scene.image.ImageView; -import org.sleuthkit.autopsy.imagegallery.grouping.GroupSortBy; +import org.sleuthkit.autopsy.imagegallery.datamodel.grouping.GroupSortBy; public class SortByListCell extends ListCell { diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/SummaryTablePane.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/SummaryTablePane.java index 955cf0760f..6fe4ce9b44 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/SummaryTablePane.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/SummaryTablePane.java @@ -36,7 +36,6 @@ import org.sleuthkit.autopsy.casemodule.Case; import org.sleuthkit.autopsy.imagegallery.FXMLConstructor; import org.sleuthkit.autopsy.imagegallery.ImageGalleryController; import org.sleuthkit.autopsy.imagegallery.datamodel.Category; -import org.sleuthkit.autopsy.imagegallery.datamodel.CategoryChangeEvent; /** * Displays summary statistics (counts) for each group @@ -88,7 +87,7 @@ public class SummaryTablePane extends AnchorPane { * listen to Category updates and rebuild the table */ @Subscribe - public void handleCategoryChanged(CategoryChangeEvent evt) { + public void handleCategoryChanged(org.sleuthkit.autopsy.imagegallery.datamodel.CategoryManager.CategoryChangeEvent evt) { final ObservableList> data = FXCollections.observableArrayList(); if (Case.isCaseOpen()) { for (Category cat : Category.values()) { diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/Toolbar.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/Toolbar.java index 2131ff73fc..33083c45b4 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/Toolbar.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/Toolbar.java @@ -41,7 +41,7 @@ import javafx.scene.image.ImageView; import javafx.scene.layout.HBox; import javax.swing.SortOrder; import org.openide.util.Exceptions; -import org.sleuthkit.autopsy.imagegallery.DrawableTagsManager; +import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableTagsManager; import org.sleuthkit.autopsy.imagegallery.FXMLConstructor; import org.sleuthkit.autopsy.imagegallery.FileIDSelectionModel; import org.sleuthkit.autopsy.imagegallery.ImageGalleryController; @@ -49,7 +49,7 @@ import org.sleuthkit.autopsy.imagegallery.ThumbnailCache; import org.sleuthkit.autopsy.imagegallery.actions.CategorizeAction; import org.sleuthkit.autopsy.imagegallery.datamodel.Category; import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableAttribute; -import org.sleuthkit.autopsy.imagegallery.grouping.GroupSortBy; +import org.sleuthkit.autopsy.imagegallery.datamodel.grouping.GroupSortBy; import org.sleuthkit.datamodel.TagName; import org.sleuthkit.datamodel.TskCoreException; diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/DrawableView.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/DrawableView.java index 6b9a532e86..4d7f31a52a 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/DrawableView.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/DrawableView.java @@ -18,7 +18,6 @@ import org.sleuthkit.autopsy.events.ContentTagAddedEvent; import org.sleuthkit.autopsy.events.ContentTagDeletedEvent; import org.sleuthkit.autopsy.imagegallery.ImageGalleryController; import org.sleuthkit.autopsy.imagegallery.datamodel.Category; -import org.sleuthkit.autopsy.imagegallery.datamodel.CategoryChangeEvent; import org.sleuthkit.autopsy.imagegallery.datamodel.CategoryManager; import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableFile; @@ -68,7 +67,7 @@ public interface DrawableView { * @param evt the CategoryChangeEvent to handle */ @Subscribe - default void handleCategoryChanged(CategoryChangeEvent evt) { + default void handleCategoryChanged(org.sleuthkit.autopsy.imagegallery.datamodel.CategoryManager.CategoryChangeEvent evt) { getFileID().ifPresent(fileID -> { if (evt.getFileIDs().contains(fileID)) { updateCategory(); diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/GroupPane.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/GroupPane.java index b95e5d51f6..4c2a056d46 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/GroupPane.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/GroupPane.java @@ -112,9 +112,9 @@ import org.sleuthkit.autopsy.imagegallery.actions.NextUnseenGroup; import org.sleuthkit.autopsy.imagegallery.actions.SwingMenuItemAdapter; import org.sleuthkit.autopsy.imagegallery.datamodel.Category; import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableAttribute; -import org.sleuthkit.autopsy.imagegallery.grouping.DrawableGroup; -import org.sleuthkit.autopsy.imagegallery.grouping.GroupViewMode; -import org.sleuthkit.autopsy.imagegallery.grouping.GroupViewState; +import org.sleuthkit.autopsy.imagegallery.datamodel.grouping.DrawableGroup; +import org.sleuthkit.autopsy.imagegallery.datamodel.grouping.GroupViewMode; +import org.sleuthkit.autopsy.imagegallery.datamodel.grouping.GroupViewState; import org.sleuthkit.autopsy.imagegallery.gui.GuiUtils; import org.sleuthkit.autopsy.imagegallery.gui.Toolbar; import org.sleuthkit.datamodel.TagName; diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/MetaDataPane.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/MetaDataPane.java index 4814357a68..5ebc6c1984 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/MetaDataPane.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/MetaDataPane.java @@ -49,8 +49,8 @@ import org.sleuthkit.autopsy.events.ContentTagDeletedEvent; import org.sleuthkit.autopsy.events.TagEvent; import org.sleuthkit.autopsy.imagegallery.ImageGalleryController; import org.sleuthkit.autopsy.imagegallery.datamodel.Category; -import org.sleuthkit.autopsy.imagegallery.datamodel.CategoryChangeEvent; import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableAttribute; +import org.sleuthkit.autopsy.imagegallery.datamodel.CategoryManager; import org.sleuthkit.datamodel.ContentTag; import org.sleuthkit.datamodel.TagName; @@ -188,7 +188,7 @@ public class MetaDataPane extends DrawableUIBase { /** {@inheritDoc } */ @Subscribe @Override - public void handleCategoryChanged(CategoryChangeEvent evt) { + public void handleCategoryChanged(CategoryManager.CategoryChangeEvent evt) { getFileID().ifPresent(fileID -> { if (evt.getFileIDs().contains(fileID)) { updateUI(); diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/navpanel/GroupTreeCell.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/navpanel/GroupTreeCell.java index 5deaf88aa8..8103a55cf6 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/navpanel/GroupTreeCell.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/navpanel/GroupTreeCell.java @@ -31,7 +31,7 @@ import javafx.scene.image.ImageView; import javax.annotation.Nonnull; import org.apache.commons.lang3.StringUtils; import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableAttribute; -import org.sleuthkit.autopsy.imagegallery.grouping.DrawableGroup; +import org.sleuthkit.autopsy.imagegallery.datamodel.grouping.DrawableGroup; /** * A cell in the NavPanel tree that listens to its associated group's fileids diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/navpanel/GroupTreeItem.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/navpanel/GroupTreeItem.java index 37925b47bb..3bd5ff72bf 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/navpanel/GroupTreeItem.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/navpanel/GroupTreeItem.java @@ -27,7 +27,7 @@ import javafx.application.Platform; import javafx.collections.FXCollections; import javafx.scene.control.TreeItem; import org.apache.commons.lang3.StringUtils; -import org.sleuthkit.autopsy.imagegallery.grouping.DrawableGroup; +import org.sleuthkit.autopsy.imagegallery.datamodel.grouping.DrawableGroup; /** * A node in the nav/hash tree. Manages inserts and removals. Has parents and diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/navpanel/NavPanel.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/navpanel/NavPanel.java index efc855e8ca..64aa5a681e 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/navpanel/NavPanel.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/navpanel/NavPanel.java @@ -45,8 +45,8 @@ import org.sleuthkit.autopsy.coreutils.ThreadConfined.ThreadType; import org.sleuthkit.autopsy.imagegallery.FXMLConstructor; import org.sleuthkit.autopsy.imagegallery.ImageGalleryController; import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableAttribute; -import org.sleuthkit.autopsy.imagegallery.grouping.DrawableGroup; -import org.sleuthkit.autopsy.imagegallery.grouping.GroupViewState; +import org.sleuthkit.autopsy.imagegallery.datamodel.grouping.DrawableGroup; +import org.sleuthkit.autopsy.imagegallery.datamodel.grouping.GroupViewState; /** * Display two trees. one shows all folders (groups) and calls out folders with diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/navpanel/TreeNode.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/navpanel/TreeNode.java index 0c7b2c2806..b230409075 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/navpanel/TreeNode.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/navpanel/TreeNode.java @@ -18,7 +18,7 @@ */ package org.sleuthkit.autopsy.imagegallery.gui.navpanel; -import org.sleuthkit.autopsy.imagegallery.grouping.DrawableGroup; +import org.sleuthkit.autopsy.imagegallery.datamodel.grouping.DrawableGroup; /** * From ad39755fe4750dc6c7eb31e2b8b1c200d3e48008 Mon Sep 17 00:00:00 2001 From: jmillman Date: Mon, 22 Jun 2015 16:42:44 -0400 Subject: [PATCH 24/56] better handling of exceptions in event bus eventhandlers --- .../datamodel/CategoryManager.java | 11 ++++++-- .../datamodel/DrawableTagsManager.java | 18 ++++++++---- .../datamodel/grouping/GroupManager.java | 28 +++++++++++-------- 3 files changed, 37 insertions(+), 20 deletions(-) diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/CategoryManager.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/CategoryManager.java index f84f759d37..31be08e71a 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/CategoryManager.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/CategoryManager.java @@ -20,20 +20,21 @@ import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; import com.google.common.cache.LoadingCache; +import com.google.common.eventbus.AsyncEventBus; import com.google.common.eventbus.EventBus; import com.google.common.eventbus.Subscribe; import java.util.Collection; import java.util.Collections; import java.util.List; +import java.util.concurrent.Executors; import java.util.concurrent.atomic.LongAdder; import java.util.logging.Level; import javax.annotation.concurrent.Immutable; +import org.apache.commons.lang3.concurrent.BasicThreadFactory; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.events.ContentTagAddedEvent; import org.sleuthkit.autopsy.events.ContentTagDeletedEvent; import org.sleuthkit.autopsy.imagegallery.ImageGalleryController; -import org.sleuthkit.autopsy.imagegallery.datamodel.Category; -import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableDB; import org.sleuthkit.datamodel.ContentTag; import org.sleuthkit.datamodel.TagName; import org.sleuthkit.datamodel.TskCoreException; @@ -66,7 +67,11 @@ public class CategoryManager { /** * Used to distribute {@link CategoryChangeEvent}s */ - private final EventBus categoryEventBus = new EventBus("Category Event Bus"); + private final EventBus categoryEventBus = new AsyncEventBus(Executors.newSingleThreadExecutor( + new BasicThreadFactory.Builder().namingPattern("Category Event Bus").uncaughtExceptionHandler((Thread t, Throwable e) -> { + LOGGER.log(Level.SEVERE, "uncaught exception in event bus handler", e); + }).build() + )); /** * For performance reasons, keep current category counts in memory. All of diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableTagsManager.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableTagsManager.java index 57d7152967..af5a0ebced 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableTagsManager.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableTagsManager.java @@ -18,19 +18,20 @@ */ package org.sleuthkit.autopsy.imagegallery.datamodel; +import com.google.common.eventbus.AsyncEventBus; import com.google.common.eventbus.EventBus; import java.util.Collection; import java.util.Collections; import java.util.List; import java.util.Objects; +import java.util.concurrent.Executors; import java.util.logging.Level; import java.util.stream.Collectors; +import org.apache.commons.lang3.concurrent.BasicThreadFactory; import org.sleuthkit.autopsy.casemodule.services.TagsManager; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.events.ContentTagAddedEvent; import org.sleuthkit.autopsy.events.ContentTagDeletedEvent; -import org.sleuthkit.autopsy.imagegallery.datamodel.Category; -import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableFile; import org.sleuthkit.datamodel.Content; import org.sleuthkit.datamodel.ContentTag; import org.sleuthkit.datamodel.TagName; @@ -42,13 +43,20 @@ import org.sleuthkit.datamodel.TskCoreException; */ public class DrawableTagsManager { + private static final Logger LOGGER = Logger.getLogger(DrawableTagsManager.class.getName()); + private static final String FOLLOW_UP = "Follow Up"; final private Object autopsyTagsManagerLock = new Object(); private TagsManager autopsyTagsManager; /** Used to distribute {@link TagsChangeEvent}s */ - private final EventBus tagsEventBus = new EventBus("Tags Event Bus"); + private final EventBus tagsEventBus = new AsyncEventBus( + Executors.newSingleThreadExecutor( + new BasicThreadFactory.Builder().namingPattern("Tags Event Bus").uncaughtExceptionHandler((Thread t, Throwable e) -> { + LOGGER.log(Level.SEVERE, "uncaught exception in event bus handler", e); + }).build() + )); /** The tag name corresponding to the "built-in" tag "Follow Up" */ private TagName followUpTagName; @@ -130,7 +138,7 @@ public class DrawableTagsManager { .filter(CategoryManager::isCategoryTagName) .collect(Collectors.toSet()); } catch (TskCoreException | IllegalStateException ex) { - Logger.getLogger(DrawableTagsManager.class.getName()).log(Level.WARNING, "couldn't access case", ex); + LOGGER.log(Level.WARNING, "couldn't access case", ex); } return Collections.emptySet(); } @@ -166,7 +174,7 @@ public class DrawableTagsManager { throw new TskCoreException("tagame exists but wasn't found", ex); } } catch (IllegalStateException ex) { - Logger.getLogger(DrawableTagsManager.class.getName()).log(Level.SEVERE, "Case was closed out from underneath", ex); + LOGGER.log(Level.SEVERE, "Case was closed out from underneath", ex); throw new TskCoreException("Case was closed out from underneath", ex); } } diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/GroupManager.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/GroupManager.java index ad99d94407..dc27ac136b 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/GroupManager.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/GroupManager.java @@ -537,15 +537,16 @@ public class GroupManager { @Subscribe public void handleTagAdded(ContentTagAddedEvent evt) { GroupKey groupKey = null; - if (groupBy == DrawableAttribute.TAGS) { - groupKey = new GroupKey(DrawableAttribute.TAGS, evt.getTag().getName()); - } else if (groupBy == DrawableAttribute.CATEGORY) { + if (groupBy == DrawableAttribute.CATEGORY && CategoryManager.isCategoryTagName(evt.getTag().getName())) { groupKey = new GroupKey(DrawableAttribute.CATEGORY, CategoryManager.categoryFromTagName(evt.getTag().getName())); + } else if (groupBy == DrawableAttribute.TAGS && CategoryManager.isNotCategoryTagName(evt.getTag().getName())) { + groupKey = new GroupKey(DrawableAttribute.TAGS, evt.getTag().getName()); + } + if (groupKey != null) { + final long fileID = evt.getTag().getContent().getId(); + DrawableGroup g = getGroupForKey(groupKey); + addFileToGroup(g, groupKey, fileID); } - final long fileID = evt.getTag().getContent().getId(); - DrawableGroup g = getGroupForKey(groupKey); - addFileToGroup(g, groupKey, fileID); - } @SuppressWarnings("AssignmentToMethodParameter") @@ -563,13 +564,16 @@ public class GroupManager { @Subscribe public void handleTagDeleted(ContentTagDeletedEvent evt) { GroupKey groupKey = null; - if (groupBy == DrawableAttribute.TAGS) { - groupKey = new GroupKey(DrawableAttribute.TAGS, evt.getTag().getName()); - } else if (groupBy == DrawableAttribute.CATEGORY) { + if (groupBy == DrawableAttribute.CATEGORY && CategoryManager.isCategoryTagName(evt.getTag().getName())) { groupKey = new GroupKey(DrawableAttribute.CATEGORY, CategoryManager.categoryFromTagName(evt.getTag().getName())); + } else if (groupBy == DrawableAttribute.TAGS && CategoryManager.isNotCategoryTagName(evt.getTag().getName())) { + groupKey = new GroupKey(DrawableAttribute.TAGS, evt.getTag().getName()); + } + + if (groupKey != null) { + final long fileID = evt.getTag().getContent().getId(); + DrawableGroup g = removeFromGroup(groupKey, fileID); } - final long fileID = evt.getTag().getContent().getId(); - DrawableGroup g = removeFromGroup(groupKey, fileID); } @Subscribe From 7dba4be3cc05f323920171b11b3082dab4c096f0 Mon Sep 17 00:00:00 2001 From: jmillman Date: Tue, 23 Jun 2015 15:46:12 -0400 Subject: [PATCH 25/56] only add new cat tag if there is no existing cat tag. put adding and removing fileids to/from group on jfx thread; remove file from groups when adding to new catagory based on new tag --- .../imagegallery/ImageGalleryController.java | 2 +- .../actions/CategorizeAction.java | 23 +++++++++---- .../datamodel/CategoryManager.java | 6 ++-- .../datamodel/grouping/GroupManager.java | 32 ++++++++++++------- 4 files changed, 41 insertions(+), 22 deletions(-) diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java index 44fa8950a3..e71aaf434c 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java @@ -18,7 +18,6 @@ */ package org.sleuthkit.autopsy.imagegallery; -import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableTagsManager; import java.beans.PropertyChangeEvent; import java.util.ArrayList; import java.util.List; @@ -63,6 +62,7 @@ import org.sleuthkit.autopsy.events.ContentTagDeletedEvent; import org.sleuthkit.autopsy.imagegallery.datamodel.CategoryManager; import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableDB; import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableFile; +import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableTagsManager; import org.sleuthkit.autopsy.imagegallery.datamodel.HashSetManager; import org.sleuthkit.autopsy.imagegallery.datamodel.grouping.GroupManager; import org.sleuthkit.autopsy.imagegallery.datamodel.grouping.GroupViewState; diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/CategorizeAction.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/CategorizeAction.java index 518a49b87a..f7c20ab56b 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/CategorizeAction.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/CategorizeAction.java @@ -19,8 +19,10 @@ package org.sleuthkit.autopsy.imagegallery.actions; import java.util.HashSet; +import java.util.List; import java.util.Set; import java.util.logging.Level; +import java.util.stream.Collectors; import javafx.event.ActionEvent; import javafx.scene.control.Menu; import javafx.scene.control.MenuItem; @@ -28,12 +30,14 @@ import javafx.scene.input.KeyCode; import javafx.scene.input.KeyCodeCombination; import javax.swing.JOptionPane; import org.sleuthkit.autopsy.coreutils.Logger; -import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableTagsManager; import org.sleuthkit.autopsy.imagegallery.FileIDSelectionModel; import org.sleuthkit.autopsy.imagegallery.ImageGalleryController; import org.sleuthkit.autopsy.imagegallery.datamodel.Category; import org.sleuthkit.autopsy.imagegallery.datamodel.CategoryManager; import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableFile; +import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableTagsManager; +import org.sleuthkit.datamodel.ContentTag; +import org.sleuthkit.datamodel.Tag; import org.sleuthkit.datamodel.TagName; import org.sleuthkit.datamodel.TskCoreException; @@ -127,11 +131,10 @@ public class CategorizeAction extends AddTagAction { try { DrawableFile file = controller.getFileFromId(fileID); //drawable db - - if (tagName != categoryManager.getTagName(Category.ZERO)) { // no tags for cat-0 - tagsManager.addContentTag(file, tagName, comment); //tsk db - } else { - tagsManager.getContentTagsByContent(file).stream() + final List fileTags = tagsManager.getContentTagsByContent(file); + if (tagName == categoryManager.getTagName(Category.ZERO)) { + // delete all cat tags for cat-0 + fileTags.stream() .filter(tag -> CategoryManager.isCategoryTagName(tag.getName())) .forEach((ct) -> { try { @@ -140,6 +143,14 @@ public class CategorizeAction extends AddTagAction { LOGGER.log(Level.SEVERE, "Error removing old categories result", ex); } }); + } else { + //add cat tag if no existing cat tag for that cat + if (fileTags.stream() + .map(Tag::getName) + .filter(tagName::equals) + .collect(Collectors.toList()).isEmpty()) { + tagsManager.addContentTag(file, tagName, comment); + } } } catch (TskCoreException ex) { diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/CategoryManager.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/CategoryManager.java index 31be08e71a..3377fdce6e 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/CategoryManager.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/CategoryManager.java @@ -233,14 +233,12 @@ public class CategoryManager { @Subscribe public void handleTagAdded(ContentTagAddedEvent event) { - ContentTag addedTag = event.getTag(); + final ContentTag addedTag = event.getTag(); if (isCategoryTagName(addedTag.getName())) { final DrawableTagsManager tagsManager = controller.getTagsManager(); try { //remove old category tag(s) if necessary - List allContentTags = tagsManager.getContentTagsByContent(addedTag.getContent()); - - for (ContentTag ct : allContentTags) { + for (ContentTag ct : tagsManager.getContentTagsByContent(addedTag.getContent())) { if (ct.getId() != addedTag.getId() && CategoryManager.isCategoryTagName(ct.getName())) { try { diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/GroupManager.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/GroupManager.java index dc27ac136b..8b7844d9c4 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/GroupManager.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/GroupManager.java @@ -270,7 +270,9 @@ public class GroupManager { //get grouping this file would be in final DrawableGroup group = getGroupForKey(groupKey); if (group != null) { - group.removeFile(fileID); + Platform.runLater(() -> { + group.removeFile(fileID); + }); // If we're grouping by category, we don't want to remove empty groups. if (groupKey.getAttribute() != DrawableAttribute.CATEGORY) { @@ -536,16 +538,21 @@ public class GroupManager { @Subscribe public void handleTagAdded(ContentTagAddedEvent evt) { - GroupKey groupKey = null; + GroupKey newGroupKey = null; + final long fileID = evt.getTag().getContent().getId(); if (groupBy == DrawableAttribute.CATEGORY && CategoryManager.isCategoryTagName(evt.getTag().getName())) { - groupKey = new GroupKey(DrawableAttribute.CATEGORY, CategoryManager.categoryFromTagName(evt.getTag().getName())); + newGroupKey = new GroupKey(DrawableAttribute.CATEGORY, CategoryManager.categoryFromTagName(evt.getTag().getName())); + for (GroupKey oldGroupKey : groupMap.keySet()) { + if (oldGroupKey.equals(newGroupKey) == false) { + removeFromGroup(oldGroupKey, fileID); + } + } } else if (groupBy == DrawableAttribute.TAGS && CategoryManager.isNotCategoryTagName(evt.getTag().getName())) { - groupKey = new GroupKey(DrawableAttribute.TAGS, evt.getTag().getName()); + newGroupKey = new GroupKey(DrawableAttribute.TAGS, evt.getTag().getName()); } - if (groupKey != null) { - final long fileID = evt.getTag().getContent().getId(); - DrawableGroup g = getGroupForKey(groupKey); - addFileToGroup(g, groupKey, fileID); + if (newGroupKey != null) { + DrawableGroup g = getGroupForKey(newGroupKey); + addFileToGroup(g, newGroupKey, fileID); } } @@ -555,9 +562,13 @@ public class GroupManager { //if there wasn't already a group check if there should be one now g = popuplateIfAnalyzed(groupKey, null); } - if (g != null) { + DrawableGroup group = g; + if (group != null) { //if there is aleady a group that was previously deemed fully analyzed, then add this newly analyzed file to it. - g.addFile(fileID); + Platform.runLater(() -> { + group.addFile(fileID); + }); + } } @@ -569,7 +580,6 @@ public class GroupManager { } else if (groupBy == DrawableAttribute.TAGS && CategoryManager.isNotCategoryTagName(evt.getTag().getName())) { groupKey = new GroupKey(DrawableAttribute.TAGS, evt.getTag().getName()); } - if (groupKey != null) { final long fileID = evt.getTag().getContent().getId(); DrawableGroup g = removeFromGroup(groupKey, fileID); From 28e3c015c34bfa3c191a6af67da106606fae1422 Mon Sep 17 00:00:00 2001 From: jmillman Date: Tue, 23 Jun 2015 16:12:55 -0400 Subject: [PATCH 26/56] clean up add tag action, use invokeLater not invokeAndWait; getNonCategoryTagNames returns TagNames in alphabetical order by displayname --- .../imagegallery/actions/AddTagAction.java | 63 +++++++------------ .../datamodel/DrawableTagsManager.java | 14 ++++- 2 files changed, 36 insertions(+), 41 deletions(-) diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/AddTagAction.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/AddTagAction.java index cefa7aad60..6e45f9bbdc 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/AddTagAction.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/AddTagAction.java @@ -18,22 +18,17 @@ */ package org.sleuthkit.autopsy.imagegallery.actions; -import java.util.List; +import java.util.Collection; import java.util.Set; -import java.util.logging.Level; import javafx.event.ActionEvent; import javafx.scene.control.Menu; import javafx.scene.control.MenuItem; import javax.swing.SwingUtilities; import org.sleuthkit.autopsy.actions.GetTagNameAndCommentDialog; import org.sleuthkit.autopsy.actions.GetTagNameDialog; -import org.sleuthkit.autopsy.casemodule.services.TagsManager; -import org.sleuthkit.autopsy.coreutils.Logger; -import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableTagsManager; import org.sleuthkit.autopsy.imagegallery.ImageGalleryController; import org.sleuthkit.autopsy.imagegallery.datamodel.CategoryManager; import org.sleuthkit.datamodel.TagName; -import org.sleuthkit.datamodel.TskCoreException; /** * An abstract base class for actions that allow users to tag SleuthKit data @@ -77,42 +72,31 @@ abstract class AddTagAction { TagMenu(ImageGalleryController controller) { super(getActionDisplayName()); - // Get the current set of tag names. - DrawableTagsManager tagsManager = controller.getTagsManager(); - List tagNames = null; - try { - tagNames = tagsManager.getAllTagNames(); - } catch (TskCoreException ex) { - Logger.getLogger(TagsManager.class.getName()).log(Level.SEVERE, "Failed to get tag names", ex); - } - // Create a "Quick Tag" sub-menu. Menu quickTagMenu = new Menu("Quick Tag"); getItems().add(quickTagMenu); - // Each tag name in the current set of tags gets its own menu item in - // the "Quick Tags" sub-menu. Selecting one of these menu items adds - // a tag with the associated tag name. - if (null != tagNames && !tagNames.isEmpty()) { - for (final TagName tagName : tagNames) { - if (CategoryManager.isNotCategoryTagName(tagName)) { - MenuItem tagNameItem = new MenuItem(tagName.getDisplayName()); - tagNameItem.setOnAction((ActionEvent t) -> { - addTag(tagName, NO_COMMENT); - }); - quickTagMenu.getItems().add(tagNameItem); - } - } - } else { + /* Each non-Category tag name in the current set of tags gets its + * own menu item in the "Quick Tags" sub-menu. Selecting one of + * these menu items adds a tag with the associated tag name. */ + Collection tagNames = controller.getTagsManager().getNonCategoryTagNames(); + if (tagNames.isEmpty()) { MenuItem empty = new MenuItem("No tags"); empty.setDisable(true); quickTagMenu.getItems().add(empty); + } else { + for (final TagName tagName : tagNames) { + MenuItem tagNameItem = new MenuItem(tagName.getDisplayName()); + tagNameItem.setOnAction((ActionEvent t) -> { + addTag(tagName, NO_COMMENT); + }); + quickTagMenu.getItems().add(tagNameItem); + } } - // quickTagMenu.addSeparator(); - // The "Quick Tag" menu also gets an "Choose Tag..." menu item. - // Selecting this item initiates a dialog that can be used to create - // or select a tag name and adds a tag with the resulting name. + /* The "Quick Tag" menu also gets an "New Tag..." menu item. + * Selecting this item initiates a dialog that can be used to create + * or select a tag name and adds a tag with the resulting name. */ MenuItem newTagMenuItem = new MenuItem("New Tag..."); newTagMenuItem.setOnAction((ActionEvent t) -> { SwingUtilities.invokeLater(() -> { @@ -125,18 +109,19 @@ abstract class AddTagAction { }); quickTagMenu.getItems().add(newTagMenuItem); - // Create a "Choose Tag and Comment..." menu item. Selecting this item initiates - // a dialog that can be used to create or select a tag name with an - // optional comment and adds a tag with the resulting name. + /* Create a "Tag and Comment..." menu item. Selecting this item + * initiates a dialog that can be used to create or select a tag + * name with an optional comment and adds a tag with the resulting + * name. */ MenuItem tagAndCommentItem = new MenuItem("Tag and Comment..."); tagAndCommentItem.setOnAction((ActionEvent t) -> { SwingUtilities.invokeLater(() -> { GetTagNameAndCommentDialog.TagNameAndComment tagNameAndComment = GetTagNameAndCommentDialog.doDialog(); if (null != tagNameAndComment) { - if (CategoryManager.isCategoryTagName(tagNameAndComment.getTagName())) { - new CategorizeAction(controller).addTag(tagNameAndComment.getTagName(), tagNameAndComment.getComment()); + if (CategoryManager.isCategoryTagName(tagNameAndComment.getTagName())) { + new CategorizeAction(controller).addTag(tagNameAndComment.getTagName(), tagNameAndComment.getComment()); } else { - new AddDrawableTagAction(controller).addTag(tagNameAndComment.getTagName(), tagNameAndComment.getComment()); + new AddDrawableTagAction(controller).addTag(tagNameAndComment.getTagName(), tagNameAndComment.getComment()); } } diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableTagsManager.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableTagsManager.java index af5a0ebced..547ab7a858 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableTagsManager.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableTagsManager.java @@ -27,6 +27,7 @@ import java.util.Objects; import java.util.concurrent.Executors; import java.util.logging.Level; import java.util.stream.Collectors; +import javax.annotation.Nonnull; import org.apache.commons.lang3.concurrent.BasicThreadFactory; import org.sleuthkit.autopsy.casemodule.services.TagsManager; import org.sleuthkit.autopsy.coreutils.Logger; @@ -131,12 +132,21 @@ public class DrawableTagsManager { } } + /** + * get all the TagNames that are not categories + * + * @return all the TagNames that are not categories, in alphabetical order + * by displayName, or, an empty set if there was an exception looking them + * up from the db. + */ + @Nonnull public Collection getNonCategoryTagNames() { synchronized (autopsyTagsManagerLock) { try { return autopsyTagsManager.getAllTagNames().stream() - .filter(CategoryManager::isCategoryTagName) - .collect(Collectors.toSet()); + .filter(CategoryManager::isNotCategoryTagName) + .distinct().sorted() + .collect(Collectors.toList()); } catch (TskCoreException | IllegalStateException ex) { LOGGER.log(Level.WARNING, "couldn't access case", ex); } From 5c0085d039c39af822babcc3c332c8d75fde420b Mon Sep 17 00:00:00 2001 From: jmillman Date: Tue, 23 Jun 2015 16:23:59 -0400 Subject: [PATCH 27/56] SlideShow toggle is disabled initialy; fix relative paths to images in fxml --- .../gui/drawableviews/DrawableTile.fxml | 112 +++++++++--------- .../gui/drawableviews/GroupPane.fxml | 12 +- .../gui/drawableviews/SlideShow.fxml | 12 +- 3 files changed, 69 insertions(+), 67 deletions(-) diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/DrawableTile.fxml b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/DrawableTile.fxml index 4d34061c77..acfcdc1336 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/DrawableTile.fxml +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/DrawableTile.fxml @@ -7,60 +7,62 @@ - - - - -
- -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+ +
+ +
+
+
-
-
- -
-
-
-
-
- - - + + + +
diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/GroupPane.fxml b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/GroupPane.fxml index 6eb799970d..4760d1f0cf 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/GroupPane.fxml +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/GroupPane.fxml @@ -23,7 +23,7 @@ - + @@ -32,7 +32,7 @@ - + @@ -53,7 +53,7 @@ - + @@ -108,16 +108,16 @@ - + - + - + diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/SlideShow.fxml b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/SlideShow.fxml index fb9e0aade4..fd3862afee 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/SlideShow.fxml +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/SlideShow.fxml @@ -18,7 +18,7 @@ - + @@ -42,7 +42,7 @@ - + @@ -88,12 +88,12 @@ - + - + @@ -110,7 +110,7 @@ - + @@ -135,7 +135,7 @@ - + From f191829cd1eba10eb9d0c17a7792559c9b52d652 Mon Sep 17 00:00:00 2001 From: jmillman Date: Tue, 23 Jun 2015 16:27:03 -0400 Subject: [PATCH 28/56] SlideShow toggle is disabled when there is no group selected; fix relative paths to images in fxml --- .../autopsy/imagegallery/gui/drawableviews/GroupPane.fxml | 2 +- .../autopsy/imagegallery/gui/drawableviews/GroupPane.java | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/GroupPane.fxml b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/GroupPane.fxml index 4760d1f0cf..6dfe0d02ed 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/GroupPane.fxml +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/GroupPane.fxml @@ -113,7 +113,7 @@ - + diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/GroupPane.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/GroupPane.java index 4c2a056d46..ab011fc493 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/GroupPane.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/GroupPane.java @@ -590,6 +590,7 @@ public class GroupPane extends BorderPane { Platform.runLater(() -> { gridView.getItems().setAll(Collections.emptyList()); setCenter(null); + slideShowToggle.setDisable(true); groupLabel.setText(""); resetScrollBar(); if (false == Case.isCaseOpen()) { From 5d73db18362998feea515f1ad5824f4a43ed8ec5 Mon Sep 17 00:00:00 2001 From: jmillman Date: Tue, 16 Jun 2015 11:14:44 -0400 Subject: [PATCH 29/56] make new DeleteFollowUpTag action; use Set instead of List to prevent duplicate files in groups --- .../actions/DeleteFollowUpTag.java | 86 +++++++++++++++++++ .../datamodel/grouping/GroupManager.java | 8 ++ .../gui/drawableviews/DrawableTileBase.java | 28 +++++- 3 files changed, 120 insertions(+), 2 deletions(-) create mode 100644 ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/DeleteFollowUpTag.java diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/DeleteFollowUpTag.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/DeleteFollowUpTag.java new file mode 100644 index 0000000000..0399b545ed --- /dev/null +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/DeleteFollowUpTag.java @@ -0,0 +1,86 @@ +/* + * Autopsy Forensic Browser + * + * Copyright 2015 Basis Technology Corp. + * Contact: carrier sleuthkit org + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.sleuthkit.autopsy.imagegallery.actions; + +import java.util.Collections; +import java.util.List; +import java.util.logging.Level; +import javafx.event.ActionEvent; +import org.controlsfx.control.action.Action; +import org.sleuthkit.autopsy.coreutils.Logger; +import org.sleuthkit.autopsy.imagegallery.FileUpdateEvent; +import org.sleuthkit.autopsy.imagegallery.ImageGalleryController; +import org.sleuthkit.autopsy.imagegallery.TagUtils; +import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableAttribute; +import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableFile; +import org.sleuthkit.autopsy.imagegallery.grouping.GroupKey; +import org.sleuthkit.autopsy.ingest.IngestServices; +import org.sleuthkit.autopsy.ingest.ModuleDataEvent; +import org.sleuthkit.datamodel.BlackboardArtifact; +import org.sleuthkit.datamodel.ContentTag; +import org.sleuthkit.datamodel.SleuthkitCase; +import org.sleuthkit.datamodel.TagName; +import org.sleuthkit.datamodel.TskCoreException; + +/** + * + */ +public class DeleteFollowUpTag extends Action { + + private static final Logger LOGGER = Logger.getLogger(DeleteFollowUpTag.class.getName()); + private final long fileID; + private final DrawableFile file; + + public DeleteFollowUpTag(DrawableFile file) { + super("Delete Follow Up Tag"); + this.file = file; + this.fileID = file.getId(); + + setEventHandler((ActionEvent t) -> { + deleteFollowupTag(); + }); + } + + /** + * + * @param fileID1 the value of fileID1 + * + * @throws IllegalStateException + */ + private void deleteFollowupTag() throws IllegalStateException { + + final ImageGalleryController controller = ImageGalleryController.getDefault(); + final SleuthkitCase sleuthKitCase = controller.getSleuthKitCase(); + try { + // remove file from old category group + controller.getGroupManager().removeFromGroup(new GroupKey(DrawableAttribute.TAGS, TagUtils.getFollowUpTagName()), fileID); + + List contentTagsByContent = sleuthKitCase.getContentTagsByContent(file); + for (ContentTag ct : contentTagsByContent) { + if (ct.getName().getDisplayName().equals(TagUtils.getFollowUpTagName().getDisplayName())) { + sleuthKitCase.deleteContentTag(ct); + } + } + IngestServices.getInstance().fireModuleDataEvent(new ModuleDataEvent("TagAction", BlackboardArtifact.ARTIFACT_TYPE.TSK_TAG_FILE)); //NON-NLS + controller.getGroupManager().handleFileUpdate(FileUpdateEvent.newUpdateEvent(Collections.singleton(fileID), DrawableAttribute.TAGS)); + } catch (TskCoreException ex) { + LOGGER.log(Level.SEVERE, "Failed to delete follow up tag.", ex); + } + } +} diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/GroupManager.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/GroupManager.java index 8b7844d9c4..2c0da12044 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/GroupManager.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/GroupManager.java @@ -243,6 +243,9 @@ public class GroupManager { /** * 'mark' the given group as seen. This removes it from the queue of * groups + public DrawableGroup makeGroup(GroupKey groupKey, Set files) { + + Set newFiles = ObjectUtils.defaultIfNull(files, new HashSet()); * to review, and is persisted in the drawable db. * * @param group the {@link DrawableGroup} to mark as seen @@ -284,6 +287,8 @@ public class GroupManager { if (unSeenGroups.contains(group)) { unSeenGroups.remove(group); } + public synchronized void populateAnalyzedGroup(final GroupKey groupKey, Set filesInGroup) { + private synchronized
> void populateAnalyzedGroup(final GroupKey groupKey, Set filesInGroup, ReGroupTask task) { }); } } @@ -291,6 +296,7 @@ public class GroupManager { // It may be that this was the last unanalyzed file in the group, so test // whether the group is now fully analyzed. popuplateIfAnalyzed(groupKey, null); + public Set checkAnalyzed(final GroupKey groupKey) { } return group; @@ -595,6 +601,7 @@ public class GroupManager { for (GroupKey gk : groupsForFile) { removeFromGroup(gk, fileId); + Set checkAnalyzed = checkAnalyzed(gk); } } } @@ -739,6 +746,7 @@ public class GroupManager { updateProgress(p, vals.size()); groupProgress.progress("regrouping files by " + groupBy.attrName.toString() + " : " + val, p); popuplateIfAnalyzed(new GroupKey(groupBy, val), this); + Set checkAnalyzed = checkAnalyzed(groupKey); } updateProgress(1, 1); diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/DrawableTileBase.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/DrawableTileBase.java index ed12891589..4f601f9400 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/DrawableTileBase.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/DrawableTileBase.java @@ -67,11 +67,9 @@ import org.sleuthkit.autopsy.imagegallery.FileIDSelectionModel; import org.sleuthkit.autopsy.imagegallery.ImageGalleryTopComponent; import org.sleuthkit.autopsy.imagegallery.actions.AddDrawableTagAction; import org.sleuthkit.autopsy.imagegallery.actions.CategorizeAction; -import org.sleuthkit.autopsy.imagegallery.actions.DeleteFollowUpTagAction; import org.sleuthkit.autopsy.imagegallery.actions.SwingMenuItemAdapter; import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableAttribute; import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableFile; -import org.sleuthkit.datamodel.ContentTag; import org.sleuthkit.datamodel.TagName; import org.sleuthkit.datamodel.TskCoreException; @@ -268,6 +266,32 @@ public abstract class DrawableTileBase extends DrawableUIBase { }); } +// /** +// * +// * @param fileID1 the value of fileID1 +// * +// * @throws IllegalStateException +// */ +// private void deleteFollowupTag(final Long fileID1) throws IllegalStateException { +// //TODO: convert this to an action! +// final ImageGalleryController controller = ImageGalleryController.getDefault(); +// try { +// // remove file from old category group +// controller.getGroupManager().removeFromGroup(new GroupKey(DrawableAttribute.TAGS, TagUtils.getFollowUpTagName()), fileID1); +// +// List contentTagsByContent = controller.getSleuthKitCase().getContentTagsByContent(file); +// for (ContentTag ct : contentTagsByContent) { +// if (ct.getName().getDisplayName().equals(TagUtils.getFollowUpTagName().getDisplayName())) { +// controller.getSleuthKitCase().deleteContentTag(ct); +// } +// } +// IngestServices.getInstance().fireModuleDataEvent(new ModuleDataEvent("TagAction", BlackboardArtifact.ARTIFACT_TYPE.TSK_TAG_FILE)); //NON-NLS +// controller.getGroupManager().handleFileUpdate(FileUpdateEvent.newUpdateEvent(Collections.singleton(fileID1), DrawableAttribute.TAGS)); +// } catch (TskCoreException ex) { +// LOGGER.log(Level.SEVERE, "Failed to delete follow up tag.", ex); +// } +// } + protected boolean hasFollowUp() { if (getFileID().isPresent()) { try { From cfe44bde9f71134fa9a9181e105e9a7519c77955 Mon Sep 17 00:00:00 2001 From: jmillman Date: Tue, 16 Jun 2015 12:51:06 -0400 Subject: [PATCH 30/56] cleanup Follow Up tag and Category TagNames (prevent short name version from being added, by removing commas) --- .../autopsy/imagegallery/actions/DeleteFollowUpTag.java | 2 ++ .../sleuthkit/autopsy/imagegallery/datamodel/Category.java | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/DeleteFollowUpTag.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/DeleteFollowUpTag.java index 0399b545ed..0fe88de953 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/DeleteFollowUpTag.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/DeleteFollowUpTag.java @@ -78,6 +78,8 @@ public class DeleteFollowUpTag extends Action { } } IngestServices.getInstance().fireModuleDataEvent(new ModuleDataEvent("TagAction", BlackboardArtifact.ARTIFACT_TYPE.TSK_TAG_FILE)); //NON-NLS + + //make sure rest of ui hears category change. controller.getGroupManager().handleFileUpdate(FileUpdateEvent.newUpdateEvent(Collections.singleton(fileID), DrawableAttribute.TAGS)); } catch (TskCoreException ex) { LOGGER.log(Level.SEVERE, "Failed to delete follow up tag.", ex); diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/Category.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/Category.java index 8999fff2f1..7cae09067f 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/Category.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/Category.java @@ -53,6 +53,10 @@ public enum Category { return nameMap.containsKey(tName); } + public static boolean isCategoryTagName(TagName tName) { + return nameMap.containsKey(tName.getDisplayName()); + } + public static boolean isNotCategoryName(String tName) { return nameMap.containsKey(tName) == false; } From 1be231107d1e14bc73316366487b1a77b34732c6 Mon Sep 17 00:00:00 2001 From: jmillman Date: Tue, 16 Jun 2015 16:53:16 -0400 Subject: [PATCH 31/56] clean up and refactor code related to Tagging and actions; move away from singleton by injecting controller rather than using getDefault(); use EventBus in DrawableTagsManager (used to be TagUtils) requires equal and hashcode method implemented on TagName --- .../imagegallery/DrawableTagsManager.java | 161 ++++++++++++++++++ .../imagegallery/ImageGalleryController.java | 4 + .../autopsy/imagegallery/TagsChangeEvent.java | 41 +++++ .../imagegallery/actions/AddTagAction.java | 1 + .../actions/CategorizeAction.java | 2 + ...eFollowUpTag.java => DeleteTagAction.java} | 42 +++-- .../datamodel/CategoryManager.java | 1 + .../imagegallery/datamodel/DrawableDB.java | 1 + .../gui/drawableviews/DrawableTileBase.java | 28 +-- .../gui/drawableviews/DrawableView.java | 1 - .../gui/drawableviews/GroupPane.java | 1 + .../gui/drawableviews/MetaDataPane.java | 5 + .../gui/drawableviews/SlideShowView.java | 1 + 13 files changed, 244 insertions(+), 45 deletions(-) create mode 100644 ImageGallery/src/org/sleuthkit/autopsy/imagegallery/DrawableTagsManager.java create mode 100644 ImageGallery/src/org/sleuthkit/autopsy/imagegallery/TagsChangeEvent.java rename ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/{DeleteFollowUpTag.java => DeleteTagAction.java} (66%) diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/DrawableTagsManager.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/DrawableTagsManager.java new file mode 100644 index 0000000000..3c1dd42de3 --- /dev/null +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/DrawableTagsManager.java @@ -0,0 +1,161 @@ +/* + * Autopsy Forensic Browser + * + * Copyright 2013 Basis Technology Corp. + * Contact: carrier sleuthkit org + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.sleuthkit.autopsy.imagegallery; + +import com.google.common.eventbus.EventBus; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.logging.Level; +import java.util.stream.Collectors; +import org.sleuthkit.autopsy.casemodule.services.TagsManager; +import org.sleuthkit.autopsy.coreutils.Logger; +import org.sleuthkit.autopsy.imagegallery.datamodel.Category; +import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableFile; +import org.sleuthkit.datamodel.ContentTag; +import org.sleuthkit.datamodel.TagName; +import org.sleuthkit.datamodel.TskCoreException; + +/** + * Manages Tags, Tagging, and the relationship between Categories and Tags in + * the autopsy Db. delegates some, work to the backing {@link TagsManager}. + */ +public class DrawableTagsManager { + + private static final String FOLLOW_UP = "Follow Up"; + + private TagsManager autopsyTagsManager; + + /** Used to distribute {@link TagsChangeEvent}s */ + private final EventBus tagsEventBus = new EventBus("Tags Event Bus"); + + /** The tag name corresponging to the "built-in" tag "Follow Up" */ + private TagName followUpTagName; + + public DrawableTagsManager(TagsManager autopsyTagsManager) { + this.autopsyTagsManager = autopsyTagsManager; + + } + + /** + * assign a new TagsManager to back this one, ie when the current case + * changes + * + * @param autopsyTagsManager + */ + public synchronized void setAutopsyTagsManager(TagsManager autopsyTagsManager) { + this.autopsyTagsManager = autopsyTagsManager; + clearFollowUpTagName(); + } + + /** + * Use when closing a case to make sure everything is re-initialized in the + * next case. + */ + public synchronized void clearFollowUpTagName() { + followUpTagName = null; + } + + /** + * fire a CategoryChangeEvent with the given fileIDs + * + * @param fileIDs + */ + public final void fireChange(Collection fileIDs) { + tagsEventBus.post(new TagsChangeEvent(fileIDs)); + } + + /** + * register an object to receive CategoryChangeEvents + * + * @param listner + */ + public void registerListener(Object listner) { + tagsEventBus.register(listner); + } + + /** + * unregister an object from receiving CategoryChangeEvents + * + * @param listener + */ + public void unregisterListener(Object listener) { + tagsEventBus.unregister(listener); + } + + /** + * get the (cached) follow up TagName + * + * @return + * + * @throws TskCoreException + */ + synchronized public TagName getFollowUpTagName() throws TskCoreException { + if (followUpTagName == null) { + followUpTagName = getTagName(FOLLOW_UP); + } + return followUpTagName; + } + + public Collection getNonCategoryTagNames() { + try { + return autopsyTagsManager.getAllTagNames().stream() + .filter(Category::isCategoryTagName) + .collect(Collectors.toSet()); + } catch (TskCoreException | IllegalStateException ex) { + Logger.getLogger(DrawableTagsManager.class.getName()).log(Level.WARNING, "couldn't access case", ex); + } + return Collections.emptySet(); + } + + public synchronized TagName getTagName(String displayName) throws TskCoreException { + try { + for (TagName tn : autopsyTagsManager.getAllTagNames()) { + if (displayName.equals(tn.getDisplayName())) { + return tn; + } + } + try { + return autopsyTagsManager.addTagName(displayName); + } catch (TagsManager.TagNameAlreadyExistsException ex) { + throw new TskCoreException("tagame exists but wasn't found", ex); + } + } catch (IllegalStateException ex) { + Logger.getLogger(DrawableTagsManager.class.getName()).log(Level.SEVERE, "Case was closed out from underneath", ex); + throw new TskCoreException("Case was closed out from underneath", ex); + } + } + + public synchronized TagName getTagName(Category cat) { + try { + return getTagName(cat.getDisplayName()); + } catch (TskCoreException ex) { + return null; + } + } + + public void addContentTag(DrawableFile file, TagName tagName, String comment) throws TskCoreException { + autopsyTagsManager.addContentTag(file, tagName, comment); + } + + public List getContentTagsByTagName(TagName t) throws TskCoreException { + return autopsyTagsManager.getContentTagsByTagName(t); + } + +} diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java index e71aaf434c..95b7141f78 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java @@ -518,6 +518,10 @@ public final class ImageGalleryController { return tagsManager; } + public DrawableTagsManager getTagsManager() { + return tagsManager; + } + // @@@ REVIEW IF THIS SHOLD BE STATIC... //TODO: concept seems like the controller deal with how much work to do at a given time // @@@ review this class for synchronization issues (i.e. reset and cancel being called, add, etc.) diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/TagsChangeEvent.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/TagsChangeEvent.java new file mode 100644 index 0000000000..0647a18456 --- /dev/null +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/TagsChangeEvent.java @@ -0,0 +1,41 @@ +/* + * Autopsy Forensic Browser + * + * Copyright 2015 Basis Technology Corp. + * Contact: carrier sleuthkit org + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.sleuthkit.autopsy.imagegallery; + +import java.util.Collection; +import java.util.Collections; +import javax.annotation.concurrent.Immutable; + +/** + * + */ +@Immutable +public class TagsChangeEvent { + + private final Collection fileIDs; + + public Collection getFileIDs() { + return Collections.unmodifiableCollection(fileIDs); + } + + public TagsChangeEvent(Collection fileIDs) { + this.fileIDs = fileIDs; + } + +} diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/AddTagAction.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/AddTagAction.java index 6e45f9bbdc..44bb02f0e0 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/AddTagAction.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/AddTagAction.java @@ -28,6 +28,7 @@ import org.sleuthkit.autopsy.actions.GetTagNameAndCommentDialog; import org.sleuthkit.autopsy.actions.GetTagNameDialog; import org.sleuthkit.autopsy.imagegallery.ImageGalleryController; import org.sleuthkit.autopsy.imagegallery.datamodel.CategoryManager; +import org.sleuthkit.autopsy.imagegallery.ImageGalleryController; import org.sleuthkit.datamodel.TagName; /** diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/CategorizeAction.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/CategorizeAction.java index f7c20ab56b..ff0c939ee3 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/CategorizeAction.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/CategorizeAction.java @@ -36,6 +36,7 @@ import org.sleuthkit.autopsy.imagegallery.datamodel.Category; import org.sleuthkit.autopsy.imagegallery.datamodel.CategoryManager; import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableFile; import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableTagsManager; +import org.sleuthkit.autopsy.imagegallery.grouping.GroupManager; import org.sleuthkit.datamodel.ContentTag; import org.sleuthkit.datamodel.Tag; import org.sleuthkit.datamodel.TagName; @@ -129,6 +130,7 @@ public class CategorizeAction extends AddTagAction { final CategoryManager categoryManager = controller.getCategoryManager(); final DrawableTagsManager tagsManager = controller.getTagsManager(); + try { DrawableFile file = controller.getFileFromId(fileID); //drawable db final List fileTags = tagsManager.getContentTagsByContent(file); diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/DeleteFollowUpTag.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/DeleteTagAction.java similarity index 66% rename from ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/DeleteFollowUpTag.java rename to ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/DeleteTagAction.java index 0fe88de953..38a8e40256 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/DeleteFollowUpTag.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/DeleteTagAction.java @@ -19,17 +19,16 @@ package org.sleuthkit.autopsy.imagegallery.actions; import java.util.Collections; -import java.util.List; import java.util.logging.Level; import javafx.event.ActionEvent; import org.controlsfx.control.action.Action; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.imagegallery.FileUpdateEvent; import org.sleuthkit.autopsy.imagegallery.ImageGalleryController; -import org.sleuthkit.autopsy.imagegallery.TagUtils; import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableAttribute; import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableFile; import org.sleuthkit.autopsy.imagegallery.grouping.GroupKey; +import org.sleuthkit.autopsy.imagegallery.grouping.GroupManager; import org.sleuthkit.autopsy.ingest.IngestServices; import org.sleuthkit.autopsy.ingest.ModuleDataEvent; import org.sleuthkit.datamodel.BlackboardArtifact; @@ -39,21 +38,26 @@ import org.sleuthkit.datamodel.TagName; import org.sleuthkit.datamodel.TskCoreException; /** + * Action to delete the follow up tag a + * * */ -public class DeleteFollowUpTag extends Action { +public class DeleteTagAction extends Action { - private static final Logger LOGGER = Logger.getLogger(DeleteFollowUpTag.class.getName()); + private static final Logger LOGGER = Logger.getLogger(DeleteTagAction.class.getName()); private final long fileID; private final DrawableFile file; + private final ImageGalleryController controller; + private final ContentTag tag; - public DeleteFollowUpTag(DrawableFile file) { + public DeleteTagAction(ImageGalleryController controller, DrawableFile file, ContentTag tag) { super("Delete Follow Up Tag"); + this.controller = controller; this.file = file; this.fileID = file.getId(); - + this.tag = tag; setEventHandler((ActionEvent t) -> { - deleteFollowupTag(); + deleteTag(); }); } @@ -63,24 +67,26 @@ public class DeleteFollowUpTag extends Action { * * @throws IllegalStateException */ - private void deleteFollowupTag() throws IllegalStateException { + private void deleteTag() throws IllegalStateException { - final ImageGalleryController controller = ImageGalleryController.getDefault(); final SleuthkitCase sleuthKitCase = controller.getSleuthKitCase(); + final GroupManager groupManager = controller.getGroupManager(); + try { // remove file from old category group - controller.getGroupManager().removeFromGroup(new GroupKey(DrawableAttribute.TAGS, TagUtils.getFollowUpTagName()), fileID); - - List contentTagsByContent = sleuthKitCase.getContentTagsByContent(file); - for (ContentTag ct : contentTagsByContent) { - if (ct.getName().getDisplayName().equals(TagUtils.getFollowUpTagName().getDisplayName())) { - sleuthKitCase.deleteContentTag(ct); - } - } + groupManager.removeFromGroup(new GroupKey(DrawableAttribute.TAGS, tag.getName()), fileID); + sleuthKitCase.deleteContentTag(tag); +// +// List contentTagsByContent = sleuthKitCase.getContentTagsByContent(file); +// for (ContentTag ct : contentTagsByContent) { +// if (ct.getName().getDisplayName().equals(tagsManager.getFollowUpTagName().getDisplayName())) { +// sleuthKitCase.deleteContentTag(ct); +// } +// } IngestServices.getInstance().fireModuleDataEvent(new ModuleDataEvent("TagAction", BlackboardArtifact.ARTIFACT_TYPE.TSK_TAG_FILE)); //NON-NLS //make sure rest of ui hears category change. - controller.getGroupManager().handleFileUpdate(FileUpdateEvent.newUpdateEvent(Collections.singleton(fileID), DrawableAttribute.TAGS)); + groupManager.handleFileUpdate(FileUpdateEvent.newUpdateEvent(Collections.singleton(fileID), DrawableAttribute.TAGS)); } catch (TskCoreException ex) { LOGGER.log(Level.SEVERE, "Failed to delete follow up tag.", ex); } diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/CategoryManager.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/CategoryManager.java index 3377fdce6e..551db0e6c6 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/CategoryManager.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/CategoryManager.java @@ -54,6 +54,7 @@ import org.sleuthkit.datamodel.TskCoreException; public class CategoryManager { private static final java.util.logging.Logger LOGGER = Logger.getLogger(CategoryManager.class.getName()); + private final ImageGalleryController controller; private final ImageGalleryController controller; diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableDB.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableDB.java index 87fa001827..db378c9917 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableDB.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableDB.java @@ -47,6 +47,7 @@ import org.openide.util.Exceptions; import org.sleuthkit.autopsy.casemodule.Case; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.imagegallery.ImageGalleryController; +import org.sleuthkit.autopsy.imagegallery.ImageGalleryController; import org.sleuthkit.autopsy.imagegallery.ImageGalleryModule; import org.sleuthkit.autopsy.imagegallery.datamodel.grouping.GroupKey; import org.sleuthkit.autopsy.imagegallery.datamodel.grouping.GroupManager; diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/DrawableTileBase.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/DrawableTileBase.java index 4f601f9400..b3bf25ee96 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/DrawableTileBase.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/DrawableTileBase.java @@ -131,11 +131,13 @@ public abstract class DrawableTileBase extends DrawableUIBase { */ final private GroupPane groupPane; volatile private boolean registered = false; + private final ImageGalleryController controller; protected DrawableTileBase(GroupPane groupPane) { super(groupPane.getController()); this.groupPane = groupPane; + this.controller = groupPane.getController(); globalSelectionModel.getSelected().addListener((Observable observable) -> { updateSelectionState(); }); @@ -266,32 +268,6 @@ public abstract class DrawableTileBase extends DrawableUIBase { }); } -// /** -// * -// * @param fileID1 the value of fileID1 -// * -// * @throws IllegalStateException -// */ -// private void deleteFollowupTag(final Long fileID1) throws IllegalStateException { -// //TODO: convert this to an action! -// final ImageGalleryController controller = ImageGalleryController.getDefault(); -// try { -// // remove file from old category group -// controller.getGroupManager().removeFromGroup(new GroupKey(DrawableAttribute.TAGS, TagUtils.getFollowUpTagName()), fileID1); -// -// List contentTagsByContent = controller.getSleuthKitCase().getContentTagsByContent(file); -// for (ContentTag ct : contentTagsByContent) { -// if (ct.getName().getDisplayName().equals(TagUtils.getFollowUpTagName().getDisplayName())) { -// controller.getSleuthKitCase().deleteContentTag(ct); -// } -// } -// IngestServices.getInstance().fireModuleDataEvent(new ModuleDataEvent("TagAction", BlackboardArtifact.ARTIFACT_TYPE.TSK_TAG_FILE)); //NON-NLS -// controller.getGroupManager().handleFileUpdate(FileUpdateEvent.newUpdateEvent(Collections.singleton(fileID1), DrawableAttribute.TAGS)); -// } catch (TskCoreException ex) { -// LOGGER.log(Level.SEVERE, "Failed to delete follow up tag.", ex); -// } -// } - protected boolean hasFollowUp() { if (getFileID().isPresent()) { try { diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/DrawableView.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/DrawableView.java index 4d7f31a52a..67647334d6 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/DrawableView.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/DrawableView.java @@ -1,7 +1,6 @@ package org.sleuthkit.autopsy.imagegallery.gui.drawableviews; import com.google.common.eventbus.Subscribe; -import java.util.Collection; import java.util.Optional; import java.util.logging.Level; import javafx.application.Platform; diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/GroupPane.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/GroupPane.java index ab011fc493..9bc0cf493e 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/GroupPane.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/GroupPane.java @@ -100,6 +100,7 @@ import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.coreutils.ThreadConfined; import org.sleuthkit.autopsy.coreutils.ThreadConfined.ThreadType; import org.sleuthkit.autopsy.directorytree.ExtractAction; +import org.sleuthkit.autopsy.imagegallery.DrawableTagsManager; import org.sleuthkit.autopsy.imagegallery.FXMLConstructor; import org.sleuthkit.autopsy.imagegallery.FileIDSelectionModel; import org.sleuthkit.autopsy.imagegallery.ImageGalleryController; diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/MetaDataPane.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/MetaDataPane.java index 5ebc6c1984..45399e2f79 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/MetaDataPane.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/MetaDataPane.java @@ -61,6 +61,11 @@ public class MetaDataPane extends DrawableUIBase { private static final Logger LOGGER = Logger.getLogger(MetaDataPane.class.getName()); + @Override + public ImageGalleryController getController() { + return controller; + } + @FXML private ImageView imageView; diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/SlideShowView.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/SlideShowView.java index 2b29e57d39..91fbec5a24 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/SlideShowView.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/SlideShowView.java @@ -50,6 +50,7 @@ import org.openide.util.Exceptions; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.coreutils.ThreadConfined; import org.sleuthkit.autopsy.coreutils.ThreadConfined.ThreadType; +import org.sleuthkit.autopsy.imagegallery.DrawableTagsManager; import org.sleuthkit.autopsy.imagegallery.FXMLConstructor; import org.sleuthkit.autopsy.imagegallery.FileIDSelectionModel; import org.sleuthkit.autopsy.imagegallery.actions.CategorizeAction; From e94f29e16df4357fd5be1b96007c1c84e9cbe1a7 Mon Sep 17 00:00:00 2001 From: jmillman Date: Wed, 17 Jun 2015 15:51:15 -0400 Subject: [PATCH 32/56] make sure all code is using the correct TagsManager (DrawableTagsManager) from controller; more cleanup --- .../imagegallery/DrawableTagsManager.java | 49 +++++++++- .../actions/AddDrawableTagAction.java | 1 + .../imagegallery/actions/AddTagAction.java | 1 + .../actions/CategorizeAction.java | 1 + .../actions/DeleteFollowUpTagAction.java | 72 +++++++++----- .../imagegallery/actions/DeleteTagAction.java | 94 ------------------- .../datamodel/grouping/GroupManager.java | 14 +++ .../gui/drawableviews/DrawableTileBase.java | 1 + 8 files changed, 111 insertions(+), 122 deletions(-) delete mode 100644 ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/DeleteTagAction.java diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/DrawableTagsManager.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/DrawableTagsManager.java index 3c1dd42de3..7ba9ceb842 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/DrawableTagsManager.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/DrawableTagsManager.java @@ -28,6 +28,10 @@ import org.sleuthkit.autopsy.casemodule.services.TagsManager; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.imagegallery.datamodel.Category; import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableFile; +import org.sleuthkit.autopsy.ingest.IngestServices; +import org.sleuthkit.autopsy.ingest.ModuleDataEvent; +import org.sleuthkit.datamodel.BlackboardArtifact; +import org.sleuthkit.datamodel.Content; import org.sleuthkit.datamodel.ContentTag; import org.sleuthkit.datamodel.TagName; import org.sleuthkit.datamodel.TskCoreException; @@ -45,7 +49,7 @@ public class DrawableTagsManager { /** Used to distribute {@link TagsChangeEvent}s */ private final EventBus tagsEventBus = new EventBus("Tags Event Bus"); - /** The tag name corresponging to the "built-in" tag "Follow Up" */ + /** The tag name corresponding to the "built-in" tag "Follow Up" */ private TagName followUpTagName; public DrawableTagsManager(TagsManager autopsyTagsManager) { @@ -113,7 +117,7 @@ public class DrawableTagsManager { return followUpTagName; } - public Collection getNonCategoryTagNames() { + synchronized public Collection getNonCategoryTagNames() { try { return autopsyTagsManager.getAllTagNames().stream() .filter(Category::isCategoryTagName) @@ -124,6 +128,20 @@ public class DrawableTagsManager { return Collections.emptySet(); } + /** + * Gets content tags count by content. + * + * @param The content of interest. + * + * @return A list, possibly empty, of the tags that have been applied to the + * artifact. + * + * @throws TskCoreException + */ + public synchronized List getContentTagsByContent(Content content) throws TskCoreException { + return autopsyTagsManager.getContentTagsByContent(content); + } + public synchronized TagName getTagName(String displayName) throws TskCoreException { try { for (TagName tn : autopsyTagsManager.getAllTagNames()) { @@ -150,12 +168,35 @@ public class DrawableTagsManager { } } - public void addContentTag(DrawableFile file, TagName tagName, String comment) throws TskCoreException { + synchronized public void addContentTag(DrawableFile file, TagName tagName, String comment) throws TskCoreException { autopsyTagsManager.addContentTag(file, tagName, comment); } - public List getContentTagsByTagName(TagName t) throws TskCoreException { + synchronized public List getContentTagsByTagName(TagName t) throws TskCoreException { return autopsyTagsManager.getContentTagsByTagName(t); } + /** + * Fire the ModuleDataEvent that we use as a place holder for a real Tag + * Event. This is used to refresh the autopsy tag tree and the ui in + * ImageGallery + * + * + * Note: this is a hack. In an ideal world, TagsManager would fire + * events so that the directory tree would refresh. But, we haven't + * had a chance to add that so, we fire these events and the tree + * refreshes based on them. + */ + static public void fireTagsChangedEvent() { + + IngestServices.getInstance().fireModuleDataEvent(new ModuleDataEvent("TagAction", BlackboardArtifact.ARTIFACT_TYPE.TSK_TAG_FILE)); //NON-NLS + } + + public synchronized List getAllTagNames() throws TskCoreException { + return autopsyTagsManager.getAllTagNames(); + } + + public synchronized List getTagNamesInUse() throws TskCoreException { + return autopsyTagsManager.getTagNamesInUse(); + } } diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/AddDrawableTagAction.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/AddDrawableTagAction.java index 3c115d9134..b3a45b3030 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/AddDrawableTagAction.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/AddDrawableTagAction.java @@ -27,6 +27,7 @@ import javax.swing.JOptionPane; import javax.swing.SwingWorker; import org.openide.util.Utilities; import org.sleuthkit.autopsy.coreutils.Logger; +import org.sleuthkit.autopsy.imagegallery.DrawableTagsManager; import org.sleuthkit.autopsy.imagegallery.FileIDSelectionModel; import org.sleuthkit.autopsy.imagegallery.ImageGalleryController; import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableFile; diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/AddTagAction.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/AddTagAction.java index 44bb02f0e0..af42c5ef2c 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/AddTagAction.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/AddTagAction.java @@ -26,6 +26,7 @@ import javafx.scene.control.MenuItem; import javax.swing.SwingUtilities; import org.sleuthkit.autopsy.actions.GetTagNameAndCommentDialog; import org.sleuthkit.autopsy.actions.GetTagNameDialog; +import org.sleuthkit.autopsy.imagegallery.DrawableTagsManager; import org.sleuthkit.autopsy.imagegallery.ImageGalleryController; import org.sleuthkit.autopsy.imagegallery.datamodel.CategoryManager; import org.sleuthkit.autopsy.imagegallery.ImageGalleryController; diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/CategorizeAction.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/CategorizeAction.java index ff0c939ee3..24e59dda65 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/CategorizeAction.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/CategorizeAction.java @@ -30,6 +30,7 @@ import javafx.scene.input.KeyCode; import javafx.scene.input.KeyCodeCombination; import javax.swing.JOptionPane; import org.sleuthkit.autopsy.coreutils.Logger; +import org.sleuthkit.autopsy.imagegallery.DrawableTagsManager; import org.sleuthkit.autopsy.imagegallery.FileIDSelectionModel; import org.sleuthkit.autopsy.imagegallery.ImageGalleryController; import org.sleuthkit.autopsy.imagegallery.datamodel.Category; diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/DeleteFollowUpTagAction.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/DeleteFollowUpTagAction.java index fb729807c0..6a1a54c30d 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/DeleteFollowUpTagAction.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/DeleteFollowUpTagAction.java @@ -18,16 +18,21 @@ */ package org.sleuthkit.autopsy.imagegallery.actions; +import java.util.Collections; import java.util.List; import java.util.logging.Level; import javafx.event.ActionEvent; -import javax.swing.SwingWorker; import org.controlsfx.control.action.Action; import org.sleuthkit.autopsy.coreutils.Logger; -import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableTagsManager; +import org.sleuthkit.autopsy.imagegallery.DrawableTagsManager; +import org.sleuthkit.autopsy.imagegallery.FileUpdateEvent; import org.sleuthkit.autopsy.imagegallery.ImageGalleryController; +import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableAttribute; import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableFile; +import org.sleuthkit.autopsy.imagegallery.grouping.GroupKey; +import org.sleuthkit.autopsy.imagegallery.grouping.GroupManager; import org.sleuthkit.datamodel.ContentTag; +import org.sleuthkit.datamodel.SleuthkitCase; import org.sleuthkit.datamodel.TagName; import org.sleuthkit.datamodel.TskCoreException; @@ -37,31 +42,50 @@ import org.sleuthkit.datamodel.TskCoreException; public class DeleteFollowUpTagAction extends Action { private static final Logger LOGGER = Logger.getLogger(DeleteFollowUpTagAction.class.getName()); + private final long fileID; + private final DrawableFile file; + private final ImageGalleryController controller; - public DeleteFollowUpTagAction(final ImageGalleryController controller, final DrawableFile file) { + public DeleteFollowUpTagAction(ImageGalleryController controller, DrawableFile file) { super("Delete Follow Up Tag"); + this.controller = controller; + this.file = file; + this.fileID = file.getId(); setEventHandler((ActionEvent t) -> { - new SwingWorker() { - - @Override - protected Void doInBackground() throws Exception { - final DrawableTagsManager tagsManager = controller.getTagsManager(); - - try { - final TagName followUpTagName = tagsManager.getFollowUpTagName(); - - List contentTagsByContent = tagsManager.getContentTagsByContent(file); - for (ContentTag ct : contentTagsByContent) { - if (ct.getName().getDisplayName().equals(followUpTagName.getDisplayName())) { - tagsManager.deleteContentTag(ct); - } - } - } catch (TskCoreException ex) { - LOGGER.log(Level.SEVERE, "Failed to delete follow up tag.", ex); - } - return null; - } - }.execute(); + deleteTag(); }); } + + /** + * + * + * + */ + private void deleteTag() { + + final SleuthkitCase sleuthKitCase = controller.getSleuthKitCase(); + final GroupManager groupManager = controller.getGroupManager(); + final DrawableTagsManager tagsManager = controller.getTagsManager(); + + try { + final TagName followUpTagName = tagsManager.getFollowUpTagName(); + // remove file from old category group + groupManager.removeFromGroup(new GroupKey(DrawableAttribute.TAGS, followUpTagName), fileID); + + List contentTagsByContent = sleuthKitCase.getContentTagsByContent(file); + for (ContentTag ct : contentTagsByContent) { + if (ct.getName().getDisplayName().equals(followUpTagName.getDisplayName())) { + sleuthKitCase.deleteContentTag(ct); + } + } + + DrawableTagsManager.fireTagsChangedEvent(); + + //make sure rest of ui hears category change. + groupManager.handleFileUpdate(FileUpdateEvent.newUpdateEvent(Collections.singleton(fileID), DrawableAttribute.TAGS)); + } catch (TskCoreException ex) { + LOGGER.log(Level.SEVERE, "Failed to delete follow up tag.", ex); + } + } + } diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/DeleteTagAction.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/DeleteTagAction.java deleted file mode 100644 index 38a8e40256..0000000000 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/DeleteTagAction.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Autopsy Forensic Browser - * - * Copyright 2015 Basis Technology Corp. - * Contact: carrier sleuthkit org - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.sleuthkit.autopsy.imagegallery.actions; - -import java.util.Collections; -import java.util.logging.Level; -import javafx.event.ActionEvent; -import org.controlsfx.control.action.Action; -import org.sleuthkit.autopsy.coreutils.Logger; -import org.sleuthkit.autopsy.imagegallery.FileUpdateEvent; -import org.sleuthkit.autopsy.imagegallery.ImageGalleryController; -import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableAttribute; -import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableFile; -import org.sleuthkit.autopsy.imagegallery.grouping.GroupKey; -import org.sleuthkit.autopsy.imagegallery.grouping.GroupManager; -import org.sleuthkit.autopsy.ingest.IngestServices; -import org.sleuthkit.autopsy.ingest.ModuleDataEvent; -import org.sleuthkit.datamodel.BlackboardArtifact; -import org.sleuthkit.datamodel.ContentTag; -import org.sleuthkit.datamodel.SleuthkitCase; -import org.sleuthkit.datamodel.TagName; -import org.sleuthkit.datamodel.TskCoreException; - -/** - * Action to delete the follow up tag a - * - * - */ -public class DeleteTagAction extends Action { - - private static final Logger LOGGER = Logger.getLogger(DeleteTagAction.class.getName()); - private final long fileID; - private final DrawableFile file; - private final ImageGalleryController controller; - private final ContentTag tag; - - public DeleteTagAction(ImageGalleryController controller, DrawableFile file, ContentTag tag) { - super("Delete Follow Up Tag"); - this.controller = controller; - this.file = file; - this.fileID = file.getId(); - this.tag = tag; - setEventHandler((ActionEvent t) -> { - deleteTag(); - }); - } - - /** - * - * @param fileID1 the value of fileID1 - * - * @throws IllegalStateException - */ - private void deleteTag() throws IllegalStateException { - - final SleuthkitCase sleuthKitCase = controller.getSleuthKitCase(); - final GroupManager groupManager = controller.getGroupManager(); - - try { - // remove file from old category group - groupManager.removeFromGroup(new GroupKey(DrawableAttribute.TAGS, tag.getName()), fileID); - sleuthKitCase.deleteContentTag(tag); -// -// List contentTagsByContent = sleuthKitCase.getContentTagsByContent(file); -// for (ContentTag ct : contentTagsByContent) { -// if (ct.getName().getDisplayName().equals(tagsManager.getFollowUpTagName().getDisplayName())) { -// sleuthKitCase.deleteContentTag(ct); -// } -// } - IngestServices.getInstance().fireModuleDataEvent(new ModuleDataEvent("TagAction", BlackboardArtifact.ARTIFACT_TYPE.TSK_TAG_FILE)); //NON-NLS - - //make sure rest of ui hears category change. - groupManager.handleFileUpdate(FileUpdateEvent.newUpdateEvent(Collections.singleton(fileID), DrawableAttribute.TAGS)); - } catch (TskCoreException ex) { - LOGGER.log(Level.SEVERE, "Failed to delete follow up tag.", ex); - } - } -} diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/GroupManager.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/GroupManager.java index 2c0da12044..61281a519c 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/GroupManager.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/GroupManager.java @@ -199,7 +199,21 @@ public class GroupManager { @Nullable public DrawableGroup getGroupForKey(@Nonnull GroupKey groupKey) { synchronized (groupMap) { + if (groupKey.getAttribute() == DrawableAttribute.TAGS) { + + System.out.println(groupKey); +// @SuppressWarnings("unchecked") +// GroupKey tagKey = (GroupKey) groupKey; +// +// return groupMap.keySet().stream() +// .filter((GroupKey t) -> t.getAttribute() == DrawableAttribute.TAGS) +// .map((GroupKey t) -> (GroupKey) t) +// .filter(t -> tagKey.getValue().getDisplayName().equals(t.getValue().getDisplayName())) +// .findFirst().map(groupMap::get).orElse(null); + + } //else { return groupMap.get(groupKey); +// } } } diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/DrawableTileBase.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/DrawableTileBase.java index b3bf25ee96..f579a35aed 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/DrawableTileBase.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/DrawableTileBase.java @@ -258,6 +258,7 @@ public abstract class DrawableTileBase extends DrawableUIBase { try { globalSelectionModel.clearAndSelect(file.getId()); new AddDrawableTagAction(getController()).addTag(getController().getTagsManager().getFollowUpTagName(), ""); + new AddDrawableTagAction(controller).addTag(followUpTagName, ""); } catch (TskCoreException ex) { LOGGER.log(Level.SEVERE, "Failed to add Follow Up tag. Could not load TagName.", ex); } From 2eecaa297e8c432773a913720b1dc3cdf8bfd9f1 Mon Sep 17 00:00:00 2001 From: jmillman Date: Wed, 17 Jun 2015 15:54:34 -0400 Subject: [PATCH 33/56] more cleanup of Categories/Tags and listening to autopsy generated "Tag Events" -remove unused code from Category.java -use Category.isCategoryTagName instead of .getDisplayName().startsWith(Category.CATEGORY_PREFIX) -regroup when notified of Tag Change from autopsy --- .../imagegallery/DrawableTagsManager.java | 3 +- .../imagegallery/ImageGalleryController.java | 224 +++++++++--------- .../imagegallery/datamodel/Category.java | 8 +- .../datamodel/grouping/GroupManager.java | 10 + 4 files changed, 133 insertions(+), 112 deletions(-) diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/DrawableTagsManager.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/DrawableTagsManager.java index 7ba9ceb842..2639de7617 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/DrawableTagsManager.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/DrawableTagsManager.java @@ -22,6 +22,7 @@ import com.google.common.eventbus.EventBus; import java.util.Collection; import java.util.Collections; import java.util.List; +import java.util.Objects; import java.util.logging.Level; import java.util.stream.Collectors; import org.sleuthkit.autopsy.casemodule.services.TagsManager; @@ -111,7 +112,7 @@ public class DrawableTagsManager { * @throws TskCoreException */ synchronized public TagName getFollowUpTagName() throws TskCoreException { - if (followUpTagName == null) { + if (Objects.isNull(followUpTagName)) { followUpTagName = getTagName(FOLLOW_UP); } return followUpTagName; diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java index 95b7141f78..907ef4556d 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java @@ -20,6 +20,7 @@ package org.sleuthkit.autopsy.imagegallery; import java.beans.PropertyChangeEvent; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.Objects; import java.util.concurrent.BlockingQueue; @@ -69,6 +70,7 @@ import org.sleuthkit.autopsy.imagegallery.datamodel.grouping.GroupViewState; import org.sleuthkit.autopsy.imagegallery.gui.NoGroupsDialog; import org.sleuthkit.autopsy.imagegallery.gui.Toolbar; import org.sleuthkit.autopsy.ingest.IngestManager; +import org.sleuthkit.autopsy.ingest.ModuleDataEvent; import org.sleuthkit.datamodel.AbstractFile; import org.sleuthkit.datamodel.BlackboardArtifact; import org.sleuthkit.datamodel.BlackboardAttribute; @@ -84,25 +86,25 @@ import org.sleuthkit.datamodel.TskData; * control. */ public final class ImageGalleryController { - + private static final Logger LOGGER = Logger.getLogger(ImageGalleryController.class.getName()); - + private final Region infoOverLayBackground = new Region() { { setBackground(new Background(new BackgroundFill(Color.GREY, CornerRadii.EMPTY, Insets.EMPTY))); setOpacity(.4); } }; - + private static ImageGalleryController instance; - + public static synchronized ImageGalleryController getDefault() { if (instance == null) { instance = new ImageGalleryController(); } return instance; } - + private final History historyManager = new History<>(); /** @@ -110,75 +112,75 @@ public final class ImageGalleryController { * not listen to speed up ingest */ private final SimpleBooleanProperty listeningEnabled = new SimpleBooleanProperty(false); - + private final ReadOnlyIntegerWrapper queueSizeProperty = new ReadOnlyIntegerWrapper(0); - + private final ReadOnlyBooleanWrapper regroupDisabled = new ReadOnlyBooleanWrapper(false); - + @ThreadConfined(type = ThreadConfined.ThreadType.JFX) private final ReadOnlyBooleanWrapper stale = new ReadOnlyBooleanWrapper(false); - + private final ReadOnlyBooleanWrapper metaDataCollapsed = new ReadOnlyBooleanWrapper(false); - + private final FileIDSelectionModel selectionModel = FileIDSelectionModel.getInstance(); - + private DBWorkerThread dbWorkerThread; - + private DrawableDB db; - + private final GroupManager groupManager = new GroupManager(this); private final HashSetManager hashSetManager = new HashSetManager(); private final CategoryManager categoryManager = new CategoryManager(this); private final DrawableTagsManager tagsManager = new DrawableTagsManager(null); - + private StackPane fullUIStackPane; - + private StackPane centralStackPane; - + private Node infoOverlay; private SleuthkitCase sleuthKitCase; - + public ReadOnlyBooleanProperty getMetaDataCollapsed() { return metaDataCollapsed.getReadOnlyProperty(); } - + public void setMetaDataCollapsed(Boolean metaDataCollapsed) { this.metaDataCollapsed.set(metaDataCollapsed); } - + private GroupViewState getViewState() { return historyManager.getCurrentState(); } - + public ReadOnlyBooleanProperty regroupDisabled() { return regroupDisabled.getReadOnlyProperty(); } - + public ReadOnlyObjectProperty viewState() { return historyManager.currentState(); } - + public synchronized FileIDSelectionModel getSelectionModel() { - + return selectionModel; } - + public GroupManager getGroupManager() { return groupManager; } - + public DrawableDB getDatabase() { return db; } - + synchronized public void setListeningEnabled(boolean enabled) { listeningEnabled.set(enabled); } - + synchronized boolean isListeningEnabled() { return listeningEnabled.get(); } - + @ThreadConfined(type = ThreadConfined.ThreadType.ANY) void setStale(Boolean b) { Platform.runLater(() -> { @@ -188,18 +190,18 @@ public final class ImageGalleryController { new PerCaseProperties(Case.getCurrentCase()).setConfigSetting(ImageGalleryModule.getModuleName(), PerCaseProperties.STALE, b.toString()); } } - + public ReadOnlyBooleanProperty stale() { return stale.getReadOnlyProperty(); } - + @ThreadConfined(type = ThreadConfined.ThreadType.JFX) boolean isStale() { return stale.get(); } - + private ImageGalleryController() { - + listeningEnabled.addListener((observable, oldValue, newValue) -> { //if we just turned on listening and a case is open and that case is not up to date if (newValue && !oldValue && Case.existsCurrentCase() && ImageGalleryModule.isDrawableDBStale(Case.getCurrentCase())) { @@ -207,28 +209,28 @@ public final class ImageGalleryController { queueDBWorkerTask(new CopyAnalyzedFiles()); } }); - + groupManager.getAnalyzedGroups().addListener((Observable o) -> { if (Case.isCaseOpen()) { checkForGroups(); } }); - + groupManager.getUnSeenGroups().addListener((Observable observable) -> { //if there are unseen groups and none being viewed if (groupManager.getUnSeenGroups().isEmpty() == false && (getViewState() == null || getViewState().getGroup() == null)) { advance(GroupViewState.tile(groupManager.getUnSeenGroups().get(0))); } }); - + viewState().addListener((Observable observable) -> { selectionModel.clearSelection(); }); - + regroupDisabled.addListener((Observable observable) -> { checkForGroups(); }); - + IngestManager.getInstance().addIngestModuleEventListener((PropertyChangeEvent evt) -> { Platform.runLater(this::updateRegroupDisabled); }); @@ -237,27 +239,27 @@ public final class ImageGalleryController { }); // metaDataCollapsed.bind(Toolbar.getDefault().showMetaDataProperty()); } - + public ReadOnlyBooleanProperty getCanAdvance() { return historyManager.getCanAdvance(); } - + public ReadOnlyBooleanProperty getCanRetreat() { return historyManager.getCanRetreat(); } - + public void advance(GroupViewState newState) { historyManager.advance(newState); } - + public GroupViewState advance() { return historyManager.advance(); } - + public GroupViewState retreat() { return historyManager.retreat(); } - + private void updateRegroupDisabled() { regroupDisabled.set(getFileUpdateQueueSizeProperty().get() > 0 || IngestManager.getInstance().isIngestRunning()); } @@ -279,7 +281,7 @@ public final class ImageGalleryController { new NoGroupsDialog("No groups are fully analyzed yet, but ingest is still ongoing. Please Wait.", new ProgressIndicator())); } - + } else if (getFileUpdateQueueSizeProperty().get() > 0) { replaceNotification(fullUIStackPane, new NoGroupsDialog("No groups are fully analyzed yet, but image / video data is still being populated. Please Wait.", @@ -293,19 +295,19 @@ public final class ImageGalleryController { replaceNotification(fullUIStackPane, new NoGroupsDialog("There are no images/videos in the added datasources.")); } - + } else if (!groupManager.isRegrouping()) { replaceNotification(centralStackPane, new NoGroupsDialog("There are no fully analyzed groups to display:" + " the current Group By setting resulted in no groups, " + "or no groups are fully analyzed but ingest is not running.")); } - + } else { clearNotification(); } } - + private void clearNotification() { //remove the ingest spinner if (fullUIStackPane != null) { @@ -316,27 +318,27 @@ public final class ImageGalleryController { centralStackPane.getChildren().remove(infoOverlay); } } - + private void replaceNotification(StackPane stackPane, Node newNode) { clearNotification(); - + infoOverlay = new StackPane(infoOverLayBackground, newNode); if (stackPane != null) { stackPane.getChildren().add(infoOverlay); } } - + private void restartWorker() { if (dbWorkerThread != null) { // Keep using the same worker thread if one exists return; } dbWorkerThread = new DBWorkerThread(); - + getFileUpdateQueueSizeProperty().addListener((Observable o) -> { Platform.runLater(this::updateRegroupDisabled); }); - + Thread th = new Thread(dbWorkerThread, "DB-Worker-Thread"); th.setDaemon(false); // we want it to go away when it is done th.start(); @@ -351,7 +353,7 @@ public final class ImageGalleryController { if (Objects.nonNull(theNewCase)) { this.sleuthKitCase = theNewCase.getSleuthkitCase(); this.db = DrawableDB.getDrawableDB(ImageGalleryModule.getModuleOutputDir(theNewCase), this); - + setListeningEnabled(ImageGalleryModule.isEnabledforCase(theNewCase)); setStale(ImageGalleryModule.isDrawableDBStale(theNewCase)); @@ -385,7 +387,7 @@ public final class ImageGalleryController { tagsManager.clearFollowUpTagName(); tagsManager.unregisterListener(groupManager); tagsManager.unregisterListener(categoryManager); - + Toolbar.getDefault(this).reset(); groupManager.clear(); if (db != null) { @@ -407,21 +409,21 @@ public final class ImageGalleryController { } dbWorkerThread.addTask(innerTask); } - + public DrawableFile getFileFromId(Long fileID) throws TskCoreException { return db.getFileFromID(fileID); } - + public void setStacks(StackPane fullUIStack, StackPane centralStack) { fullUIStackPane = fullUIStack; this.centralStackPane = centralStack; Platform.runLater(this::checkForGroups); } - + public ReadOnlyIntegerProperty getFileUpdateQueueSizeProperty() { return queueSizeProperty.getReadOnlyProperty(); } - + public ReadOnlyDoubleProperty regroupProgress() { return groupManager.regroupProgress(); } @@ -440,6 +442,10 @@ public final class ImageGalleryController { case CONTENT_CHANGED: //TODO: do we need to do anything here? -jm case DATA_ADDED: + ModuleDataEvent oldValue = (ModuleDataEvent) evt.getOldValue(); + if ("TagAction".equals(oldValue.getModuleName()) && oldValue.getArtifactType() == BlackboardArtifact.ARTIFACT_TYPE.TSK_TAG_FILE) { + getTagsManager().fireChange(Collections.singleton(-1L)); + } /* we could listen to DATA events and progressivly * update files, and get data from DataSource ingest * modules, but given that most modules don't post new @@ -505,11 +511,11 @@ public final class ImageGalleryController { } }); } - + public HashSetManager getHashSetManager() { return hashSetManager; } - + public CategoryManager getCategoryManager() { return categoryManager; } @@ -517,7 +523,7 @@ public final class ImageGalleryController { public DrawableTagsManager getTagsManager() { return tagsManager; } - + public DrawableTagsManager getTagsManager() { return tagsManager; } @@ -558,7 +564,7 @@ public final class ImageGalleryController { queueSizeProperty.set(workQueue.size()); }); } - + @Override public void run() { @@ -569,22 +575,22 @@ public final class ImageGalleryController { } try { InnerTask it = workQueue.take(); - + if (it.cancelled == false) { it.run(); } - + Platform.runLater(() -> { queueSizeProperty.set(workQueue.size()); }); - + } catch (InterruptedException ex) { Exceptions.printStackTrace(ex); } } } } - + public synchronized SleuthkitCase getSleuthKitCase() { return sleuthKitCase; } @@ -593,55 +599,55 @@ public final class ImageGalleryController { * Abstract base class for task to be done on {@link DBWorkerThread} */ static public abstract class InnerTask implements Runnable { - + public double getProgress() { return progress.get(); } - + public final void updateProgress(Double workDone) { this.progress.set(workDone); } - + public String getMessage() { return message.get(); } - + public final void updateMessage(String Status) { this.message.set(Status); } SimpleObjectProperty state = new SimpleObjectProperty<>(Worker.State.READY); SimpleDoubleProperty progress = new SimpleDoubleProperty(this, "pregress"); SimpleStringProperty message = new SimpleStringProperty(this, "status"); - + public SimpleDoubleProperty progressProperty() { return progress; } - + public SimpleStringProperty messageProperty() { return message; } - + public Worker.State getState() { return state.get(); } - + protected void updateState(Worker.State newState) { state.set(newState); } - + public ReadOnlyObjectProperty stateProperty() { return new ReadOnlyObjectWrapper<>(state.get()); } - + protected InnerTask() { } - + protected volatile boolean cancelled = false; - + public void cancel() { updateState(Worker.State.CANCELLED); } - + protected boolean isCancelled() { return getState() == Worker.State.CANCELLED; } @@ -651,25 +657,25 @@ public final class ImageGalleryController { * Abstract base class for tasks associated with a file in the database */ static public abstract class FileTask extends InnerTask { - + private final AbstractFile file; - + public AbstractFile getFile() { return file; } - + public FileTask(AbstractFile f) { super(); this.file = f; } - + } /** * task that updates one file in database with results from ingest */ private class UpdateFileTask extends FileTask { - + public UpdateFileTask(AbstractFile f) { super(f); } @@ -696,7 +702,7 @@ public final class ImageGalleryController { * task that updates one file in database with results from ingest */ private class RemoveFileTask extends FileTask { - + public RemoveFileTask(AbstractFile f) { super(f); } @@ -715,7 +721,7 @@ public final class ImageGalleryController { Logger.getLogger(RemoveFileTask.class.getName()).log(Level.SEVERE, "Case was closed out from underneath RemoveFile task"); } } - + } } @@ -727,16 +733,16 @@ public final class ImageGalleryController { * adds them to the Drawable DB */ private class CopyAnalyzedFiles extends InnerTask { - + final private String DRAWABLE_QUERY = "name LIKE '%." + StringUtils.join(ImageGalleryModule.getAllSupportedExtensions(), "' or name LIKE '%.") + "'"; - + private ProgressHandle progressHandle = ProgressHandleFactory.createHandle("populating analyzed image/video database"); - + @Override public void run() { progressHandle.start(); updateMessage("populating analyzed image/video database"); - + try { //grab all files with supported extension or detected mime types final List files = getSleuthKitCase().findAllFilesWhere(DRAWABLE_QUERY + " or tsk_files.obj_id in (select tsk_files.obj_id from tsk_files , blackboard_artifacts, blackboard_attributes" @@ -746,7 +752,7 @@ public final class ImageGalleryController { + " and blackboard_attributes.attribute_type_id = " + BlackboardAttribute.ATTRIBUTE_TYPE.TSK_FILE_TYPE_SIG.getTypeID() + " and blackboard_attributes.value_text in ('" + StringUtils.join(ImageGalleryModule.getSupportedMimes(), "','") + "'))"); progressHandle.switchToDeterminate(files.size()); - + updateProgress(0.0); //do in transaction @@ -760,7 +766,7 @@ public final class ImageGalleryController { } final Boolean hasMimeType = ImageGalleryModule.hasSupportedMimeType(f); final boolean known = f.getKnown() == TskData.FileKnown.KNOWN; - + if (known) { db.removeFile(f.getId(), tr); //remove known files } else { @@ -780,38 +786,38 @@ public final class ImageGalleryController { } } } - + units++; final int prog = units; progressHandle.progress(f.getName(), units); updateProgress(prog - 1 / (double) files.size()); updateMessage(f.getName()); } - + progressHandle.finish(); - + progressHandle = ProgressHandleFactory.createHandle("commiting image/video database"); updateMessage("commiting image/video database"); updateProgress(1.0); - + progressHandle.start(); db.commitTransaction(tr, true); - + } catch (TskCoreException ex) { Logger.getLogger(CopyAnalyzedFiles.class.getName()).log(Level.WARNING, "failed to transfer all database contents", ex); } catch (IllegalStateException ex) { Logger.getLogger(CopyAnalyzedFiles.class.getName()).log(Level.SEVERE, "Case was closed out from underneath CopyDataSource task", ex); } - + progressHandle.finish(); - + updateMessage( ""); updateProgress( -1.0); setStale(false); } - + } /** @@ -822,7 +828,7 @@ public final class ImageGalleryController { * netbeans and ImageGallery progress/status */ class PrePopulateDataSourceFiles extends InnerTask { - + private final Content dataSource; /** @@ -832,7 +838,7 @@ public final class ImageGalleryController { */ // (name like '.jpg' or name like '.png' ...) private final String DRAWABLE_QUERY = "(name LIKE '%." + StringUtils.join(ImageGalleryModule.getAllSupportedExtensions(), "' or name LIKE '%.") + "') "; - + private ProgressHandle progressHandle = ProgressHandleFactory.createHandle("prepopulating image/video database"); /** @@ -858,7 +864,7 @@ public final class ImageGalleryController { final List files; try { List fsObjIds = new ArrayList<>(); - + String fsQuery; if (dataSource instanceof Image) { Image image = (Image) dataSource; @@ -872,7 +878,7 @@ public final class ImageGalleryController { else { fsQuery = "(fs_obj_id IS NULL) "; } - + files = getSleuthKitCase().findAllFilesWhere(fsQuery + " and " + DRAWABLE_QUERY); progressHandle.switchToDeterminate(files.size()); @@ -890,21 +896,21 @@ public final class ImageGalleryController { final int prog = units; progressHandle.progress(f.getName(), units); } - + progressHandle.finish(); progressHandle = ProgressHandleFactory.createHandle("commiting image/video database"); - + progressHandle.start(); db.commitTransaction(tr, false); - + } catch (TskCoreException ex) { Logger.getLogger(PrePopulateDataSourceFiles.class.getName()).log(Level.WARNING, "failed to transfer all database contents", ex); } catch (IllegalStateException | NullPointerException ex) { Logger.getLogger(PrePopulateDataSourceFiles.class.getName()).log(Level.WARNING, "Case was closed out from underneath prepopulating database"); } - + progressHandle.finish(); } } - + } diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/Category.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/Category.java index 7cae09067f..d2160e9196 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/Category.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/Category.java @@ -53,8 +53,12 @@ public enum Category { return nameMap.containsKey(tName); } - public static boolean isCategoryTagName(TagName tName) { - return nameMap.containsKey(tName.getDisplayName()); + public static boolean isNotCategoryTagName(TagName tName) { + return isNotCategoryName(tName.getDisplayName()); + } + + public static boolean isNotCategoryName(String tName) { + return nameMap.containsKey(tName) == false; } public static boolean isNotCategoryName(String tName) { diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/GroupManager.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/GroupManager.java index 61281a519c..921cd9b8ff 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/GroupManager.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/GroupManager.java @@ -63,6 +63,7 @@ import org.sleuthkit.autopsy.events.ContentTagAddedEvent; import org.sleuthkit.autopsy.events.ContentTagDeletedEvent; import org.sleuthkit.autopsy.imagegallery.ImageGalleryController; import org.sleuthkit.autopsy.imagegallery.ImageGalleryModule; +import org.sleuthkit.autopsy.imagegallery.TagsChangeEvent; import org.sleuthkit.autopsy.imagegallery.datamodel.Category; import org.sleuthkit.autopsy.imagegallery.datamodel.CategoryManager; import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableAttribute; @@ -556,6 +557,15 @@ public class GroupManager { return regroupProgress.getReadOnlyProperty(); } + @Subscribe + public void handleAutopsyTagChange(TagsChangeEvent evt) { + if (groupBy == DrawableAttribute.TAGS + && evt.getFileIDs().size() == 1 + && evt.getFileIDs().contains(-1L)) { + regroup(groupBy, sortBy, sortOrder, Boolean.TRUE); + } + } + @Subscribe public void handleTagAdded(ContentTagAddedEvent evt) { GroupKey newGroupKey = null; From 1f813a6708af73e555fb7ccd3cec2e414b604d2c Mon Sep 17 00:00:00 2001 From: jmillman Date: Wed, 17 Jun 2015 17:42:00 -0400 Subject: [PATCH 34/56] more work to keep autopsy and ImageGallery tags in sync add setFiles method to DrawableGroup; don't clear groups from GroupMap except for CaseChange; reuse groups via setFiles method when regrouping reselect group in navpanel after regroup --- .../imagegallery/DrawableTagsManager.java | 2 +- .../datamodel/grouping/DrawableGroup.java | 6 +++-- .../datamodel/grouping/GroupManager.java | 22 ++++++------------- 3 files changed, 12 insertions(+), 18 deletions(-) diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/DrawableTagsManager.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/DrawableTagsManager.java index 2639de7617..149c7fd888 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/DrawableTagsManager.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/DrawableTagsManager.java @@ -1,7 +1,7 @@ /* * Autopsy Forensic Browser * - * Copyright 2013 Basis Technology Corp. + * Copyright 2013-15 Basis Technology Corp. * Contact: carrier sleuthkit org * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/DrawableGroup.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/DrawableGroup.java index ac0493d75e..6fdc9c236a 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/DrawableGroup.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/DrawableGroup.java @@ -165,11 +165,13 @@ public class DrawableGroup implements Comparable { // By default, sort by group key name @Override - public int compareTo(DrawableGroup other) { + public int compareTo(DrawableGroup other + ) { return this.groupKey.getValueDisplayName().compareTo(other.groupKey.getValueDisplayName()); } - void setSeen(boolean isSeen) { + void setSeen(boolean isSeen + ) { this.seen.set(isSeen); } diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/GroupManager.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/GroupManager.java index 921cd9b8ff..d373e29728 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/GroupManager.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/GroupManager.java @@ -200,21 +200,7 @@ public class GroupManager { @Nullable public DrawableGroup getGroupForKey(@Nonnull GroupKey groupKey) { synchronized (groupMap) { - if (groupKey.getAttribute() == DrawableAttribute.TAGS) { - - System.out.println(groupKey); -// @SuppressWarnings("unchecked") -// GroupKey tagKey = (GroupKey) groupKey; -// -// return groupMap.keySet().stream() -// .filter((GroupKey t) -> t.getAttribute() == DrawableAttribute.TAGS) -// .map((GroupKey t) -> (GroupKey) t) -// .filter(t -> tagKey.getValue().getDisplayName().equals(t.getValue().getDisplayName())) -// .findFirst().map(groupMap::get).orElse(null); - - } //else { return groupMap.get(groupKey); -// } } } @@ -258,15 +244,19 @@ public class GroupManager { /** * 'mark' the given group as seen. This removes it from the queue of * groups + * files. public DrawableGroup makeGroup(GroupKey groupKey, Set files) { Set newFiles = ObjectUtils.defaultIfNull(files, new HashSet()); + } + * groups * to review, and is persisted in the drawable db. * * @param group the {@link DrawableGroup} to mark as seen */ @ThreadConfined(type = ThreadType.JFX) - public void markGroupSeen(DrawableGroup group, boolean seen) { + public void markGroupSeen(DrawableGroup group, boolean seen + ) { db.markGroupSeen(group.getGroupKey(), seen); group.setSeen(seen); if (seen) { @@ -546,6 +536,7 @@ public class GroupManager { unmodifiableUnSeenGroups.setComparator(sortBy.getGrpComparator(sortOrder)); }); } + } /** @@ -705,6 +696,7 @@ public class GroupManager { LOGGER.log(Level.SEVERE, "failed to get files for group: " + groupKey.getAttribute().attrName.toString() + " = " + groupKey.getValue(), ex); } } + } return null; } From e336dccfb2968b4a995d3bbeab0d2933d6264bec Mon Sep 17 00:00:00 2001 From: jmillman Date: Thu, 18 Jun 2015 11:39:16 -0400 Subject: [PATCH 35/56] refactor in GroupManager, to make logic and flow cleaner split FileUpdateEvent handlers to seperate update and removed methods name DbWorkerThread, Thread --- .../imagegallery/ImageGalleryController.java | 218 +++++++++--------- .../datamodel/grouping/DrawableGroup.java | 6 +- .../datamodel/grouping/GroupManager.java | 58 ++++- 3 files changed, 160 insertions(+), 122 deletions(-) diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java index 907ef4556d..3bb7f83f97 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java @@ -86,25 +86,25 @@ import org.sleuthkit.datamodel.TskData; * control. */ public final class ImageGalleryController { - + private static final Logger LOGGER = Logger.getLogger(ImageGalleryController.class.getName()); - + private final Region infoOverLayBackground = new Region() { { setBackground(new Background(new BackgroundFill(Color.GREY, CornerRadii.EMPTY, Insets.EMPTY))); setOpacity(.4); } }; - + private static ImageGalleryController instance; - + public static synchronized ImageGalleryController getDefault() { if (instance == null) { instance = new ImageGalleryController(); } return instance; } - + private final History historyManager = new History<>(); /** @@ -112,75 +112,75 @@ public final class ImageGalleryController { * not listen to speed up ingest */ private final SimpleBooleanProperty listeningEnabled = new SimpleBooleanProperty(false); - + private final ReadOnlyIntegerWrapper queueSizeProperty = new ReadOnlyIntegerWrapper(0); - + private final ReadOnlyBooleanWrapper regroupDisabled = new ReadOnlyBooleanWrapper(false); - + @ThreadConfined(type = ThreadConfined.ThreadType.JFX) private final ReadOnlyBooleanWrapper stale = new ReadOnlyBooleanWrapper(false); - + private final ReadOnlyBooleanWrapper metaDataCollapsed = new ReadOnlyBooleanWrapper(false); - + private final FileIDSelectionModel selectionModel = FileIDSelectionModel.getInstance(); - + private DBWorkerThread dbWorkerThread; - + private DrawableDB db; - + private final GroupManager groupManager = new GroupManager(this); private final HashSetManager hashSetManager = new HashSetManager(); private final CategoryManager categoryManager = new CategoryManager(this); private final DrawableTagsManager tagsManager = new DrawableTagsManager(null); - + private StackPane fullUIStackPane; - + private StackPane centralStackPane; - + private Node infoOverlay; private SleuthkitCase sleuthKitCase; - + public ReadOnlyBooleanProperty getMetaDataCollapsed() { return metaDataCollapsed.getReadOnlyProperty(); } - + public void setMetaDataCollapsed(Boolean metaDataCollapsed) { this.metaDataCollapsed.set(metaDataCollapsed); } - + private GroupViewState getViewState() { return historyManager.getCurrentState(); } - + public ReadOnlyBooleanProperty regroupDisabled() { return regroupDisabled.getReadOnlyProperty(); } - + public ReadOnlyObjectProperty viewState() { return historyManager.currentState(); } - + public synchronized FileIDSelectionModel getSelectionModel() { - + return selectionModel; } - + public GroupManager getGroupManager() { return groupManager; } - + public DrawableDB getDatabase() { return db; } - + synchronized public void setListeningEnabled(boolean enabled) { listeningEnabled.set(enabled); } - + synchronized boolean isListeningEnabled() { return listeningEnabled.get(); } - + @ThreadConfined(type = ThreadConfined.ThreadType.ANY) void setStale(Boolean b) { Platform.runLater(() -> { @@ -190,18 +190,18 @@ public final class ImageGalleryController { new PerCaseProperties(Case.getCurrentCase()).setConfigSetting(ImageGalleryModule.getModuleName(), PerCaseProperties.STALE, b.toString()); } } - + public ReadOnlyBooleanProperty stale() { return stale.getReadOnlyProperty(); } - + @ThreadConfined(type = ThreadConfined.ThreadType.JFX) boolean isStale() { return stale.get(); } - + private ImageGalleryController() { - + listeningEnabled.addListener((observable, oldValue, newValue) -> { //if we just turned on listening and a case is open and that case is not up to date if (newValue && !oldValue && Case.existsCurrentCase() && ImageGalleryModule.isDrawableDBStale(Case.getCurrentCase())) { @@ -209,28 +209,28 @@ public final class ImageGalleryController { queueDBWorkerTask(new CopyAnalyzedFiles()); } }); - + groupManager.getAnalyzedGroups().addListener((Observable o) -> { if (Case.isCaseOpen()) { checkForGroups(); } }); - + groupManager.getUnSeenGroups().addListener((Observable observable) -> { //if there are unseen groups and none being viewed if (groupManager.getUnSeenGroups().isEmpty() == false && (getViewState() == null || getViewState().getGroup() == null)) { advance(GroupViewState.tile(groupManager.getUnSeenGroups().get(0))); } }); - + viewState().addListener((Observable observable) -> { selectionModel.clearSelection(); }); - + regroupDisabled.addListener((Observable observable) -> { checkForGroups(); }); - + IngestManager.getInstance().addIngestModuleEventListener((PropertyChangeEvent evt) -> { Platform.runLater(this::updateRegroupDisabled); }); @@ -239,27 +239,27 @@ public final class ImageGalleryController { }); // metaDataCollapsed.bind(Toolbar.getDefault().showMetaDataProperty()); } - + public ReadOnlyBooleanProperty getCanAdvance() { return historyManager.getCanAdvance(); } - + public ReadOnlyBooleanProperty getCanRetreat() { return historyManager.getCanRetreat(); } - + public void advance(GroupViewState newState) { historyManager.advance(newState); } - + public GroupViewState advance() { return historyManager.advance(); } - + public GroupViewState retreat() { return historyManager.retreat(); } - + private void updateRegroupDisabled() { regroupDisabled.set(getFileUpdateQueueSizeProperty().get() > 0 || IngestManager.getInstance().isIngestRunning()); } @@ -281,7 +281,7 @@ public final class ImageGalleryController { new NoGroupsDialog("No groups are fully analyzed yet, but ingest is still ongoing. Please Wait.", new ProgressIndicator())); } - + } else if (getFileUpdateQueueSizeProperty().get() > 0) { replaceNotification(fullUIStackPane, new NoGroupsDialog("No groups are fully analyzed yet, but image / video data is still being populated. Please Wait.", @@ -295,19 +295,19 @@ public final class ImageGalleryController { replaceNotification(fullUIStackPane, new NoGroupsDialog("There are no images/videos in the added datasources.")); } - + } else if (!groupManager.isRegrouping()) { replaceNotification(centralStackPane, new NoGroupsDialog("There are no fully analyzed groups to display:" + " the current Group By setting resulted in no groups, " + "or no groups are fully analyzed but ingest is not running.")); } - + } else { clearNotification(); } } - + private void clearNotification() { //remove the ingest spinner if (fullUIStackPane != null) { @@ -318,27 +318,27 @@ public final class ImageGalleryController { centralStackPane.getChildren().remove(infoOverlay); } } - + private void replaceNotification(StackPane stackPane, Node newNode) { clearNotification(); - + infoOverlay = new StackPane(infoOverLayBackground, newNode); if (stackPane != null) { stackPane.getChildren().add(infoOverlay); } } - + private void restartWorker() { if (dbWorkerThread != null) { // Keep using the same worker thread if one exists return; } dbWorkerThread = new DBWorkerThread(); - + getFileUpdateQueueSizeProperty().addListener((Observable o) -> { Platform.runLater(this::updateRegroupDisabled); }); - + Thread th = new Thread(dbWorkerThread, "DB-Worker-Thread"); th.setDaemon(false); // we want it to go away when it is done th.start(); @@ -353,7 +353,7 @@ public final class ImageGalleryController { if (Objects.nonNull(theNewCase)) { this.sleuthKitCase = theNewCase.getSleuthkitCase(); this.db = DrawableDB.getDrawableDB(ImageGalleryModule.getModuleOutputDir(theNewCase), this); - + setListeningEnabled(ImageGalleryModule.isEnabledforCase(theNewCase)); setStale(ImageGalleryModule.isDrawableDBStale(theNewCase)); @@ -387,7 +387,7 @@ public final class ImageGalleryController { tagsManager.clearFollowUpTagName(); tagsManager.unregisterListener(groupManager); tagsManager.unregisterListener(categoryManager); - + Toolbar.getDefault(this).reset(); groupManager.clear(); if (db != null) { @@ -409,21 +409,21 @@ public final class ImageGalleryController { } dbWorkerThread.addTask(innerTask); } - + public DrawableFile getFileFromId(Long fileID) throws TskCoreException { return db.getFileFromID(fileID); } - + public void setStacks(StackPane fullUIStack, StackPane centralStack) { fullUIStackPane = fullUIStack; this.centralStackPane = centralStack; Platform.runLater(this::checkForGroups); } - + public ReadOnlyIntegerProperty getFileUpdateQueueSizeProperty() { return queueSizeProperty.getReadOnlyProperty(); } - + public ReadOnlyDoubleProperty regroupProgress() { return groupManager.regroupProgress(); } @@ -511,11 +511,11 @@ public final class ImageGalleryController { } }); } - + public HashSetManager getHashSetManager() { return hashSetManager; } - + public CategoryManager getCategoryManager() { return categoryManager; } @@ -523,7 +523,7 @@ public final class ImageGalleryController { public DrawableTagsManager getTagsManager() { return tagsManager; } - + public DrawableTagsManager getTagsManager() { return tagsManager; } @@ -564,7 +564,7 @@ public final class ImageGalleryController { queueSizeProperty.set(workQueue.size()); }); } - + @Override public void run() { @@ -575,22 +575,22 @@ public final class ImageGalleryController { } try { InnerTask it = workQueue.take(); - + if (it.cancelled == false) { it.run(); } - + Platform.runLater(() -> { queueSizeProperty.set(workQueue.size()); }); - + } catch (InterruptedException ex) { Exceptions.printStackTrace(ex); } } } } - + public synchronized SleuthkitCase getSleuthKitCase() { return sleuthKitCase; } @@ -599,55 +599,55 @@ public final class ImageGalleryController { * Abstract base class for task to be done on {@link DBWorkerThread} */ static public abstract class InnerTask implements Runnable { - + public double getProgress() { return progress.get(); } - + public final void updateProgress(Double workDone) { this.progress.set(workDone); } - + public String getMessage() { return message.get(); } - + public final void updateMessage(String Status) { this.message.set(Status); } SimpleObjectProperty state = new SimpleObjectProperty<>(Worker.State.READY); SimpleDoubleProperty progress = new SimpleDoubleProperty(this, "pregress"); SimpleStringProperty message = new SimpleStringProperty(this, "status"); - + public SimpleDoubleProperty progressProperty() { return progress; } - + public SimpleStringProperty messageProperty() { return message; } - + public Worker.State getState() { return state.get(); } - + protected void updateState(Worker.State newState) { state.set(newState); } - + public ReadOnlyObjectProperty stateProperty() { return new ReadOnlyObjectWrapper<>(state.get()); } - + protected InnerTask() { } - + protected volatile boolean cancelled = false; - + public void cancel() { updateState(Worker.State.CANCELLED); } - + protected boolean isCancelled() { return getState() == Worker.State.CANCELLED; } @@ -657,25 +657,25 @@ public final class ImageGalleryController { * Abstract base class for tasks associated with a file in the database */ static public abstract class FileTask extends InnerTask { - + private final AbstractFile file; - + public AbstractFile getFile() { return file; } - + public FileTask(AbstractFile f) { super(); this.file = f; } - + } /** * task that updates one file in database with results from ingest */ private class UpdateFileTask extends FileTask { - + public UpdateFileTask(AbstractFile f) { super(f); } @@ -702,7 +702,7 @@ public final class ImageGalleryController { * task that updates one file in database with results from ingest */ private class RemoveFileTask extends FileTask { - + public RemoveFileTask(AbstractFile f) { super(f); } @@ -721,7 +721,7 @@ public final class ImageGalleryController { Logger.getLogger(RemoveFileTask.class.getName()).log(Level.SEVERE, "Case was closed out from underneath RemoveFile task"); } } - + } } @@ -733,16 +733,16 @@ public final class ImageGalleryController { * adds them to the Drawable DB */ private class CopyAnalyzedFiles extends InnerTask { - + final private String DRAWABLE_QUERY = "name LIKE '%." + StringUtils.join(ImageGalleryModule.getAllSupportedExtensions(), "' or name LIKE '%.") + "'"; - + private ProgressHandle progressHandle = ProgressHandleFactory.createHandle("populating analyzed image/video database"); - + @Override public void run() { progressHandle.start(); updateMessage("populating analyzed image/video database"); - + try { //grab all files with supported extension or detected mime types final List files = getSleuthKitCase().findAllFilesWhere(DRAWABLE_QUERY + " or tsk_files.obj_id in (select tsk_files.obj_id from tsk_files , blackboard_artifacts, blackboard_attributes" @@ -752,7 +752,7 @@ public final class ImageGalleryController { + " and blackboard_attributes.attribute_type_id = " + BlackboardAttribute.ATTRIBUTE_TYPE.TSK_FILE_TYPE_SIG.getTypeID() + " and blackboard_attributes.value_text in ('" + StringUtils.join(ImageGalleryModule.getSupportedMimes(), "','") + "'))"); progressHandle.switchToDeterminate(files.size()); - + updateProgress(0.0); //do in transaction @@ -766,7 +766,7 @@ public final class ImageGalleryController { } final Boolean hasMimeType = ImageGalleryModule.hasSupportedMimeType(f); final boolean known = f.getKnown() == TskData.FileKnown.KNOWN; - + if (known) { db.removeFile(f.getId(), tr); //remove known files } else { @@ -786,38 +786,38 @@ public final class ImageGalleryController { } } } - + units++; final int prog = units; progressHandle.progress(f.getName(), units); updateProgress(prog - 1 / (double) files.size()); updateMessage(f.getName()); } - + progressHandle.finish(); - + progressHandle = ProgressHandleFactory.createHandle("commiting image/video database"); updateMessage("commiting image/video database"); updateProgress(1.0); - + progressHandle.start(); db.commitTransaction(tr, true); - + } catch (TskCoreException ex) { Logger.getLogger(CopyAnalyzedFiles.class.getName()).log(Level.WARNING, "failed to transfer all database contents", ex); } catch (IllegalStateException ex) { Logger.getLogger(CopyAnalyzedFiles.class.getName()).log(Level.SEVERE, "Case was closed out from underneath CopyDataSource task", ex); } - + progressHandle.finish(); - + updateMessage( ""); updateProgress( -1.0); setStale(false); } - + } /** @@ -828,7 +828,7 @@ public final class ImageGalleryController { * netbeans and ImageGallery progress/status */ class PrePopulateDataSourceFiles extends InnerTask { - + private final Content dataSource; /** @@ -838,7 +838,7 @@ public final class ImageGalleryController { */ // (name like '.jpg' or name like '.png' ...) private final String DRAWABLE_QUERY = "(name LIKE '%." + StringUtils.join(ImageGalleryModule.getAllSupportedExtensions(), "' or name LIKE '%.") + "') "; - + private ProgressHandle progressHandle = ProgressHandleFactory.createHandle("prepopulating image/video database"); /** @@ -864,7 +864,7 @@ public final class ImageGalleryController { final List files; try { List fsObjIds = new ArrayList<>(); - + String fsQuery; if (dataSource instanceof Image) { Image image = (Image) dataSource; @@ -878,7 +878,7 @@ public final class ImageGalleryController { else { fsQuery = "(fs_obj_id IS NULL) "; } - + files = getSleuthKitCase().findAllFilesWhere(fsQuery + " and " + DRAWABLE_QUERY); progressHandle.switchToDeterminate(files.size()); @@ -896,21 +896,21 @@ public final class ImageGalleryController { final int prog = units; progressHandle.progress(f.getName(), units); } - + progressHandle.finish(); progressHandle = ProgressHandleFactory.createHandle("commiting image/video database"); - + progressHandle.start(); db.commitTransaction(tr, false); - + } catch (TskCoreException ex) { Logger.getLogger(PrePopulateDataSourceFiles.class.getName()).log(Level.WARNING, "failed to transfer all database contents", ex); } catch (IllegalStateException | NullPointerException ex) { Logger.getLogger(PrePopulateDataSourceFiles.class.getName()).log(Level.WARNING, "Case was closed out from underneath prepopulating database"); } - + progressHandle.finish(); } } - + } diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/DrawableGroup.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/DrawableGroup.java index 6fdc9c236a..ac0493d75e 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/DrawableGroup.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/DrawableGroup.java @@ -165,13 +165,11 @@ public class DrawableGroup implements Comparable { // By default, sort by group key name @Override - public int compareTo(DrawableGroup other - ) { + public int compareTo(DrawableGroup other) { return this.groupKey.getValueDisplayName().compareTo(other.groupKey.getValueDisplayName()); } - void setSeen(boolean isSeen - ) { + void setSeen(boolean isSeen) { this.seen.set(isSeen); } diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/GroupManager.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/GroupManager.java index d373e29728..edbe0c1ff9 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/GroupManager.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/GroupManager.java @@ -50,6 +50,7 @@ import javax.annotation.concurrent.GuardedBy; import javax.swing.SortOrder; import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.Validate; import org.apache.commons.lang3.concurrent.BasicThreadFactory; import org.netbeans.api.progress.ProgressHandle; import org.netbeans.api.progress.ProgressHandleFactory; @@ -255,6 +256,7 @@ public class GroupManager { * @param group the {@link DrawableGroup} to mark as seen */ @ThreadConfined(type = ThreadType.JFX) + public void markGroupSeen(DrawableGroup group, boolean seen) { public void markGroupSeen(DrawableGroup group, boolean seen ) { db.markGroupSeen(group.getGroupKey(), seen); @@ -292,8 +294,6 @@ public class GroupManager { if (unSeenGroups.contains(group)) { unSeenGroups.remove(group); } - public synchronized void populateAnalyzedGroup(final GroupKey groupKey, Set filesInGroup) { - private synchronized > void populateAnalyzedGroup(final GroupKey groupKey, Set filesInGroup, ReGroupTask task) { }); } } @@ -301,8 +301,6 @@ public class GroupManager { // It may be that this was the last unanalyzed file in the group, so test // whether the group is now fully analyzed. popuplateIfAnalyzed(groupKey, null); - public Set checkAnalyzed(final GroupKey groupKey) { - } return group; } @@ -536,7 +534,6 @@ public class GroupManager { unmodifiableUnSeenGroups.setComparator(sortBy.getGrpComparator(sortOrder)); }); } - } /** @@ -616,7 +613,6 @@ public class GroupManager { for (GroupKey gk : groupsForFile) { removeFromGroup(gk, fileId); - Set checkAnalyzed = checkAnalyzed(gk); } } } @@ -629,6 +625,8 @@ public class GroupManager { */ @Subscribe synchronized public void handleFileUpdate(Collection updatedFileIDs) { + Validate.isTrue(evt.getUpdateType() == FileUpdateEvent.UpdateType.UPDATE); + Collection fileIDs = evt.getFileIDs(); /** * TODO: is there a way to optimize this to avoid quering to db * so much. the problem is that as a new files are analyzed they @@ -682,6 +680,51 @@ public class GroupManager { markGroupSeen(group, newSeen); }); groupMap.put(groupKey, group); + } + Platform.runLater(() -> { + if (analyzedGroups.contains(group) == false) { + analyzedGroups.add(group); + } + markGroupSeen(group, groupSeen); + }); + return group; + } + } catch (TskCoreException ex) { + LOGGER.log(Level.SEVERE, "failed to get files for group: " + groupKey.getAttribute().attrName.toString() + " = " + groupKey.getValue(), ex); + } + } + + private void popuplateIfAnalyzed(GroupKey groupKey, ReGroupTask task) { + + if (Objects.nonNull(task) && (task.isCancelled())) { + /* if this method call is part of a ReGroupTask and that task is + * cancelled, no-op + * + * this allows us to stop if a regroup task has been cancelled (e.g. + * the user picked a different group by attribute, while the + * current task was still running) */ + } else { // no task or un-cancelled task + if ((groupKey.getAttribute() != DrawableAttribute.PATH) || db.isGroupAnalyzed(groupKey)) { + /* for attributes other than path we can't be sure a group is + * fully analyzed because we don't know all the files that + * will be a part of that group */ + + try { + Set fileIDs = getFileIDsInGroup(groupKey); + if (Objects.nonNull(fileIDs)) { + DrawableGroup group; + final boolean groupSeen = db.isGroupSeen(groupKey); + synchronized (groupMap) { + if (groupMap.containsKey(groupKey)) { + group = groupMap.get(groupKey); + group.setFiles(ObjectUtils.defaultIfNull(fileIDs, Collections.emptySet())); + } else { + + group = new DrawableGroup(groupKey, fileIDs, groupSeen); + group.seenProperty().addListener((observable, oldSeen, newSeen) -> { + markGroupSeen(group, newSeen); + }); + groupMap.put(groupKey, group); } } Platform.runLater(() -> { @@ -690,13 +733,11 @@ public class GroupManager { } markGroupSeen(group, groupSeen); }); - return group; } } catch (TskCoreException ex) { LOGGER.log(Level.SEVERE, "failed to get files for group: " + groupKey.getAttribute().attrName.toString() + " = " + groupKey.getValue(), ex); } } - } return null; } @@ -762,7 +803,6 @@ public class GroupManager { updateProgress(p, vals.size()); groupProgress.progress("regrouping files by " + groupBy.attrName.toString() + " : " + val, p); popuplateIfAnalyzed(new GroupKey(groupBy, val), this); - Set checkAnalyzed = checkAnalyzed(groupKey); } updateProgress(1, 1); From 5432309c2f35c84980d163bf992aa9955630f331 Mon Sep 17 00:00:00 2001 From: jmillman Date: Thu, 18 Jun 2015 13:51:37 -0400 Subject: [PATCH 36/56] rename method; add synchronization; remove singletonness from SummaryTablePane --- .../sleuthkit/autopsy/imagegallery/DrawableTagsManager.java | 4 ++-- .../autopsy/imagegallery/ImageGalleryController.java | 2 +- .../autopsy/imagegallery/actions/DeleteFollowUpTagAction.java | 2 +- .../autopsy/imagegallery/datamodel/CategoryManager.java | 1 + 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/DrawableTagsManager.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/DrawableTagsManager.java index 149c7fd888..7e0303fe4d 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/DrawableTagsManager.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/DrawableTagsManager.java @@ -78,7 +78,7 @@ public class DrawableTagsManager { } /** - * fire a CategoryChangeEvent with the given fileIDs + * fire a TagsChangeEvent with the given fileIDs * * @param fileIDs */ @@ -188,7 +188,7 @@ public class DrawableTagsManager { * had a chance to add that so, we fire these events and the tree * refreshes based on them. */ - static public void fireTagsChangedEvent() { + static public void refreshTagsInAutopsy() { IngestServices.getInstance().fireModuleDataEvent(new ModuleDataEvent("TagAction", BlackboardArtifact.ARTIFACT_TYPE.TSK_TAG_FILE)); //NON-NLS } diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java index 3bb7f83f97..1a5e254d98 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java @@ -367,7 +367,6 @@ public final class ImageGalleryController { tagsManager.setAutopsyTagsManager(theNewCase.getServices().getTagsManager()); tagsManager.registerListener(groupManager); tagsManager.registerListener(categoryManager); - } else { reset(); } @@ -445,6 +444,7 @@ public final class ImageGalleryController { ModuleDataEvent oldValue = (ModuleDataEvent) evt.getOldValue(); if ("TagAction".equals(oldValue.getModuleName()) && oldValue.getArtifactType() == BlackboardArtifact.ARTIFACT_TYPE.TSK_TAG_FILE) { getTagsManager().fireChange(Collections.singleton(-1L)); + getCategoryManager().invalidateCaches(); } /* we could listen to DATA events and progressivly * update files, and get data from DataSource ingest diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/DeleteFollowUpTagAction.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/DeleteFollowUpTagAction.java index 6a1a54c30d..bba6d5e4dc 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/DeleteFollowUpTagAction.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/DeleteFollowUpTagAction.java @@ -79,7 +79,7 @@ public class DeleteFollowUpTagAction extends Action { } } - DrawableTagsManager.fireTagsChangedEvent(); + DrawableTagsManager.refreshTagsInAutopsy(); //make sure rest of ui hears category change. groupManager.handleFileUpdate(FileUpdateEvent.newUpdateEvent(Collections.singleton(fileID), DrawableAttribute.TAGS)); diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/CategoryManager.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/CategoryManager.java index 551db0e6c6..5e9b407c56 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/CategoryManager.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/CategoryManager.java @@ -54,6 +54,7 @@ import org.sleuthkit.datamodel.TskCoreException; public class CategoryManager { private static final java.util.logging.Logger LOGGER = Logger.getLogger(CategoryManager.class.getName()); + private final ImageGalleryController controller; private final ImageGalleryController controller; From e126aee4cbbc2a1ea10e5d0e0bada3fb44069241 Mon Sep 17 00:00:00 2001 From: jmillman Date: Thu, 18 Jun 2015 16:57:28 -0400 Subject: [PATCH 37/56] new Tag event system --- .../imagegallery/DrawableTagsManager.java | 148 +++++++++++------- .../imagegallery/ImageGalleryController.java | 28 +++- .../actions/DeleteFollowUpTagAction.java | 70 ++++----- .../imagegallery/datamodel/Category.java | 3 + .../datamodel/grouping/GroupManager.java | 1 - .../gui/drawableviews/DrawableTileBase.java | 8 + 6 files changed, 157 insertions(+), 101 deletions(-) diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/DrawableTagsManager.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/DrawableTagsManager.java index 7e0303fe4d..add7065742 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/DrawableTagsManager.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/DrawableTagsManager.java @@ -45,6 +45,7 @@ public class DrawableTagsManager { private static final String FOLLOW_UP = "Follow Up"; + private Object autopsyTagsManagerLock = new Object(); private TagsManager autopsyTagsManager; /** Used to distribute {@link TagsChangeEvent}s */ @@ -64,26 +65,21 @@ public class DrawableTagsManager { * * @param autopsyTagsManager */ - public synchronized void setAutopsyTagsManager(TagsManager autopsyTagsManager) { - this.autopsyTagsManager = autopsyTagsManager; - clearFollowUpTagName(); + public void setAutopsyTagsManager(TagsManager autopsyTagsManager) { + synchronized (autopsyTagsManager) { + this.autopsyTagsManager = autopsyTagsManager; + clearFollowUpTagName(); + } } /** * Use when closing a case to make sure everything is re-initialized in the * next case. */ - public synchronized void clearFollowUpTagName() { - followUpTagName = null; - } - - /** - * fire a TagsChangeEvent with the given fileIDs - * - * @param fileIDs - */ - public final void fireChange(Collection fileIDs) { - tagsEventBus.post(new TagsChangeEvent(fileIDs)); + public void clearFollowUpTagName() { + synchronized (autopsyTagsManager) { + followUpTagName = null; + } } /** @@ -111,22 +107,26 @@ public class DrawableTagsManager { * * @throws TskCoreException */ - synchronized public TagName getFollowUpTagName() throws TskCoreException { - if (Objects.isNull(followUpTagName)) { - followUpTagName = getTagName(FOLLOW_UP); + public TagName getFollowUpTagName() throws TskCoreException { + synchronized (autopsyTagsManager) { + if (Objects.isNull(followUpTagName)) { + followUpTagName = getTagName(FOLLOW_UP); + } + return followUpTagName; } - return followUpTagName; } - synchronized public Collection getNonCategoryTagNames() { - try { - return autopsyTagsManager.getAllTagNames().stream() - .filter(Category::isCategoryTagName) - .collect(Collectors.toSet()); - } catch (TskCoreException | IllegalStateException ex) { - Logger.getLogger(DrawableTagsManager.class.getName()).log(Level.WARNING, "couldn't access case", ex); + public Collection getNonCategoryTagNames() { + synchronized (autopsyTagsManager) { + try { + return autopsyTagsManager.getAllTagNames().stream() + .filter(Category::isCategoryTagName) + .collect(Collectors.toSet()); + } catch (TskCoreException | IllegalStateException ex) { + Logger.getLogger(DrawableTagsManager.class.getName()).log(Level.WARNING, "couldn't access case", ex); + } + return Collections.emptySet(); } - return Collections.emptySet(); } /** @@ -139,29 +139,33 @@ public class DrawableTagsManager { * * @throws TskCoreException */ - public synchronized List getContentTagsByContent(Content content) throws TskCoreException { - return autopsyTagsManager.getContentTagsByContent(content); - } - - public synchronized TagName getTagName(String displayName) throws TskCoreException { - try { - for (TagName tn : autopsyTagsManager.getAllTagNames()) { - if (displayName.equals(tn.getDisplayName())) { - return tn; - } - } - try { - return autopsyTagsManager.addTagName(displayName); - } catch (TagsManager.TagNameAlreadyExistsException ex) { - throw new TskCoreException("tagame exists but wasn't found", ex); - } - } catch (IllegalStateException ex) { - Logger.getLogger(DrawableTagsManager.class.getName()).log(Level.SEVERE, "Case was closed out from underneath", ex); - throw new TskCoreException("Case was closed out from underneath", ex); + public List getContentTagsByContent(Content content) throws TskCoreException { + synchronized (autopsyTagsManager) { + return autopsyTagsManager.getContentTagsByContent(content); } } - public synchronized TagName getTagName(Category cat) { + public TagName getTagName(String displayName) throws TskCoreException { + synchronized (autopsyTagsManager) { + try { + for (TagName tn : autopsyTagsManager.getAllTagNames()) { + if (displayName.equals(tn.getDisplayName())) { + return tn; + } + } + try { + return autopsyTagsManager.addTagName(displayName); + } catch (TagsManager.TagNameAlreadyExistsException ex) { + throw new TskCoreException("tagame exists but wasn't found", ex); + } + } catch (IllegalStateException ex) { + Logger.getLogger(DrawableTagsManager.class.getName()).log(Level.SEVERE, "Case was closed out from underneath", ex); + throw new TskCoreException("Case was closed out from underneath", ex); + } + } + } + + public TagName getTagName(Category cat) { try { return getTagName(cat.getDisplayName()); } catch (TskCoreException ex) { @@ -169,12 +173,18 @@ public class DrawableTagsManager { } } - synchronized public void addContentTag(DrawableFile file, TagName tagName, String comment) throws TskCoreException { - autopsyTagsManager.addContentTag(file, tagName, comment); + public void addContentTag(DrawableFile file, TagName tagName, String comment) throws TskCoreException { + ContentTag addContentTag; + synchronized (autopsyTagsManager) { + addContentTag = autopsyTagsManager.addContentTag(file, tagName, comment); + } + fireTagAdded(addContentTag); } - synchronized public List getContentTagsByTagName(TagName t) throws TskCoreException { - return autopsyTagsManager.getContentTagsByTagName(t); + public List getContentTagsByTagName(TagName t) throws TskCoreException { + synchronized (autopsyTagsManager) { + return autopsyTagsManager.getContentTagsByTagName(t); + } } /** @@ -189,15 +199,43 @@ public class DrawableTagsManager { * refreshes based on them. */ static public void refreshTagsInAutopsy() { - IngestServices.getInstance().fireModuleDataEvent(new ModuleDataEvent("TagAction", BlackboardArtifact.ARTIFACT_TYPE.TSK_TAG_FILE)); //NON-NLS } - public synchronized List getAllTagNames() throws TskCoreException { - return autopsyTagsManager.getAllTagNames(); + public List getAllTagNames() throws TskCoreException { + synchronized (autopsyTagsManager) { + return autopsyTagsManager.getAllTagNames(); + } } - public synchronized List getTagNamesInUse() throws TskCoreException { - return autopsyTagsManager.getTagNamesInUse(); + public List getTagNamesInUse() throws TskCoreException { + synchronized (autopsyTagsManager) { + return autopsyTagsManager.getTagNamesInUse(); + } } + + public void fireTagAdded(ContentTag newTag) { + tagsEventBus.post(new TagsChangeEvent(Collections.singleton(newTag.getContent().getId()))); + } + + public void fireTagDeleted(ContentTag oldTag) { + tagsEventBus.post(new TagsChangeEvent(Collections.singleton(oldTag.getContent().getId()))); + } +// +// /** +// * fire a TagsChangeEvent with the given fileIDs +// * +// * @param fileIDs +// */ +// public final void fireChange(Collection fileIDs) { +// tagsEventBus.post(new TagsChangeEvent(fileIDs)); +// } + + public void deleteContentTag(ContentTag ct) throws TskCoreException { + synchronized (autopsyTagsManager) { + autopsyTagsManager.deleteContentTag(ct); + } + fireTagDeleted(ct); + } + } diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java index 1a5e254d98..76f94e2a92 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java @@ -61,6 +61,7 @@ import org.sleuthkit.autopsy.coreutils.ThreadConfined; import org.sleuthkit.autopsy.events.ContentTagAddedEvent; import org.sleuthkit.autopsy.events.ContentTagDeletedEvent; import org.sleuthkit.autopsy.imagegallery.datamodel.CategoryManager; +import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableAttribute; import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableDB; import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableFile; import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableTagsManager; @@ -70,11 +71,11 @@ import org.sleuthkit.autopsy.imagegallery.datamodel.grouping.GroupViewState; import org.sleuthkit.autopsy.imagegallery.gui.NoGroupsDialog; import org.sleuthkit.autopsy.imagegallery.gui.Toolbar; import org.sleuthkit.autopsy.ingest.IngestManager; -import org.sleuthkit.autopsy.ingest.ModuleDataEvent; import org.sleuthkit.datamodel.AbstractFile; import org.sleuthkit.datamodel.BlackboardArtifact; import org.sleuthkit.datamodel.BlackboardAttribute; import org.sleuthkit.datamodel.Content; +import org.sleuthkit.datamodel.ContentTag; import org.sleuthkit.datamodel.FileSystem; import org.sleuthkit.datamodel.Image; import org.sleuthkit.datamodel.SleuthkitCase; @@ -441,11 +442,6 @@ public final class ImageGalleryController { case CONTENT_CHANGED: //TODO: do we need to do anything here? -jm case DATA_ADDED: - ModuleDataEvent oldValue = (ModuleDataEvent) evt.getOldValue(); - if ("TagAction".equals(oldValue.getModuleName()) && oldValue.getArtifactType() == BlackboardArtifact.ARTIFACT_TYPE.TSK_TAG_FILE) { - getTagsManager().fireChange(Collections.singleton(-1L)); - getCategoryManager().invalidateCaches(); - } /* we could listen to DATA events and progressivly * update files, and get data from DataSource ingest * modules, but given that most modules don't post new @@ -496,6 +492,26 @@ public final class ImageGalleryController { setStale(true); } break; + case CONTENT_TAG_ADDED: + ContentTag newTag = (ContentTag) evt.getNewValue(); + if (Category.isCategoryTagName(newTag.getName())) { + new CategorizeAction(ImageGalleryController.this).addTag(newTag.getName(), ""); + } else { + getTagsManager().fireTagAdded(newTag); + } + break; + case CONTENT_TAG_DELETED: + ContentTag oldTag = (ContentTag) evt.getOldValue(); + final long fileID = oldTag.getContent().getId(); + if (getDatabase().isInDB(fileID)) { + if (Category.isCategoryTagName(oldTag.getName())) { + getCategoryManager().decrementCategoryCount(Category.fromTagName(oldTag.getName())); + getGroupManager().handleFileUpdate(FileUpdateEvent.newUpdateEvent(Collections.singleton(fileID), DrawableAttribute.CATEGORY)); + } else { + getTagsManager().fireTagDeleted(oldTag); + } + } + break; case CONTENT_TAG_ADDED: final ContentTagAddedEvent tagAddedEvent = (ContentTagAddedEvent) evt; if (getDatabase().isInDB((tagAddedEvent).getTag().getContent().getId())) { diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/DeleteFollowUpTagAction.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/DeleteFollowUpTagAction.java index bba6d5e4dc..98fdc316ad 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/DeleteFollowUpTagAction.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/DeleteFollowUpTagAction.java @@ -22,6 +22,7 @@ import java.util.Collections; import java.util.List; import java.util.logging.Level; import javafx.event.ActionEvent; +import javax.swing.SwingWorker; import org.controlsfx.control.action.Action; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.imagegallery.DrawableTagsManager; @@ -43,49 +44,40 @@ public class DeleteFollowUpTagAction extends Action { private static final Logger LOGGER = Logger.getLogger(DeleteFollowUpTagAction.class.getName()); private final long fileID; - private final DrawableFile file; - private final ImageGalleryController controller; - public DeleteFollowUpTagAction(ImageGalleryController controller, DrawableFile file) { + public DeleteFollowUpTagAction(final ImageGalleryController controller, final DrawableFile file) { super("Delete Follow Up Tag"); - this.controller = controller; - this.file = file; this.fileID = file.getId(); setEventHandler((ActionEvent t) -> { - deleteTag(); + new SwingWorker() { + + @Override + protected Void doInBackground() throws Exception { + final SleuthkitCase sleuthKitCase = controller.getSleuthKitCase(); + final GroupManager groupManager = controller.getGroupManager(); + final DrawableTagsManager tagsManager = controller.getTagsManager(); + + try { + final TagName followUpTagName = tagsManager.getFollowUpTagName(); + // remove file from old category group + groupManager.removeFromGroup(new GroupKey(DrawableAttribute.TAGS, followUpTagName), fileID); + + List contentTagsByContent = tagsManager.getContentTagsByContent(file); + for (ContentTag ct : contentTagsByContent) { + if (ct.getName().getDisplayName().equals(followUpTagName.getDisplayName())) { + tagsManager.deleteContentTag(ct); + } + } + + DrawableTagsManager.refreshTagsInAutopsy(); + //make sure rest of ui hears category change. + groupManager.handleFileUpdate(FileUpdateEvent.newUpdateEvent(Collections.singleton(fileID), DrawableAttribute.TAGS)); + } catch (TskCoreException ex) { + LOGGER.log(Level.SEVERE, "Failed to delete follow up tag.", ex); + } + return null; + } + }.execute(); }); } - - /** - * - * - * - */ - private void deleteTag() { - - final SleuthkitCase sleuthKitCase = controller.getSleuthKitCase(); - final GroupManager groupManager = controller.getGroupManager(); - final DrawableTagsManager tagsManager = controller.getTagsManager(); - - try { - final TagName followUpTagName = tagsManager.getFollowUpTagName(); - // remove file from old category group - groupManager.removeFromGroup(new GroupKey(DrawableAttribute.TAGS, followUpTagName), fileID); - - List contentTagsByContent = sleuthKitCase.getContentTagsByContent(file); - for (ContentTag ct : contentTagsByContent) { - if (ct.getName().getDisplayName().equals(followUpTagName.getDisplayName())) { - sleuthKitCase.deleteContentTag(ct); - } - } - - DrawableTagsManager.refreshTagsInAutopsy(); - - //make sure rest of ui hears category change. - groupManager.handleFileUpdate(FileUpdateEvent.newUpdateEvent(Collections.singleton(fileID), DrawableAttribute.TAGS)); - } catch (TskCoreException ex) { - LOGGER.log(Level.SEVERE, "Failed to delete follow up tag.", ex); - } - } - } diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/Category.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/Category.java index d2160e9196..4743e8b48e 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/Category.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/Category.java @@ -48,6 +48,9 @@ public enum Category { public static Category fromDisplayName(String displayName) { return nameMap.get(displayName); } + public static Category fromTagName(TagName tagName) { + return nameMap.get(tagName.getDisplayName()); + } public static boolean isCategoryName(String tName) { return nameMap.containsKey(tName); diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/GroupManager.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/GroupManager.java index edbe0c1ff9..f47feeb804 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/GroupManager.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/GroupManager.java @@ -691,7 +691,6 @@ public class GroupManager { } } catch (TskCoreException ex) { LOGGER.log(Level.SEVERE, "failed to get files for group: " + groupKey.getAttribute().attrName.toString() + " = " + groupKey.getValue(), ex); - } } private void popuplateIfAnalyzed(GroupKey groupKey, ReGroupTask task) { diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/DrawableTileBase.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/DrawableTileBase.java index f579a35aed..14b660410d 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/DrawableTileBase.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/DrawableTileBase.java @@ -349,6 +349,14 @@ public abstract class DrawableTileBase extends DrawableUIBase { return imageBorder; } + @Subscribe + @Override + synchronized public void handleTagsChanged(TagsChangeEvent evnt) { + if (fileID != null && (evnt.getFileIDs().contains(fileID) || evnt.getFileIDs().contains(-1L))) { + updateFollowUpIcon(); + } + } + @Subscribe @Override public void handleTagAdded(ContentTagAddedEvent evt) { From bc33284c68e55e3bb680b935975482e94c99fe21 Mon Sep 17 00:00:00 2001 From: jmillman Date: Thu, 18 Jun 2015 17:00:05 -0400 Subject: [PATCH 38/56] more granular synchronization in DrawableTagsManager --- .../imagegallery/DrawableTagsManager.java | 34 +++++++------------ 1 file changed, 12 insertions(+), 22 deletions(-) diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/DrawableTagsManager.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/DrawableTagsManager.java index add7065742..13455d2fb1 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/DrawableTagsManager.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/DrawableTagsManager.java @@ -45,7 +45,7 @@ public class DrawableTagsManager { private static final String FOLLOW_UP = "Follow Up"; - private Object autopsyTagsManagerLock = new Object(); + final private Object autopsyTagsManagerLock = new Object(); private TagsManager autopsyTagsManager; /** Used to distribute {@link TagsChangeEvent}s */ @@ -66,7 +66,7 @@ public class DrawableTagsManager { * @param autopsyTagsManager */ public void setAutopsyTagsManager(TagsManager autopsyTagsManager) { - synchronized (autopsyTagsManager) { + synchronized (autopsyTagsManagerLock) { this.autopsyTagsManager = autopsyTagsManager; clearFollowUpTagName(); } @@ -77,7 +77,7 @@ public class DrawableTagsManager { * next case. */ public void clearFollowUpTagName() { - synchronized (autopsyTagsManager) { + synchronized (autopsyTagsManagerLock) { followUpTagName = null; } } @@ -108,7 +108,7 @@ public class DrawableTagsManager { * @throws TskCoreException */ public TagName getFollowUpTagName() throws TskCoreException { - synchronized (autopsyTagsManager) { + synchronized (autopsyTagsManagerLock) { if (Objects.isNull(followUpTagName)) { followUpTagName = getTagName(FOLLOW_UP); } @@ -117,7 +117,7 @@ public class DrawableTagsManager { } public Collection getNonCategoryTagNames() { - synchronized (autopsyTagsManager) { + synchronized (autopsyTagsManagerLock) { try { return autopsyTagsManager.getAllTagNames().stream() .filter(Category::isCategoryTagName) @@ -140,13 +140,13 @@ public class DrawableTagsManager { * @throws TskCoreException */ public List getContentTagsByContent(Content content) throws TskCoreException { - synchronized (autopsyTagsManager) { + synchronized (autopsyTagsManagerLock) { return autopsyTagsManager.getContentTagsByContent(content); } } public TagName getTagName(String displayName) throws TskCoreException { - synchronized (autopsyTagsManager) { + synchronized (autopsyTagsManagerLock) { try { for (TagName tn : autopsyTagsManager.getAllTagNames()) { if (displayName.equals(tn.getDisplayName())) { @@ -175,14 +175,14 @@ public class DrawableTagsManager { public void addContentTag(DrawableFile file, TagName tagName, String comment) throws TskCoreException { ContentTag addContentTag; - synchronized (autopsyTagsManager) { + synchronized (autopsyTagsManagerLock) { addContentTag = autopsyTagsManager.addContentTag(file, tagName, comment); } fireTagAdded(addContentTag); } public List getContentTagsByTagName(TagName t) throws TskCoreException { - synchronized (autopsyTagsManager) { + synchronized (autopsyTagsManagerLock) { return autopsyTagsManager.getContentTagsByTagName(t); } } @@ -203,13 +203,13 @@ public class DrawableTagsManager { } public List getAllTagNames() throws TskCoreException { - synchronized (autopsyTagsManager) { + synchronized (autopsyTagsManagerLock) { return autopsyTagsManager.getAllTagNames(); } } public List getTagNamesInUse() throws TskCoreException { - synchronized (autopsyTagsManager) { + synchronized (autopsyTagsManagerLock) { return autopsyTagsManager.getTagNamesInUse(); } } @@ -221,21 +221,11 @@ public class DrawableTagsManager { public void fireTagDeleted(ContentTag oldTag) { tagsEventBus.post(new TagsChangeEvent(Collections.singleton(oldTag.getContent().getId()))); } -// -// /** -// * fire a TagsChangeEvent with the given fileIDs -// * -// * @param fileIDs -// */ -// public final void fireChange(Collection fileIDs) { -// tagsEventBus.post(new TagsChangeEvent(fileIDs)); -// } public void deleteContentTag(ContentTag ct) throws TskCoreException { - synchronized (autopsyTagsManager) { + synchronized (autopsyTagsManagerLock) { autopsyTagsManager.deleteContentTag(ct); } fireTagDeleted(ct); } - } From 39a5b142be258c25f41f5eb8d42a5d1ea7847205 Mon Sep 17 00:00:00 2001 From: jmillman Date: Fri, 19 Jun 2015 10:22:18 -0400 Subject: [PATCH 39/56] Tag Events - created new Case.Event enum values for BlackBoard/Content tags added/deleted - created new PropertyChangeEvent subclasses for BlackBoard/Content tags added/deleted - replaced ModuleDataEvent hack with new Tag Events - removed [in] from javadocs, other minor cleanup --- .../sleuthkit/autopsy/casemodule/Case.java | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/Case.java b/Core/src/org/sleuthkit/autopsy/casemodule/Case.java index 30216d3140..e7086cf3b0 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/Case.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/Case.java @@ -600,6 +600,59 @@ public class Case implements SleuthkitCase.ErrorObserver { } } + /** + * Notifies the UI that a new ContentTag has been added. + * + * @param newTag new ContentTag added + */ + public void notifyContentTagAdded(ContentTag newTag) { + notify(new ContentTagAddedEvent(newTag)); + } + + /** + * Notifies the UI that a ContentTag has been deleted. + * + * @param deletedTag ContentTag deleted + */ + public void notifyContentTagDeleted(ContentTag deletedTag) { + notify(new ContentTagDeletedEvent(deletedTag)); + } + + /** + * Notifies the UI that a new BlackboardArtifactTag has been added. + * + * @param newTag new BlackboardArtifactTag added + */ + public void notifyBlackBoardArtifactTagAdded(BlackboardArtifactTag newTag) { + notify(new BlackBoardArtifactTagAddedEvent(newTag)); + } + + /** + * Notifies the UI that a BlackboardArtifactTag has been. + * + * @param deletedTag BlackboardArtifactTag deleted + */ + public void notifyBlackBoardArtifactTagDeleted(BlackboardArtifactTag deletedTag) { + notify(new BlackBoardArtifactTagDeletedEvent(deletedTag)); + } + + /** + * Notifies the UI about a Case level event. + * + * @param propertyChangeEvent the event to distribute + */ + private void notify(final PropertyChangeEvent propertyChangeEvent) { + try { + pcs.firePropertyChange(propertyChangeEvent); + } catch (Exception e) { + logger.log(Level.SEVERE, "Case threw exception", e); //NON-NLS + MessageNotifyUtil.Notify.show(NbBundle.getMessage(this.getClass(), "Case.moduleErr"), + NbBundle.getMessage(this.getClass(), + "Case.changeCase.errListenToCaseUpdates.msg"), + MessageNotifyUtil.MessageType.ERROR); + } + } + /** * @return The Services object for this case. */ From 1665dc11b913461a94f8c760d42780a60d27ab18 Mon Sep 17 00:00:00 2001 From: jmillman Date: Fri, 19 Jun 2015 13:53:53 -0400 Subject: [PATCH 40/56] use new Autopsy Tag events, don't fire extra events from ig, but listen to events from autopsy --- .../casemodule/services/TagsManager.java | 1 - .../imagegallery/DrawableTagsManager.java | 82 ++++++++----------- .../imagegallery/ImageGalleryController.java | 24 ++---- .../autopsy/imagegallery/TagsChangeEvent.java | 41 ---------- .../actions/AddDrawableTagAction.java | 1 - .../actions/DeleteFollowUpTagAction.java | 7 +- .../imagegallery/datamodel/Category.java | 9 -- .../datamodel/CategoryManager.java | 1 + .../datamodel/grouping/GroupManager.java | 29 +++++-- .../gui/drawableviews/DrawableTileBase.java | 13 ++- .../gui/drawableviews/MetaDataPane.java | 9 +- 11 files changed, 80 insertions(+), 137 deletions(-) delete mode 100644 ImageGallery/src/org/sleuthkit/autopsy/imagegallery/TagsChangeEvent.java diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/services/TagsManager.java b/Core/src/org/sleuthkit/autopsy/casemodule/services/TagsManager.java index f94976b572..d5ec4fc7c2 100755 --- a/Core/src/org/sleuthkit/autopsy/casemodule/services/TagsManager.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/services/TagsManager.java @@ -253,7 +253,6 @@ public class TagsManager implements Closeable { } catch (IllegalArgumentException ex) { Logger.getLogger(TagsManager.class.getName()).log(Level.WARNING, NbBundle.getMessage(TagsManager.class, "TagsManager.addContentTag.noCaseWarning")); } - return newContentTag; } /** diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/DrawableTagsManager.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/DrawableTagsManager.java index 13455d2fb1..0bbc4b9d5a 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/DrawableTagsManager.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/DrawableTagsManager.java @@ -27,11 +27,11 @@ import java.util.logging.Level; import java.util.stream.Collectors; import org.sleuthkit.autopsy.casemodule.services.TagsManager; import org.sleuthkit.autopsy.coreutils.Logger; +import org.sleuthkit.autopsy.events.ContentTagAddedEvent; +import org.sleuthkit.autopsy.events.ContentTagDeletedEvent; import org.sleuthkit.autopsy.imagegallery.datamodel.Category; +import org.sleuthkit.autopsy.imagegallery.datamodel.CategoryManager; import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableFile; -import org.sleuthkit.autopsy.ingest.IngestServices; -import org.sleuthkit.autopsy.ingest.ModuleDataEvent; -import org.sleuthkit.datamodel.BlackboardArtifact; import org.sleuthkit.datamodel.Content; import org.sleuthkit.datamodel.ContentTag; import org.sleuthkit.datamodel.TagName; @@ -59,6 +59,32 @@ public class DrawableTagsManager { } + /** + * register an object to receive CategoryChangeEvents + * + * @param listner + */ + public void registerListener(Object listner) { + tagsEventBus.register(listner); + } + + /** + * unregister an object from receiving CategoryChangeEvents + * + * @param listener + */ + public void unregisterListener(Object listener) { + tagsEventBus.unregister(listener); + } + + public void fireTagAddedEvent(ContentTagAddedEvent event) { + tagsEventBus.post(event); + } + + public void fireTagDeletedEvent(ContentTagDeletedEvent event) { + tagsEventBus.post(event); + } + /** * assign a new TagsManager to back this one, ie when the current case * changes @@ -82,24 +108,6 @@ public class DrawableTagsManager { } } - /** - * register an object to receive CategoryChangeEvents - * - * @param listner - */ - public void registerListener(Object listner) { - tagsEventBus.register(listner); - } - - /** - * unregister an object from receiving CategoryChangeEvents - * - * @param listener - */ - public void unregisterListener(Object listener) { - tagsEventBus.unregister(listener); - } - /** * get the (cached) follow up TagName * @@ -120,7 +128,7 @@ public class DrawableTagsManager { synchronized (autopsyTagsManagerLock) { try { return autopsyTagsManager.getAllTagNames().stream() - .filter(Category::isCategoryTagName) + .filter(CategoryManager::isCategoryTagName) .collect(Collectors.toSet()); } catch (TskCoreException | IllegalStateException ex) { Logger.getLogger(DrawableTagsManager.class.getName()).log(Level.WARNING, "couldn't access case", ex); @@ -173,12 +181,10 @@ public class DrawableTagsManager { } } - public void addContentTag(DrawableFile file, TagName tagName, String comment) throws TskCoreException { - ContentTag addContentTag; + public ContentTag addContentTag(DrawableFile file, TagName tagName, String comment) throws TskCoreException { synchronized (autopsyTagsManagerLock) { - addContentTag = autopsyTagsManager.addContentTag(file, tagName, comment); + return autopsyTagsManager.addContentTag(file, tagName, comment); } - fireTagAdded(addContentTag); } public List getContentTagsByTagName(TagName t) throws TskCoreException { @@ -187,21 +193,6 @@ public class DrawableTagsManager { } } - /** - * Fire the ModuleDataEvent that we use as a place holder for a real Tag - * Event. This is used to refresh the autopsy tag tree and the ui in - * ImageGallery - * - * - * Note: this is a hack. In an ideal world, TagsManager would fire - * events so that the directory tree would refresh. But, we haven't - * had a chance to add that so, we fire these events and the tree - * refreshes based on them. - */ - static public void refreshTagsInAutopsy() { - IngestServices.getInstance().fireModuleDataEvent(new ModuleDataEvent("TagAction", BlackboardArtifact.ARTIFACT_TYPE.TSK_TAG_FILE)); //NON-NLS - } - public List getAllTagNames() throws TskCoreException { synchronized (autopsyTagsManagerLock) { return autopsyTagsManager.getAllTagNames(); @@ -214,18 +205,9 @@ public class DrawableTagsManager { } } - public void fireTagAdded(ContentTag newTag) { - tagsEventBus.post(new TagsChangeEvent(Collections.singleton(newTag.getContent().getId()))); - } - - public void fireTagDeleted(ContentTag oldTag) { - tagsEventBus.post(new TagsChangeEvent(Collections.singleton(oldTag.getContent().getId()))); - } - public void deleteContentTag(ContentTag ct) throws TskCoreException { synchronized (autopsyTagsManagerLock) { autopsyTagsManager.deleteContentTag(ct); } - fireTagDeleted(ct); } } diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java index 76f94e2a92..11646338dc 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java @@ -20,7 +20,6 @@ package org.sleuthkit.autopsy.imagegallery; import java.beans.PropertyChangeEvent; import java.util.ArrayList; -import java.util.Collections; import java.util.List; import java.util.Objects; import java.util.concurrent.BlockingQueue; @@ -61,7 +60,6 @@ import org.sleuthkit.autopsy.coreutils.ThreadConfined; import org.sleuthkit.autopsy.events.ContentTagAddedEvent; import org.sleuthkit.autopsy.events.ContentTagDeletedEvent; import org.sleuthkit.autopsy.imagegallery.datamodel.CategoryManager; -import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableAttribute; import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableDB; import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableFile; import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableTagsManager; @@ -75,7 +73,6 @@ import org.sleuthkit.datamodel.AbstractFile; import org.sleuthkit.datamodel.BlackboardArtifact; import org.sleuthkit.datamodel.BlackboardAttribute; import org.sleuthkit.datamodel.Content; -import org.sleuthkit.datamodel.ContentTag; import org.sleuthkit.datamodel.FileSystem; import org.sleuthkit.datamodel.Image; import org.sleuthkit.datamodel.SleuthkitCase; @@ -368,6 +365,7 @@ public final class ImageGalleryController { tagsManager.setAutopsyTagsManager(theNewCase.getServices().getTagsManager()); tagsManager.registerListener(groupManager); tagsManager.registerListener(categoryManager); + } else { reset(); } @@ -493,23 +491,15 @@ public final class ImageGalleryController { } break; case CONTENT_TAG_ADDED: - ContentTag newTag = (ContentTag) evt.getNewValue(); - if (Category.isCategoryTagName(newTag.getName())) { - new CategorizeAction(ImageGalleryController.this).addTag(newTag.getName(), ""); - } else { - getTagsManager().fireTagAdded(newTag); + final ContentTagAddedEvent tagAddedEvent = (ContentTagAddedEvent) evt; + if (getDatabase().isInDB((tagAddedEvent).getAddedTag().getContent().getId())) { + getTagsManager().fireTagAddedEvent(tagAddedEvent); } break; case CONTENT_TAG_DELETED: - ContentTag oldTag = (ContentTag) evt.getOldValue(); - final long fileID = oldTag.getContent().getId(); - if (getDatabase().isInDB(fileID)) { - if (Category.isCategoryTagName(oldTag.getName())) { - getCategoryManager().decrementCategoryCount(Category.fromTagName(oldTag.getName())); - getGroupManager().handleFileUpdate(FileUpdateEvent.newUpdateEvent(Collections.singleton(fileID), DrawableAttribute.CATEGORY)); - } else { - getTagsManager().fireTagDeleted(oldTag); - } + final ContentTagDeletedEvent tagDeletedEvent = (ContentTagDeletedEvent) evt; + if (getDatabase().isInDB((tagDeletedEvent).getDeletedTag().getContent().getId())) { + getTagsManager().fireTagDeletedEvent(tagDeletedEvent); } break; case CONTENT_TAG_ADDED: diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/TagsChangeEvent.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/TagsChangeEvent.java deleted file mode 100644 index 0647a18456..0000000000 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/TagsChangeEvent.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Autopsy Forensic Browser - * - * Copyright 2015 Basis Technology Corp. - * Contact: carrier sleuthkit org - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.sleuthkit.autopsy.imagegallery; - -import java.util.Collection; -import java.util.Collections; -import javax.annotation.concurrent.Immutable; - -/** - * - */ -@Immutable -public class TagsChangeEvent { - - private final Collection fileIDs; - - public Collection getFileIDs() { - return Collections.unmodifiableCollection(fileIDs); - } - - public TagsChangeEvent(Collection fileIDs) { - this.fileIDs = fileIDs; - } - -} diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/AddDrawableTagAction.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/AddDrawableTagAction.java index b3a45b3030..3c115d9134 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/AddDrawableTagAction.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/AddDrawableTagAction.java @@ -27,7 +27,6 @@ import javax.swing.JOptionPane; import javax.swing.SwingWorker; import org.openide.util.Utilities; import org.sleuthkit.autopsy.coreutils.Logger; -import org.sleuthkit.autopsy.imagegallery.DrawableTagsManager; import org.sleuthkit.autopsy.imagegallery.FileIDSelectionModel; import org.sleuthkit.autopsy.imagegallery.ImageGalleryController; import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableFile; diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/DeleteFollowUpTagAction.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/DeleteFollowUpTagAction.java index 98fdc316ad..aab8a9c827 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/DeleteFollowUpTagAction.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/DeleteFollowUpTagAction.java @@ -18,7 +18,6 @@ */ package org.sleuthkit.autopsy.imagegallery.actions; -import java.util.Collections; import java.util.List; import java.util.logging.Level; import javafx.event.ActionEvent; @@ -26,14 +25,12 @@ import javax.swing.SwingWorker; import org.controlsfx.control.action.Action; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.imagegallery.DrawableTagsManager; -import org.sleuthkit.autopsy.imagegallery.FileUpdateEvent; import org.sleuthkit.autopsy.imagegallery.ImageGalleryController; import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableAttribute; import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableFile; import org.sleuthkit.autopsy.imagegallery.grouping.GroupKey; import org.sleuthkit.autopsy.imagegallery.grouping.GroupManager; import org.sleuthkit.datamodel.ContentTag; -import org.sleuthkit.datamodel.SleuthkitCase; import org.sleuthkit.datamodel.TagName; import org.sleuthkit.datamodel.TskCoreException; @@ -53,7 +50,6 @@ public class DeleteFollowUpTagAction extends Action { @Override protected Void doInBackground() throws Exception { - final SleuthkitCase sleuthKitCase = controller.getSleuthKitCase(); final GroupManager groupManager = controller.getGroupManager(); final DrawableTagsManager tagsManager = controller.getTagsManager(); @@ -69,9 +65,8 @@ public class DeleteFollowUpTagAction extends Action { } } - DrawableTagsManager.refreshTagsInAutopsy(); //make sure rest of ui hears category change. - groupManager.handleFileUpdate(FileUpdateEvent.newUpdateEvent(Collections.singleton(fileID), DrawableAttribute.TAGS)); +// groupManager.handleFileUpdate(FileUpdateEvent.newUpdateEvent(Collections.singleton(fileID), DrawableAttribute.TAGS)); } catch (TskCoreException ex) { LOGGER.log(Level.SEVERE, "Failed to delete follow up tag.", ex); } diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/Category.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/Category.java index 4743e8b48e..3fd1a6c92c 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/Category.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/Category.java @@ -48,17 +48,8 @@ public enum Category { public static Category fromDisplayName(String displayName) { return nameMap.get(displayName); } - public static Category fromTagName(TagName tagName) { - return nameMap.get(tagName.getDisplayName()); - } - public static boolean isCategoryName(String tName) { return nameMap.containsKey(tName); - } - - public static boolean isNotCategoryTagName(TagName tName) { - return isNotCategoryName(tName.getDisplayName()); - } public static boolean isNotCategoryName(String tName) { return nameMap.containsKey(tName) == false; diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/CategoryManager.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/CategoryManager.java index 5e9b407c56..1f0d490857 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/CategoryManager.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/CategoryManager.java @@ -34,6 +34,7 @@ import org.apache.commons.lang3.concurrent.BasicThreadFactory; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.events.ContentTagAddedEvent; import org.sleuthkit.autopsy.events.ContentTagDeletedEvent; +import org.sleuthkit.autopsy.imagegallery.DrawableTagsManager; import org.sleuthkit.autopsy.imagegallery.ImageGalleryController; import org.sleuthkit.datamodel.ContentTag; import org.sleuthkit.datamodel.TagName; diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/GroupManager.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/GroupManager.java index f47feeb804..e0c865e86e 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/GroupManager.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/GroupManager.java @@ -64,7 +64,6 @@ import org.sleuthkit.autopsy.events.ContentTagAddedEvent; import org.sleuthkit.autopsy.events.ContentTagDeletedEvent; import org.sleuthkit.autopsy.imagegallery.ImageGalleryController; import org.sleuthkit.autopsy.imagegallery.ImageGalleryModule; -import org.sleuthkit.autopsy.imagegallery.TagsChangeEvent; import org.sleuthkit.autopsy.imagegallery.datamodel.Category; import org.sleuthkit.autopsy.imagegallery.datamodel.CategoryManager; import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableAttribute; @@ -296,6 +295,10 @@ public class GroupManager { } }); } + } else { //group == null + // It may be that this was the last unanalyzed file in the group, so test + // whether the group is now fully analyzed. + popuplateIfAnalyzed(groupKey, null); } } else { //group == null // It may be that this was the last unanalyzed file in the group, so test @@ -546,11 +549,21 @@ public class GroupManager { } @Subscribe - public void handleAutopsyTagChange(TagsChangeEvent evt) { - if (groupBy == DrawableAttribute.TAGS - && evt.getFileIDs().size() == 1 - && evt.getFileIDs().contains(-1L)) { - regroup(groupBy, sortBy, sortOrder, Boolean.TRUE); + public void handleTagAdded(ContentTagAddedEvent evt) { + final GroupKey groupKey = new GroupKey<>(DrawableAttribute.TAGS, evt.getAddedTag().getName()); + final long fileID = evt.getAddedTag().getContent().getId(); + DrawableGroup g = getGroupForKey(groupKey); + addFileToGroup(g, groupKey, fileID); + + } + + private void addFileToGroup(DrawableGroup g, final GroupKey groupKey, final long fileID) { + if (g == null) { + //if there wasn't already a group check if there should be one now + popuplateIfAnalyzed(groupKey, null); + } else { + //if there is aleady a group that was previously deemed fully analyzed, then add this newly analyzed file to it. + g.addFile(fileID); } } @@ -693,7 +706,7 @@ public class GroupManager { LOGGER.log(Level.SEVERE, "failed to get files for group: " + groupKey.getAttribute().attrName.toString() + " = " + groupKey.getValue(), ex); } - private void popuplateIfAnalyzed(GroupKey groupKey, ReGroupTask task) { + private DrawableGroup popuplateIfAnalyzed(GroupKey groupKey, ReGroupTask task) { if (Objects.nonNull(task) && (task.isCancelled())) { /* if this method call is part of a ReGroupTask and that task is @@ -702,6 +715,7 @@ public class GroupManager { * this allows us to stop if a regroup task has been cancelled (e.g. * the user picked a different group by attribute, while the * current task was still running) */ + } else { // no task or un-cancelled task if ((groupKey.getAttribute() != DrawableAttribute.PATH) || db.isGroupAnalyzed(groupKey)) { /* for attributes other than path we can't be sure a group is @@ -732,6 +746,7 @@ public class GroupManager { } markGroupSeen(group, groupSeen); }); + return group; } } catch (TskCoreException ex) { LOGGER.log(Level.SEVERE, "failed to get files for group: " + groupKey.getAttribute().attrName.toString() + " = " + groupKey.getValue(), ex); diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/DrawableTileBase.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/DrawableTileBase.java index 14b660410d..6bfbc8a70a 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/DrawableTileBase.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/DrawableTileBase.java @@ -351,10 +351,15 @@ public abstract class DrawableTileBase extends DrawableUIBase { @Subscribe @Override - synchronized public void handleTagsChanged(TagsChangeEvent evnt) { - if (fileID != null && (evnt.getFileIDs().contains(fileID) || evnt.getFileIDs().contains(-1L))) { - updateFollowUpIcon(); - } + public void handleTagAdded(ContentTagAddedEvent evt) { + + updateFollowUpIcon(); + } + + @Subscribe + @Override + public void handleTagDeleted(ContentTagDeletedEvent evt) { + updateFollowUpIcon(); } @Subscribe diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/MetaDataPane.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/MetaDataPane.java index 45399e2f79..e9109ab121 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/MetaDataPane.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/MetaDataPane.java @@ -207,7 +207,6 @@ public class MetaDataPane extends DrawableUIBase { handleTagEvent(evt, this::updateUI); } - @Subscribe @Override public void handleTagDeleted(ContentTagDeletedEvent evt) { handleTagEvent(evt, this::updateUI); @@ -225,4 +224,12 @@ public class MetaDataPane extends DrawableUIBase { } }); } + + @Override + public void handleTagDeleted(ContentTagDeletedEvent evt) { + if (getFile() != null && evt.getDeletedTag().getContent().getId() == getFileID()) { + updateUI(); + } + } + } From 1f1d59d76f49c8d8091d890750a435f7b8d555ff Mon Sep 17 00:00:00 2001 From: jmillman Date: Fri, 19 Jun 2015 17:20:35 -0400 Subject: [PATCH 41/56] remove uneeded notification code; let event handlers do it all. optionalize DrawableView --- .../actions/CategorizeAction.java | 13 +++- .../actions/DeleteFollowUpTagAction.java | 11 +--- .../datamodel/CategoryManager.java | 2 +- .../datamodel/grouping/GroupManager.java | 12 ++-- .../gui/drawableviews/DrawableTileBase.java | 66 +++++++++++++++++-- .../gui/drawableviews/DrawableView.java | 1 + .../gui/drawableviews/MetaDataPane.java | 41 ++++++++++-- .../gui/drawableviews/SlideShowView.java | 2 +- 8 files changed, 119 insertions(+), 29 deletions(-) diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/CategorizeAction.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/CategorizeAction.java index 24e59dda65..3f6a918524 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/CategorizeAction.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/CategorizeAction.java @@ -19,7 +19,6 @@ package org.sleuthkit.autopsy.imagegallery.actions; import java.util.HashSet; -import java.util.List; import java.util.Set; import java.util.logging.Level; import java.util.stream.Collectors; @@ -37,8 +36,6 @@ import org.sleuthkit.autopsy.imagegallery.datamodel.Category; import org.sleuthkit.autopsy.imagegallery.datamodel.CategoryManager; import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableFile; import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableTagsManager; -import org.sleuthkit.autopsy.imagegallery.grouping.GroupManager; -import org.sleuthkit.datamodel.ContentTag; import org.sleuthkit.datamodel.Tag; import org.sleuthkit.datamodel.TagName; import org.sleuthkit.datamodel.TskCoreException; @@ -154,6 +151,16 @@ public class CategorizeAction extends AddTagAction { .collect(Collectors.toList()).isEmpty()) { tagsManager.addContentTag(file, tagName, comment); } + } else { + tagsManager.getContentTagsByContent(file).stream() + .filter(tag -> CategoryManager.isCategoryTagName(tag.getName())) + .forEach((ct) -> { + try { + tagsManager.deleteContentTag(ct); + } catch (TskCoreException ex) { + LOGGER.log(Level.SEVERE, "Error removing old categories result", ex); + } + }); } } catch (TskCoreException ex) { diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/DeleteFollowUpTagAction.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/DeleteFollowUpTagAction.java index aab8a9c827..74082fcd1c 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/DeleteFollowUpTagAction.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/DeleteFollowUpTagAction.java @@ -26,10 +26,7 @@ import org.controlsfx.control.action.Action; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.imagegallery.DrawableTagsManager; import org.sleuthkit.autopsy.imagegallery.ImageGalleryController; -import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableAttribute; import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableFile; -import org.sleuthkit.autopsy.imagegallery.grouping.GroupKey; -import org.sleuthkit.autopsy.imagegallery.grouping.GroupManager; import org.sleuthkit.datamodel.ContentTag; import org.sleuthkit.datamodel.TagName; import org.sleuthkit.datamodel.TskCoreException; @@ -50,23 +47,17 @@ public class DeleteFollowUpTagAction extends Action { @Override protected Void doInBackground() throws Exception { - final GroupManager groupManager = controller.getGroupManager(); final DrawableTagsManager tagsManager = controller.getTagsManager(); try { final TagName followUpTagName = tagsManager.getFollowUpTagName(); - // remove file from old category group - groupManager.removeFromGroup(new GroupKey(DrawableAttribute.TAGS, followUpTagName), fileID); - + List contentTagsByContent = tagsManager.getContentTagsByContent(file); for (ContentTag ct : contentTagsByContent) { if (ct.getName().getDisplayName().equals(followUpTagName.getDisplayName())) { tagsManager.deleteContentTag(ct); } } - - //make sure rest of ui hears category change. -// groupManager.handleFileUpdate(FileUpdateEvent.newUpdateEvent(Collections.singleton(fileID), DrawableAttribute.TAGS)); } catch (TskCoreException ex) { LOGGER.log(Level.SEVERE, "Failed to delete follow up tag.", ex); } diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/CategoryManager.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/CategoryManager.java index 1f0d490857..e685c118f5 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/CategoryManager.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/CategoryManager.java @@ -262,7 +262,7 @@ public class CategoryManager { fireChange(Collections.singleton(addedTag.getContent().getId()), newCat); } } - + @Subscribe @Subscribe public void handleTagDeleted(ContentTagDeletedEvent event) { ContentTag deleted = event.getTag(); diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/GroupManager.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/GroupManager.java index e0c865e86e..ed1b5b3706 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/GroupManager.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/GroupManager.java @@ -293,6 +293,7 @@ public class GroupManager { if (unSeenGroups.contains(group)) { unSeenGroups.remove(group); } + } }); } } else { //group == null @@ -550,10 +551,12 @@ public class GroupManager { @Subscribe public void handleTagAdded(ContentTagAddedEvent evt) { - final GroupKey groupKey = new GroupKey<>(DrawableAttribute.TAGS, evt.getAddedTag().getName()); - final long fileID = evt.getAddedTag().getContent().getId(); - DrawableGroup g = getGroupForKey(groupKey); - addFileToGroup(g, groupKey, fileID); + if (groupBy == DrawableAttribute.TAGS || groupBy == DrawableAttribute.CATEGORY) { + final GroupKey groupKey = new GroupKey<>(DrawableAttribute.TAGS, evt.getAddedTag().getName()); + final long fileID = evt.getAddedTag().getContent().getId(); + DrawableGroup g = getGroupForKey(groupKey); + addFileToGroup(g, groupKey, fileID); + } } @@ -615,6 +618,7 @@ public class GroupManager { final long fileID = evt.getTag().getContent().getId(); DrawableGroup g = removeFromGroup(groupKey, fileID); } + } } @Subscribe diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/DrawableTileBase.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/DrawableTileBase.java index 6bfbc8a70a..c9bfe35b29 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/DrawableTileBase.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/DrawableTileBase.java @@ -23,6 +23,8 @@ import com.google.common.eventbus.Subscribe; import java.util.ArrayList; import java.util.Collection; import java.util.Optional; +import static java.util.Objects.nonNull; +import java.util.Optional; import java.util.logging.Level; import javafx.application.Platform; import javafx.beans.Observable; @@ -126,6 +128,30 @@ public abstract class DrawableTileBase extends DrawableUIBase { @FXML protected BorderPane imageBorder; + + @Override + public Optional getFileID() { + return fileIDOpt; + } + + @Override + public Optional> getFile() { + if (fileIDOpt.isPresent()) { + if (fileOpt.isPresent() && fileOpt.get().getId() == fileIDOpt.get()) { + return fileOpt; + } else { + try { + fileOpt = Optional.of(ImageGalleryController.getDefault().getFileFromId(fileIDOpt.get())); + } catch (TskCoreException ex) { + Logger.getAnonymousLogger().log(Level.WARNING, "failed to get DrawableFile for obj_id" + fileIDOpt.get(), ex); + fileOpt = Optional.empty(); + } + return fileOpt; + } + } else { + return Optional.empty(); + } + } /** * the groupPane this {@link DrawableTileBase} is embedded in */ @@ -258,7 +284,7 @@ public abstract class DrawableTileBase extends DrawableUIBase { try { globalSelectionModel.clearAndSelect(file.getId()); new AddDrawableTagAction(getController()).addTag(getController().getTagsManager().getFollowUpTagName(), ""); - new AddDrawableTagAction(controller).addTag(followUpTagName, ""); + new AddDrawableTagAction(controller).addTag(followUpTagName, ""); } catch (TskCoreException ex) { LOGGER.log(Level.SEVERE, "Failed to add Follow Up tag. Could not load TagName.", ex); } @@ -281,10 +307,12 @@ public abstract class DrawableTileBase extends DrawableUIBase { } } else { return false; + if (Objects.equals(newFileID, fileIDOpt.get()) == false) { + setFileHelper(newFileID); } } - @Override + private void setFileHelper(final Long newFileID) { protected void setFileHelper(final Long newFileID) { setFileIDOpt(Optional.ofNullable(newFileID)); disposeContent(); @@ -352,14 +380,44 @@ public abstract class DrawableTileBase extends DrawableUIBase { @Subscribe @Override public void handleTagAdded(ContentTagAddedEvent evt) { + fileIDOpt.ifPresent(fileID -> { + try { + if (fileID == evt.getAddedTag().getContent().getId() + && evt.getAddedTag().getName() == getController().getTagsManager().getFollowUpTagName()) { - updateFollowUpIcon(); + Platform.runLater(() -> { + followUpImageView.setImage(followUpIcon); + followUpToggle.setSelected(true); + }); + } + } catch (TskCoreException ex) { + LOGGER.log(Level.SEVERE, "Failed to get follow up status for file.", ex); + } + }); } @Subscribe @Override public void handleTagDeleted(ContentTagDeletedEvent evt) { - updateFollowUpIcon(); + + fileIDOpt.ifPresent(fileID -> { + try { + if (fileID == evt.getDeletedTag().getContent().getId() + && evt.getDeletedTag().getName() == controller.getTagsManager().getFollowUpTagName()) { + updateFollowUpIcon(); + } + } catch (TskCoreException ex) { + LOGGER.log(Level.SEVERE, "Failed to get follow up status for file.", ex); + } + }); + } + + private void updateFollowUpIcon() { + boolean hasFollowUp = hasFollowUp(); + Platform.runLater(() -> { + followUpImageView.setImage(hasFollowUp ? followUpIcon : followUpGray); + followUpToggle.setSelected(hasFollowUp); + }); } @Subscribe diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/DrawableView.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/DrawableView.java index 67647334d6..37737675e5 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/DrawableView.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/DrawableView.java @@ -2,6 +2,7 @@ package org.sleuthkit.autopsy.imagegallery.gui.drawableviews; import com.google.common.eventbus.Subscribe; import java.util.Optional; +import java.util.Optional; import java.util.logging.Level; import javafx.application.Platform; import javafx.scene.layout.Border; diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/MetaDataPane.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/MetaDataPane.java index e9109ab121..232cfe8a6f 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/MetaDataPane.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/MetaDataPane.java @@ -24,6 +24,7 @@ import java.util.Arrays; import java.util.Collection; import java.util.Objects; import java.util.Optional; +import java.util.Optional; import java.util.stream.Collectors; import javafx.application.Platform; import javafx.beans.property.SimpleObjectProperty; @@ -83,7 +84,6 @@ public class MetaDataPane extends DrawableUIBase { public MetaDataPane(ImageGalleryController controller) { super(controller); - FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("MetaDataPane.fxml")); fxmlLoader.setRoot(this); fxmlLoader.setController(this); @@ -93,8 +93,6 @@ public class MetaDataPane extends DrawableUIBase { } catch (IOException exception) { throw new RuntimeException(exception); } - } - @FXML @SuppressWarnings("unchecked") void initialize() { @@ -155,10 +153,35 @@ public class MetaDataPane extends DrawableUIBase { }); } + volatile private Optional> fileOpt = Optional.empty(); + + volatile private Optional fileIDOpt = Optional.empty(); + @Override protected synchronized void setFileHelper(Long newFileID) { setFileIDOpt(Optional.ofNullable(newFileID)); if (newFileID == null) { + + @Override + public Optional> getFile() { + if (fileIDOpt.isPresent()) { + if (fileOpt.isPresent() && fileOpt.get().getId() == fileIDOpt.get()) { + return fileOpt; + } else { + return fileOpt; + if (Objects.equals(newFileID, fileIDOpt.get()) == false) { + setFileHelper(newFileID); + } + } else { + if (nonNull(newFileID)) { + setFileHelper(newFileID); + } + } + setFileHelper(newFileID); + } + private void setFileHelper(Long newFileID) { + fileIDOpt = Optional.of(newFileID); + if (newFileID == null) { Platform.runLater(() -> { imageView.setImage(null); tableView.getItems().clear(); @@ -183,6 +206,7 @@ public class MetaDataPane extends DrawableUIBase { updateCategory(); }); + } @Override @@ -227,9 +251,14 @@ public class MetaDataPane extends DrawableUIBase { @Override public void handleTagDeleted(ContentTagDeletedEvent evt) { - if (getFile() != null && evt.getDeletedTag().getContent().getId() == getFileID()) { - updateUI(); - } + handleTagChanged(evt.getDeletedTag().getContent().getId()); } + private void handleTagChanged(Long tagFileID) { + getFileID().ifPresent(fileID -> { + if (Objects.equals(tagFileID, fileID)) { + updateUI(); + } + }); + } } diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/SlideShowView.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/SlideShowView.java index 91fbec5a24..ba60735da9 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/SlideShowView.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/SlideShowView.java @@ -50,7 +50,6 @@ import org.openide.util.Exceptions; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.coreutils.ThreadConfined; import org.sleuthkit.autopsy.coreutils.ThreadConfined.ThreadType; -import org.sleuthkit.autopsy.imagegallery.DrawableTagsManager; import org.sleuthkit.autopsy.imagegallery.FXMLConstructor; import org.sleuthkit.autopsy.imagegallery.FileIDSelectionModel; import org.sleuthkit.autopsy.imagegallery.actions.CategorizeAction; @@ -319,6 +318,7 @@ public class SlideShowView extends DrawableTileBase { public Category updateCategory() { if (getFile().isPresent()) { final Category category = super.updateCategory(); + final Border border1 = hasHashHit() && (category == Category.ZERO) ToggleButton toggleForCategory = getToggleForCategory(category); Platform.runLater(() -> { toggleForCategory.setSelected(true); From da0554de6a392ff7616e8e4a40a35565ad207034 Mon Sep 17 00:00:00 2001 From: jmillman Date: Mon, 22 Jun 2015 13:33:07 -0400 Subject: [PATCH 42/56] fix bugs updating tags/categpries in slideshowview and metadata pane make new abstract base calss DrawableUIBase and move fileid and file object access to it. --- .../actions/DeleteFollowUpTagAction.java | 2 - .../imagegallery/gui/DrawableTileBase.java | 391 ++++++++++++++++++ .../imagegallery/gui/DrawableUIBase.java | 97 +++++ .../gui/drawableviews/MetaDataPane.java | 32 +- .../gui/drawableviews/SlideShowView.java | 2 +- 5 files changed, 490 insertions(+), 34 deletions(-) create mode 100644 ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableTileBase.java create mode 100644 ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableUIBase.java diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/DeleteFollowUpTagAction.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/DeleteFollowUpTagAction.java index 74082fcd1c..934a3fb258 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/DeleteFollowUpTagAction.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/DeleteFollowUpTagAction.java @@ -37,11 +37,9 @@ import org.sleuthkit.datamodel.TskCoreException; public class DeleteFollowUpTagAction extends Action { private static final Logger LOGGER = Logger.getLogger(DeleteFollowUpTagAction.class.getName()); - private final long fileID; public DeleteFollowUpTagAction(final ImageGalleryController controller, final DrawableFile file) { super("Delete Follow Up Tag"); - this.fileID = file.getId(); setEventHandler((ActionEvent t) -> { new SwingWorker() { diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableTileBase.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableTileBase.java new file mode 100644 index 0000000000..80c73b1ae9 --- /dev/null +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableTileBase.java @@ -0,0 +1,391 @@ + +/* + * Autopsy Forensic Browser + * + * Copyright 2013-15 Basis Technology Corp. + * Contact: carrier sleuthkit org + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.sleuthkit.autopsy.imagegallery.gui; + +import com.google.common.eventbus.Subscribe; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Optional; +import java.util.logging.Level; +import javafx.application.Platform; +import javafx.beans.Observable; +import javafx.event.ActionEvent; +import javafx.event.EventHandler; +import javafx.fxml.FXML; +import javafx.scene.control.ContextMenu; +import javafx.scene.control.Label; +import javafx.scene.control.MenuItem; +import javafx.scene.control.ToggleButton; +import javafx.scene.control.Tooltip; +import javafx.scene.image.Image; +import javafx.scene.image.ImageView; +import javafx.scene.input.MouseEvent; +import javafx.scene.layout.Border; +import javafx.scene.layout.BorderPane; +import javafx.scene.layout.BorderStroke; +import javafx.scene.layout.BorderStrokeStyle; +import javafx.scene.layout.BorderWidths; +import javafx.scene.layout.CornerRadii; +import javafx.scene.layout.Region; +import javafx.scene.paint.Color; +import javax.swing.Action; +import javax.swing.SwingUtilities; +import org.openide.util.Lookup; +import org.openide.util.actions.Presenter; +import org.openide.windows.TopComponent; +import org.openide.windows.WindowManager; +import org.sleuthkit.autopsy.casemodule.Case; +import org.sleuthkit.autopsy.corecomponentinterfaces.ContextMenuActionsProvider; +import org.sleuthkit.autopsy.coreutils.Logger; +import org.sleuthkit.autopsy.coreutils.ThreadConfined; +import org.sleuthkit.autopsy.coreutils.ThreadConfined.ThreadType; +import org.sleuthkit.autopsy.datamodel.FileNode; +import org.sleuthkit.autopsy.directorytree.ExternalViewerAction; +import org.sleuthkit.autopsy.directorytree.ExtractAction; +import org.sleuthkit.autopsy.directorytree.NewWindowViewAction; +import org.sleuthkit.autopsy.events.ContentTagAddedEvent; +import org.sleuthkit.autopsy.events.ContentTagDeletedEvent; +import org.sleuthkit.autopsy.imagegallery.FileIDSelectionModel; +import org.sleuthkit.autopsy.imagegallery.ImageGalleryTopComponent; +import org.sleuthkit.autopsy.imagegallery.actions.AddDrawableTagAction; +import org.sleuthkit.autopsy.imagegallery.actions.CategorizeAction; +import org.sleuthkit.autopsy.imagegallery.actions.DeleteFollowUpTagAction; +import org.sleuthkit.autopsy.imagegallery.actions.SwingMenuItemAdapter; +import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableAttribute; +import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableFile; +import org.sleuthkit.datamodel.TagName; +import org.sleuthkit.datamodel.TskCoreException; + +/** + * An abstract base class for {@link DrawableTile} and {@link SlideShowView}, + * since they share a similar node tree and many behaviors, other implementers + * of {@link DrawableView}s should implement the interface directly + * + */ +public abstract class DrawableTileBase extends DrawableUIBase { + + private static final Logger LOGGER = Logger.getLogger(DrawableTileBase.class.getName()); + + private static final Border UNSELECTED_BORDER = new Border(new BorderStroke(Color.GRAY, BorderStrokeStyle.SOLID, new CornerRadii(2), new BorderWidths(3))); + + private static final Border SELECTED_BORDER = new Border(new BorderStroke(Color.BLUE, BorderStrokeStyle.SOLID, new CornerRadii(2), new BorderWidths(3))); + + //TODO: do this in CSS? -jm + protected static final Image videoIcon = new Image("org/sleuthkit/autopsy/imagegallery/images/video-file.png"); + protected static final Image hashHitIcon = new Image("org/sleuthkit/autopsy/imagegallery/images/hashset_hits.png"); + protected static final Image followUpIcon = new Image("org/sleuthkit/autopsy/imagegallery/images/flag_red.png"); + protected static final Image followUpGray = new Image("org/sleuthkit/autopsy/imagegallery/images/flag_gray.png"); + + protected static final FileIDSelectionModel globalSelectionModel = FileIDSelectionModel.getInstance(); + private static ContextMenu contextMenu; + + /** + * displays the icon representing video files + */ + @FXML + protected ImageView fileTypeImageView; + + /** + * displays the icon representing hash hits + */ + @FXML + protected ImageView hashHitImageView; + + /** + * displays the icon representing follow up tag + */ + @FXML + protected ImageView followUpImageView; + + @FXML + protected ToggleButton followUpToggle; + + /** + * the label that shows the name of the represented file + */ + @FXML + protected Label nameLabel; + + @FXML + protected BorderPane imageBorder; + + /** + * the groupPane this {@link DrawableTileBase} is embedded in + */ + final private GroupPane groupPane; + volatile private boolean registered = false; + + protected DrawableTileBase(GroupPane groupPane) { + super(groupPane.getController()); + + this.groupPane = groupPane; + globalSelectionModel.getSelected().addListener((Observable observable) -> { + updateSelectionState(); + }); + + //set up mouse listener + //TODO: split this between DrawableTile and SingleDrawableViewBase + addEventFilter(MouseEvent.MOUSE_CLICKED, new EventHandler() { + + @Override + public void handle(MouseEvent t) { + getFile().ifPresent(file -> { + final long fileID = file.getId(); + switch (t.getButton()) { + case PRIMARY: + if (t.getClickCount() == 1) { + if (t.isControlDown()) { + + globalSelectionModel.toggleSelection(fileID); + } else { + groupPane.makeSelection(t.isShiftDown(), fileID); + } + } else if (t.getClickCount() > 1) { + groupPane.activateSlideShowViewer(fileID); + } + break; + case SECONDARY: + if (t.getClickCount() == 1) { + if (globalSelectionModel.isSelected(fileID) == false) { + groupPane.makeSelection(false, fileID); + } + } + if (contextMenu != null) { + contextMenu.hide(); + } + final ContextMenu groupContextMenu = groupPane.getContextMenu(); + if (groupContextMenu != null) { + groupContextMenu.hide(); + } + contextMenu = buildContextMenu(file); + contextMenu.show(DrawableTileBase.this, t.getScreenX(), t.getScreenY()); + break; + } + }); + + t.consume(); + } + + private ContextMenu buildContextMenu(DrawableFile file) { + final ArrayList menuItems = new ArrayList<>(); + + menuItems.add(new CategorizeAction(getController()).getPopupMenu()); + + menuItems.add(new AddDrawableTagAction(getController()).getPopupMenu()); + + final MenuItem extractMenuItem = new MenuItem("Extract File(s)"); + extractMenuItem.setOnAction((ActionEvent t) -> { + SwingUtilities.invokeLater(() -> { + TopComponent etc = WindowManager.getDefault().findTopComponent(ImageGalleryTopComponent.PREFERRED_ID); + ExtractAction.getInstance().actionPerformed(new java.awt.event.ActionEvent(etc, 0, null)); + }); + }); + menuItems.add(extractMenuItem); + + MenuItem contentViewer = new MenuItem("Show Content Viewer"); + contentViewer.setOnAction((ActionEvent t) -> { + SwingUtilities.invokeLater(() -> { + new NewWindowViewAction("Show Content Viewer", new FileNode(file.getAbstractFile())).actionPerformed(null); + }); + }); + menuItems.add(contentViewer); + + MenuItem externalViewer = new MenuItem("Open in External Viewer"); + final ExternalViewerAction externalViewerAction = new ExternalViewerAction("Open in External Viewer", new FileNode(file.getAbstractFile())); + + externalViewer.setDisable(externalViewerAction.isEnabled() == false); + externalViewer.setOnAction((ActionEvent t) -> { + SwingUtilities.invokeLater(() -> { + externalViewerAction.actionPerformed(null); + }); + }); + menuItems.add(externalViewer); + + Collection menuProviders = Lookup.getDefault().lookupAll(ContextMenuActionsProvider.class); + + for (ContextMenuActionsProvider provider : menuProviders) { + for (final Action act : provider.getActions()) { + if (act instanceof Presenter.Popup) { + Presenter.Popup aact = (Presenter.Popup) act; + menuItems.add(SwingMenuItemAdapter.create(aact.getPopupPresenter())); + } + } + } + + ContextMenu contextMenu = new ContextMenu(menuItems.toArray(new MenuItem[]{})); + contextMenu.setAutoHide(true); + return contextMenu; + } + }); + } + + GroupPane getGroupPane() { + return groupPane; + } + + @ThreadConfined(type = ThreadType.UI) + protected abstract void clearContent(); + + protected abstract void disposeContent(); + + protected abstract Runnable getContentUpdateRunnable(); + + protected abstract String getTextForLabel(); + + protected void initialize() { + followUpToggle.setOnAction((ActionEvent event) -> { + getFile().ifPresent(file -> { + if (followUpToggle.isSelected() == true) { + try { + globalSelectionModel.clearAndSelect(file.getId()); + new AddDrawableTagAction(getController()).addTag(getController().getTagsManager().getFollowUpTagName(), ""); + } catch (TskCoreException ex) { + LOGGER.log(Level.SEVERE, "Failed to add Follow Up tag. Could not load TagName.", ex); + } + } else { + new DeleteFollowUpTagAction(getController(), file).handle(event); + } + }); + }); + } + + protected boolean hasFollowUp() { + if (getFileID().isPresent()) { + try { + TagName followUpTagName = getController().getTagsManager().getFollowUpTagName(); + return DrawableAttribute.TAGS.getValue(getFile().get()).stream() + .anyMatch(followUpTagName::equals); + } catch (TskCoreException ex) { + LOGGER.log(Level.WARNING, "failed to get follow up tag name ", ex); + return true; + } + } else { + return false; + } + } + + @Override + protected void setFileHelper(final Long newFileID) { + setFileIDOpt(Optional.ofNullable(newFileID)); + disposeContent(); + + if (getFileID().isPresent() == false || Case.isCaseOpen() == false) { + if (registered == true) { + getController().getCategoryManager().unregisterListener(this); + getController().getTagsManager().unregisterListener(this); + registered = false; + } + setFileOpt(Optional.empty()); + Platform.runLater(() -> { + clearContent(); + }); + } else { + if (registered == false) { + getController().getCategoryManager().registerListener(this); + getController().getTagsManager().registerListener(this); + registered = true; + } + setFileOpt(Optional.empty()); + + updateSelectionState(); + updateCategory(); + updateFollowUpIcon(); + updateUI(); + Platform.runLater(getContentUpdateRunnable()); + } + } + + private void updateUI() { + getFile().ifPresent(file -> { + final boolean isVideo = file.isVideo(); + final boolean hasHashSetHits = hasHashHit(); + final String text = getTextForLabel(); + + Platform.runLater(() -> { + fileTypeImageView.setImage(isVideo ? videoIcon : null); + hashHitImageView.setImage(hasHashSetHits ? hashHitIcon : null); + nameLabel.setText(text); + nameLabel.setTooltip(new Tooltip(text)); + }); + }); + + } + + /** + * update the visual representation of the selection state of this + * DrawableView + */ + protected void updateSelectionState() { + getFile().ifPresent(file -> { + final boolean selected = globalSelectionModel.isSelected(file.getId()); + Platform.runLater(() -> { + setBorder(selected ? SELECTED_BORDER : UNSELECTED_BORDER); + }); + }); + } + + @Override + public Region getCategoryBorderRegion() { + return imageBorder; + } + + @Subscribe + @Override + public void handleTagAdded(ContentTagAddedEvent evt) { + getFileID().ifPresent(fileID -> { + try { + if (fileID == evt.getAddedTag().getContent().getId() + && evt.getAddedTag().getName().equals(getController().getTagsManager().getFollowUpTagName())) { + + Platform.runLater(() -> { + followUpImageView.setImage(followUpIcon); + followUpToggle.setSelected(true); + }); + } + } catch (TskCoreException ex) { + LOGGER.log(Level.SEVERE, "Failed to get follow up status for file.", ex); + } + }); + } + + @Subscribe + @Override + public void handleTagDeleted(ContentTagDeletedEvent evt) { + + getFileID().ifPresent(fileID -> { + try { + if (fileID == evt.getDeletedTag().getContent().getId() + && evt.getDeletedTag().getName().equals(getController().getTagsManager().getFollowUpTagName())) { + updateFollowUpIcon(); + } + } catch (TskCoreException ex) { + LOGGER.log(Level.SEVERE, "Failed to get follow up status for file.", ex); + } + }); + } + + private void updateFollowUpIcon() { + boolean hasFollowUp = hasFollowUp(); + Platform.runLater(() -> { + followUpImageView.setImage(hasFollowUp ? followUpIcon : followUpGray); + followUpToggle.setSelected(hasFollowUp); + }); + } +} diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableUIBase.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableUIBase.java new file mode 100644 index 0000000000..ec794eabae --- /dev/null +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableUIBase.java @@ -0,0 +1,97 @@ +/* + * Autopsy Forensic Browser + * + * Copyright 2015 Basis Technology Corp. + * Contact: carrier sleuthkit org + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.sleuthkit.autopsy.imagegallery.gui; + +import java.util.Objects; +import static java.util.Objects.nonNull; +import java.util.Optional; +import java.util.logging.Level; +import javafx.scene.layout.AnchorPane; +import org.sleuthkit.autopsy.coreutils.Logger; +import org.sleuthkit.autopsy.imagegallery.ImageGalleryController; +import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableFile; +import org.sleuthkit.datamodel.TskCoreException; + +/** + * + */ +abstract public class DrawableUIBase extends AnchorPane implements DrawableView { + + private final ImageGalleryController controller; + + volatile private Optional> fileOpt = Optional.empty(); + + volatile private Optional fileIDOpt = Optional.empty(); + + public DrawableUIBase(ImageGalleryController controller) { + this.controller = controller; + } + + @Override + public ImageGalleryController getController() { + return controller; + } + + @Override + public Optional getFileID() { + return fileIDOpt; + } + + void setFileIDOpt(Optional fileIDOpt) { + this.fileIDOpt = fileIDOpt; + } + + void setFileOpt(Optional> fileOpt) { + this.fileOpt = fileOpt; + } + + @Override + public Optional> getFile() { + if (fileIDOpt.isPresent()) { + if (fileOpt.isPresent() && fileOpt.get().getId() == fileIDOpt.get()) { + return fileOpt; + } else { + try { + fileOpt = Optional.of(getController().getFileFromId(fileIDOpt.get())); + } catch (TskCoreException ex) { + Logger.getAnonymousLogger().log(Level.WARNING, "failed to get DrawableFile for obj_id" + fileIDOpt.get(), ex); + fileOpt = Optional.empty(); + } + return fileOpt; + } + } else { + return Optional.empty(); + } + } + + protected abstract void setFileHelper(Long newFileID); + + @Override + public void setFile(Long newFileID) { + if (getFileID().isPresent()) { + if (Objects.equals(newFileID, getFileID().get()) == false) { + setFileHelper(newFileID); + } + } else if (nonNull(newFileID)) { + setFileHelper(newFileID); + } + } + + +} diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/MetaDataPane.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/MetaDataPane.java index 232cfe8a6f..d8104ad1df 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/MetaDataPane.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/MetaDataPane.java @@ -62,11 +62,6 @@ public class MetaDataPane extends DrawableUIBase { private static final Logger LOGGER = Logger.getLogger(MetaDataPane.class.getName()); - @Override - public ImageGalleryController getController() { - return controller; - } - @FXML private ImageView imageView; @@ -153,34 +148,9 @@ public class MetaDataPane extends DrawableUIBase { }); } - volatile private Optional> fileOpt = Optional.empty(); - - volatile private Optional fileIDOpt = Optional.empty(); - - @Override protected synchronized void setFileHelper(Long newFileID) { setFileIDOpt(Optional.ofNullable(newFileID)); if (newFileID == null) { - - @Override - public Optional> getFile() { - if (fileIDOpt.isPresent()) { - if (fileOpt.isPresent() && fileOpt.get().getId() == fileIDOpt.get()) { - return fileOpt; - } else { - return fileOpt; - if (Objects.equals(newFileID, fileIDOpt.get()) == false) { - setFileHelper(newFileID); - } - } else { - if (nonNull(newFileID)) { - setFileHelper(newFileID); - } - } - setFileHelper(newFileID); - } - private void setFileHelper(Long newFileID) { - fileIDOpt = Optional.of(newFileID); if (newFileID == null) { Platform.runLater(() -> { imageView.setImage(null); @@ -206,7 +176,6 @@ public class MetaDataPane extends DrawableUIBase { updateCategory(); }); - } @Override @@ -249,6 +218,7 @@ public class MetaDataPane extends DrawableUIBase { }); } + @Subscribe @Override public void handleTagDeleted(ContentTagDeletedEvent evt) { handleTagChanged(evt.getDeletedTag().getContent().getId()); diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/SlideShowView.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/SlideShowView.java index ba60735da9..6459b0f670 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/SlideShowView.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/SlideShowView.java @@ -220,6 +220,7 @@ public class SlideShowView extends DrawableTileBase { } @ThreadConfined(type = ThreadType.JFX) + public void stopVideo() { if (imageBorder.getCenter() instanceof MediaControl) { ((MediaControl) imageBorder.getCenter()).stopVideo(); @@ -318,7 +319,6 @@ public class SlideShowView extends DrawableTileBase { public Category updateCategory() { if (getFile().isPresent()) { final Category category = super.updateCategory(); - final Border border1 = hasHashHit() && (category == Category.ZERO) ToggleButton toggleForCategory = getToggleForCategory(category); Platform.runLater(() -> { toggleForCategory.setSelected(true); From 4b7285ffd8f8e2865697d6be43b39e5ca298a16a Mon Sep 17 00:00:00 2001 From: jmillman Date: Mon, 22 Jun 2015 14:11:44 -0400 Subject: [PATCH 43/56] rename method in CategoryManager to be more descriptive; fix tag and category grouping when tags aer added / removed --- .../datamodel/grouping/GroupManager.java | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/GroupManager.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/GroupManager.java index ed1b5b3706..6b357a5457 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/GroupManager.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/GroupManager.java @@ -551,20 +551,25 @@ public class GroupManager { @Subscribe public void handleTagAdded(ContentTagAddedEvent evt) { - if (groupBy == DrawableAttribute.TAGS || groupBy == DrawableAttribute.CATEGORY) { - final GroupKey groupKey = new GroupKey<>(DrawableAttribute.TAGS, evt.getAddedTag().getName()); - final long fileID = evt.getAddedTag().getContent().getId(); - DrawableGroup g = getGroupForKey(groupKey); - addFileToGroup(g, groupKey, fileID); + GroupKey groupKey = null; + if (groupBy == DrawableAttribute.TAGS) { + groupKey = new GroupKey(DrawableAttribute.TAGS, evt.getAddedTag().getName()); + } else if (groupBy == DrawableAttribute.CATEGORY) { + groupKey = new GroupKey(DrawableAttribute.CATEGORY, CategoryManager.categoryFromTagName(evt.getAddedTag().getName())); } + final long fileID = evt.getAddedTag().getContent().getId(); + DrawableGroup g = getGroupForKey(groupKey); + addFileToGroup(g, groupKey, fileID); } + @SuppressWarnings("AssignmentToMethodParameter") private void addFileToGroup(DrawableGroup g, final GroupKey groupKey, final long fileID) { if (g == null) { //if there wasn't already a group check if there should be one now - popuplateIfAnalyzed(groupKey, null); - } else { + g = popuplateIfAnalyzed(groupKey, null); + } + if (g != null) { //if there is aleady a group that was previously deemed fully analyzed, then add this newly analyzed file to it. g.addFile(fileID); } @@ -616,8 +621,8 @@ public class GroupManager { } if (groupKey != null) { final long fileID = evt.getTag().getContent().getId(); - DrawableGroup g = removeFromGroup(groupKey, fileID); - } + DrawableGroup g = removeFromGroup(groupKey, fileID); + } } } @@ -724,7 +729,7 @@ public class GroupManager { if ((groupKey.getAttribute() != DrawableAttribute.PATH) || db.isGroupAnalyzed(groupKey)) { /* for attributes other than path we can't be sure a group is * fully analyzed because we don't know all the files that - * will be a part of that group */ + * will be a part of that group,. just show them no matter what. */ try { Set fileIDs = getFileIDsInGroup(groupKey); @@ -736,9 +741,8 @@ public class GroupManager { group = groupMap.get(groupKey); group.setFiles(ObjectUtils.defaultIfNull(fileIDs, Collections.emptySet())); } else { - group = new DrawableGroup(groupKey, fileIDs, groupSeen); - group.seenProperty().addListener((observable, oldSeen, newSeen) -> { + group.seenProperty().addListener((o, oldSeen, newSeen) -> { markGroupSeen(group, newSeen); }); groupMap.put(groupKey, group); From d11e4b03d54991da4181f979044fc410c425f4cd Mon Sep 17 00:00:00 2001 From: jmillman Date: Mon, 22 Jun 2015 15:11:16 -0400 Subject: [PATCH 44/56] reduce duplicate code --- .../imagegallery/ImageGalleryController.java | 4 +-- .../datamodel/grouping/GroupManager.java | 6 ++-- .../imagegallery/gui/DrawableTileBase.java | 34 ++++++++++--------- .../gui/drawableviews/MetaDataPane.java | 13 ++++--- 4 files changed, 32 insertions(+), 25 deletions(-) diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java index 11646338dc..6752b3a44f 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java @@ -492,13 +492,13 @@ public final class ImageGalleryController { break; case CONTENT_TAG_ADDED: final ContentTagAddedEvent tagAddedEvent = (ContentTagAddedEvent) evt; - if (getDatabase().isInDB((tagAddedEvent).getAddedTag().getContent().getId())) { + if (getDatabase().isInDB((tagAddedEvent).getTag().getContent().getId())) { getTagsManager().fireTagAddedEvent(tagAddedEvent); } break; case CONTENT_TAG_DELETED: final ContentTagDeletedEvent tagDeletedEvent = (ContentTagDeletedEvent) evt; - if (getDatabase().isInDB((tagDeletedEvent).getDeletedTag().getContent().getId())) { + if (getDatabase().isInDB((tagDeletedEvent).getTag().getContent().getId())) { getTagsManager().fireTagDeletedEvent(tagDeletedEvent); } break; diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/GroupManager.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/GroupManager.java index 6b357a5457..c0f0c27725 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/GroupManager.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/GroupManager.java @@ -553,11 +553,11 @@ public class GroupManager { public void handleTagAdded(ContentTagAddedEvent evt) { GroupKey groupKey = null; if (groupBy == DrawableAttribute.TAGS) { - groupKey = new GroupKey(DrawableAttribute.TAGS, evt.getAddedTag().getName()); + groupKey = new GroupKey(DrawableAttribute.TAGS, evt.getTag().getName()); } else if (groupBy == DrawableAttribute.CATEGORY) { - groupKey = new GroupKey(DrawableAttribute.CATEGORY, CategoryManager.categoryFromTagName(evt.getAddedTag().getName())); + groupKey = new GroupKey(DrawableAttribute.CATEGORY, CategoryManager.categoryFromTagName(evt.getTag().getName())); } - final long fileID = evt.getAddedTag().getContent().getId(); + final long fileID = evt.getTag().getContent().getId(); DrawableGroup g = getGroupForKey(groupKey); addFileToGroup(g, groupKey, fileID); diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableTileBase.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableTileBase.java index 80c73b1ae9..428bd0b5f4 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableTileBase.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableTileBase.java @@ -62,6 +62,7 @@ import org.sleuthkit.autopsy.directorytree.ExtractAction; import org.sleuthkit.autopsy.directorytree.NewWindowViewAction; import org.sleuthkit.autopsy.events.ContentTagAddedEvent; import org.sleuthkit.autopsy.events.ContentTagDeletedEvent; +import org.sleuthkit.autopsy.events.TagEvent; import org.sleuthkit.autopsy.imagegallery.FileIDSelectionModel; import org.sleuthkit.autopsy.imagegallery.ImageGalleryTopComponent; import org.sleuthkit.autopsy.imagegallery.actions.AddDrawableTagAction; @@ -70,6 +71,7 @@ import org.sleuthkit.autopsy.imagegallery.actions.DeleteFollowUpTagAction; import org.sleuthkit.autopsy.imagegallery.actions.SwingMenuItemAdapter; import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableAttribute; import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableFile; +import org.sleuthkit.datamodel.ContentTag; import org.sleuthkit.datamodel.TagName; import org.sleuthkit.datamodel.TskCoreException; @@ -349,36 +351,36 @@ public abstract class DrawableTileBase extends DrawableUIBase { @Subscribe @Override public void handleTagAdded(ContentTagAddedEvent evt) { - getFileID().ifPresent(fileID -> { - try { - if (fileID == evt.getAddedTag().getContent().getId() - && evt.getAddedTag().getName().equals(getController().getTagsManager().getFollowUpTagName())) { - Platform.runLater(() -> { - followUpImageView.setImage(followUpIcon); - followUpToggle.setSelected(true); - }); - } - } catch (TskCoreException ex) { - LOGGER.log(Level.SEVERE, "Failed to get follow up status for file.", ex); - } + handleTagEvent(evt, () -> { + Platform.runLater(() -> { + followUpImageView.setImage(followUpIcon); + followUpToggle.setSelected(true); + }); }); } @Subscribe @Override public void handleTagDeleted(ContentTagDeletedEvent evt) { + handleTagEvent(evt, this::updateFollowUpIcon); + } + void handleTagEvent(TagEvent evt, Runnable runnable) { getFileID().ifPresent(fileID -> { try { - if (fileID == evt.getDeletedTag().getContent().getId() - && evt.getDeletedTag().getName().equals(getController().getTagsManager().getFollowUpTagName())) { - updateFollowUpIcon(); + final TagName followUpTagName = getController().getTagsManager().getFollowUpTagName(); + final ContentTag deletedTag = evt.getTag(); + + if (fileID == deletedTag.getContent().getId() + && deletedTag.getName().equals(followUpTagName)) { + runnable.run(); } } catch (TskCoreException ex) { - LOGGER.log(Level.SEVERE, "Failed to get follow up status for file.", ex); + LOGGER.log(Level.SEVERE, "Failed to get followup tag name. Unable to update follow up status for file. ", ex); } }); + } private void updateFollowUpIcon() { diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/MetaDataPane.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/MetaDataPane.java index d8104ad1df..aa169053ff 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/MetaDataPane.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/MetaDataPane.java @@ -221,13 +221,18 @@ public class MetaDataPane extends DrawableUIBase { @Subscribe @Override public void handleTagDeleted(ContentTagDeletedEvent evt) { - handleTagChanged(evt.getDeletedTag().getContent().getId()); + handleTagEvent(evt, this::updateUI); } - private void handleTagChanged(Long tagFileID) { + /** + * + * @param tagFileID the value of tagEvent + * @param runnable the value of runnable + */ + void handleTagEvent(TagEvent tagEvent, final Runnable runnable) { getFileID().ifPresent(fileID -> { - if (Objects.equals(tagFileID, fileID)) { - updateUI(); + if (Objects.equals(tagEvent.getTag().getContent().getId(), fileID)) { + runnable.run(); } }); } From 38732c17ba7bd188ba0156518b832573c4f1fbb1 Mon Sep 17 00:00:00 2001 From: jmillman Date: Mon, 22 Jun 2015 15:22:14 -0400 Subject: [PATCH 45/56] move DrawableView and GroupPane to a new package --- .../imagegallery/gui/DrawableTileBase.java | 393 ------------------ .../imagegallery/gui/DrawableUIBase.java | 97 ----- .../gui/drawableviews/DrawableTile.fxml | 112 +++-- .../gui/drawableviews/DrawableTileBase.java | 78 +--- .../gui/drawableviews/GroupPane.java | 2 + .../gui/drawableviews/MetaDataPane.java | 3 + .../gui/drawableviews/SlideShowView.java | 1 - 7 files changed, 63 insertions(+), 623 deletions(-) delete mode 100644 ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableTileBase.java delete mode 100644 ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableUIBase.java diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableTileBase.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableTileBase.java deleted file mode 100644 index 428bd0b5f4..0000000000 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableTileBase.java +++ /dev/null @@ -1,393 +0,0 @@ - -/* - * Autopsy Forensic Browser - * - * Copyright 2013-15 Basis Technology Corp. - * Contact: carrier sleuthkit org - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.sleuthkit.autopsy.imagegallery.gui; - -import com.google.common.eventbus.Subscribe; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Optional; -import java.util.logging.Level; -import javafx.application.Platform; -import javafx.beans.Observable; -import javafx.event.ActionEvent; -import javafx.event.EventHandler; -import javafx.fxml.FXML; -import javafx.scene.control.ContextMenu; -import javafx.scene.control.Label; -import javafx.scene.control.MenuItem; -import javafx.scene.control.ToggleButton; -import javafx.scene.control.Tooltip; -import javafx.scene.image.Image; -import javafx.scene.image.ImageView; -import javafx.scene.input.MouseEvent; -import javafx.scene.layout.Border; -import javafx.scene.layout.BorderPane; -import javafx.scene.layout.BorderStroke; -import javafx.scene.layout.BorderStrokeStyle; -import javafx.scene.layout.BorderWidths; -import javafx.scene.layout.CornerRadii; -import javafx.scene.layout.Region; -import javafx.scene.paint.Color; -import javax.swing.Action; -import javax.swing.SwingUtilities; -import org.openide.util.Lookup; -import org.openide.util.actions.Presenter; -import org.openide.windows.TopComponent; -import org.openide.windows.WindowManager; -import org.sleuthkit.autopsy.casemodule.Case; -import org.sleuthkit.autopsy.corecomponentinterfaces.ContextMenuActionsProvider; -import org.sleuthkit.autopsy.coreutils.Logger; -import org.sleuthkit.autopsy.coreutils.ThreadConfined; -import org.sleuthkit.autopsy.coreutils.ThreadConfined.ThreadType; -import org.sleuthkit.autopsy.datamodel.FileNode; -import org.sleuthkit.autopsy.directorytree.ExternalViewerAction; -import org.sleuthkit.autopsy.directorytree.ExtractAction; -import org.sleuthkit.autopsy.directorytree.NewWindowViewAction; -import org.sleuthkit.autopsy.events.ContentTagAddedEvent; -import org.sleuthkit.autopsy.events.ContentTagDeletedEvent; -import org.sleuthkit.autopsy.events.TagEvent; -import org.sleuthkit.autopsy.imagegallery.FileIDSelectionModel; -import org.sleuthkit.autopsy.imagegallery.ImageGalleryTopComponent; -import org.sleuthkit.autopsy.imagegallery.actions.AddDrawableTagAction; -import org.sleuthkit.autopsy.imagegallery.actions.CategorizeAction; -import org.sleuthkit.autopsy.imagegallery.actions.DeleteFollowUpTagAction; -import org.sleuthkit.autopsy.imagegallery.actions.SwingMenuItemAdapter; -import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableAttribute; -import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableFile; -import org.sleuthkit.datamodel.ContentTag; -import org.sleuthkit.datamodel.TagName; -import org.sleuthkit.datamodel.TskCoreException; - -/** - * An abstract base class for {@link DrawableTile} and {@link SlideShowView}, - * since they share a similar node tree and many behaviors, other implementers - * of {@link DrawableView}s should implement the interface directly - * - */ -public abstract class DrawableTileBase extends DrawableUIBase { - - private static final Logger LOGGER = Logger.getLogger(DrawableTileBase.class.getName()); - - private static final Border UNSELECTED_BORDER = new Border(new BorderStroke(Color.GRAY, BorderStrokeStyle.SOLID, new CornerRadii(2), new BorderWidths(3))); - - private static final Border SELECTED_BORDER = new Border(new BorderStroke(Color.BLUE, BorderStrokeStyle.SOLID, new CornerRadii(2), new BorderWidths(3))); - - //TODO: do this in CSS? -jm - protected static final Image videoIcon = new Image("org/sleuthkit/autopsy/imagegallery/images/video-file.png"); - protected static final Image hashHitIcon = new Image("org/sleuthkit/autopsy/imagegallery/images/hashset_hits.png"); - protected static final Image followUpIcon = new Image("org/sleuthkit/autopsy/imagegallery/images/flag_red.png"); - protected static final Image followUpGray = new Image("org/sleuthkit/autopsy/imagegallery/images/flag_gray.png"); - - protected static final FileIDSelectionModel globalSelectionModel = FileIDSelectionModel.getInstance(); - private static ContextMenu contextMenu; - - /** - * displays the icon representing video files - */ - @FXML - protected ImageView fileTypeImageView; - - /** - * displays the icon representing hash hits - */ - @FXML - protected ImageView hashHitImageView; - - /** - * displays the icon representing follow up tag - */ - @FXML - protected ImageView followUpImageView; - - @FXML - protected ToggleButton followUpToggle; - - /** - * the label that shows the name of the represented file - */ - @FXML - protected Label nameLabel; - - @FXML - protected BorderPane imageBorder; - - /** - * the groupPane this {@link DrawableTileBase} is embedded in - */ - final private GroupPane groupPane; - volatile private boolean registered = false; - - protected DrawableTileBase(GroupPane groupPane) { - super(groupPane.getController()); - - this.groupPane = groupPane; - globalSelectionModel.getSelected().addListener((Observable observable) -> { - updateSelectionState(); - }); - - //set up mouse listener - //TODO: split this between DrawableTile and SingleDrawableViewBase - addEventFilter(MouseEvent.MOUSE_CLICKED, new EventHandler() { - - @Override - public void handle(MouseEvent t) { - getFile().ifPresent(file -> { - final long fileID = file.getId(); - switch (t.getButton()) { - case PRIMARY: - if (t.getClickCount() == 1) { - if (t.isControlDown()) { - - globalSelectionModel.toggleSelection(fileID); - } else { - groupPane.makeSelection(t.isShiftDown(), fileID); - } - } else if (t.getClickCount() > 1) { - groupPane.activateSlideShowViewer(fileID); - } - break; - case SECONDARY: - if (t.getClickCount() == 1) { - if (globalSelectionModel.isSelected(fileID) == false) { - groupPane.makeSelection(false, fileID); - } - } - if (contextMenu != null) { - contextMenu.hide(); - } - final ContextMenu groupContextMenu = groupPane.getContextMenu(); - if (groupContextMenu != null) { - groupContextMenu.hide(); - } - contextMenu = buildContextMenu(file); - contextMenu.show(DrawableTileBase.this, t.getScreenX(), t.getScreenY()); - break; - } - }); - - t.consume(); - } - - private ContextMenu buildContextMenu(DrawableFile file) { - final ArrayList menuItems = new ArrayList<>(); - - menuItems.add(new CategorizeAction(getController()).getPopupMenu()); - - menuItems.add(new AddDrawableTagAction(getController()).getPopupMenu()); - - final MenuItem extractMenuItem = new MenuItem("Extract File(s)"); - extractMenuItem.setOnAction((ActionEvent t) -> { - SwingUtilities.invokeLater(() -> { - TopComponent etc = WindowManager.getDefault().findTopComponent(ImageGalleryTopComponent.PREFERRED_ID); - ExtractAction.getInstance().actionPerformed(new java.awt.event.ActionEvent(etc, 0, null)); - }); - }); - menuItems.add(extractMenuItem); - - MenuItem contentViewer = new MenuItem("Show Content Viewer"); - contentViewer.setOnAction((ActionEvent t) -> { - SwingUtilities.invokeLater(() -> { - new NewWindowViewAction("Show Content Viewer", new FileNode(file.getAbstractFile())).actionPerformed(null); - }); - }); - menuItems.add(contentViewer); - - MenuItem externalViewer = new MenuItem("Open in External Viewer"); - final ExternalViewerAction externalViewerAction = new ExternalViewerAction("Open in External Viewer", new FileNode(file.getAbstractFile())); - - externalViewer.setDisable(externalViewerAction.isEnabled() == false); - externalViewer.setOnAction((ActionEvent t) -> { - SwingUtilities.invokeLater(() -> { - externalViewerAction.actionPerformed(null); - }); - }); - menuItems.add(externalViewer); - - Collection menuProviders = Lookup.getDefault().lookupAll(ContextMenuActionsProvider.class); - - for (ContextMenuActionsProvider provider : menuProviders) { - for (final Action act : provider.getActions()) { - if (act instanceof Presenter.Popup) { - Presenter.Popup aact = (Presenter.Popup) act; - menuItems.add(SwingMenuItemAdapter.create(aact.getPopupPresenter())); - } - } - } - - ContextMenu contextMenu = new ContextMenu(menuItems.toArray(new MenuItem[]{})); - contextMenu.setAutoHide(true); - return contextMenu; - } - }); - } - - GroupPane getGroupPane() { - return groupPane; - } - - @ThreadConfined(type = ThreadType.UI) - protected abstract void clearContent(); - - protected abstract void disposeContent(); - - protected abstract Runnable getContentUpdateRunnable(); - - protected abstract String getTextForLabel(); - - protected void initialize() { - followUpToggle.setOnAction((ActionEvent event) -> { - getFile().ifPresent(file -> { - if (followUpToggle.isSelected() == true) { - try { - globalSelectionModel.clearAndSelect(file.getId()); - new AddDrawableTagAction(getController()).addTag(getController().getTagsManager().getFollowUpTagName(), ""); - } catch (TskCoreException ex) { - LOGGER.log(Level.SEVERE, "Failed to add Follow Up tag. Could not load TagName.", ex); - } - } else { - new DeleteFollowUpTagAction(getController(), file).handle(event); - } - }); - }); - } - - protected boolean hasFollowUp() { - if (getFileID().isPresent()) { - try { - TagName followUpTagName = getController().getTagsManager().getFollowUpTagName(); - return DrawableAttribute.TAGS.getValue(getFile().get()).stream() - .anyMatch(followUpTagName::equals); - } catch (TskCoreException ex) { - LOGGER.log(Level.WARNING, "failed to get follow up tag name ", ex); - return true; - } - } else { - return false; - } - } - - @Override - protected void setFileHelper(final Long newFileID) { - setFileIDOpt(Optional.ofNullable(newFileID)); - disposeContent(); - - if (getFileID().isPresent() == false || Case.isCaseOpen() == false) { - if (registered == true) { - getController().getCategoryManager().unregisterListener(this); - getController().getTagsManager().unregisterListener(this); - registered = false; - } - setFileOpt(Optional.empty()); - Platform.runLater(() -> { - clearContent(); - }); - } else { - if (registered == false) { - getController().getCategoryManager().registerListener(this); - getController().getTagsManager().registerListener(this); - registered = true; - } - setFileOpt(Optional.empty()); - - updateSelectionState(); - updateCategory(); - updateFollowUpIcon(); - updateUI(); - Platform.runLater(getContentUpdateRunnable()); - } - } - - private void updateUI() { - getFile().ifPresent(file -> { - final boolean isVideo = file.isVideo(); - final boolean hasHashSetHits = hasHashHit(); - final String text = getTextForLabel(); - - Platform.runLater(() -> { - fileTypeImageView.setImage(isVideo ? videoIcon : null); - hashHitImageView.setImage(hasHashSetHits ? hashHitIcon : null); - nameLabel.setText(text); - nameLabel.setTooltip(new Tooltip(text)); - }); - }); - - } - - /** - * update the visual representation of the selection state of this - * DrawableView - */ - protected void updateSelectionState() { - getFile().ifPresent(file -> { - final boolean selected = globalSelectionModel.isSelected(file.getId()); - Platform.runLater(() -> { - setBorder(selected ? SELECTED_BORDER : UNSELECTED_BORDER); - }); - }); - } - - @Override - public Region getCategoryBorderRegion() { - return imageBorder; - } - - @Subscribe - @Override - public void handleTagAdded(ContentTagAddedEvent evt) { - - handleTagEvent(evt, () -> { - Platform.runLater(() -> { - followUpImageView.setImage(followUpIcon); - followUpToggle.setSelected(true); - }); - }); - } - - @Subscribe - @Override - public void handleTagDeleted(ContentTagDeletedEvent evt) { - handleTagEvent(evt, this::updateFollowUpIcon); - } - - void handleTagEvent(TagEvent evt, Runnable runnable) { - getFileID().ifPresent(fileID -> { - try { - final TagName followUpTagName = getController().getTagsManager().getFollowUpTagName(); - final ContentTag deletedTag = evt.getTag(); - - if (fileID == deletedTag.getContent().getId() - && deletedTag.getName().equals(followUpTagName)) { - runnable.run(); - } - } catch (TskCoreException ex) { - LOGGER.log(Level.SEVERE, "Failed to get followup tag name. Unable to update follow up status for file. ", ex); - } - }); - - } - - private void updateFollowUpIcon() { - boolean hasFollowUp = hasFollowUp(); - Platform.runLater(() -> { - followUpImageView.setImage(hasFollowUp ? followUpIcon : followUpGray); - followUpToggle.setSelected(hasFollowUp); - }); - } -} diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableUIBase.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableUIBase.java deleted file mode 100644 index ec794eabae..0000000000 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableUIBase.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Autopsy Forensic Browser - * - * Copyright 2015 Basis Technology Corp. - * Contact: carrier sleuthkit org - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.sleuthkit.autopsy.imagegallery.gui; - -import java.util.Objects; -import static java.util.Objects.nonNull; -import java.util.Optional; -import java.util.logging.Level; -import javafx.scene.layout.AnchorPane; -import org.sleuthkit.autopsy.coreutils.Logger; -import org.sleuthkit.autopsy.imagegallery.ImageGalleryController; -import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableFile; -import org.sleuthkit.datamodel.TskCoreException; - -/** - * - */ -abstract public class DrawableUIBase extends AnchorPane implements DrawableView { - - private final ImageGalleryController controller; - - volatile private Optional> fileOpt = Optional.empty(); - - volatile private Optional fileIDOpt = Optional.empty(); - - public DrawableUIBase(ImageGalleryController controller) { - this.controller = controller; - } - - @Override - public ImageGalleryController getController() { - return controller; - } - - @Override - public Optional getFileID() { - return fileIDOpt; - } - - void setFileIDOpt(Optional fileIDOpt) { - this.fileIDOpt = fileIDOpt; - } - - void setFileOpt(Optional> fileOpt) { - this.fileOpt = fileOpt; - } - - @Override - public Optional> getFile() { - if (fileIDOpt.isPresent()) { - if (fileOpt.isPresent() && fileOpt.get().getId() == fileIDOpt.get()) { - return fileOpt; - } else { - try { - fileOpt = Optional.of(getController().getFileFromId(fileIDOpt.get())); - } catch (TskCoreException ex) { - Logger.getAnonymousLogger().log(Level.WARNING, "failed to get DrawableFile for obj_id" + fileIDOpt.get(), ex); - fileOpt = Optional.empty(); - } - return fileOpt; - } - } else { - return Optional.empty(); - } - } - - protected abstract void setFileHelper(Long newFileID); - - @Override - public void setFile(Long newFileID) { - if (getFileID().isPresent()) { - if (Objects.equals(newFileID, getFileID().get()) == false) { - setFileHelper(newFileID); - } - } else if (nonNull(newFileID)) { - setFileHelper(newFileID); - } - } - - -} diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/DrawableTile.fxml b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/DrawableTile.fxml index acfcdc1336..4d34061c77 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/DrawableTile.fxml +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/DrawableTile.fxml @@ -7,62 +7,60 @@ - - - - -
- -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
-
- -
- -
-
-
+ + + + +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
-
- - - + +
+ +
+
+
+
+
+ + +
diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/DrawableTileBase.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/DrawableTileBase.java index c9bfe35b29..ed12891589 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/DrawableTileBase.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/DrawableTileBase.java @@ -23,8 +23,6 @@ import com.google.common.eventbus.Subscribe; import java.util.ArrayList; import java.util.Collection; import java.util.Optional; -import static java.util.Objects.nonNull; -import java.util.Optional; import java.util.logging.Level; import javafx.application.Platform; import javafx.beans.Observable; @@ -69,9 +67,11 @@ import org.sleuthkit.autopsy.imagegallery.FileIDSelectionModel; import org.sleuthkit.autopsy.imagegallery.ImageGalleryTopComponent; import org.sleuthkit.autopsy.imagegallery.actions.AddDrawableTagAction; import org.sleuthkit.autopsy.imagegallery.actions.CategorizeAction; +import org.sleuthkit.autopsy.imagegallery.actions.DeleteFollowUpTagAction; import org.sleuthkit.autopsy.imagegallery.actions.SwingMenuItemAdapter; import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableAttribute; import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableFile; +import org.sleuthkit.datamodel.ContentTag; import org.sleuthkit.datamodel.TagName; import org.sleuthkit.datamodel.TskCoreException; @@ -128,42 +128,16 @@ public abstract class DrawableTileBase extends DrawableUIBase { @FXML protected BorderPane imageBorder; - - @Override - public Optional getFileID() { - return fileIDOpt; - } - - @Override - public Optional> getFile() { - if (fileIDOpt.isPresent()) { - if (fileOpt.isPresent() && fileOpt.get().getId() == fileIDOpt.get()) { - return fileOpt; - } else { - try { - fileOpt = Optional.of(ImageGalleryController.getDefault().getFileFromId(fileIDOpt.get())); - } catch (TskCoreException ex) { - Logger.getAnonymousLogger().log(Level.WARNING, "failed to get DrawableFile for obj_id" + fileIDOpt.get(), ex); - fileOpt = Optional.empty(); - } - return fileOpt; - } - } else { - return Optional.empty(); - } - } /** * the groupPane this {@link DrawableTileBase} is embedded in */ final private GroupPane groupPane; volatile private boolean registered = false; - private final ImageGalleryController controller; protected DrawableTileBase(GroupPane groupPane) { super(groupPane.getController()); this.groupPane = groupPane; - this.controller = groupPane.getController(); globalSelectionModel.getSelected().addListener((Observable observable) -> { updateSelectionState(); }); @@ -284,7 +258,6 @@ public abstract class DrawableTileBase extends DrawableUIBase { try { globalSelectionModel.clearAndSelect(file.getId()); new AddDrawableTagAction(getController()).addTag(getController().getTagsManager().getFollowUpTagName(), ""); - new AddDrawableTagAction(controller).addTag(followUpTagName, ""); } catch (TskCoreException ex) { LOGGER.log(Level.SEVERE, "Failed to add Follow Up tag. Could not load TagName.", ex); } @@ -307,12 +280,10 @@ public abstract class DrawableTileBase extends DrawableUIBase { } } else { return false; - if (Objects.equals(newFileID, fileIDOpt.get()) == false) { - setFileHelper(newFileID); } } - private void setFileHelper(final Long newFileID) { + @Override protected void setFileHelper(final Long newFileID) { setFileIDOpt(Optional.ofNullable(newFileID)); disposeContent(); @@ -377,49 +348,6 @@ public abstract class DrawableTileBase extends DrawableUIBase { return imageBorder; } - @Subscribe - @Override - public void handleTagAdded(ContentTagAddedEvent evt) { - fileIDOpt.ifPresent(fileID -> { - try { - if (fileID == evt.getAddedTag().getContent().getId() - && evt.getAddedTag().getName() == getController().getTagsManager().getFollowUpTagName()) { - - Platform.runLater(() -> { - followUpImageView.setImage(followUpIcon); - followUpToggle.setSelected(true); - }); - } - } catch (TskCoreException ex) { - LOGGER.log(Level.SEVERE, "Failed to get follow up status for file.", ex); - } - }); - } - - @Subscribe - @Override - public void handleTagDeleted(ContentTagDeletedEvent evt) { - - fileIDOpt.ifPresent(fileID -> { - try { - if (fileID == evt.getDeletedTag().getContent().getId() - && evt.getDeletedTag().getName() == controller.getTagsManager().getFollowUpTagName()) { - updateFollowUpIcon(); - } - } catch (TskCoreException ex) { - LOGGER.log(Level.SEVERE, "Failed to get follow up status for file.", ex); - } - }); - } - - private void updateFollowUpIcon() { - boolean hasFollowUp = hasFollowUp(); - Platform.runLater(() -> { - followUpImageView.setImage(hasFollowUp ? followUpIcon : followUpGray); - followUpToggle.setSelected(hasFollowUp); - }); - } - @Subscribe @Override public void handleTagAdded(ContentTagAddedEvent evt) { diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/GroupPane.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/GroupPane.java index 9bc0cf493e..15d52e56e8 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/GroupPane.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/GroupPane.java @@ -18,6 +18,8 @@ */ package org.sleuthkit.autopsy.imagegallery.gui.drawableviews; +import org.sleuthkit.autopsy.imagegallery.gui.drawableviews.SlideShowView; +import org.sleuthkit.autopsy.imagegallery.gui.drawableviews.DrawableTile; import com.google.common.collect.ImmutableMap; import java.util.ArrayList; import java.util.Arrays; diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/MetaDataPane.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/MetaDataPane.java index aa169053ff..095ec88495 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/MetaDataPane.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/MetaDataPane.java @@ -88,6 +88,9 @@ public class MetaDataPane extends DrawableUIBase { } catch (IOException exception) { throw new RuntimeException(exception); } + } + } + @FXML @SuppressWarnings("unchecked") void initialize() { diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/SlideShowView.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/SlideShowView.java index 6459b0f670..2b29e57d39 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/SlideShowView.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/SlideShowView.java @@ -220,7 +220,6 @@ public class SlideShowView extends DrawableTileBase { } @ThreadConfined(type = ThreadType.JFX) - public void stopVideo() { if (imageBorder.getCenter() instanceof MediaControl) { ((MediaControl) imageBorder.getCenter()).stopVideo(); From f293485a2f8827f98c44d2a41cf806d59a70af7b Mon Sep 17 00:00:00 2001 From: jmillman Date: Mon, 22 Jun 2015 15:23:36 -0400 Subject: [PATCH 46/56] remove unneeded interface --- .../autopsy/imagegallery/gui/drawableviews/GroupPane.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/GroupPane.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/GroupPane.java index 15d52e56e8..ab011fc493 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/GroupPane.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/GroupPane.java @@ -18,8 +18,6 @@ */ package org.sleuthkit.autopsy.imagegallery.gui.drawableviews; -import org.sleuthkit.autopsy.imagegallery.gui.drawableviews.SlideShowView; -import org.sleuthkit.autopsy.imagegallery.gui.drawableviews.DrawableTile; import com.google.common.collect.ImmutableMap; import java.util.ArrayList; import java.util.Arrays; @@ -102,7 +100,6 @@ import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.coreutils.ThreadConfined; import org.sleuthkit.autopsy.coreutils.ThreadConfined.ThreadType; import org.sleuthkit.autopsy.directorytree.ExtractAction; -import org.sleuthkit.autopsy.imagegallery.DrawableTagsManager; import org.sleuthkit.autopsy.imagegallery.FXMLConstructor; import org.sleuthkit.autopsy.imagegallery.FileIDSelectionModel; import org.sleuthkit.autopsy.imagegallery.ImageGalleryController; From 8c2f6d274a1fc84204d8588ff7d2a0420a350718 Mon Sep 17 00:00:00 2001 From: jmillman Date: Mon, 22 Jun 2015 15:42:48 -0400 Subject: [PATCH 47/56] move classes to better packages; remove FileUpdateEvent --- .../imagegallery/DrawableTagsManager.java | 213 ------------------ .../imagegallery/ImageGalleryController.java | 1 + .../imagegallery/actions/AddTagAction.java | 2 +- .../actions/CategorizeAction.java | 2 +- .../actions/DeleteFollowUpTagAction.java | 2 +- .../datamodel/CategoryManager.java | 4 +- .../imagegallery/datamodel/DrawableDB.java | 1 - .../datamodel/DrawableTagsManager.java | 32 +-- .../datamodel/grouping/GroupManager.java | 4 - 9 files changed, 14 insertions(+), 247 deletions(-) delete mode 100644 ImageGallery/src/org/sleuthkit/autopsy/imagegallery/DrawableTagsManager.java diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/DrawableTagsManager.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/DrawableTagsManager.java deleted file mode 100644 index 0bbc4b9d5a..0000000000 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/DrawableTagsManager.java +++ /dev/null @@ -1,213 +0,0 @@ -/* - * Autopsy Forensic Browser - * - * Copyright 2013-15 Basis Technology Corp. - * Contact: carrier sleuthkit org - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.sleuthkit.autopsy.imagegallery; - -import com.google.common.eventbus.EventBus; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.Objects; -import java.util.logging.Level; -import java.util.stream.Collectors; -import org.sleuthkit.autopsy.casemodule.services.TagsManager; -import org.sleuthkit.autopsy.coreutils.Logger; -import org.sleuthkit.autopsy.events.ContentTagAddedEvent; -import org.sleuthkit.autopsy.events.ContentTagDeletedEvent; -import org.sleuthkit.autopsy.imagegallery.datamodel.Category; -import org.sleuthkit.autopsy.imagegallery.datamodel.CategoryManager; -import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableFile; -import org.sleuthkit.datamodel.Content; -import org.sleuthkit.datamodel.ContentTag; -import org.sleuthkit.datamodel.TagName; -import org.sleuthkit.datamodel.TskCoreException; - -/** - * Manages Tags, Tagging, and the relationship between Categories and Tags in - * the autopsy Db. delegates some, work to the backing {@link TagsManager}. - */ -public class DrawableTagsManager { - - private static final String FOLLOW_UP = "Follow Up"; - - final private Object autopsyTagsManagerLock = new Object(); - private TagsManager autopsyTagsManager; - - /** Used to distribute {@link TagsChangeEvent}s */ - private final EventBus tagsEventBus = new EventBus("Tags Event Bus"); - - /** The tag name corresponding to the "built-in" tag "Follow Up" */ - private TagName followUpTagName; - - public DrawableTagsManager(TagsManager autopsyTagsManager) { - this.autopsyTagsManager = autopsyTagsManager; - - } - - /** - * register an object to receive CategoryChangeEvents - * - * @param listner - */ - public void registerListener(Object listner) { - tagsEventBus.register(listner); - } - - /** - * unregister an object from receiving CategoryChangeEvents - * - * @param listener - */ - public void unregisterListener(Object listener) { - tagsEventBus.unregister(listener); - } - - public void fireTagAddedEvent(ContentTagAddedEvent event) { - tagsEventBus.post(event); - } - - public void fireTagDeletedEvent(ContentTagDeletedEvent event) { - tagsEventBus.post(event); - } - - /** - * assign a new TagsManager to back this one, ie when the current case - * changes - * - * @param autopsyTagsManager - */ - public void setAutopsyTagsManager(TagsManager autopsyTagsManager) { - synchronized (autopsyTagsManagerLock) { - this.autopsyTagsManager = autopsyTagsManager; - clearFollowUpTagName(); - } - } - - /** - * Use when closing a case to make sure everything is re-initialized in the - * next case. - */ - public void clearFollowUpTagName() { - synchronized (autopsyTagsManagerLock) { - followUpTagName = null; - } - } - - /** - * get the (cached) follow up TagName - * - * @return - * - * @throws TskCoreException - */ - public TagName getFollowUpTagName() throws TskCoreException { - synchronized (autopsyTagsManagerLock) { - if (Objects.isNull(followUpTagName)) { - followUpTagName = getTagName(FOLLOW_UP); - } - return followUpTagName; - } - } - - public Collection getNonCategoryTagNames() { - synchronized (autopsyTagsManagerLock) { - try { - return autopsyTagsManager.getAllTagNames().stream() - .filter(CategoryManager::isCategoryTagName) - .collect(Collectors.toSet()); - } catch (TskCoreException | IllegalStateException ex) { - Logger.getLogger(DrawableTagsManager.class.getName()).log(Level.WARNING, "couldn't access case", ex); - } - return Collections.emptySet(); - } - } - - /** - * Gets content tags count by content. - * - * @param The content of interest. - * - * @return A list, possibly empty, of the tags that have been applied to the - * artifact. - * - * @throws TskCoreException - */ - public List getContentTagsByContent(Content content) throws TskCoreException { - synchronized (autopsyTagsManagerLock) { - return autopsyTagsManager.getContentTagsByContent(content); - } - } - - public TagName getTagName(String displayName) throws TskCoreException { - synchronized (autopsyTagsManagerLock) { - try { - for (TagName tn : autopsyTagsManager.getAllTagNames()) { - if (displayName.equals(tn.getDisplayName())) { - return tn; - } - } - try { - return autopsyTagsManager.addTagName(displayName); - } catch (TagsManager.TagNameAlreadyExistsException ex) { - throw new TskCoreException("tagame exists but wasn't found", ex); - } - } catch (IllegalStateException ex) { - Logger.getLogger(DrawableTagsManager.class.getName()).log(Level.SEVERE, "Case was closed out from underneath", ex); - throw new TskCoreException("Case was closed out from underneath", ex); - } - } - } - - public TagName getTagName(Category cat) { - try { - return getTagName(cat.getDisplayName()); - } catch (TskCoreException ex) { - return null; - } - } - - public ContentTag addContentTag(DrawableFile file, TagName tagName, String comment) throws TskCoreException { - synchronized (autopsyTagsManagerLock) { - return autopsyTagsManager.addContentTag(file, tagName, comment); - } - } - - public List getContentTagsByTagName(TagName t) throws TskCoreException { - synchronized (autopsyTagsManagerLock) { - return autopsyTagsManager.getContentTagsByTagName(t); - } - } - - public List getAllTagNames() throws TskCoreException { - synchronized (autopsyTagsManagerLock) { - return autopsyTagsManager.getAllTagNames(); - } - } - - public List getTagNamesInUse() throws TskCoreException { - synchronized (autopsyTagsManagerLock) { - return autopsyTagsManager.getTagNamesInUse(); - } - } - - public void deleteContentTag(ContentTag ct) throws TskCoreException { - synchronized (autopsyTagsManagerLock) { - autopsyTagsManager.deleteContentTag(ct); - } - } -} diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java index 6752b3a44f..b47bafe5a9 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java @@ -18,6 +18,7 @@ */ package org.sleuthkit.autopsy.imagegallery; +import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableTagsManager; import java.beans.PropertyChangeEvent; import java.util.ArrayList; import java.util.List; diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/AddTagAction.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/AddTagAction.java index af42c5ef2c..bcf4e18555 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/AddTagAction.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/AddTagAction.java @@ -26,7 +26,7 @@ import javafx.scene.control.MenuItem; import javax.swing.SwingUtilities; import org.sleuthkit.autopsy.actions.GetTagNameAndCommentDialog; import org.sleuthkit.autopsy.actions.GetTagNameDialog; -import org.sleuthkit.autopsy.imagegallery.DrawableTagsManager; +import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableTagsManager; import org.sleuthkit.autopsy.imagegallery.ImageGalleryController; import org.sleuthkit.autopsy.imagegallery.datamodel.CategoryManager; import org.sleuthkit.autopsy.imagegallery.ImageGalleryController; diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/CategorizeAction.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/CategorizeAction.java index 3f6a918524..cfe1f3ac42 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/CategorizeAction.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/CategorizeAction.java @@ -29,7 +29,7 @@ import javafx.scene.input.KeyCode; import javafx.scene.input.KeyCodeCombination; import javax.swing.JOptionPane; import org.sleuthkit.autopsy.coreutils.Logger; -import org.sleuthkit.autopsy.imagegallery.DrawableTagsManager; +import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableTagsManager; import org.sleuthkit.autopsy.imagegallery.FileIDSelectionModel; import org.sleuthkit.autopsy.imagegallery.ImageGalleryController; import org.sleuthkit.autopsy.imagegallery.datamodel.Category; diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/DeleteFollowUpTagAction.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/DeleteFollowUpTagAction.java index 934a3fb258..fb729807c0 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/DeleteFollowUpTagAction.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/DeleteFollowUpTagAction.java @@ -24,7 +24,7 @@ import javafx.event.ActionEvent; import javax.swing.SwingWorker; import org.controlsfx.control.action.Action; import org.sleuthkit.autopsy.coreutils.Logger; -import org.sleuthkit.autopsy.imagegallery.DrawableTagsManager; +import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableTagsManager; import org.sleuthkit.autopsy.imagegallery.ImageGalleryController; import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableFile; import org.sleuthkit.datamodel.ContentTag; diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/CategoryManager.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/CategoryManager.java index e685c118f5..2c7c558997 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/CategoryManager.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/CategoryManager.java @@ -34,8 +34,9 @@ import org.apache.commons.lang3.concurrent.BasicThreadFactory; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.events.ContentTagAddedEvent; import org.sleuthkit.autopsy.events.ContentTagDeletedEvent; -import org.sleuthkit.autopsy.imagegallery.DrawableTagsManager; import org.sleuthkit.autopsy.imagegallery.ImageGalleryController; +import org.sleuthkit.autopsy.imagegallery.datamodel.Category; +import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableDB; import org.sleuthkit.datamodel.ContentTag; import org.sleuthkit.datamodel.TagName; import org.sleuthkit.datamodel.TskCoreException; @@ -262,6 +263,7 @@ public class CategoryManager { fireChange(Collections.singleton(addedTag.getContent().getId()), newCat); } } + @Subscribe @Subscribe public void handleTagDeleted(ContentTagDeletedEvent event) { diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableDB.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableDB.java index db378c9917..87fa001827 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableDB.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableDB.java @@ -47,7 +47,6 @@ import org.openide.util.Exceptions; import org.sleuthkit.autopsy.casemodule.Case; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.imagegallery.ImageGalleryController; -import org.sleuthkit.autopsy.imagegallery.ImageGalleryController; import org.sleuthkit.autopsy.imagegallery.ImageGalleryModule; import org.sleuthkit.autopsy.imagegallery.datamodel.grouping.GroupKey; import org.sleuthkit.autopsy.imagegallery.datamodel.grouping.GroupManager; diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableTagsManager.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableTagsManager.java index 547ab7a858..57d7152967 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableTagsManager.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableTagsManager.java @@ -18,21 +18,19 @@ */ package org.sleuthkit.autopsy.imagegallery.datamodel; -import com.google.common.eventbus.AsyncEventBus; import com.google.common.eventbus.EventBus; import java.util.Collection; import java.util.Collections; import java.util.List; import java.util.Objects; -import java.util.concurrent.Executors; import java.util.logging.Level; import java.util.stream.Collectors; -import javax.annotation.Nonnull; -import org.apache.commons.lang3.concurrent.BasicThreadFactory; import org.sleuthkit.autopsy.casemodule.services.TagsManager; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.events.ContentTagAddedEvent; import org.sleuthkit.autopsy.events.ContentTagDeletedEvent; +import org.sleuthkit.autopsy.imagegallery.datamodel.Category; +import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableFile; import org.sleuthkit.datamodel.Content; import org.sleuthkit.datamodel.ContentTag; import org.sleuthkit.datamodel.TagName; @@ -44,20 +42,13 @@ import org.sleuthkit.datamodel.TskCoreException; */ public class DrawableTagsManager { - private static final Logger LOGGER = Logger.getLogger(DrawableTagsManager.class.getName()); - private static final String FOLLOW_UP = "Follow Up"; final private Object autopsyTagsManagerLock = new Object(); private TagsManager autopsyTagsManager; /** Used to distribute {@link TagsChangeEvent}s */ - private final EventBus tagsEventBus = new AsyncEventBus( - Executors.newSingleThreadExecutor( - new BasicThreadFactory.Builder().namingPattern("Tags Event Bus").uncaughtExceptionHandler((Thread t, Throwable e) -> { - LOGGER.log(Level.SEVERE, "uncaught exception in event bus handler", e); - }).build() - )); + private final EventBus tagsEventBus = new EventBus("Tags Event Bus"); /** The tag name corresponding to the "built-in" tag "Follow Up" */ private TagName followUpTagName; @@ -132,23 +123,14 @@ public class DrawableTagsManager { } } - /** - * get all the TagNames that are not categories - * - * @return all the TagNames that are not categories, in alphabetical order - * by displayName, or, an empty set if there was an exception looking them - * up from the db. - */ - @Nonnull public Collection getNonCategoryTagNames() { synchronized (autopsyTagsManagerLock) { try { return autopsyTagsManager.getAllTagNames().stream() - .filter(CategoryManager::isNotCategoryTagName) - .distinct().sorted() - .collect(Collectors.toList()); + .filter(CategoryManager::isCategoryTagName) + .collect(Collectors.toSet()); } catch (TskCoreException | IllegalStateException ex) { - LOGGER.log(Level.WARNING, "couldn't access case", ex); + Logger.getLogger(DrawableTagsManager.class.getName()).log(Level.WARNING, "couldn't access case", ex); } return Collections.emptySet(); } @@ -184,7 +166,7 @@ public class DrawableTagsManager { throw new TskCoreException("tagame exists but wasn't found", ex); } } catch (IllegalStateException ex) { - LOGGER.log(Level.SEVERE, "Case was closed out from underneath", ex); + Logger.getLogger(DrawableTagsManager.class.getName()).log(Level.SEVERE, "Case was closed out from underneath", ex); throw new TskCoreException("Case was closed out from underneath", ex); } } diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/GroupManager.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/GroupManager.java index c0f0c27725..6ecf5a5dca 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/GroupManager.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/GroupManager.java @@ -50,7 +50,6 @@ import javax.annotation.concurrent.GuardedBy; import javax.swing.SortOrder; import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.commons.lang3.Validate; import org.apache.commons.lang3.concurrent.BasicThreadFactory; import org.netbeans.api.progress.ProgressHandle; import org.netbeans.api.progress.ProgressHandleFactory; @@ -647,8 +646,6 @@ public class GroupManager { */ @Subscribe synchronized public void handleFileUpdate(Collection updatedFileIDs) { - Validate.isTrue(evt.getUpdateType() == FileUpdateEvent.UpdateType.UPDATE); - Collection fileIDs = evt.getFileIDs(); /** * TODO: is there a way to optimize this to avoid quering to db * so much. the problem is that as a new files are analyzed they @@ -670,7 +667,6 @@ public class GroupManager { //we fire this event for all files so that the category counts get updated during initial db population controller.getCategoryManager().fireChange(updatedFileIDs, null); } - private DrawableGroup popuplateIfAnalyzed(GroupKey groupKey, ReGroupTask task) { if (Objects.nonNull(task) && (task.isCancelled())) { From ed2fcdf80eceb4c01b26126bb83edb324b8ca0a3 Mon Sep 17 00:00:00 2001 From: jmillman Date: Mon, 22 Jun 2015 16:42:44 -0400 Subject: [PATCH 48/56] better handling of exceptions in event bus eventhandlers --- .../datamodel/CategoryManager.java | 2 -- .../datamodel/DrawableTagsManager.java | 18 +++++++++++++----- .../datamodel/grouping/GroupManager.java | 19 +++++++++++-------- 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/CategoryManager.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/CategoryManager.java index 2c7c558997..d77d9583ce 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/CategoryManager.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/CategoryManager.java @@ -35,8 +35,6 @@ import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.events.ContentTagAddedEvent; import org.sleuthkit.autopsy.events.ContentTagDeletedEvent; import org.sleuthkit.autopsy.imagegallery.ImageGalleryController; -import org.sleuthkit.autopsy.imagegallery.datamodel.Category; -import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableDB; import org.sleuthkit.datamodel.ContentTag; import org.sleuthkit.datamodel.TagName; import org.sleuthkit.datamodel.TskCoreException; diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableTagsManager.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableTagsManager.java index 57d7152967..af5a0ebced 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableTagsManager.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableTagsManager.java @@ -18,19 +18,20 @@ */ package org.sleuthkit.autopsy.imagegallery.datamodel; +import com.google.common.eventbus.AsyncEventBus; import com.google.common.eventbus.EventBus; import java.util.Collection; import java.util.Collections; import java.util.List; import java.util.Objects; +import java.util.concurrent.Executors; import java.util.logging.Level; import java.util.stream.Collectors; +import org.apache.commons.lang3.concurrent.BasicThreadFactory; import org.sleuthkit.autopsy.casemodule.services.TagsManager; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.events.ContentTagAddedEvent; import org.sleuthkit.autopsy.events.ContentTagDeletedEvent; -import org.sleuthkit.autopsy.imagegallery.datamodel.Category; -import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableFile; import org.sleuthkit.datamodel.Content; import org.sleuthkit.datamodel.ContentTag; import org.sleuthkit.datamodel.TagName; @@ -42,13 +43,20 @@ import org.sleuthkit.datamodel.TskCoreException; */ public class DrawableTagsManager { + private static final Logger LOGGER = Logger.getLogger(DrawableTagsManager.class.getName()); + private static final String FOLLOW_UP = "Follow Up"; final private Object autopsyTagsManagerLock = new Object(); private TagsManager autopsyTagsManager; /** Used to distribute {@link TagsChangeEvent}s */ - private final EventBus tagsEventBus = new EventBus("Tags Event Bus"); + private final EventBus tagsEventBus = new AsyncEventBus( + Executors.newSingleThreadExecutor( + new BasicThreadFactory.Builder().namingPattern("Tags Event Bus").uncaughtExceptionHandler((Thread t, Throwable e) -> { + LOGGER.log(Level.SEVERE, "uncaught exception in event bus handler", e); + }).build() + )); /** The tag name corresponding to the "built-in" tag "Follow Up" */ private TagName followUpTagName; @@ -130,7 +138,7 @@ public class DrawableTagsManager { .filter(CategoryManager::isCategoryTagName) .collect(Collectors.toSet()); } catch (TskCoreException | IllegalStateException ex) { - Logger.getLogger(DrawableTagsManager.class.getName()).log(Level.WARNING, "couldn't access case", ex); + LOGGER.log(Level.WARNING, "couldn't access case", ex); } return Collections.emptySet(); } @@ -166,7 +174,7 @@ public class DrawableTagsManager { throw new TskCoreException("tagame exists but wasn't found", ex); } } catch (IllegalStateException ex) { - Logger.getLogger(DrawableTagsManager.class.getName()).log(Level.SEVERE, "Case was closed out from underneath", ex); + LOGGER.log(Level.SEVERE, "Case was closed out from underneath", ex); throw new TskCoreException("Case was closed out from underneath", ex); } } diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/GroupManager.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/GroupManager.java index 6ecf5a5dca..623d0e7363 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/GroupManager.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/GroupManager.java @@ -551,15 +551,16 @@ public class GroupManager { @Subscribe public void handleTagAdded(ContentTagAddedEvent evt) { GroupKey groupKey = null; - if (groupBy == DrawableAttribute.TAGS) { - groupKey = new GroupKey(DrawableAttribute.TAGS, evt.getTag().getName()); - } else if (groupBy == DrawableAttribute.CATEGORY) { + if (groupBy == DrawableAttribute.CATEGORY && CategoryManager.isCategoryTagName(evt.getTag().getName())) { groupKey = new GroupKey(DrawableAttribute.CATEGORY, CategoryManager.categoryFromTagName(evt.getTag().getName())); + } else if (groupBy == DrawableAttribute.TAGS && CategoryManager.isNotCategoryTagName(evt.getTag().getName())) { + groupKey = new GroupKey(DrawableAttribute.TAGS, evt.getTag().getName()); + } + if (groupKey != null) { + final long fileID = evt.getTag().getContent().getId(); + DrawableGroup g = getGroupForKey(groupKey); + addFileToGroup(g, groupKey, fileID); } - final long fileID = evt.getTag().getContent().getId(); - DrawableGroup g = getGroupForKey(groupKey); - addFileToGroup(g, groupKey, fileID); - } @SuppressWarnings("AssignmentToMethodParameter") @@ -618,9 +619,11 @@ public class GroupManager { } else if (groupBy == DrawableAttribute.TAGS && CategoryManager.isNotCategoryTagName(evt.getTag().getName())) { groupKey = new GroupKey(DrawableAttribute.TAGS, evt.getTag().getName()); } + if (groupKey != null) { final long fileID = evt.getTag().getContent().getId(); - DrawableGroup g = removeFromGroup(groupKey, fileID); + DrawableGroup g = removeFromGroup(groupKey, fileID); + } } } } From e157a5b53b9cd152b2656cf5074aa235132aa1fe Mon Sep 17 00:00:00 2001 From: jmillman Date: Tue, 23 Jun 2015 15:46:12 -0400 Subject: [PATCH 49/56] only add new cat tag if there is no existing cat tag. put adding and removing fileids to/from group on jfx thread; remove file from groups when adding to new catagory based on new tag --- .../imagegallery/ImageGalleryController.java | 1 - .../actions/CategorizeAction.java | 13 +++++++-- .../datamodel/grouping/GroupManager.java | 28 ++++++++++++------- 3 files changed, 28 insertions(+), 14 deletions(-) diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java index b47bafe5a9..6752b3a44f 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java @@ -18,7 +18,6 @@ */ package org.sleuthkit.autopsy.imagegallery; -import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableTagsManager; import java.beans.PropertyChangeEvent; import java.util.ArrayList; import java.util.List; diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/CategorizeAction.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/CategorizeAction.java index cfe1f3ac42..b9b9cee59f 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/CategorizeAction.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/CategorizeAction.java @@ -19,6 +19,7 @@ package org.sleuthkit.autopsy.imagegallery.actions; import java.util.HashSet; +import java.util.List; import java.util.Set; import java.util.logging.Level; import java.util.stream.Collectors; @@ -29,13 +30,13 @@ import javafx.scene.input.KeyCode; import javafx.scene.input.KeyCodeCombination; import javax.swing.JOptionPane; import org.sleuthkit.autopsy.coreutils.Logger; -import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableTagsManager; import org.sleuthkit.autopsy.imagegallery.FileIDSelectionModel; import org.sleuthkit.autopsy.imagegallery.ImageGalleryController; import org.sleuthkit.autopsy.imagegallery.datamodel.Category; import org.sleuthkit.autopsy.imagegallery.datamodel.CategoryManager; import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableFile; import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableTagsManager; +import org.sleuthkit.datamodel.ContentTag; import org.sleuthkit.datamodel.Tag; import org.sleuthkit.datamodel.TagName; import org.sleuthkit.datamodel.TskCoreException; @@ -151,8 +152,6 @@ public class CategorizeAction extends AddTagAction { .collect(Collectors.toList()).isEmpty()) { tagsManager.addContentTag(file, tagName, comment); } - } else { - tagsManager.getContentTagsByContent(file).stream() .filter(tag -> CategoryManager.isCategoryTagName(tag.getName())) .forEach((ct) -> { try { @@ -161,6 +160,14 @@ public class CategorizeAction extends AddTagAction { LOGGER.log(Level.SEVERE, "Error removing old categories result", ex); } }); + } else { + //add cat tag if no existing cat tag for that cat + if (fileTags.stream() + .map(Tag::getName) + .filter(tagName::equals) + .collect(Collectors.toList()).isEmpty()) { + tagsManager.addContentTag(file, tagName, comment); + } } } catch (TskCoreException ex) { diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/GroupManager.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/GroupManager.java index 623d0e7363..0fbf76a64e 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/GroupManager.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/GroupManager.java @@ -550,16 +550,21 @@ public class GroupManager { @Subscribe public void handleTagAdded(ContentTagAddedEvent evt) { - GroupKey groupKey = null; + GroupKey newGroupKey = null; + final long fileID = evt.getTag().getContent().getId(); if (groupBy == DrawableAttribute.CATEGORY && CategoryManager.isCategoryTagName(evt.getTag().getName())) { - groupKey = new GroupKey(DrawableAttribute.CATEGORY, CategoryManager.categoryFromTagName(evt.getTag().getName())); + newGroupKey = new GroupKey(DrawableAttribute.CATEGORY, CategoryManager.categoryFromTagName(evt.getTag().getName())); + for (GroupKey oldGroupKey : groupMap.keySet()) { + if (oldGroupKey.equals(newGroupKey) == false) { + removeFromGroup(oldGroupKey, fileID); + } + } } else if (groupBy == DrawableAttribute.TAGS && CategoryManager.isNotCategoryTagName(evt.getTag().getName())) { - groupKey = new GroupKey(DrawableAttribute.TAGS, evt.getTag().getName()); + newGroupKey = new GroupKey(DrawableAttribute.TAGS, evt.getTag().getName()); } - if (groupKey != null) { - final long fileID = evt.getTag().getContent().getId(); - DrawableGroup g = getGroupForKey(groupKey); - addFileToGroup(g, groupKey, fileID); + if (newGroupKey != null) { + DrawableGroup g = getGroupForKey(newGroupKey); + addFileToGroup(g, newGroupKey, fileID); } } @@ -569,9 +574,13 @@ public class GroupManager { //if there wasn't already a group check if there should be one now g = popuplateIfAnalyzed(groupKey, null); } - if (g != null) { + DrawableGroup group = g; + if (group != null) { //if there is aleady a group that was previously deemed fully analyzed, then add this newly analyzed file to it. - g.addFile(fileID); + Platform.runLater(() -> { + group.addFile(fileID); + }); + } } @@ -619,7 +628,6 @@ public class GroupManager { } else if (groupBy == DrawableAttribute.TAGS && CategoryManager.isNotCategoryTagName(evt.getTag().getName())) { groupKey = new GroupKey(DrawableAttribute.TAGS, evt.getTag().getName()); } - if (groupKey != null) { final long fileID = evt.getTag().getContent().getId(); DrawableGroup g = removeFromGroup(groupKey, fileID); From 257ebc64da55e7180aa4d70434cc2fd3177e4215 Mon Sep 17 00:00:00 2001 From: jmillman Date: Tue, 23 Jun 2015 16:12:55 -0400 Subject: [PATCH 50/56] clean up add tag action, use invokeLater not invokeAndWait; getNonCategoryTagNames returns TagNames in alphabetical order by displayname --- .../autopsy/imagegallery/actions/AddTagAction.java | 1 - .../datamodel/DrawableTagsManager.java | 14 ++++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/AddTagAction.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/AddTagAction.java index bcf4e18555..44bb02f0e0 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/AddTagAction.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/AddTagAction.java @@ -26,7 +26,6 @@ import javafx.scene.control.MenuItem; import javax.swing.SwingUtilities; import org.sleuthkit.autopsy.actions.GetTagNameAndCommentDialog; import org.sleuthkit.autopsy.actions.GetTagNameDialog; -import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableTagsManager; import org.sleuthkit.autopsy.imagegallery.ImageGalleryController; import org.sleuthkit.autopsy.imagegallery.datamodel.CategoryManager; import org.sleuthkit.autopsy.imagegallery.ImageGalleryController; diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableTagsManager.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableTagsManager.java index af5a0ebced..547ab7a858 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableTagsManager.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableTagsManager.java @@ -27,6 +27,7 @@ import java.util.Objects; import java.util.concurrent.Executors; import java.util.logging.Level; import java.util.stream.Collectors; +import javax.annotation.Nonnull; import org.apache.commons.lang3.concurrent.BasicThreadFactory; import org.sleuthkit.autopsy.casemodule.services.TagsManager; import org.sleuthkit.autopsy.coreutils.Logger; @@ -131,12 +132,21 @@ public class DrawableTagsManager { } } + /** + * get all the TagNames that are not categories + * + * @return all the TagNames that are not categories, in alphabetical order + * by displayName, or, an empty set if there was an exception looking them + * up from the db. + */ + @Nonnull public Collection getNonCategoryTagNames() { synchronized (autopsyTagsManagerLock) { try { return autopsyTagsManager.getAllTagNames().stream() - .filter(CategoryManager::isCategoryTagName) - .collect(Collectors.toSet()); + .filter(CategoryManager::isNotCategoryTagName) + .distinct().sorted() + .collect(Collectors.toList()); } catch (TskCoreException | IllegalStateException ex) { LOGGER.log(Level.WARNING, "couldn't access case", ex); } From bb85f3feda300aa8b9932dc0f10eb0861a875cab Mon Sep 17 00:00:00 2001 From: jmillman Date: Tue, 23 Jun 2015 16:23:59 -0400 Subject: [PATCH 51/56] SlideShow toggle is disabled initialy; fix relative paths to images in fxml --- .../gui/drawableviews/DrawableTile.fxml | 112 +++++++++--------- .../gui/drawableviews/GroupPane.fxml | 2 +- 2 files changed, 58 insertions(+), 56 deletions(-) diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/DrawableTile.fxml b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/DrawableTile.fxml index 4d34061c77..acfcdc1336 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/DrawableTile.fxml +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/DrawableTile.fxml @@ -7,60 +7,62 @@ - - - - -
- -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+ +
+ +
+
+
-
-
- -
-
-
-
-
- - - + + + +
diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/GroupPane.fxml b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/GroupPane.fxml index 6dfe0d02ed..4760d1f0cf 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/GroupPane.fxml +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/GroupPane.fxml @@ -113,7 +113,7 @@ - + From 773e4293c54b6cc5378de857e9eca09502f8cdbc Mon Sep 17 00:00:00 2001 From: jmillman Date: Tue, 23 Jun 2015 16:27:03 -0400 Subject: [PATCH 52/56] SlideShow toggle is disabled when there is no group selected; fix relative paths to images in fxml --- .../autopsy/imagegallery/gui/drawableviews/GroupPane.fxml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/GroupPane.fxml b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/GroupPane.fxml index 4760d1f0cf..6dfe0d02ed 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/GroupPane.fxml +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/GroupPane.fxml @@ -113,7 +113,7 @@ - + From 622da1c8de70b3aaeaa94954abb1c5c224d7ee9a Mon Sep 17 00:00:00 2001 From: jmillman Date: Wed, 24 Jun 2015 10:17:51 -0400 Subject: [PATCH 53/56] use private notifyPropertyChangeEvent() method in notifyNewDataSource --- .../sleuthkit/autopsy/casemodule/Case.java | 203 +++++++++--------- 1 file changed, 97 insertions(+), 106 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/Case.java b/Core/src/org/sleuthkit/autopsy/casemodule/Case.java index e7086cf3b0..d26210177e 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/Case.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/Case.java @@ -521,6 +521,103 @@ public class Case implements SleuthkitCase.ErrorObserver { notifyPropertyChangeEvent(new BlackBoardArtifactTagAddedEvent(newTag)); } + /** + * Notifies the UI that a BlackboardArtifactTag has been. + * + * @param deletedTag BlackboardArtifactTag deleted + */ + public void notifyBlackBoardArtifactTagDeleted(BlackboardArtifactTag deletedTag) { + notifyPropertyChangeEvent(new BlackBoardArtifactTagDeletedEvent(deletedTag)); + } + /** + * Notifies the UI about a Case level event. + * + * @param propertyChangeEvent the event to distribute + */ + private void notifyPropertyChangeEvent(final PropertyChangeEvent propertyChangeEvent) { + pcs.firePropertyChange(propertyChangeEvent); + } catch (Exception e) { + logger.log(Level.SEVERE, "Case threw exception", e); //NON-NLS + MessageNotifyUtil.Notify.show(NbBundle.getMessage(this.getClass(), "Case.moduleErr"), + NbBundle.getMessage(this.getClass(), + "Case.changeCase.errListenToCaseUpdates.msg"), + MessageNotifyUtil.MessageType.ERROR); + } + } + + /** + * Notifies the UI that a new ContentTag has been added. + * + * @param newTag new ContentTag added + */ + public void notifyContentTagAdded(ContentTag newTag) { + notify(new ContentTagAddedEvent(newTag)); + } + + /** + * Notifies the UI that a ContentTag has been deleted. + * + * @param deletedTag ContentTag deleted + */ + public void notifyContentTagDeleted(ContentTag deletedTag) { + notify(new ContentTagDeletedEvent(deletedTag)); + } + + /** + * Notifies the UI that a new BlackboardArtifactTag has been added. + * + * @param newTag new BlackboardArtifactTag added + */ + public void notifyBlackBoardArtifactTagAdded(BlackboardArtifactTag newTag) { + notify(new BlackBoardArtifactTagAddedEvent(newTag)); + } + + /** + * Notifies the UI that a BlackboardArtifactTag has been. + * + * @param deletedTag BlackboardArtifactTag deleted + */ + public void notifyBlackBoardArtifactTagDeleted(BlackboardArtifactTag deletedTag) { + notify(new BlackBoardArtifactTagDeletedEvent(deletedTag)); + } + + /** + * Notifies the UI about a Case level event. + * + * @param propertyChangeEvent the event to distribute + */ + private void notify(final PropertyChangeEvent propertyChangeEvent) { + try { + pcs.firePropertyChange(propertyChangeEvent); + } + + /** + * Notifies the UI that a new ContentTag has been added. + * + * @param newTag new ContentTag added + */ + public void notifyContentTagAdded(ContentTag newTag) { + notifyPropertyChangeEvent(new ContentTagAddedEvent(newTag)); + } + + /** + * Notifies the UI that a ContentTag has been deleted. + * + * @param deletedTag ContentTag deleted + */ + public void notifyContentTagDeleted(ContentTag deletedTag) { + notifyPropertyChangeEvent(new ContentTagDeletedEvent(deletedTag)); + } + + /** + * Notifies the UI that a new BlackboardArtifactTag has been added. + * + * @param newTag new BlackboardArtifactTag added + */ + public void notifyBlackBoardArtifactTagAdded(BlackboardArtifactTag newTag) { + notifyPropertyChangeEvent(new BlackBoardArtifactTagAddedEvent(newTag)); + } + /** * Notifies the UI that a BlackboardArtifactTag has been. * @@ -547,112 +644,6 @@ public class Case implements SleuthkitCase.ErrorObserver { } } - /** - * Notifies the UI that a new ContentTag has been added. - * - * @param newTag new ContentTag added - */ - public void notifyContentTagAdded(ContentTag newTag) { - notify(new ContentTagAddedEvent(newTag)); - } - - /** - * Notifies the UI that a ContentTag has been deleted. - * - * @param deletedTag ContentTag deleted - */ - public void notifyContentTagDeleted(ContentTag deletedTag) { - notify(new ContentTagDeletedEvent(deletedTag)); - } - - /** - * Notifies the UI that a new BlackboardArtifactTag has been added. - * - * @param newTag new BlackboardArtifactTag added - */ - public void notifyBlackBoardArtifactTagAdded(BlackboardArtifactTag newTag) { - notify(new BlackBoardArtifactTagAddedEvent(newTag)); - } - - /** - * Notifies the UI that a BlackboardArtifactTag has been. - * - * @param deletedTag BlackboardArtifactTag deleted - */ - public void notifyBlackBoardArtifactTagDeleted(BlackboardArtifactTag deletedTag) { - notify(new BlackBoardArtifactTagDeletedEvent(deletedTag)); - } - - /** - * Notifies the UI about a Case level event. - * - * @param propertyChangeEvent the event to distribute - */ - private void notify(final PropertyChangeEvent propertyChangeEvent) { - try { - pcs.firePropertyChange(propertyChangeEvent); - } catch (Exception e) { - logger.log(Level.SEVERE, "Case threw exception", e); //NON-NLS - MessageNotifyUtil.Notify.show(NbBundle.getMessage(this.getClass(), "Case.moduleErr"), - NbBundle.getMessage(this.getClass(), - "Case.changeCase.errListenToCaseUpdates.msg"), - MessageNotifyUtil.MessageType.ERROR); - } - } - - /** - * Notifies the UI that a new ContentTag has been added. - * - * @param newTag new ContentTag added - */ - public void notifyContentTagAdded(ContentTag newTag) { - notify(new ContentTagAddedEvent(newTag)); - } - - /** - * Notifies the UI that a ContentTag has been deleted. - * - * @param deletedTag ContentTag deleted - */ - public void notifyContentTagDeleted(ContentTag deletedTag) { - notify(new ContentTagDeletedEvent(deletedTag)); - } - - /** - * Notifies the UI that a new BlackboardArtifactTag has been added. - * - * @param newTag new BlackboardArtifactTag added - */ - public void notifyBlackBoardArtifactTagAdded(BlackboardArtifactTag newTag) { - notify(new BlackBoardArtifactTagAddedEvent(newTag)); - } - - /** - * Notifies the UI that a BlackboardArtifactTag has been. - * - * @param deletedTag BlackboardArtifactTag deleted - */ - public void notifyBlackBoardArtifactTagDeleted(BlackboardArtifactTag deletedTag) { - notify(new BlackBoardArtifactTagDeletedEvent(deletedTag)); - } - - /** - * Notifies the UI about a Case level event. - * - * @param propertyChangeEvent the event to distribute - */ - private void notify(final PropertyChangeEvent propertyChangeEvent) { - try { - pcs.firePropertyChange(propertyChangeEvent); - } catch (Exception e) { - logger.log(Level.SEVERE, "Case threw exception", e); //NON-NLS - MessageNotifyUtil.Notify.show(NbBundle.getMessage(this.getClass(), "Case.moduleErr"), - NbBundle.getMessage(this.getClass(), - "Case.changeCase.errListenToCaseUpdates.msg"), - MessageNotifyUtil.MessageType.ERROR); - } - } - /** * @return The Services object for this case. */ From 5b904edba673bf1251ed6c2f568527b955240616 Mon Sep 17 00:00:00 2001 From: jmillman Date: Thu, 25 Jun 2015 11:07:45 -0400 Subject: [PATCH 54/56] fix merge mistakes --- .../sleuthkit/autopsy/casemodule/Case.java | 97 --------------- .../casemodule/services/TagsManager.java | 2 +- .../imagegallery/ImageGalleryController.java | 17 +-- .../actions/CategorizeAction.java | 18 +-- .../imagegallery/datamodel/Category.java | 4 +- .../datamodel/CategoryManager.java | 4 +- .../datamodel/grouping/GroupManager.java | 117 +++--------------- .../gui/drawableviews/DrawableView.java | 2 +- .../gui/drawableviews/MetaDataPane.java | 30 ++--- 9 files changed, 33 insertions(+), 258 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/Case.java b/Core/src/org/sleuthkit/autopsy/casemodule/Case.java index d26210177e..b4c61305b2 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/Case.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/Case.java @@ -521,103 +521,6 @@ public class Case implements SleuthkitCase.ErrorObserver { notifyPropertyChangeEvent(new BlackBoardArtifactTagAddedEvent(newTag)); } - /** - * Notifies the UI that a BlackboardArtifactTag has been. - * - * @param deletedTag BlackboardArtifactTag deleted - */ - public void notifyBlackBoardArtifactTagDeleted(BlackboardArtifactTag deletedTag) { - notifyPropertyChangeEvent(new BlackBoardArtifactTagDeletedEvent(deletedTag)); - } - /** - * Notifies the UI about a Case level event. - * - * @param propertyChangeEvent the event to distribute - */ - private void notifyPropertyChangeEvent(final PropertyChangeEvent propertyChangeEvent) { - pcs.firePropertyChange(propertyChangeEvent); - } catch (Exception e) { - logger.log(Level.SEVERE, "Case threw exception", e); //NON-NLS - MessageNotifyUtil.Notify.show(NbBundle.getMessage(this.getClass(), "Case.moduleErr"), - NbBundle.getMessage(this.getClass(), - "Case.changeCase.errListenToCaseUpdates.msg"), - MessageNotifyUtil.MessageType.ERROR); - } - } - - /** - * Notifies the UI that a new ContentTag has been added. - * - * @param newTag new ContentTag added - */ - public void notifyContentTagAdded(ContentTag newTag) { - notify(new ContentTagAddedEvent(newTag)); - } - - /** - * Notifies the UI that a ContentTag has been deleted. - * - * @param deletedTag ContentTag deleted - */ - public void notifyContentTagDeleted(ContentTag deletedTag) { - notify(new ContentTagDeletedEvent(deletedTag)); - } - - /** - * Notifies the UI that a new BlackboardArtifactTag has been added. - * - * @param newTag new BlackboardArtifactTag added - */ - public void notifyBlackBoardArtifactTagAdded(BlackboardArtifactTag newTag) { - notify(new BlackBoardArtifactTagAddedEvent(newTag)); - } - - /** - * Notifies the UI that a BlackboardArtifactTag has been. - * - * @param deletedTag BlackboardArtifactTag deleted - */ - public void notifyBlackBoardArtifactTagDeleted(BlackboardArtifactTag deletedTag) { - notify(new BlackBoardArtifactTagDeletedEvent(deletedTag)); - } - - /** - * Notifies the UI about a Case level event. - * - * @param propertyChangeEvent the event to distribute - */ - private void notify(final PropertyChangeEvent propertyChangeEvent) { - try { - pcs.firePropertyChange(propertyChangeEvent); - } - - /** - * Notifies the UI that a new ContentTag has been added. - * - * @param newTag new ContentTag added - */ - public void notifyContentTagAdded(ContentTag newTag) { - notifyPropertyChangeEvent(new ContentTagAddedEvent(newTag)); - } - - /** - * Notifies the UI that a ContentTag has been deleted. - * - * @param deletedTag ContentTag deleted - */ - public void notifyContentTagDeleted(ContentTag deletedTag) { - notifyPropertyChangeEvent(new ContentTagDeletedEvent(deletedTag)); - } - - /** - * Notifies the UI that a new BlackboardArtifactTag has been added. - * - * @param newTag new BlackboardArtifactTag added - */ - public void notifyBlackBoardArtifactTagAdded(BlackboardArtifactTag newTag) { - notifyPropertyChangeEvent(new BlackBoardArtifactTagAddedEvent(newTag)); - } - /** * Notifies the UI that a BlackboardArtifactTag has been. * diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/services/TagsManager.java b/Core/src/org/sleuthkit/autopsy/casemodule/services/TagsManager.java index d5ec4fc7c2..01daae9fba 100755 --- a/Core/src/org/sleuthkit/autopsy/casemodule/services/TagsManager.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/services/TagsManager.java @@ -253,6 +253,7 @@ public class TagsManager implements Closeable { } catch (IllegalArgumentException ex) { Logger.getLogger(TagsManager.class.getName()).log(Level.WARNING, NbBundle.getMessage(TagsManager.class, "TagsManager.addContentTag.noCaseWarning")); } + return newContentTag; } /** @@ -403,7 +404,6 @@ public class TagsManager implements Closeable { getExistingTagNames(); } - Case.getPropertyChangeSupport().firePropertyChange(Case.Events.BLACKBOARD_ARTIFACT_TAG_DELETED.toString(), tag, null); tskCase.deleteBlackboardArtifactTag(tag); try { Case.getCurrentCase().notifyBlackBoardArtifactTagDeleted(tag); diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java index 6752b3a44f..84fe4bef36 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java @@ -502,18 +502,7 @@ public final class ImageGalleryController { getTagsManager().fireTagDeletedEvent(tagDeletedEvent); } break; - case CONTENT_TAG_ADDED: - final ContentTagAddedEvent tagAddedEvent = (ContentTagAddedEvent) evt; - if (getDatabase().isInDB((tagAddedEvent).getTag().getContent().getId())) { - getTagsManager().fireTagAddedEvent(tagAddedEvent); - } - break; - case CONTENT_TAG_DELETED: - final ContentTagDeletedEvent tagDeletedEvent = (ContentTagDeletedEvent) evt; - if (getDatabase().isInDB((tagDeletedEvent).getTag().getContent().getId())) { - getTagsManager().fireTagDeletedEvent(tagDeletedEvent); - } - break; + } }); } @@ -530,9 +519,7 @@ public final class ImageGalleryController { return tagsManager; } - public DrawableTagsManager getTagsManager() { - return tagsManager; - } + // @@@ REVIEW IF THIS SHOLD BE STATIC... //TODO: concept seems like the controller deal with how much work to do at a given time diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/CategorizeAction.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/CategorizeAction.java index b9b9cee59f..463ab3a1be 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/CategorizeAction.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/CategorizeAction.java @@ -144,23 +144,7 @@ public class CategorizeAction extends AddTagAction { LOGGER.log(Level.SEVERE, "Error removing old categories result", ex); } }); - } else { - //add cat tag if no existing cat tag for that cat - if (fileTags.stream() - .map(Tag::getName) - .filter(tagName::equals) - .collect(Collectors.toList()).isEmpty()) { - tagsManager.addContentTag(file, tagName, comment); - } - .filter(tag -> CategoryManager.isCategoryTagName(tag.getName())) - .forEach((ct) -> { - try { - tagsManager.deleteContentTag(ct); - } catch (TskCoreException ex) { - LOGGER.log(Level.SEVERE, "Error removing old categories result", ex); - } - }); - } else { + } else { //add cat tag if no existing cat tag for that cat if (fileTags.stream() .map(Tag::getName) diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/Category.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/Category.java index 3fd1a6c92c..8999fff2f1 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/Category.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/Category.java @@ -48,11 +48,9 @@ public enum Category { public static Category fromDisplayName(String displayName) { return nameMap.get(displayName); } + public static boolean isCategoryName(String tName) { return nameMap.containsKey(tName); - - public static boolean isNotCategoryName(String tName) { - return nameMap.containsKey(tName) == false; } public static boolean isNotCategoryName(String tName) { diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/CategoryManager.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/CategoryManager.java index d77d9583ce..f6ab66fa04 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/CategoryManager.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/CategoryManager.java @@ -25,7 +25,6 @@ import com.google.common.eventbus.EventBus; import com.google.common.eventbus.Subscribe; import java.util.Collection; import java.util.Collections; -import java.util.List; import java.util.concurrent.Executors; import java.util.concurrent.atomic.LongAdder; import java.util.logging.Level; @@ -57,7 +56,7 @@ public class CategoryManager { private final ImageGalleryController controller; - private final ImageGalleryController controller; + /** * the DrawableDB that backs the category counts cache. The counts are @@ -262,7 +261,6 @@ public class CategoryManager { } } - @Subscribe @Subscribe public void handleTagDeleted(ContentTagDeletedEvent event) { ContentTag deleted = event.getTag(); diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/GroupManager.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/GroupManager.java index 0fbf76a64e..ec63a51740 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/GroupManager.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/GroupManager.java @@ -36,6 +36,7 @@ import java.util.TreeSet; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.logging.Level; +import java.util.logging.Logger; import java.util.stream.Collectors; import java.util.stream.Stream; import javafx.application.Platform; @@ -44,6 +45,12 @@ import javafx.beans.property.ReadOnlyDoubleWrapper; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.collections.transformation.SortedList; +import static javafx.concurrent.Worker.State.CANCELLED; +import static javafx.concurrent.Worker.State.FAILED; +import static javafx.concurrent.Worker.State.READY; +import static javafx.concurrent.Worker.State.RUNNING; +import static javafx.concurrent.Worker.State.SCHEDULED; +import static javafx.concurrent.Worker.State.SUCCEEDED; import javax.annotation.Nonnull; import javax.annotation.Nullable; import javax.annotation.concurrent.GuardedBy; @@ -56,7 +63,6 @@ import org.netbeans.api.progress.ProgressHandleFactory; import org.openide.util.Exceptions; import org.sleuthkit.autopsy.casemodule.Case; import org.sleuthkit.autopsy.coreutils.LoggedTask; -import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.coreutils.ThreadConfined; import org.sleuthkit.autopsy.coreutils.ThreadConfined.ThreadType; import org.sleuthkit.autopsy.events.ContentTagAddedEvent; @@ -244,10 +250,11 @@ public class GroupManager { * 'mark' the given group as seen. This removes it from the queue of * groups * files. - public DrawableGroup makeGroup(GroupKey groupKey, Set files) { - - Set newFiles = ObjectUtils.defaultIfNull(files, new HashSet()); - } + * public DrawableGroup makeGroup(GroupKey groupKey, Set files) { + * + * Set newFiles = ObjectUtils.defaultIfNull(files, new + * HashSet()); + * } * groups * to review, and is persisted in the drawable db. * @@ -255,8 +262,7 @@ public class GroupManager { */ @ThreadConfined(type = ThreadType.JFX) public void markGroupSeen(DrawableGroup group, boolean seen) { - public void markGroupSeen(DrawableGroup group, boolean seen - ) { + db.markGroupSeen(group.getGroupKey(), seen); group.setSeen(seen); if (seen) { @@ -292,19 +298,15 @@ public class GroupManager { if (unSeenGroups.contains(group)) { unSeenGroups.remove(group); } - } + }); } - } else { //group == null - // It may be that this was the last unanalyzed file in the group, so test - // whether the group is now fully analyzed. - popuplateIfAnalyzed(groupKey, null); + } else { //group == null + // It may be that this was the last unanalyzed file in the group, so test + // whether the group is now fully analyzed. + popuplateIfAnalyzed(groupKey, null); } - } else { //group == null - // It may be that this was the last unanalyzed file in the group, so test - // whether the group is now fully analyzed. - popuplateIfAnalyzed(groupKey, null); - + } return group; } @@ -584,42 +586,6 @@ public class GroupManager { } } - @Subscribe - public void handleTagAdded(ContentTagAddedEvent evt) { - GroupKey newGroupKey = null; - final long fileID = evt.getTag().getContent().getId(); - if (groupBy == DrawableAttribute.CATEGORY && CategoryManager.isCategoryTagName(evt.getTag().getName())) { - newGroupKey = new GroupKey(DrawableAttribute.CATEGORY, CategoryManager.categoryFromTagName(evt.getTag().getName())); - for (GroupKey oldGroupKey : groupMap.keySet()) { - if (oldGroupKey.equals(newGroupKey) == false) { - removeFromGroup(oldGroupKey, fileID); - } - } - } else if (groupBy == DrawableAttribute.TAGS && CategoryManager.isNotCategoryTagName(evt.getTag().getName())) { - newGroupKey = new GroupKey(DrawableAttribute.TAGS, evt.getTag().getName()); - } - if (newGroupKey != null) { - DrawableGroup g = getGroupForKey(newGroupKey); - addFileToGroup(g, newGroupKey, fileID); - } - } - - @SuppressWarnings("AssignmentToMethodParameter") - private void addFileToGroup(DrawableGroup g, final GroupKey groupKey, final long fileID) { - if (g == null) { - //if there wasn't already a group check if there should be one now - g = popuplateIfAnalyzed(groupKey, null); - } - DrawableGroup group = g; - if (group != null) { - //if there is aleady a group that was previously deemed fully analyzed, then add this newly analyzed file to it. - Platform.runLater(() -> { - group.addFile(fileID); - }); - - } - } - @Subscribe public void handleTagDeleted(ContentTagDeletedEvent evt) { GroupKey groupKey = null; @@ -633,8 +599,6 @@ public class GroupManager { DrawableGroup g = removeFromGroup(groupKey, fileID); } } - } - } @Subscribe synchronized public void handleFileRemoved(Collection removedFileIDs) { @@ -678,49 +642,6 @@ public class GroupManager { //we fire this event for all files so that the category counts get updated during initial db population controller.getCategoryManager().fireChange(updatedFileIDs, null); } - private DrawableGroup popuplateIfAnalyzed(GroupKey groupKey, ReGroupTask task) { - - if (Objects.nonNull(task) && (task.isCancelled())) { - /* if this method call is part of a ReGroupTask and that task is - * cancelled, no-op - * - * this allows us to stop if a regroup task has been cancelled (e.g. - * the user picked a different group by attribute, while the - * current task was still running) */ - - } else { // no task or un-cancelled task - if ((groupKey.getAttribute() != DrawableAttribute.PATH) || db.isGroupAnalyzed(groupKey)) { - /* for attributes other than path we can't be sure a group is - * fully analyzed because we don't know all the files that - * will be a part of that group,. just show them no matter what. */ - - try { - Set fileIDs = getFileIDsInGroup(groupKey); - if (Objects.nonNull(fileIDs)) { - DrawableGroup group; - final boolean groupSeen = db.isGroupSeen(groupKey); - synchronized (groupMap) { - if (groupMap.containsKey(groupKey)) { - group = groupMap.get(groupKey); - group.setFiles(ObjectUtils.defaultIfNull(fileIDs, Collections.emptySet())); - } else { - group = new DrawableGroup(groupKey, fileIDs, groupSeen); - group.seenProperty().addListener((o, oldSeen, newSeen) -> { - markGroupSeen(group, newSeen); - }); - groupMap.put(groupKey, group); - } - Platform.runLater(() -> { - if (analyzedGroups.contains(group) == false) { - analyzedGroups.add(group); - } - markGroupSeen(group, groupSeen); - }); - return group; - } - } catch (TskCoreException ex) { - LOGGER.log(Level.SEVERE, "failed to get files for group: " + groupKey.getAttribute().attrName.toString() + " = " + groupKey.getValue(), ex); - } private DrawableGroup popuplateIfAnalyzed(GroupKey groupKey, ReGroupTask task) { diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/DrawableView.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/DrawableView.java index 37737675e5..4d7f31a52a 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/DrawableView.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/DrawableView.java @@ -1,7 +1,7 @@ package org.sleuthkit.autopsy.imagegallery.gui.drawableviews; import com.google.common.eventbus.Subscribe; -import java.util.Optional; +import java.util.Collection; import java.util.Optional; import java.util.logging.Level; import javafx.application.Platform; diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/MetaDataPane.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/MetaDataPane.java index 095ec88495..3e8a228c64 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/MetaDataPane.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/MetaDataPane.java @@ -18,13 +18,14 @@ */ package org.sleuthkit.autopsy.imagegallery.gui.drawableviews; + import com.google.common.eventbus.Subscribe; import java.io.IOException; import java.util.Arrays; import java.util.Collection; import java.util.Objects; import java.util.Optional; -import java.util.Optional; +import java.util.logging.Logger; import java.util.stream.Collectors; import javafx.application.Platform; import javafx.beans.property.SimpleObjectProperty; @@ -40,18 +41,16 @@ import javafx.scene.image.Image; import javafx.scene.image.ImageView; import javafx.scene.layout.BorderPane; import javafx.scene.layout.Region; -import static javafx.scene.layout.Region.USE_COMPUTED_SIZE; import javafx.scene.text.Text; import javafx.util.Pair; import org.apache.commons.lang3.StringUtils; -import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.events.ContentTagAddedEvent; import org.sleuthkit.autopsy.events.ContentTagDeletedEvent; import org.sleuthkit.autopsy.events.TagEvent; import org.sleuthkit.autopsy.imagegallery.ImageGalleryController; import org.sleuthkit.autopsy.imagegallery.datamodel.Category; -import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableAttribute; import org.sleuthkit.autopsy.imagegallery.datamodel.CategoryManager; +import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableAttribute; import org.sleuthkit.datamodel.ContentTag; import org.sleuthkit.datamodel.TagName; @@ -87,7 +86,7 @@ public class MetaDataPane extends DrawableUIBase { fxmlLoader.load(); } catch (IOException exception) { throw new RuntimeException(exception); - } + } } @@ -151,9 +150,9 @@ public class MetaDataPane extends DrawableUIBase { }); } +@Override protected synchronized void setFileHelper(Long newFileID) { setFileIDOpt(Optional.ofNullable(newFileID)); - if (newFileID == null) { if (newFileID == null) { Platform.runLater(() -> { imageView.setImage(null); @@ -221,22 +220,7 @@ public class MetaDataPane extends DrawableUIBase { }); } - @Subscribe - @Override - public void handleTagDeleted(ContentTagDeletedEvent evt) { - handleTagEvent(evt, this::updateUI); - } + - /** - * - * @param tagFileID the value of tagEvent - * @param runnable the value of runnable - */ - void handleTagEvent(TagEvent tagEvent, final Runnable runnable) { - getFileID().ifPresent(fileID -> { - if (Objects.equals(tagEvent.getTag().getContent().getId(), fileID)) { - runnable.run(); - } - }); - } + } From 72ba0cad26d209fd379e9eca2d42c99fb8a09bb0 Mon Sep 17 00:00:00 2001 From: Richard Cordovano Date: Fri, 26 Jun 2015 12:03:10 -0400 Subject: [PATCH 55/56] Add timestamps to notifications --- .../autopsy/coreutils/MessageNotifyUtil.java | 44 ++++++++++++------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/coreutils/MessageNotifyUtil.java b/Core/src/org/sleuthkit/autopsy/coreutils/MessageNotifyUtil.java index 558167c2bb..498115f310 100644 --- a/Core/src/org/sleuthkit/autopsy/coreutils/MessageNotifyUtil.java +++ b/Core/src/org/sleuthkit/autopsy/coreutils/MessageNotifyUtil.java @@ -1,7 +1,7 @@ /* * Autopsy Forensic Browser * - * Copyright 2013 Basis Technology Corp. + * Copyright 2013-2015 Basis Technology Corp. * Contact: carrier sleuthkit org * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,8 +20,10 @@ package org.sleuthkit.autopsy.coreutils; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Collections; +import java.util.Date; import java.util.List; import java.util.logging.Level; import javax.swing.Icon; @@ -52,8 +54,8 @@ public class MessageNotifyUtil { INFO(NotifyDescriptor.INFORMATION_MESSAGE, "info-icon-16.png"), //NON-NLS ERROR(NotifyDescriptor.ERROR_MESSAGE, "error-icon-16.png"), //NON-NLS WARNING(NotifyDescriptor.WARNING_MESSAGE, "warning-icon-16.png"); //NON-NLS - private int notifyDescriptorType; - private Icon icon; + private final int notifyDescriptorType; + private final Icon icon; private MessageType(int notifyDescriptorType, String resourceName) { this.notifyDescriptorType = notifyDescriptorType; @@ -138,24 +140,25 @@ public class MessageNotifyUtil { } /** - * Utility to display notifications with baloons + * Utility to display notifications with balloons */ public static class Notify { + private static final SimpleDateFormat TIME_STAMP_FORMAT = new SimpleDateFormat("MM/dd/yy HH:mm:ss z"); + //notifications to keep track of and to reset when case is closed private static final List notifications = Collections.synchronizedList(new ArrayList()); private Notify() { } - + /** - * Clear pending notifications - * Should really only be used by Case + * Clear pending notifications Should really only be used by Case */ public static void clear() { - for (Notification n : notifications) { + notifications.stream().forEach((n) -> { n.clear(); - } + }); notifications.clear(); } @@ -163,8 +166,8 @@ public class MessageNotifyUtil { * Show message with the specified type and action listener */ public static void show(String title, String message, MessageType type, ActionListener actionListener) { - Notification newNotification = - NotificationDisplayer.getDefault().notify(title, type.getIcon(), message, actionListener); + Notification newNotification + = NotificationDisplayer.getDefault().notify(addTimeStampToTitle(title), type.getIcon(), message, actionListener); notifications.add(newNotification); } @@ -178,11 +181,8 @@ public class MessageNotifyUtil { * @param type type of the message */ public static void show(String title, final String message, final MessageType type) { - ActionListener actionListener = new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - MessageNotifyUtil.Message.show(message, type); - } + ActionListener actionListener = (ActionEvent e) -> { + MessageNotifyUtil.Message.show(message, type); }; show(title, message, type, actionListener); @@ -217,5 +217,17 @@ public class MessageNotifyUtil { public static void warn(String title, String message) { show(title, message, MessageType.WARNING); } + + /** + * Adds a time stamp prefix to the title of notifications so that they + * will be in order (they are sorted alphabetically) in the + * notifications area. + * + * @param title A notification title without a time stamp prefix. + * @return The notification title with a time stamp prefix. + */ + private static String addTimeStampToTitle(String title) { + return TIME_STAMP_FORMAT.format(new Date()) + " " + title; + } } } From 9b182d18fabd4350e4d1475156bac470dd05cae3 Mon Sep 17 00:00:00 2001 From: Brian Carrier Date: Fri, 26 Jun 2015 20:50:10 -0400 Subject: [PATCH 56/56] added to python docs --- docs/doxygen/modDevPython.dox | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/docs/doxygen/modDevPython.dox b/docs/doxygen/modDevPython.dox index 7ec3d3112c..19d522e570 100755 --- a/docs/doxygen/modDevPython.dox +++ b/docs/doxygen/modDevPython.dox @@ -7,9 +7,9 @@ go into the page for that module type. --> This page describes the basic concepts and setup that are needed for all types of Python modules. It is not needed for Java module development. Autopsy uses Jython (http://www.jython.org) to enable Python scripting. Jython looks like Python and gets converted into Java byte code and run on the JVM. Its biggest limitations are: -- Limited to Python 2.5 +- Limited to Python 2.7 (as of Autopsy 3.1.3) - Can't use Python libraries that have native code -- You can't make any UIs. This means that you can't make content viewer modules or have configuration settings for your ingest modules. +- You can't easily make UIs. This means that you can't make content viewer modules or easily have configuration settings for your ingest modules. We have done it, but it is tedious compared to using a Java tool to place UI widgets in various places. Using it is very easy though in Autopsy and it allows you to access all of the Java services and classes that you need. @@ -29,10 +29,11 @@ Autopsy requires that you have a self-contained folder for each Python module. You will need to copy this folder into Autopsy's Python script folder. It will scan this folder each time it looks for modules. You can find the location of this folder from the "Tools -> Python Scripts" menu item. + \subsection mod_dev_py_create_create Module Creation -# Create a folder --# Add a .py file to it (see later sections for details on its contents) +-# Copy one of the sample modules from the github repository (listed below) or make one from scratch -# Copy the folder to the previously mentioned folder to make updates during development. That's it. Autopsy will find the module each time it needs it and you can make updates without having to restart Autopsy each time. @@ -52,6 +53,11 @@ from neededLib.mylib import neededClass Jython will look in the module's folder to resolve these libraries. +\subsection mod_dev_py_misc Minor Gotchas +This section lists some helpful tips that we have found. These are all now in the sample modules, so refer to those for examples and a place to copy and paste from. +- We haven't found a good way to debug while running inside of Autopsy. So, logging becomes critical. You need to go through a bunch of steps to get the logger to display your module name. See the sample module for a log() method that does all of this for you. +- When you name the file with your Python module in it, restrict its name to letters, numbers, and underscore (_). + \section mod_dev_py_distribute Distribution To distribute and share your Python module, ZIP up the folder and send it around. Other users of the module should expand the ZIP file and drop the folder into their Autopsy Python folder. @@ -63,5 +69,7 @@ There are only two types of modules that you can make with Python. Those (along - Ingest Modules (both file-level and data source-level): https://github.com/sleuthkit/autopsy/blob/develop/pythonExamples/ - Report Modules: https://github.com/sleuthkit/autopsy/blob/develop/pythonExamples/reportmodule.py + + */