Skip to main content
summaryrefslogtreecommitdiffstats
blob: 6d7d2500c9da7c5d37a004a6d82e419c8ac729c7 (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
/*****************************************************************************
 * Copyright (c) 2012 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:
 *		
 *		CEA LIST - Initial API and implementation
 *
 *****************************************************************************/
package org.eclipse.papyrus.sysml.diagram.common.edit.policy;

import java.util.Arrays;
import java.util.List;

import org.eclipse.emf.ecore.EObject;
import org.eclipse.gef.commands.Command;
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
import org.eclipse.gmf.runtime.emf.type.core.ISpecializationType;
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest;
import org.eclipse.papyrus.gmf.diagram.common.edit.policy.DefaultSemanticEditPolicy;
import org.eclipse.papyrus.infra.extendedtypes.types.IExtendedHintedElementType;
import org.eclipse.papyrus.infra.services.edit.commands.IConfigureCommandFactory;
import org.eclipse.papyrus.sysml.diagram.common.commands.CreateFlowPortWithFlowSpecificationConfigureCommandFactory;
import org.eclipse.papyrus.sysml.service.types.element.SysMLElementTypes;
import org.eclipse.papyrus.uml.service.types.element.UMLElementTypes;
import org.eclipse.uml2.uml.Property;
import org.eclipse.uml2.uml.Type;

/**
 * Semantic edit policy for Property owned by a Block (Part or Reference especially).
 */
@Deprecated
public class NestedBlockPropertyCompositeSemanticEditPolicy extends DefaultSemanticEditPolicy {

	/**
	 * {@inheritDoc}
	 */
	@Override
	protected Command getCreateCommand(CreateElementRequest req) {

		// Port - FlowPort creation is allowed if the semantic element is 
		// a Property typed by a Block, the new Port - FlowPort is created on this Block.
		EObject eObject = req.getContainer();
		if ((eObject != null) && (eObject instanceof Property)) {
			Type type = ((Property) eObject).getType();
			if ((type != null) && (((ISpecializationType)SysMLElementTypes.BLOCK).getMatcher().matches(type))) {
				

				IElementType elementTypeToCreate = req.getElementType();
				IElementType baseType = elementTypeToCreate;
				//if extended type, retrieve the sysml closest element element type
				if(elementTypeToCreate instanceof IExtendedHintedElementType) {
					List<IElementType> superTypes = Arrays.asList(elementTypeToCreate.getAllSuperTypes());
					if(superTypes.contains(SysMLElementTypes.FLOW_PORT)) {
						baseType = SysMLElementTypes.FLOW_PORT;
					} else if(superTypes.contains(SysMLElementTypes.FLOW_PORT_IN)) {
						baseType = SysMLElementTypes.FLOW_PORT_IN;
					} else if(superTypes.contains(SysMLElementTypes.FLOW_PORT_OUT)) {
						baseType = SysMLElementTypes.FLOW_PORT_OUT;
					} else if(superTypes.contains(SysMLElementTypes.FLOW_PORT_IN_OUT)) {
						baseType = SysMLElementTypes.FLOW_PORT_IN_OUT;
					} else if(superTypes.contains(SysMLElementTypes.FLOW_PORT_NA)) {
						baseType = SysMLElementTypes.FLOW_PORT_NA;
					}  else if(superTypes.contains(UMLElementTypes.PORT )) {
						baseType = UMLElementTypes.PORT ;
					} 
				}
				
				if((SysMLElementTypes.FLOW_PORT == baseType)
					|| (SysMLElementTypes.FLOW_PORT_IN == baseType)
					|| (SysMLElementTypes.FLOW_PORT_OUT == baseType)
					|| (SysMLElementTypes.FLOW_PORT_IN_OUT == baseType)
					|| (SysMLElementTypes.FLOW_PORT_NA == baseType)
					|| (UMLElementTypes.PORT == baseType)) {
					
					req.setContainer(type);
				}
				
				if(SysMLElementTypes.FLOW_PORT_NA == baseType) {
					req.setParameter(IConfigureCommandFactory.CONFIGURE_COMMAND_FACTORY_ID, new CreateFlowPortWithFlowSpecificationConfigureCommandFactory());
				}
			}
		}
		
		return super.getCreateCommand(req);
	}
}

Back to the top