From: Reino Ruusu Date: Wed, 23 Sep 2020 13:17:39 +0000 (+0300) Subject: Add UI for resetting component values X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=f502933963c63185379cb5a6097e05c9263f2d1a;p=simantics%2Fdistrict.git Add UI for resetting component values gitlab #93 Change-Id: I206d0eb815d06c66bd27ab48a0a33a28b02d0880 --- diff --git a/org.simantics.district.network.ui/fragment.e4xmi b/org.simantics.district.network.ui/fragment.e4xmi index 1ea9c909..db3597fc 100644 --- a/org.simantics.district.network.ui/fragment.e4xmi +++ b/org.simantics.district.network.ui/fragment.e4xmi @@ -18,6 +18,7 @@ + @@ -52,5 +53,6 @@ + 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 index 00000000..a95ecec4 --- /dev/null +++ b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/techtype/table/ResetComponentsHandler.java @@ -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); + } + } + +} 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 6c25251c..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; @@ -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;