renames and usage or error manager

This commit is contained in:
Brian Sweeney 2018-08-21 10:51:31 -06:00
parent 71d9336981
commit addb312dc0
3 changed files with 152 additions and 43 deletions

View File

@ -58,6 +58,8 @@ public final class CommonAttributePanel extends javax.swing.JDialog {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private static final Long NO_DATA_SOURCE_SELECTED = -1L; private static final Long NO_DATA_SOURCE_SELECTED = -1L;
private final UserInputErrorManager errorManager;
private boolean pictureViewCheckboxState; private boolean pictureViewCheckboxState;
@ -88,6 +90,8 @@ public final class CommonAttributePanel extends javax.swing.JDialog {
this.disableIntercaseSearch(); this.disableIntercaseSearch();
this.disablePercentageOptions(); this.disablePercentageOptions();
} }
this.errorManager = new UserInputErrorManager();
} }
private static boolean isEamDbAvailable() { private static boolean isEamDbAvailable() {
@ -621,20 +625,20 @@ public final class CommonAttributePanel extends javax.swing.JDialog {
}//GEN-LAST:event_cancelButtonActionPerformed }//GEN-LAST:event_cancelButtonActionPerformed
private void allFileCategoriesRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_allFileCategoriesRadioButtonActionPerformed private void allFileCategoriesRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_allFileCategoriesRadioButtonActionPerformed
this.manageCheckBoxState(); this.manageFileTypeCheckBoxState();
this.toggleErrorTextAndSearchBox(); this.updateErrorTextAndSearchBox();
}//GEN-LAST:event_allFileCategoriesRadioButtonActionPerformed }//GEN-LAST:event_allFileCategoriesRadioButtonActionPerformed
private void selectedFileCategoriesButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_selectedFileCategoriesButtonActionPerformed private void selectedFileCategoriesButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_selectedFileCategoriesButtonActionPerformed
this.manageCheckBoxState(); this.manageFileTypeCheckBoxState();
}//GEN-LAST:event_selectedFileCategoriesButtonActionPerformed }//GEN-LAST:event_selectedFileCategoriesButtonActionPerformed
private void pictureVideoCheckboxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pictureVideoCheckboxActionPerformed private void pictureVideoCheckboxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pictureVideoCheckboxActionPerformed
this.toggleErrorTextAndSearchBox(); this.updateErrorTextAndSearchBox();
}//GEN-LAST:event_pictureVideoCheckboxActionPerformed }//GEN-LAST:event_pictureVideoCheckboxActionPerformed
private void documentsCheckboxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_documentsCheckboxActionPerformed private void documentsCheckboxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_documentsCheckboxActionPerformed
this.toggleErrorTextAndSearchBox(); this.updateErrorTextAndSearchBox();
}//GEN-LAST:event_documentsCheckboxActionPerformed }//GEN-LAST:event_documentsCheckboxActionPerformed
private void intraCaseRadioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_intraCaseRadioActionPerformed private void intraCaseRadioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_intraCaseRadioActionPerformed
@ -669,12 +673,14 @@ public final class CommonAttributePanel extends javax.swing.JDialog {
} else { } else {
this.percentageThreshold.setEnabled(false); this.percentageThreshold.setEnabled(false);
} }
this.handleFrequencyPercentageCriteriaMet();
}//GEN-LAST:event_percentageThresholdCheckActionPerformed }//GEN-LAST:event_percentageThresholdCheckActionPerformed
private void percentageThresholdActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_percentageThresholdActionPerformed private void percentageThresholdActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_percentageThresholdActionPerformed
String percentageString = this.percentageThreshold.getText(); String percentageString = this.percentageThreshold.getText();
Integer percentage; Integer percentage = null;
try{ try{
percentage = Integer.parseInt(percentageString); percentage = Integer.parseInt(percentageString);
@ -683,6 +689,9 @@ public final class CommonAttributePanel extends javax.swing.JDialog {
this.percentageThresholdValue = -1; this.percentageThresholdValue = -1;
} }
this.percentageThresholdValue = percentage.intValue();
this.handleFrequencyPercentageCriteriaMet();
}//GEN-LAST:event_percentageThresholdActionPerformed }//GEN-LAST:event_percentageThresholdActionPerformed
public void handleInterCaseSearchCriteriaChanged() { public void handleInterCaseSearchCriteriaChanged() {
@ -696,7 +705,18 @@ public final class CommonAttributePanel extends javax.swing.JDialog {
} }
} }
private void toggleErrorTextAndSearchBox() { private void updateErrorTextAndSearchBox() {
if(this.errorManager.anyErrors()){
this.searchButton.setEnabled(false);
//grab the first error error and show it
this.errorText.setText(this.errorManager.getErrors().get(0));
this.errorText.setVisible(true);
} else {
this.searchButton.setEnabled(true);
this.errorText.setVisible(false);
}
if (!this.pictureVideoCheckbox.isSelected() && !this.documentsCheckbox.isSelected() && !this.allFileCategoriesRadioButton.isSelected()) { if (!this.pictureVideoCheckbox.isSelected() && !this.documentsCheckbox.isSelected() && !this.allFileCategoriesRadioButton.isSelected()) {
this.searchButton.setEnabled(false); this.searchButton.setEnabled(false);
this.errorText.setVisible(true); this.errorText.setVisible(true);
@ -706,7 +726,7 @@ public final class CommonAttributePanel extends javax.swing.JDialog {
} }
} }
private void manageCheckBoxState() { private void manageFileTypeCheckBoxState() {
this.pictureViewCheckboxState = this.pictureVideoCheckbox.isSelected(); this.pictureViewCheckboxState = this.pictureVideoCheckbox.isSelected();
this.documentsCheckboxState = this.documentsCheckbox.isSelected(); this.documentsCheckboxState = this.documentsCheckbox.isSelected();
@ -724,7 +744,7 @@ public final class CommonAttributePanel extends javax.swing.JDialog {
this.pictureVideoCheckbox.setEnabled(true); this.pictureVideoCheckbox.setEnabled(true);
this.documentsCheckbox.setEnabled(true); this.documentsCheckbox.setEnabled(true);
this.toggleErrorTextAndSearchBox(); this.updateErrorTextAndSearchBox();
} }
} }
@ -789,4 +809,12 @@ public final class CommonAttributePanel extends javax.swing.JDialog {
this.percentageThresholdCheck.setEnabled(false); this.percentageThresholdCheck.setEnabled(false);
this.percentageThresholdCheck.setSelected(false); this.percentageThresholdCheck.setSelected(false);
} }
private void handleFrequencyPercentageCriteriaMet() {
if(this.percentageThresholdValue > 0 && this.percentageThresholdValue<= 100){
this.errorManager.setError(UserInputErrorManager.FREQUENCY_PERCENTAGE_OUT_OF_RANGE_KEY, false);
} else {
this.errorManager.setError(UserInputErrorManager.FREQUENCY_PERCENTAGE_OUT_OF_RANGE_KEY, true);
}
}
} }

