Restrict events and UI if not running interactively

This commit is contained in:
Richard Cordovano
2015-06-19 14:28:10 -04:00
parent 6071dc5357
commit ad376fc96d
5 changed files with 125 additions and 116 deletions
@@ -1392,29 +1392,33 @@ public class Case {
Case.clearTempFolder();
checkSubFolders(toChangeTo);
// enable these menus
CallableSystemAction.get(AddImageAction.class).setEnabled(true);
CallableSystemAction.get(CaseCloseAction.class).setEnabled(true);
CallableSystemAction.get(CasePropertiesAction.class).setEnabled(true);
CallableSystemAction.get(CaseDeleteAction.class).setEnabled(true); // Delete Case menu
if (IngestManager.getInstance().isRunningInteractively()) {
// enable these menus
CallableSystemAction.get(AddImageAction.class).setEnabled(true);
CallableSystemAction.get(CaseCloseAction.class).setEnabled(true);
CallableSystemAction.get(CasePropertiesAction.class).setEnabled(true);
CallableSystemAction.get(CaseDeleteAction.class).setEnabled(true); // Delete Case menu
if (toChangeTo.hasData()) {
// open all top components
CoreComponentControl.openCoreWindows();
} else {
// close all top components
CoreComponentControl.closeCoreWindows();
if (toChangeTo.hasData()) {
// open all top components
CoreComponentControl.openCoreWindows();
} else {
// close all top components
CoreComponentControl.closeCoreWindows();
}
}
} else { // case is closed
// close all top components first
CoreComponentControl.closeCoreWindows();
// disable these menus
CallableSystemAction.get(AddImageAction.class).setEnabled(false); // Add Image menu
CallableSystemAction.get(CaseCloseAction.class).setEnabled(false); // Case Close menu
CallableSystemAction.get(CasePropertiesAction.class).setEnabled(false); // Case Properties menu
CallableSystemAction.get(CaseDeleteAction.class).setEnabled(false); // Delete Case menu
if (IngestManager.getInstance().isRunningInteractively()) {
// close all top components first
CoreComponentControl.closeCoreWindows();
// disable these menus
CallableSystemAction.get(AddImageAction.class).setEnabled(false); // Add Image menu
CallableSystemAction.get(CaseCloseAction.class).setEnabled(false); // Case Close menu
CallableSystemAction.get(CasePropertiesAction.class).setEnabled(false); // Case Properties menu
CallableSystemAction.get(CaseDeleteAction.class).setEnabled(false); // Delete Case menu
}
//clear pending notifications
MessageNotifyUtil.Notify.clear();
@@ -523,80 +523,82 @@ public final class DirectoryTreeTopComponent extends TopComponent implements Dat
*/
@Override
public void propertyChange(PropertyChangeEvent evt) {
String changed = evt.getPropertyName();
if (changed.equals(Case.Events.CURRENT_CASE.toString())) { // changed current case
// When a case is closed, the old value of this property is the
// closed Case object and the new value is null. When a case is
// opened, the old value is null and the new value is the new Case
// object.
// @@@ This needs to be revisited. Perhaps case closed and case
// opened events instead of property change events would be a better
// solution. Either way, more probably needs to be done to clean up
// data model objects when a case is closed.
if (evt.getOldValue() != null && evt.getNewValue() == null) {
// The current case has been closed. Reset the ExplorerManager.
SwingUtilities.invokeLater(() -> {
Node emptyNode = new AbstractNode(Children.LEAF);
em.setRootContext(emptyNode);
});
} else if (evt.getNewValue() != null) {
// A new case has been opened. Reset the ExplorerManager.
Case newCase = (Case) evt.getNewValue();
final String newCaseName = newCase.getName();
SwingUtilities.invokeLater(() -> {
em.getRootContext().setName(newCaseName);
em.getRootContext().setDisplayName(newCaseName);
if (IngestManager.getInstance().isRunningInteractively()) {
String changed = evt.getPropertyName();
if (changed.equals(Case.Events.CURRENT_CASE.toString())) { // changed current case
// When a case is closed, the old value of this property is the
// closed Case object and the new value is null. When a case is
// opened, the old value is null and the new value is the new Case
// object.
// @@@ This needs to be revisited. Perhaps case closed and case
// opened events instead of property change events would be a better
// solution. Either way, more probably needs to be done to clean up
// data model objects when a case is closed.
if (evt.getOldValue() != null && evt.getNewValue() == null) {
// The current case has been closed. Reset the ExplorerManager.
SwingUtilities.invokeLater(() -> {
Node emptyNode = new AbstractNode(Children.LEAF);
em.setRootContext(emptyNode);
});
} else if (evt.getNewValue() != null) {
// A new case has been opened. Reset the ExplorerManager.
Case newCase = (Case) evt.getNewValue();
final String newCaseName = newCase.getName();
SwingUtilities.invokeLater(() -> {
em.getRootContext().setName(newCaseName);
em.getRootContext().setDisplayName(newCaseName);
// Reset the forward and back
// buttons. Note that a call to CoreComponentControl.openCoreWindows()
// by the new Case object will lead to a componentOpened() call
// that will repopulate the tree.
// @@@ The repopulation of the tree in this fashion also merits
// reconsideration.
resetHistory();
// buttons. Note that a call to CoreComponentControl.openCoreWindows()
// by the new Case object will lead to a componentOpened() call
// that will repopulate the tree.
// @@@ The repopulation of the tree in this fashion also merits
// reconsideration.
resetHistory();
});
}
} // if the image is added to the case
else if (changed.equals(Case.Events.DATA_SOURCE_ADDED.toString())) {
/**
* Checking for a current case is a stop gap measure until a
* different way of handling the closing of cases is worked out.
* Currently, remote events may be received for a case that is
* already closed.
*/
try {
Case.getCurrentCase();
CoreComponentControl.openCoreWindows();
SwingUtilities.invokeLater(this::componentOpened);
} catch (IllegalStateException notUsed) {
/**
* Case is closed, do nothing.
*/
}
} // change in node selection
else if (changed.equals(ExplorerManager.PROP_SELECTED_NODES)) {
SwingUtilities.invokeLater(() -> {
respondSelection((Node[]) evt.getOldValue(), (Node[]) evt.getNewValue());
});
}
} // if the image is added to the case
else if (changed.equals(Case.Events.DATA_SOURCE_ADDED.toString())) {
/**
* Checking for a current case is a stop gap measure until a
* different way of handling the closing of cases is worked out.
* Currently, remote events may be received for a case that is
* already closed.
*/
try {
Case.getCurrentCase();
CoreComponentControl.openCoreWindows();
SwingUtilities.invokeLater(this::componentOpened);
} catch (IllegalStateException notUsed) {
/**
* Case is closed, do nothing.
*/
}
} // change in node selection
else if (changed.equals(ExplorerManager.PROP_SELECTED_NODES)) {
SwingUtilities.invokeLater(() -> {
respondSelection((Node[]) evt.getOldValue(), (Node[]) evt.getNewValue());
});
} else if (changed.equals(IngestManager.IngestModuleEvent.DATA_ADDED.toString())) {
} else if (changed.equals(IngestManager.IngestModuleEvent.DATA_ADDED.toString())) {
// nothing to do here.
// all nodes should be listening for these events and update accordingly.
} else if (changed.equals(IngestManager.IngestJobEvent.COMPLETED.toString())
|| changed.equals(IngestManager.IngestJobEvent.CANCELLED.toString())
|| changed.equals(IngestManager.IngestModuleEvent.CONTENT_CHANGED.toString())) {
/**
* Checking for a current case is a stop gap measure until a
* different way of handling the closing of cases is worked out.
* Currently, remote events may be received for a case that is
* already closed.
*/
try {
Case.getCurrentCase();
SwingUtilities.invokeLater(this::refreshDataSourceTree);
} catch (IllegalStateException notUsed) {
// all nodes should be listening for these events and update accordingly.
} else if (changed.equals(IngestManager.IngestJobEvent.COMPLETED.toString())
|| changed.equals(IngestManager.IngestJobEvent.CANCELLED.toString())
|| changed.equals(IngestManager.IngestModuleEvent.CONTENT_CHANGED.toString())) {
/**
* Case is closed, do nothing.
* Checking for a current case is a stop gap measure until a
* different way of handling the closing of cases is worked out.
* Currently, remote events may be received for a case that is
* already closed.
*/
try {
Case.getCurrentCase();
SwingUtilities.invokeLater(this::refreshDataSourceTree);
} catch (IllegalStateException notUsed) {
/**
* Case is closed, do nothing.
*/
}
}
}
}
@@ -34,6 +34,7 @@ import javax.jms.Topic;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.sleuthkit.autopsy.casemodule.Case;
import org.sleuthkit.autopsy.coreutils.Logger;
import org.sleuthkit.autopsy.ingest.IngestManager;
/**
* Provides thread-safe support for publishing events to registered subscribers
@@ -135,38 +136,40 @@ final class RemoteEventPublisher {
*/
@Override
public void onMessage(Message message) {
/**
* This is a stop gap measure until a different way of handling the
* closing of cases is worked out. Currently, Case.currentCase is
* set to null before Case.Event.CURRENT_CASE is published. That
* means that clients of this class have not had the chance to close
* their remote event channels and remote events may be received for
* a case that is already closed.
*/
try {
Case.getCurrentCase();
} catch (IllegalStateException notUsed) {
if (IngestManager.getInstance().isRunningInteractively()) {
/**
* Case is closed, do not publish the event.
* This is a stop gap measure until a different way of handling
* the closing of cases is worked out. Currently,
* Case.currentCase is set to null before
* Case.Event.CURRENT_CASE is published. That means that clients
* of this class have not had the chance to close their remote
* event channels and remote events may be received for a case
* that is already closed.
*/
return;
}
try {
if (message instanceof ObjectMessage) {
ObjectMessage objectMessage = (ObjectMessage) message;
Object object = objectMessage.getObject();
if (object instanceof AutopsyEvent) {
AutopsyEvent event = (AutopsyEvent) object;
event.setSourceType(AutopsyEvent.SourceType.REMOTE);
localPublisher.publish(event);
}
try {
Case.getCurrentCase();
} catch (IllegalStateException notUsed) {
/**
* Case is closed, do not publish the event.
*/
return;
}
try {
if (message instanceof ObjectMessage) {
ObjectMessage objectMessage = (ObjectMessage) message;
Object object = objectMessage.getObject();
if (object instanceof AutopsyEvent) {
AutopsyEvent event = (AutopsyEvent) object;
event.setSourceType(AutopsyEvent.SourceType.REMOTE);
localPublisher.publish(event);
}
}
} catch (Exception ex) {
logger.log(Level.SEVERE, "Error receiving message", ex);
}
} catch (Exception ex) {
logger.log(Level.SEVERE, "Error receiving message", ex);
}
}
}
}
@@ -1,5 +1,5 @@
#Updated by build script
#Mon, 08 Jun 2015 11:37:44 -0400
#Fri, 19 Jun 2015 13:59:39 -0400
LBL_splash_window_title=Starting Autopsy
SPLASH_HEIGHT=314
SPLASH_WIDTH=538
@@ -1,5 +1,5 @@
#Updated by build script
#Mon, 08 Jun 2015 11:37:44 -0400
#Fri, 19 Jun 2015 13:59:39 -0400
CTL_MainWindow_Title=Autopsy 3.1.2
CTL_MainWindow_Title_No_Project=Autopsy 3.1.2