mirror of
https://github.com/overcuriousity/autopsy-flatpak.git
synced 2025-07-13 00:16:16 +00:00
inline method, remove potential redundant check of too many files
This commit is contained in:
parent
96e7c4db6a
commit
282fb49e82
@ -24,6 +24,7 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
import java.util.function.Consumer;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import javafx.application.Platform;
|
import javafx.application.Platform;
|
||||||
@ -37,6 +38,7 @@ import javafx.scene.control.Alert;
|
|||||||
import javafx.scene.control.ButtonType;
|
import javafx.scene.control.ButtonType;
|
||||||
import javafx.scene.control.ChoiceDialog;
|
import javafx.scene.control.ChoiceDialog;
|
||||||
import javafx.scene.control.ComboBox;
|
import javafx.scene.control.ComboBox;
|
||||||
|
import javafx.scene.control.ListView;
|
||||||
import javafx.scene.control.ProgressIndicator;
|
import javafx.scene.control.ProgressIndicator;
|
||||||
import javafx.scene.control.SplitPane;
|
import javafx.scene.control.SplitPane;
|
||||||
import javafx.scene.control.TabPane;
|
import javafx.scene.control.TabPane;
|
||||||
@ -53,6 +55,7 @@ import javafx.stage.Modality;
|
|||||||
import javax.swing.SwingUtilities;
|
import javax.swing.SwingUtilities;
|
||||||
import static org.apache.commons.collections4.CollectionUtils.isNotEmpty;
|
import static org.apache.commons.collections4.CollectionUtils.isNotEmpty;
|
||||||
import static org.apache.commons.lang3.ObjectUtils.notEqual;
|
import static org.apache.commons.lang3.ObjectUtils.notEqual;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.openide.explorer.ExplorerManager;
|
import org.openide.explorer.ExplorerManager;
|
||||||
import org.openide.explorer.ExplorerUtils;
|
import org.openide.explorer.ExplorerUtils;
|
||||||
import org.openide.util.Exceptions;
|
import org.openide.util.Exceptions;
|
||||||
@ -125,7 +128,6 @@ public final class ImageGalleryTopComponent extends TopComponent implements Expl
|
|||||||
|
|
||||||
private Node infoOverlay;
|
private Node infoOverlay;
|
||||||
private final Region infoOverLayBackground = new TranslucentRegion();
|
private final Region infoOverLayBackground = new TranslucentRegion();
|
||||||
private final Map<DataSource, Boolean> dataSourcesViewble = new HashMap<>();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns whether the ImageGallery window is open or not.
|
* Returns whether the ImageGallery window is open or not.
|
||||||
@ -151,10 +153,11 @@ public final class ImageGalleryTopComponent extends TopComponent implements Expl
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* NOTE: This usually gets called on the EDT
|
* Open the ImageGalleryTopComponent.
|
||||||
*
|
*
|
||||||
*
|
* @throws NoCurrentCaseException If there is no case open.
|
||||||
* @throws NoCurrentCaseException
|
* @throws TskCoreException If there is a problem accessing the case
|
||||||
|
* db.
|
||||||
*/
|
*/
|
||||||
@ThreadConfined(type = ThreadConfined.ThreadType.AWT)
|
@ThreadConfined(type = ThreadConfined.ThreadType.AWT)
|
||||||
@Messages({
|
@Messages({
|
||||||
@ -164,7 +167,7 @@ public final class ImageGalleryTopComponent extends TopComponent implements Expl
|
|||||||
"ImageGalleryTopComponent.chooseDataSourceDialog.titleText=Image Gallery",})
|
"ImageGalleryTopComponent.chooseDataSourceDialog.titleText=Image Gallery",})
|
||||||
public static void openTopComponent() throws NoCurrentCaseException, TskCoreException {
|
public static void openTopComponent() throws NoCurrentCaseException, TskCoreException {
|
||||||
|
|
||||||
// This creates the top component and adds the UI widgets if it has not yet been opened
|
// This creates the top component and adds the UI widgets (via the constructor) if it has not yet been opened
|
||||||
final TopComponent topComponent = WindowManager.getDefault().findTopComponent(PREFERRED_ID);
|
final TopComponent topComponent = WindowManager.getDefault().findTopComponent(PREFERRED_ID);
|
||||||
if (topComponent == null) {
|
if (topComponent == null) {
|
||||||
return;
|
return;
|
||||||
@ -182,16 +185,15 @@ public final class ImageGalleryTopComponent extends TopComponent implements Expl
|
|||||||
}
|
}
|
||||||
|
|
||||||
ImageGalleryController controller = ImageGalleryModule.getController();
|
ImageGalleryController controller = ImageGalleryModule.getController();
|
||||||
|
|
||||||
ImageGalleryTopComponent igTopComponent = (ImageGalleryTopComponent) topComponent;
|
ImageGalleryTopComponent igTopComponent = (ImageGalleryTopComponent) topComponent;
|
||||||
igTopComponent.setController(controller);
|
igTopComponent.setController(controller);
|
||||||
|
|
||||||
|
//gather information about datasources and the groupmanager in a bg thread.
|
||||||
new Thread(new Task<Void>() {
|
new Thread(new Task<Void>() {
|
||||||
@Override
|
@Override
|
||||||
protected Void call() throws Exception {
|
protected Void call() throws Exception {
|
||||||
|
Map<DataSource, Boolean> dataSourcesTooManyFiles = new HashMap<>();
|
||||||
List<DataSource> dataSources = new ArrayList<>();
|
List<DataSource> dataSources = controller.getSleuthKitCase().getDataSources();
|
||||||
dataSources.addAll(controller.getSleuthKitCase().getDataSources());
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If there is only one datasource or the grouping is already
|
* If there is only one datasource or the grouping is already
|
||||||
@ -200,22 +202,59 @@ public final class ImageGalleryTopComponent extends TopComponent implements Expl
|
|||||||
*/
|
*/
|
||||||
if (dataSources.size() <= 1
|
if (dataSources.size() <= 1
|
||||||
|| controller.getGroupManager().getGroupBy() != DrawableAttribute.PATH) {
|
|| controller.getGroupManager().getGroupBy() != DrawableAttribute.PATH) {
|
||||||
|
// null represents all datasources, which is only one in this case.
|
||||||
igTopComponent.showDataSource(null);
|
dataSourcesTooManyFiles.put(null, controller.hasTooManyFiles(null));
|
||||||
|
igTopComponent.showDataSource(null, dataSourcesTooManyFiles);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Else there is more than one data source and the grouping is
|
||||||
|
* PATH (the default): open a dialog prompting the user to pick
|
||||||
|
* a datasource.
|
||||||
|
*/
|
||||||
dataSources.add(0, null); //null represents all datasources
|
dataSources.add(0, null); //null represents all datasources
|
||||||
igTopComponent.promptForDataSource(dataSources);
|
//first, while still on background thread, gather viewability info for the datasources.
|
||||||
|
for (DataSource dataSource : dataSources) {
|
||||||
|
dataSourcesTooManyFiles.put(dataSource, controller.hasTooManyFiles(dataSource));
|
||||||
|
}
|
||||||
|
|
||||||
|
Platform.runLater(() -> {
|
||||||
|
//configure the dialog
|
||||||
|
List<Optional<DataSource>> dataSourceOptionals = dataSources.stream().map(Optional::ofNullable).collect(Collectors.toList());
|
||||||
|
ChoiceDialog<Optional<DataSource>> datasourceDialog = new ChoiceDialog<>(null, dataSourceOptionals);
|
||||||
|
datasourceDialog.setTitle(Bundle.ImageGalleryTopComponent_chooseDataSourceDialog_titleText());
|
||||||
|
datasourceDialog.setHeaderText(Bundle.ImageGalleryTopComponent_chooseDataSourceDialog_headerText());
|
||||||
|
datasourceDialog.setContentText(Bundle.ImageGalleryTopComponent_chooseDataSourceDialog_contentText());
|
||||||
|
datasourceDialog.initModality(Modality.APPLICATION_MODAL);
|
||||||
|
GuiUtils.setDialogIcons(datasourceDialog);
|
||||||
|
//get the combobox by its css class... this is hacky but should be safe.
|
||||||
|
@SuppressWarnings(value = "unchecked")
|
||||||
|
ComboBox<Optional<DataSource>> comboBox = (ComboBox<Optional<DataSource>>) datasourceDialog.getDialogPane().lookup(".combo-box");
|
||||||
|
//set custom cell renderer
|
||||||
|
comboBox.setCellFactory((ListView<Optional<DataSource>> param) -> new DataSourceCell(dataSourcesTooManyFiles));
|
||||||
|
comboBox.setButtonCell(new DataSourceCell(dataSourcesTooManyFiles));
|
||||||
|
|
||||||
|
DataSource dataSource = datasourceDialog.showAndWait().orElse(Optional.empty()).orElse(null);
|
||||||
|
try {
|
||||||
|
|
||||||
|
igTopComponent.showDataSource(dataSource, dataSourcesTooManyFiles);
|
||||||
|
} catch (TskCoreException ex) {
|
||||||
|
if (dataSource != null) {
|
||||||
|
logger.log(Level.SEVERE, "Error showing data source " + dataSource.getName() + ":" + dataSource.getId() + " in Image Gallery", ex);
|
||||||
|
} else {
|
||||||
|
logger.log(Level.SEVERE, "Error showing all data sources in Image Gallery.", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
}).start();
|
}).start();
|
||||||
}
|
}
|
||||||
|
|
||||||
synchronized private void showDataSource(DataSource datasource) throws TskCoreException {
|
synchronized private void showDataSource(DataSource datasource, Map<DataSource, Boolean> dataSourcesTooManyFiles) throws TskCoreException {
|
||||||
if (controller.hasTooManyFiles(datasource)) {
|
if (dataSourcesTooManyFiles.get(datasource)) {
|
||||||
Platform.runLater(ImageGalleryTopComponent::showTooManyFiles);
|
Platform.runLater(ImageGalleryTopComponent::showTooManyFiles);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -227,43 +266,6 @@ public final class ImageGalleryTopComponent extends TopComponent implements Expl
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
synchronized private void promptForDataSource(List<DataSource> dataSources) throws TskCoreException {
|
|
||||||
|
|
||||||
dataSourcesViewble.clear();
|
|
||||||
for (DataSource dataSource : dataSources) {
|
|
||||||
dataSourcesViewble.put(dataSource, controller.hasTooManyFiles(dataSource));
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
* If there is more than one data source and the grouping is PATH (the
|
|
||||||
* default), open a dialog prompting the user to pick a datasource.
|
|
||||||
*/
|
|
||||||
Platform.runLater(() -> {
|
|
||||||
List<Optional<DataSource>> dataSourceOptionals = dataSources.stream().map(Optional::ofNullable).collect(Collectors.toList());
|
|
||||||
//configure the dialog
|
|
||||||
ChoiceDialog<Optional<DataSource>> datasourceDialog = new ChoiceDialog<>(null, dataSourceOptionals);
|
|
||||||
datasourceDialog.setTitle(Bundle.ImageGalleryTopComponent_chooseDataSourceDialog_titleText());
|
|
||||||
datasourceDialog.setHeaderText(Bundle.ImageGalleryTopComponent_chooseDataSourceDialog_headerText());
|
|
||||||
datasourceDialog.setContentText(Bundle.ImageGalleryTopComponent_chooseDataSourceDialog_contentText());
|
|
||||||
datasourceDialog.initModality(Modality.APPLICATION_MODAL);
|
|
||||||
GuiUtils.setDialogIcons(datasourceDialog);
|
|
||||||
//get the combobox by its css class... this is hacky but should be safe.
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
ComboBox<Optional<DataSource>> comboBox = (ComboBox<Optional<DataSource>>) datasourceDialog.getDialogPane().lookup(".combo-box");
|
|
||||||
//set custom cell renderer
|
|
||||||
comboBox.setCellFactory(param -> new DataSourceCell(dataSourcesViewble));
|
|
||||||
comboBox.setButtonCell(new DataSourceCell(dataSourcesViewble));
|
|
||||||
|
|
||||||
Optional<DataSource> dataSource = datasourceDialog.showAndWait().orElse(Optional.empty());
|
|
||||||
|
|
||||||
try {
|
|
||||||
showDataSource(dataSource.orElse(null));
|
|
||||||
} catch (TskCoreException ex) {
|
|
||||||
logger.log(Level.SEVERE, "Error showing data source " + Objects.toString(dataSource), ex);
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@NbBundle.Messages({"ImageGallery.dialogTitle=Image Gallery",
|
@NbBundle.Messages({"ImageGallery.dialogTitle=Image Gallery",
|
||||||
"ImageGallery.showTooManyFiles.contentText=There are too many files in the selected datasource(s) to ensure reasonable performance.",
|
"ImageGallery.showTooManyFiles.contentText=There are too many files in the selected datasource(s) to ensure reasonable performance.",
|
||||||
"ImageGallery.showTooManyFiles.headerText="})
|
"ImageGallery.showTooManyFiles.headerText="})
|
||||||
|
@ -28,10 +28,10 @@ import org.sleuthkit.datamodel.DataSource;
|
|||||||
*/
|
*/
|
||||||
public class DataSourceCell extends ListCell<Optional<DataSource>> {
|
public class DataSourceCell extends ListCell<Optional<DataSource>> {
|
||||||
|
|
||||||
private final Map<DataSource, Boolean> dataSourcesViewable;
|
private final Map<DataSource, Boolean> dataSourcesTooManyFiles;
|
||||||
|
|
||||||
public DataSourceCell(Map<DataSource, Boolean> dataSourcesViewable) {
|
public DataSourceCell(Map<DataSource, Boolean> dataSourcesViewable) {
|
||||||
this.dataSourcesViewable = dataSourcesViewable;
|
this.dataSourcesTooManyFiles = dataSourcesViewable;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -42,7 +42,7 @@ public class DataSourceCell extends ListCell<Optional<DataSource>> {
|
|||||||
} else {
|
} else {
|
||||||
DataSource dataSource = item.orElse(null);
|
DataSource dataSource = item.orElse(null);
|
||||||
String text = (dataSource == null) ? "All" : dataSource.getName() + " (Id: " + dataSource.getId() + ")";
|
String text = (dataSource == null) ? "All" : dataSource.getName() + " (Id: " + dataSource.getId() + ")";
|
||||||
Boolean tooManyFilesInDataSource = dataSourcesViewable.getOrDefault(dataSource, false);
|
Boolean tooManyFilesInDataSource = dataSourcesTooManyFiles.getOrDefault(dataSource, false);
|
||||||
if (tooManyFilesInDataSource) {
|
if (tooManyFilesInDataSource) {
|
||||||
text += " - Too many files";
|
text += " - Too many files";
|
||||||
setStyle("-fx-opacity : .5");
|
setStyle("-fx-opacity : .5");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user