From 73b8436076b0f35ee79e654b9af78286c132cc5f Mon Sep 17 00:00:00 2001 From: Dominik Lindner Date: Fri, 15 Jul 2022 14:05:38 +0100 Subject: [PATCH] Count images not files for import progress display --- .../agents/fsimporter/view/ImporterUI.java | 38 +++++++++---------- 1 file changed, 17 insertions(+), 21 deletions(-) diff --git a/src/main/java/org/openmicroscopy/shoola/agents/fsimporter/view/ImporterUI.java b/src/main/java/org/openmicroscopy/shoola/agents/fsimporter/view/ImporterUI.java index 5f1ec2c16d..a2c12b3043 100644 --- a/src/main/java/org/openmicroscopy/shoola/agents/fsimporter/view/ImporterUI.java +++ b/src/main/java/org/openmicroscopy/shoola/agents/fsimporter/view/ImporterUI.java @@ -2,7 +2,7 @@ * org.openmicroscopy.shoola.agents.fsimporter.view.ImporterUI * *------------------------------------------------------------------------------ - * Copyright (C) 2006-2018 University of Dundee. All rights reserved. + * Copyright (C) 2006-2022 University of Dundee. All rights reserved. * * * This program is free software; you can redistribute it and/or modify @@ -71,6 +71,9 @@ //Third-party libraries import info.clearthought.layout.TableLayout; +import ome.formats.importer.ImportCandidates; +import ome.formats.importer.ImportConfig; +import ome.formats.importer.OMEROWrapper; import org.apache.commons.collections4.CollectionUtils; import org.jdesktop.swingx.JXLabel; import org.jdesktop.swingx.JXPanel; @@ -468,8 +471,6 @@ void addComponent(ImportDialog chooser) /** * Adds the chooser to the tab. - * - * @param chooser The component to add. */ void addMDComponent(MetaDataDialog mde) { @@ -539,13 +540,13 @@ ImporterUIElement addImporterElement(ImportableObject object) if (object == null) return null; - int maxFiles = (Integer) ImporterAgent.getRegistry().lookup( + int maxImages = (Integer) ImporterAgent.getRegistry().lookup( "/options/DetailedImportFileLimit"); int n = tabs.getComponentCount(); String title = "Import #"+total; ImporterUIElement element = null; - if (fileCount(object) > maxFiles) { + if (imageCount(object) > maxImages) { element = new ImporterUIElementLight(controller, model, this, uiElementID, n, title, object); } else { @@ -563,28 +564,23 @@ ImporterUIElement addImporterElement(ImportableObject object) return element; } - private int fileCount(ImportableObject obj) { + /** + * Determines how many individual images an ImportableObject has. + * @param obj The ImportableObject + * @return The number of images + */ + private int imageCount(ImportableObject obj) { int count = 0; for (ImportableFile f : obj.getFiles()) { - count += fileCount(f.getOriginalFile().getTrueFile()); + OMEROWrapper reader = new OMEROWrapper(new ImportConfig()); + File file = f.getFile().getFileToImport(); + String[] paths = new String[1]; + paths[0] = file.getAbsolutePath(); + count += (new ImportCandidates(obj.getDepth(), reader, paths, null)).size(); } return count; } - private int fileCount(File file) { - if (file == null) - return 0; - - if (file.isDirectory()) { - int count = 0; - for (File f : file.listFiles()) { - count += fileCount(f); - } - return count; - } - return 1; - } - /** Resets the import.*/ void reset() {