blob: b2bf5815ce04981dcd8ead9698bd1c522507bc2f (
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
|
/*******************************************************************************
* Copyright (c) 2007, 2018 THALES GLOBAL SERVICES.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Obeo - initial API and implementation
*******************************************************************************/
package org.eclipse.sirius.diagram.ui.tools.api.figure;
import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.MarginBorder;
import org.eclipse.draw2d.RectangleFigure;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.sirius.diagram.ui.business.internal.view.ShowingViewUtil;
import org.eclipse.sirius.ext.gmf.runtime.gef.ui.figures.IContainerLabelOffsets;
import org.eclipse.sirius.ext.gmf.runtime.gef.ui.figures.SiriusWrapLabel;
import org.eclipse.sirius.ext.gmf.runtime.gef.ui.figures.ViewNodeContainerFigureDesc;
/**
* Basic implementation of {@link ViewNodeContainerFigureDesc} with a rectangle shape.
*
* @author cbrun
*
*/
public class ViewNodeContainerRectangleFigureDesc extends RectangleFigure implements ViewNodeContainerFigureDesc {
private SiriusWrapLabel fContainerLabelFigure;
private View view;
/**
* Create a new {@link ViewNodeContainerFigureDesc}.
*
* @param view
* the model view of the part showing the figure.
*/
public ViewNodeContainerRectangleFigureDesc(View view) {
this.view = view;
this.setFill(false);
createContents();
this.setBorder(new MarginBorder(IContainerLabelOffsets.LABEL_OFFSET, 0, 0, 0));
}
@Override
public void paint(Graphics graphics) {
if (view != null) {
ShowingViewUtil.initGraphicsForVisibleAndInvisibleElements(this, graphics, view);
try {
super.paint(graphics);
graphics.restoreState();
} finally {
graphics.popState();
}
} else {
super.paint(graphics);
}
}
private void createContents() {
fContainerLabelFigure = new SiriusWrapLabel() {
@Override
public void paint(Graphics graphics) {
if (view != null) {
ShowingViewUtil.initGraphicsForVisibleAndInvisibleElements(this, graphics, view);
try {
super.paint(graphics);
graphics.restoreState();
} finally {
graphics.popState();
}
} else {
super.paint(graphics);
}
}
};
fContainerLabelFigure.setText(" "); //$NON-NLS-1$
fContainerLabelFigure.setTextWrap(true);
this.add(fContainerLabelFigure);
}
/**
* {@inheritDoc}
*
* @was-generated
* @see org.eclipse.sirius.ext.gmf.runtime.gef.ui.figures.ViewNodeContainerFigureDesc#getLabelFigure()
*/
@Override
public SiriusWrapLabel getLabelFigure() {
return fContainerLabelFigure;
}
}
|