2929package org .scijava .desktop .links ;
3030
3131import java .awt .Desktop ;
32+ import java .awt .GraphicsEnvironment ;
3233import java .net .URI ;
3334import java .util .Arrays ;
3435import java .util .Collections ;
4647import org .scijava .plugin .Parameter ;
4748import org .scijava .plugin .Plugin ;
4849import org .scijava .service .Service ;
50+ import org .scijava .ui .DialogPrompt ;
51+ import org .scijava .ui .UIService ;
4952
5053/**
5154 * Default implementation of {@link LinkService}.
@@ -61,6 +64,12 @@ public class DefaultLinkService extends AbstractHandlerService<URI, LinkHandler>
6164 @ Parameter (required = false )
6265 private PlatformService platformService ;
6366
67+ @ Parameter (required = false )
68+ private UIService uiService ;
69+
70+ /** Maximum number of characters of an unsupported URI shown to the user. */
71+ private static final int MAX_URI_DISPLAY_LENGTH = 120 ;
72+
6473 @ EventHandler
6574 private void onEvent (final ContextCreatedEvent evt ) {
6675 // Register URI handler with the desktop system, if possible.
@@ -75,6 +84,26 @@ private void onEvent(final ContextCreatedEvent evt) {
7584 installSchemes ();
7685 }
7786
87+ @ Override
88+ public void handleUnsupported (final URI uri ) {
89+ final String appName = System .getProperty ("scijava.app.name" , "This application" );
90+ final String appDir = System .getProperty ("scijava.app.directory" );
91+ String shown = String .valueOf (uri );
92+ if (shown .length () > MAX_URI_DISPLAY_LENGTH ) {
93+ shown = shown .substring (0 , MAX_URI_DISPLAY_LENGTH ) + "..." ;
94+ }
95+ final String msg = appName + " cannot handle this link:\n \n " + shown +
96+ "\n \n The component that supports it may be missing or outdated. " +
97+ "Please make sure it is installed and up to date." +
98+ (appDir == null ? "" : "\n \n If several installations exist in your system, " +
99+ "the one that received this link may not include the component it " +
100+ "needs. This link has been opened by:\n " + appDir );
101+ if (log != null ) log .warn (msg .replace ("\n \n " , " " ).replace ("\n " , " " ));
102+ if (uiService != null && !GraphicsEnvironment .isHeadless ()) {
103+ uiService .showDialog (msg , "Unsupported Link" , DialogPrompt .MessageType .ERROR_MESSAGE );
104+ }
105+ }
106+
78107 /**
79108 * Installs URI schemes with the operating system.
80109 * <p>
0 commit comments