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=8f4b57c98b88384bbfaa9f46594406ab7976c7eb;hb=f502933963c63185379cb5a6097e05c9263f2d1a;hp=42b88207c1881fe0b8b1735f7a10e843675a915c;hpb=ae7fa2cc4cfe235b2a392d6fb7e3038042ac4221;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 42b88207..8f4b57c9 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 @@ -13,6 +13,7 @@ import org.eclipse.e4.ui.model.application.ui.basic.MPart; import org.eclipse.e4.ui.model.application.ui.menu.MHandledToolItem; 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.model.application.ui.menu.MToolBarElement; import org.eclipse.e4.ui.workbench.modeling.ESelectionService; import org.eclipse.swt.widgets.Composite; import org.simantics.Simantics; @@ -21,9 +22,9 @@ 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.simantics.district.network.techtype.requests.PossibleTechTypeTable; +import org.simantics.district.network.techtype.requests.PossibleTechTypeTableData; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -31,6 +32,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; @@ -40,9 +43,21 @@ public class TechTypeTableView { MToolBar toolBar = MMenuFactory.INSTANCE.createToolBar(); toolBar.setToBeRendered(true); toolBar.getChildren().add(createImportCSVDataToolItem(app)); + toolBar.getChildren().add(createValidateTableToolItem(app)); + toolBar.getChildren().add(createResetComponentsItem(app)); part.setToolbar(toolBar); } + private MHandledToolItem createValidateTableToolItem(MApplication app) { + MHandledToolItem createHandledToolItem = MMenuFactory.INSTANCE.createHandledToolItem(); + // Command is contributed via fragment + MCommand command = app.getCommand("org.simantics.district.network.ui.command.validatetechtypetable"); + createHandledToolItem.setCommand(command); //$NON-NLS-1$ + createHandledToolItem.setLabel("Validate Tech Type Table"); + createHandledToolItem.setIconURI("platform:/plugin/com.famfamfam.silk/icons/accept.png"); //$NON-NLS-1$ + return createHandledToolItem; + } + private MHandledToolItem createImportCSVDataToolItem(MApplication app) { MHandledToolItem createHandledToolItem = MMenuFactory.INSTANCE.createHandledToolItem(); // Command is contributed via fragment @@ -53,6 +68,16 @@ public class TechTypeTableView { return createHandledToolItem; } + private MToolBarElement createResetComponentsItem(MApplication app) { + MHandledToolItem createHandledToolItem = MMenuFactory.INSTANCE.createHandledToolItem(); + // Command is contributed via fragment + MCommand command = app.getCommand("org.simantics.district.network.ui.command.resetcomponentproperties"); + createHandledToolItem.setCommand(command); //$NON-NLS-1$ + createHandledToolItem.setLabel("Reset Component Properties"); + createHandledToolItem.setIconURI("platform:/plugin/com.famfamfam.silk/icons/database_go.png"); //$NON-NLS-1$ + return createHandledToolItem; + } + @PostConstruct public void postConstruct(Composite parent) { Resource pipe = null; @@ -63,10 +88,6 @@ public class TechTypeTableView { .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); } @@ -74,15 +95,20 @@ public class TechTypeTableView { 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); + Resource tableResource = null; + if (pipe != null) { + try { + Resource model = Simantics.getSession().syncRequest(new PossibleActiveModel(Simantics.getProjectResource())); + if (model != null) { + tableResource = Simantics.getSession().syncRequest(new PossibleTechTypeTable(model, pipe), TransientCacheListener.instance()); + 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); + table = new TechTypeTable(parent, 0, pipe, tableResource, data); } @PreDestroy