Skip to content

Commit

Permalink
Count images not files for import progress display
Browse files Browse the repository at this point in the history
  • Loading branch information
dominikl committed Jul 15, 2022
1 parent d8d85ad commit 57f5eec
Showing 1 changed file with 17 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -468,8 +471,6 @@ void addComponent(ImportDialog chooser)

/**
* Adds the chooser to the tab.
*
* @param chooser The component to add.
*/
void addMDComponent(MetaDataDialog mde)
{
Expand Down Expand Up @@ -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 {
Expand All @@ -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()
{
Expand Down

0 comments on commit 57f5eec

Please sign in to comment.