package org.simantics.district.network.ui; import org.simantics.Simantics; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.Session; import org.simantics.db.exception.DatabaseException; import org.simantics.district.network.ontology.DistrictNetworkResource; import org.simantics.ui.workbench.editor.AbstractResourceEditorAdapter; import org.simantics.utils.ui.BundleUtils; /** * @author Tuukka Lehtonen * @since 1.35.0 */ public class OpenDiagramFromNetworkElementAdapter extends AbstractResourceEditorAdapter { public OpenDiagramFromNetworkElementAdapter() { super("District Network Diagram", BundleUtils.getImageDescriptorFromPlugin("com.famfamfam.silk", "icons/map.png")); } @Override public boolean canHandle(ReadGraph graph, Object input) throws DatabaseException { DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph); Resource r = DistrictNetworkUIUtil.getInputResource(graph, input); return r != null && graph.isInstanceOf(r, DN.Element) && graph.getPossibleURI(r) != null; } @Override public void openEditor(Object input) throws Exception { Session s = Simantics.getSession(); Resource dhElement = s.syncRequest(new DistrictNetworkUIUtil.GetInputResource(input)); DistrictNetworkUIUtil.Input in = dhElement != null ? s.syncRequest(new DistrictNetworkUIUtil.ElementToInput(dhElement)) : null; if (in != null) DistrictNetworkUIUtil.openDNDiagramEditorWithSelection(in, in.element()); } }