Skip to content

Commit

Permalink
Added case listener to OpenAction to allow it to enable and disable i…
Browse files Browse the repository at this point in the history
…tself
  • Loading branch information
wishdasher committed Sep 8, 2016
1 parent 7993d6d commit b9c3cd2
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 36 deletions.
2 changes: 1 addition & 1 deletion Core/src/org/sleuthkit/autopsy/core/layer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@
-->
</folder>
<folder name="Ingest">
<attr name="position" intvalue="109"/>
<attr name="position" intvalue="105"/>
<file name="org-sleuthkit-autopsy-ingest-IngestMessagesAction.shadow">
<attr name="originalFile" stringvalue="Actions/Tools/org-sleuthkit-autopsy-ingest-IngestMessagesAction.instance"/>
</file>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
/*
* Autopsy Forensic Browser
*
* Copyright 2013 Basis Technology Corp.
* Contact: carrier <at> sleuthkit <dot> org
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
* Autopsy Forensic Browser
*
* Copyright 2013 Basis Technology Corp.
* Contact: carrier <at> sleuthkit <dot> org
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.sleuthkit.autopsy.imagegallery.actions;

import java.awt.Component;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JOptionPane;
Expand All @@ -45,28 +47,35 @@
})
@ActionRegistration(displayName = "#CTL_OpenAction", lazy = false)
@Messages({"CTL_OpenAction=View Images/Videos",
"OpenAction.stale.confDlg.msg=The image / video database may be out of date. " +
"Do you want to update and listen for further ingest results?\n" +
"Choosing 'yes' will update the database and enable listening to future ingests.",
"OpenAction.stale.confDlg.title=Image Gallery"})
"OpenAction.stale.confDlg.msg=The image / video database may be out of date. " +
"Do you want to update and listen for further ingest results?\n" +
"Choosing 'yes' will update the database and enable listening to future ingests.",
"OpenAction.stale.confDlg.title=Image Gallery"})
public final class OpenAction extends CallableSystemAction implements Presenter.Toolbar {

private static final String VIEW_IMAGES_VIDEOS = Bundle.CTL_OpenAction();
private static final boolean fxInited = Installer.isJavaFxInited();
private static final Logger LOGGER = Logger.getLogger(OpenAction.class.getName());
private JButton toolbarButton = new JButton();
private final PropertyChangeListener pcl;

public OpenAction() {
super();
toolbarButton.addActionListener(actionEvent -> performAction());
this.setEnabled(true);
pcl = (PropertyChangeEvent evt) -> {
if (evt.getPropertyName().equals(Case.Events.CURRENT_CASE.toString())) {
setEnabled(Case.isCaseOpen());
}
};
Case.addPropertyChangeListener(pcl);
this.setEnabled(false);
}

@Override
public boolean isEnabled() {
return Case.isCaseOpen() && fxInited;// && Case.getCurrentCase().hasData();
return Case.isCaseOpen() && fxInited && Case.getCurrentCase().hasData();
}

/** Returns the toolbar component of this action
*
* @return component the toolbar button */
Expand All @@ -77,7 +86,7 @@ public Component getToolbarPresenter() {
toolbarButton.setText(this.getName());
return toolbarButton;
}

/**
* Set this action to be enabled/disabled
*
Expand All @@ -88,26 +97,26 @@ public void setEnabled(boolean value) {
super.setEnabled(value);
toolbarButton.setEnabled(value);
}

@Override
@SuppressWarnings("fallthrough")
public void performAction() {

//check case
if (!Case.isCaseOpen()) {
return;
}
final Case currentCase = Case.getCurrentCase();

if (ImageGalleryModule.isDrawableDBStale(currentCase)) {
//drawable db is stale, ask what to do
int answer = JOptionPane.showConfirmDialog(WindowManager.getDefault().getMainWindow(), Bundle.OpenAction_stale_confDlg_msg(),
Bundle.OpenAction_stale_confDlg_title(), JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE);

switch (answer) {
case JOptionPane.YES_OPTION:
ImageGalleryController.getDefault().setListeningEnabled(true);
//fall through
//fall through
case JOptionPane.NO_OPTION:
ImageGalleryTopComponent.openTopComponent();
break;
Expand All @@ -119,17 +128,17 @@ public void performAction() {
ImageGalleryTopComponent.openTopComponent();
}
}

@Override
public String getName() {
return VIEW_IMAGES_VIDEOS;
}

@Override
public HelpCtx getHelpCtx() {
return HelpCtx.DEFAULT_HELP;
}

@Override
public boolean asynchronous() {
return false; // run on edt
Expand Down

0 comments on commit b9c3cd2

Please sign in to comment.