Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add depth option to importer and include ZarrReader #310

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ version = "5.7.3-SNAPSHOT"
repositories {
mavenLocal()
mavenCentral()
maven { url 'https://nexus.senbox.net/nexus/content/groups/public/' }
}

java {
Expand Down Expand Up @@ -47,6 +48,9 @@ dependencies {
// Conflicts with `net.java.dev.jna`
exclude group: "com.sun.jna", module: "jna"
}
// Add zarr reader
implementation("ome:OMEZarrReader:0.3.0")
implementation("com.bc.zarr:jzarr:0.3.4")
}

test {
Expand Down
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pluginManagement {
mavenLocal()
mavenCentral()
maven { url 'https://artifacts.openmicroscopy.org/artifactory/maven/' }
maven { url 'https://nexus.senbox.net/nexus/content/groups/public/' }
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
*------------------------------------------------------------------------------
* Copyright (C) 2006-2017 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 @@ -160,18 +160,6 @@ public static ExperimenterData getUserDetails()
LookupNames.CURRENT_USER_DETAILS);
}

/**
* Returns how deep to scan when a folder is selected.
*
* @return See above.
*/
public static int getScanningDepth()
{
Integer value = (Integer) registry.lookup("/options/ScanningDepth");
if (value == null || value.intValue() < 0) return 1;
return value.intValue();
}

/**
* Returns the available user groups.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
*------------------------------------------------------------------------------
* Copyright (C) 2006-2021 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 @@ -214,6 +214,9 @@ public class ImportDialog extends ClosableTabbedPaneComponent
/** Text for metadata pane */
private static final String TEXT_METADATA_DEFAULTS = "Metadata Defaults";

/** Text for metadata pane */
private static final String TEXT_ADVANCED = "Advanced options";

/** Text for naming panel */
private static final String TEXT_DIRECTORIES_BEFORE_FILE =
"Directories before File";
Expand Down Expand Up @@ -328,6 +331,9 @@ public class ImportDialog extends ClosableTabbedPaneComponent
/** Text field indicating how many folders to include. */
private NumericalTextField numberOfFolders;

/** Text field indicating Bioformats search depth */
private NumericalTextField depth;

/** Button to bring up the tags wizard. */
private JButton tagButton;

