Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 5d045c41f03551ee5371d213de044335bbb0b738 (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
/*****************************************************************************
 * Copyright (c) 2015 CEA LIST.
 *
 * All rights reserved. This program and the accompanying materials
 * are 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:
 *  Celine JANSSENS (ALL4TEC) celine.janssens@all4tec.net - Initial API and implementation
 *****************************************************************************/
package org.eclipse.papyrusrt.umlrt.tooling.diagram.common.editparts.providers;

import java.util.HashMap;
import java.util.Map;

import org.eclipse.emf.ecore.EObject;
import org.eclipse.gmf.runtime.common.core.service.IOperation;
import org.eclipse.gmf.runtime.diagram.ui.services.editpart.AbstractEditPartProvider;
import org.eclipse.gmf.runtime.diagram.ui.services.editpart.CreateGraphicEditPartOperation;
import org.eclipse.gmf.runtime.diagram.ui.services.editpart.IEditPartOperation;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.papyrus.uml.diagram.composite.edit.parts.ClassCompositeEditPart;
import org.eclipse.papyrus.uml.diagram.composite.edit.parts.PropertyPartEditPartCN;
import org.eclipse.papyrusrt.umlrt.core.utils.CapsulePartUtils;
import org.eclipse.papyrusrt.umlrt.core.utils.CapsuleUtils;
import org.eclipse.papyrusrt.umlrt.tooling.diagram.common.editparts.RTClassCompositeEditPart;
import org.eclipse.papyrusrt.umlrt.tooling.diagram.common.editparts.RTPropertyPartEditPart;
import org.eclipse.uml2.uml.Classifier;
import org.eclipse.uml2.uml.Property;


/**
 * The Class RTEditPartProvider provide the editParts for the Real Time specification.
 * This is applied for the Composite Structure Diagram
 */
public class RTEditPartProvider extends AbstractEditPartProvider {

	/** The provides only provides for this diagram type. */
	protected String diagramType = org.eclipse.papyrus.uml.diagram.composite.edit.parts.CompositeStructureDiagramEditPart.MODEL_ID;

	/** Map containing node view types supported by this provider. */
	protected Map<String, Class<?>> nodeMap = new HashMap<String, Class<?>>();

	/** Map containing edge view types supported by this provider. */
	protected Map<String, Class<?>> edgeMap = new HashMap<String, Class<?>>();

	/**
	 * Default constructor.
	 */
	public RTEditPartProvider() {
		super();

		// Nodes
		nodeMap.put(ClassCompositeEditPart.VISUAL_ID, RTClassCompositeEditPart.class);
		nodeMap.put(PropertyPartEditPartCN.VISUAL_ID, RTPropertyPartEditPart.class);

	}

	/**
	 * Provides.
	 *
	 * @param operation
	 *            the operation
	 * @return true, if successful
	 * @see org.eclipse.gmf.runtime.diagram.ui.services.editpart.AbstractEditPartProvider#provides(org.eclipse.gmf.runtime.common.core.service.IOperation)
	 */
	@Override
	public boolean provides(IOperation operation) {

		boolean provide = false;
		String currentDiagramType;
		EObject referenceElement = ((IEditPartOperation) operation).getView().getElement();

		// Test Capsule in Composite Structure Diagram
		if ((operation instanceof CreateGraphicEditPartOperation) && (referenceElement instanceof Classifier) && (CapsuleUtils.isCapsule((Classifier) referenceElement))) {

			currentDiagramType = ((IEditPartOperation) operation).getView().getDiagram().getType();

			if ((diagramType == null) || (!diagramType.equals(currentDiagramType))) {
				provide = false;
			} else {
				provide = super.provides(operation);
			}


		}

		// Test Capsule Part in Composite Structure Diagram
		if ((operation instanceof CreateGraphicEditPartOperation) && (referenceElement instanceof Property) && (CapsulePartUtils.isCapsulePart((Property) referenceElement))) {

			currentDiagramType = ((IEditPartOperation) operation).getView().getDiagram().getType();

			if ((diagramType == null) || (!diagramType.equals(currentDiagramType))) {
				provide = false;
			} else {
				provide = super.provides(operation);
			}


		}


		return provide;

	}

	/**
	 * Gets the node edit part class.
	 *
	 * @param view
	 *            the view
	 * @return the node edit part class
	 * @see org.eclipse.gmf.runtime.diagram.ui.services.editpart.AbstractEditPartProvider#getNodeEditPartClass(org.eclipse.gmf.runtime.notation.View)
	 */
	@Override
	protected Class getNodeEditPartClass(View view) {

		return nodeMap.get(view.getType());
	}

}

Back to the top