1 package fi.vtt.simantics.processeditor.tools;
\r
3 import java.util.ArrayList;
\r
4 import java.util.Collection;
\r
5 import java.util.List;
\r
7 import org.eclipse.jface.action.Action;
\r
8 import org.eclipse.jface.action.IContributionItem;
\r
9 import org.eclipse.jface.action.IMenuManager;
\r
10 import org.eclipse.jface.action.IToolBarManager;
\r
11 import org.eclipse.swt.SWT;
\r
12 import org.eclipse.swt.layout.FillLayout;
\r
13 import org.eclipse.swt.layout.FormAttachment;
\r
14 import org.eclipse.swt.layout.FormData;
\r
15 import org.eclipse.swt.layout.FormLayout;
\r
16 import org.eclipse.swt.widgets.Button;
\r
17 import org.eclipse.swt.widgets.Composite;
\r
18 import org.eclipse.swt.widgets.Label;
\r
19 import org.eclipse.swt.widgets.Text;
\r
20 import org.simantics.db.Graph;
\r
21 import org.simantics.db.Resource;
\r
22 import org.simantics.proconf.g3d.actions.ContextAction;
\r
23 import org.simantics.proconf.g3d.base.EditorContribution;
\r
24 import org.simantics.proconf.g3d.base.ThreeDimensionalEditorBase;
\r
25 import org.simantics.proconf.g3d.common.StructuredResourceSelection;
\r
27 import fi.vtt.simantics.processeditor.ProcessResource;
\r
29 public class NozzleContribution implements EditorContribution {
\r
30 private List<ContextAction> actions = new ArrayList<ContextAction>();
\r
31 private ThreeDimensionalEditorBase parent;
\r
32 private Resource equipmentResource;
\r
33 private Composite sideComposite;
\r
35 public NozzleContribution(ThreeDimensionalEditorBase parent) {
\r
36 this.parent = parent;
\r
40 public void createControl(Composite parent) {
\r
41 FormLayout flayout = new FormLayout();
\r
42 parent.setLayout(flayout);
\r
43 sideComposite = new Composite(parent,SWT.BORDER);
\r
44 FormData data = new FormData();
\r
45 data.top = new FormAttachment(0, 0);
\r
46 data.left = new FormAttachment(0, 0);
\r
47 data.right = new FormAttachment(sideComposite, 0, SWT.LEFT);
\r
48 data.bottom = new FormAttachment(100,0);
\r
49 this.parent.getRenderingComposite().setLayoutData(data);
\r
50 sideComposite.setLayout(new FillLayout(SWT.VERTICAL));
\r
51 data = new FormData();
\r
52 data.top = new FormAttachment(0, 0);
\r
53 data.bottom = new FormAttachment(100,0);
\r
54 data.right = new FormAttachment(100,0);
\r
55 sideComposite.setLayoutData(data);
\r
58 Button addButton = new Button(sideComposite,SWT.PUSH);
\r
59 addButton.setText("Add Nozzle");
\r
60 Label label = new Label(sideComposite,SWT.NONE);
\r
61 label.setText("Restrictions:");
\r
62 Button minButton = new Button(sideComposite,SWT.CHECK);
\r
63 minButton.setText("Min");
\r
64 Text minText = new Text(sideComposite,SWT.SINGLE | SWT.BORDER);
\r
65 Button maxButton = new Button(sideComposite,SWT.CHECK);
\r
66 maxButton.setText("Max");
\r
67 Text maxText = new Text(sideComposite,SWT.SINGLE | SWT.BORDER);
\r
68 minText.setToolTipText("Enter minimum number of nozzles");
\r
69 maxText.setToolTipText("Enter maximum number of nozzles");
\r
74 public void disposeControl() {
\r
75 sideComposite.dispose();
\r
79 public void fillContextMenu(Graph graph, IMenuManager manager,
\r
80 StructuredResourceSelection selection) {
\r
85 public void fillLocalPullDown(IMenuManager manager) {
\r
90 public void fillLocalToolBar(IToolBarManager manager) {
\r
95 public Collection<ContextAction> getActions() {
\r
100 public String getName() {
\r
104 private void showNozzles(boolean show) {
\r
109 public void initialize(Graph graph) {
\r
110 Resource modelResource = parent.getInputResource();
\r
111 Resource inverse = graph.getInverse(ProcessResource.plant3Dresource.HasGraphics);
\r
112 Collection<Resource> equipment = graph.getObjects(modelResource, inverse);
\r
113 if (equipment.size() != 1)
\r
114 throw new RuntimeException("Cannot find equipment");
\r
115 equipmentResource = equipment.iterator().next();
\r
119 public void dispose() {
\r
120 showNozzles(false);
\r
124 public void run() {
\r