Merge pull request #3262 from wschaeferB/3248-ViewFileInDirectoryBug

3248 make navigate to file work when already in directory
This commit is contained in:
Richard Cordovano 2017-12-08 17:10:47 -05:00 committed by GitHub
commit 5ae161753e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 11 deletions

View File

@ -149,6 +149,7 @@ public final class DirectoryTreeTopComponent extends TopComponent implements Dat
} }
} }
}); });
Case.addEventTypeSubscriber(EnumSet.of(Case.Events.CURRENT_CASE, Case.Events.DATA_SOURCE_ADDED), this); Case.addEventTypeSubscriber(EnumSet.of(Case.Events.CURRENT_CASE, Case.Events.DATA_SOURCE_ADDED), this);
this.em.addPropertyChangeListener(this); this.em.addPropertyChangeListener(this);
IngestManager.getInstance().addIngestJobEventListener(this); IngestManager.getInstance().addIngestJobEventListener(this);
@ -642,7 +643,7 @@ public final class DirectoryTreeTopComponent extends TopComponent implements Dat
* @param newNodes * @param newNodes
*/ */
@NbBundle.Messages("DirectoryTreeTopComponent.emptyMimeNode.text=Data not available. Run file type identification module.") @NbBundle.Messages("DirectoryTreeTopComponent.emptyMimeNode.text=Data not available. Run file type identification module.")
private void respondSelection(final Node[] oldNodes, final Node[] newNodes) { void respondSelection(final Node[] oldNodes, final Node[] newNodes) {
if (!Case.isCaseOpen()) { if (!Case.isCaseOpen()) {
return; return;
} }

View File

@ -73,7 +73,7 @@ public class ViewContextAction extends AbstractAction {
public ViewContextAction(String displayName, BlackboardArtifactNode artifactNode) { public ViewContextAction(String displayName, BlackboardArtifactNode artifactNode) {
super(displayName); super(displayName);
this.content = artifactNode.getLookup().lookup(AbstractFile.class); this.content = artifactNode.getLookup().lookup(AbstractFile.class);
if(this.content != null) { if (this.content != null) {
AbstractFile file = (AbstractFile) content; AbstractFile file = (AbstractFile) content;
if ((TskData.FileKnown.KNOWN == file.getKnown() && UserPreferences.hideKnownFilesInDataSourcesTree()) if ((TskData.FileKnown.KNOWN == file.getKnown() && UserPreferences.hideKnownFilesInDataSourcesTree())
|| (TskData.TSK_DB_FILES_TYPE_ENUM.SLACK == file.getType() && UserPreferences.hideSlackFilesInDataSourcesTree())) { || (TskData.TSK_DB_FILES_TYPE_ENUM.SLACK == file.getType() && UserPreferences.hideSlackFilesInDataSourcesTree())) {
@ -122,8 +122,7 @@ public class ViewContextAction extends AbstractAction {
@Override @Override
@Messages({ @Messages({
"ViewContextAction.errorMessage.cannotFindDirectory=Failed to locate directory.", "ViewContextAction.errorMessage.cannotFindDirectory=Failed to locate directory.",
"ViewContextAction.errorMessage.cannotSelectDirectory=Failed to select directory in tree.", "ViewContextAction.errorMessage.cannotSelectDirectory=Failed to select directory in tree.",})
})
public void actionPerformed(ActionEvent event) { public void actionPerformed(ActionEvent event) {
EventQueue.invokeLater(() -> { EventQueue.invokeLater(() -> {
/* /*
@ -132,7 +131,6 @@ public class ViewContextAction extends AbstractAction {
DirectoryTreeTopComponent treeViewTopComponent = DirectoryTreeTopComponent.findInstance(); DirectoryTreeTopComponent treeViewTopComponent = DirectoryTreeTopComponent.findInstance();
ExplorerManager treeViewExplorerMgr = treeViewTopComponent.getExplorerManager(); ExplorerManager treeViewExplorerMgr = treeViewTopComponent.getExplorerManager();
Node parentTreeViewNode = treeViewExplorerMgr.getRootContext().getChildren().findChild(DataSourcesNode.NAME); Node parentTreeViewNode = treeViewExplorerMgr.getRootContext().getChildren().findChild(DataSourcesNode.NAME);
/* /*
* Get the parent content for the content to be selected in the * Get the parent content for the content to be selected in the
* results view. If the parent content is null, then the specified * results view. If the parent content is null, then the specified
@ -204,11 +202,21 @@ public class ViewContextAction extends AbstractAction {
undecoratedParentNode.setChildNodeSelectionInfo(new ContentNodeSelectionInfo(content)); undecoratedParentNode.setChildNodeSelectionInfo(new ContentNodeSelectionInfo(content));
TreeView treeView = treeViewTopComponent.getTree(); TreeView treeView = treeViewTopComponent.getTree();
treeView.expandNode(parentTreeViewNode); treeView.expandNode(parentTreeViewNode);
try { if (treeViewTopComponent.getSelectedNode().getDisplayName().equals(parentTreeViewNode.getDisplayName())) {
treeViewExplorerMgr.setExploredContextAndSelection(parentTreeViewNode, new Node[]{parentTreeViewNode}); //In the case where our tree view already has the destination directory selected
} catch (PropertyVetoException ex) { //due to an optimization in the ExplorerManager.setExploredContextAndSelection method
MessageNotifyUtil.Message.error(Bundle.ViewContextAction_errorMessage_cannotSelectDirectory()); //the property change we listen for to call DirectoryTreeTopComponent.respondSelection
logger.log(Level.SEVERE, "Failed to select the parent node in the tree view", ex); //NON-NLS //will not be sent so we call it manually ourselves after making
//the directory listing the active tab.
treeViewTopComponent.setDirectoryListingActive();
treeViewTopComponent.respondSelection(treeViewExplorerMgr.getSelectedNodes(), new Node[]{parentTreeViewNode});
} else {
try {
treeViewExplorerMgr.setExploredContextAndSelection(parentTreeViewNode, new Node[]{parentTreeViewNode});
} catch (PropertyVetoException ex) {
MessageNotifyUtil.Message.error(Bundle.ViewContextAction_errorMessage_cannotSelectDirectory());
logger.log(Level.SEVERE, "Failed to select the parent node in the tree view", ex); //NON-NLS
}
} }
}); });
} }