mirror of
https://github.com/overcuriousity/autopsy-flatpak.git
synced 2025-07-17 18:17:43 +00:00
revisions based on feedback
This commit is contained in:
parent
47d200d190
commit
dd5f2b4e40
@ -34,15 +34,6 @@ abstract class BaseDataSourceSummaryPanel extends JPanel {
|
||||
private final SwingWorkerSequentialExecutor executor = new SwingWorkerSequentialExecutor();
|
||||
private DataSource dataSource;
|
||||
|
||||
/**
|
||||
* The datasource currently used as the model in this panel.
|
||||
*
|
||||
* @return The datasource currently being used as the model in this panel.
|
||||
*/
|
||||
synchronized DataSource getDataSource() {
|
||||
return dataSource;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets datasource to visualize in the panel.
|
||||
*
|
||||
@ -52,6 +43,7 @@ abstract class BaseDataSourceSummaryPanel extends JPanel {
|
||||
DataSource oldDataSource = this.dataSource;
|
||||
this.dataSource = dataSource;
|
||||
if (this.dataSource != oldDataSource) {
|
||||
this.executor.cancelRunning();
|
||||
onNewDataSource(this.dataSource);
|
||||
}
|
||||
}
|
||||
|
@ -159,7 +159,7 @@ public class DataSourceSummaryUserActivityPanel extends BaseDataSourceSummaryPan
|
||||
// set results for tables to null.
|
||||
if (dataSource == null || !Case.isCaseOpen()) {
|
||||
this.dataFetchComponents.forEach((item) -> item.getResultHandler()
|
||||
.accept(DataFetchResult.getLoadedResult(null)));
|
||||
.accept(DataFetchResult.getSuccessResult(null)));
|
||||
|
||||
} else {
|
||||
// set tables to display loading screen
|
||||
|
@ -19,52 +19,52 @@
|
||||
package org.sleuthkit.autopsy.datasourcesummary.uiutils;
|
||||
|
||||
/**
|
||||
* The intermediate or end result of a loading process.
|
||||
* The result of a loading process.
|
||||
*/
|
||||
public final class DataFetchResult<R> {
|
||||
|
||||
/**
|
||||
* The state of loading in the result.
|
||||
* The type of result.
|
||||
*/
|
||||
public enum ProcessorState {
|
||||
LOADED, LOAD_ERROR
|
||||
public enum ResultType {
|
||||
SUCCESS, ERROR
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a DataLoadingResult of loaded data including the data.
|
||||
* Creates a DataFetchResult of loaded data including the data.
|
||||
*
|
||||
* @param data The data.
|
||||
*
|
||||
* @return The loaded data result.
|
||||
*/
|
||||
public static <R> DataFetchResult<R> getLoadedResult(R data) {
|
||||
return new DataFetchResult<>(ProcessorState.LOADED, data, null);
|
||||
public static <R> DataFetchResult<R> getSuccessResult(R data) {
|
||||
return new DataFetchResult<>(ResultType.SUCCESS, data, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a load error result.
|
||||
* Returns an error result.
|
||||
*
|
||||
* @param e The exception (if any) present with the error.
|
||||
*
|
||||
* @return
|
||||
* @return The error result.
|
||||
*/
|
||||
public static <R> DataFetchResult<R> getLoadErrorResult(DataFetcherException e) {
|
||||
return new DataFetchResult<>(ProcessorState.LOAD_ERROR, null, e);
|
||||
public static <R> DataFetchResult<R> getErrorResult(Throwable e) {
|
||||
return new DataFetchResult<>(ResultType.ERROR, null, e);
|
||||
}
|
||||
|
||||
private final ProcessorState state;
|
||||
private final ResultType state;
|
||||
private final R data;
|
||||
private final DataFetcherException exception;
|
||||
private final Throwable exception;
|
||||
|
||||
/**
|
||||
* Main constructor for the DataLoadingResult.
|
||||
*
|
||||
* @param state The state of the result.
|
||||
* @param data If the result is LOADED, the data related to this
|
||||
* @param data If the result is SUCCESS, the data related to this
|
||||
* result.
|
||||
* @param exception If the result is LOAD_ERROR, the related exception.
|
||||
* @param exception If the result is ERROR, the related exception.
|
||||
*/
|
||||
private DataFetchResult(ProcessorState state, R data, DataFetcherException exception) {
|
||||
private DataFetchResult(ResultType state, R data, Throwable exception) {
|
||||
this.state = state;
|
||||
this.data = data;
|
||||
this.exception = exception;
|
||||
@ -73,21 +73,21 @@ public final class DataFetchResult<R> {
|
||||
/**
|
||||
* @return The current loading state.
|
||||
*/
|
||||
public ProcessorState getState() {
|
||||
public ResultType getResultType() {
|
||||
return state;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The data if the state is LOADED.
|
||||
* @return The data if the state is SUCCESS.
|
||||
*/
|
||||
public R getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The exception if the state is LOAD_ERROR.
|
||||
* @return The exception if the state is ERROR.
|
||||
*/
|
||||
public DataFetcherException getException() {
|
||||
public Throwable getException() {
|
||||
return exception;
|
||||
}
|
||||
}
|
||||
|
@ -25,39 +25,40 @@ import javax.swing.SwingWorker;
|
||||
import org.sleuthkit.autopsy.coreutils.Logger;
|
||||
|
||||
/**
|
||||
* A Swing worker that accepts an argument of a data processor and a result
|
||||
* handler.
|
||||
* A Swing worker that accepts an argument of a data fetcher and a result
|
||||
* handler. If the data fetcher throws an InterruptedException, it is treated as
|
||||
* a cancellation and not passed to the result handler.
|
||||
*/
|
||||
public class DataFetchWorker<A, R> extends SwingWorker<R, Void> {
|
||||
|
||||
/**
|
||||
* Holds the functions necessary for a DataFetchWorker. Includes the
|
||||
* processor and result handler. The args are not included since they are
|
||||
* likely dynamic.
|
||||
* Holds the functions necessary for a DataFetchWorker. Includes the fetcher
|
||||
* and result handler. The args are not included since they are likely
|
||||
* dynamic.
|
||||
*/
|
||||
public static class DataFetchComponents<A1, R1> {
|
||||
|
||||
private final DataFetcher<A1, R1> processor;
|
||||
private final DataFetcher<A1, R1> fetcher;
|
||||
private final Consumer<DataFetchResult<R1>> resultHandler;
|
||||
|
||||
/**
|
||||
* Main constructor.
|
||||
*
|
||||
* @param processor The processor to be used as an argument for the
|
||||
* @param fetcher The fetcher to be used as an argument for the
|
||||
* DataFetchWorker.
|
||||
* @param resultHandler The result handler to be used as an argument for
|
||||
* the DataFetchWorker.
|
||||
*/
|
||||
public DataFetchComponents(DataFetcher<A1, R1> processor, Consumer<DataFetchResult<R1>> resultHandler) {
|
||||
this.processor = processor;
|
||||
public DataFetchComponents(DataFetcher<A1, R1> fetcher, Consumer<DataFetchResult<R1>> resultHandler) {
|
||||
this.fetcher = fetcher;
|
||||
this.resultHandler = resultHandler;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The function that processes or fetches the data.
|
||||
* @return The function that fetches the data.
|
||||
*/
|
||||
public DataFetcher<A1, R1> getProcessor() {
|
||||
return processor;
|
||||
public DataFetcher<A1, R1> getFetcher() {
|
||||
return fetcher;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -83,14 +84,16 @@ public class DataFetchWorker<A, R> extends SwingWorker<R, Void> {
|
||||
* @param args The argument to be provided to the data processor.
|
||||
*/
|
||||
public DataFetchWorker(DataFetchComponents<A, R> components, A args) {
|
||||
this(components.getProcessor(), components.getResultHandler(), args);
|
||||
this(components.getFetcher(), components.getResultHandler(), args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Main constructor for this swing worker.
|
||||
*
|
||||
* @param processor The function that will do the processing of the data
|
||||
* provided the given args.
|
||||
* @param processor The function that will do the fetching of the data
|
||||
* provided the given args. InterruptedException's are
|
||||
* treated as cancellations and are not passed to the
|
||||
* result handler.
|
||||
* @param resultHandler The ui function that will handle the result of the
|
||||
* data processing.
|
||||
* @param args The args provided to the data processor.
|
||||
@ -133,9 +136,8 @@ public class DataFetchWorker<A, R> extends SwingWorker<R, Void> {
|
||||
// otherwise, there is an error to log
|
||||
logger.log(Level.WARNING, "There was an error while fetching results.", ex);
|
||||
|
||||
if (inner instanceof DataFetcherException) {
|
||||
resultHandler.accept(DataFetchResult.getLoadErrorResult((DataFetcherException) inner));
|
||||
}
|
||||
// and pass the result to the client
|
||||
resultHandler.accept(DataFetchResult.getErrorResult(inner));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -145,6 +147,6 @@ public class DataFetchWorker<A, R> extends SwingWorker<R, Void> {
|
||||
}
|
||||
|
||||
// if the data is loaded, send the data to the consumer.
|
||||
resultHandler.accept(DataFetchResult.getLoadedResult(result));
|
||||
resultHandler.accept(DataFetchResult.getSuccessResult(result));
|
||||
}
|
||||
}
|
||||
|
@ -21,25 +21,23 @@ package org.sleuthkit.autopsy.datasourcesummary.uiutils;
|
||||
/**
|
||||
* A function that accepts input of type I and outputs type O. This function is
|
||||
* meant to be utilized with DataFetchWorker and can therefore, throw an
|
||||
* interrupted exception if the processing is cancelled or a
|
||||
* DataProcessorException in the event that the processing encountered an error.
|
||||
* interrupted exception if the processing is cancelled or an Exception of on
|
||||
* another type in the event that the fetching encountered an error.
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface DataFetcher<I, O> {
|
||||
|
||||
/**
|
||||
* A function that accepts an input argument and outputs a result. Since it
|
||||
* is meant to be used with the DataFetchWorker, it throws an interrupted
|
||||
* exception if the thread has been interrupted. It throws a data processing
|
||||
* exception if there is an error during processing.
|
||||
* is meant to be used with the DataFetchWorker, it may throw an interrupted
|
||||
* exception if the thread has been interrupted. It throws another type of
|
||||
* exception if there is an error during fetching.
|
||||
*
|
||||
* @param input The input argument.
|
||||
*
|
||||
* @return The output result.
|
||||
*
|
||||
* @throws InterruptedException Thrown if the operation is cancelled.
|
||||
* @throws DataFetcherException Thrown if there is an issue processing the
|
||||
* request.
|
||||
* @throws Exception
|
||||
*/
|
||||
O runQuery(I input) throws InterruptedException, DataFetcherException;
|
||||
O runQuery(I input) throws Exception;
|
||||
}
|
||||
|
@ -1,47 +0,0 @@
|
||||
/*
|
||||
* Autopsy Forensic Browser
|
||||
*
|
||||
* Copyright 2020 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.datasourcesummary.uiutils;
|
||||
|
||||
/**
|
||||
* An Exception that is thrown when there is an issue processing data in a
|
||||
* DataProcessor.
|
||||
*/
|
||||
public class DataFetcherException extends Exception {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* Main constructor.
|
||||
*
|
||||
* @param string The error message.
|
||||
*/
|
||||
public DataFetcherException(String string) {
|
||||
super(string);
|
||||
}
|
||||
|
||||
/**
|
||||
* Main constructor.
|
||||
*
|
||||
* @param string The error message.
|
||||
* @param thrwbl The inner exception.
|
||||
*/
|
||||
public DataFetcherException(String string, Throwable thrwbl) {
|
||||
super(string, thrwbl);
|
||||
}
|
||||
}
|
@ -90,13 +90,6 @@ public class JTablePanel<T> extends JPanel {
|
||||
this.visible = visible;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The child JLabel component.
|
||||
*/
|
||||
JLabel getLabel() {
|
||||
return label;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the message to be displayed in the child jlabel.
|
||||
*
|
||||
@ -391,15 +384,15 @@ public class JTablePanel<T> extends JPanel {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (result.getState()) {
|
||||
case LOADED:
|
||||
switch (result.getResultType()) {
|
||||
case SUCCESS:
|
||||
if (result.getData() == null || result.getData().isEmpty()) {
|
||||
showMessage(noResultsMessage);
|
||||
} else {
|
||||
showResults(result.getData());
|
||||
}
|
||||
break;
|
||||
case LOAD_ERROR:
|
||||
case ERROR:
|
||||
// if there is an error, log accordingly, set result list to
|
||||
// empty and display error message
|
||||
logger.log(Level.WARNING, "An exception was caused while results were loaded.", result.getException());
|
||||
|
Loading…
x
Reference in New Issue
Block a user