1 | package de.uka.ipd.sdq.pcm.gmf.repository.helper; |
2 | |
3 | import org.eclipse.gmf.runtime.common.core.command.ICommand; |
4 | import org.eclipse.gmf.runtime.emf.type.core.commands.SetValueCommand; |
5 | import org.eclipse.gmf.runtime.emf.type.core.edithelper.AbstractEditHelperAdvice; |
6 | import org.eclipse.gmf.runtime.emf.type.core.edithelper.IEditHelperAdvice; |
7 | import org.eclipse.gmf.runtime.emf.type.core.requests.ConfigureRequest; |
8 | import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest; |
9 | |
10 | import de.uka.ipd.sdq.pcm.core.entity.EntityPackage; |
11 | import de.uka.ipd.sdq.pcm.repository.InfrastructureProvidedRole; |
12 | import de.uka.ipd.sdq.pcm.repository.InfrastructureRequiredRole; |
13 | import de.uka.ipd.sdq.pcm.repository.OperationProvidedRole; |
14 | import de.uka.ipd.sdq.pcm.repository.OperationRequiredRole; |
15 | import de.uka.ipd.sdq.pcm.repository.Role; |
16 | |
17 | public class RoleEditHelperAdvice extends AbstractEditHelperAdvice implements |
18 | IEditHelperAdvice { |
19 | |
20 | @Override |
21 | protected ICommand getAfterConfigureCommand(ConfigureRequest request) { |
22 | Role r = (Role) request.getElementToConfigure(); |
23 | String interfaceName = ""; |
24 | String componentName = ""; |
25 | String prefix = ""; |
26 | if (r instanceof OperationProvidedRole) { |
27 | OperationProvidedRole pr = (OperationProvidedRole) r; |
28 | interfaceName = pr.getProvidedInterface__OperationProvidedRole() == null ? "interface" |
29 | : pr.getProvidedInterface__OperationProvidedRole().getEntityName(); |
30 | componentName = pr.getProvidingEntity_ProvidedRole() == null ? "component" |
31 | : pr.getProvidingEntity_ProvidedRole().getEntityName(); |
32 | prefix = "Provided"; |
33 | } else if (r instanceof OperationRequiredRole) { |
34 | OperationRequiredRole rr = (OperationRequiredRole) r; |
35 | interfaceName = rr.getRequiredInterface__OperationRequiredRole() == null ? "interface" |
36 | : rr.getRequiredInterface__OperationRequiredRole().getEntityName(); |
37 | componentName = rr.getRequiringEntity_RequiredRole() == null ? "component" |
38 | : rr.getRequiringEntity_RequiredRole().getEntityName(); |
39 | prefix = "Required"; |
40 | } else if (r instanceof InfrastructureProvidedRole) { |
41 | InfrastructureProvidedRole pr = (InfrastructureProvidedRole) r; |
42 | interfaceName = pr.getProvidedInterface__InfrastructureProvidedRole() == null ? "infrastructureInterface" |
43 | : pr.getProvidedInterface__InfrastructureProvidedRole().getEntityName(); |
44 | componentName = pr.getProvidingEntity_ProvidedRole() == null ? "infrastructureComponent" |
45 | : pr.getProvidingEntity_ProvidedRole().getEntityName(); |
46 | prefix = "Provided"; |
47 | } else if (r instanceof InfrastructureRequiredRole) { |
48 | InfrastructureRequiredRole pr = (InfrastructureRequiredRole) r; |
49 | interfaceName = pr |
50 | .getRequiredInterface__InfrastructureRequiredRole() == null ? "infrastructureInterface" |
51 | : pr.getRequiredInterface__InfrastructureRequiredRole().getEntityName(); |
52 | componentName = pr.getRequiringEntity_RequiredRole() == null ? "infrastructureComponent" |
53 | : pr.getRequiringEntity_RequiredRole().getEntityName(); |
54 | prefix = "Required"; |
55 | } |
56 | SetRequest setRequest = new SetRequest(r, EntityPackage.eINSTANCE |
57 | .getNamedElement_EntityName(), prefix + "_" + interfaceName + "_" |
58 | + componentName); |
59 | return new SetValueCommand(setRequest); |
60 | } |
61 | |
62 | } |