]> gerrit.simantics Code Review - simantics/district.git/commitdiff
Add UI for resetting component values 03/4503/1
authorReino Ruusu <reino.ruusu@semantum.fi>
Wed, 23 Sep 2020 13:17:39 +0000 (16:17 +0300)
committerReino Ruusu <reino.ruusu@semantum.fi>
Wed, 23 Sep 2020 13:17:39 +0000 (16:17 +0300)
gitlab #93

Change-Id: I206d0eb815d06c66bd27ab48a0a33a28b02d0880

org.simantics.district.network.ui/fragment.e4xmi
org.simantics.district.network.ui/src/org/simantics/district/network/ui/techtype/table/ResetComponentsHandler.java [new file with mode: 0644]
org.simantics.district.network.ui/src/org/simantics/district/network/ui/techtype/table/TechTypeTableView.java

index 1ea9c9098a5041e6d5033d6971e94c13bc67c9d5..db3597fc42985a17aec4775fa7953b9ac8f4cd0d 100644 (file)
@@ -18,6 +18,7 @@
     <elements xsi:type="commands:Command" xmi:id="_QcEKQIAGEemKlokjSaREFQ" elementId="org.simantics.district.network.ui.command.importcsv" commandName="Import CSV"/>
     <elements xsi:type="commands:Command" xmi:id="_VWtY8LqWEemcscVaZzEyWw" elementId="org.simantics.district.network.ui.command.importtechtypecsv" commandName="Import Tech Type CSV"/>
     <elements xsi:type="commands:Command" xmi:id="_dN5OYPaJEeqB1-l6EhcCjg" elementId="org.simantics.district.network.ui.command.validatetechtypetable" commandName="Validate Tech Type Table"/>
+    <elements xsi:type="commands:Command" xmi:id="_fzvVQP2aEeqB1-l6EhcCjg" elementId="org.simantics.district.network.ui.command.resetcomponentproperties" commandName="Reset Component Properties"/>
   </fragments>
   <fragments xsi:type="fragment:StringModelFragment" xmi:id="_Js7rUMMAEea1mdgpHNVHMA" featurename="menuContributions" parentElementId="xpath:/">
     <elements xsi:type="menu:MenuContribution" xmi:id="_T-jiEN8NEeaigNyzMJBOrg" elementId="org.simantics.district.network.ui.menucontribution.districtDiagramPopup" parentId="#DistrictDiagramPopup">
@@ -52,5 +53,6 @@
     <elements xsi:type="commands:Handler" xmi:id="_akE8EIAGEemKlokjSaREFQ" elementId="org.simantics.district.network.ui.handler.9" contributionURI="bundleclass://org.simantics.district.network.ui/org.simantics.district.network.ui.table.ImportCSVHandler" command="_QcEKQIAGEemKlokjSaREFQ"/>
     <elements xsi:type="commands:Handler" xmi:id="_XjbIILqWEemcscVaZzEyWw" elementId="org.simantics.district.network.ui.handler.10" contributionURI="bundleclass://org.simantics.district.network.ui/org.simantics.district.network.ui.table.ImportTechTypeCSVHandler" command="_VWtY8LqWEemcscVaZzEyWw"/>
     <elements xsi:type="commands:Handler" xmi:id="_luZP0PaJEeqB1-l6EhcCjg" elementId="org.simantics.district.network.ui.handler.11" contributionURI="bundleclass://org.simantics.district.network.ui/org.simantics.district.network.ui.techtype.table.ValidateTechTypeTableHandler" command="_dN5OYPaJEeqB1-l6EhcCjg"/>
+    <elements xsi:type="commands:Handler" xmi:id="_nFUFcP2aEeqB1-l6EhcCjg" elementId="org.simantics.district.network.ui.handler.12" contributionURI="bundleclass://org.simantics.district.network.ui/org.simantics.district.network.ui.techtype.table.ResetComponentsHandler" command="_fzvVQP2aEeqB1-l6EhcCjg"/>
   </fragments>
 </fragment:ModelFragments>
diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/techtype/table/ResetComponentsHandler.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/techtype/table/ResetComponentsHandler.java
new file mode 100644 (file)
index 0000000..a95ecec
--- /dev/null
@@ -0,0 +1,39 @@
+package org.simantics.district.network.ui.techtype.table;
+
+import javax.inject.Named;
+
+import org.eclipse.e4.core.di.annotations.CanExecute;
+import org.eclipse.e4.core.di.annotations.Execute;
+import org.eclipse.e4.ui.services.IServiceConstants;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.swt.widgets.Shell;
+import org.simantics.db.Resource;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.district.network.techtype.TechTypeUtils;
+import org.simantics.utils.ui.ExceptionUtils;
+
+public class ResetComponentsHandler {
+
+       @CanExecute
+       public boolean canExecute() {
+               return TechTypeTableView.table.getCurrentTable() != null;
+       }
+       
+       @Execute
+       public void execute(@Named(IServiceConstants.ACTIVE_SHELL) Shell s) {
+               Resource table = TechTypeTableView.table.getCurrentTable();
+               if (table == null)
+                       return;
+               
+               boolean result = MessageDialog.openConfirm(null, "Confirmation", "Do you really want to reset all component properties to values in this table?");
+               if (result == false)
+                       return;
+               
+               try {
+                       TechTypeUtils.resetComponents(table);
+               } catch (DatabaseException e) {
+                       ExceptionUtils.logAndShowError("Error resetting components.", e);
+               }
+       }
+       
+}
index 6c25251c344da677ea4459de21be02db14533979..8f4b57c98b88384bbfaa9f46594406ab7976c7eb 100644 (file)
@@ -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;
@@ -43,6 +44,7 @@ public class TechTypeTableView {
                toolBar.setToBeRendered(true);
                toolBar.getChildren().add(createImportCSVDataToolItem(app));
                toolBar.getChildren().add(createValidateTableToolItem(app));
+               toolBar.getChildren().add(createResetComponentsItem(app));
                part.setToolbar(toolBar);
        }
 
@@ -66,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;