Implement bookmarks are specialized tags. Add icons.

Artifact node - add optional icon in constructor rather than default.
This commit is contained in:
adam-m 2012-08-27 15:06:15 -04:00
parent 60f82ae28d
commit 168ddcc6b8
9 changed files with 91 additions and 22 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 774 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 773 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 559 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 600 B

View File

@ -103,7 +103,7 @@ abstract class AbstractContentChildren extends Keys<Object> {
} }
/** /**
* Creates appropriate Node for each sub-class of Content * Creates appropriate Node for each supported artifact category / grouping
*/ */
static class CreateAutopsyNodeVisitor extends AutopsyItemVisitor.Default<AbstractNode> { static class CreateAutopsyNodeVisitor extends AutopsyItemVisitor.Default<AbstractNode> {

View File

@ -44,6 +44,25 @@ public class BlackboardArtifactNode extends DisplayableItemNode {
Content associated; Content associated;
static final Logger logger = Logger.getLogger(BlackboardArtifactNode.class.getName()); static final Logger logger = Logger.getLogger(BlackboardArtifactNode.class.getName());
/**
* Construct blackboard artifact node from an artifact and using provided icon
* @param artifact artifact to encapsulate
* @param iconPath icon to use for the artifact
*/
public BlackboardArtifactNode(BlackboardArtifact artifact, String iconPath) {
super(Children.LEAF, getLookups(artifact));
this.artifact = artifact;
this.associated = getAssociatedContent(artifact);
this.setName(Long.toString(artifact.getArtifactID()));
this.setDisplayName(associated.getName());
this.setIconBaseWithExtension(iconPath);
}
/**
* Construct blackboard artifact node from an artifact and using default icon for artifact type
* @param artifact artifact to encapsulate
*/
public BlackboardArtifactNode(BlackboardArtifact artifact) { public BlackboardArtifactNode(BlackboardArtifact artifact) {
super(Children.LEAF, getLookups(artifact)); super(Children.LEAF, getLookups(artifact));
@ -209,6 +228,10 @@ public class BlackboardArtifactNode extends DisplayableItemNode {
return "programs.png"; return "programs.png";
case TSK_RECENT_OBJECT: case TSK_RECENT_OBJECT:
return "recent_docs.png"; return "recent_docs.png";
case TSK_TAG_FILE:
return "blue-tag-icon-16.png";
case TSK_TAG_ARTIFACT:
return "green-tag-icon-16.png";
} }
return "artifact-icon.png"; return "artifact-icon.png";
} }

View File

@ -23,26 +23,35 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.openide.nodes.AbstractNode;
import org.openide.nodes.ChildFactory; import org.openide.nodes.ChildFactory;
import org.openide.nodes.Children; import org.openide.nodes.Children;
import org.openide.nodes.Node; import org.openide.nodes.Node;
import org.openide.nodes.Sheet; import org.openide.nodes.Sheet;
import org.openide.util.lookup.Lookups; import org.openide.util.lookup.Lookups;
import org.sleuthkit.datamodel.BlackboardArtifact; import org.sleuthkit.datamodel.BlackboardArtifact;
import org.sleuthkit.datamodel.BlackboardAttribute;
import org.sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE;
import org.sleuthkit.datamodel.SleuthkitCase; import org.sleuthkit.datamodel.SleuthkitCase;
import org.sleuthkit.datamodel.TskCoreException; import org.sleuthkit.datamodel.TskCoreException;
import org.sleuthkit.datamodel.TskException;
/** /**
* Support for bookmark (file and result/artifact) nodes and displaying * Support for bookmark (file and result/artifact) nodes and displaying
* bookmarks in the directory tree Bookmarks are divided into file and result * bookmarks in the directory tree Bookmarks are divided into file and result
* children bookmarks. * children bookmarks.
*
* Bookmarks are specialized tags - TSK_TAG_NAME starts with Bookmark
*
* TODO bookmark hierarchy support (TSK_TAG_NAME with slashes)
*/ */
public class Bookmarks implements AutopsyVisitableItem { public class Bookmarks implements AutopsyVisitableItem {
private static final String LABEL_NAME = "Bookmarks"; private static final String LABEL_NAME = "Bookmarks";
private static final String DISPLAY_NAME = LABEL_NAME; private static final String DISPLAY_NAME = LABEL_NAME;
private static final String FILE_BOOKMARKS_LABEL_NAME = "File Bookmarks";
private static final String RESULT_BOOKMARKS_LABEL_NAME = "Result Bookmarks";
private static final String BOOKMARK_ICON_PATH = "org/sleuthkit/autopsy/images/star-bookmark-icon-16.png";
private static final Logger logger = Logger.getLogger(Bookmarks.class.getName()); private static final Logger logger = Logger.getLogger(Bookmarks.class.getName());
private SleuthkitCase skCase; private SleuthkitCase skCase;
private final Map<BlackboardArtifact.ARTIFACT_TYPE, List<BlackboardArtifact>> data = private final Map<BlackboardArtifact.ARTIFACT_TYPE, List<BlackboardArtifact>> data =
@ -67,13 +76,13 @@ public class Bookmarks implements AutopsyVisitableItem {
super(Children.create(new BookmarksRootChildren(), true), Lookups.singleton(DISPLAY_NAME)); super(Children.create(new BookmarksRootChildren(), true), Lookups.singleton(DISPLAY_NAME));
super.setName(LABEL_NAME); super.setName(LABEL_NAME);
super.setDisplayName(DISPLAY_NAME); super.setDisplayName(DISPLAY_NAME);
this.setIconBaseWithExtension("org/sleuthkit/autopsy/images/mail-icon-16.png"); this.setIconBaseWithExtension(BOOKMARK_ICON_PATH);
initData(); initData();
} }
private void initData() { private void initData() {
data.put(BlackboardArtifact.ARTIFACT_TYPE.TSK_BOOKMARK_FILE, null); data.put(BlackboardArtifact.ARTIFACT_TYPE.TSK_TAG_FILE, null);
data.put(BlackboardArtifact.ARTIFACT_TYPE.TSK_BOOKMARK_ARTIFACT, null); data.put(BlackboardArtifact.ARTIFACT_TYPE.TSK_TAG_ARTIFACT, null);
try { try {
for (BlackboardArtifact.ARTIFACT_TYPE artType : data.keySet()) { for (BlackboardArtifact.ARTIFACT_TYPE artType : data.keySet()) {
@ -141,10 +150,19 @@ public class Bookmarks implements AutopsyVisitableItem {
public BookmarksNodeRoot(BlackboardArtifact.ARTIFACT_TYPE bookType, List<BlackboardArtifact> bookmarks) { public BookmarksNodeRoot(BlackboardArtifact.ARTIFACT_TYPE bookType, List<BlackboardArtifact> bookmarks) {
super(Children.create(new BookmarksChildrenNode(bookmarks), true), Lookups.singleton(bookType.getDisplayName())); super(Children.create(new BookmarksChildrenNode(bookmarks), true), Lookups.singleton(bookType.getDisplayName()));
final String name = bookType.getDisplayName();
String name = null;
if (bookType.equals(BlackboardArtifact.ARTIFACT_TYPE.TSK_TAG_FILE)) {
name = FILE_BOOKMARKS_LABEL_NAME;
}
else if (bookType.equals(BlackboardArtifact.ARTIFACT_TYPE.TSK_TAG_ARTIFACT)) {
name = RESULT_BOOKMARKS_LABEL_NAME;
}
super.setName(name); super.setName(name);
super.setDisplayName(name + " (" + bookmarks.size() + ")"); super.setDisplayName(name + " (" + bookmarks.size() + ")");
this.setIconBaseWithExtension("org/sleuthkit/autopsy/images/account-icon-16.png");
this.setIconBaseWithExtension(BOOKMARK_ICON_PATH);
} }
@Override @Override
@ -200,7 +218,31 @@ public class Bookmarks implements AutopsyVisitableItem {
@Override @Override
protected Node createNodeForKey(BlackboardArtifact artifact) { protected Node createNodeForKey(BlackboardArtifact artifact) {
return new BlackboardArtifactNode(artifact); return new BlackboardArtifactNode(artifact, BOOKMARK_ICON_PATH);
} }
} }
/**
* Links existing blackboard artifact (a tag) to this artifact.
* Linkage is made using TSK_TAGGED_ARTIFACT attribute.
*/
void addArtifactTag(BlackboardArtifact art, BlackboardArtifact tag) throws TskCoreException {
if (art.equals(tag)) {
throw new TskCoreException("Cannot tag the same artifact: id" + art.getArtifactID() );
}
BlackboardAttribute attrLink = new BlackboardAttribute(ATTRIBUTE_TYPE.TSK_TAGGED_ARTIFACT.getTypeID(),
"", art.getArtifactID());
tag.addAttribute(attrLink);
}
/**
* Get tag artifacts linked to the artifact
* @param art artifact to get tags for
* @return list of children artifacts or an empty list
* @throws TskCoreException exception thrown if a critical error occurs
* within tsk core and child artifact could not be queried
*/
List<BlackboardArtifact> getTagArtifacts(BlackboardArtifact art) throws TskCoreException {
return skCase.getBlackboardArtifacts(ATTRIBUTE_TYPE.TSK_TAGGED_ARTIFACT, art.getArtifactID());
}
} }

View File

@ -68,13 +68,13 @@ public class RootContentChildren extends AbstractContentChildren {
break; break;
//TODO check //TODO check
case TSK_BOOKMARK_FILE: case TSK_TAG_FILE:
if (o instanceof Bookmarks) if (o instanceof Bookmarks)
this.refreshKey(o); this.refreshKey(o);
break; break;
//TODO check //TODO check
case TSK_BOOKMARK_ARTIFACT: case TSK_TAG_ARTIFACT:
if (o instanceof Bookmarks) if (o instanceof Bookmarks)
this.refreshKey(o); this.refreshKey(o);
break; break;

View File

@ -37,11 +37,13 @@ import org.sleuthkit.datamodel.TskCoreException;
/** /**
* Action on a file that bookmarks a file and reloads the bookmark view. * Action on a file that bookmarks a file and reloads the bookmark view.
* Supports bookmarking of a fs file, directory and layout file and layout * Supports bookmarking of a fs file, directory and layout file and layout
* directory (virtual files/dirs for unalloc content) * directory (virtual files/dirs for unalloc content) TODO add use enters
* description and hierarchy (TSK_TAG_NAME with slashes)
*/ */
public class FileBookmarkAction extends AbstractAction { public class FileBookmarkAction extends AbstractAction {
private static final Logger logger = Logger.getLogger(FileBookmarkAction.class.getName()); private static final Logger logger = Logger.getLogger(FileBookmarkAction.class.getName());
private static final String BOOKMARKS_ROOT_NAME = "Bookmarks";
//content to bookmark (AbstractFile) //content to bookmark (AbstractFile)
private AbstractFile bookmarkFile; private AbstractFile bookmarkFile;
private final InitializeBookmarkFileV initializer = new InitializeBookmarkFileV(); private final InitializeBookmarkFileV initializer = new InitializeBookmarkFileV();
@ -52,7 +54,6 @@ public class FileBookmarkAction extends AbstractAction {
bookmarkFile = content.accept(initializer); bookmarkFile = content.accept(initializer);
this.setEnabled(bookmarkFile != null); this.setEnabled(bookmarkFile != null);
} }
/** /**
@ -95,20 +96,23 @@ public class FileBookmarkAction extends AbstractAction {
private void refreshView() { private void refreshView() {
DirectoryTreeTopComponent viewer = DirectoryTreeTopComponent.findInstance(); DirectoryTreeTopComponent viewer = DirectoryTreeTopComponent.findInstance();
viewer.refreshTree(BlackboardArtifact.ARTIFACT_TYPE.TSK_BOOKMARK_FILE); viewer.refreshTree(BlackboardArtifact.ARTIFACT_TYPE.TSK_TAG_FILE);
viewer.refreshTree(BlackboardArtifact.ARTIFACT_TYPE.TSK_TAG_ARTIFACT);
} }
private boolean doBookmarkFile(AbstractFile file) { private boolean doBookmarkFile(AbstractFile file) {
try { try {
//TODO popup a dialog and allow user to enter category and description //TODO popup a dialog and allow user to enter description
//with the currently present categories and descrptions pre-populated (pull-downs) //and optional bookmark name (TSK_TAG_NAME) with slashes representating hierarchy
//should always start with "Bookmarks"
final BlackboardArtifact bookArt = file.newArtifact(BlackboardArtifact.ARTIFACT_TYPE.TSK_BOOKMARK_FILE); final BlackboardArtifact bookArt = file.newArtifact(BlackboardArtifact.ARTIFACT_TYPE.TSK_TAG_FILE);
List<BlackboardAttribute> attrs = new ArrayList<BlackboardAttribute>(); List<BlackboardAttribute> attrs = new ArrayList<BlackboardAttribute>();
BlackboardAttribute attr1 = new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_CATEGORY.getTypeID(),
"", "", "category1");
BlackboardAttribute attr1 = new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_TAG_NAME.getTypeID(),
"", BOOKMARKS_ROOT_NAME);
BlackboardAttribute attr2 = new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DESCRIPTION.getTypeID(), BlackboardAttribute attr2 = new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DESCRIPTION.getTypeID(),
"", "", "description2"); "", "No Description");
attrs.add(attr1); attrs.add(attr1);
attrs.add(attr2); attrs.add(attr2);
bookArt.addAttributes(attrs); bookArt.addAttributes(attrs);