package org.simantics.plant3d.actions; import org.eclipse.jface.action.Action; import org.eclipse.swt.widgets.Display; import org.simantics.plant3d.dialog.EquipmentSelectionDialog; import org.simantics.plant3d.scenegraph.Equipment; import org.simantics.plant3d.scenegraph.P3DRootNode; import org.simantics.plant3d.utils.ComponentUtils; import org.simantics.plant3d.utils.Item; import org.simantics.utils.ui.ExceptionUtils; /** * Action that allows user to choose added Equipment with a dialog. * * @author luukkainen * */ public class AddEquipmentAction extends Action { P3DRootNode root; private String libUri; public AddEquipmentAction(P3DRootNode root, String libUri) { this.root = root; this.libUri = libUri; setText("Add equipment"); } @Override public void run() { EquipmentSelectionDialog dialog = new EquipmentSelectionDialog(Display.getCurrent().getActiveShell(), root, libUri); if (dialog.open() == EquipmentSelectionDialog.CANCEL) return; Item item = dialog.getSelected(); if (item == null) return; Item selectedNozzle = dialog.getSelectedNozzle(); try { Equipment equipment = null; if (selectedNozzle == null) equipment = ComponentUtils.createEquipment(root, item); else equipment = ComponentUtils.createEquipmentWithNozzles(root, item, selectedNozzle); root.getNodeMap().commit("Add equipment " + equipment.getName()); } catch (Exception e) { ExceptionUtils.logAndShowError("Cannot create equipment",e); } } }