@Override default String getIdentifier() { // NB: By default, we assume that the delegate class name uniquely // distinguishes the module from others. If the same delegate class is used // for more than one module, though, it may need to override this method to // provide more differentiating details. return "module:" + getDelegateClassName(); }
@Override default String getIdentifier() { // NB: By default, we assume that the delegate class name uniquely // distinguishes the module from others. If the same delegate class is used // for more than one module, though, it may need to override this method to // provide more differentiating details. return "module:" + getDelegateClassName(); }
@Override default String getTitle() { final String title = UIDetails.super.getTitle(); if (!title.equals(getClass().getSimpleName())) return title; // use delegate class name rather than actual class name final String className = getDelegateClassName(); final int dot = className.lastIndexOf("."); return dot < 0 ? className : className.substring(dot + 1); }
@Override default String getTitle() { final String title = UIDetails.super.getTitle(); if (!title.equals(getClass().getSimpleName())) return title; // use delegate class name rather than actual class name final String className = getDelegateClassName(); final int dot = className.lastIndexOf("."); return dot < 0 ? className : className.substring(dot + 1); }
/** * Gets a string describing the given op, highlighting the specific parameter. * * @param info The {@link ModuleInfo} metadata which describes the op. * @param special A parameter of particular interest when describing the op. * @return A string describing the op. */ public static String opString(final ModuleInfo info, final ModuleItem<?> special) { final StringBuilder sb = new StringBuilder(); final String outputString = paramString(outputs(info), null).trim(); if (!outputString.isEmpty()) sb.append("(" + outputString + ") =\n\t"); sb.append(info.getDelegateClassName()); sb.append("(" + paramString(inputs(info), special) + ")"); return sb.toString(); }
private String details(final ModuleInfo info) { if (info == null) return "<null>"; String className, classLocation; try { final Class<?> c = info.loadDelegateClass(); className = c.getName(); classLocation = Types.location(c).toString(); } catch (final ClassNotFoundException exc) { className = info.getDelegateClassName(); classLocation = "<invalid>"; } return info.getMenuPath() + " : " + className + " [" + classLocation + "]"; }
private String details(final ModuleInfo info) { if (info == null) return "<null>"; String className, classLocation; try { final Class<?> c = info.loadDelegateClass(); className = c.getName(); classLocation = Types.location(c).toString(); } catch (final ClassNotFoundException exc) { className = info.getDelegateClassName(); classLocation = "<invalid>"; } return info.getMenuPath() + " : " + className + " [" + classLocation + "]"; }
@Override public void process(final Module module) { final ModuleInfo info = module.getInfo(); if (info.isValid()) return; final StringBuilder sb = new StringBuilder("The module \"" + info.getDelegateClassName() + "\" is invalid:\n"); for (final ValidityProblem problem : info.getProblems()) { sb.append("- " + problem.getMessage()); sb.append("\n"); } cancel(sb.toString()); }
@Override public void process(final Module module) { final ModuleInfo info = module.getInfo(); if (info.isValid()) return; final StringBuilder sb = new StringBuilder("The module \"" + info.getDelegateClassName() + "\" is invalid:\n"); for (final ValidityProblem problem : info.getProblems()) { sb.append("- " + problem.getMessage()); sb.append("\n"); } cancel(sb.toString()); }
/** * Checks the {@link ObjectService} for a single registered {@link Module} * instance of the given {@link ModuleInfo}. In this way, if you want to * repeatedly reuse the same module instance instead of creating a new one * with each execution, you can register it with the {@link ObjectService} and * it will be automatically returned by the {@link #createModule(ModuleInfo)} * method (and hence automatically used whenever a {@link #run} method with * {@link ModuleInfo} argument is called). */ private Module getRegisteredModuleInstance(final ModuleInfo info) { final Class<?> type = Types.load(info.getDelegateClassName()); if (type == null || !Module.class.isAssignableFrom(type)) return null; // the module metadata's delegate class extends Module, so there is hope @SuppressWarnings("unchecked") final Class<? extends Module> moduleType = (Class<? extends Module>) type; // ask the object service for an instance of the delegate type final List<? extends Module> objects = objectService.getObjects(moduleType); if (objects == null || objects.isEmpty()) { // the object service has no such instances return null; } if (objects.size() > 1) { // there are multiple instances; it's not clear which one to use log.warn("Ignoring multiple candidate module instances for class: " + type.getName()); return null; } // found exactly one instance; return it! return objects.get(0); }
/** * Checks the {@link ObjectService} for a single registered {@link Module} * instance of the given {@link ModuleInfo}. In this way, if you want to * repeatedly reuse the same module instance instead of creating a new one * with each execution, you can register it with the {@link ObjectService} and * it will be automatically returned by the {@link #createModule(ModuleInfo)} * method (and hence automatically used whenever a {@link #run} method with * {@link ModuleInfo} argument is called). */ private Module getRegisteredModuleInstance(final ModuleInfo info) { final Class<?> type = Types.load(info.getDelegateClassName()); if (type == null || !Module.class.isAssignableFrom(type)) return null; // the module metadata's delegate class extends Module, so there is hope @SuppressWarnings("unchecked") final Class<? extends Module> moduleType = (Class<? extends Module>) type; // ask the object service for an instance of the delegate type final List<? extends Module> objects = objectService.getObjects(moduleType); if (objects == null || objects.isEmpty()) { // the object service has no such instances return null; } if (objects.size() > 1) { // there are multiple instances; it's not clear which one to use log.warn("Ignoring multiple candidate module instances for class: " + type.getName()); return null; } // found exactly one instance; return it! return objects.get(0); }
return menuLeaf == null ? "" : menuLeaf.getAccelerator(); if (column == 4) return info.getDelegateClassName(); if (column == 5) { final URL location = ClassUtils.getLocation(info.getDelegateClassName()); final File file = FileUtils.urlToFile(location); final String path = file == null ? null : file.getAbsolutePath();
/** * Gets the URL of the icon associated with this node's {@link MenuEntry}. * * @see org.scijava.plugin.PluginInfo#getIconURL() */ public URL getIconURL() { if (menuEntry == null) return null; String iconPath = menuEntry.getIconPath(); if (iconPath == null || iconPath.isEmpty()) { if (isLeaf()) iconPath = DEFAULT_ICON_PATH; else return null; } final String className = moduleInfo.getDelegateClassName(); try { final Class<?> c = Types.load(className, false); final URL iconURL = c.getResource(iconPath); if (iconURL == null) { if (log != null) log.error("Could not load icon: " + iconPath); } return iconURL; } catch (final IllegalArgumentException exc) { final String message = "Could not load icon for class: " + className; if (log.isDebug()) log.debug(message, exc); else log.error(message); return null; } }
/** * Gets the URL of the icon associated with this node's {@link MenuEntry}. * * @see org.scijava.plugin.PluginInfo#getIconURL() */ public URL getIconURL() { if (menuEntry == null) return null; String iconPath = menuEntry.getIconPath(); if (iconPath == null || iconPath.isEmpty()) { if (isLeaf()) iconPath = DEFAULT_ICON_PATH; else return null; } final String className = moduleInfo.getDelegateClassName(); try { final Class<?> c = Types.load(className, false); final URL iconURL = c.getResource(iconPath); if (iconURL == null) { if (log != null) log.error("Could not load icon: " + iconPath); } return iconURL; } catch (final IllegalArgumentException exc) { final String message = "Could not load icon for class: " + className; if (log.isDebug()) log.debug(message, exc); else log.error(message); return null; } }
@Override public void process(final Module module) { try { module.initialize(); if (isCanceled(module)) cancel(getCancelReason(module)); } catch (final MethodCallException exc) { if (log != null) log.error(exc); final String moduleClass = module.getInfo().getDelegateClassName(); cancel("The module \"" + moduleClass + "\" failed to initialize."); } }
@Override public void process(final Module module) { try { module.initialize(); if (isCanceled(module)) cancel(getCancelReason(module)); } catch (final MethodCallException exc) { if (log != null) log.error(exc); final String moduleClass = module.getInfo().getDelegateClassName(); cancel("The module \"" + moduleClass + "\" failed to initialize."); } }
@Override public Module createModule(final ModuleInfo info) { final Module existing = getRegisteredModuleInstance(info); if (existing != null) return existing; try { final Module module = info.createModule(); getContext().inject(module); Priority.inject(module, info.getPriority()); return module; } catch (final ModuleException exc) { log.error("Cannot create module: " + info.getDelegateClassName(), exc); } return null; }
@Override public Module createModule(final ModuleInfo info) { final Module existing = getRegisteredModuleInstance(info); if (existing != null) return existing; try { final Module module = info.createModule(); getContext().inject(module); Priority.inject(module, info.getPriority()); return module; } catch (final ModuleException exc) { log.error("Cannot create module: " + info.getDelegateClassName(), exc); } return null; }