Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 637a8b30c67d5bf9042f4d3ce5c764f09148d1c8 (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) 2017 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
 *   
 *****************************************************************************/

package org.eclipse.papyrus.uml.diagram.sequence.referencialgrilling;

import java.io.ObjectInputStream.GetField;

import org.eclipse.draw2d.geometry.PrecisionRectangle;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart;
import org.eclipse.gmf.runtime.notation.Bounds;
import org.eclipse.gmf.runtime.notation.Node;
import org.eclipse.gmf.runtime.notation.NotationPackage;
import org.eclipse.papyrus.infra.gmfdiag.common.helper.NotationHelper;
import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.CombinedFragmentCombinedFragmentCompartmentEditPart;
import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.CombinedFragmentEditPart;
import org.eclipse.uml2.uml.Element;

/**
 * this editpolicy is overloaded because the width of the interaction operand is managed by the editpartparent
 *
 */
public class ConnectInteractionOperandToGridEditPolicy  extends ConnectRectangleToGridEditPolicy{

	private CombinedFragmentEditPart combinedFragmentEditPart;
	/**
	 * Constructor.
	 *
	 */
	public ConnectInteractionOperandToGridEditPolicy() {
		super();
		margin=27;
	}

	/**
	 * @see org.eclipse.papyrus.uml.diagram.sequence.referencialgrilling.ConnectNodeToGridEditPolicy#activate()
	 *
	 */
	@Override
	public void activate() {
		//the parent is the compartment of combinedFragment so we look for its great parent
		if( getHost().getParent() instanceof CombinedFragmentCombinedFragmentCompartmentEditPart){
			if(getHost().getParent().getParent() instanceof CombinedFragmentEditPart){
				combinedFragmentEditPart = (CombinedFragmentEditPart)getHost().getParent().getParent();
				getDiagramEventBroker().addNotificationListener(combinedFragmentEditPart.getNotationView(), this);	
			}
		}
		super.activate();
	}

	/**
	 * @see org.eclipse.papyrus.uml.diagram.sequence.referencialgrilling.ConnectNodeToGridEditPolicy#deactivate()
	 *
	 */
	@Override
	public void deactivate() {
		if( combinedFragmentEditPart!=null){
			getDiagramEventBroker().removeNotificationListener(combinedFragmentEditPart.getNotationView(), this);
		}
		super.deactivate();
	}
	/**
	 * @see org.eclipse.papyrus.uml.diagram.sequence.referencialgrilling.ConnectNodeToGridEditPolicy#initListeningColumnFinish(org.eclipse.gmf.runtime.notation.Node, org.eclipse.papyrus.uml.diagram.sequence.referencialgrilling.GrillingManagementEditPolicy, org.eclipse.uml2.uml.Element, org.eclipse.draw2d.geometry.PrecisionRectangle)
	 *
	 * @param node
	 * @param grilling
	 * @param element
	 * @param bounds
	 * @throws NoGrillElementFound
	 */
	@Override
	protected void initListeningColumnFinish(Node node, GridManagementEditPolicy grilling, Element element, PrecisionRectangle bounds) throws NoGrillElementFound {
		if(combinedFragmentEditPart!=null){
			Node cfNode=(Node)combinedFragmentEditPart.getNotationView();
			columnFinish=grilling.createColumnTolisten(bounds.x+BoundForEditPart.getWidthFromView(cfNode), element);
			getDiagramEventBroker().addNotificationListener(columnFinish, this);
		}
	}

	
	
	/**
	 * @see org.eclipse.papyrus.uml.diagram.sequence.referencialgrilling.ConnectNodeToGridEditPolicy#updateColumFinishFromWitdhNotification(org.eclipse.draw2d.geometry.PrecisionRectangle)
	 *
	 * @param notationBound
	 */
	@Override
	protected void updateColumFinishFromWitdhNotification(PrecisionRectangle notationBound) {
		if( combinedFragmentEditPart!=null){
			Node cfNode=(Node)combinedFragmentEditPart.getNotationView();
			int newX=notationBound.x+BoundForEditPart.getWidthFromView(cfNode);
			updatePositionGridAxis(columnFinish, newX,0);
		}
	}
	/**
	 * @see org.eclipse.papyrus.uml.diagram.sequence.referencialgrilling.ConnectNodeToGridEditPolicy#notifyChanged(org.eclipse.emf.common.notify.Notification)
	 *
	 * @param notification
	 */
	@Override
	public void notifyChanged(Notification notification) {
		super.notifyChanged(notification);
		if( notification.getEventType()==Notification.SET && notification.getNotifier() instanceof Bounds && (((EObject)notification.getNotifier()).eContainer().equals(combinedFragmentEditPart.getNotationView()))){
			PrecisionRectangle bounds=NotationHelper.getAbsoluteBounds((Node)((GraphicalEditPart)getHost()).getNotationView());
			if( notification.getFeature().equals(NotationPackage.eINSTANCE.getSize_Width())){
				updateColumFinishFromWitdhNotification(bounds);
			}
		}
	}
	
}

Back to the top