1 package org.simantics.district.network.ui;
3 import org.simantics.Simantics;
4 import org.simantics.db.ReadGraph;
5 import org.simantics.db.Resource;
6 import org.simantics.db.Session;
7 import org.simantics.db.exception.DatabaseException;
8 import org.simantics.district.network.ontology.DistrictNetworkResource;
9 import org.simantics.ui.workbench.editor.AbstractResourceEditorAdapter;
10 import org.simantics.utils.ui.BundleUtils;
13 * @author Tuukka Lehtonen
16 public class OpenDiagramFromNetworkElementAdapter extends AbstractResourceEditorAdapter {
18 public OpenDiagramFromNetworkElementAdapter() {
19 super("District Network Diagram",
20 BundleUtils.getImageDescriptorFromPlugin("com.famfamfam.silk", "icons/map.png"));
24 public boolean canHandle(ReadGraph graph, Object input) throws DatabaseException {
25 DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
26 Resource r = DistrictNetworkUIUtil.getInputResource(graph, input);
28 && graph.isInstanceOf(r, DN.Element)
29 && graph.getPossibleURI(r) != null;
33 public void openEditor(Object input) throws Exception {
34 Session s = Simantics.getSession();
35 Resource dhElement = s.syncRequest(new DistrictNetworkUIUtil.GetInputResource(input));
36 DistrictNetworkUIUtil.Input in = dhElement != null ? s.syncRequest(new DistrictNetworkUIUtil.ElementToInput(dhElement)) : null;
38 DistrictNetworkUIUtil.openDNDiagramEditorWithSelection(in, in.element());