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
|
/*****************************************************************************
* Copyright (c) 2010 CEA
*
*
* 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:
* Soyatec - Initial API and implementation
*
*****************************************************************************/
package org.eclipse.papyrus.uml.diagram.sequence.command;
import java.util.Map;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.gmf.runtime.common.core.command.CommandResult;
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest;
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest;
import org.eclipse.papyrus.uml.diagram.sequence.edit.commands.Message2CreateCommand;
import org.eclipse.papyrus.uml.diagram.sequence.edit.policies.UMLBaseItemSemanticEditPolicy;
import org.eclipse.papyrus.uml.diagram.sequence.util.CommandHelper;
import org.eclipse.papyrus.uml.diagram.sequence.util.MessageConnectionHelper;
import org.eclipse.papyrus.uml.diagram.sequence.util.OccurrenceSpecificationHelper;
import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.ExecutionOccurrenceSpecification;
import org.eclipse.uml2.uml.ExecutionSpecification;
import org.eclipse.uml2.uml.Message;
import org.eclipse.uml2.uml.MessageSort;
/**
* @author Jin Liu (jin.liu@soyatec.com)
*/
public class CustomMessage2CreateCommand extends Message2CreateCommand {
/**
* Message for create link error
*/
private static final String CREATE_LINK_ERROR_MSG = "Invalid arguments in create link command"; //$NON-NLS-1$
/**
* Message for no container error
*/
private static final String NO_CONTAINER_ERROR_MSG = "There is now valid container for events"; //$NON-NLS-1$
/**
* Constructor.
*
* @param request
* @param source
* @param target
*/
public CustomMessage2CreateCommand(CreateRelationshipRequest request, EObject source, EObject target) {
super(request, source, target);
}
/**
* Add a condition on the MOS container
*
* @Override
*/
@Override
public boolean canExecute() {
if(source == null && target == null) {
return false;
}
if(source != null && false == source instanceof Element) {
return false;
}
if(target != null && false == target instanceof Element) {
return false;
}
if(getSource() == null) {
return true; // link creation is in progress; source is not defined yet
}
// target may be null here but it's possible to check constraint
if(getContainer() == null) {
return false;
}
if(getSource() != null && getTarget() != null) {
if(!CommandHelper.hasValidContainer(getRequest())) {
return false;
}
}
if(!UMLBaseItemSemanticEditPolicy.getLinkConstraints().canCreateMessage_4004(getContainer(), getSource(), getTarget())) {
return false;
}
return MessageConnectionHelper.canExist(MessageSort.ASYNCH_CALL_LITERAL, getSource(), getTarget());
}
/**
* added code to create the gate , message occurence and event when a Async message is created.
*
* @Override
*/
@Override
protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
if(!canExecute()) {
throw new ExecutionException(CREATE_LINK_ERROR_MSG);
}
Map<Object, Object> parameters = getRequest().getParameters();
Message message = CommandHelper.doCreateMessage(container, null, getSource(), getTarget(), parameters);
//Fixed bug about creating message, if created failed, return error result.
if(message == null || message.getSendEvent() == null || message.getReceiveEvent() == null) {
return CommandResult.newErrorCommandResult("Failed to create message");
}
if(message != null) {
//Do reset message end to target ExecutionSpecification. See https://bugs.eclipse.org/bugs/show_bug.cgi?id=402975
if(getTarget() instanceof ExecutionSpecification) {
OccurrenceSpecificationHelper.resetExecutionStart((ExecutionSpecification)getTarget(), message.getReceiveEvent());
}
if(getSource() instanceof ExecutionOccurrenceSpecification) {
ExecutionSpecification execution = ((ExecutionOccurrenceSpecification)getSource()).getExecution();
if(execution != null) {
OccurrenceSpecificationHelper.resetExecutionStart(execution, message.getSendEvent());
}
}
doConfigure(message, monitor, info);
((CreateElementRequest)getRequest()).setNewElement(message);
return CommandResult.newOKCommandResult(message);
}
return CommandResult.newErrorCommandResult(NO_CONTAINER_ERROR_MSG);
}
}
|