19 package org.sleuthkit.autopsy.discovery.ui;
21 import com.google.common.eventbus.Subscribe;
22 import java.awt.Component;
23 import java.util.logging.Level;
24 import javax.swing.JPanel;
25 import javax.swing.SwingUtilities;
26 import javax.swing.event.ChangeEvent;
27 import javax.swing.event.ChangeListener;
28 import org.apache.commons.lang.StringUtils;
29 import org.openide.util.NbBundle;
45 final class DomainDetailsPanel
extends JPanel {
47 private static final long serialVersionUID = 1L;
48 private static final Logger logger = Logger.getLogger(DomainDetailsPanel.class.getName());
49 private ArtifactsWorker singleArtifactDomainWorker;
50 private String domain;
51 private String selectedTabName = null;
58 @NbBundle.Messages({
"DomainDetailsPanel.otherOccurrencesTab.title=Other Occurrences"})
59 @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
60 DomainDetailsPanel() {
62 MiniTimelinePanel timelinePanel =
new MiniTimelinePanel();
63 DiscoveryEventUtils.getDiscoveryEventBus().register(timelinePanel);
64 jTabbedPane1.add(Bundle.DomainDetailsPanel_miniTimelineTitle_text(), timelinePanel);
65 for (BlackboardArtifact.ARTIFACT_TYPE type : SearchData.Type.DOMAIN.getArtifactTypes()) {
66 jTabbedPane1.add(type.getDisplayName(),
new DomainArtifactsTabPanel(type));
68 if (CentralRepository.isEnabled()) {
69 jTabbedPane1.add(Bundle.DomainDetailsPanel_otherOccurrencesTab_title(),
new OtherOccurrencesPanel());
79 @NbBundle.Messages({
"DomainDetailsPanel.miniTimelineTitle.text=Timeline"})
80 @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
81 void configureArtifactTabs(String tabName) {
82 selectedTabName = tabName;
83 if (StringUtils.isBlank(selectedTabName)) {
84 selectedTabName = Bundle.DomainDetailsPanel_miniTimelineTitle_text();
87 jTabbedPane1.addChangeListener(
new ChangeListener() {
89 public void stateChanged(ChangeEvent e) {
90 if (jTabbedPane1.getSelectedIndex() >= 0) {
91 String newTabTitle = jTabbedPane1.getTitleAt(jTabbedPane1.getSelectedIndex());
92 if (selectedTabName == null || !selectedTabName.equals(newTabTitle)) {
93 selectedTabName = newTabTitle;
94 Component selectedComponent = jTabbedPane1.getSelectedComponent();
95 if (!StringUtils.isBlank(domain) && selectedComponent instanceof DomainArtifactsTabPanel) {
96 runDomainWorker((DomainArtifactsTabPanel) selectedComponent,
true);
97 }
else if (!StringUtils.isBlank(domain) && selectedComponent instanceof MiniTimelinePanel) {
98 runMiniTimelineWorker((MiniTimelinePanel) selectedComponent,
true);
99 }
else if (selectedComponent instanceof OtherOccurrencesPanel) {
100 if (CentralRepository.isEnabled()) {
102 ((OtherOccurrencesPanel) selectedComponent).populateTableForOneType(CentralRepository.getInstance().getCorrelationTypeById(CorrelationAttributeInstance.DOMAIN_TYPE_ID), domain);
103 }
catch (CentralRepoException ex) {
104 logger.log(Level.INFO,
"Central repository exception while trying to get instances by type and value for domain: " + domain, ex);
105 ((OtherOccurrencesPanel) selectedComponent).reset();
108 ((OtherOccurrencesPanel) selectedComponent).reset();
117 @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
122 private
void selectTab() {
123 for (
int i = 0; i < jTabbedPane1.getTabCount(); i++) {
124 if (!StringUtils.isBlank(selectedTabName) && selectedTabName.equals(jTabbedPane1.getTitleAt(i))) {
125 jTabbedPane1.setSelectedIndex(i);
136 DomainArtifactsTabPanel.ArtifactRetrievalStatus getCurrentTabStatus() {
137 if (jTabbedPane1.getSelectedComponent() instanceof MiniTimelinePanel) {
138 return ((MiniTimelinePanel) jTabbedPane1.getSelectedComponent()).getStatus();
139 }
else if (jTabbedPane1.getSelectedComponent() instanceof DomainArtifactsTabPanel) {
140 return ((DomainArtifactsTabPanel) jTabbedPane1.getSelectedComponent()).getStatus();
154 @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
155 private
void runDomainWorker(DomainArtifactsTabPanel domainArtifactsTabPanel,
boolean shouldGrabFocus) {
156 if (singleArtifactDomainWorker != null && !singleArtifactDomainWorker.isDone()) {
157 singleArtifactDomainWorker.cancel(
true);
159 if (domainArtifactsTabPanel.getStatus() == DomainArtifactsTabPanel.ArtifactRetrievalStatus.UNPOPULATED) {
160 DiscoveryEventUtils.getDiscoveryEventBus().register(domainArtifactsTabPanel);
161 domainArtifactsTabPanel.setStatus(DomainArtifactsTabPanel.ArtifactRetrievalStatus.POPULATING);
162 singleArtifactDomainWorker =
new ArtifactsWorker(domainArtifactsTabPanel.getArtifactType(), domain, shouldGrabFocus);
163 singleArtifactDomainWorker.execute();
164 }
else if (domainArtifactsTabPanel.getStatus() == DomainArtifactsTabPanel.ArtifactRetrievalStatus.POPULATED) {
165 domainArtifactsTabPanel.focusList();
178 private void runMiniTimelineWorker(MiniTimelinePanel miniTimelinePanel,
boolean shouldGrabFocus) {
179 if (miniTimelinePanel.getStatus() == DomainArtifactsTabPanel.ArtifactRetrievalStatus.UNPOPULATED) {
180 miniTimelinePanel.setStatus(DomainArtifactsTabPanel.ArtifactRetrievalStatus.POPULATING, domain);
181 new MiniTimelineWorker(domain, shouldGrabFocus).execute();
182 }
else if (miniTimelinePanel.getStatus() == DomainArtifactsTabPanel.ArtifactRetrievalStatus.POPULATED) {
183 miniTimelinePanel.focusList();
194 void handlePopulateDomainTabsEvent(DiscoveryEventUtils.PopulateDomainTabsEvent populateEvent) {
195 SwingUtilities.invokeLater(() -> {
196 domain = populateEvent.getDomain();
197 if (StringUtils.isBlank(domain)) {
200 DiscoveryEventUtils.getDiscoveryEventBus().post(
new DiscoveryEventUtils.DetailsVisibleEvent(
false));
203 Component selectedComponent = jTabbedPane1.getSelectedComponent();
204 if (selectedComponent instanceof DomainArtifactsTabPanel) {
205 runDomainWorker((DomainArtifactsTabPanel) selectedComponent,
false);
206 }
else if (selectedComponent instanceof MiniTimelinePanel) {
207 runMiniTimelineWorker((MiniTimelinePanel) selectedComponent,
false);
208 }
else if (selectedComponent instanceof OtherOccurrencesPanel) {
209 if (CentralRepository.isEnabled()) {
211 ((OtherOccurrencesPanel) selectedComponent).populateTableForOneType(CentralRepository.getInstance().getCorrelationTypeById(CorrelationAttributeInstance.DOMAIN_TYPE_ID), domain);
212 }
catch (CentralRepoException ex) {
213 logger.log(Level.INFO,
"Central repository exception while trying to get instances by type and value for domain: " + domain, ex);
214 ((OtherOccurrencesPanel) selectedComponent).reset();
217 ((OtherOccurrencesPanel) selectedComponent).reset();
221 DiscoveryEventUtils.getDiscoveryEventBus().post(
new DiscoveryEventUtils.DetailsVisibleEvent(
true));
230 @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
231 private
void resetTabsStatus() {
232 for (Component comp : jTabbedPane1.getComponents()) {
233 if (comp instanceof DomainArtifactsTabPanel) {
234 ((DomainArtifactsTabPanel) comp).setStatus(DomainArtifactsTabPanel.ArtifactRetrievalStatus.UNPOPULATED);
235 }
else if (comp instanceof MiniTimelinePanel) {
236 ((MiniTimelinePanel) comp).setStatus(DomainArtifactsTabPanel.ArtifactRetrievalStatus.UNPOPULATED, domain);
237 }
else if (comp instanceof OtherOccurrencesPanel) {
238 ((OtherOccurrencesPanel) comp).reset();
248 @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
249 String getSelectedTabName() {
250 return selectedTabName;
258 @SuppressWarnings(
"unchecked")
260 private
void initComponents() {
262 jTabbedPane1 =
new javax.swing.JTabbedPane();
265 setMinimumSize(
new java.awt.Dimension(0, 0));
266 setPreferredSize(
new java.awt.Dimension(0, 0));
267 setLayout(
new java.awt.BorderLayout());
269 jTabbedPane1.setMinimumSize(
new java.awt.Dimension(0, 0));
270 jTabbedPane1.setPreferredSize(
new java.awt.Dimension(0, 0));
271 add(jTabbedPane1, java.awt.BorderLayout.CENTER);
275 private javax.swing.JTabbedPane jTabbedPane1;
282 for (Component comp : jTabbedPane1.getComponents()) {
283 if (comp instanceof MiniTimelinePanel) {
284 DiscoveryEventUtils.getDiscoveryEventBus().unregister(comp);