saalfeldlab / n5-ij

ImageJ convenience layer for N5
BSD 2-Clause "Simplified" License
15 stars 12 forks source link

DatasetSelectorDialog starting API #95

Open xulman opened 4 days ago

xulman commented 4 days ago

Minimal opening example

final String zarrRootStrPath = "/temp/Zurich.hackathon.testData/maybe_top_level.zarr";
DatasetSelectorDialog selectionDialog = new DatasetSelectorDialog(
                  new N5Importer.N5ViewerReaderFun(),
                  new N5Importer.N5BasePathFun(),
                  zarrRootStrPath,
                  new N5MetadataParser[]{new OmeNgffMetadataParser()},
                  PARSERS);

//just an empty function, otherwise NPE is thrown
selectionDialog.setContainerPathUpdateCallback(s -> {});

selectionDialog.run(ds -> {
     System.out.println("just some data is selected...");
});

//makes the dialog to update (and thus display) its content
selectionDialog.detectDatasets();

When working with the pointed at file/path, the dialog is calling its containerPathUpdateCallback, which is normally initiated as null.

So, one has to provide there simply anything... to avoid having it getting NPE. And the issue is that it is not obvious and perhaps the empty callback could be a better initial setting than just null. What do you think? @bogovicj

xulman commented 4 days ago

I have of course forgotten to suggest what to do with it:

replace current code with

private Consumer<String> containerPathUpdateCallback = s -> {};
bogovicj commented 4 days ago

@xulman I agree, if you're interested in doing this, I would happily accept a PR, otherwise I'll get to it eventually.

xulman commented 3 days ago

actually, the PR #96 is solving this issue (by getting access to the original code base rather than trying to construct and use the dialog itself directly)