]> gerrit.simantics Code Review - simantics/district.git/blob - org.simantics.district.network.ui/src/org/simantics/district/network/ui/techtype/table/ValidateTechTypeTableHandler.java
Fix NPEs in tech type command handlers' canExecute()
[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 != null &&
21                                 TechTypeTableView.table.getCurrentTable() != null &&
22                                 TechTypeTableView.table.getComponentType() != null;
23         }
24         
25         @Execute
26         public void execute(@Named(IServiceConstants.ACTIVE_SHELL) Shell s) {
27                 Resource table = TechTypeTableView.table.getCurrentTable();
28                 if (table == null)
29                         return;
30                 
31                 Set<String> result;
32                 try {
33                         result = TechTypeValidationUtils.validateTechTypeTable(table);
34                 } catch (DatabaseException e) {
35                         ExceptionUtils.logAndShowError("Tech type table validation failed", e);
36                         return;
37                 }
38                 
39                 TechTypeTableView.table.setValidationResult(result);
40                 
41                 MessageDialog.openInformation(s, "Validation result", result.isEmpty() ?
42                                 "No invalid values found" : result.size() + " invalid values found");
43         }
44 }