Autopsy  4.20.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  } else if (selectedComponent instanceof OtherOccurrencesPanel) {
100  if (CentralRepository.isEnabled()) {
101  try {
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();
106  }
107  } else {
108  ((OtherOccurrencesPanel) selectedComponent).reset();
109  }
110  }
111  }
112  }
113  }
114  });
115  }
116 
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);
126  return;
127  }
128  }
129  }
130 
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();
141  }
142  return null;
143  }
144 
154  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
155  private void runDomainWorker(DomainArtifactsTabPanel domainArtifactsTabPanel, boolean shouldGrabFocus) {
156  if (singleArtifactDomainWorker != null && !singleArtifactDomainWorker.isDone()) {
157  singleArtifactDomainWorker.cancel(true);
158  }
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();
166  }
167 
168  }
169 
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();
184  }
185  }
186 
193  @Subscribe
194  void handlePopulateDomainTabsEvent(DiscoveryEventUtils.PopulateDomainTabsEvent populateEvent) {
195  SwingUtilities.invokeLater(() -> {
196  domain = populateEvent.getDomain();
197  if (StringUtils.isBlank(domain)) {
198  resetTabsStatus();
199  //send fade out event
200  DiscoveryEventUtils.getDiscoveryEventBus().post(new DiscoveryEventUtils.DetailsVisibleEvent(false));
201  } else {
202  resetTabsStatus();
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()) {
210  try {
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();
215  }
216  } else {
217  ((OtherOccurrencesPanel) selectedComponent).reset();
218  }
219  }
220  //send fade in event
221  DiscoveryEventUtils.getDiscoveryEventBus().post(new DiscoveryEventUtils.DetailsVisibleEvent(true));
222  }
223  });
224  }
225 
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();
239  }
240  }
241  }
242 
248  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
249  String getSelectedTabName() {
250  return selectedTabName;
251  }
252 
258  @SuppressWarnings("unchecked")
259  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
260  private void initComponents() {
261 
262  jTabbedPane1 = new javax.swing.JTabbedPane();
263 
264  setEnabled(false);
265  setMinimumSize(new java.awt.Dimension(0, 0));
266  setPreferredSize(new java.awt.Dimension(0, 0));
267  setLayout(new java.awt.BorderLayout());
268 
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);
272  }// </editor-fold>//GEN-END:initComponents
273 
274  // Variables declaration - do not modify//GEN-BEGIN:variables
275  private javax.swing.JTabbedPane jTabbedPane1;
276  // End of variables declaration//GEN-END:variables
277 
278  /*
279  * Unregister the MiniTimelinePanel from the event bus.
280  */
281  void unregister() {
282  for (Component comp : jTabbedPane1.getComponents()) {
283  if (comp instanceof MiniTimelinePanel) {
284  DiscoveryEventUtils.getDiscoveryEventBus().unregister(comp);
285  }
286  }
287  }
288 }

Copyright © 2012-2022 Basis Technology. Generated on: Tue Aug 1 2023
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.