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%2FResetComponentsHandler.java;fp=org.simantics.district.network.ui%2Fsrc%2Forg%2Fsimantics%2Fdistrict%2Fnetwork%2Fui%2Ftechtype%2Ftable%2FResetComponentsHandler.java;h=a95ecec4fd62901a673a058e5cad5633f766b650;hb=9419a042ed963c52ae6f003ef330e7ffde9a08d5;hp=0000000000000000000000000000000000000000;hpb=35ecae565400a65c199ebb0c2e76eae4d3bf68cf;p=simantics%2Fdistrict.git 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); + } + } + +}