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: SelfShowableContent - a new kind of opening outcome #473

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

xulman
Copy link

@xulman xulman commented Oct 18, 2023

It is often used in conjuction with openers that do load-and-show on their own,
as opposed to load-only-and-have-Fiji-to-show pattern.

Requires a patch on the imagej-legacy side... will PR there too.

Example code

package sc.fiji.ome.zarr.fiji.ui;

import net.imagej.ImageJ;
import org.scijava.io.AbstractIOPlugin;
import org.scijava.io.IOPlugin;
import org.scijava.io.location.Location;
import org.scijava.plugin.Attr;
import org.scijava.plugin.Plugin;
import org.scijava.ui.SelfShowableContent;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

@Plugin(type = IOPlugin.class, attrs = @Attr(name = "eager"))
public class MinimalFolderOpeningExample extends AbstractIOPlugin<Object> {
	@Override
	public boolean supportsOpen(Location source) {
		System.out.println(this.getClass().getName() + " is considering the file "+source);
		//
		final Path filePath = Paths.get(source.getURI());
		boolean canOpen = Files.isDirectory(filePath) && filePath.toString().endsWith(".xyz");
		System.out.println(this.getClass().getName() + " says canOpen = " + canOpen);
		return canOpen;
	}

	@Override
	public Object open(Location source) throws IOException {
		final String message = this.getClass().getName() + " is opening the file "+source;

		return new SelfShowableContent<>(
				source.toString(),
				m -> System.out.println("I just took care of the .xyz folder: "+m)
		);
	}

	@Override
	public Class<Object> getDataType() {
		return Object.class;
	}

	public static void main(String[] args) {
		ImageJ ij = new ImageJ();
		ij.ui().showUI();
	}
}

@xulman
Copy link
Author

xulman commented Oct 18, 2023

this PR becomes useful only in conjunction with imagej/imagej-legacy#302

It is often used in conjuction with openers that do load-and-show
on their own, as opposite to load-only-and-have-Fiji-to-show pattern.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants