]> gerrit.simantics Code Review - simantics/3d.git/blob - org.simantics.plant3d/src/org/simantics/plant3d/actions/AddEquipmentAction.java
Remove dependencies on log4j
[simantics/3d.git] / org.simantics.plant3d / src / org / simantics / plant3d / actions / AddEquipmentAction.java
1 package org.simantics.plant3d.actions;
2
3 import org.eclipse.jface.action.Action;
4 import org.eclipse.swt.widgets.Display;
5 import org.simantics.plant3d.dialog.EquipmentSelectionDialog;
6 import org.simantics.plant3d.scenegraph.Equipment;
7 import org.simantics.plant3d.scenegraph.P3DRootNode;
8 import org.simantics.plant3d.utils.ComponentUtils;
9 import org.simantics.plant3d.utils.Item;
10 import org.simantics.utils.ui.ExceptionUtils;
11
12 /**
13  * Action that allows user to choose added Equipment with a dialog.
14  * 
15  * @author luukkainen
16  *
17  */
18 public class AddEquipmentAction extends Action {
19
20         P3DRootNode root;
21         
22         private String libUri;
23         
24         public AddEquipmentAction(P3DRootNode root, String libUri) {
25                 this.root = root;
26                 this.libUri = libUri;
27                 setText("Add equipment");
28         }
29         
30         @Override
31         public void run() {
32             EquipmentSelectionDialog dialog = new EquipmentSelectionDialog(Display.getCurrent().getActiveShell(), root, libUri);
33             if (dialog.open() == EquipmentSelectionDialog.CANCEL)
34                 return;
35             Item item = dialog.getSelected();
36             if (item == null)
37                 return;
38             Item selectedNozzle = dialog.getSelectedNozzle();
39                 try {
40                     Equipment equipment = null;
41                     if (selectedNozzle == null)
42                         equipment = ComponentUtils.createEquipment(root, item);
43                     else
44                         equipment = ComponentUtils.createEquipmentWithNozzles(root, item, selectedNozzle);
45                         root.getNodeMap().commit("Add equipment " + equipment.getName());
46                 } catch (Exception e) {
47                         ExceptionUtils.logAndShowError("Cannot create equipment",e);
48                 }
49         }
50 }