1 package org.simantics.plant3d.dialog;
3 import java.util.HashSet;
7 import org.eclipse.jface.dialogs.Dialog;
8 import org.eclipse.jface.dialogs.IDialogConstants;
9 import org.eclipse.jface.layout.GridDataFactory;
10 import org.eclipse.jface.resource.JFaceResources;
11 import org.eclipse.jface.resource.LocalResourceManager;
12 import org.eclipse.jface.resource.ResourceManager;
13 import org.eclipse.jface.viewers.ISelectionChangedListener;
14 import org.eclipse.jface.viewers.IStructuredSelection;
15 import org.eclipse.jface.viewers.ListViewer;
16 import org.eclipse.jface.viewers.SelectionChangedEvent;
17 import org.eclipse.swt.SWT;
18 import org.eclipse.swt.layout.GridData;
19 import org.eclipse.swt.layout.GridLayout;
20 import org.eclipse.swt.widgets.Composite;
21 import org.eclipse.swt.widgets.Control;
22 import org.eclipse.swt.widgets.ExpandBar;
23 import org.eclipse.swt.widgets.ExpandItem;
24 import org.eclipse.swt.widgets.Label;
25 import org.eclipse.swt.widgets.Shell;
26 import org.simantics.db.exception.DatabaseException;
27 import org.simantics.plant3d.ontology.Plant3D;
28 import org.simantics.plant3d.scenegraph.Equipment;
29 import org.simantics.plant3d.scenegraph.InlineComponent;
30 import org.simantics.plant3d.scenegraph.Nozzle;
31 import org.simantics.plant3d.scenegraph.P3DRootNode;
32 import org.simantics.plant3d.scenegraph.PipelineComponent;
33 import org.simantics.plant3d.scenegraph.controlpoint.PipeControlPoint.PositionType;
34 import org.simantics.plant3d.utils.Item;
35 import org.simantics.plant3d.utils.P3DUtil;
36 import org.simantics.utils.ui.ExceptionUtils;
38 public class EquipmentSelectionDialog extends Dialog implements ISelectionChangedListener{
40 private ResourceManager resourceManager;
41 private String libUri;
42 private P3DRootNode root;
44 private Item selected;
45 private Item selectedNozzle;
47 ListViewer equipmentViewer;
48 ListViewer nozzleViewer;
50 public EquipmentSelectionDialog(Shell parentShell, P3DRootNode root) {
51 this(parentShell,root,Plant3D.URIs.Builtin);
54 public EquipmentSelectionDialog(Shell parentShell, P3DRootNode root, String libUri){
60 protected List<Item> getItems(Class c, String libUri) throws DatabaseException{
61 if (Equipment.class.equals(c)) {
62 return P3DUtil.getEquipments(libUri);
63 } else if (Nozzle.class.equals(c)) {
64 return P3DUtil.getNozzles(libUri);
70 protected Control createDialogArea(Composite parent) {
71 resourceManager = new LocalResourceManager(JFaceResources.getResources(), parent);
73 Composite composite = new Composite(parent, SWT.NONE);
74 GridLayout layout = new GridLayout(2,false);
75 layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
76 layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
77 layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
78 layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
79 composite.setLayout(layout);
80 composite.setLayoutData(new GridData(GridData.FILL_BOTH));
81 applyDialogFont(composite);
83 List<Item> equipment = null;
84 List<Item> nozzles = null;
86 equipment = getItems(Equipment.class, libUri);
87 nozzles = getItems(Nozzle.class, libUri);
88 } catch (DatabaseException e) {
89 Label label = new Label(composite, SWT.NONE);
90 label.setText("Cannot load equipment data: " + e.getMessage());
91 ExceptionUtils.logError(e);
94 ExpandBar expandBar = new ExpandBar(composite, SWT.NONE);
96 ExpandItem equipmentItem = new ExpandItem(expandBar, SWT.NONE);
98 equipmentItem.setText("Equipment");
99 equipmentViewer = new ListViewer(expandBar);
100 equipmentViewer.setLabelProvider(new ComponentLabelProvider());
101 equipmentViewer.setContentProvider(new ComponentContentProvider());
103 ExpandItem nozzleItem = new ExpandItem(expandBar, SWT.NONE);
105 nozzleItem.setText("Nozzles");
106 nozzleViewer = new ListViewer(expandBar);
107 nozzleViewer.setLabelProvider(new ComponentLabelProvider());
108 nozzleViewer.setContentProvider(new ComponentContentProvider());
110 equipmentItem.setControl(equipmentViewer.getList());
111 nozzleItem.setControl(nozzleViewer.getList());
113 equipmentViewer.setInput(equipment);
114 nozzleViewer.setInput(nozzles);
116 equipmentItem.setHeight(equipmentViewer.getList().computeSize(SWT.DEFAULT, SWT.DEFAULT).y);
117 nozzleItem.setHeight(nozzleViewer.getList().computeSize(SWT.DEFAULT, SWT.DEFAULT).y);
119 equipmentViewer.addSelectionChangedListener(this);
120 nozzleViewer.addSelectionChangedListener(this);
122 GridDataFactory.fillDefaults().grab(true, true).align(SWT.FILL, SWT.FILL).span(2, 1).applyTo(expandBar);
123 GridDataFactory.fillDefaults().minSize(500, 500).hint(500, 500).applyTo(composite);
129 public void selectionChanged(SelectionChangedEvent event) {
130 IStructuredSelection sel = (IStructuredSelection)event.getSelection();
131 Item i = (Item)sel.getFirstElement();
133 if (event.getSource() == equipmentViewer) {
135 } else if (event.getSource() == nozzleViewer) {
140 if (event.getSource() == equipmentViewer) {
142 } else if (event.getSource() == nozzleViewer) {
148 public Item getSelected() {
152 public Item getSelectedNozzle() {
153 return selectedNozzle;