]> gerrit.simantics Code Review - simantics/district.git/blob - org.simantics.district.network.ui/src/org/simantics/district/network/ui/techtype/table/ValidateTechTypeTableHandler.java
8438fd7b3898cb0000cda112fa13a299549ea5c5
[simantics/district.git] / org.simantics.district.network.ui / src / org / simantics / district / network / ui / techtype / table / ValidateTechTypeTableHandler.java
1 package org.simantics.district.network.ui.techtype.table;
2
3 import java.util.Set;
4
5 import javax.inject.Named;
6
7 import org.eclipse.e4.core.di.annotations.CanExecute;
8 import org.eclipse.e4.core.di.annotations.Execute;
9 import org.eclipse.e4.ui.services.IServiceConstants;
10 import org.eclipse.jface.dialogs.MessageDialog;
11 import org.eclipse.swt.widgets.Shell;
12 import org.simantics.db.Resource;
13 import org.simantics.db.exception.DatabaseException;
14 import org.simantics.district.network.techtype.TechTypeValidationUtils;
15 import org.simantics.utils.ui.ExceptionUtils;
16
17 public class ValidateTechTypeTableHandler {
18         @CanExecute
19         public boolean canExecute() {
20                 return TechTypeTableView.table.getCurrentTable() != null;
21         }
22         
23         @Execute
24         public void execute(@Named(IServiceConstants.ACTIVE_SHELL) Shell s) {
25                 Resource table = TechTypeTableView.table.getCurrentTable();
26                 if (table == null)
27                         return;
28                 
29                 Set<String> result;
30                 try {
31                         result = TechTypeValidationUtils.validateTechTypeTable(table);
32                 } catch (DatabaseException e) {
33                         ExceptionUtils.logAndShowError("Tech type table validation failed", e);
34                         return;
35                 }
36                 
37                 TechTypeTableView.table.setValidationResult(result);
38                 
39                 MessageDialog.openInformation(s, "Validation result", result.isEmpty() ?
40                                 "No invalid values found" : result.size() + " invalid values found");
41         }
42 }