19 package org.sleuthkit.autopsy.datamodel;
21 import java.beans.PropertyChangeEvent;
22 import java.beans.PropertyChangeListener;
23 import java.util.ArrayList;
24 import java.util.EnumSet;
25 import java.util.List;
26 import java.util.Optional;
27 import java.util.function.Function;
28 import java.util.logging.Level;
29 import java.util.stream.Collectors;
30 import javax.swing.Action;
31 import org.openide.nodes.ChildFactory;
33 import org.openide.nodes.Children;
34 import org.openide.nodes.Node;
35 import org.openide.nodes.Sheet;
36 import org.openide.util.NbBundle;
37 import org.openide.util.NbBundle.Messages;
38 import org.openide.util.WeakListeners;
39 import org.openide.util.lookup.Lookups;
57 @NbBundle.Messages(value = {
"HostGroupingNode_unknownHostNode_title=Unknown Host"})
78 this.dataSourceToNode = dataSourceToNode;
86 private final PropertyChangeListener dataSourceAddedPcl =
new PropertyChangeListener() {
88 public void propertyChange(PropertyChangeEvent evt) {
89 String eventType = evt.getPropertyName();
97 private final PropertyChangeListener weakPcl = WeakListeners.propertyChange(dataSourceAddedPcl, null);
113 return this.dataSourceToNode.apply(key);
117 protected boolean createKeys(List<DataSourceGrouping> toPopulate) {
118 List<DataSource> dataSources = null;
122 String hostName = host == null || host.getName() == null ?
"<unknown>" : host.getName();
123 logger.log(Level.WARNING, String.format(
"Unable to get data sources for host: %s", hostName), ex);
126 if (dataSources != null) {
127 toPopulate.addAll(dataSources.stream()
128 .filter(ds -> ds != null)
129 .map(DataSourceGrouping::new)
130 .sorted((a, b) -> getNameOrEmpty(a).compareToIgnoreCase(getNameOrEmpty(b)))
131 .collect(Collectors.toList()));
145 return (dsGroup == null || dsGroup.getDataSource() == null || dsGroup.getDataSource().getName() == null)
147 : dsGroup.getDataSource().getName();
152 private static final String ICON_PATH =
"org/sleuthkit/autopsy/images/host.png";
159 private static final Function<DataSourceGrouping, Node> HOST_DATA_SOURCES = key -> {
160 if (key.getDataSource() instanceof SleuthkitVisitableItem) {
161 return ((SleuthkitVisitableItem) key.getDataSource()).accept(CREATE_TSK_NODE_VISITOR);
170 private static final Function<DataSourceGrouping, Node> HOST_GROUPING_CONVERTER = key -> {
171 if (key == null || key.getDataSource() == null) {
175 return new DataSourceGroupingNode(key.getDataSource());
181 private final PropertyChangeListener hostChangePcl =
new PropertyChangeListener() {
183 public void propertyChange(PropertyChangeEvent evt) {
184 String eventType = evt.getPropertyName();
186 ((HostsUpdatedEvent) evt).getHosts().stream()
187 .filter(h -> h != null && h.getHostId() == hostId)
189 .ifPresent((newHost) -> {
190 setName(newHost.getName());
191 setDisplayName(newHost.getName());
197 private final PropertyChangeListener weakPcl = WeakListeners.propertyChange(hostChangePcl, null);
206 return (host == null || host.getName() == null)
207 ? Bundle.HostGroupingNode_unknownHostNode_title()
221 this(Children.create(
new HostGroupingChildren(HOST_DATA_SOURCES, hosts.getHost()),
true), hosts.getHost());
231 this(Children.create(
new HostGroupingChildren(HOST_GROUPING_CONVERTER, hostGrouping.getHost()),
true), hostGrouping.getHost());
241 this(children, host, getHostName(host));
251 private HostNode(Children children, Host host, String displayName) {
253 host == null ? Lookups.fixed(displayName) : Lookups.fixed(host, displayName));
255 hostId = host == null ? null : host.getHostId();
257 super.setName(displayName);
258 super.setDisplayName(displayName);
259 this.setIconBaseWithExtension(ICON_PATH);
270 return getClass().getName();
275 return visitor.
visit(
this);
279 "HostNode_createSheet_nameProperty=Name",})
282 Sheet sheet = Sheet.createDefault();
283 Sheet.Set sheetSet = sheet.get(Sheet.PROPERTIES);
284 if (sheetSet == null) {
285 sheetSet = Sheet.createPropertiesSet();
289 sheetSet.put(
new NodeProperty<>(
"Name", Bundle.HostNode_createSheet_nameProperty(),
"", getDisplayName()));
295 @Messages({
"HostNode_actions_associateWithExisting=Associate with existing person...",
296 "HostNode_actions_associateWithNew=Associate with new person...",
298 "HostNode_actions_removeFromPerson=Remove from person ({0})"})
301 List<Action> actionsList =
new ArrayList<>();
304 if (this.host != null) {
307 Optional<Person> parent;
311 logger.log(Level.WARNING, String.format(
"Error fetching parent person of host: %s",
this.host.getName() == null ?
"<null>" : this.host.getName()), ex);
312 return new Action[0];
316 if (parent.isPresent()) {
325 return actionsList.toArray(
new Action[actionsList.size()]);
Node createNodeForKey(DataSourceGrouping key)
static String getHostName(Host host)
boolean createKeys(List< DataSourceGrouping > toPopulate)
Action[] getActions(boolean context)
HostNode(Children children, Host host)
HostNode(Children children, Host host, String displayName)
final Function< DataSourceGrouping, Node > dataSourceToNode
SleuthkitCase getSleuthkitCase()
T visit(DataSourceFilesNode in)
String getNameOrEmpty(DataSourceGrouping dsGroup)
synchronized static Logger getLogger(String name)
static Case getCurrentCaseThrows()
static void addEventTypeSubscriber(Set< Events > eventTypes, PropertyChangeListener subscriber)
static void removeEventTypeSubscriber(Set< Events > eventTypes, PropertyChangeListener subscriber)