]> gerrit.simantics Code Review - simantics/district.git/blobdiff - org.simantics.district.network.ui/src/org/simantics/district/network/ui/techtype/table/TechTypeTableView.java
Tech type table content validation
[simantics/district.git] / org.simantics.district.network.ui / src / org / simantics / district / network / ui / techtype / table / TechTypeTableView.java
index 15b31784fae96db7579e4f99a65521a68f2e301a..6c25251c344da677ea4459de21be02db14533979 100644 (file)
@@ -21,8 +21,8 @@ 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.techtype.requests.PossibleTechTypeTable;
 import org.simantics.district.network.techtype.requests.PossibleTechTypeTableData;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -42,9 +42,20 @@ public class TechTypeTableView {
                MToolBar toolBar = MMenuFactory.INSTANCE.createToolBar();
                toolBar.setToBeRendered(true);
                toolBar.getChildren().add(createImportCSVDataToolItem(app));
+               toolBar.getChildren().add(createValidateTableToolItem(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
@@ -65,10 +76,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);
                }
@@ -76,15 +83,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