Repository: mobie/mobie-viewer-fiji (language: python)

Issue:
MoBIE opens tables for segmentations that are not selected
When opening a view that has a segmentation with a table, the table is always opened, even if the segmentation is **not** shown by default in the view.
This behaviour is weird, but might be due to the fact that we do not have a "showTable" field in the spec for the segmentationDisplay.

@tischi: I think there are two ways to fix this:
- when opening a view with a segmentation show the tables only if the segmentation is selected (i.e. "visible:True")
- add an optional field "showTable" to the spec (default: True). Then it's the responsibility of the project creator to make sure that showTable is set to false if the segmentation is not shown by default. With this approach it would also be feasible to show a segmentation, but not the table when opening a view.

I would be fine with either solution, let me know what you prefer. (And in the second case I could update the spec and the example below.)

Example: 
- Open https://github.com/mobie/covid-if-project
- This opens the tables for "cell segmentation" and "nucleus segmentation" although these sources are not set to visible in the view:
![aaaaaa-mobie-tables](https://user-images.githubusercontent.com/4263537/142633702-129c3ed0-30e6-42ba-b734-fe444c79f380.png)


Discussion / hints:
Thanks for finding this.

Turns out, in Java we do have a `showTable` field already:


```
public abstract class AnnotatedRegionDisplay< T extends TableRow > extends AbstractSourceDisplay
{
	// Serialization
	protected String lut = ColoringLuts.GLASBEY;
	protected String colorByColumn;
	protected Double[] valueLimits = new Double[]{ null, null };
	protected boolean showScatterPlot = false;
	protected String[] scatterPlotAxes = new String[]{ TableColumnNames.ANCHOR_X, TableColumnNames.ANCHOR_Y };
	protected List< String > tables; // tables to display
	protected boolean showTable = true;
```

However, in `public void initTableViewer( SegmentationSourceDisplay display  )` I show the table anyway, not even looking at this field 😄 

Maybe we just use this field both in the code and in the JSON?
I guess we need to leave the default at `true` in order not to have to rewrite too many JSON files?

@tischi I double checked this now, and we have `showTable` in the spec already. 

> I guess we need to leave the default at `true` in order not to have to rewrite too many JSON files?

Yes, the default should be `true`.

For the segmentationDisplays in https://github.com/mobie/covid-if-project (default) the `showTable` field is set to `false` now.
But the table is still opened when opening the view. Could you please have a look and fix the behaviour in MoBIE s.t. it does not open the tables by default for this view?

Fix patch:
diff --git a/src/main/java/org/embl/mobie/viewer/display/AbstractSourceDisplay.java b/src/main/java/org/embl/mobie/viewer/display/AbstractSourceDisplay.java
index 5a22e4c1f..2d4df8724 100644
--- a/src/main/java/org/embl/mobie/viewer/display/AbstractSourceDisplay.java
+++ b/src/main/java/org/embl/mobie/viewer/display/AbstractSourceDisplay.java
@@ -22,10 +22,7 @@ public double getOpacity()
 	{
 		return opacity;
 	}
-	public boolean isVisible()
-	{
-		return visible;
-	}
+	public boolean isVisible() { return visible; }
 
 	// Runtime
 	public transient Map< String, SourceAndConverter< ? > > sourceNameToSourceAndConverter;
diff --git a/src/main/java/org/embl/mobie/viewer/table/TableViewer.java b/src/main/java/org/embl/mobie/viewer/table/TableViewer.java
index 2ef3b04a1..2196fd931 100644
--- a/src/main/java/org/embl/mobie/viewer/table/TableViewer.java
+++ b/src/main/java/org/embl/mobie/viewer/table/TableViewer.java
@@ -129,6 +129,16 @@ public TableViewer(
 
 		// TODO: reconsider
 		registerAsTableRowListener( tableRows );
+
+		configureJTable();
+
+		if ( selectionModel != null )
+			installSelectionModelNotification();
+
+		if ( coloringModel != null)
+			configureTableRowColoring();
+
+		createFrame();
 	}
 
 	public TableViewer< T > show()
@@ -141,7 +151,7 @@ public TableViewer< T > show()
 		if ( coloringModel != null)
 			configureTableRowColoring();
 
-		createAndShowMenu();
+		createFrame();
 
 		return this;
 	}
@@ -753,7 +763,7 @@ public void continueAnnotation( String columnName )
 		annotator.showDialog();
 	}
 
-	private void createAndShowMenu()
+	private void createFrame()
 	{
 		final JPanel panel = new JPanel( new GridLayout( 1, 0 ) );
 		JScrollPane scrollPane = new JScrollPane(
@@ -781,8 +791,11 @@ public void windowClosing( WindowEvent ev) {
 				frame.setVisible( false );
 			}
 		});
+	}
 
-		SwingUtilities.invokeLater( () -> frame.setVisible( true ) );
+	public void setVisible( boolean visible )
+	{
+		SwingUtilities.invokeLater( () -> frame.setVisible( visible ) );
 	}
 
 	public void addColumn( String column, Object defaultValue )
