]> gerrit.simantics Code Review - simantics/district.git/blob
a95ecec4fd62901a673a058e5cad5633f766b650
[simantics/district.git] /
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.getCurrentTable() != null;
20         }
21         
22         @Execute
23         public void execute(@Named(IServiceConstants.ACTIVE_SHELL) Shell s) {
24                 Resource table = TechTypeTableView.table.getCurrentTable();
25                 if (table == null)
26                         return;
27                 
28                 boolean result = MessageDialog.openConfirm(null, "Confirmation", "Do you really want to reset all component properties to values in this table?");
29                 if (result == false)
30                         return;
31                 
32                 try {
33                         TechTypeUtils.resetComponents(table);
34                 } catch (DatabaseException e) {
35                         ExceptionUtils.logAndShowError("Error resetting components.", e);
36                 }
37         }
38         
39 }