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%2FValidateTechTypeTableHandler.java;fp=org.simantics.district.network.ui%2Fsrc%2Forg%2Fsimantics%2Fdistrict%2Fnetwork%2Fui%2Ftechtype%2Ftable%2FValidateTechTypeTableHandler.java;h=8438fd7b3898cb0000cda112fa13a299549ea5c5;hb=7d3e650a2d3891988e7d0ef83fcb3b283a226d09;hp=0000000000000000000000000000000000000000;hpb=99bc656915a53349cf33f66bfcb2ccdedc92cea1;p=simantics%2Fdistrict.git diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/techtype/table/ValidateTechTypeTableHandler.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/techtype/table/ValidateTechTypeTableHandler.java new file mode 100644 index 00000000..8438fd7b --- /dev/null +++ b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/techtype/table/ValidateTechTypeTableHandler.java @@ -0,0 +1,42 @@ +package org.simantics.district.network.ui.techtype.table; + +import java.util.Set; + +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.TechTypeValidationUtils; +import org.simantics.utils.ui.ExceptionUtils; + +public class ValidateTechTypeTableHandler { + @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; + + Set result; + try { + result = TechTypeValidationUtils.validateTechTypeTable(table); + } catch (DatabaseException e) { + ExceptionUtils.logAndShowError("Tech type table validation failed", e); + return; + } + + TechTypeTableView.table.setValidationResult(result); + + MessageDialog.openInformation(s, "Validation result", result.isEmpty() ? + "No invalid values found" : result.size() + " invalid values found"); + } +}