Skip to content

Commit be870d1

Browse files
stefanhahmannclaude
andcommitted
Let "Open Current OME-Zarr Image in BigDataViewer" also open several OME-Zarr images at once.
The command previously opened only the active OME-Zarr. With more than one open, in ImageJ or BDV, it now asks which to show, via OmeZarrImagesChooser, and shows them in one new BDV window, like BigDataViewer's own "Open Current Image" does. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
1 parent a430f43 commit be870d1

2 files changed

Lines changed: 61 additions & 6 deletions

File tree

‎ome-zarr-fiji-ui/src/main/java/ome/zarr/fijiui/plugin/command/tools/OpenInBDVCommand.java‎

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
package ome.zarr.fijiui.plugin.command.tools;
3030

3131
import java.lang.invoke.MethodHandles;
32+
import java.util.Collections;
33+
import java.util.List;
3234

3335
import org.scijava.command.Command;
3436
import org.scijava.plugin.Parameter;
@@ -40,10 +42,11 @@
4042

4143
import bdv.util.BdvHandle;
4244
import ome.zarr.fiji.Pyramidal;
43-
import ome.zarr.fiji.PyramidalBdv;
4445
import ome.zarr.fiji.plugins.PyramidalService;
4546
import ome.zarr.fiji.util.BdvUtils;
47+
import ome.zarr.fiji.util.OmeZarrImagesChooser;
4648
import ome.zarr.fijiui.open.OmeZarrDropListener;
49+
import ome.zarr.imglib2.PyramidContents;
4750

4851
@Plugin( type = Command.class, menuPath = "Plugins > OME-Zarr > Open Current OME-Zarr Image in BigDataViewer" )
4952
public class OpenInBDVCommand implements Command
@@ -72,8 +75,23 @@ public void run()
7275
logger.warn( message );
7376
return;
7477
}
75-
final PyramidalBdv< ? > pyramidalBdv = new PyramidalBdv<>( this.pyramidal.getContext(), this.pyramidal.getPyramidContents() );
76-
final BdvHandle bdvHandle = BdvUtils.show( pyramidalBdv, pyramidalService );
77-
OmeZarrDropListener.install( bdvHandle, this.pyramidal.getContext() );
78+
final BdvHandle bdvHandle = BdvUtils.showInOneWindow( selectContents(), this.pyramidal.getContext(), pyramidalService );
79+
if ( bdvHandle != null )
80+
OmeZarrDropListener.install( bdvHandle, this.pyramidal.getContext() );
81+
}
82+
83+
/**
84+
* The OME-Zarrs to show in one BDV window: just the active one, unless more than one
85+
* is open, in ImageJ or BigDataViewer. Each is listed once, however many windows show it.
86+
*/
87+
private List< PyramidContents< ? > > selectContents()
88+
{
89+
final List< PyramidContents< ? > > open = pyramidalService.getPyramidContents();
90+
if ( open.isEmpty() )
91+
return Collections.emptyList();
92+
// for one OME-Zarr, this.pyramidal's contents should be the same as open.get( 0 ) and for headless mode, we don't want to show a chooser dialog, so just return the active one
93+
if ( open.size() == 1 || uiService.isHeadless() )
94+
return Collections.singletonList( this.pyramidal.getPyramidContents() );
95+
return OmeZarrImagesChooser.choose( open, this.pyramidal.getPyramidContents() ); // NB: the active one is pre-selected
7896
}
7997
}

‎ome-zarr-fiji-ui/src/test/java/ome/zarr/fijiui/plugin/command/tools/OpenInBDVCommandTest.java‎

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
* %%
77
* Redistribution and use in source and binary forms, with or without
88
* modification, are permitted provided that the following conditions are met:
9-
*
9+
*
1010
* 1. Redistributions of source code must retain the above copyright notice,
1111
* this list of conditions and the following disclaimer.
1212
* 2. Redistributions in binary form must reproduce the above copyright notice,
1313
* this list of conditions and the following disclaimer in the documentation
1414
* and/or other materials provided with the distribution.
15-
*
15+
*
1616
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
1717
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1818
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -37,6 +37,7 @@
3737
import java.net.URISyntaxException;
3838
import java.nio.file.Path;
3939
import java.util.List;
40+
import java.util.stream.Collectors;
4041
import java.util.concurrent.ExecutionException;
4142

4243
import javax.swing.SwingUtilities;
@@ -49,9 +50,11 @@
4950
import org.junit.jupiter.api.Test;
5051
import org.scijava.Context;
5152
import org.scijava.command.CommandService;
53+
import org.scijava.ui.UIService;
5254

5355
import ome.zarr.fijiui.open.OmeZarrOpenActions;
5456
import ome.zarr.fiji.Pyramidal;
57+
import ome.zarr.fiji.PyramidalBdv;
5558
import ome.zarr.fiji.plugins.PyramidalService;
5659
import ome.zarr.ZarrTestUtils;
5760

@@ -76,6 +79,10 @@ private static void flushEventQueue() throws InterruptedException
7679
}
7780
}
7881

82+
private static final String SPOTS = "ome/zarr/testdata/bdv_testing/logo_spots.ome.zarr";
83+
84+
private static final String LABELS = "ome/zarr/testdata/bdv_testing/logo_labels.ome.zarr";
85+
7986
// 2 resolution levels: level 0 = 64x64x16, level 1 = 32x32x8
8087
private static final String PYRAMID_RESOURCE = "ome/zarr/testdata/5d_testing/5d_dataset_v5.ome.zarr";
8188

@@ -146,4 +153,34 @@ void runAfterBdvOpenCreatesSecondBdvDataset() throws URISyntaxException, Executi
146153
assertSame( firstBdvPyramidal.getPyramidContents(), secondBdvPyramidal.getPyramidContents() );
147154
}
148155
}
156+
157+
/**
158+
* Headless, there is no dialog: with two OME-Zarrs open, only the active one is shown.
159+
*/
160+
@Test
161+
void runHeadlessWithTwoOpenShowsOnlyTheActiveOne() throws Exception
162+
{
163+
try (Context context = new Context())
164+
{
165+
new OmeZarrOpenActions( ZarrTestUtils.resourcePath( SPOTS ).toUri(), context ).showInImageJ();
166+
new OmeZarrOpenActions( ZarrTestUtils.resourcePath( LABELS ).toUri(), context ).showInImageJ();
167+
flushEventQueue();
168+
Pyramidal active = context.getService( PyramidalService.class ).getActivePyramidal();
169+
context.getService( UIService.class ).setHeadless( true );
170+
171+
context.getService( CommandService.class ).run( OpenInBDVCommand.class, true ).get();
172+
173+
List< PyramidalBdv< ? > > shown = bdvPyramidals( context );
174+
assertEquals( 1, shown.size() );
175+
assertSame( active.getPyramidContents(), shown.get( 0 ).getPyramidContents() );
176+
}
177+
}
178+
179+
private static List< PyramidalBdv< ? > > bdvPyramidals( final Context context )
180+
{
181+
return context.getService( PyramidalService.class ).getPyramidals().stream()
182+
.filter( PyramidalBdv.class::isInstance )
183+
.map( pyramidal -> ( PyramidalBdv< ? > ) pyramidal )
184+
.collect( Collectors.toList() );
185+
}
149186
}

0 commit comments

Comments
 (0)