Expand Down Expand Up @@ -671,6 +677,13 @@ public void actionPerformed(ActionEvent e) {
tagsMap = new LinkedHashMap<JButton, TagAnnotationData>();
mapAnnotation=new LinkedHashMap<String,List<MapAnnotationData>>();

depth = new NumericalTextField();
depth.setMinimum(1);
depth.setText(System.getProperty("omero.import.depth", "50"));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That property should be put in the config or retrieve from the server if available.

depth.setColumns(4);
depth.setToolTipText("Maximum depth Bioformats uses for looking for importable files");
depth.addPropertyChangeListener(this);

IconManager icons = IconManager.getInstance();

refreshFilesButton = new JButton(TEXT_REFRESH_FILES);
Expand Down Expand Up @@ -970,6 +983,15 @@ private JPanel buildPixelSizeComponent() {
return UIUtilities.buildComponentPanel(p);
}

private JPanel buildAdvancedComponent() {
JPanel p = new JPanel();
JLabel l = new JLabel();
l.setText("Depth: ");
p.add(l);
p.add(depth);
return UIUtilities.buildComponentPanel(p);
}

/**
* Builds and lays out the components displaying the naming options.
*
Expand Down Expand Up @@ -1068,9 +1090,14 @@ private JComponent buildOptionsPane() {
c.gridy = 2;
options.add(buildPane(TEXT_METADATA_DEFAULTS, buildPixelSizeComponent()), c);

// Constraints for meta data component
c.gridx = 0;
c.gridy = 3;
options.add(buildPane(TEXT_ADVANCED, buildAdvancedComponent()), c);

// Fills in bottom space of GridBagLayout
c.gridx = 0;
c.gridy = 3;
c.gridy = 4;
c.weighty = 1;
options.add(new JLabel(" "), c);

Expand Down Expand Up @@ -1219,7 +1246,6 @@ public void importFiles() {
object.setMapAnnotation(mapAnnotation);
}

object.setScanningDepth(ImporterAgent.getScanningDepth());
Boolean loadThumbnails = (Boolean) ImporterAgent.getRegistry()
.lookup(LOAD_THUMBNAIL);
if (loadThumbnails != null)
Expand All @@ -1241,6 +1267,8 @@ public void importFiles() {
object.setTags(l);
}

object.setDepth((Integer) depth.getValueAsNumber());

if (partialName.isSelected()) {
Integer number = (Integer) numberOfFolders.getValueAsNumber();
if (number != null && number >= 0)
Expand Down
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
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
*------------------------------------------------------------------------------
* Copyright (C) 2006-2021 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 @@ -5874,6 +5874,7 @@ Object importImageFile(SecurityContext ctx, ImportableObject object,
* @param ctx The security context.
* @param object Host information about the file to import.
* @param file The file to import.
* @param status The status tracking object.
* @return See above.
* @throws ImportException If an error occurred while importing.
*/
Expand All @@ -5895,7 +5896,7 @@ ImportCandidates getImportCandidates(SecurityContext ctx,
reader = new OMEROWrapper(config);
String[] paths = new String[1];
paths[0] = file.getAbsolutePath();
ImportCandidates icans = new ImportCandidates(reader, paths, status);
ImportCandidates icans = new ImportCandidates(object.getDepth(), reader, paths, status);

for(ImportContainer ic : icans.getContainers()) {
if(object.isOverrideName()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
*------------------------------------------------------------------------------
* 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 @@ -212,14 +212,6 @@ private int getNumberOfRenderingEngines(SecurityContext ctx, long pixelsID)

/**
* Imports the specified candidates.
*
* @param ctx The security context.
* @param status The original status.
* @param object The object hosting information about the import.
* @param list The list of annotations.
* @param userID The identifier of the user.
* @param hcs Value returns by the import containers.
* @param userName The login name of the user to import for.
*/
private Object importCandidates(SecurityContext ctx,
Map<File, Status> files, Status status,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
*------------------------------------------------------------------------------
* 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 @@ -190,9 +190,6 @@ public static boolean isArbitraryFile(File f)
/** The depth when the name is overridden. */
private int depthForName;

/** The depth used when scanning a folder. */
private int scanningDepth;

/**
* Flag indicating to override the name set by B-F when importing the data.
*/
Expand Down Expand Up @@ -225,6 +222,9 @@ public static boolean isArbitraryFile(File f)
/** Map of skip options mapping to ImportConfig functions */
private Map<String, Object> skipChoices;

/** The depth Bioformats uses to find the importable files */
private int depth = Integer.valueOf(System.getProperty("omero.import.depth", "4"));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same


/**
* Returns the object corresponding to the passed file.
*
Expand Down Expand Up @@ -355,24 +355,7 @@ public void setMapAnnotation(Map<String,List<MapAnnotationData>> map)
{
this.mapAnnots=getCloneOfMap(map);
}


/**
* Sets the depth used scanning a folder.
*
* @param scanningDepth The value to set.
*/
public void setScanningDepth(int scanningDepth)
{
this.scanningDepth = scanningDepth;
}

/**
* Returns the depth used scanning a folder.
*
* @return See above.
*/
public int getScanningDepth() { return scanningDepth; }

/**
* Sets the depth used when the name is overridden.
Expand Down Expand Up @@ -764,4 +747,19 @@ public boolean skipThumbnails() {
return option != null && !option;
}

/**
* Get the depth Bioformats uses to find the importable files
* @return See above
*/
public int getDepth() {
return depth;
}

/**
* Set the depth Bioformats uses to find the importable files
* @param depth The depth
*/
public void setDepth(int depth) {
this.depth = depth;
}
}