diff --git a/src/main/java/org/embl/mobie/viewer/ui/UserInterfaceHelper.java b/src/main/java/org/embl/mobie/viewer/ui/UserInterfaceHelper.java
index 9cba6c0ad..551d1051f 100644
--- a/src/main/java/org/embl/mobie/viewer/ui/UserInterfaceHelper.java
+++ b/src/main/java/org/embl/mobie/viewer/ui/UserInterfaceHelper.java
@@ -646,7 +646,7 @@ private static JCheckBox createWindowVisibilityCheckbox(
 		JCheckBox checkBox = new JCheckBox( "T" );
 		checkBox.setSelected( isVisible );
 		checkBox.setPreferredSize( PREFERRED_CHECKBOX_SIZE );
-		window.setVisible( checkBox.isSelected() );
+		window.setVisible( isVisible );
 		checkBox.addActionListener( e -> SwingUtilities.invokeLater( () -> window.setVisible( checkBox.isSelected() ) ) );
 
 		window.addWindowListener(
diff --git a/src/main/java/org/embl/mobie/viewer/view/ViewManager.java b/src/main/java/org/embl/mobie/viewer/view/ViewManager.java
index da8d3c78a..c1c42f53b 100644
--- a/src/main/java/org/embl/mobie/viewer/view/ViewManager.java
+++ b/src/main/java/org/embl/mobie/viewer/view/ViewManager.java
@@ -146,7 +146,7 @@ private static void configureMoBIEColoringModel( AnnotatedRegionDisplay< ? > dis
 		}
 	}
 
-	public void showInTableViewer( SegmentationSourceDisplay display  )
+	public void initTableViewer( SegmentationSourceDisplay display  )
 	{
 		Map<String, String> sourceNameToTableDir = new HashMap<>();
 		for ( String source: display.getSources() )
@@ -161,7 +161,8 @@ public void showInTableViewer( SegmentationSourceDisplay display  )
 				sourceNameToTableDir.put( source, null );
 			}
 		}
-		display.tableViewer = new TableViewer<>( moBIE, display.tableRows, display.selectionModel, display.coloringModel, display.getName(), sourceNameToTableDir, false ).show();
+		display.tableViewer = new TableViewer<>( moBIE, display.tableRows, display.selectionModel, display.coloringModel, display.getName(), sourceNameToTableDir, false );
+		display.tableViewer.setVisible( display.showTable() );
 		display.selectionModel.listeners().add( display.tableViewer );
 		display.coloringModel.listeners().add( display.tableViewer );
 	}
@@ -417,7 +418,7 @@ private void showAnnotatedIntervalDisplay( AnnotatedIntervalDisplay annotationDi
 		}
 
 		showInSliceViewer( annotationDisplay );
-		showInTableViewer( annotationDisplay );
+		initTableViewer( annotationDisplay );
 		initScatterPlotViewer( annotationDisplay );
 
 		SwingUtilities.invokeLater( () ->
@@ -426,7 +427,7 @@ private void showAnnotatedIntervalDisplay( AnnotatedIntervalDisplay annotationDi
 		} );
 	}
 
-	private void showInTableViewer( AnnotatedIntervalDisplay annotationDisplay )
+	private void initTableViewer( AnnotatedIntervalDisplay annotationDisplay )
 	{
 		HashMap<String, String> nameToTableDir = new HashMap<>();
 		nameToTableDir.put( annotationDisplay.getName(), annotationDisplay.getTableDataFolder( TableDataFormat.TabDelimitedFile ) );
@@ -462,7 +463,7 @@ private void showSegmentationDisplay( SegmentationSourceDisplay segmentationDisp
 
 		if ( segmentationDisplay.tableRows != null )
 		{
-			showInTableViewer( segmentationDisplay );
+			initTableViewer( segmentationDisplay );
 			initScatterPlotViewer( segmentationDisplay );
 
 			SwingUtilities.invokeLater( () ->


Test patch:
diff --git a/src/test/java/projects/OpenRemoteCovidScreen.java b/src/test/java/projects/OpenRemoteCovidScreen.java
new file mode 100644
index 000000000..93f52460d
--- /dev/null
+++ b/src/test/java/projects/OpenRemoteCovidScreen.java
@@ -0,0 +1,24 @@
+package projects;
+
+import net.imagej.ImageJ;
+import org.embl.mobie.viewer.MoBIE;
+import org.embl.mobie.viewer.MoBIESettings;
+import org.embl.mobie.viewer.source.ImageDataFormat;
+
+import java.io.IOException;
+
+public class OpenRemoteCovidScreen
+{
+	public static void main( String[] args )
+	{
+		final ImageJ imageJ = new ImageJ();
+		imageJ.ui().showUI();
+
+		try {
+			new MoBIE("https://github.com/mobie/covid-if-project",
+					MoBIESettings.settings().gitProjectBranch( "main" ).imageDataFormat( ImageDataFormat.OmeZarrS3 ) );
+		} catch (IOException e) {
+			e.printStackTrace();
+		}
+	}
+}