package org.simantics.plant3d.actions; import org.eclipse.jface.action.Action; import org.simantics.plant3d.Activator; import org.simantics.plant3d.scenegraph.Equipment; import org.simantics.plant3d.scenegraph.Nozzle; import org.simantics.plant3d.scenegraph.P3DRootNode; import org.simantics.plant3d.scenegraph.PipeRun; import org.simantics.plant3d.utils.Item; import org.simantics.utils.ui.ExceptionUtils; public class AddNozzleAction extends Action { P3DRootNode root; private Item item; private Equipment equipment; public AddNozzleAction(P3DRootNode root, Item item) { this.root = root; this.item = item; setText("Add " + item.getName()); setImageDescriptor(Activator.imageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/Nozzle.png")); } public void setEquipment(Equipment equipment) { this.equipment = equipment; } @Override public void run() { try { Nozzle nozzle = root.createNozzle(); nozzle.setType(item.getUri()); String n = root.getUniqueName(item.getName()); nozzle.setName(n); PipeRun pipeRun = new PipeRun(); n = root.getUniqueName("PipeRun"); pipeRun.setName(n); nozzle.setPipeRun(pipeRun); equipment.addChild(nozzle); //root.addChild(nozzle); root.addChild(pipeRun); root.getNodeMap().commit(); } catch (Exception e) { ExceptionUtils.logAndShowError("Cannot create equipment",e); } } }