]> gerrit.simantics Code Review - simantics/district.git/blob - org.simantics.district.network.ui/src/org/simantics/district/network/ui/techtype/table/ResetComponentsHandler.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 / ResetComponentsHandler.java
1 package org.simantics.district.network.ui.techtype.table;
2
3 import javax.inject.Named;
4
5 import org.eclipse.e4.core.di.annotations.CanExecute;
6 import org.eclipse.e4.core.di.annotations.Execute;
7 import org.eclipse.e4.ui.services.IServiceConstants;
8 import org.eclipse.jface.dialogs.MessageDialog;
9 import org.eclipse.swt.widgets.Shell;
10 import org.simantics.db.Resource;
11 import org.simantics.db.exception.DatabaseException;
12 import org.simantics.district.network.techtype.TechTypeUtils;
13 import org.simantics.utils.ui.ExceptionUtils;
14
15 public class ResetComponentsHandler {
16
17         @CanExecute
18         public boolean canExecute() {
19                 return TechTypeTableView.table != null &&
20                         TechTypeTableView.table.getCurrentTable() != null &&
21                         TechTypeTableView.table.getComponentType() != null;
22         }
23         
24         @Execute
25         public void execute(@Named(IServiceConstants.ACTIVE_SHELL) Shell s) {
26                 Resource table = TechTypeTableView.table.getCurrentTable();
27                 if (table == null)
28                         return;
29                 
30                 boolean result = MessageDialog.openConfirm(null, "Confirmation", "Do you really want to reset all component properties to values in this table?");
31                 if (result == false)
32                         return;
33                 
34                 try {
35                         TechTypeUtils.resetComponents(table);
36                 } catch (DatabaseException e) {
37                         ExceptionUtils.logAndShowError("Error resetting components.", e);
38                 }
39         }
40         
41 }