This commit is contained in:
Greg DiCristofaro 2021-02-23 14:24:32 -05:00
parent 7d49ee323e
commit e4442cce82
7 changed files with 62 additions and 26 deletions

View File

@ -246,20 +246,23 @@ public class HostNode extends DisplayableItemNode {
Optional<Person> parent = Optional.empty();
// if there is a host, then provide actions
if (this.host != null) {
try {
parent = Case.getCurrentCaseThrows().getSleuthkitCase().getPersonManager().getPerson(this.host);
parent = Case.getCurrentCaseThrows().getSleuthkitCase().getHostManager().getPerson(this.host);
} catch (NoCurrentCaseException | TskCoreException ex) {
logger.log(Level.WARNING, String.format("Error fetching parent person of host: %s", this.host.getName() == null ? "<null>" : this.host.getName()), ex);
return new Action[0];
}
// if there is a parent, only give option to remove parent person.
if (parent.isPresent()) {
return new Action[]{
new RemoveParentPersonAction(this.host, parent.get()),
null
};
} else {
// otherwise provide options to associate with new person or existing persons
List<Person> existingPersons = Collections.emptyList();
try {
existingPersons = Case.getCurrentCaseThrows().getSleuthkitCase().getPersonManager().getPersons();

View File

@ -28,7 +28,6 @@ import org.openide.util.NbBundle.Messages;
import org.openide.windows.WindowManager;
import org.sleuthkit.autopsy.casemodule.Case;
import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException;
import org.sleuthkit.datamodel.TskCoreException;
import org.sleuthkit.autopsy.coreutils.Logger;
import org.sleuthkit.autopsy.datamodel.persons.AddEditPersonDialog;
import org.sleuthkit.datamodel.Host;
@ -82,6 +81,13 @@ public class AssociateNewPersonAction extends AbstractAction {
}
/**
* Get dialog to add new person name.
*
* @return The name for the new person or null to cancel.
* @throws NoCurrentCaseException
* @throws TskCoreException
*/
private String getAddDialogName() throws NoCurrentCaseException, TskCoreException {
Frame parent = WindowManager.getDefault().getMainWindow();

View File

@ -26,7 +26,6 @@ import org.openide.util.NbBundle.Messages;
import org.openide.windows.WindowManager;
import org.sleuthkit.autopsy.casemodule.Case;
import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException;
import org.sleuthkit.datamodel.TskCoreException;
import org.sleuthkit.autopsy.coreutils.Logger;
import org.sleuthkit.datamodel.Host;
import org.sleuthkit.datamodel.Person;
@ -51,13 +50,13 @@ public class AssociatePersonAction extends AbstractAction {
/**
* Main constructor.
*
* @param host The host that will become parentless.
* @param person The person to be removed as a parent from the host.
* @param host The host that will get associated with the person.
* @param person The person to be the parent of the host.
*/
public AssociatePersonAction(Host host, Person person) {
super(person == null || person.getName() == null ?
Bundle.RemoveParentPersonAction_unknownPerson() :
person.getName());
super(person == null || person.getName() == null
? Bundle.RemoveParentPersonAction_unknownPerson()
: person.getName());
this.host = host;
this.person = person;

View File

@ -30,16 +30,22 @@ import org.sleuthkit.datamodel.Person;
/**
*
* JMenu item to show menu to associate given host with an existing person.
* JMenu item to show a menu giving options to associate the given host with an
* existing person.
*/
@Messages({
"AssociatePersonsMenuAction_menuTitle=Associate with Existing Person",
})
"AssociatePersonsMenuAction_menuTitle=Associate with Existing Person",})
public class AssociatePersonsMenuAction extends AbstractAction implements Presenter.Popup {
private final List<Person> persons;
private final Host host;
/**
* Main constructor.
*
* @param persons The persons that this host can be associated with.
* @param host The host.
*/
public AssociatePersonsMenuAction(List<Person> persons, Host host) {
super("");
this.persons = persons;
@ -64,5 +70,4 @@ public class AssociatePersonsMenuAction extends AbstractAction implements Presen
return menu;
}
}

View File

@ -58,6 +58,9 @@ public class DeletePersonAction extends AbstractAction {
setEnabled();
}
/**
* Sets the action enabled only if no child hosts.
*/
private void setEnabled() {
if (person == null) {
this.setEnabled(false);

View File

@ -76,6 +76,13 @@ public class EditPersonAction extends AbstractAction {
}
}
/**
* Presents a dialog that will allow the user to edit the person's name.
* @param person The person.
* @return The edited person's name or null if cancelled..
* @throws NoCurrentCaseException
* @throws TskCoreException
*/
private String getEditedPersonName(Person person) throws NoCurrentCaseException, TskCoreException {
Frame parent = WindowManager.getDefault().getMainWindow();

View File

@ -25,6 +25,7 @@ import java.util.logging.Level;
import javax.swing.Action;
import org.openide.nodes.FilterNode;
import org.openide.nodes.Node;
import org.openide.util.Lookup;
import org.openide.util.NbBundle;
import org.openide.util.lookup.Lookups;
import org.openide.util.lookup.ProxyLookup;
@ -36,6 +37,8 @@ import org.sleuthkit.datamodel.AbstractFile;
import org.sleuthkit.datamodel.BlackboardArtifact;
import org.sleuthkit.datamodel.BlackboardArtifact.ARTIFACT_TYPE;
import org.sleuthkit.datamodel.Content;
import org.sleuthkit.datamodel.Host;
import org.sleuthkit.datamodel.Person;
import org.sleuthkit.datamodel.TskCoreException;
import org.sleuthkit.datamodel.TskData;
@ -141,8 +144,7 @@ class DirectoryTreeFilterNode extends FilterNode {
&& (bba.getArtifactTypeID() != ARTIFACT_TYPE.TSK_MESSAGE.getTypeID())) {
numVisibleChildren--;
}
}
else {
} else {
numVisibleChildren--;
}
}
@ -163,15 +165,26 @@ class DirectoryTreeFilterNode extends FilterNode {
@Override
public Action[] getActions(boolean context) {
List<Action> actions = new ArrayList<>();
//final Content content = this.getLookup().lookup(Content.class);
//if (content != null) {
actions.addAll(Arrays.asList(super.getActions(true)));
//}
actions.addAll(Arrays.asList(getNodeActions()));
actions.add(collapseAllAction);
return actions.toArray(new Action[actions.size()]);
}
/**
* @return If lookup node is content, host, or person, returns super
* actions. Otherwise, returns empty array.
*/
private Action[] getNodeActions() {
Lookup lookup = this.getLookup();
if (lookup.lookup(Content.class) != null
|| lookup.lookup(Host.class) != null
|| lookup.lookup(Person.class) != null) {
return super.getActions(true);
} else {
return new Action[0];
}
}
/**
* Get the wrapped node.
*