]> gerrit.simantics Code Review - simantics/district.git/blob - org.simantics.district.network.ui/src/org/simantics/district/network/ui/OpenDiagramFromNetworkElementAdapter.java
Remover for tech type tables
[simantics/district.git] / org.simantics.district.network.ui / src / org / simantics / district / network / ui / OpenDiagramFromNetworkElementAdapter.java
1 package org.simantics.district.network.ui;
2
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;
11
12 /**
13  * @author Tuukka Lehtonen
14  * @since 1.35.0
15  */
16 public class OpenDiagramFromNetworkElementAdapter extends AbstractResourceEditorAdapter {
17
18     public OpenDiagramFromNetworkElementAdapter() {
19         super("District Network Diagram",
20                 BundleUtils.getImageDescriptorFromPlugin("com.famfamfam.silk", "icons/map.png"));
21     }
22
23     @Override
24     public boolean canHandle(ReadGraph graph, Object input) throws DatabaseException {
25         DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
26         Resource r = DistrictNetworkUIUtil.getInputResource(graph, input);
27         return r != null
28                 && graph.isInstanceOf(r, DN.Element)
29                 && graph.getPossibleURI(r) != null;
30     }
31
32     @Override
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;
37         if (in != null)
38             DistrictNetworkUIUtil.openDNDiagramEditorWithSelection(in, in.element());
39     }
40
41 }