Skip to content

Commit

Permalink
CHG2/2: N5Importer.runWithDialog(path, selectionPath)...
Browse files Browse the repository at this point in the history
...commands its 'selectionDialog' to potentially uncollapse parts
of its tree, and select (highlight) the item that matches the
provided path. Before looking for the right tree item/node, the
code needs to wait until the container is fully discovered and thus
the tree is populated, and the wanted item could be thus found.
  • Loading branch information
xulman committed Nov 21, 2024
1 parent 882d70e commit 4488228
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/main/java/org/janelia/saalfeldlab/n5/ij/N5Importer.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.swing.JTree;

import org.apache.commons.lang.ArrayUtils;
import org.janelia.saalfeldlab.n5.DataType;
Expand All @@ -62,6 +63,7 @@
import org.janelia.saalfeldlab.n5.ui.DataSelection;
import org.janelia.saalfeldlab.n5.ui.DatasetSelectorDialog;
import org.janelia.saalfeldlab.n5.ui.N5DatasetTreeCellRenderer;
import org.janelia.saalfeldlab.n5.ui.N5SwingTreeNode;
import org.janelia.saalfeldlab.n5.universe.N5DatasetDiscoverer;
import org.janelia.saalfeldlab.n5.universe.N5Factory;
import org.janelia.saalfeldlab.n5.universe.N5Factory.StorageFormat;
Expand Down Expand Up @@ -253,14 +255,34 @@ public void setShow(final boolean show) {
this.show = show;
}

public void runWithDialog(final String pathToContainer) {
public void runWithDialog(final String pathToContainer, final List<String> selectThisSubPath) {
lastOpenedContainer = pathToContainer;
selectionDialog = null;
run(null);
if (selectionDialog == null) {
throw new RuntimeException("The \"Open N5\" didn't come up when it should.");
} else {
selectionDialog.detectDatasets();
if (selectThisSubPath != null) {
boolean isDiscoveryFinished = selectionDialog.waitUntilDiscoveryIsFinished(60000);
if (isDiscoveryFinished) selectTreeItem(selectThisSubPath);
}
}
}

private void selectTreeItem(final List<String> itemPath) {
final JTree t = selectionDialog.getJTree();
int currRow = 0;
for (String subPath : itemPath) {
for (int r = currRow; r < t.getRowCount(); ++r, ++currRow) {
N5SwingTreeNode n = (N5SwingTreeNode)t.getPathForRow(r).getLastPathComponent();
if (n.getNodeName().equals(subPath)) {
t.expandRow(r);
t.setSelectionRow(r);
++currRow;
break;
}
}
}
}

Expand Down

0 comments on commit 4488228

Please sign in to comment.