X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.district.network.ui%2Fsrc%2Forg%2Fsimantics%2Fdistrict%2Fnetwork%2Fui%2Ftechtype%2Ftable%2FTechTypeTableView.java;h=42b88207c1881fe0b8b1735f7a10e843675a915c;hb=refs%2Fchanges%2F33%2F4433%2F1;hp=cdb502c3c5a870ddc887f240a8c6c185173d055d;hpb=7b3111c1cbb19842294bffc6a34289a2fecabdf9;p=simantics%2Fdistrict.git diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/techtype/table/TechTypeTableView.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/techtype/table/TechTypeTableView.java index cdb502c3..42b88207 100644 --- a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/techtype/table/TechTypeTableView.java +++ b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/techtype/table/TechTypeTableView.java @@ -1,6 +1,8 @@ package org.simantics.district.network.ui.techtype.table; +import java.util.List; + import javax.annotation.PostConstruct; import javax.annotation.PreDestroy; import javax.inject.Inject; @@ -13,9 +15,22 @@ import org.eclipse.e4.ui.model.application.ui.menu.MMenuFactory; import org.eclipse.e4.ui.model.application.ui.menu.MToolBar; import org.eclipse.e4.ui.workbench.modeling.ESelectionService; import org.eclipse.swt.widgets.Composite; +import org.simantics.Simantics; +import org.simantics.db.Resource; +import org.simantics.db.common.NamedResource; +import org.simantics.db.common.procedure.adapter.TransientCacheListener; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.request.PossibleActiveModel; +import org.simantics.db.layer0.request.PossibleResource; +import org.simantics.district.network.DistrictNetworkUtil; +import org.simantics.district.network.ui.techtype.requests.PossibleTechTypeTableData; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class TechTypeTableView { + private final static Logger LOGGER = LoggerFactory.getLogger(TechTypeTableView.class); + @Inject ESelectionService selectionService; public static TechTypeTable table; @@ -40,10 +55,36 @@ public class TechTypeTableView { @PostConstruct public void postConstruct(Composite parent) { - table = new TechTypeTable(parent, 0); - + Resource pipe = null; + try { + List componentTypes = DistrictNetworkUtil.getDistrictComponents(); + + pipe = componentTypes.stream() + .filter(r -> r.getName().toLowerCase().contains("pipe")) + .map(r -> r.getResource()) + .findFirst().orElse(null); + + if (pipe == null) { + pipe = Simantics.getSession().syncRequest(new PossibleResource("http://DistrictComponents@C/dh_pipe@1")); + } + } catch (DatabaseException e) { + LOGGER.error("Failed to read district component types for active model", e); + } + + LOGGER.debug("Pipe component type is {}", pipe); + + String data = null; + try { + Resource model = Simantics.getSession().syncRequest(new PossibleActiveModel(Simantics.getProjectResource())); + if (model != null) + data = Simantics.getSession().syncRequest(new PossibleTechTypeTableData(model, pipe), TransientCacheListener.instance()); + } catch (DatabaseException e) { + LOGGER.error("Failed to read tech type table data for {}", pipe, e); + } + + table = new TechTypeTable(parent, 0, pipe, data); } - + @PreDestroy public void dispose() { table.dispose();