blob: fce18347ab49deb47f2ad4560ae1ab467295210a (
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
|
/*****************************************************************************
* Copyright (c) 2012 ATOS.
*
*
* 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:
* Olivier Mélois (ATOS) - Initial API and implementation
*
******************************************************************************/
package org.eclipse.papyrus.sysml.diagram.requirement.edit.part;
import org.eclipse.draw2d.IFigure;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.EditPolicy;
import org.eclipse.gmf.runtime.diagram.ui.editparts.LabelEditPart;
import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.papyrus.sysml.diagram.requirement.edit.policy.CustomRequirementInfoLabelUpdateEditPolicy;
import org.eclipse.papyrus.sysml.requirements.Requirement;
import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeLabelDisplayEditPolicy;
import org.eclipse.swt.widgets.Display;
import org.eclipse.uml2.uml.Element;
public abstract class CustomAbstractRequirementInformationLabelEditPart extends LabelEditPart {
Requirement requirement;
public CustomAbstractRequirementInformationLabelEditPart(View view) {
super(view);
}
@Override
protected void createDefaultEditPolicies() {
/*
* edit policy used to refresh the labels when the stereotype application "Requirement" is updated.
*/
installEditPolicy(AppliedStereotypeLabelDisplayEditPolicy.STEREOTYPE_LABEL_POLICY, new CustomRequirementInfoLabelUpdateEditPolicy());
super.createDefaultEditPolicies();
// Removing useless edit policies installed by superclasses.
removeEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
removeEditPolicy(EditPolicy.COMPONENT_ROLE);
}
@Override
protected IFigure createFigure() {
IFigure figure = new WrappingLabel();
((WrappingLabel) figure).setTextWrap(true);
figure.setFont(Display.getDefault().getSystemFont());
return figure;
}
@Override
public IFigure getFigure() {
IFigure figure = super.getFigure();
refreshLabelText();
return figure;
}
public abstract void refreshLabelText();
/**
* Refreshes the text of the label.
*/
@Override
public void refresh() {
this.refreshLabelText();
super.refresh();
}
/**
* Gets the requirement associated to this edit part.
*/
protected Requirement getRequirement() {
EditPart compartment = this.getParent();
EditPart classEditPart = compartment.getParent();
// Getting the class out of the edit part.
Element clazz = (Element) ((View) classEditPart.getModel()).getElement();
// Getting the requirement out of the class.
if (clazz != null) {
for (EObject appliedStereotype : clazz.getStereotypeApplications()) {
if (appliedStereotype instanceof Requirement) {
return ((Requirement) appliedStereotype);
}
}
}
return null;
}
}
|