1 package org.simantics.plant3d.actions;
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;
13 * Action that allows user to choose added Equipment with a dialog.
18 public class AddEquipmentAction extends Action {
22 private String libUri;
24 public AddEquipmentAction(P3DRootNode root, String libUri) {
27 setText("Add equipment");
32 EquipmentSelectionDialog dialog = new EquipmentSelectionDialog(Display.getCurrent().getActiveShell(), root, libUri);
33 if (dialog.open() == EquipmentSelectionDialog.CANCEL)
35 Item item = dialog.getSelected();
38 Item selectedNozzle = dialog.getSelectedNozzle();
40 Equipment equipment = null;
41 if (selectedNozzle == null)
42 equipment = ComponentUtils.createEquipment(root, item);
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);