change to ChildFactory, do CommunicationsManager calls off the EDT

This commit is contained in:
millmanorama 2017-11-20 14:57:44 +01:00
parent 183daff325
commit f47edb131e
6 changed files with 135 additions and 88 deletions

View File

@ -18,17 +18,16 @@
*/
package org.sleuthkit.autopsy.communications;
import java.util.List;
import java.util.Set;
import java.util.logging.Level;
import org.openide.nodes.AbstractNode;
import org.openide.nodes.ChildFactory;
import org.openide.nodes.Children;
import org.openide.nodes.Node;
import org.sleuthkit.autopsy.coreutils.Logger;
import org.sleuthkit.datamodel.AccountDeviceInstance;
import org.sleuthkit.datamodel.BlackboardArtifact;
import org.sleuthkit.datamodel.CommunicationsFilter;
import org.sleuthkit.datamodel.CommunicationsManager;
import org.sleuthkit.datamodel.TskCoreException;
/**
* 'Root' Node for the Account/Messages area. Has children which are all the
@ -39,37 +38,43 @@ class AccountDetailsNode extends AbstractNode {
private final static Logger logger = Logger.getLogger(AccountDetailsNode.class.getName());
AccountDetailsNode(Set<AccountDeviceInstance> accountDeviceInstances, CommunicationsFilter filter, CommunicationsManager commsManager) {
super(new AccountRelationshipChildren(accountDeviceInstances, commsManager, filter));
AccountDetailsNode(Set<BlackboardArtifact> accountDeviceInstances, CommunicationsFilter filter, CommunicationsManager commsManager) {
super(Children.create(new AccountRelationshipChildren(accountDeviceInstances, commsManager, filter), true));
}
/**
* Children object for the relationships that the accounts are part of.
*/
private static class AccountRelationshipChildren extends Children.Keys<BlackboardArtifact> {
private static class AccountRelationshipChildren extends ChildFactory<BlackboardArtifact> {
private final Set<AccountDeviceInstance> accountDeviceInstances;
private final Set<BlackboardArtifact> accountDeviceInstances;
private final CommunicationsManager commsManager;
private final CommunicationsFilter filter;
private AccountRelationshipChildren(Set<AccountDeviceInstance> accountDeviceInstances, CommunicationsManager commsManager, CommunicationsFilter filter) {
private AccountRelationshipChildren(Set<BlackboardArtifact> accountDeviceInstances, CommunicationsManager commsManager, CommunicationsFilter filter) {
this.accountDeviceInstances = accountDeviceInstances;
this.commsManager = commsManager;
this.filter = filter;
}
@Override
protected Node[] createNodes(BlackboardArtifact key) {
return new Node[]{new RelationShipNode(key)};
protected boolean createKeys(List<BlackboardArtifact> list) {
list.addAll(accountDeviceInstances);
return true;
}
@Override
protected void addNotify() {
try {
setKeys(commsManager.getCommunications(accountDeviceInstances, filter));
} catch (TskCoreException ex) {
logger.log(Level.WARNING, "Error loading communications for accounts. ", ex);
}
protected Node createNodeForKey(BlackboardArtifact t) {
return new RelationShipNode(t); //To change body of generated methods, choose Tools | Templates.
}
// @Override
// protected Node[] createNodes(BlackboardArtifact key) {
// return new Node[]{new RelationShipNode(key)};
// }
// @Override
// protected void addNotify() {
// setKeys(accountDeviceInstances);
// }
}
}

View File

@ -23,17 +23,21 @@ import org.sleuthkit.datamodel.CommunicationsFilter;
/**
* Key for AccountDeviceInstance node.
*
*
* Encapsulates a AccountDeviceInstance, and CommunicationsFilter.
*/
public class AccountDeviceInstanceKey {
class AccountDeviceInstanceKey {
private final AccountDeviceInstance accountDeviceInstance;
private final CommunicationsFilter filter;
private final long messageCount;
AccountDeviceInstanceKey(AccountDeviceInstance accountDeviceInstance, CommunicationsFilter filter) {
AccountDeviceInstanceKey(AccountDeviceInstance accountDeviceInstance, CommunicationsFilter filter, long msgCount) {
this.accountDeviceInstance = accountDeviceInstance;
this.filter = filter;
this.messageCount = msgCount;
}
AccountDeviceInstance getAccountDeviceInstance() {
@ -43,4 +47,8 @@ public class AccountDeviceInstanceKey {
CommunicationsFilter getCommunicationsFilter() {
return filter;
}
long getMessageCount() {
return messageCount;
}
}

View File

@ -18,59 +18,59 @@
*/
package org.sleuthkit.autopsy.communications;
import java.util.Collections;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.openide.nodes.AbstractNode;
import org.openide.nodes.ChildFactory;
import org.openide.nodes.Children;
import org.openide.nodes.Node;
import org.openide.nodes.Sheet;
import org.openide.util.NbBundle;
import org.openide.util.lookup.Lookups;
import org.sleuthkit.autopsy.datamodel.NodeProperty;
import org.sleuthkit.datamodel.Account;
import org.sleuthkit.datamodel.AccountDeviceInstance;
import org.sleuthkit.datamodel.CommunicationsFilter;
import org.sleuthkit.datamodel.CommunicationsManager;
import org.sleuthkit.datamodel.TskCoreException;
class AccountsRootChildren extends Children.Keys<AccountDeviceInstanceKey> {
class AccountsRootChildren extends ChildFactory<AccountDeviceInstanceKey> {
private final List<AccountDeviceInstanceKey> accountDeviceInstanceKeys;
private final CommunicationsManager commsManager;
AccountsRootChildren(List<AccountDeviceInstanceKey> accountDeviceInstanceKeys, CommunicationsManager commsManager) {
super(true);
super();
this.accountDeviceInstanceKeys = accountDeviceInstanceKeys;
this.commsManager = commsManager;
}
@Override
protected void removeNotify() {
super.removeNotify();
setKeys(Collections.emptySet());
}
@Override
protected void addNotify() {
super.addNotify();
setKeys(accountDeviceInstanceKeys);
}
//these are the methods for Children.Keys
// @Override
// protected void removeNotify() {
// super.removeNotify();
// setKeys(Collections.emptySet());
// }
//
// @Override
// protected void addNotify() {
// super.addNotify();
// setKeys(accountDeviceInstanceKeys);
// }
// @Override
// protected Node[] createNodes(AccountDeviceInstanceKey key) {
// return new Node[]{new AccountDeviceInstanceNode(key, commsManager)};
// }
//These are the methods for ChildFactory. I am going to keep them around but commented until we make a final descision.
// @Override
// protected boolean createKeys(List<Account> list) {
// list.addAll(accounts);
// return true;
// }
//
// @Override
// protected Node createNodeForKey(Account key) {
// return new AccountDeviceInstanceNode(key);
// }
@Override
protected Node[] createNodes(AccountDeviceInstanceKey key) {
return new Node[]{new AccountDeviceInstanceNode(key, commsManager)};
protected boolean createKeys(List<AccountDeviceInstanceKey> list) {
list.addAll(accountDeviceInstanceKeys);
return true;
}
@Override
protected Node createNodeForKey(AccountDeviceInstanceKey key) {
return new AccountDeviceInstanceNode(key, commsManager);
}
/**
@ -79,21 +79,21 @@ class AccountsRootChildren extends Children.Keys<AccountDeviceInstanceKey> {
static class AccountDeviceInstanceNode extends AbstractNode {
private static final Logger LOGGER = Logger.getLogger(AccountDeviceInstanceNode.class.getName());
private final AccountDeviceInstance accountDeviceInstance;
private final AccountDeviceInstanceKey accountDeviceInstanceKey;
private final CommunicationsManager commsManager;
private final CommunicationsFilter filter;
private final Account account;
private AccountDeviceInstanceNode(AccountDeviceInstanceKey accountDeviceInstanceKey, CommunicationsManager commsManager) {
super(Children.LEAF, Lookups.fixed(accountDeviceInstanceKey, commsManager));
this.accountDeviceInstance = accountDeviceInstanceKey.getAccountDeviceInstance();
this.accountDeviceInstanceKey = accountDeviceInstanceKey;
this.commsManager = commsManager;
this.filter = accountDeviceInstanceKey.getCommunicationsFilter();
setName(accountDeviceInstance.getAccount().getAccountUniqueID());
setIconBaseWithExtension("org/sleuthkit/autopsy/communications/images/" + Utils.getIconFileName(accountDeviceInstance.getAccount().getAccountType()));
this.account = accountDeviceInstanceKey.getAccountDeviceInstance().getAccount();
setName(account.getAccountUniqueID());
setIconBaseWithExtension("org/sleuthkit/autopsy/communications/images/" + Utils.getIconFileName(account.getAccountType()));
}
public AccountDeviceInstance getAccountDeviceInstance() {
return accountDeviceInstance;
return accountDeviceInstanceKey.getAccountDeviceInstance();
}
public CommunicationsManager getCommsManager() {
@ -101,7 +101,7 @@ class AccountsRootChildren extends Children.Keys<AccountDeviceInstanceKey> {
}
public CommunicationsFilter getFilter() {
return filter;
return accountDeviceInstanceKey.getCommunicationsFilter();
}
@Override
@ -116,15 +116,13 @@ class AccountsRootChildren extends Children.Keys<AccountDeviceInstanceKey> {
properties = Sheet.createPropertiesSet();
s.put(properties);
}
long msgCount = 0;
try {
msgCount = commsManager.getCommunicationsCount(accountDeviceInstance, filter );
} catch (TskCoreException ex) {
LOGGER.log(Level.WARNING, "Failed to get message count for account", ex); //NON-NLS
}
properties.put(new NodeProperty<>("type", Bundle.AccountNode_accountType(), "type", accountDeviceInstance.getAccount().getAccountType().getDisplayName())); // NON-NLS
properties.put(new NodeProperty<>("count", Bundle.AccountNode_messageCount(), "count", msgCount)); // NON-NLS
properties.put(new NodeProperty<>("device", Bundle.AccountNode_device(), "device", accountDeviceInstance.getDeviceId())); // NON-NLS
properties.put(new NodeProperty<>("type", Bundle.AccountNode_accountType(), "type",
account.getAccountType().getDisplayName())); // NON-NLS
properties.put(new NodeProperty<>("count", Bundle.AccountNode_messageCount(), "count",
accountDeviceInstanceKey.getMessageCount())); // NON-NLS
properties.put(new NodeProperty<>("device", Bundle.AccountNode_device(), "device",
accountDeviceInstanceKey.getAccountDeviceInstance().getDeviceId())); // NON-NLS
return s;
}
}

View File

@ -68,15 +68,15 @@
</Component>
<Component class="javax.swing.JLabel" name="filtersTitleLabel">
<Properties>
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
<Font name="Tahoma" size="16" style="0"/>
</Property>
<Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor">
<Image iconType="3" name="/org/sleuthkit/autopsy/communications/images/funnel.png"/>
</Property>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="org/sleuthkit/autopsy/communications/Bundle.properties" key="FiltersPanel.filtersTitleLabel.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property>
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
<Font name="Tahoma" size="16" style="0"/>
</Property>
</Properties>
</Component>
<Container class="javax.swing.JPanel" name="jPanel2">
@ -271,13 +271,13 @@
<EmptySpace max="-2" attributes="0"/>
<Component id="startDatePicker" min="-2" pref="162" max="-2" attributes="0"/>
</Group>
<Group type="102" alignment="0" attributes="0">
<Group type="102" alignment="1" attributes="0">
<Component id="endCheckBox" min="-2" max="-2" attributes="0"/>
<EmptySpace type="unrelated" max="-2" attributes="0"/>
<Component id="endDatePicker" min="-2" pref="161" max="-2" attributes="0"/>
<Component id="endDatePicker" min="-2" pref="163" max="-2" attributes="0"/>
</Group>
</Group>
<EmptySpace min="0" pref="0" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="0" max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>

View File

@ -21,6 +21,7 @@ package org.sleuthkit.autopsy.communications;
import java.awt.Cursor;
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -32,10 +33,12 @@ import javax.swing.JCheckBox;
import javax.swing.SwingWorker;
import org.openide.explorer.ExplorerManager;
import org.openide.nodes.AbstractNode;
import org.openide.nodes.Children;
import org.sleuthkit.autopsy.casemodule.Case;
import org.sleuthkit.autopsy.coreutils.Logger;
import org.sleuthkit.autopsy.coreutils.ThreadConfined;
import org.sleuthkit.datamodel.Account;
import org.sleuthkit.datamodel.AccountDeviceInstance;
import org.sleuthkit.datamodel.AccountTypeFilter;
import org.sleuthkit.datamodel.CommunicationsFilter;
import org.sleuthkit.datamodel.CommunicationsManager;
@ -53,7 +56,6 @@ final public class FiltersPanel extends javax.swing.JPanel {
private static final Logger logger = Logger.getLogger(FiltersPanel.class.getName());
private static final long serialVersionUID = 1L;
// private static final DateFormat DATE_FORMAT = new SimpleDateFormat("MM/dd/yyyy");
private ExplorerManager em;
@ThreadConfined(type = ThreadConfined.ThreadType.AWT)
@ -67,8 +69,6 @@ final public class FiltersPanel extends javax.swing.JPanel {
endDatePicker.setDateToToday();
startDatePicker.getSettings().setVetoPolicy(
//no end date, or start is before end
startDate -> endCheckBox.isSelected() == false
|| startDate.compareTo(endDatePicker.getDate()) <= 0
);
@ -77,16 +77,15 @@ final public class FiltersPanel extends javax.swing.JPanel {
endDate -> startCheckBox.isSelected() == false
|| endDate.compareTo(startDatePicker.getDate()) >= 0
);
applyFiltersButton.addActionListener(actionEvent -> applyFilters());
applyFiltersButton.addActionListener(actionEvent -> applyFilters());
}
/**
* Update the filter widgets, and apply them.
*/
void updateAndApplyFilters() {
updateAccountTypeFilter();
updateDeviceFilter();
updateFilters();
if (em != null) {
applyFilters();
}
@ -94,6 +93,11 @@ final public class FiltersPanel extends javax.swing.JPanel {
dateRangeLabel.setText("Date Range ( " + Utils.getUserPreferredZoneId().getId() + "):");
}
private void updateFilters() {
updateAccountTypeFilter();
updateDeviceFilter();
}
@Override
public void addNotify() {
super.addNotify();
@ -312,10 +316,10 @@ final public class FiltersPanel extends javax.swing.JPanel {
.addComponent(startCheckBox)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(startDatePicker, javax.swing.GroupLayout.PREFERRED_SIZE, 162, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(jPanel4Layout.createSequentialGroup()
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
.addComponent(endCheckBox)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(endDatePicker, javax.swing.GroupLayout.PREFERRED_SIZE, 161, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addComponent(endDatePicker, javax.swing.GroupLayout.PREFERRED_SIZE, 163, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGap(0, 0, 0))
);
jPanel4Layout.setVerticalGroup(
@ -377,16 +381,18 @@ final public class FiltersPanel extends javax.swing.JPanel {
try {
final CommunicationsManager commsManager = Case.getCurrentCase().getSleuthkitCase().getCommunicationsManager();
getRootPane().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
new SwingWorker<AbstractNode, Void>() {
@Override
protected AbstractNode doInBackground() throws Exception {
List<AccountDeviceInstanceKey> accountDeviceInstanceKeys =
commsManager.getAccountDeviceInstancesWithCommunications(commsFilter)
.stream()
.map(adi -> new AccountDeviceInstanceKey(adi, commsFilter))
.collect(Collectors.toList());
return new AbstractNode(new AccountsRootChildren(accountDeviceInstanceKeys, commsManager));
List<AccountDeviceInstanceKey> accountDeviceInstanceKeys = new ArrayList<>();
for (AccountDeviceInstance adi : commsManager.getAccountDeviceInstancesWithCommunications(commsFilter)) {
long communicationsCount = commsManager.getCommunicationsCount(adi, commsFilter);
accountDeviceInstanceKeys.add(new AccountDeviceInstanceKey(adi, commsFilter, communicationsCount));
};
return new AbstractNode(Children.create(new AccountsRootChildren(accountDeviceInstanceKeys, commsManager), true));
}
@Override
@ -394,6 +400,7 @@ final public class FiltersPanel extends javax.swing.JPanel {
super.done(); //To change body of generated methods, choose Tools | Templates.
setCursor(Cursor.getDefaultCursor());
getRootPane().setCursor(Cursor.getDefaultCursor());
try {
em.setRootContext(get());
} catch (InterruptedException | ExecutionException ex) {

View File

@ -18,17 +18,23 @@
*/
package org.sleuthkit.autopsy.communications;
import java.awt.Cursor;
import java.util.Collections;
import java.util.Set;
import java.util.concurrent.ExecutionException;
import java.util.logging.Level;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.swing.SwingWorker;
import org.openide.explorer.ExplorerManager;
import org.openide.nodes.Node;
import org.sleuthkit.autopsy.communications.AccountsRootChildren.AccountDeviceInstanceNode;
import org.sleuthkit.autopsy.corecomponents.DataResultPanel;
import org.sleuthkit.autopsy.corecomponents.DataResultViewerTable;
import org.sleuthkit.autopsy.corecomponents.TableFilterNode;
import org.sleuthkit.autopsy.coreutils.Logger;
import org.sleuthkit.datamodel.AccountDeviceInstance;
import org.sleuthkit.datamodel.BlackboardArtifact;
import org.sleuthkit.datamodel.CommunicationsFilter;
import org.sleuthkit.datamodel.CommunicationsManager;
@ -40,6 +46,8 @@ final class MessageBrowser extends javax.swing.JPanel implements ExplorerManager
private static final long serialVersionUID = 1L;
private static final Logger logger = Logger.getLogger(MessageBrowser.class.getName());
private final DataResultPanel messagesResultPanel;
private final ExplorerManager explorerManager = new ExplorerManager();
private final DataResultViewerTable dataResultViewerTable = new DataResultViewerTable(explorerManager, "Messages");
@ -84,8 +92,29 @@ final class MessageBrowser extends javax.swing.JPanel implements ExplorerManager
.collect(Collectors.toSet());
messagesResultPanel.setPath(selectedNodes.length + " accounts");
}
messagesResultPanel.setNode(new TableFilterNode(
new AccountDetailsNode(collect, filter, commsManager), true));
messagesResultPanel.setNumMatches(0);
messagesResultPanel.setNode(null);
getRootPane().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
new SwingWorker<Set<BlackboardArtifact>, Void>() {
@Override
protected Set<BlackboardArtifact> doInBackground() throws Exception {
return commsManager.getCommunications(collect, filter);
}
@Override
protected void done() {
super.done(); //To change body of generated methods, choose Tools | Templates.
try {
messagesResultPanel.setNode(new TableFilterNode(
new AccountDetailsNode(get(), filter, commsManager), true));
} catch (InterruptedException | ExecutionException ex) {
logger.log(Level.SEVERE, "Error getting relationships", ex);
}
getRootPane().setCursor(Cursor.getDefaultCursor());
}
}.execute();
}
}
});