]> gerrit.simantics Code Review - simantics/3d.git/blob - org.simantics.plant3d/src/org/simantics/plant3d/actions/AddEquipmentAction2.java
Adding specified equipment with nozzles did not work
[simantics/3d.git] / org.simantics.plant3d / src / org / simantics / plant3d / actions / AddEquipmentAction2.java
1 package org.simantics.plant3d.actions;
2
3 import org.eclipse.jface.action.Action;
4 import org.simantics.plant3d.scenegraph.Equipment;
5 import org.simantics.plant3d.scenegraph.P3DRootNode;
6 import org.simantics.plant3d.utils.ComponentUtils;
7 import org.simantics.plant3d.utils.Item;
8 import org.simantics.utils.ui.ExceptionUtils;
9
10 /**
11  * Action that creates given Equipment.
12  * 
13  * @author luukkainen
14  *
15  */
16 public class AddEquipmentAction2 extends Action {
17
18         P3DRootNode root;
19         private Item item;
20         private Item nozzleItem;
21         
22         public AddEquipmentAction2(P3DRootNode root, Item item) {
23             this(root, item, null);
24         }
25         
26         public AddEquipmentAction2(P3DRootNode root, Item item, Item nozzleItem) {
27                 this.root = root;
28                 this.item = item;
29                 this.nozzleItem = nozzleItem;
30                 setText("Add " + item.getName());
31         }
32         
33         @Override
34         public void run() {
35                 try {
36                     Equipment equipment = null;
37                     if (nozzleItem == null)
38                         equipment = ComponentUtils.createEquipment(root, item);
39                     else
40                         equipment = ComponentUtils.createEquipmentWithNozzles(root, item, nozzleItem);
41                         root.getNodeMap().commit("Add equipment " + equipment.getName());
42                 } catch (Exception e) {
43                         ExceptionUtils.logAndShowError("Cannot create equipment",e);
44                 }
45         }
46 }