Autopsy  4.18.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
DomainDetailsPanel.java
Go to the documentation of this file.
1 /*
2  * Autopsy
3  *
4  * Copyright 2020 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.discovery.ui;
20 
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;
38 import org.sleuthkit.datamodel.BlackboardArtifact;
40 
45 final class DomainDetailsPanel extends JPanel {
46 
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;
52 
58  @NbBundle.Messages({"DomainDetailsPanel.otherOccurrencesTab.title=Other Occurrences"})
59  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
60  DomainDetailsPanel() {
61  initComponents();
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));
67  }
68  if (CentralRepository.isEnabled()) {
69  jTabbedPane1.add(Bundle.DomainDetailsPanel_otherOccurrencesTab_title(), new OtherOccurrencesPanel());
70  }
71  }
72 
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();
85  }
86  selectTab();
87  jTabbedPane1.addChangeListener(new ChangeListener() {
88  @Override
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  }
100  }
101  }
102  }
103  });
104  }
105 
106  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
111  private void selectTab() {
112  for (int i = 0; i < jTabbedPane1.getTabCount(); i++) {
113  if (!StringUtils.isBlank(selectedTabName) && selectedTabName.equals(jTabbedPane1.getTitleAt(i))) {
114  jTabbedPane1.setSelectedIndex(i);
115  return;
116  }
117  }
118  }
119 
125  DomainArtifactsTabPanel.ArtifactRetrievalStatus getCurrentTabStatus() {
126  if (jTabbedPane1.getSelectedComponent() instanceof MiniTimelinePanel) {
127  return ((MiniTimelinePanel) jTabbedPane1.getSelectedComponent()).getStatus();
128  } else if (jTabbedPane1.getSelectedComponent() instanceof DomainArtifactsTabPanel) {
129  return ((DomainArtifactsTabPanel) jTabbedPane1.getSelectedComponent()).getStatus();
130  }
131  return null;
132  }
133 
143  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
144  private void runDomainWorker(DomainArtifactsTabPanel domainArtifactsTabPanel, boolean shouldGrabFocus) {
145  if (singleArtifactDomainWorker != null && !singleArtifactDomainWorker.isDone()) {
146  singleArtifactDomainWorker.cancel(true);
147  }
148  if (domainArtifactsTabPanel.getStatus() == DomainArtifactsTabPanel.ArtifactRetrievalStatus.UNPOPULATED) {
149  DiscoveryEventUtils.getDiscoveryEventBus().register(domainArtifactsTabPanel);
150  domainArtifactsTabPanel.setStatus(DomainArtifactsTabPanel.ArtifactRetrievalStatus.POPULATING);
151  singleArtifactDomainWorker = new ArtifactsWorker(domainArtifactsTabPanel.getArtifactType(), domain, shouldGrabFocus);
152  singleArtifactDomainWorker.execute();
153  } else if (domainArtifactsTabPanel.getStatus() == DomainArtifactsTabPanel.ArtifactRetrievalStatus.POPULATED) {
154  domainArtifactsTabPanel.focusList();
155  }
156 
157  }
158 
167  private void runMiniTimelineWorker(MiniTimelinePanel miniTimelinePanel, boolean shouldGrabFocus) {
168  if (miniTimelinePanel.getStatus() == DomainArtifactsTabPanel.ArtifactRetrievalStatus.UNPOPULATED) {
169  miniTimelinePanel.setStatus(DomainArtifactsTabPanel.ArtifactRetrievalStatus.POPULATING, domain);
170  new MiniTimelineWorker(domain, shouldGrabFocus).execute();
171  } else if (miniTimelinePanel.getStatus() == DomainArtifactsTabPanel.ArtifactRetrievalStatus.POPULATED) {
172  miniTimelinePanel.focusList();
173  }
174  }
175 
182  @Subscribe
183  void handlePopulateDomainTabsEvent(DiscoveryEventUtils.PopulateDomainTabsEvent populateEvent) {
184  SwingUtilities.invokeLater(() -> {
185  domain = populateEvent.getDomain();
186  if (StringUtils.isBlank(domain)) {
187  resetTabsStatus();
188  //send fade out event
189  DiscoveryEventUtils.getDiscoveryEventBus().post(new DiscoveryEventUtils.DetailsVisibleEvent(false));
190  } else {
191  resetTabsStatus();
192  Component selectedComponent = jTabbedPane1.getSelectedComponent();
193  if (selectedComponent instanceof DomainArtifactsTabPanel) {
194  runDomainWorker((DomainArtifactsTabPanel) selectedComponent, false);
195  } else if (selectedComponent instanceof MiniTimelinePanel) {
196  runMiniTimelineWorker((MiniTimelinePanel) selectedComponent, false);
197  } else if (selectedComponent instanceof OtherOccurrencesPanel) {
198  if (CentralRepository.isEnabled()) {
199  try {
200  ((OtherOccurrencesPanel) selectedComponent).populateTableForOneType(CentralRepository.getInstance().getCorrelationTypeById(CorrelationAttributeInstance.DOMAIN_TYPE_ID), domain);
201  } catch (CentralRepoException ex) {
202  logger.log(Level.INFO, "Central repository exception while trying to get instances by type and value for domain: " + domain, ex);
203  ((OtherOccurrencesPanel) selectedComponent).reset();
204  }
205  } else {
206  ((OtherOccurrencesPanel) selectedComponent).reset();
207  }
208  }
209  //send fade in event
210  DiscoveryEventUtils.getDiscoveryEventBus().post(new DiscoveryEventUtils.DetailsVisibleEvent(true));
211  }
212  });
213  }
214 
219  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
220  private void resetTabsStatus() {
221  for (Component comp : jTabbedPane1.getComponents()) {
222  if (comp instanceof DomainArtifactsTabPanel) {
223  ((DomainArtifactsTabPanel) comp).setStatus(DomainArtifactsTabPanel.ArtifactRetrievalStatus.UNPOPULATED);
224  } else if (comp instanceof MiniTimelinePanel) {
225  ((MiniTimelinePanel) comp).setStatus(DomainArtifactsTabPanel.ArtifactRetrievalStatus.UNPOPULATED, domain);
226  } else if (comp instanceof OtherOccurrencesPanel) {
227  ((OtherOccurrencesPanel) comp).reset();
228  }
229  }
230  }
231 
237  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
238  String getSelectedTabName() {
239  return selectedTabName;
240  }
241 
247  @SuppressWarnings("unchecked")
248  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
249  private void initComponents() {
250 
251  jTabbedPane1 = new javax.swing.JTabbedPane();
252 
253  setEnabled(false);
254  setMinimumSize(new java.awt.Dimension(0, 0));
255  setPreferredSize(new java.awt.Dimension(0, 0));
256  setLayout(new java.awt.BorderLayout());
257 
258  jTabbedPane1.setMinimumSize(new java.awt.Dimension(0, 0));
259  jTabbedPane1.setPreferredSize(new java.awt.Dimension(0, 0));
260  add(jTabbedPane1, java.awt.BorderLayout.CENTER);
261  }// </editor-fold>//GEN-END:initComponents
262 
263  // Variables declaration - do not modify//GEN-BEGIN:variables
264  private javax.swing.JTabbedPane jTabbedPane1;
265  // End of variables declaration//GEN-END:variables
266 
267  /*
268  * Unregister the MiniTimelinePanel from the event bus.
269  */
270  void unregister() {
271  for (Component comp : jTabbedPane1.getComponents()) {
272  if (comp instanceof MiniTimelinePanel) {
273  DiscoveryEventUtils.getDiscoveryEventBus().unregister(comp);
274  }
275  }
276  }
277 }

Copyright © 2012-2021 Basis Technology. Generated on: Thu Jul 8 2021
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.