View File

@ -1,34 +0,0 @@
/*
*
* Autopsy Forensic Browser
*
* Copyright 2018 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.commonfilesearch;
/**
*
* @author bsweeney
*/
class PanelErrorMessages {
private class ErrorMessage{
int id;
String message;
boolean showMessage;
}
}

View File

@ -0,0 +1,115 @@
/*
*
* Autopsy Forensic Browser
*
* Copyright 2018 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.commonfilesearch;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* Manager for present state of errors on the Common Files Search.
*/
class UserInputErrorManager {
static final int FREQUENCY_PERCENTAGE_OUT_OF_RANGE_KEY = 1;
private final Map<Integer, ErrorMessage> currentErrors;
UserInputErrorManager (){
this.currentErrors = new HashMap<>();
this.currentErrors.put(FREQUENCY_PERCENTAGE_OUT_OF_RANGE_KEY, new ErrorMessage("Frequency percentage must be greater than zero and less than or equal to 100."));
}
/**
* Toggle the given error message on, or off
* @param errorId the error to toggle
* @param errorState true for on, false for off
*/
void setError(int errorId, boolean errorState){
if(this.currentErrors.containsKey(errorId)){
this.currentErrors.get(errorId).setStatus(errorState);
} else {
throw new IllegalArgumentException(String.format("The given errorId is not mapped to an ErrorMessage: %s.", errorId));
}
}
/**
* Are any user settings presently in an error state?
* @return true for yes, else false
*/
boolean anyErrors(){
return this.currentErrors.values().stream().anyMatch(errorMessage -> errorMessage.getStatus() == true);
}
/**
* Get a list of distinct string messages describing the various error states.
*/
List<String> getErrors(){
return this.currentErrors.values().stream()
.filter(errorMessage -> errorMessage.getStatus() == true)
.map(ErrorMessage::getMessage)
.collect(Collectors.toList());
}
/**
* Represents an error message for the CommonFilesSearch panel, it's
* uniqueId, and it's status.
*/
private class ErrorMessage {
private final String message;
private boolean status;
/**
* Create a message with a unique uniqueId. Default status is false (off).
* @param uniqueId unique uniqueId
* @param message message to display
*/
ErrorMessage(String message){
this.message = message;
this.status = false;
}
/**
* Update the status of this message
* @param status
*/
void setStatus(boolean status){
this.status = status;
}
/**
* Return the message
* @return
*/
String getMessage(){
return this.message;
}
/**
* Return the status (true for error status, false for no error)
* @return
*/
boolean getStatus(){
return this.status;
}
}
}