Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 042d095b69dae7fb05fa89340dbb7b99b0a6b650 (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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
/*
 * Copyright (c) 2006, 2009 Borland Software Corporation
 * 
 * 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:
 *    Dmitry Stadnik (Borland) - initial API and implementation
 */

«IMPORT 'http://www.eclipse.org/gmf/2009/GenModel'»
«IMPORT 'http://www.eclipse.org/emf/2002/Ecore'»

«DEFINE TextSelectionEditPolicy FOR gmfgen::GenDiagram-»
«EXPAND xpt::Common::copyright FOR editorGen-»
package «editPoliciesPackageName»;

«EXPAND xpt::Common::generatedClassComment»
public class «textSelectionEditPolicyClassName» extends org.eclipse.gef.editpolicies.SelectionEditPolicy {

	«EXPAND textFeedback FOR self-»
}
«ENDDEFINE»

«DEFINE TextNonResizableEditPolicy FOR gmfgen::GenDiagram-»
«EXPAND xpt::Common::copyright FOR editorGen-»
package «editPoliciesPackageName»;

«EXPAND xpt::Common::generatedClassComment»
public class «textNonResizableEditPolicyClassName» extends org.eclipse.gmf.runtime.diagram.ui.editpolicies.NonResizableEditPolicyEx {

	«EXPAND textFeedback FOR self-»

	«EXPAND xpt::Common::generatedMemberComment»
	protected java.util.List createSelectionHandles() {
		org.eclipse.gef.handles.MoveHandle moveHandle =
			new org.eclipse.gef.handles.MoveHandle((org.eclipse.gef.GraphicalEditPart) getHost());
		moveHandle.setBorder(null);
		moveHandle.setDragTracker(new org.eclipse.gmf.runtime.diagram.ui.tools.DragEditPartsTrackerEx(getHost()));
		return java.util.Collections.singletonList(moveHandle);
	}
}
«ENDDEFINE»

«DEFINE textFeedback FOR gmfgen::GenDiagram»
	«EXPAND xpt::Common::generatedMemberComment»
	private org.eclipse.draw2d.IFigure selectionFeedbackFigure;

	«EXPAND xpt::Common::generatedMemberComment»
	private org.eclipse.draw2d.IFigure focusFeedbackFigure;

	«EXPAND xpt::Common::generatedMemberComment»
	private org.eclipse.draw2d.FigureListener hostPositionListener;

	«EXPAND xpt::Common::generatedMemberComment»
	protected void showPrimarySelection() {
		if (getHostFigure() instanceof org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel) {
			((org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel) getHostFigure()).setSelected(true);
			((org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel) getHostFigure()).setFocus(true);
		} else {
			showSelection();
			showFocus();
		}
	}

	«EXPAND xpt::Common::generatedMemberComment»
	protected void showSelection() {
		if (getHostFigure() instanceof org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel) {
			((org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel) getHostFigure()).setSelected(true);
			((org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel) getHostFigure()).setFocus(false);
		} else {
			hideSelection();
			addFeedback(selectionFeedbackFigure = createSelectionFeedbackFigure());
			getHostFigure().addFigureListener(getHostPositionListener());
			refreshSelectionFeedback();
			hideFocus();
		}
	}

	«EXPAND xpt::Common::generatedMemberComment»
	protected void hideSelection() {
		if (getHostFigure() instanceof org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel) {
			((org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel) getHostFigure()).setSelected(false);
			((org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel) getHostFigure()).setFocus(false);
		} else {
			if (selectionFeedbackFigure != null) {
				removeFeedback(selectionFeedbackFigure);
				getHostFigure().removeFigureListener(getHostPositionListener());
				selectionFeedbackFigure = null;
			}
			hideFocus();
		}
	}

	«EXPAND xpt::Common::generatedMemberComment»
	protected void showFocus() {
		if (getHostFigure() instanceof org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel) {
			((org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel) getHostFigure()).setFocus(true);
		} else {
			hideFocus();
			addFeedback(focusFeedbackFigure = createFocusFeedbackFigure());
			refreshFocusFeedback();
		}
	}

	«EXPAND xpt::Common::generatedMemberComment»
	protected void hideFocus() {
		if (getHostFigure() instanceof org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel) {
			((org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel) getHostFigure()).setFocus(false);
		} else {
			if (focusFeedbackFigure != null) {
				removeFeedback(focusFeedbackFigure);
				focusFeedbackFigure = null;
			}
		}
	}

	«EXPAND xpt::Common::generatedMemberComment»
	protected org.eclipse.draw2d.geometry.Rectangle getFeedbackBounds() {
		org.eclipse.draw2d.geometry.Rectangle bounds;
		if (getHostFigure() instanceof org.eclipse.draw2d.Label) {
			bounds = ((org.eclipse.draw2d.Label) getHostFigure()).getTextBounds();
			bounds.intersect(getHostFigure().getBounds());
		} else {
			bounds = getHostFigure().getBounds().getCopy();
		}
		getHostFigure().getParent().translateToAbsolute(bounds);
		getFeedbackLayer().translateToRelative(bounds);
		return bounds;
	}

	«EXPAND xpt::Common::generatedMemberComment»
	protected org.eclipse.draw2d.IFigure createSelectionFeedbackFigure() {
		if (getHostFigure() instanceof org.eclipse.draw2d.Label) {
			org.eclipse.draw2d.Label feedbackFigure = new org.eclipse.draw2d.Label();
			feedbackFigure.setOpaque(true);
			feedbackFigure.setBackgroundColor(org.eclipse.draw2d.ColorConstants.menuBackgroundSelected);
			feedbackFigure.setForegroundColor(org.eclipse.draw2d.ColorConstants.menuForegroundSelected);
			return feedbackFigure;
		} else {
			org.eclipse.draw2d.RectangleFigure feedbackFigure = new org.eclipse.draw2d.RectangleFigure();
			feedbackFigure.setFill(false);
			return feedbackFigure;
		}
	}

	«EXPAND xpt::Common::generatedMemberComment»
	protected org.eclipse.draw2d.IFigure createFocusFeedbackFigure() {
		return new org.eclipse.draw2d.Figure() {

			protected void paintFigure(org.eclipse.draw2d.Graphics graphics) {
				graphics.drawFocus(getBounds().getResized(-1, -1));
			}
		};
	}

	«EXPAND xpt::Common::generatedMemberComment»
	protected void updateLabel(org.eclipse.draw2d.Label target) {
		org.eclipse.draw2d.Label source = (org.eclipse.draw2d.Label) getHostFigure();
		target.setText(source.getText());
		target.setTextAlignment(source.getTextAlignment());
		target.setFont(source.getFont());
	}

	«EXPAND xpt::Common::generatedMemberComment»
	protected void refreshSelectionFeedback() {
		if (selectionFeedbackFigure != null) {
			if (selectionFeedbackFigure instanceof org.eclipse.draw2d.Label) {
				updateLabel((org.eclipse.draw2d.Label) selectionFeedbackFigure);
				selectionFeedbackFigure.setBounds(getFeedbackBounds());
			} else {
				selectionFeedbackFigure.setBounds(getFeedbackBounds().expand(5, 5));
			}
		}
	}

	«EXPAND xpt::Common::generatedMemberComment»
	protected void refreshFocusFeedback() {
		if (focusFeedbackFigure != null) {
			focusFeedbackFigure.setBounds(getFeedbackBounds());
		}
	}

	«EXPAND xpt::Common::generatedMemberComment»
	public void refreshFeedback() {
		refreshSelectionFeedback();
		refreshFocusFeedback();
	}

	«EXPAND xpt::Common::generatedMemberComment»
	private org.eclipse.draw2d.FigureListener getHostPositionListener() {
		if (hostPositionListener == null) {
			hostPositionListener = new org.eclipse.draw2d.FigureListener() {
				public void figureMoved(org.eclipse.draw2d.IFigure source) {
					refreshFeedback();
				}
			};
		}
		return hostPositionListener;
	}
«ENDDEFINE»

Back to the top