]> gerrit.simantics Code Review - simantics/district.git/commitdiff
Editor adapter for tech type table entities 35/4435/1
authorReino Ruusu <reino.ruusu@semantum.fi>
Mon, 31 Aug 2020 14:57:33 +0000 (17:57 +0300)
committerReino Ruusu <reino.ruusu@semantum.fi>
Wed, 9 Sep 2020 12:33:48 +0000 (15:33 +0300)
gitlab #93

Change-Id: I7f7dd9aae0d90b00250ecf42e01ce566e57544d0

org.simantics.district.network.ui/plugin.xml
org.simantics.district.network.ui/src/org/simantics/district/network/ui/techtype/adapters/TechTypeEditorAdapter.java [new file with mode: 0644]
org.simantics.district.network.ui/src/org/simantics/district/network/ui/techtype/table/TechTypeTable.java
org.simantics.district.network.ui/src/org/simantics/district/network/ui/techtype/table/TechTypeTableView.java

index cee0a77f6b24ecd5a7b14b9d5da3bc5f71feb02d..3b8bf45c07df28c51deca62bf2f5b77040bd1edd 100644 (file)
             priority="300"
             class="org.simantics.district.network.ui.OpenDiagramFromNetworkElementAdapter">
       </adapterClass>
+      <adapterClass
+            class="org.simantics.district.network.ui.techtype.adapters.TechTypeEditorAdapter"
+            priority="100">
+      </adapterClass>
    </extension>
    <extension
          point="org.simantics.scl.reflection.binding">
diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/techtype/adapters/TechTypeEditorAdapter.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/techtype/adapters/TechTypeEditorAdapter.java
new file mode 100644 (file)
index 0000000..5ebe6ed
--- /dev/null
@@ -0,0 +1,79 @@
+package org.simantics.district.network.ui.techtype.adapters;
+
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.e4.core.contexts.IEclipseContext;
+import org.eclipse.e4.ui.workbench.modeling.EPartService;
+import org.eclipse.e4.ui.workbench.modeling.EPartService.PartState;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.ui.PlatformUI;
+import org.simantics.Simantics;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.common.request.ReadRequest;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.district.network.ontology.DistrictNetworkResource;
+import org.simantics.district.network.ui.techtype.table.TechTypeTableView;
+import org.simantics.ui.utils.ResourceAdaptionUtils;
+import org.simantics.ui.workbench.editor.AbstractResourceEditorAdapter;
+import org.simantics.ui.workbench.editor.EditorAdapter;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * @author Reino Ruusu
+ */
+public class TechTypeEditorAdapter extends AbstractResourceEditorAdapter implements EditorAdapter {
+
+       private static final Logger LOGGER = LoggerFactory.getLogger(TechTypeEditorAdapter.class);
+
+       public TechTypeEditorAdapter() throws MalformedURLException, IOException {
+               super("Tech Type Table View");
+               setIcon(ImageDescriptor.createFromURL(FileLocator.resolve(new URL("platform:/plugin/com.famfamfam.silk/icons/table.png")))); //$NON-NLS-1$
+       }
+
+       @Override
+       public boolean canHandle(ReadGraph graph, Object input) throws DatabaseException {
+               Resource r = ResourceAdaptionUtils.toSingleResource(input);
+               if (r == null)
+                       return false;
+               return graph.isInstanceOf(r, DistrictNetworkResource.getInstance(graph).TechType_TechTypeTable);
+       }
+
+       @Override
+       public void openEditor(Resource table) throws Exception {
+               IEclipseContext eclipseContext = PlatformUI.getWorkbench().getService(IEclipseContext.class);
+               if (eclipseContext == null) {
+                       LOGGER.error("No Eclipse context available");
+                       return;
+               }
+
+               eclipseContext = eclipseContext.getActiveLeaf();
+               EPartService partService = eclipseContext.get(EPartService.class);
+               if (partService == null)
+                       return;
+
+               partService.showPart(TechTypeTableView.ID, PartState.ACTIVATE);
+
+               try {
+                       Simantics.getSession().syncRequest(new ReadRequest() {
+                               @Override
+                               public void run(ReadGraph graph) throws DatabaseException {
+                                       DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
+                                       Resource componentType = graph.getPossibleObject(table, DN.TechType_TechTypeTable_HasComponentType);
+                                       String data = graph.getPossibleRelatedValue2(table, DN.TechType_TechTypeTable_HasData);
+
+                                       TechTypeTableView.table.getDisplay().asyncExec(() -> {
+                                               TechTypeTableView.table.setComponentType(componentType);
+                                               TechTypeTableView.table.setTechTypeData(data);
+                                       });
+                               }
+                       });
+               } catch (DatabaseException e) {
+                       LOGGER.error("Failed to read tech type table {}", table, e);
+               }
+       }
+}
index 3b3d4a7014f13cbdc924ef46368f3111db828dfa..296d9af38058e288aec15a5ec853619dacbba72d 100644 (file)
@@ -208,8 +208,17 @@ public class TechTypeTable extends Composite {
                        LOGGER.error("Failed to write tech type table data to model", e);
                }
 
+               setTechTypeData(data);
+       }
+
+       public void setTechTypeData(String data) {
                bodyDataProvider.setData(data);
                table.refresh(true);
        }
 
+       public void setComponentType(Resource componentType) {
+               this.componentType = componentType;
+       }
+
 }
+
index 42b88207c1881fe0b8b1735f7a10e843675a915c..50368d2c2ed2a8d992cb3db1d68cc6636b24a531 100644 (file)
@@ -31,6 +31,8 @@ public class TechTypeTableView {
 
        private final static Logger LOGGER = LoggerFactory.getLogger(TechTypeTableView.class);
 
+       public static final String ID = "org.simantics.district.network.ui.techtype.table.techtypeTableView";
+
        @Inject ESelectionService selectionService;
 
        public static TechTypeTable table;