Autopsy  4.10.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
KeyValueNode.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011-2018 Basis Technology Corp.
5  * Contact: carrier <at> sleuthkit <dot> org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 package org.sleuthkit.autopsy.datamodel;
20 
21 import java.util.ArrayList;
22 import java.util.Arrays;
23 import java.util.List;
24 import java.util.Map;
25 import javax.swing.Action;
26 import org.openide.nodes.AbstractNode;
27 import org.openide.nodes.Children;
28 import org.openide.nodes.Sheet;
29 import org.openide.util.Lookup;
30 import org.openide.util.NbBundle;
31 import org.openide.util.NbBundle.Messages;
32 import org.openide.util.lookup.Lookups;
35 import org.sleuthkit.datamodel.AbstractFile;
36 
42 public class KeyValueNode extends AbstractNode {
43 
44  private KeyValue data;
45 
46  public KeyValueNode(KeyValue thing, Children children) {
47  super(children, Lookups.singleton(thing));
48  this.setName(thing.getName());
49  this.data = thing;
50 
51  setIcon();
52  }
53 
54  public KeyValueNode(KeyValue thing, Children children, Lookup lookup) {
55  super(children, lookup);
56  this.setName(thing.getName());
57  this.data = thing;
58 
59  setIcon();
60  }
61 
62  private void setIcon() {
63  //if file/dir, set icon
64  AbstractFile af = Lookup.getDefault().lookup(AbstractFile.class);
65  if (af != null) {
66  // set name, display name, and icon
67  if (af.isDir()) {
68  this.setIconBaseWithExtension("org/sleuthkit/autopsy/images/Folder-icon.png"); //NON-NLS
69  } else {
70  this.setIconBaseWithExtension(FileNode.getIconForFileType(af));
71  }
72 
73  }
74  }
75 
76  @Override
77  protected Sheet createSheet() {
78  Sheet sheet = super.createSheet();
79  Sheet.Set sheetSet = sheet.get(Sheet.PROPERTIES);
80  if (sheetSet == null) {
81  sheetSet = Sheet.createPropertiesSet();
82  sheet.put(sheetSet);
83  }
84 
85  // table view drops first column of properties under assumption
86  // that it contains the node's name
87  sheetSet.put(new NodeProperty<>(NbBundle.getMessage(this.getClass(), "KeyValueNode.createSheet.name.name"),
88  NbBundle.getMessage(this.getClass(), "KeyValueNode.createSheet.name.displayName"),
89  NbBundle.getMessage(this.getClass(), "KeyValueNode.createSheet.name.desc"),
90  data.getName()));
91 
92  for (Map.Entry<String, Object> entry : data.getMap().entrySet()) {
93  String key = entry.getKey();
94  Object value = entry.getValue();
95  sheetSet.put(new NodeProperty<>(key,
96  key,
97  NbBundle.getMessage(this.getClass(), "KeyValueNode.createSheet.map.desc"),
98  value));
99  }
100 
101  return sheet;
102  }
103 
112  @Messages({
113  "KeyValueNode.menuItemText.viewFileInDir=View Source File in Directory"
114  })
115  @Override
116  public Action[] getActions(boolean popup) {
117  List<Action> actionsList = new ArrayList<>();
118  actionsList.addAll(Arrays.asList(super.getActions(popup)));
119  // If this artifact has associated content, add the actions.
120  AbstractFile file = getLookup().lookup(AbstractFile.class);
121  if (null != file) {
123  actionsList.add(new ViewContextAction(Bundle.KeyValueNode_menuItemText_viewFileInDir(), file));
124  }
125  actionsList.add(null); // creates a menu separator
126 
127  return actionsList.toArray(new Action[actionsList.size()]);
128  }
129 }
Map< String, Object > getMap()
Definition: KeyValue.java:61
static ViewFileInTimelineAction createViewSourceFileAction(AbstractFile file)
KeyValueNode(KeyValue thing, Children children)
KeyValueNode(KeyValue thing, Children children, Lookup lookup)

Copyright © 2012-2018 Basis Technology. Generated on: Fri Mar 22 2019
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.