blob: 3efbaecff0701d5e10b1d191bb2f28cc86fce596 (
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
|
/*****************************************************************************
* Copyright (c) 2015 CEA LIST and others.
*
* 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
* Vincent Lorenzo - bug 493317 (deprecated)
*****************************************************************************/
package org.eclipse.papyrus.uml.diagram.common.editpolicies;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.Request;
import org.eclipse.gef.RootEditPart;
import org.eclipse.gef.commands.Command;
import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil;
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyReferenceRequest;
import org.eclipse.gmf.runtime.emf.type.core.requests.IEditCommandRequest;
import org.eclipse.gmf.runtime.notation.Connector;
import org.eclipse.gmf.runtime.notation.Edge;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.DefaultSemanticEditPolicy;
import org.eclipse.uml2.uml.Constraint;
/**
* Custom context link semantic edit policy that provides removing a context from constrained element
* during delete/hide context link command
*
* @deprecated since 2.0, the work is now done by an advice helper in the oep.uml.service.types
*/
public class ContextLinkSemanticEditPolicy extends DefaultSemanticEditPolicy {
@Override
public Command getCommand(Request request) {
if (isContextLinkHideRequest(request)) {
EObject context = ViewUtil.resolveSemanticElement(((Edge) getHost().getModel()).getSource());
EObject referenceObject = resolveSemanticElement(getHost().getParent());
DestroyReferenceRequest req = new DestroyReferenceRequest(((IGraphicalEditPart) getHost()).getEditingDomain(), context, null, referenceObject, false);
return getSemanticCommand(req);
}
return super.getCommand(request);
}
@Override
protected Command getDestroyReferenceCommand(DestroyReferenceRequest req) {
EObject context = req.getContainer();
return super.getDestroyReferenceCommand(req, context);
}
@Override
protected IEditCommandRequest completeRequest(IEditCommandRequest request) {
return request;
}
private boolean isContextLinkHideRequest(Request request) {
if (!REQ_DELETE.equals(request.getType())) {
return false;
}
View hostView = ((IGraphicalEditPart) getHost()).getNotationView();
if (false == hostView instanceof Connector) {
return false;
}
EObject hostElement = ((IGraphicalEditPart) getHost()).resolveSemanticElement();
EObject sourceElement = ((Connector) hostView).getSource().getElement();
return hostElement == null && sourceElement instanceof Constraint;
}
private EObject resolveSemanticElement(EditPart editPart) {
if (editPart == null) {
return null;
}
if (editPart instanceof RootEditPart) {
return ViewUtil.resolveSemanticElement((View) ((RootEditPart) editPart).getContents().getModel());
}
return ((IGraphicalEditPart) editPart).resolveSemanticElement();
}
}
|