rename method in CategoryManager to be more descriptive; fix tag and category grouping when tags aer added / removed

This commit is contained in:
jmillman 2015-06-22 14:11:44 -04:00
parent d19dbbeaba
commit 4fdac3a8be
3 changed files with 38 additions and 31 deletions

View File

@ -211,7 +211,7 @@ public class CategoryManager {
} }
public static Category fromTagName(TagName tagName) { public static Category categoryFromTagName(TagName tagName) {
return Category.fromDisplayName(tagName.getDisplayName()); return Category.fromDisplayName(tagName.getDisplayName());
} }
@ -246,7 +246,7 @@ public class CategoryManager {
} catch (TskCoreException tskException) { } catch (TskCoreException tskException) {
LOGGER.log(Level.SEVERE, "Failed to get content tags for content. Unable to maintain category in a consistent state.", 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) { if (newCat != Category.ZERO) {
incrementCategoryCount(newCat); incrementCategoryCount(newCat);
} }
@ -259,7 +259,7 @@ public class CategoryManager {
ContentTag deleted = event.getDeletedTag(); ContentTag deleted = event.getDeletedTag();
if (isCategoryTagName(deleted.getName())) { if (isCategoryTagName(deleted.getName())) {
Category deletedCat = CategoryManager.fromTagName(deleted.getName()); Category deletedCat = CategoryManager.categoryFromTagName(deleted.getName());
if (deletedCat != Category.ZERO) { if (deletedCat != Category.ZERO) {
decrementCategoryCount(deletedCat); decrementCategoryCount(deletedCat);
} }

View File

@ -539,20 +539,25 @@ public class GroupManager implements FileUpdateEvent.FileUpdateListener {
@Subscribe @Subscribe
public void handleTagAdded(ContentTagAddedEvent evt) { public void handleTagAdded(ContentTagAddedEvent evt) {
if (groupBy == DrawableAttribute.TAGS || groupBy == DrawableAttribute.CATEGORY) { GroupKey<?> groupKey = null;
final GroupKey<TagName> groupKey = new GroupKey<>(DrawableAttribute.TAGS, evt.getAddedTag().getName()); if (groupBy == DrawableAttribute.TAGS) {
groupKey = new GroupKey<TagName>(DrawableAttribute.TAGS, evt.getAddedTag().getName());
} else if (groupBy == DrawableAttribute.CATEGORY) {
groupKey = new GroupKey<Category>(DrawableAttribute.CATEGORY, CategoryManager.categoryFromTagName(evt.getAddedTag().getName()));
}
final long fileID = evt.getAddedTag().getContent().getId(); final long fileID = evt.getAddedTag().getContent().getId();
DrawableGroup g = getGroupForKey(groupKey); DrawableGroup g = getGroupForKey(groupKey);
addFileToGroup(g, groupKey, fileID); addFileToGroup(g, groupKey, fileID);
}
} }
@SuppressWarnings("AssignmentToMethodParameter")
private void addFileToGroup(DrawableGroup g, final GroupKey<?> groupKey, final long fileID) { private void addFileToGroup(DrawableGroup g, final GroupKey<?> groupKey, final long fileID) {
if (g == null) { if (g == null) {
//if there wasn't already a group check if there should be one now //if there wasn't already a group check if there should be one now
popuplateIfAnalyzed(groupKey, null); g = popuplateIfAnalyzed(groupKey, null);
} else { }
if (g != null) {
//if there is aleady a group that was previously deemed fully analyzed, then add this newly analyzed file to it. //if there is aleady a group that was previously deemed fully analyzed, then add this newly analyzed file to it.
g.addFile(fileID); g.addFile(fileID);
} }
@ -560,12 +565,15 @@ public class GroupManager implements FileUpdateEvent.FileUpdateListener {
@Subscribe @Subscribe
public void handleTagDeleted(ContentTagDeletedEvent evt) { public void handleTagDeleted(ContentTagDeletedEvent evt) {
if (groupBy == DrawableAttribute.TAGS || groupBy == DrawableAttribute.CATEGORY) { GroupKey<?> groupKey = null;
final GroupKey<TagName> groupKey = new GroupKey<>(DrawableAttribute.TAGS, evt.getDeletedTag().getName()); if (groupBy == DrawableAttribute.TAGS) {
groupKey = new GroupKey<TagName>(DrawableAttribute.TAGS, evt.getDeletedTag().getName());
} else if (groupBy == DrawableAttribute.CATEGORY) {
groupKey = new GroupKey<Category>(DrawableAttribute.CATEGORY, CategoryManager.categoryFromTagName(evt.getDeletedTag().getName()));
}
final long fileID = evt.getDeletedTag().getContent().getId(); final long fileID = evt.getDeletedTag().getContent().getId();
DrawableGroup g = removeFromGroup(groupKey, fileID); DrawableGroup g = removeFromGroup(groupKey, fileID);
} }
}
@Override @Override
synchronized public void handleFileRemoved(FileUpdateEvent evt) { synchronized public void handleFileRemoved(FileUpdateEvent evt) {
@ -631,7 +639,7 @@ public class GroupManager implements FileUpdateEvent.FileUpdateListener {
if ((groupKey.getAttribute() != DrawableAttribute.PATH) || db.isGroupAnalyzed(groupKey)) { if ((groupKey.getAttribute() != DrawableAttribute.PATH) || db.isGroupAnalyzed(groupKey)) {
/* for attributes other than path we can't be sure a group is /* for attributes other than path we can't be sure a group is
* fully analyzed because we don't know all the files that * 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 { try {
Set<Long> fileIDs = getFileIDsInGroup(groupKey); Set<Long> fileIDs = getFileIDsInGroup(groupKey);
@ -643,9 +651,8 @@ public class GroupManager implements FileUpdateEvent.FileUpdateListener {
group = groupMap.get(groupKey); group = groupMap.get(groupKey);
group.setFiles(ObjectUtils.defaultIfNull(fileIDs, Collections.emptySet())); group.setFiles(ObjectUtils.defaultIfNull(fileIDs, Collections.emptySet()));
} else { } else {
group = new DrawableGroup(groupKey, fileIDs, groupSeen); group = new DrawableGroup(groupKey, fileIDs, groupSeen);
group.seenProperty().addListener((observable, oldSeen, newSeen) -> { group.seenProperty().addListener((o, oldSeen, newSeen) -> {
markGroupSeen(group, newSeen); markGroupSeen(group, newSeen);
}); });
groupMap.put(groupKey, group); groupMap.put(groupKey, group);

View File

@ -25,6 +25,7 @@ import javafx.application.Platform;
import javafx.beans.Observable; import javafx.beans.Observable;
import javafx.beans.value.ChangeListener; import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue; import javafx.beans.value.ObservableValue;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent; import javafx.event.ActionEvent;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.scene.control.Button; import javafx.scene.control.Button;
@ -282,24 +283,20 @@ public class SlideShowView extends DrawableTileBase {
@Override @Override
protected String getTextForLabel() { protected String getTextForLabel() {
return getFile().map(file -> file.getName() + " " + getSupplementalText()).orElse(""); return getFile().map(file -> file.getName()).orElse("") + " " + getSupplementalText();
} }
@ThreadConfined(type = ThreadType.JFX) @ThreadConfined(type = ThreadType.JFX)
private void cycleSlideShowImage(int d) { private void cycleSlideShowImage(int direction) {
stopVideo(); stopVideo();
if (getFileID().isPresent()) { final int groupSize = getGroupPane().getGrouping().fileIds().size();
int index = getGroupPane().getGrouping().fileIds().indexOf(getFileID()); final Integer nextIndex = getFileID().map(fileID -> {
final int size = getGroupPane().getGrouping().fileIds().size(); final int currentIndex = getGroupPane().getGrouping().fileIds().indexOf(fileID);
index = (index + d) % size; return (currentIndex + direction + groupSize) % groupSize;
if (index < 0) { }).orElse(0);
index += size; setFile(getGroupPane().getGrouping().fileIds().get(nextIndex)
} );
setFile(getGroupPane().getGrouping().fileIds().get(index));
} else {
setFile(getGroupPane().getGrouping().fileIds().get(0));
}
} }
/** /**
@ -307,7 +304,10 @@ public class SlideShowView extends DrawableTileBase {
* of y" * of y"
*/ */
private String getSupplementalText() { private String getSupplementalText() {
return " ( " + (getGroupPane().getGrouping().fileIds().indexOf(getFileID()) + 1) + " of " + getGroupPane().getGrouping().fileIds().size() + " in group )"; final ObservableList<Long> fileIds = getGroupPane().getGrouping().fileIds();
return getFileID().map(fileID -> " ( " + (fileIds.indexOf(fileID) + 1) + " of " + fileIds.size() + " in group )")
.orElse("");
} }
@Override @Override