1 package org.simantics.district.network.ui.techtype.adapters;
3 import java.io.IOException;
4 import java.net.MalformedURLException;
7 import org.eclipse.core.runtime.FileLocator;
8 import org.eclipse.e4.core.contexts.IEclipseContext;
9 import org.eclipse.e4.ui.workbench.modeling.EPartService;
10 import org.eclipse.e4.ui.workbench.modeling.EPartService.PartState;
11 import org.eclipse.jface.resource.ImageDescriptor;
12 import org.eclipse.ui.PlatformUI;
13 import org.simantics.Simantics;
14 import org.simantics.db.ReadGraph;
15 import org.simantics.db.Resource;
16 import org.simantics.db.common.request.ReadRequest;
17 import org.simantics.db.exception.DatabaseException;
18 import org.simantics.district.network.ontology.DistrictNetworkResource;
19 import org.simantics.district.network.ui.techtype.table.TechTypeTableView;
20 import org.simantics.ui.utils.ResourceAdaptionUtils;
21 import org.simantics.ui.workbench.editor.AbstractResourceEditorAdapter;
22 import org.simantics.ui.workbench.editor.EditorAdapter;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
29 public class TechTypeEditorAdapter extends AbstractResourceEditorAdapter implements EditorAdapter {
31 private static final Logger LOGGER = LoggerFactory.getLogger(TechTypeEditorAdapter.class);
33 public TechTypeEditorAdapter() throws MalformedURLException, IOException {
34 super("Tech Type Table View");
35 setIcon(ImageDescriptor.createFromURL(FileLocator.resolve(new URL("platform:/plugin/com.famfamfam.silk/icons/table.png")))); //$NON-NLS-1$
39 public boolean canHandle(ReadGraph graph, Object input) throws DatabaseException {
40 Resource r = ResourceAdaptionUtils.toSingleResource(input);
43 return graph.isInstanceOf(r, DistrictNetworkResource.getInstance(graph).TechType_TechTypeTable);
47 public void openEditor(Resource table) throws Exception {
48 IEclipseContext eclipseContext = PlatformUI.getWorkbench().getService(IEclipseContext.class);
49 if (eclipseContext == null) {
50 LOGGER.error("No Eclipse context available");
54 eclipseContext = eclipseContext.getActiveLeaf();
55 EPartService partService = eclipseContext.get(EPartService.class);
56 if (partService == null)
59 partService.showPart(TechTypeTableView.ID, PartState.ACTIVATE);
62 Simantics.getSession().syncRequest(new ReadRequest() {
64 public void run(ReadGraph graph) throws DatabaseException {
65 DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
66 Resource componentType = graph.getPossibleObject(table, DN.TechType_TechTypeTable_HasComponentType);
67 String data = graph.getPossibleRelatedValue2(table, DN.TechType_TechTypeTable_HasData);
69 TechTypeTableView.table.getDisplay().asyncExec(() -> {
70 TechTypeTableView.table.setComponentType(componentType);
71 TechTypeTableView.table.setTechTypeData(data);
75 } catch (DatabaseException e) {
76 LOGGER.error("Failed to read tech type table {}", table, e);