Skip to main content
summaryrefslogtreecommitdiffstats
blob: e27f228d0d46f8f074bb427b80da9289f2bc7a52 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/*******************************************************************************
 * Copyright (c) 2011, 2012 Red Hat, Inc.
 *  All rights reserved.
 * This program is made available under the terms of the
 * Eclipse Public License v1.0 which accompanies this distribution,
 * and is available at http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 * Red Hat, Inc. - initial API and implementation
 *
 * @author Bob Brodt
 ******************************************************************************/

package org.eclipse.bpmn2.modeler.ui.property.diagrams;

import org.eclipse.bpmn2.Bpmn2Factory;
import org.eclipse.bpmn2.Bpmn2Package;
import org.eclipse.bpmn2.Participant;
import org.eclipse.bpmn2.ParticipantMultiplicity;
import org.eclipse.bpmn2.modeler.core.adapters.InsertionAdapter;
import org.eclipse.bpmn2.modeler.core.merrimac.clad.AbstractBpmn2PropertySection;
import org.eclipse.bpmn2.modeler.core.merrimac.clad.AbstractDetailComposite;
import org.eclipse.bpmn2.modeler.core.merrimac.clad.AbstractPropertiesProvider;
import org.eclipse.bpmn2.modeler.core.merrimac.clad.DefaultDetailComposite;
import org.eclipse.bpmn2.modeler.core.merrimac.dialogs.IntObjectEditor;
import org.eclipse.bpmn2.modeler.core.utils.ErrorUtils;
import org.eclipse.bpmn2.modeler.ui.property.data.InterfacePropertySection.ProvidedInterfaceListComposite;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;

/**
 * @author Bob Brodt
 *
 */
public class ParticipantDetailComposite extends DefaultDetailComposite {

	protected ProvidedInterfaceListComposite providedInterfacesTable;

	public ParticipantDetailComposite(Composite parent, int style) {
		super(parent, style);
	}

	/**
	 * @param section
	 */
	public ParticipantDetailComposite(AbstractBpmn2PropertySection section) {
		super(section);
	}

	@Override
	public AbstractPropertiesProvider getPropertiesProvider(EObject object) {
		if (propertiesProvider==null) {
			propertiesProvider = new AbstractPropertiesProvider(object) {
				String[] properties = new String[] {
						"processRef", //$NON-NLS-1$
						"participantMultiplicity", //$NON-NLS-1$
						"interfaceRefs", //$NON-NLS-1$
//						"endPointRefs", //$NON-NLS-1$
				};
				
				@Override
				public String[] getProperties() {
					return properties; 
				}
			};
		}
		return propertiesProvider;
	}

	@Override
	public void cleanBindings() {
		super.cleanBindings();
		providedInterfacesTable = null;
	}
	
	protected void bindReference(Composite parent, EObject object, EReference reference) {
		if (isModelObjectEnabled(object.eClass(), reference)) {
			if (parent==null)
				parent = getAttributesParent();

			Participant participant = (Participant) object;
			if ("participantMultiplicity".equals(reference.getName())) {
				Composite composite = getToolkit().createComposite(parent);
				composite.setLayout(new GridLayout(7,true));
				composite.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 3, 1));
				createLabel(composite,"Multiplicity");
				
				ParticipantMultiplicity pm =
						participant.getParticipantMultiplicity() != null ?
						participant.getParticipantMultiplicity() :
						Bpmn2Factory.eINSTANCE.createParticipantMultiplicity();
						
				InsertionAdapter.add(object, Bpmn2Package.eINSTANCE.getParticipant_ParticipantMultiplicity(), pm);
				
				MyIntObjectEditor minEditor = new MyIntObjectEditor(this, pm, Bpmn2Package.eINSTANCE.getParticipantMultiplicity_Minimum());
				minEditor.createControl(composite, "Minimum");
				
				MyIntObjectEditor maxEditor = new MyIntObjectEditor(this, pm, Bpmn2Package.eINSTANCE.getParticipantMultiplicity_Maximum());
				maxEditor.createControl(composite, "Maximum");
				
				minEditor.updateText();
			}
			else if ("interfaceRefs".equals(reference.getName())) {
				providedInterfacesTable = new ProvidedInterfaceListComposite(this);
				providedInterfacesTable.bindList(object, getFeature(object, "interfaceRefs")); //$NON-NLS-1$
			}
			else {
				super.bindReference(parent, object, reference);
			}
		}
	}
	
	private class MyIntObjectEditor extends IntObjectEditor {

		public MyIntObjectEditor(AbstractDetailComposite parent,
				EObject object, EStructuralFeature feature) {
			super(parent, object, feature);
		}

		public void updateText() {
			super.updateText();
			ParticipantMultiplicity pm = (ParticipantMultiplicity) object;
			if (pm.getMinimum() >= pm.getMaximum()) {
				ErrorUtils.showErrorMessage("Minimum must be less than Maximum");
			}
		}
	}
}

Back to the top