LinkIndexConverter
has only two methods:public class TreeElement { public final String namespace; public final String name; public TreeElement(String namespace, String name) { this.namespace = namespace; this.name = name; } @Override public String toString() { return namespace + ":" + name; } @Override public int hashCode() { int hash = 7; hash = 79 * hash + Objects.hashCode(this.namespace); hash = 79 * hash + Objects.hashCode(this.name); return hash; } @Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } final TreeElement other = (TreeElement) obj; return true; } }The following code will allow to create a link description from a
TreeElement
and a TreeElement
from a link description:public class MyLinkIndexConverter implements LinkIndexConverter { @Override public String getLinkFromObject(TreeElement element) { return element.namespace + "$" + element.name; } @Override public TreeElement getObjectFromLink(String linkID) { int index = linkID.indexOf("$"); if (index != -1) { String namespace = linkID.substring(0, index); String name = linkID.substring(index + 1); TreeElement key = new TreeElement(namespace, name); if (elements.containsKey(key)) { return elements.get(key); } else { return null; } } else { return null; } } }
LinkIndexConverter
, you must use the ScriptLogger.registerLinkIndexConverter(LinkIndexConverter) method.GroovyScriptWrapper<Script> wrapper = new GroovyScriptWrapper<Script>() { }; LinkIndexConverter converter = new MyLinkIndexConverter(); ScriptLogger logger = new DefaultSwingScriptLogger(); logger.registerLinkIndexConverter(converter); wrapper.setScriptLogger(logger);
Copyright 2019-2020 Herve Girod. All Rights Reserved. Documentation and source under the BSD licence