Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 80318 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/uml2/diagram/clazz/edit/parts/InstanceSpecificationEditPart.java (+553 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.parts;
2
3
import java.util.Collections;
4
import java.util.List;
5
6
import org.eclipse.draw2d.IFigure;
7
import org.eclipse.draw2d.Label;
8
import org.eclipse.draw2d.geometry.Point;
9
import org.eclipse.emf.common.notify.Notification;
10
import org.eclipse.emf.ecore.EObject;
11
import org.eclipse.emf.transaction.RunnableWithResult;
12
import org.eclipse.gef.AccessibleEditPart;
13
import org.eclipse.gef.DragTracker;
14
import org.eclipse.gef.EditPolicy;
15
import org.eclipse.gef.Request;
16
import org.eclipse.gef.requests.DirectEditRequest;
17
import org.eclipse.gef.requests.SelectionRequest;
18
import org.eclipse.gef.tools.DirectEditManager;
19
import org.eclipse.gmf.runtime.common.ui.services.parser.IParser;
20
import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus;
21
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserEditStatus;
22
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions;
23
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserService;
24
import org.eclipse.gmf.runtime.diagram.ui.editparts.CompartmentEditPart;
25
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
26
import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart;
27
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
28
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy;
29
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.ListItemComponentEditPolicy;
30
import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry;
31
import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants;
32
import org.eclipse.gmf.runtime.diagram.ui.tools.DragEditPartsTrackerEx;
33
import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager;
34
import org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel;
35
import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
36
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
37
import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser;
38
import org.eclipse.gmf.runtime.emf.ui.services.parser.ParserHintAdapter;
39
import org.eclipse.gmf.runtime.notation.FontStyle;
40
import org.eclipse.gmf.runtime.notation.NotationPackage;
41
import org.eclipse.gmf.runtime.notation.View;
42
import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
43
import org.eclipse.jface.viewers.ICellEditorValidator;
44
import org.eclipse.swt.SWT;
45
import org.eclipse.swt.accessibility.AccessibleEvent;
46
import org.eclipse.swt.graphics.Color;
47
import org.eclipse.swt.graphics.FontData;
48
import org.eclipse.swt.graphics.Image;
49
import org.eclipse.uml2.diagram.clazz.edit.policies.InstanceSpecificationItemSemanticEditPolicy;
50
import org.eclipse.uml2.diagram.clazz.edit.policies.UMLTextNonResizableEditPolicy;
51
import org.eclipse.uml2.diagram.clazz.edit.policies.UMLTextSelectionEditPolicy;
52
import org.eclipse.uml2.diagram.clazz.providers.UMLElementTypes;
53
54
/**
55
 * @generated
56
 */
57
public class InstanceSpecificationEditPart extends CompartmentEditPart implements ITextAwareEditPart {
58
59
	/**
60
	 * @generated
61
	 */
62
	public static final int VISUAL_ID = 3013;
63
64
	/**
65
	 * @generated
66
	 */
67
	private DirectEditManager manager;
68
69
	/**
70
	 * @generated
71
	 */
72
	private IParser parser;
73
74
	/**
75
	 * @generated
76
	 */
77
	private List parserElements;
78
79
	/**
80
	 * @generated
81
	 */
82
	private String defaultText;
83
84
	/**
85
	 * @generated
86
	 */
87
	public InstanceSpecificationEditPart(View view) {
88
		super(view);
89
	}
90
91
	/**
92
	 * @generated
93
	 */
94
	public DragTracker getDragTracker(Request request) {
95
		if (request instanceof SelectionRequest && ((SelectionRequest) request).getLastButtonPressed() == 3) {
96
			return null;
97
		}
98
		return new DragEditPartsTrackerEx(this);
99
	}
100
101
	/**
102
	 * @generated
103
	 */
104
	protected void createDefaultEditPolicies() {
105
		super.createDefaultEditPolicies();
106
		installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new InstanceSpecificationItemSemanticEditPolicy());
107
		installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new UMLTextNonResizableEditPolicy());
108
		installEditPolicy(EditPolicy.COMPONENT_ROLE, new ListItemComponentEditPolicy());
109
		installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy());
110
111
	}
112
113
	/**
114
	 * @generated
115
	 */
116
	protected String getLabelTextHelper(IFigure figure) {
117
		if (figure instanceof WrapLabel) {
118
			return ((WrapLabel) figure).getText();
119
		} else {
120
			return ((Label) figure).getText();
121
		}
122
	}
123
124
	/**
125
	 * @generated
126
	 */
127
	protected void setLabelTextHelper(IFigure figure, String text) {
128
		if (figure instanceof WrapLabel) {
129
			((WrapLabel) figure).setText(text);
130
		} else {
131
			((Label) figure).setText(text);
132
		}
133
	}
134
135
	/**
136
	 * @generated
137
	 */
138
	protected Image getLabelIconHelper(IFigure figure) {
139
		if (figure instanceof WrapLabel) {
140
			return ((WrapLabel) figure).getIcon();
141
		} else {
142
			return ((Label) figure).getIcon();
143
		}
144
	}
145
146
	/**
147
	 * @generated
148
	 */
149
	protected void setLabelIconHelper(IFigure figure, Image icon) {
150
		if (figure instanceof WrapLabel) {
151
			((WrapLabel) figure).setIcon(icon);
152
		} else {
153
			((Label) figure).setIcon(icon);
154
		}
155
	}
156
157
	/**
158
	 * @generated
159
	 */
160
	public void setLabel(IFigure figure) {
161
		unregisterVisuals();
162
		setFigure(figure);
163
		defaultText = getLabelTextHelper(figure);
164
		registerVisuals();
165
		refreshVisuals();
166
	}
167
168
	/**
169
	 * @generated
170
	 */
171
	protected List getModelChildren() {
172
		return Collections.EMPTY_LIST;
173
	}
174
175
	/**
176
	 * @generated
177
	 */
178
	public IGraphicalEditPart getChildBySemanticHint(String semanticHint) {
179
		return null;
180
	}
181
182
	/**
183
	 * @generated
184
	 */
185
	protected EObject getParserElement() {
186
		EObject element = resolveSemanticElement();
187
		return element != null ? element : (View) getModel();
188
	}
189
190
	/**
191
	 * @generated
192
	 */
193
	protected Image getLabelIcon() {
194
		return null;
195
	}
196
197
	/**
198
	 * @generated
199
	 */
200
	protected String getLabelText() {
201
		String text = null;
202
		if (getParser() != null) {
203
			text = getParser().getPrintString(new EObjectAdapter(getParserElement()), getParserOptions().intValue());
204
		}
205
		if (text == null || text.length() == 0) {
206
			text = defaultText;
207
		}
208
		return text;
209
	}
210
211
	/**
212
	 * @generated
213
	 */
214
	public void setLabelText(String text) {
215
		setLabelTextHelper(getFigure(), text);
216
		Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
217
		if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) {
218
			((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback();
219
		}
220
	}
221
222
	/**
223
	 * @generated
224
	 */
225
	public String getEditText() {
226
		if (getParser() == null) {
227
			return ""; //$NON-NLS-1$
228
		}
229
		return getParser().getEditString(new EObjectAdapter(getParserElement()), getParserOptions().intValue());
230
	}
231
232
	/**
233
	 * @generated
234
	 */
235
	protected boolean isEditable() {
236
		return getEditText() != null;
237
	}
238
239
	/**
240
	 * @generated
241
	 */
242
	public ICellEditorValidator getEditTextValidator() {
243
		return new ICellEditorValidator() {
244
245
			public String isValid(final Object value) {
246
				if (value instanceof String) {
247
					final EObject element = getParserElement();
248
					final IParser parser = getParser();
249
					try {
250
						IParserEditStatus valid = (IParserEditStatus) getEditingDomain().runExclusive(new RunnableWithResult.Impl() {
251
252
							public void run() {
253
								setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value));
254
							}
255
						});
256
						return valid.getCode() == ParserEditStatus.EDITABLE ? null : valid.getMessage();
257
					} catch (InterruptedException ie) {
258
						ie.printStackTrace();
259
					}
260
				}
261
262
				// shouldn't get here
263
				return null;
264
			}
265
		};
266
	}
267
268
	/**
269
	 * @generated
270
	 */
271
	public IContentAssistProcessor getCompletionProcessor() {
272
		if (getParser() == null) {
273
			return null;
274
		}
275
		return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement()));
276
	}
277
278
	/**
279
	 * @generated
280
	 */
281
	public ParserOptions getParserOptions() {
282
		return ParserOptions.NONE;
283
	}
284
285
	/**
286
	 * @generated
287
	 */
288
	public IParser getParser() {
289
		if (parser == null) {
290
			String parserHint = ((View) getModel()).getType();
291
			ParserHintAdapter hintAdapter = new ParserHintAdapter(getParserElement(), parserHint) {
292
293
				public Object getAdapter(Class adapter) {
294
					if (IElementType.class.equals(adapter)) {
295
						return UMLElementTypes.InstanceSpecification_3013;
296
					}
297
					return super.getAdapter(adapter);
298
				}
299
			};
300
			parser = ParserService.getInstance().getParser(hintAdapter);
301
		}
302
		return parser;
303
	}
304
305
	/**
306
	 * @generated
307
	 */
308
	protected DirectEditManager getManager() {
309
		if (manager == null) {
310
			setManager(new TextDirectEditManager(this, TextDirectEditManager.getTextCellEditorClass(this), UMLEditPartFactory.getTextCellEditorLocator(this)));
311
		}
312
		return manager;
313
	}
314
315
	/**
316
	 * @generated
317
	 */
318
	protected void setManager(DirectEditManager manager) {
319
		this.manager = manager;
320
	}
321
322
	/**
323
	 * @generated
324
	 */
325
	protected void performDirectEdit() {
326
		getManager().show();
327
	}
328
329
	/**
330
	 * @generated
331
	 */
332
	protected void performDirectEdit(Point eventLocation) {
333
		if (getManager().getClass() == TextDirectEditManager.class) {
334
			((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint());
335
		}
336
	}
337
338
	/**
339
	 * @generated
340
	 */
341
	private void performDirectEdit(char initialCharacter) {
342
		if (getManager() instanceof TextDirectEditManager) {
343
			((TextDirectEditManager) getManager()).show(initialCharacter);
344
		} else {
345
			performDirectEdit();
346
		}
347
	}
348
349
	/**
350
	 * @generated
351
	 */
352
	protected void performDirectEditRequest(Request request) {
353
		final Request theRequest = request;
354
		try {
355
			getEditingDomain().runExclusive(new Runnable() {
356
357
				public void run() {
358
					if (isActive() && isEditable()) {
359
						if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) {
360
							Character initialChar = (Character) theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR);
361
							performDirectEdit(initialChar.charValue());
362
						} else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) {
363
							DirectEditRequest editRequest = (DirectEditRequest) theRequest;
364
							performDirectEdit(editRequest.getLocation());
365
						} else {
366
							performDirectEdit();
367
						}
368
					}
369
				}
370
			});
371
		} catch (InterruptedException e) {
372
			e.printStackTrace();
373
		}
374
	}
375
376
	/**
377
	 * @generated
378
	 */
379
	protected void refreshVisuals() {
380
		super.refreshVisuals();
381
		refreshLabel();
382
		refreshFont();
383
		refreshFontColor();
384
		refreshUnderline();
385
		refreshStrikeThrough();
386
	}
387
388
	/**
389
	 * @generated
390
	 */
391
	protected void refreshLabel() {
392
		setLabelTextHelper(getFigure(), getLabelText());
393
		setLabelIconHelper(getFigure(), getLabelIcon());
394
		Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
395
		if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) {
396
			((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback();
397
		}
398
	}
399
400
	/**
401
	 * @generated
402
	 */
403
	protected void refreshUnderline() {
404
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
405
		if (style != null && getFigure() instanceof WrapLabel) {
406
			((WrapLabel) getFigure()).setTextUnderline(style.isUnderline());
407
		}
408
	}
409
410
	/**
411
	 * @generated
412
	 */
413
	protected void refreshStrikeThrough() {
414
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
415
		if (style != null && getFigure() instanceof WrapLabel) {
416
			((WrapLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough());
417
		}
418
	}
419
420
	/**
421
	 * @generated
422
	 */
423
	protected void refreshFont() {
424
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
425
		if (style != null) {
426
			FontData fontData = new FontData(style.getFontName(), style.getFontHeight(), (style.isBold() ? SWT.BOLD : SWT.NORMAL) | (style.isItalic() ? SWT.ITALIC : SWT.NORMAL));
427
			setFont(fontData);
428
		}
429
	}
430
431
	/**
432
	 * @generated
433
	 */
434
	protected void setFontColor(Color color) {
435
		getFigure().setForegroundColor(color);
436
	}
437
438
	/**
439
	 * @generated
440
	 */
441
	protected void addSemanticListeners() {
442
		if (getParser() instanceof ISemanticParser) {
443
			EObject element = resolveSemanticElement();
444
			parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element);
445
			for (int i = 0; i < parserElements.size(); i++) {
446
				addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$
447
			}
448
		} else {
449
			super.addSemanticListeners();
450
		}
451
	}
452
453
	/**
454
	 * @generated
455
	 */
456
	protected void removeSemanticListeners() {
457
		if (parserElements != null) {
458
			for (int i = 0; i < parserElements.size(); i++) {
459
				removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$
460
			}
461
		} else {
462
			super.removeSemanticListeners();
463
		}
464
	}
465
466
	/**
467
	 * @generated
468
	 */
469
	protected AccessibleEditPart getAccessibleEditPart() {
470
		if (accessibleEP == null) {
471
			accessibleEP = new AccessibleGraphicalEditPart() {
472
473
				public void getName(AccessibleEvent e) {
474
					e.result = getLabelTextHelper(getFigure());
475
				}
476
			};
477
		}
478
		return accessibleEP;
479
	}
480
481
	/**
482
	 * @generated
483
	 */
484
	private View getFontStyleOwnerView() {
485
		return getPrimaryView();
486
	}
487
488
	/**
489
	 * @generated
490
	 */
491
	protected void addNotationalListeners() {
492
		super.addNotationalListeners();
493
		addListenerFilter("PrimaryView", this, getPrimaryView()); //$NON-NLS-1$
494
	}
495
496
	/**
497
	 * @generated
498
	 */
499
	protected void removeNotationalListeners() {
500
		super.removeNotationalListeners();
501
		removeListenerFilter("PrimaryView"); //$NON-NLS-1$
502
	}
503
504
	/**
505
	 * @generated
506
	 */
507
	protected void handleNotificationEvent(Notification event) {
508
		Object feature = event.getFeature();
509
		if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) {
510
			Integer c = (Integer) event.getNewValue();
511
			setFontColor(DiagramColorRegistry.getInstance().getColor(c));
512
		} else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) {
513
			refreshUnderline();
514
		} else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) {
515
			refreshStrikeThrough();
516
		} else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature)
517
				|| NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) {
518
			refreshFont();
519
		} else {
520
			if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) {
521
				refreshLabel();
522
			}
523
			if (getParser() instanceof ISemanticParser) {
524
				ISemanticParser modelParser = (ISemanticParser) getParser();
525
				if (modelParser.areSemanticElementsAffected(null, event)) {
526
					removeSemanticListeners();
527
					if (resolveSemanticElement() != null) {
528
						addSemanticListeners();
529
					}
530
					refreshLabel();
531
				}
532
			}
533
		}
534
		super.handleNotificationEvent(event);
535
	}
536
537
	/**
538
	 * @generated
539
	 */
540
	protected IFigure createFigure() {
541
		IFigure label = createFigurePrim();
542
		defaultText = getLabelTextHelper(label);
543
		return label;
544
	}
545
546
	/**
547
	 * @generated
548
	 */
549
	protected IFigure createFigurePrim() {
550
		return new WrapLabel();
551
	}
552
553
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/policies/Operation2ItemSemanticEditPolicy.java (+255 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.policies;
2
3
import org.eclipse.emf.ecore.EAnnotation;
4
import org.eclipse.emf.ecore.EClass;
5
import org.eclipse.emf.ecore.EObject;
6
import org.eclipse.gef.commands.Command;
7
import org.eclipse.gef.commands.UnexecutableCommand;
8
import org.eclipse.gmf.runtime.emf.type.core.commands.CreateRelationshipCommand;
9
import org.eclipse.gmf.runtime.emf.type.core.commands.DestroyElementCommand;
10
import org.eclipse.gmf.runtime.emf.type.core.commands.SetValueCommand;
11
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest;
12
import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest;
13
import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest;
14
import org.eclipse.gmf.runtime.notation.View;
15
import org.eclipse.uml2.diagram.clazz.providers.UMLElementTypes;
16
import org.eclipse.uml2.uml.Constraint;
17
import org.eclipse.uml2.uml.Dependency;
18
import org.eclipse.uml2.uml.NamedElement;
19
import org.eclipse.uml2.uml.UMLPackage;
20
import org.eclipse.uml2.uml.Usage;
21
22
/**
23
 * @generated
24
 */
25
public class Operation2ItemSemanticEditPolicy extends UMLBaseItemSemanticEditPolicy {
26
27
	/**
28
	 * @generated
29
	 */
30
	protected Command getDestroyElementCommand(DestroyElementRequest req) {
31
		return getMSLWrapper(new DestroyElementCommand(req) {
32
33
			protected EObject getElementToDestroy() {
34
				View view = (View) getHost().getModel();
35
				EAnnotation annotation = view.getEAnnotation("Shortcut"); //$NON-NLS-1$
36
				if (annotation != null) {
37
					return view;
38
				}
39
				return super.getElementToDestroy();
40
			}
41
42
		});
43
	}
44
45
	/**
46
	 * @generated
47
	 */
48
	protected Command getCreateRelationshipCommand(CreateRelationshipRequest req) {
49
		if (UMLElementTypes.Dependency_4002 == req.getElementType()) {
50
			return req.getTarget() == null ? getCreateStartOutgoingDependency4002Command(req) : getCreateCompleteIncomingDependency4002Command(req);
51
		}
52
		if (UMLElementTypes.ConstraintConstrainedElement_4004 == req.getElementType()) {
53
			return req.getTarget() == null ? null : getCreateCompleteIncomingConstraint_ConstrainedElement4004Command(req);
54
		}
55
		if (UMLElementTypes.DependencySupplier_4006 == req.getElementType()) {
56
			return req.getTarget() == null ? null : getCreateCompleteIncomingDependency_Supplier4006Command(req);
57
		}
58
		if (UMLElementTypes.DependencyClient_4007 == req.getElementType()) {
59
			return req.getTarget() == null ? null : getCreateCompleteIncomingDependency_Client4007Command(req);
60
		}
61
		if (UMLElementTypes.Usage_4009 == req.getElementType()) {
62
			return req.getTarget() == null ? getCreateStartOutgoingUsage4009Command(req) : getCreateCompleteIncomingUsage4009Command(req);
63
		}
64
		return super.getCreateRelationshipCommand(req);
65
	}
66
67
	/**
68
	 * @generated
69
	 */
70
	protected Command getCreateStartOutgoingDependency4002Command(CreateRelationshipRequest req) {
71
		return new Command() {
72
		};
73
	}
74
75
	/**
76
	 * @generated
77
	 */
78
	protected Command getCreateCompleteIncomingDependency4002Command(CreateRelationshipRequest req) {
79
		if (!(req.getSource() instanceof NamedElement)) {
80
			return UnexecutableCommand.INSTANCE;
81
		}
82
		final org.eclipse.uml2.uml.Package element = (org.eclipse.uml2.uml.Package) getRelationshipContainer(req.getSource(), UMLPackage.eINSTANCE.getPackage(), req.getElementType());
83
		if (element == null) {
84
			return UnexecutableCommand.INSTANCE;
85
		}
86
		if (req.getContainmentFeature() == null) {
87
			req.setContainmentFeature(UMLPackage.eINSTANCE.getPackage_PackagedElement());
88
		}
89
		return getMSLWrapper(new CreateIncomingDependency4002Command(req) {
90
91
			protected EObject getElementToEdit() {
92
				return element;
93
			}
94
		});
95
	}
96
97
	/**
98
	 * @generated
99
	 */
100
	private static class CreateIncomingDependency4002Command extends CreateRelationshipCommand {
101
102
		/**
103
		 * @generated
104
		 */
105
		public CreateIncomingDependency4002Command(CreateRelationshipRequest req) {
106
			super(req);
107
		}
108
109
		/**
110
		 * @generated
111
		 */
112
		protected EClass getEClassToEdit() {
113
			return UMLPackage.eINSTANCE.getPackage();
114
		};
115
116
		/**
117
		 * @generated
118
		 */
119
		protected void setElementToEdit(EObject element) {
120
			throw new UnsupportedOperationException();
121
		}
122
123
		/**
124
		 * @generated
125
		 */
126
		protected EObject doDefaultElementCreation() {
127
			Dependency newElement = (Dependency) super.doDefaultElementCreation();
128
			if (newElement != null) {
129
				newElement.getSuppliers().add((NamedElement) getTarget());
130
				newElement.getClients().add((NamedElement) getSource());
131
			}
132
			return newElement;
133
		}
134
	}
135
136
	/**
137
	 * @generated
138
	 */
139
	protected Command getCreateCompleteIncomingConstraint_ConstrainedElement4004Command(CreateRelationshipRequest req) {
140
		if (!(req.getSource() instanceof Constraint)) {
141
			return UnexecutableCommand.INSTANCE;
142
		}
143
		Constraint element = (Constraint) req.getSource();
144
		if (element.getConstrainedElements().contains(req.getTarget())) {
145
			return UnexecutableCommand.INSTANCE;
146
		}
147
		SetRequest setReq = new SetRequest(req.getSource(), UMLPackage.eINSTANCE.getConstraint_ConstrainedElement(), req.getTarget());
148
		return getMSLWrapper(new SetValueCommand(setReq));
149
	}
150
151
	/**
152
	 * @generated
153
	 */
154
	protected Command getCreateCompleteIncomingDependency_Supplier4006Command(CreateRelationshipRequest req) {
155
		if (!(req.getSource() instanceof Dependency)) {
156
			return UnexecutableCommand.INSTANCE;
157
		}
158
		Dependency element = (Dependency) req.getSource();
159
		if (element.getSuppliers().contains(req.getTarget())) {
160
			return UnexecutableCommand.INSTANCE;
161
		}
162
		SetRequest setReq = new SetRequest(req.getSource(), UMLPackage.eINSTANCE.getDependency_Supplier(), req.getTarget());
163
		return getMSLWrapper(new SetValueCommand(setReq));
164
	}
165
166
	/**
167
	 * @generated
168
	 */
169
	protected Command getCreateCompleteIncomingDependency_Client4007Command(CreateRelationshipRequest req) {
170
		if (!(req.getSource() instanceof Dependency)) {
171
			return UnexecutableCommand.INSTANCE;
172
		}
173
		Dependency element = (Dependency) req.getSource();
174
		if (element.getClients().contains(req.getTarget())) {
175
			return UnexecutableCommand.INSTANCE;
176
		}
177
		SetRequest setReq = new SetRequest(req.getSource(), UMLPackage.eINSTANCE.getDependency_Client(), req.getTarget());
178
		return getMSLWrapper(new SetValueCommand(setReq));
179
	}
180
181
	/**
182
	 * @generated
183
	 */
184
	protected Command getCreateStartOutgoingUsage4009Command(CreateRelationshipRequest req) {
185
		if (!UMLBaseItemSemanticEditPolicy.LinkConstraints.Usage_4009.canCreateLink(req, false)) {
186
			return UnexecutableCommand.INSTANCE;
187
		}
188
		return new Command() {
189
		};
190
	}
191
192
	/**
193
	 * @generated
194
	 */
195
	protected Command getCreateCompleteIncomingUsage4009Command(CreateRelationshipRequest req) {
196
		if (!(req.getSource() instanceof NamedElement)) {
197
			return UnexecutableCommand.INSTANCE;
198
		}
199
		final org.eclipse.uml2.uml.Package element = (org.eclipse.uml2.uml.Package) getRelationshipContainer(req.getSource(), UMLPackage.eINSTANCE.getPackage(), req.getElementType());
200
		if (element == null) {
201
			return UnexecutableCommand.INSTANCE;
202
		}
203
		if (!UMLBaseItemSemanticEditPolicy.LinkConstraints.Usage_4009.canCreateLink(req, false)) {
204
			return UnexecutableCommand.INSTANCE;
205
		}
206
		if (req.getContainmentFeature() == null) {
207
			req.setContainmentFeature(UMLPackage.eINSTANCE.getPackage_PackagedElement());
208
		}
209
		return getMSLWrapper(new CreateIncomingUsage4009Command(req) {
210
211
			protected EObject getElementToEdit() {
212
				return element;
213
			}
214
		});
215
	}
216
217
	/**
218
	 * @generated
219
	 */
220
	private static class CreateIncomingUsage4009Command extends CreateRelationshipCommand {
221
222
		/**
223
		 * @generated
224
		 */
225
		public CreateIncomingUsage4009Command(CreateRelationshipRequest req) {
226
			super(req);
227
		}
228
229
		/**
230
		 * @generated
231
		 */
232
		protected EClass getEClassToEdit() {
233
			return UMLPackage.eINSTANCE.getPackage();
234
		};
235
236
		/**
237
		 * @generated
238
		 */
239
		protected void setElementToEdit(EObject element) {
240
			throw new UnsupportedOperationException();
241
		}
242
243
		/**
244
		 * @generated
245
		 */
246
		protected EObject doDefaultElementCreation() {
247
			Usage newElement = (Usage) super.doDefaultElementCreation();
248
			if (newElement != null) {
249
				newElement.getSuppliers().add((NamedElement) getTarget());
250
				newElement.getClients().add((NamedElement) getSource());
251
			}
252
			return newElement;
253
		}
254
	}
255
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/policies/UMLTextNonResizableEditPolicy.java (+208 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.policies;
2
3
import java.util.Collections;
4
import java.util.List;
5
6
import org.eclipse.draw2d.ColorConstants;
7
import org.eclipse.draw2d.Figure;
8
import org.eclipse.draw2d.Graphics;
9
import org.eclipse.draw2d.IFigure;
10
import org.eclipse.draw2d.Label;
11
import org.eclipse.draw2d.RectangleFigure;
12
import org.eclipse.draw2d.geometry.Rectangle;
13
import org.eclipse.gef.GraphicalEditPart;
14
import org.eclipse.gef.LayerConstants;
15
import org.eclipse.gef.handles.MoveHandle;
16
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.NonResizableEditPolicyEx;
17
import org.eclipse.gmf.runtime.diagram.ui.tools.DragEditPartsTrackerEx;
18
import org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel;
19
20
/**
21
 * @generated
22
 */
23
public class UMLTextNonResizableEditPolicy extends NonResizableEditPolicyEx {
24
25
	/**
26
	 * @generated
27
	 */
28
	private IFigure selectionFeedbackFigure;
29
30
	/**
31
	 * @generated
32
	 */
33
	private IFigure focusFeedbackFigure;
34
35
	/**
36
	 * @generated
37
	 */
38
	protected void showPrimarySelection() {
39
		if (getHostFigure() instanceof WrapLabel) {
40
			((WrapLabel) getHostFigure()).setSelected(true);
41
			((WrapLabel) getHostFigure()).setFocus(true);
42
		} else {
43
			showSelection();
44
			showFocus();
45
		}
46
	}
47
48
	/**
49
	 * @generated
50
	 */
51
	protected void showSelection() {
52
		if (getHostFigure() instanceof WrapLabel) {
53
			((WrapLabel) getHostFigure()).setSelected(true);
54
			((WrapLabel) getHostFigure()).setFocus(false);
55
		} else {
56
			hideSelection();
57
			addFeedback(selectionFeedbackFigure = createSelectionFeedbackFigure());
58
			refreshSelectionFeedback();
59
			hideFocus();
60
		}
61
	}
62
63
	/**
64
	 * @generated
65
	 */
66
	protected void hideSelection() {
67
		if (getHostFigure() instanceof WrapLabel) {
68
			((WrapLabel) getHostFigure()).setSelected(false);
69
			((WrapLabel) getHostFigure()).setFocus(false);
70
		} else {
71
			if (selectionFeedbackFigure != null) {
72
				removeFeedback(selectionFeedbackFigure);
73
				selectionFeedbackFigure = null;
74
			}
75
			hideFocus();
76
		}
77
	}
78
79
	/**
80
	 * @generated
81
	 */
82
	protected void showFocus() {
83
		if (getHostFigure() instanceof WrapLabel) {
84
			((WrapLabel) getHostFigure()).setFocus(true);
85
		} else {
86
			hideFocus();
87
			addFeedback(focusFeedbackFigure = createFocusFeedbackFigure());
88
			refreshFocusFeedback();
89
		}
90
	}
91
92
	/**
93
	 * @generated
94
	 */
95
	protected void hideFocus() {
96
		if (getHostFigure() instanceof WrapLabel) {
97
			((WrapLabel) getHostFigure()).setFocus(false);
98
		} else {
99
			if (focusFeedbackFigure != null) {
100
				removeFeedback(focusFeedbackFigure);
101
				focusFeedbackFigure = null;
102
			}
103
		}
104
	}
105
106
	/**
107
	 * @generated
108
	 */
109
	protected IFigure getFeedbackLayer() {
110
		return getLayer(LayerConstants.SCALED_FEEDBACK_LAYER);
111
	}
112
113
	/**
114
	 * @generated
115
	 */
116
	protected Rectangle getFeedbackBounds() {
117
		Rectangle bounds;
118
		if (getHostFigure() instanceof Label) {
119
			bounds = ((Label) getHostFigure()).getTextBounds();
120
			bounds.intersect(getHostFigure().getBounds());
121
		} else {
122
			bounds = getHostFigure().getBounds().getCopy();
123
		}
124
		getHostFigure().getParent().translateToAbsolute(bounds);
125
		getFeedbackLayer().translateToRelative(bounds);
126
		return bounds;
127
	}
128
129
	/**
130
	 * @generated
131
	 */
132
	protected IFigure createSelectionFeedbackFigure() {
133
		if (getHostFigure() instanceof Label) {
134
			Label feedbackFigure = new Label();
135
			feedbackFigure.setOpaque(true);
136
			feedbackFigure.setBackgroundColor(ColorConstants.menuBackgroundSelected);
137
			feedbackFigure.setForegroundColor(ColorConstants.menuForegroundSelected);
138
			return feedbackFigure;
139
		} else {
140
			RectangleFigure feedbackFigure = new RectangleFigure();
141
			feedbackFigure.setFill(false);
142
			return feedbackFigure;
143
		}
144
	}
145
146
	/**
147
	 * @generated
148
	 */
149
	protected IFigure createFocusFeedbackFigure() {
150
		return new Figure() {
151
152
			protected void paintFigure(Graphics graphics) {
153
				graphics.drawFocus(getBounds().getResized(-1, -1));
154
			}
155
		};
156
	}
157
158
	/**
159
	 * @generated
160
	 */
161
	protected void updateLabel(Label target) {
162
		Label source = (Label) getHostFigure();
163
		target.setText(source.getText());
164
		target.setTextAlignment(source.getTextAlignment());
165
		target.setFont(source.getFont());
166
	}
167
168
	/**
169
	 * @generated
170
	 */
171
	protected void refreshSelectionFeedback() {
172
		if (selectionFeedbackFigure != null) {
173
			if (selectionFeedbackFigure instanceof Label) {
174
				updateLabel((Label) selectionFeedbackFigure);
175
				selectionFeedbackFigure.setBounds(getFeedbackBounds());
176
			} else {
177
				selectionFeedbackFigure.setBounds(getFeedbackBounds().expand(5, 5));
178
			}
179
		}
180
	}
181
182
	/**
183
	 * @generated
184
	 */
185
	protected void refreshFocusFeedback() {
186
		if (focusFeedbackFigure != null) {
187
			focusFeedbackFigure.setBounds(getFeedbackBounds());
188
		}
189
	}
190
191
	/**
192
	 * @generated
193
	 */
194
	public void refreshFeedback() {
195
		refreshSelectionFeedback();
196
		refreshFocusFeedback();
197
	}
198
199
	/**
200
	 * @generated
201
	 */
202
	protected List createSelectionHandles() {
203
		MoveHandle moveHandle = new MoveHandle((GraphicalEditPart) getHost());
204
		moveHandle.setBorder(null);
205
		moveHandle.setDragTracker(new DragEditPartsTrackerEx(getHost()));
206
		return Collections.singletonList(moveHandle);
207
	}
208
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/parts/ClassOperationsEditPart.java (+67 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.parts;
2
3
import org.eclipse.emf.common.notify.Notification;
4
import org.eclipse.gef.EditPolicy;
5
import org.eclipse.gmf.runtime.diagram.ui.editparts.ListCompartmentEditPart;
6
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.CreationEditPolicy;
7
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.DragDropEditPolicy;
8
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
9
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.ResizableCompartmentEditPolicy;
10
import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout;
11
import org.eclipse.gmf.runtime.notation.View;
12
import org.eclipse.uml2.diagram.clazz.edit.policies.ClassOperationsCanonicalEditPolicy;
13
import org.eclipse.uml2.diagram.clazz.edit.policies.ClassOperationsItemSemanticEditPolicy;
14
15
/**
16
 * @generated
17
 */
18
public class ClassOperationsEditPart extends ListCompartmentEditPart {
19
20
	/**
21
	 * @generated
22
	 */
23
	public static final int VISUAL_ID = 7002;
24
25
	/**
26
	 * @generated
27
	 */
28
	public ClassOperationsEditPart(View view) {
29
		super(view);
30
	}
31
32
	/**
33
	 * @generated
34
	 */
35
	protected boolean hasModelChildrenChanged(Notification evt) {
36
		return false;
37
	}
38
39
	/**
40
	 * @generated
41
	 */
42
	public String getCompartmentName() {
43
		return "operations";
44
	}
45
46
	/**
47
	 * @generated
48
	 */
49
	protected void createDefaultEditPolicies() {
50
		super.createDefaultEditPolicies();
51
		installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ResizableCompartmentEditPolicy());
52
		installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new ClassOperationsItemSemanticEditPolicy());
53
		installEditPolicy(EditPolicyRoles.CREATION_ROLE, new CreationEditPolicy());
54
		installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, new DragDropEditPolicy());
55
		installEditPolicy(EditPolicyRoles.CANONICAL_ROLE, new ClassOperationsCanonicalEditPolicy());
56
57
	}
58
59
	/**
60
	 * @generated
61
	 */
62
	protected void setRatio(Double ratio) {
63
		if (getFigure().getParent().getLayoutManager() instanceof ConstrainedToolbarLayout) {
64
			super.setRatio(ratio);
65
		}
66
	}
67
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/policies/ConstraintItemSemanticEditPolicy.java (+264 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.policies;
2
3
import org.eclipse.emf.ecore.EAnnotation;
4
import org.eclipse.emf.ecore.EClass;
5
import org.eclipse.emf.ecore.EObject;
6
import org.eclipse.gef.commands.Command;
7
import org.eclipse.gef.commands.UnexecutableCommand;
8
import org.eclipse.gmf.runtime.emf.type.core.commands.CreateRelationshipCommand;
9
import org.eclipse.gmf.runtime.emf.type.core.commands.DestroyElementCommand;
10
import org.eclipse.gmf.runtime.emf.type.core.commands.SetValueCommand;
11
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest;
12
import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest;
13
import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest;
14
import org.eclipse.gmf.runtime.notation.View;
15
import org.eclipse.uml2.diagram.clazz.providers.UMLElementTypes;
16
import org.eclipse.uml2.uml.Constraint;
17
import org.eclipse.uml2.uml.Dependency;
18
import org.eclipse.uml2.uml.NamedElement;
19
import org.eclipse.uml2.uml.UMLPackage;
20
import org.eclipse.uml2.uml.Usage;
21
22
/**
23
 * @generated
24
 */
25
public class ConstraintItemSemanticEditPolicy extends UMLBaseItemSemanticEditPolicy {
26
27
	/**
28
	 * @generated
29
	 */
30
	protected Command getDestroyElementCommand(DestroyElementRequest req) {
31
		return getMSLWrapper(new DestroyElementCommand(req) {
32
33
			protected EObject getElementToDestroy() {
34
				View view = (View) getHost().getModel();
35
				EAnnotation annotation = view.getEAnnotation("Shortcut"); //$NON-NLS-1$
36
				if (annotation != null) {
37
					return view;
38
				}
39
				return super.getElementToDestroy();
40
			}
41
42
		});
43
	}
44
45
	/**
46
	 * @generated
47
	 */
48
	protected Command getCreateRelationshipCommand(CreateRelationshipRequest req) {
49
		if (UMLElementTypes.Dependency_4002 == req.getElementType()) {
50
			return req.getTarget() == null ? getCreateStartOutgoingDependency4002Command(req) : getCreateCompleteIncomingDependency4002Command(req);
51
		}
52
		if (UMLElementTypes.ConstraintConstrainedElement_4004 == req.getElementType()) {
53
			return req.getTarget() == null ? getCreateStartOutgoingConstraint_ConstrainedElement4004Command(req) : getCreateCompleteIncomingConstraint_ConstrainedElement4004Command(req);
54
		}
55
		if (UMLElementTypes.DependencySupplier_4006 == req.getElementType()) {
56
			return req.getTarget() == null ? null : getCreateCompleteIncomingDependency_Supplier4006Command(req);
57
		}
58
		if (UMLElementTypes.DependencyClient_4007 == req.getElementType()) {
59
			return req.getTarget() == null ? null : getCreateCompleteIncomingDependency_Client4007Command(req);
60
		}
61
		if (UMLElementTypes.Usage_4009 == req.getElementType()) {
62
			return req.getTarget() == null ? getCreateStartOutgoingUsage4009Command(req) : getCreateCompleteIncomingUsage4009Command(req);
63
		}
64
		return super.getCreateRelationshipCommand(req);
65
	}
66
67
	/**
68
	 * @generated
69
	 */
70
	protected Command getCreateStartOutgoingDependency4002Command(CreateRelationshipRequest req) {
71
		return new Command() {
72
		};
73
	}
74
75
	/**
76
	 * @generated
77
	 */
78
	protected Command getCreateCompleteIncomingDependency4002Command(CreateRelationshipRequest req) {
79
		if (!(req.getSource() instanceof NamedElement)) {
80
			return UnexecutableCommand.INSTANCE;
81
		}
82
		final org.eclipse.uml2.uml.Package element = (org.eclipse.uml2.uml.Package) getRelationshipContainer(req.getSource(), UMLPackage.eINSTANCE.getPackage(), req.getElementType());
83
		if (element == null) {
84
			return UnexecutableCommand.INSTANCE;
85
		}
86
		if (req.getContainmentFeature() == null) {
87
			req.setContainmentFeature(UMLPackage.eINSTANCE.getPackage_PackagedElement());
88
		}
89
		return getMSLWrapper(new CreateIncomingDependency4002Command(req) {
90
91
			protected EObject getElementToEdit() {
92
				return element;
93
			}
94
		});
95
	}
96
97
	/**
98
	 * @generated
99
	 */
100
	private static class CreateIncomingDependency4002Command extends CreateRelationshipCommand {
101
102
		/**
103
		 * @generated
104
		 */
105
		public CreateIncomingDependency4002Command(CreateRelationshipRequest req) {
106
			super(req);
107
		}
108
109
		/**
110
		 * @generated
111
		 */
112
		protected EClass getEClassToEdit() {
113
			return UMLPackage.eINSTANCE.getPackage();
114
		};
115
116
		/**
117
		 * @generated
118
		 */
119
		protected void setElementToEdit(EObject element) {
120
			throw new UnsupportedOperationException();
121
		}
122
123
		/**
124
		 * @generated
125
		 */
126
		protected EObject doDefaultElementCreation() {
127
			Dependency newElement = (Dependency) super.doDefaultElementCreation();
128
			if (newElement != null) {
129
				newElement.getSuppliers().add((NamedElement) getTarget());
130
				newElement.getClients().add((NamedElement) getSource());
131
			}
132
			return newElement;
133
		}
134
	}
135
136
	/**
137
	 * @generated
138
	 */
139
	protected Command getCreateStartOutgoingConstraint_ConstrainedElement4004Command(CreateRelationshipRequest req) {
140
141
		return new Command() {
142
		};
143
	}
144
145
	/**
146
	 * @generated
147
	 */
148
	protected Command getCreateCompleteIncomingConstraint_ConstrainedElement4004Command(CreateRelationshipRequest req) {
149
		if (!(req.getSource() instanceof Constraint)) {
150
			return UnexecutableCommand.INSTANCE;
151
		}
152
		Constraint element = (Constraint) req.getSource();
153
		if (element.getConstrainedElements().contains(req.getTarget())) {
154
			return UnexecutableCommand.INSTANCE;
155
		}
156
		SetRequest setReq = new SetRequest(req.getSource(), UMLPackage.eINSTANCE.getConstraint_ConstrainedElement(), req.getTarget());
157
		return getMSLWrapper(new SetValueCommand(setReq));
158
	}
159
160
	/**
161
	 * @generated
162
	 */
163
	protected Command getCreateCompleteIncomingDependency_Supplier4006Command(CreateRelationshipRequest req) {
164
		if (!(req.getSource() instanceof Dependency)) {
165
			return UnexecutableCommand.INSTANCE;
166
		}
167
		Dependency element = (Dependency) req.getSource();
168
		if (element.getSuppliers().contains(req.getTarget())) {
169
			return UnexecutableCommand.INSTANCE;
170
		}
171
		SetRequest setReq = new SetRequest(req.getSource(), UMLPackage.eINSTANCE.getDependency_Supplier(), req.getTarget());
172
		return getMSLWrapper(new SetValueCommand(setReq));
173
	}
174
175
	/**
176
	 * @generated
177
	 */
178
	protected Command getCreateCompleteIncomingDependency_Client4007Command(CreateRelationshipRequest req) {
179
		if (!(req.getSource() instanceof Dependency)) {
180
			return UnexecutableCommand.INSTANCE;
181
		}
182
		Dependency element = (Dependency) req.getSource();
183
		if (element.getClients().contains(req.getTarget())) {
184
			return UnexecutableCommand.INSTANCE;
185
		}
186
		SetRequest setReq = new SetRequest(req.getSource(), UMLPackage.eINSTANCE.getDependency_Client(), req.getTarget());
187
		return getMSLWrapper(new SetValueCommand(setReq));
188
	}
189
190
	/**
191
	 * @generated
192
	 */
193
	protected Command getCreateStartOutgoingUsage4009Command(CreateRelationshipRequest req) {
194
		if (!UMLBaseItemSemanticEditPolicy.LinkConstraints.Usage_4009.canCreateLink(req, false)) {
195
			return UnexecutableCommand.INSTANCE;
196
		}
197
		return new Command() {
198
		};
199
	}
200
201
	/**
202
	 * @generated
203
	 */
204
	protected Command getCreateCompleteIncomingUsage4009Command(CreateRelationshipRequest req) {
205
		if (!(req.getSource() instanceof NamedElement)) {
206
			return UnexecutableCommand.INSTANCE;
207
		}
208
		final org.eclipse.uml2.uml.Package element = (org.eclipse.uml2.uml.Package) getRelationshipContainer(req.getSource(), UMLPackage.eINSTANCE.getPackage(), req.getElementType());
209
		if (element == null) {
210
			return UnexecutableCommand.INSTANCE;
211
		}
212
		if (!UMLBaseItemSemanticEditPolicy.LinkConstraints.Usage_4009.canCreateLink(req, false)) {
213
			return UnexecutableCommand.INSTANCE;
214
		}
215
		if (req.getContainmentFeature() == null) {
216
			req.setContainmentFeature(UMLPackage.eINSTANCE.getPackage_PackagedElement());
217
		}
218
		return getMSLWrapper(new CreateIncomingUsage4009Command(req) {
219
220
			protected EObject getElementToEdit() {
221
				return element;
222
			}
223
		});
224
	}
225
226
	/**
227
	 * @generated
228
	 */
229
	private static class CreateIncomingUsage4009Command extends CreateRelationshipCommand {
230
231
		/**
232
		 * @generated
233
		 */
234
		public CreateIncomingUsage4009Command(CreateRelationshipRequest req) {
235
			super(req);
236
		}
237
238
		/**
239
		 * @generated
240
		 */
241
		protected EClass getEClassToEdit() {
242
			return UMLPackage.eINSTANCE.getPackage();
243
		};
244
245
		/**
246
		 * @generated
247
		 */
248
		protected void setElementToEdit(EObject element) {
249
			throw new UnsupportedOperationException();
250
		}
251
252
		/**
253
		 * @generated
254
		 */
255
		protected EObject doDefaultElementCreation() {
256
			Usage newElement = (Usage) super.doDefaultElementCreation();
257
			if (newElement != null) {
258
				newElement.getSuppliers().add((NamedElement) getTarget());
259
				newElement.getClients().add((NamedElement) getSource());
260
			}
261
			return newElement;
262
		}
263
	}
264
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/policies/LiteralStringItemSemanticEditPolicy.java (+255 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.policies;
2
3
import org.eclipse.emf.ecore.EAnnotation;
4
import org.eclipse.emf.ecore.EClass;
5
import org.eclipse.emf.ecore.EObject;
6
import org.eclipse.gef.commands.Command;
7
import org.eclipse.gef.commands.UnexecutableCommand;
8
import org.eclipse.gmf.runtime.emf.type.core.commands.CreateRelationshipCommand;
9
import org.eclipse.gmf.runtime.emf.type.core.commands.DestroyElementCommand;
10
import org.eclipse.gmf.runtime.emf.type.core.commands.SetValueCommand;
11
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest;
12
import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest;
13
import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest;
14
import org.eclipse.gmf.runtime.notation.View;
15
import org.eclipse.uml2.diagram.clazz.providers.UMLElementTypes;
16
import org.eclipse.uml2.uml.Constraint;
17
import org.eclipse.uml2.uml.Dependency;
18
import org.eclipse.uml2.uml.NamedElement;
19
import org.eclipse.uml2.uml.UMLPackage;
20
import org.eclipse.uml2.uml.Usage;
21
22
/**
23
 * @generated
24
 */
25
public class LiteralStringItemSemanticEditPolicy extends UMLBaseItemSemanticEditPolicy {
26
27
	/**
28
	 * @generated
29
	 */
30
	protected Command getDestroyElementCommand(DestroyElementRequest req) {
31
		return getMSLWrapper(new DestroyElementCommand(req) {
32
33
			protected EObject getElementToDestroy() {
34
				View view = (View) getHost().getModel();
35
				EAnnotation annotation = view.getEAnnotation("Shortcut"); //$NON-NLS-1$
36
				if (annotation != null) {
37
					return view;
38
				}
39
				return super.getElementToDestroy();
40
			}
41
42
		});
43
	}
44
45
	/**
46
	 * @generated
47
	 */
48
	protected Command getCreateRelationshipCommand(CreateRelationshipRequest req) {
49
		if (UMLElementTypes.Dependency_4002 == req.getElementType()) {
50
			return req.getTarget() == null ? getCreateStartOutgoingDependency4002Command(req) : getCreateCompleteIncomingDependency4002Command(req);
51
		}
52
		if (UMLElementTypes.ConstraintConstrainedElement_4004 == req.getElementType()) {
53
			return req.getTarget() == null ? null : getCreateCompleteIncomingConstraint_ConstrainedElement4004Command(req);
54
		}
55
		if (UMLElementTypes.DependencySupplier_4006 == req.getElementType()) {
56
			return req.getTarget() == null ? null : getCreateCompleteIncomingDependency_Supplier4006Command(req);
57
		}
58
		if (UMLElementTypes.DependencyClient_4007 == req.getElementType()) {
59
			return req.getTarget() == null ? null : getCreateCompleteIncomingDependency_Client4007Command(req);
60
		}
61
		if (UMLElementTypes.Usage_4009 == req.getElementType()) {
62
			return req.getTarget() == null ? getCreateStartOutgoingUsage4009Command(req) : getCreateCompleteIncomingUsage4009Command(req);
63
		}
64
		return super.getCreateRelationshipCommand(req);
65
	}
66
67
	/**
68
	 * @generated
69
	 */
70
	protected Command getCreateStartOutgoingDependency4002Command(CreateRelationshipRequest req) {
71
		return new Command() {
72
		};
73
	}
74
75
	/**
76
	 * @generated
77
	 */
78
	protected Command getCreateCompleteIncomingDependency4002Command(CreateRelationshipRequest req) {
79
		if (!(req.getSource() instanceof NamedElement)) {
80
			return UnexecutableCommand.INSTANCE;
81
		}
82
		final org.eclipse.uml2.uml.Package element = (org.eclipse.uml2.uml.Package) getRelationshipContainer(req.getSource(), UMLPackage.eINSTANCE.getPackage(), req.getElementType());
83
		if (element == null) {
84
			return UnexecutableCommand.INSTANCE;
85
		}
86
		if (req.getContainmentFeature() == null) {
87
			req.setContainmentFeature(UMLPackage.eINSTANCE.getPackage_PackagedElement());
88
		}
89
		return getMSLWrapper(new CreateIncomingDependency4002Command(req) {
90
91
			protected EObject getElementToEdit() {
92
				return element;
93
			}
94
		});
95
	}
96
97
	/**
98
	 * @generated
99
	 */
100
	private static class CreateIncomingDependency4002Command extends CreateRelationshipCommand {
101
102
		/**
103
		 * @generated
104
		 */
105
		public CreateIncomingDependency4002Command(CreateRelationshipRequest req) {
106
			super(req);
107
		}
108
109
		/**
110
		 * @generated
111
		 */
112
		protected EClass getEClassToEdit() {
113
			return UMLPackage.eINSTANCE.getPackage();
114
		};
115
116
		/**
117
		 * @generated
118
		 */
119
		protected void setElementToEdit(EObject element) {
120
			throw new UnsupportedOperationException();
121
		}
122
123
		/**
124
		 * @generated
125
		 */
126
		protected EObject doDefaultElementCreation() {
127
			Dependency newElement = (Dependency) super.doDefaultElementCreation();
128
			if (newElement != null) {
129
				newElement.getSuppliers().add((NamedElement) getTarget());
130
				newElement.getClients().add((NamedElement) getSource());
131
			}
132
			return newElement;
133
		}
134
	}
135
136
	/**
137
	 * @generated
138
	 */
139
	protected Command getCreateCompleteIncomingConstraint_ConstrainedElement4004Command(CreateRelationshipRequest req) {
140
		if (!(req.getSource() instanceof Constraint)) {
141
			return UnexecutableCommand.INSTANCE;
142
		}
143
		Constraint element = (Constraint) req.getSource();
144
		if (element.getConstrainedElements().contains(req.getTarget())) {
145
			return UnexecutableCommand.INSTANCE;
146
		}
147
		SetRequest setReq = new SetRequest(req.getSource(), UMLPackage.eINSTANCE.getConstraint_ConstrainedElement(), req.getTarget());
148
		return getMSLWrapper(new SetValueCommand(setReq));
149
	}
150
151
	/**
152
	 * @generated
153
	 */
154
	protected Command getCreateCompleteIncomingDependency_Supplier4006Command(CreateRelationshipRequest req) {
155
		if (!(req.getSource() instanceof Dependency)) {
156
			return UnexecutableCommand.INSTANCE;
157
		}
158
		Dependency element = (Dependency) req.getSource();
159
		if (element.getSuppliers().contains(req.getTarget())) {
160
			return UnexecutableCommand.INSTANCE;
161
		}
162
		SetRequest setReq = new SetRequest(req.getSource(), UMLPackage.eINSTANCE.getDependency_Supplier(), req.getTarget());
163
		return getMSLWrapper(new SetValueCommand(setReq));
164
	}
165
166
	/**
167
	 * @generated
168
	 */
169
	protected Command getCreateCompleteIncomingDependency_Client4007Command(CreateRelationshipRequest req) {
170
		if (!(req.getSource() instanceof Dependency)) {
171
			return UnexecutableCommand.INSTANCE;
172
		}
173
		Dependency element = (Dependency) req.getSource();
174
		if (element.getClients().contains(req.getTarget())) {
175
			return UnexecutableCommand.INSTANCE;
176
		}
177
		SetRequest setReq = new SetRequest(req.getSource(), UMLPackage.eINSTANCE.getDependency_Client(), req.getTarget());
178
		return getMSLWrapper(new SetValueCommand(setReq));
179
	}
180
181
	/**
182
	 * @generated
183
	 */
184
	protected Command getCreateStartOutgoingUsage4009Command(CreateRelationshipRequest req) {
185
		if (!UMLBaseItemSemanticEditPolicy.LinkConstraints.Usage_4009.canCreateLink(req, false)) {
186
			return UnexecutableCommand.INSTANCE;
187
		}
188
		return new Command() {
189
		};
190
	}
191
192
	/**
193
	 * @generated
194
	 */
195
	protected Command getCreateCompleteIncomingUsage4009Command(CreateRelationshipRequest req) {
196
		if (!(req.getSource() instanceof NamedElement)) {
197
			return UnexecutableCommand.INSTANCE;
198
		}
199
		final org.eclipse.uml2.uml.Package element = (org.eclipse.uml2.uml.Package) getRelationshipContainer(req.getSource(), UMLPackage.eINSTANCE.getPackage(), req.getElementType());
200
		if (element == null) {
201
			return UnexecutableCommand.INSTANCE;
202
		}
203
		if (!UMLBaseItemSemanticEditPolicy.LinkConstraints.Usage_4009.canCreateLink(req, false)) {
204
			return UnexecutableCommand.INSTANCE;
205
		}
206
		if (req.getContainmentFeature() == null) {
207
			req.setContainmentFeature(UMLPackage.eINSTANCE.getPackage_PackagedElement());
208
		}
209
		return getMSLWrapper(new CreateIncomingUsage4009Command(req) {
210
211
			protected EObject getElementToEdit() {
212
				return element;
213
			}
214
		});
215
	}
216
217
	/**
218
	 * @generated
219
	 */
220
	private static class CreateIncomingUsage4009Command extends CreateRelationshipCommand {
221
222
		/**
223
		 * @generated
224
		 */
225
		public CreateIncomingUsage4009Command(CreateRelationshipRequest req) {
226
			super(req);
227
		}
228
229
		/**
230
		 * @generated
231
		 */
232
		protected EClass getEClassToEdit() {
233
			return UMLPackage.eINSTANCE.getPackage();
234
		};
235
236
		/**
237
		 * @generated
238
		 */
239
		protected void setElementToEdit(EObject element) {
240
			throw new UnsupportedOperationException();
241
		}
242
243
		/**
244
		 * @generated
245
		 */
246
		protected EObject doDefaultElementCreation() {
247
			Usage newElement = (Usage) super.doDefaultElementCreation();
248
			if (newElement != null) {
249
				newElement.getSuppliers().add((NamedElement) getTarget());
250
				newElement.getClients().add((NamedElement) getSource());
251
			}
252
			return newElement;
253
		}
254
	}
255
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/policies/PackageCanonicalEditPolicy.java (+655 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.policies;
2
3
import java.util.Collection;
4
import java.util.Collections;
5
import java.util.HashMap;
6
import java.util.Iterator;
7
import java.util.LinkedList;
8
import java.util.List;
9
import java.util.Map;
10
11
import org.eclipse.core.runtime.IAdaptable;
12
import org.eclipse.emf.ecore.EClass;
13
import org.eclipse.emf.ecore.EObject;
14
import org.eclipse.gef.EditPart;
15
import org.eclipse.gef.commands.Command;
16
import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil;
17
import org.eclipse.gmf.runtime.diagram.ui.commands.DeferredLayoutCommand;
18
import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
19
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
20
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.CanonicalConnectionEditPolicy;
21
import org.eclipse.gmf.runtime.diagram.ui.requests.CreateConnectionViewRequest;
22
import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants;
23
import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
24
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
25
import org.eclipse.gmf.runtime.notation.Diagram;
26
import org.eclipse.gmf.runtime.notation.Edge;
27
import org.eclipse.gmf.runtime.notation.View;
28
import org.eclipse.uml2.diagram.clazz.association.AssociationEndConvention;
29
import org.eclipse.uml2.diagram.clazz.edit.parts.AssociationClass2EditPart;
30
import org.eclipse.uml2.diagram.clazz.edit.parts.AssociationClassEditPart;
31
import org.eclipse.uml2.diagram.clazz.edit.parts.AssociationEditPart;
32
import org.eclipse.uml2.diagram.clazz.edit.parts.Class2EditPart;
33
import org.eclipse.uml2.diagram.clazz.edit.parts.Class3EditPart;
34
import org.eclipse.uml2.diagram.clazz.edit.parts.ClassEditPart;
35
import org.eclipse.uml2.diagram.clazz.edit.parts.ConstraintConstrainedElementEditPart;
36
import org.eclipse.uml2.diagram.clazz.edit.parts.ConstraintEditPart;
37
import org.eclipse.uml2.diagram.clazz.edit.parts.DataType2EditPart;
38
import org.eclipse.uml2.diagram.clazz.edit.parts.DataTypeEditPart;
39
import org.eclipse.uml2.diagram.clazz.edit.parts.Dependency2EditPart;
40
import org.eclipse.uml2.diagram.clazz.edit.parts.DependencyClientEditPart;
41
import org.eclipse.uml2.diagram.clazz.edit.parts.DependencyEditPart;
42
import org.eclipse.uml2.diagram.clazz.edit.parts.DependencySupplierEditPart;
43
import org.eclipse.uml2.diagram.clazz.edit.parts.Enumeration2EditPart;
44
import org.eclipse.uml2.diagram.clazz.edit.parts.EnumerationEditPart;
45
import org.eclipse.uml2.diagram.clazz.edit.parts.EnumerationLiteralEditPart;
46
import org.eclipse.uml2.diagram.clazz.edit.parts.GeneralizationEditPart;
47
import org.eclipse.uml2.diagram.clazz.edit.parts.InstanceSpecification2EditPart;
48
import org.eclipse.uml2.diagram.clazz.edit.parts.InstanceSpecificationEditPart;
49
import org.eclipse.uml2.diagram.clazz.edit.parts.InterfaceEditPart;
50
import org.eclipse.uml2.diagram.clazz.edit.parts.InterfaceRealizationEditPart;
51
import org.eclipse.uml2.diagram.clazz.edit.parts.LiteralStringEditPart;
52
import org.eclipse.uml2.diagram.clazz.edit.parts.Operation2EditPart;
53
import org.eclipse.uml2.diagram.clazz.edit.parts.Operation3EditPart;
54
import org.eclipse.uml2.diagram.clazz.edit.parts.Operation4EditPart;
55
import org.eclipse.uml2.diagram.clazz.edit.parts.Operation5EditPart;
56
import org.eclipse.uml2.diagram.clazz.edit.parts.OperationEditPart;
57
import org.eclipse.uml2.diagram.clazz.edit.parts.Package2EditPart;
58
import org.eclipse.uml2.diagram.clazz.edit.parts.Package3EditPart;
59
import org.eclipse.uml2.diagram.clazz.edit.parts.PackageEditPart;
60
import org.eclipse.uml2.diagram.clazz.edit.parts.PortEditPart;
61
import org.eclipse.uml2.diagram.clazz.edit.parts.PrimitiveType2EditPart;
62
import org.eclipse.uml2.diagram.clazz.edit.parts.PrimitiveTypeEditPart;
63
import org.eclipse.uml2.diagram.clazz.edit.parts.Property2EditPart;
64
import org.eclipse.uml2.diagram.clazz.edit.parts.Property3EditPart;
65
import org.eclipse.uml2.diagram.clazz.edit.parts.Property4EditPart;
66
import org.eclipse.uml2.diagram.clazz.edit.parts.Property5EditPart;
67
import org.eclipse.uml2.diagram.clazz.edit.parts.Property6EditPart;
68
import org.eclipse.uml2.diagram.clazz.edit.parts.PropertyEditPart;
69
import org.eclipse.uml2.diagram.clazz.edit.parts.SlotEditPart;
70
import org.eclipse.uml2.diagram.clazz.edit.parts.UsageEditPart;
71
import org.eclipse.uml2.diagram.clazz.part.UMLVisualIDRegistry;
72
import org.eclipse.uml2.diagram.clazz.providers.UMLElementTypes;
73
import org.eclipse.uml2.uml.Association;
74
import org.eclipse.uml2.uml.BehavioredClassifier;
75
import org.eclipse.uml2.uml.Classifier;
76
import org.eclipse.uml2.uml.Constraint;
77
import org.eclipse.uml2.uml.Dependency;
78
import org.eclipse.uml2.uml.Generalization;
79
import org.eclipse.uml2.uml.InterfaceRealization;
80
import org.eclipse.uml2.uml.Property;
81
import org.eclipse.uml2.uml.TypedElement;
82
import org.eclipse.uml2.uml.UMLPackage;
83
84
/**
85
 * @generated
86
 */
87
public class PackageCanonicalEditPolicy extends CanonicalConnectionEditPolicy {
88
89
	/**
90
	 * @generated
91
	 */
92
	protected List getSemanticChildrenList() {
93
		List result = new LinkedList();
94
		EObject modelObject = ((View) getHost().getModel()).getElement();
95
		View viewObject = (View) getHost().getModel();
96
		EObject nextValue;
97
		int nodeVID;
98
		for (Iterator values = ((org.eclipse.uml2.uml.Package) modelObject).getNestedPackages().iterator(); values.hasNext();) {
99
			nextValue = (EObject) values.next();
100
			nodeVID = UMLVisualIDRegistry.getNodeVisualID(viewObject, nextValue);
101
			if (Package2EditPart.VISUAL_ID == nodeVID) {
102
				result.add(nextValue);
103
			}
104
		}
105
		for (Iterator values = ((org.eclipse.uml2.uml.Package) modelObject).getOwnedTypes().iterator(); values.hasNext();) {
106
			nextValue = (EObject) values.next();
107
			nodeVID = UMLVisualIDRegistry.getNodeVisualID(viewObject, nextValue);
108
			switch (nodeVID) {
109
			case Class2EditPart.VISUAL_ID: {
110
				result.add(nextValue);
111
				break;
112
			}
113
			case AssociationClass2EditPart.VISUAL_ID: {
114
				result.add(nextValue);
115
				break;
116
			}
117
			case DataType2EditPart.VISUAL_ID: {
118
				result.add(nextValue);
119
				break;
120
			}
121
			case PrimitiveType2EditPart.VISUAL_ID: {
122
				result.add(nextValue);
123
				break;
124
			}
125
			case Enumeration2EditPart.VISUAL_ID: {
126
				result.add(nextValue);
127
				break;
128
			}
129
			case InterfaceEditPart.VISUAL_ID: {
130
				result.add(nextValue);
131
				break;
132
			}
133
			}
134
		}
135
		for (Iterator values = ((org.eclipse.uml2.uml.Package) modelObject).getPackagedElements().iterator(); values.hasNext();) {
136
			nextValue = (EObject) values.next();
137
			nodeVID = UMLVisualIDRegistry.getNodeVisualID(viewObject, nextValue);
138
			switch (nodeVID) {
139
			case ConstraintEditPart.VISUAL_ID: {
140
				result.add(nextValue);
141
				break;
142
			}
143
			case InstanceSpecification2EditPart.VISUAL_ID: {
144
				result.add(nextValue);
145
				break;
146
			}
147
			case DependencyEditPart.VISUAL_ID: {
148
				result.add(nextValue);
149
				break;
150
			}
151
			}
152
		}
153
		return result;
154
	}
155
156
	/**
157
	 * @generated
158
	 */
159
	protected boolean shouldDeleteView(View view) {
160
		return view.isSetElement() && view.getElement() != null && view.getElement().eIsProxy();
161
	}
162
163
	/**
164
	 * @generated
165
	 */
166
	protected String getDefaultFactoryHint() {
167
		return null;
168
	}
169
170
	/**
171
	 * @generated
172
	 */
173
	protected List getSemanticConnectionsList() {
174
		return Collections.EMPTY_LIST;
175
	}
176
177
	/**
178
	 * @generated
179
	 */
180
	protected EObject getSourceElement(EObject relationship) {
181
		return null;
182
	}
183
184
	/**
185
	 * @generated
186
	 */
187
	protected EObject getTargetElement(EObject relationship) {
188
		return null;
189
	}
190
191
	/**
192
	 * @generated
193
	 */
194
	protected boolean shouldIncludeConnection(Edge connector, Collection children) {
195
		return false;
196
	}
197
198
	/**
199
	 * @generated
200
	 */
201
	protected void refreshSemantic() {
202
		List createdViews = new LinkedList();
203
		createdViews.addAll(refreshSemanticChildren());
204
		List createdConnectionViews = new LinkedList();
205
		createdConnectionViews.addAll(refreshSemanticConnections());
206
		createdConnectionViews.addAll(refreshConnections());
207
208
		if (createdViews.size() > 1) {
209
			// perform a layout of the container
210
			DeferredLayoutCommand layoutCmd = new DeferredLayoutCommand(host().getEditingDomain(), createdViews, host());
211
			executeCommand(new ICommandProxy(layoutCmd));
212
		}
213
214
		createdViews.addAll(createdConnectionViews);
215
		makeViewsImmutable(createdViews);
216
	}
217
218
	/**
219
	 * @generated
220
	 */
221
	private Collection myLinkDescriptors = new LinkedList();
222
223
	/**
224
	 * @generated
225
	 */
226
	private Map myEObject2ViewMap = new HashMap();
227
228
	/**
229
	 * @generated
230
	 */
231
	private Collection refreshConnections() {
232
		try {
233
			collectAllLinks(getDiagram());
234
			Collection existingLinks = new LinkedList(getDiagram().getEdges());
235
			for (Iterator diagramLinks = existingLinks.iterator(); diagramLinks.hasNext();) {
236
				Edge nextDiagramLink = (Edge) diagramLinks.next();
237
				EObject diagramLinkObject = nextDiagramLink.getElement();
238
				EObject diagramLinkSrc = nextDiagramLink.getSource().getElement();
239
				EObject diagramLinkDst = nextDiagramLink.getTarget().getElement();
240
				int diagramLinkVisualID = UMLVisualIDRegistry.getVisualID(nextDiagramLink);
241
				for (Iterator modelLinkDescriptors = myLinkDescriptors.iterator(); modelLinkDescriptors.hasNext();) {
242
					LinkDescriptor nextLinkDescriptor = (LinkDescriptor) modelLinkDescriptors.next();
243
					if (diagramLinkObject == nextLinkDescriptor.getLinkElement() && diagramLinkSrc == nextLinkDescriptor.getSource() && diagramLinkDst == nextLinkDescriptor.getDestination()
244
							&& diagramLinkVisualID == nextLinkDescriptor.getVisualID()) {
245
						diagramLinks.remove();
246
						modelLinkDescriptors.remove();
247
					}
248
				}
249
			}
250
			deleteViews(existingLinks.iterator());
251
			return createConnections(myLinkDescriptors);
252
		} finally {
253
			myLinkDescriptors.clear();
254
			myEObject2ViewMap.clear();
255
		}
256
	}
257
258
	/**
259
	 * @generated
260
	 */
261
	private void collectAllLinks(View view) {
262
		EObject modelElement = view.getElement();
263
		int diagramElementVisualID = UMLVisualIDRegistry.getVisualID(view);
264
		switch (diagramElementVisualID) {
265
		case Package2EditPart.VISUAL_ID:
266
		case Class2EditPart.VISUAL_ID:
267
		case AssociationClass2EditPart.VISUAL_ID:
268
		case DataType2EditPart.VISUAL_ID:
269
		case PrimitiveType2EditPart.VISUAL_ID:
270
		case Enumeration2EditPart.VISUAL_ID:
271
		case InterfaceEditPart.VISUAL_ID:
272
		case ConstraintEditPart.VISUAL_ID:
273
		case InstanceSpecification2EditPart.VISUAL_ID:
274
		case DependencyEditPart.VISUAL_ID:
275
		case Package3EditPart.VISUAL_ID:
276
		case ClassEditPart.VISUAL_ID:
277
		case DataTypeEditPart.VISUAL_ID:
278
		case PrimitiveTypeEditPart.VISUAL_ID:
279
		case EnumerationEditPart.VISUAL_ID:
280
		case AssociationClassEditPart.VISUAL_ID:
281
		case InstanceSpecificationEditPart.VISUAL_ID:
282
		case PropertyEditPart.VISUAL_ID:
283
		case OperationEditPart.VISUAL_ID:
284
		case Class3EditPart.VISUAL_ID:
285
		case PortEditPart.VISUAL_ID:
286
		case Property2EditPart.VISUAL_ID:
287
		case Operation2EditPart.VISUAL_ID:
288
		case Property3EditPart.VISUAL_ID:
289
		case Operation3EditPart.VISUAL_ID:
290
		case Property4EditPart.VISUAL_ID:
291
		case Operation4EditPart.VISUAL_ID:
292
		case EnumerationLiteralEditPart.VISUAL_ID:
293
		case Property5EditPart.VISUAL_ID:
294
		case Operation5EditPart.VISUAL_ID:
295
		case LiteralStringEditPart.VISUAL_ID:
296
		case SlotEditPart.VISUAL_ID:
297
		case PackageEditPart.VISUAL_ID: {
298
			myEObject2ViewMap.put(modelElement, view);
299
			storeLinks(modelElement, getDiagram());
300
		}
301
		default: {
302
		}
303
			for (Iterator children = view.getChildren().iterator(); children.hasNext();) {
304
				View childView = (View) children.next();
305
				collectAllLinks(childView);
306
			}
307
		}
308
	}
309
310
	/**
311
	 * @generated
312
	 */
313
	private Collection createConnections(Collection linkDescriptors) {
314
		if (linkDescriptors.isEmpty()) {
315
			return Collections.EMPTY_LIST;
316
		}
317
		List adapters = new LinkedList();
318
		for (Iterator linkDescriptorsIterator = linkDescriptors.iterator(); linkDescriptorsIterator.hasNext();) {
319
			final LinkDescriptor nextLinkDescriptor = (LinkDescriptor) linkDescriptorsIterator.next();
320
			EditPart sourceEditPart = getEditPartFor(nextLinkDescriptor.getSource());
321
			EditPart targetEditPart = getEditPartFor(nextLinkDescriptor.getDestination());
322
			if (sourceEditPart == null || targetEditPart == null) {
323
				continue;
324
			}
325
			CreateConnectionViewRequest.ConnectionViewDescriptor descriptor = new CreateConnectionViewRequest.ConnectionViewDescriptor(nextLinkDescriptor.getSemanticAdapter(), null, ViewUtil.APPEND,
326
					false, ((IGraphicalEditPart) getHost()).getDiagramPreferencesHint());
327
			CreateConnectionViewRequest ccr = new CreateConnectionViewRequest(descriptor);
328
			ccr.setType(RequestConstants.REQ_CONNECTION_START);
329
			ccr.setSourceEditPart(sourceEditPart);
330
			sourceEditPart.getCommand(ccr);
331
			ccr.setTargetEditPart(targetEditPart);
332
			ccr.setType(RequestConstants.REQ_CONNECTION_END);
333
			Command cmd = targetEditPart.getCommand(ccr);
334
			if (cmd != null && cmd.canExecute()) {
335
				executeCommand(cmd);
336
				IAdaptable viewAdapter = (IAdaptable) ccr.getNewObject();
337
				if (viewAdapter != null) {
338
					adapters.add(viewAdapter);
339
				}
340
			}
341
		}
342
		return adapters;
343
	}
344
345
	/**
346
	 * @generated
347
	 */
348
	private EditPart getEditPartFor(EObject modelElement) {
349
		View view = (View) myEObject2ViewMap.get(modelElement);
350
		if (view != null) {
351
			return (EditPart) getHost().getViewer().getEditPartRegistry().get(view);
352
		}
353
		return null;
354
	}
355
356
	/**
357
	 *@generated
358
	 */
359
	private void storeLinks(EObject container, Diagram diagram) {
360
		EClass containerMetaclass = container.eClass();
361
		storeFeatureModelFacetLinks(container, containerMetaclass, diagram);
362
		storeTypeModelFacetLinks(container, containerMetaclass);
363
	}
364
365
	/**
366
	 * @generated
367
	 */
368
	private void storeTypeModelFacetLinks(EObject container, EClass containerMetaclass) {
369
		storeTypeModelFacetLinks_Generalization_4001(container, containerMetaclass);
370
		storeTypeModelFacetLinks_Dependency_4002(container, containerMetaclass);
371
		storeTypeModelFacetLinks_Property_4003(container, containerMetaclass);
372
		storeTypeModelFacetLinks_Association_4005(container, containerMetaclass);
373
		storeTypeModelFacetLinks_InterfaceRealization_4008(container, containerMetaclass);
374
		storeTypeModelFacetLinks_Usage_4009(container, containerMetaclass);
375
	}
376
377
	/**
378
	 * @generated
379
	 */
380
	private void storeTypeModelFacetLinks_Generalization_4001(EObject container, EClass containerMetaclass) {
381
		if (UMLPackage.eINSTANCE.getClassifier().isSuperTypeOf(containerMetaclass)) {
382
			for (Iterator values = ((Classifier) container).getGeneralizations().iterator(); values.hasNext();) {
383
				EObject nextValue = ((EObject) values.next());
384
				int linkVID = UMLVisualIDRegistry.getLinkWithClassVisualID(nextValue);
385
				if (GeneralizationEditPart.VISUAL_ID == linkVID) {
386
					Object structuralFeatureResult = ((Generalization) nextValue).getGeneral();
387
					if (structuralFeatureResult instanceof EObject) {
388
						EObject dst = (EObject) structuralFeatureResult;
389
						EObject src = container;
390
						myLinkDescriptors.add(new LinkDescriptor(src, dst, nextValue, linkVID));
391
					}
392
				}
393
			}
394
		}
395
	}
396
397
	/**
398
	 * @generated
399
	 */
400
	private void storeTypeModelFacetLinks_Dependency_4002(EObject container, EClass containerMetaclass) {
401
		if (UMLPackage.eINSTANCE.getPackage().isSuperTypeOf(containerMetaclass)) {
402
			for (Iterator values = ((org.eclipse.uml2.uml.Package) container).getPackagedElements().iterator(); values.hasNext();) {
403
				EObject nextValue = ((EObject) values.next());
404
				int linkVID = UMLVisualIDRegistry.getLinkWithClassVisualID(nextValue);
405
				if (Dependency2EditPart.VISUAL_ID == linkVID) {
406
					Object structuralFeatureResult = ((Dependency) nextValue).getSuppliers();
407
					List targets = (List) structuralFeatureResult;
408
					structuralFeatureResult = targets.size() == 1 ? targets.get(0) : null;
409
					if (structuralFeatureResult instanceof EObject) {
410
						EObject dst = (EObject) structuralFeatureResult;
411
						structuralFeatureResult = ((Dependency) nextValue).getClients();
412
						List sources = (List) structuralFeatureResult;
413
						structuralFeatureResult = sources.size() == 1 ? sources.get(0) : null;
414
						if (structuralFeatureResult instanceof EObject) {
415
							EObject src = (EObject) structuralFeatureResult;
416
							myLinkDescriptors.add(new LinkDescriptor(src, dst, nextValue, linkVID));
417
						}
418
					}
419
				}
420
			}
421
		}
422
	}
423
424
	/**
425
	 * @generated
426
	 */
427
	private void storeTypeModelFacetLinks_Property_4003(EObject container, EClass containerMetaclass) {
428
		if (UMLPackage.eINSTANCE.getAssociation().isSuperTypeOf(containerMetaclass)) {
429
			for (Iterator values = ((Association) container).getOwnedEnds().iterator(); values.hasNext();) {
430
				EObject nextValue = ((EObject) values.next());
431
				int linkVID = UMLVisualIDRegistry.getLinkWithClassVisualID(nextValue);
432
				if (Property6EditPart.VISUAL_ID == linkVID) {
433
					Object structuralFeatureResult = ((TypedElement) nextValue).getType();
434
					if (structuralFeatureResult instanceof EObject) {
435
						EObject dst = (EObject) structuralFeatureResult;
436
						EObject src = container;
437
						myLinkDescriptors.add(new LinkDescriptor(src, dst, nextValue, linkVID));
438
					}
439
				}
440
			}
441
		}
442
	}
443
444
	/**
445
	 * @generated NOT
446
	 */
447
	private void storeTypeModelFacetLinks_Association_4005(EObject container, EClass containerMetaclass) {
448
		if (UMLPackage.eINSTANCE.getPackage().isSuperTypeOf(containerMetaclass)) {
449
			for (Iterator values = ((org.eclipse.uml2.uml.Package) container).getPackagedElements().iterator(); values.hasNext();) {
450
				EObject nextValue = ((EObject) values.next());
451
				int linkVID = UMLVisualIDRegistry.getLinkWithClassVisualID(nextValue);
452
				if (AssociationEditPart.VISUAL_ID == linkVID) {
453
					Association association = (Association) nextValue;
454
					if (association.isBinary()) {
455
						Property sourceEnd = AssociationEndConvention.getSourceEnd(association);
456
						Property targetEnd = AssociationEndConvention.getTargetEnd(association);
457
						EObject gmfSource = sourceEnd.getType();
458
						EObject gmfTarget = targetEnd.getType();
459
						myLinkDescriptors.add(new LinkDescriptor(gmfSource, gmfTarget, association, linkVID));
460
					}
461
				}
462
			}
463
		}
464
	}
465
466
	/**
467
	 * @generated
468
	 */
469
	private void storeTypeModelFacetLinks_InterfaceRealization_4008(EObject container, EClass containerMetaclass) {
470
		if (UMLPackage.eINSTANCE.getBehavioredClassifier().isSuperTypeOf(containerMetaclass)) {
471
			for (Iterator values = ((BehavioredClassifier) container).getInterfaceRealizations().iterator(); values.hasNext();) {
472
				EObject nextValue = ((EObject) values.next());
473
				int linkVID = UMLVisualIDRegistry.getLinkWithClassVisualID(nextValue);
474
				if (InterfaceRealizationEditPart.VISUAL_ID == linkVID) {
475
					Object structuralFeatureResult = ((InterfaceRealization) nextValue).getContract();
476
					if (structuralFeatureResult instanceof EObject) {
477
						EObject dst = (EObject) structuralFeatureResult;
478
						structuralFeatureResult = ((InterfaceRealization) nextValue).getImplementingClassifier();
479
						if (structuralFeatureResult instanceof EObject) {
480
							EObject src = (EObject) structuralFeatureResult;
481
							myLinkDescriptors.add(new LinkDescriptor(src, dst, nextValue, linkVID));
482
						}
483
					}
484
				}
485
			}
486
		}
487
	}
488
489
	/**
490
	 * @generated
491
	 */
492
	private void storeTypeModelFacetLinks_Usage_4009(EObject container, EClass containerMetaclass) {
493
		if (UMLPackage.eINSTANCE.getPackage().isSuperTypeOf(containerMetaclass)) {
494
			for (Iterator values = ((org.eclipse.uml2.uml.Package) container).getPackagedElements().iterator(); values.hasNext();) {
495
				EObject nextValue = ((EObject) values.next());
496
				int linkVID = UMLVisualIDRegistry.getLinkWithClassVisualID(nextValue);
497
				if (UsageEditPart.VISUAL_ID == linkVID) {
498
					Object structuralFeatureResult = ((Dependency) nextValue).getSuppliers();
499
					List targets = (List) structuralFeatureResult;
500
					structuralFeatureResult = targets.size() == 1 ? targets.get(0) : null;
501
					if (structuralFeatureResult instanceof EObject) {
502
						EObject dst = (EObject) structuralFeatureResult;
503
						structuralFeatureResult = ((Dependency) nextValue).getClients();
504
						List sources = (List) structuralFeatureResult;
505
						structuralFeatureResult = sources.size() == 1 ? sources.get(0) : null;
506
						if (structuralFeatureResult instanceof EObject) {
507
							EObject src = (EObject) structuralFeatureResult;
508
							myLinkDescriptors.add(new LinkDescriptor(src, dst, nextValue, linkVID));
509
						}
510
					}
511
				}
512
			}
513
		}
514
	}
515
516
	/**
517
	 *@generated
518
	 */
519
	private void storeFeatureModelFacetLinks(EObject container, EClass containerMetaclass, Diagram diagram) {
520
521
		if (UMLPackage.eINSTANCE.getConstraint().isSuperTypeOf(containerMetaclass)) {
522
			for (Iterator destinations = ((Constraint) container).getConstrainedElements().iterator(); destinations.hasNext();) {
523
				EObject nextDestination = (EObject) destinations.next();
524
				myLinkDescriptors.add(new LinkDescriptor(container, nextDestination, UMLElementTypes.ConstraintConstrainedElement_4004, ConstraintConstrainedElementEditPart.VISUAL_ID));
525
526
			}
527
		}
528
529
		if (UMLPackage.eINSTANCE.getDependency().isSuperTypeOf(containerMetaclass)) {
530
			for (Iterator destinations = ((Dependency) container).getSuppliers().iterator(); destinations.hasNext();) {
531
				EObject nextDestination = (EObject) destinations.next();
532
				myLinkDescriptors.add(new LinkDescriptor(container, nextDestination, UMLElementTypes.DependencySupplier_4006, DependencySupplierEditPart.VISUAL_ID));
533
534
			}
535
		}
536
		if (UMLPackage.eINSTANCE.getDependency().isSuperTypeOf(containerMetaclass)) {
537
			for (Iterator destinations = ((Dependency) container).getClients().iterator(); destinations.hasNext();) {
538
				EObject nextDestination = (EObject) destinations.next();
539
				myLinkDescriptors.add(new LinkDescriptor(container, nextDestination, UMLElementTypes.DependencyClient_4007, DependencyClientEditPart.VISUAL_ID));
540
541
			}
542
		}
543
544
	}
545
546
	/**
547
	 * @generated
548
	 */
549
	private Diagram getDiagram() {
550
		return ((View) getHost().getModel()).getDiagram();
551
	}
552
553
	/**
554
	 * @generated
555
	 */
556
	private class LinkDescriptor {
557
558
		/**
559
		 * @generated
560
		 */
561
		private EObject mySource;
562
563
		/**
564
		 * @generated
565
		 */
566
		private EObject myDestination;
567
568
		/**
569
		 * @generated
570
		 */
571
		private EObject myLinkElement;
572
573
		/**
574
		 * @generated
575
		 */
576
		private int myVisualID;
577
578
		/**
579
		 * @generated
580
		 */
581
		private IAdaptable mySemanticAdapter;
582
583
		/**
584
		 * @generated
585
		 */
586
		protected LinkDescriptor(EObject source, EObject destination, EObject linkElement, int linkVID) {
587
			this(source, destination, linkVID);
588
			myLinkElement = linkElement;
589
			mySemanticAdapter = new EObjectAdapter(linkElement);
590
		}
591
592
		/**
593
		 * @generated
594
		 */
595
		protected LinkDescriptor(EObject source, EObject destination, IElementType elementType, int linkVID) {
596
			this(source, destination, linkVID);
597
			myLinkElement = null;
598
			final IElementType elementTypeCopy = elementType;
599
			mySemanticAdapter = new IAdaptable() {
600
601
				public Object getAdapter(Class adapter) {
602
					if (IElementType.class.equals(adapter)) {
603
						return elementTypeCopy;
604
					}
605
					return null;
606
				}
607
			};
608
		}
609
610
		/**
611
		 * @generated
612
		 */
613
		private LinkDescriptor(EObject source, EObject destination, int linkVID) {
614
			mySource = source;
615
			myDestination = destination;
616
			myVisualID = linkVID;
617
		}
618
619
		/**
620
		 * @generated
621
		 */
622
		protected EObject getSource() {
623
			return mySource;
624
		}
625
626
		/**
627
		 * @generated
628
		 */
629
		protected EObject getDestination() {
630
			return myDestination;
631
		}
632
633
		/**
634
		 * @generated
635
		 */
636
		protected EObject getLinkElement() {
637
			return myLinkElement;
638
		}
639
640
		/**
641
		 * @generated
642
		 */
643
		protected int getVisualID() {
644
			return myVisualID;
645
		}
646
647
		/**
648
		 * @generated
649
		 */
650
		protected IAdaptable getSemanticAdapter() {
651
			return mySemanticAdapter;
652
		}
653
	}
654
655
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/policies/InstanceSpecificationSlotsCanonicalEditPolicy.java (+52 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.policies;
2
3
import java.util.Iterator;
4
import java.util.LinkedList;
5
import java.util.List;
6
7
import org.eclipse.emf.ecore.EObject;
8
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.CanonicalEditPolicy;
9
import org.eclipse.gmf.runtime.notation.View;
10
import org.eclipse.uml2.diagram.clazz.edit.parts.SlotEditPart;
11
import org.eclipse.uml2.diagram.clazz.part.UMLVisualIDRegistry;
12
import org.eclipse.uml2.uml.InstanceSpecification;
13
14
/**
15
 * @generated
16
 */
17
public class InstanceSpecificationSlotsCanonicalEditPolicy extends CanonicalEditPolicy {
18
19
	/**
20
	 * @generated
21
	 */
22
	protected List getSemanticChildrenList() {
23
		List result = new LinkedList();
24
		EObject modelObject = ((View) getHost().getModel()).getElement();
25
		View viewObject = (View) getHost().getModel();
26
		EObject nextValue;
27
		int nodeVID;
28
		for (Iterator values = ((InstanceSpecification) modelObject).getSlots().iterator(); values.hasNext();) {
29
			nextValue = (EObject) values.next();
30
			nodeVID = UMLVisualIDRegistry.getNodeVisualID(viewObject, nextValue);
31
			if (SlotEditPart.VISUAL_ID == nodeVID) {
32
				result.add(nextValue);
33
			}
34
		}
35
		return result;
36
	}
37
38
	/**
39
	 * @generated
40
	 */
41
	protected boolean shouldDeleteView(View view) {
42
		return view.isSetElement() && view.getElement() != null && view.getElement().eIsProxy();
43
	}
44
45
	/**
46
	 * @generated
47
	 */
48
	protected String getDefaultFactoryHint() {
49
		return null;
50
	}
51
52
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/policies/Class3ItemSemanticEditPolicy.java (+466 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.policies;
2
3
import org.eclipse.emf.ecore.EAnnotation;
4
import org.eclipse.emf.ecore.EClass;
5
import org.eclipse.emf.ecore.EObject;
6
import org.eclipse.gef.commands.Command;
7
import org.eclipse.gef.commands.UnexecutableCommand;
8
import org.eclipse.gmf.runtime.emf.type.core.commands.CreateRelationshipCommand;
9
import org.eclipse.gmf.runtime.emf.type.core.commands.DestroyElementCommand;
10
import org.eclipse.gmf.runtime.emf.type.core.commands.SetValueCommand;
11
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest;
12
import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest;
13
import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest;
14
import org.eclipse.gmf.runtime.notation.View;
15
import org.eclipse.uml2.diagram.clazz.providers.UMLElementTypes;
16
import org.eclipse.uml2.uml.Association;
17
import org.eclipse.uml2.uml.Classifier;
18
import org.eclipse.uml2.uml.Constraint;
19
import org.eclipse.uml2.uml.Dependency;
20
import org.eclipse.uml2.uml.Generalization;
21
import org.eclipse.uml2.uml.NamedElement;
22
import org.eclipse.uml2.uml.Property;
23
import org.eclipse.uml2.uml.Type;
24
import org.eclipse.uml2.uml.UMLPackage;
25
import org.eclipse.uml2.uml.Usage;
26
27
/**
28
 * @generated
29
 */
30
public class Class3ItemSemanticEditPolicy extends UMLBaseItemSemanticEditPolicy {
31
32
	/**
33
	 * @generated
34
	 */
35
	protected Command getDestroyElementCommand(DestroyElementRequest req) {
36
		return getMSLWrapper(new DestroyElementCommand(req) {
37
38
			protected EObject getElementToDestroy() {
39
				View view = (View) getHost().getModel();
40
				EAnnotation annotation = view.getEAnnotation("Shortcut"); //$NON-NLS-1$
41
				if (annotation != null) {
42
					return view;
43
				}
44
				return super.getElementToDestroy();
45
			}
46
47
		});
48
	}
49
50
	/**
51
	 * @generated
52
	 */
53
	protected Command getCreateRelationshipCommand(CreateRelationshipRequest req) {
54
		if (UMLElementTypes.Generalization_4001 == req.getElementType()) {
55
			return req.getTarget() == null ? getCreateStartOutgoingGeneralization4001Command(req) : getCreateCompleteIncomingGeneralization4001Command(req);
56
		}
57
		if (UMLElementTypes.Dependency_4002 == req.getElementType()) {
58
			return req.getTarget() == null ? getCreateStartOutgoingDependency4002Command(req) : getCreateCompleteIncomingDependency4002Command(req);
59
		}
60
		if (UMLElementTypes.Property_4003 == req.getElementType()) {
61
			return req.getTarget() == null ? null : getCreateCompleteIncomingProperty4003Command(req);
62
		}
63
		if (UMLElementTypes.ConstraintConstrainedElement_4004 == req.getElementType()) {
64
			return req.getTarget() == null ? null : getCreateCompleteIncomingConstraint_ConstrainedElement4004Command(req);
65
		}
66
		if (UMLElementTypes.Association_4005 == req.getElementType()) {
67
			return req.getTarget() == null ? getCreateStartOutgoingAssociation4005Command(req) : getCreateCompleteIncomingAssociation4005Command(req);
68
		}
69
		if (UMLElementTypes.DependencySupplier_4006 == req.getElementType()) {
70
			return req.getTarget() == null ? null : getCreateCompleteIncomingDependency_Supplier4006Command(req);
71
		}
72
		if (UMLElementTypes.DependencyClient_4007 == req.getElementType()) {
73
			return req.getTarget() == null ? null : getCreateCompleteIncomingDependency_Client4007Command(req);
74
		}
75
		if (UMLElementTypes.InterfaceRealization_4008 == req.getElementType()) {
76
			return req.getTarget() == null ? getCreateStartOutgoingInterfaceRealization4008Command(req) : null;
77
		}
78
		if (UMLElementTypes.Usage_4009 == req.getElementType()) {
79
			return req.getTarget() == null ? getCreateStartOutgoingUsage4009Command(req) : getCreateCompleteIncomingUsage4009Command(req);
80
		}
81
		return super.getCreateRelationshipCommand(req);
82
	}
83
84
	/**
85
	 * @generated
86
	 */
87
	protected Command getCreateStartOutgoingGeneralization4001Command(CreateRelationshipRequest req) {
88
		return new Command() {
89
		};
90
	}
91
92
	/**
93
	 * @generated
94
	 */
95
	protected Command getCreateCompleteIncomingGeneralization4001Command(CreateRelationshipRequest req) {
96
		if (!(req.getSource() instanceof Classifier)) {
97
			return UnexecutableCommand.INSTANCE;
98
		}
99
		final Classifier element = (Classifier) req.getSource();
100
		if (req.getContainmentFeature() == null) {
101
			req.setContainmentFeature(UMLPackage.eINSTANCE.getClassifier_Generalization());
102
		}
103
		return getMSLWrapper(new CreateIncomingGeneralization4001Command(req) {
104
105
			protected EObject getElementToEdit() {
106
				return element;
107
			}
108
		});
109
	}
110
111
	/**
112
	 * @generated
113
	 */
114
	private static class CreateIncomingGeneralization4001Command extends CreateRelationshipCommand {
115
116
		/**
117
		 * @generated
118
		 */
119
		public CreateIncomingGeneralization4001Command(CreateRelationshipRequest req) {
120
			super(req);
121
		}
122
123
		/**
124
		 * @generated
125
		 */
126
		protected EClass getEClassToEdit() {
127
			return UMLPackage.eINSTANCE.getClassifier();
128
		};
129
130
		/**
131
		 * @generated
132
		 */
133
		protected void setElementToEdit(EObject element) {
134
			throw new UnsupportedOperationException();
135
		}
136
137
		/**
138
		 * @generated
139
		 */
140
		protected EObject doDefaultElementCreation() {
141
			Generalization newElement = (Generalization) super.doDefaultElementCreation();
142
			if (newElement != null) {
143
				newElement.setGeneral((Classifier) getTarget());
144
			}
145
			return newElement;
146
		}
147
	}
148
149
	/**
150
	 * @generated
151
	 */
152
	protected Command getCreateStartOutgoingDependency4002Command(CreateRelationshipRequest req) {
153
		return new Command() {
154
		};
155
	}
156
157
	/**
158
	 * @generated
159
	 */
160
	protected Command getCreateCompleteIncomingDependency4002Command(CreateRelationshipRequest req) {
161
		if (!(req.getSource() instanceof NamedElement)) {
162
			return UnexecutableCommand.INSTANCE;
163
		}
164
		final org.eclipse.uml2.uml.Package element = (org.eclipse.uml2.uml.Package) getRelationshipContainer(req.getSource(), UMLPackage.eINSTANCE.getPackage(), req.getElementType());
165
		if (element == null) {
166
			return UnexecutableCommand.INSTANCE;
167
		}
168
		if (req.getContainmentFeature() == null) {
169
			req.setContainmentFeature(UMLPackage.eINSTANCE.getPackage_PackagedElement());
170
		}
171
		return getMSLWrapper(new CreateIncomingDependency4002Command(req) {
172
173
			protected EObject getElementToEdit() {
174
				return element;
175
			}
176
		});
177
	}
178
179
	/**
180
	 * @generated
181
	 */
182
	private static class CreateIncomingDependency4002Command extends CreateRelationshipCommand {
183
184
		/**
185
		 * @generated
186
		 */
187
		public CreateIncomingDependency4002Command(CreateRelationshipRequest req) {
188
			super(req);
189
		}
190
191
		/**
192
		 * @generated
193
		 */
194
		protected EClass getEClassToEdit() {
195
			return UMLPackage.eINSTANCE.getPackage();
196
		};
197
198
		/**
199
		 * @generated
200
		 */
201
		protected void setElementToEdit(EObject element) {
202
			throw new UnsupportedOperationException();
203
		}
204
205
		/**
206
		 * @generated
207
		 */
208
		protected EObject doDefaultElementCreation() {
209
			Dependency newElement = (Dependency) super.doDefaultElementCreation();
210
			if (newElement != null) {
211
				newElement.getSuppliers().add((NamedElement) getTarget());
212
				newElement.getClients().add((NamedElement) getSource());
213
			}
214
			return newElement;
215
		}
216
	}
217
218
	/**
219
	 * @generated
220
	 */
221
	protected Command getCreateCompleteIncomingProperty4003Command(CreateRelationshipRequest req) {
222
		if (!(req.getSource() instanceof Association)) {
223
			return UnexecutableCommand.INSTANCE;
224
		}
225
		final Association element = (Association) req.getSource();
226
		if (req.getContainmentFeature() == null) {
227
			req.setContainmentFeature(UMLPackage.eINSTANCE.getAssociation_OwnedEnd());
228
		}
229
		return getMSLWrapper(new CreateIncomingProperty4003Command(req) {
230
231
			protected EObject getElementToEdit() {
232
				return element;
233
			}
234
		});
235
	}
236
237
	/**
238
	 * @generated
239
	 */
240
	private static class CreateIncomingProperty4003Command extends CreateRelationshipCommand {
241
242
		/**
243
		 * @generated
244
		 */
245
		public CreateIncomingProperty4003Command(CreateRelationshipRequest req) {
246
			super(req);
247
		}
248
249
		/**
250
		 * @generated
251
		 */
252
		protected EClass getEClassToEdit() {
253
			return UMLPackage.eINSTANCE.getAssociation();
254
		};
255
256
		/**
257
		 * @generated
258
		 */
259
		protected void setElementToEdit(EObject element) {
260
			throw new UnsupportedOperationException();
261
		}
262
263
		/**
264
		 * @generated
265
		 */
266
		protected EObject doDefaultElementCreation() {
267
			Property newElement = (Property) super.doDefaultElementCreation();
268
			if (newElement != null) {
269
				newElement.setType((Type) getTarget());
270
			}
271
			return newElement;
272
		}
273
	}
274
275
	/**
276
	 * @generated
277
	 */
278
	protected Command getCreateCompleteIncomingConstraint_ConstrainedElement4004Command(CreateRelationshipRequest req) {
279
		if (!(req.getSource() instanceof Constraint)) {
280
			return UnexecutableCommand.INSTANCE;
281
		}
282
		Constraint element = (Constraint) req.getSource();
283
		if (element.getConstrainedElements().contains(req.getTarget())) {
284
			return UnexecutableCommand.INSTANCE;
285
		}
286
		SetRequest setReq = new SetRequest(req.getSource(), UMLPackage.eINSTANCE.getConstraint_ConstrainedElement(), req.getTarget());
287
		return getMSLWrapper(new SetValueCommand(setReq));
288
	}
289
290
	/**
291
	 * @generated
292
	 */
293
	protected Command getCreateStartOutgoingAssociation4005Command(CreateRelationshipRequest req) {
294
		return new Command() {
295
		};
296
	}
297
298
	/**
299
	 * @generated
300
	 */
301
	protected Command getCreateCompleteIncomingAssociation4005Command(CreateRelationshipRequest req) {
302
		if (!(req.getSource() instanceof Type)) {
303
			return UnexecutableCommand.INSTANCE;
304
		}
305
		final org.eclipse.uml2.uml.Package element = (org.eclipse.uml2.uml.Package) getRelationshipContainer(req.getSource(), UMLPackage.eINSTANCE.getPackage(), req.getElementType());
306
		if (element == null) {
307
			return UnexecutableCommand.INSTANCE;
308
		}
309
		if (req.getContainmentFeature() == null) {
310
			req.setContainmentFeature(UMLPackage.eINSTANCE.getPackage_PackagedElement());
311
		}
312
		return getMSLWrapper(new CreateIncomingAssociation4005Command(req) {
313
314
			protected EObject getElementToEdit() {
315
				return element;
316
			}
317
		});
318
	}
319
320
	/**
321
	 * @generated NOT
322
	 */
323
	private static class CreateIncomingAssociation4005Command extends CreateAssociationCommand {
324
325
		/**
326
		 * @generated
327
		 */
328
		public CreateIncomingAssociation4005Command(CreateRelationshipRequest req) {
329
			super(req);
330
		}
331
332
		/**
333
		 * @generated
334
		 */
335
		protected EClass getEClassToEdit() {
336
			return UMLPackage.eINSTANCE.getPackage();
337
		};
338
339
		/**
340
		 * @generated
341
		 */
342
		protected void setElementToEdit(EObject element) {
343
			throw new UnsupportedOperationException();
344
		}
345
346
		/**
347
		 * @generated NOT
348
		 */
349
		protected EObject doDefaultElementCreation() {
350
			return super.doDefaultElementCreation();
351
		}
352
	}
353
354
	/**
355
	 * @generated
356
	 */
357
	protected Command getCreateCompleteIncomingDependency_Supplier4006Command(CreateRelationshipRequest req) {
358
		if (!(req.getSource() instanceof Dependency)) {
359
			return UnexecutableCommand.INSTANCE;
360
		}
361
		Dependency element = (Dependency) req.getSource();
362
		if (element.getSuppliers().contains(req.getTarget())) {
363
			return UnexecutableCommand.INSTANCE;
364
		}
365
		SetRequest setReq = new SetRequest(req.getSource(), UMLPackage.eINSTANCE.getDependency_Supplier(), req.getTarget());
366
		return getMSLWrapper(new SetValueCommand(setReq));
367
	}
368
369
	/**
370
	 * @generated
371
	 */
372
	protected Command getCreateCompleteIncomingDependency_Client4007Command(CreateRelationshipRequest req) {
373
		if (!(req.getSource() instanceof Dependency)) {
374
			return UnexecutableCommand.INSTANCE;
375
		}
376
		Dependency element = (Dependency) req.getSource();
377
		if (element.getClients().contains(req.getTarget())) {
378
			return UnexecutableCommand.INSTANCE;
379
		}
380
		SetRequest setReq = new SetRequest(req.getSource(), UMLPackage.eINSTANCE.getDependency_Client(), req.getTarget());
381
		return getMSLWrapper(new SetValueCommand(setReq));
382
	}
383
384
	/**
385
	 * @generated
386
	 */
387
	protected Command getCreateStartOutgoingInterfaceRealization4008Command(CreateRelationshipRequest req) {
388
		return new Command() {
389
		};
390
	}
391
392
	/**
393
	 * @generated
394
	 */
395
	protected Command getCreateStartOutgoingUsage4009Command(CreateRelationshipRequest req) {
396
		if (!UMLBaseItemSemanticEditPolicy.LinkConstraints.Usage_4009.canCreateLink(req, false)) {
397
			return UnexecutableCommand.INSTANCE;
398
		}
399
		return new Command() {
400
		};
401
	}
402
403
	/**
404
	 * @generated
405
	 */
406
	protected Command getCreateCompleteIncomingUsage4009Command(CreateRelationshipRequest req) {
407
		if (!(req.getSource() instanceof NamedElement)) {
408
			return UnexecutableCommand.INSTANCE;
409
		}
410
		final org.eclipse.uml2.uml.Package element = (org.eclipse.uml2.uml.Package) getRelationshipContainer(req.getSource(), UMLPackage.eINSTANCE.getPackage(), req.getElementType());
411
		if (element == null) {
412
			return UnexecutableCommand.INSTANCE;
413
		}
414
		if (!UMLBaseItemSemanticEditPolicy.LinkConstraints.Usage_4009.canCreateLink(req, false)) {
415
			return UnexecutableCommand.INSTANCE;
416
		}
417
		if (req.getContainmentFeature() == null) {
418
			req.setContainmentFeature(UMLPackage.eINSTANCE.getPackage_PackagedElement());
419
		}
420
		return getMSLWrapper(new CreateIncomingUsage4009Command(req) {
421
422
			protected EObject getElementToEdit() {
423
				return element;
424
			}
425
		});
426
	}
427
428
	/**
429
	 * @generated
430
	 */
431
	private static class CreateIncomingUsage4009Command extends CreateRelationshipCommand {
432
433
		/**
434
		 * @generated
435
		 */
436
		public CreateIncomingUsage4009Command(CreateRelationshipRequest req) {
437
			super(req);
438
		}
439
440
		/**
441
		 * @generated
442
		 */
443
		protected EClass getEClassToEdit() {
444
			return UMLPackage.eINSTANCE.getPackage();
445
		};
446
447
		/**
448
		 * @generated
449
		 */
450
		protected void setElementToEdit(EObject element) {
451
			throw new UnsupportedOperationException();
452
		}
453
454
		/**
455
		 * @generated
456
		 */
457
		protected EObject doDefaultElementCreation() {
458
			Usage newElement = (Usage) super.doDefaultElementCreation();
459
			if (newElement != null) {
460
				newElement.getSuppliers().add((NamedElement) getTarget());
461
				newElement.getClients().add((NamedElement) getSource());
462
			}
463
			return newElement;
464
		}
465
	}
466
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/policies/PackageOtherCanonicalEditPolicy.java (+51 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.policies;
2
3
import java.util.Iterator;
4
import java.util.LinkedList;
5
import java.util.List;
6
7
import org.eclipse.emf.ecore.EObject;
8
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.CanonicalEditPolicy;
9
import org.eclipse.gmf.runtime.notation.View;
10
import org.eclipse.uml2.diagram.clazz.edit.parts.InstanceSpecificationEditPart;
11
import org.eclipse.uml2.diagram.clazz.part.UMLVisualIDRegistry;
12
13
/**
14
 * @generated
15
 */
16
public class PackageOtherCanonicalEditPolicy extends CanonicalEditPolicy {
17
18
	/**
19
	 * @generated
20
	 */
21
	protected List getSemanticChildrenList() {
22
		List result = new LinkedList();
23
		EObject modelObject = ((View) getHost().getModel()).getElement();
24
		View viewObject = (View) getHost().getModel();
25
		EObject nextValue;
26
		int nodeVID;
27
		for (Iterator values = ((org.eclipse.uml2.uml.Package) modelObject).getPackagedElements().iterator(); values.hasNext();) {
28
			nextValue = (EObject) values.next();
29
			nodeVID = UMLVisualIDRegistry.getNodeVisualID(viewObject, nextValue);
30
			if (InstanceSpecificationEditPart.VISUAL_ID == nodeVID) {
31
				result.add(nextValue);
32
			}
33
		}
34
		return result;
35
	}
36
37
	/**
38
	 * @generated
39
	 */
40
	protected boolean shouldDeleteView(View view) {
41
		return view.isSetElement() && view.getElement() != null && view.getElement().eIsProxy();
42
	}
43
44
	/**
45
	 * @generated
46
	 */
47
	protected String getDefaultFactoryHint() {
48
		return null;
49
	}
50
51
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/policies/UMLExtNodeLabelHostLayoutEditPolicy.java (+211 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.policies;
2
3
import java.util.ArrayList;
4
import java.util.Iterator;
5
import java.util.List;
6
7
import org.eclipse.draw2d.geometry.Rectangle;
8
import org.eclipse.gef.EditPart;
9
import org.eclipse.gef.GraphicalEditPart;
10
import org.eclipse.gef.Request;
11
import org.eclipse.gef.commands.Command;
12
import org.eclipse.gef.editpolicies.LayoutEditPolicy;
13
import org.eclipse.gef.requests.ChangeBoundsRequest;
14
import org.eclipse.gef.requests.GroupRequest;
15
import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil;
16
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.XYLayoutEditPolicy;
17
import org.eclipse.gmf.runtime.notation.NotationPackage;
18
import org.eclipse.gmf.runtime.notation.View;
19
20
/**
21
 * @generated
22
 */
23
public class UMLExtNodeLabelHostLayoutEditPolicy extends XYLayoutEditPolicy {
24
25
	/**
26
	 * @generated
27
	 */
28
	private LayoutEditPolicy realLayoutEditPolicy;
29
30
	/**
31
	 * @generated
32
	 */
33
	public LayoutEditPolicy getRealLayoutEditPolicy() {
34
		return realLayoutEditPolicy;
35
	}
36
37
	/**
38
	 * @generated
39
	 */
40
	public void setRealLayoutEditPolicy(LayoutEditPolicy realLayoutEditPolicy) {
41
		this.realLayoutEditPolicy = realLayoutEditPolicy;
42
	}
43
44
	/**
45
	 * @generated
46
	 */
47
	protected boolean isExternalLabel(EditPart editPart) {
48
		return false;
49
	}
50
51
	/**
52
	 * @generated
53
	 */
54
	protected final List getExternalLabels(GroupRequest request) {
55
		List editParts = new ArrayList();
56
		if (request.getEditParts() != null) {
57
			for (Iterator it = request.getEditParts().iterator(); it.hasNext();) {
58
				EditPart editPart = (EditPart) it.next();
59
				if (isExternalLabel(editPart)) {
60
					editParts.add(editPart);
61
				}
62
			}
63
		}
64
		return editParts;
65
	}
66
67
	/**
68
	 * @generated
69
	 */
70
	public Command getCommand(Request request) {
71
		if (REQ_MOVE_CHILDREN.equals(request.getType())) {
72
			ChangeBoundsRequest cbRequest = (ChangeBoundsRequest) request;
73
			List extLabels = getExternalLabels(cbRequest);
74
			if (!extLabels.isEmpty()) {
75
				List editParts = cbRequest.getEditParts();
76
				Command cmd = null;
77
				if (realLayoutEditPolicy != null && editParts.size() > extLabels.size()) {
78
					List other = new ArrayList(editParts);
79
					other.removeAll(extLabels);
80
					cbRequest.setEditParts(other);
81
					cmd = realLayoutEditPolicy.getCommand(request);
82
				}
83
				cbRequest.setEditParts(extLabels);
84
				Command extLabelsCmd = getMoveChildrenCommand(request);
85
				cbRequest.setEditParts(editParts);
86
				return cmd == null ? extLabelsCmd : cmd.chain(extLabelsCmd);
87
			}
88
		}
89
		if (request instanceof GroupRequest) {
90
			List extLabels = getExternalLabels((GroupRequest) request);
91
			if (!extLabels.isEmpty()) {
92
				return null;
93
			}
94
		}
95
		return realLayoutEditPolicy == null ? null : realLayoutEditPolicy.getCommand(request);
96
	}
97
98
	/**
99
	 * @generated
100
	 */
101
	protected Object getConstraintFor(ChangeBoundsRequest request, GraphicalEditPart child) {
102
		int dx = ((Integer) ViewUtil.getStructuralFeatureValue((View) child.getModel(), NotationPackage.eINSTANCE.getLocation_X())).intValue();
103
		int dy = ((Integer) ViewUtil.getStructuralFeatureValue((View) child.getModel(), NotationPackage.eINSTANCE.getLocation_Y())).intValue();
104
		Rectangle r = new Rectangle(dx, dy, 0, 0);
105
		child.getFigure().translateToAbsolute(r);
106
		r.translate(request.getMoveDelta());
107
		child.getFigure().translateToRelative(r);
108
		return r;
109
	}
110
111
	/**
112
	 * @generated
113
	 */
114
	public boolean understandsRequest(Request req) {
115
		if (realLayoutEditPolicy != null && realLayoutEditPolicy.understandsRequest(req)) {
116
			return true;
117
		}
118
		return super.understandsRequest(req);
119
	}
120
121
	/**
122
	 * @generated
123
	 */
124
	protected void decorateChild(EditPart child) {
125
	}
126
127
	/**
128
	 * @generated
129
	 */
130
	public void setHost(EditPart host) {
131
		super.setHost(host);
132
		if (realLayoutEditPolicy != null) {
133
			realLayoutEditPolicy.setHost(host);
134
		}
135
	}
136
137
	/**
138
	 * @generated
139
	 */
140
	public void activate() {
141
		super.activate();
142
		if (realLayoutEditPolicy != null) {
143
			realLayoutEditPolicy.activate();
144
		}
145
	}
146
147
	/**
148
	 * @generated
149
	 */
150
	public void deactivate() {
151
		super.deactivate();
152
		if (realLayoutEditPolicy != null) {
153
			realLayoutEditPolicy.deactivate();
154
		}
155
	}
156
157
	/**
158
	 * @generated
159
	 */
160
	public EditPart getTargetEditPart(Request request) {
161
		if (realLayoutEditPolicy != null) {
162
			return realLayoutEditPolicy.getTargetEditPart(request);
163
		} else {
164
			return super.getTargetEditPart(request);
165
		}
166
	}
167
168
	/**
169
	 * @generated
170
	 */
171
	public void showSourceFeedback(Request request) {
172
		if (realLayoutEditPolicy != null) {
173
			realLayoutEditPolicy.showSourceFeedback(request);
174
		} else {
175
			super.showSourceFeedback(request);
176
		}
177
	}
178
179
	/**
180
	 * @generated
181
	 */
182
	public void eraseSourceFeedback(Request request) {
183
		if (realLayoutEditPolicy != null) {
184
			realLayoutEditPolicy.eraseSourceFeedback(request);
185
		} else {
186
			super.eraseSourceFeedback(request);
187
		}
188
	}
189
190
	/**
191
	 * @generated
192
	 */
193
	public void showTargetFeedback(Request request) {
194
		if (realLayoutEditPolicy != null) {
195
			realLayoutEditPolicy.showTargetFeedback(request);
196
		} else {
197
			super.showTargetFeedback(request);
198
		}
199
	}
200
201
	/**
202
	 * @generated
203
	 */
204
	public void eraseTargetFeedback(Request request) {
205
		if (realLayoutEditPolicy != null) {
206
			realLayoutEditPolicy.eraseTargetFeedback(request);
207
		} else {
208
			super.eraseTargetFeedback(request);
209
		}
210
	}
211
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/parts/AssociationClassOperationsEditPart.java (+67 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.parts;
2
3
import org.eclipse.emf.common.notify.Notification;
4
import org.eclipse.gef.EditPolicy;
5
import org.eclipse.gmf.runtime.diagram.ui.editparts.ListCompartmentEditPart;
6
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.CreationEditPolicy;
7
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.DragDropEditPolicy;
8
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
9
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.ResizableCompartmentEditPolicy;
10
import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout;
11
import org.eclipse.gmf.runtime.notation.View;
12
import org.eclipse.uml2.diagram.clazz.edit.policies.AssociationClassOperationsCanonicalEditPolicy;
13
import org.eclipse.uml2.diagram.clazz.edit.policies.AssociationClassOperationsItemSemanticEditPolicy;
14
15
/**
16
 * @generated
17
 */
18
public class AssociationClassOperationsEditPart extends ListCompartmentEditPart {
19
20
	/**
21
	 * @generated
22
	 */
23
	public static final int VISUAL_ID = 7025;
24
25
	/**
26
	 * @generated
27
	 */
28
	public AssociationClassOperationsEditPart(View view) {
29
		super(view);
30
	}
31
32
	/**
33
	 * @generated
34
	 */
35
	protected boolean hasModelChildrenChanged(Notification evt) {
36
		return false;
37
	}
38
39
	/**
40
	 * @generated
41
	 */
42
	public String getCompartmentName() {
43
		return "operations";
44
	}
45
46
	/**
47
	 * @generated
48
	 */
49
	protected void createDefaultEditPolicies() {
50
		super.createDefaultEditPolicies();
51
		installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ResizableCompartmentEditPolicy());
52
		installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new AssociationClassOperationsItemSemanticEditPolicy());
53
		installEditPolicy(EditPolicyRoles.CREATION_ROLE, new CreationEditPolicy());
54
		installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, new DragDropEditPolicy());
55
		installEditPolicy(EditPolicyRoles.CANONICAL_ROLE, new AssociationClassOperationsCanonicalEditPolicy());
56
57
	}
58
59
	/**
60
	 * @generated
61
	 */
62
	protected void setRatio(Double ratio) {
63
		if (getFigure().getParent().getLayoutManager() instanceof ConstrainedToolbarLayout) {
64
			super.setRatio(ratio);
65
		}
66
	}
67
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/parts/PrimitiveTypeOperationsEditPart.java (+67 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.parts;
2
3
import org.eclipse.emf.common.notify.Notification;
4
import org.eclipse.gef.EditPolicy;
5
import org.eclipse.gmf.runtime.diagram.ui.editparts.ListCompartmentEditPart;
6
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.CreationEditPolicy;
7
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.DragDropEditPolicy;
8
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
9
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.ResizableCompartmentEditPolicy;
10
import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout;
11
import org.eclipse.gmf.runtime.notation.View;
12
import org.eclipse.uml2.diagram.clazz.edit.policies.PrimitiveTypeOperationsCanonicalEditPolicy;
13
import org.eclipse.uml2.diagram.clazz.edit.policies.PrimitiveTypeOperationsItemSemanticEditPolicy;
14
15
/**
16
 * @generated
17
 */
18
public class PrimitiveTypeOperationsEditPart extends ListCompartmentEditPart {
19
20
	/**
21
	 * @generated
22
	 */
23
	public static final int VISUAL_ID = 7021;
24
25
	/**
26
	 * @generated
27
	 */
28
	public PrimitiveTypeOperationsEditPart(View view) {
29
		super(view);
30
	}
31
32
	/**
33
	 * @generated
34
	 */
35
	protected boolean hasModelChildrenChanged(Notification evt) {
36
		return false;
37
	}
38
39
	/**
40
	 * @generated
41
	 */
42
	public String getCompartmentName() {
43
		return "operations";
44
	}
45
46
	/**
47
	 * @generated
48
	 */
49
	protected void createDefaultEditPolicies() {
50
		super.createDefaultEditPolicies();
51
		installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ResizableCompartmentEditPolicy());
52
		installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new PrimitiveTypeOperationsItemSemanticEditPolicy());
53
		installEditPolicy(EditPolicyRoles.CREATION_ROLE, new CreationEditPolicy());
54
		installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, new DragDropEditPolicy());
55
		installEditPolicy(EditPolicyRoles.CANONICAL_ROLE, new PrimitiveTypeOperationsCanonicalEditPolicy());
56
57
	}
58
59
	/**
60
	 * @generated
61
	 */
62
	protected void setRatio(Double ratio) {
63
		if (getFigure().getParent().getLayoutManager() instanceof ConstrainedToolbarLayout) {
64
			super.setRatio(ratio);
65
		}
66
	}
67
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/parts/PackagePackagesEditPart.java (+67 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.parts;
2
3
import org.eclipse.emf.common.notify.Notification;
4
import org.eclipse.gef.EditPolicy;
5
import org.eclipse.gmf.runtime.diagram.ui.editparts.ListCompartmentEditPart;
6
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.CreationEditPolicy;
7
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.DragDropEditPolicy;
8
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
9
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.ResizableCompartmentEditPolicy;
10
import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout;
11
import org.eclipse.gmf.runtime.notation.View;
12
import org.eclipse.uml2.diagram.clazz.edit.policies.PackagePackagesCanonicalEditPolicy;
13
import org.eclipse.uml2.diagram.clazz.edit.policies.PackagePackagesItemSemanticEditPolicy;
14
15
/**
16
 * @generated
17
 */
18
public class PackagePackagesEditPart extends ListCompartmentEditPart {
19
20
	/**
21
	 * @generated
22
	 */
23
	public static final int VISUAL_ID = 7010;
24
25
	/**
26
	 * @generated
27
	 */
28
	public PackagePackagesEditPart(View view) {
29
		super(view);
30
	}
31
32
	/**
33
	 * @generated
34
	 */
35
	protected boolean hasModelChildrenChanged(Notification evt) {
36
		return false;
37
	}
38
39
	/**
40
	 * @generated
41
	 */
42
	public String getCompartmentName() {
43
		return "packages";
44
	}
45
46
	/**
47
	 * @generated
48
	 */
49
	protected void createDefaultEditPolicies() {
50
		super.createDefaultEditPolicies();
51
		installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ResizableCompartmentEditPolicy());
52
		installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new PackagePackagesItemSemanticEditPolicy());
53
		installEditPolicy(EditPolicyRoles.CREATION_ROLE, new CreationEditPolicy());
54
		installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, new DragDropEditPolicy());
55
		installEditPolicy(EditPolicyRoles.CANONICAL_ROLE, new PackagePackagesCanonicalEditPolicy());
56
57
	}
58
59
	/**
60
	 * @generated
61
	 */
62
	protected void setRatio(Double ratio) {
63
		if (getFigure().getParent().getLayoutManager() instanceof ConstrainedToolbarLayout) {
64
			super.setRatio(ratio);
65
		}
66
	}
67
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/parts/GeneralizationEditPart.java (+81 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.parts;
2
3
import org.eclipse.draw2d.Connection;
4
import org.eclipse.gmf.runtime.diagram.ui.editparts.ConnectionNodeEditPart;
5
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
6
import org.eclipse.gmf.runtime.notation.View;
7
import org.eclipse.uml2.diagram.clazz.edit.policies.GeneralizationItemSemanticEditPolicy;
8
9
/**
10
 * @generated
11
 */
12
public class GeneralizationEditPart extends ConnectionNodeEditPart {
13
14
	/**
15
	 * @generated
16
	 */
17
	public static final int VISUAL_ID = 4001;
18
19
	/**
20
	 * @generated
21
	 */
22
	public GeneralizationEditPart(View view) {
23
		super(view);
24
	}
25
26
	/**
27
	 * @generated
28
	 */
29
	protected void createDefaultEditPolicies() {
30
		super.createDefaultEditPolicies();
31
		installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new GeneralizationItemSemanticEditPolicy());
32
33
	}
34
35
	/**
36
	 * Creates figure for this edit part.
37
	 * 
38
	 * Body of this method does not depend on settings in generation model
39
	 * so you may safely remove <i>generated</i> tag and modify it.
40
	 * 
41
	 * @generated
42
	 */
43
	protected Connection createConnectionFigure() {
44
		return new SolidLineWDstClosedArrow();
45
	}
46
47
	/**
48
	 * @generated
49
	 */
50
	public class SolidLineWDstClosedArrow extends org.eclipse.gmf.runtime.draw2d.ui.figures.PolylineConnectionEx {
51
52
		/**
53
		 * @generated
54
		 */
55
		public SolidLineWDstClosedArrow() {
56
57
			setTargetDecoration(createTargetDecoration());
58
		}
59
60
		/**
61
		 * @generated
62
		 */
63
		private org.eclipse.draw2d.PolygonDecoration createTargetDecoration() {
64
			org.eclipse.draw2d.PolygonDecoration df = new org.eclipse.draw2d.PolygonDecoration();
65
			// dispatchNext?
66
			df.setFill(true);
67
			df.setBackgroundColor(org.eclipse.draw2d.ColorConstants.white);
68
			org.eclipse.draw2d.geometry.PointList pl = new org.eclipse.draw2d.geometry.PointList();
69
			pl.addPoint(0, 0);
70
			pl.addPoint(-2, 2);
71
			pl.addPoint(-2, -2);
72
			pl.addPoint(0, 0);
73
			df.setTemplate(pl);
74
			df.setScale(getMapMode().DPtoLP(7), getMapMode().DPtoLP(3));
75
76
			return df;
77
		}
78
79
	}
80
81
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/policies/Enumeration2ItemSemanticEditPolicy.java (+455 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.policies;
2
3
import org.eclipse.emf.ecore.EAnnotation;
4
import org.eclipse.emf.ecore.EClass;
5
import org.eclipse.emf.ecore.EObject;
6
import org.eclipse.gef.commands.Command;
7
import org.eclipse.gef.commands.UnexecutableCommand;
8
import org.eclipse.gmf.runtime.emf.type.core.commands.CreateRelationshipCommand;
9
import org.eclipse.gmf.runtime.emf.type.core.commands.DestroyElementCommand;
10
import org.eclipse.gmf.runtime.emf.type.core.commands.SetValueCommand;
11
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest;
12
import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest;
13
import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest;
14
import org.eclipse.gmf.runtime.notation.View;
15
import org.eclipse.uml2.diagram.clazz.providers.UMLElementTypes;
16
import org.eclipse.uml2.uml.Association;
17
import org.eclipse.uml2.uml.Classifier;
18
import org.eclipse.uml2.uml.Constraint;
19
import org.eclipse.uml2.uml.Dependency;
20
import org.eclipse.uml2.uml.Generalization;
21
import org.eclipse.uml2.uml.NamedElement;
22
import org.eclipse.uml2.uml.Property;
23
import org.eclipse.uml2.uml.Type;
24
import org.eclipse.uml2.uml.UMLPackage;
25
import org.eclipse.uml2.uml.Usage;
26
27
/**
28
 * @generated
29
 */
30
public class Enumeration2ItemSemanticEditPolicy extends UMLBaseItemSemanticEditPolicy {
31
32
	/**
33
	 * @generated
34
	 */
35
	protected Command getDestroyElementCommand(DestroyElementRequest req) {
36
		return getMSLWrapper(new DestroyElementCommand(req) {
37
38
			protected EObject getElementToDestroy() {
39
				View view = (View) getHost().getModel();
40
				EAnnotation annotation = view.getEAnnotation("Shortcut"); //$NON-NLS-1$
41
				if (annotation != null) {
42
					return view;
43
				}
44
				return super.getElementToDestroy();
45
			}
46
47
		});
48
	}
49
50
	/**
51
	 * @generated
52
	 */
53
	protected Command getCreateRelationshipCommand(CreateRelationshipRequest req) {
54
		if (UMLElementTypes.Generalization_4001 == req.getElementType()) {
55
			return req.getTarget() == null ? getCreateStartOutgoingGeneralization4001Command(req) : getCreateCompleteIncomingGeneralization4001Command(req);
56
		}
57
		if (UMLElementTypes.Dependency_4002 == req.getElementType()) {
58
			return req.getTarget() == null ? getCreateStartOutgoingDependency4002Command(req) : getCreateCompleteIncomingDependency4002Command(req);
59
		}
60
		if (UMLElementTypes.Property_4003 == req.getElementType()) {
61
			return req.getTarget() == null ? null : getCreateCompleteIncomingProperty4003Command(req);
62
		}
63
		if (UMLElementTypes.ConstraintConstrainedElement_4004 == req.getElementType()) {
64
			return req.getTarget() == null ? null : getCreateCompleteIncomingConstraint_ConstrainedElement4004Command(req);
65
		}
66
		if (UMLElementTypes.Association_4005 == req.getElementType()) {
67
			return req.getTarget() == null ? getCreateStartOutgoingAssociation4005Command(req) : getCreateCompleteIncomingAssociation4005Command(req);
68
		}
69
		if (UMLElementTypes.DependencySupplier_4006 == req.getElementType()) {
70
			return req.getTarget() == null ? null : getCreateCompleteIncomingDependency_Supplier4006Command(req);
71
		}
72
		if (UMLElementTypes.DependencyClient_4007 == req.getElementType()) {
73
			return req.getTarget() == null ? null : getCreateCompleteIncomingDependency_Client4007Command(req);
74
		}
75
		if (UMLElementTypes.Usage_4009 == req.getElementType()) {
76
			return req.getTarget() == null ? getCreateStartOutgoingUsage4009Command(req) : getCreateCompleteIncomingUsage4009Command(req);
77
		}
78
		return super.getCreateRelationshipCommand(req);
79
	}
80
81
	/**
82
	 * @generated
83
	 */
84
	protected Command getCreateStartOutgoingGeneralization4001Command(CreateRelationshipRequest req) {
85
		return new Command() {
86
		};
87
	}
88
89
	/**
90
	 * @generated
91
	 */
92
	protected Command getCreateCompleteIncomingGeneralization4001Command(CreateRelationshipRequest req) {
93
		if (!(req.getSource() instanceof Classifier)) {
94
			return UnexecutableCommand.INSTANCE;
95
		}
96
		final Classifier element = (Classifier) req.getSource();
97
		if (req.getContainmentFeature() == null) {
98
			req.setContainmentFeature(UMLPackage.eINSTANCE.getClassifier_Generalization());
99
		}
100
		return getMSLWrapper(new CreateIncomingGeneralization4001Command(req) {
101
102
			protected EObject getElementToEdit() {
103
				return element;
104
			}
105
		});
106
	}
107
108
	/**
109
	 * @generated
110
	 */
111
	private static class CreateIncomingGeneralization4001Command extends CreateRelationshipCommand {
112
113
		/**
114
		 * @generated
115
		 */
116
		public CreateIncomingGeneralization4001Command(CreateRelationshipRequest req) {
117
			super(req);
118
		}
119
120
		/**
121
		 * @generated
122
		 */
123
		protected EClass getEClassToEdit() {
124
			return UMLPackage.eINSTANCE.getClassifier();
125
		};
126
127
		/**
128
		 * @generated
129
		 */
130
		protected void setElementToEdit(EObject element) {
131
			throw new UnsupportedOperationException();
132
		}
133
134
		/**
135
		 * @generated
136
		 */
137
		protected EObject doDefaultElementCreation() {
138
			Generalization newElement = (Generalization) super.doDefaultElementCreation();
139
			if (newElement != null) {
140
				newElement.setGeneral((Classifier) getTarget());
141
			}
142
			return newElement;
143
		}
144
	}
145
146
	/**
147
	 * @generated
148
	 */
149
	protected Command getCreateStartOutgoingDependency4002Command(CreateRelationshipRequest req) {
150
		return new Command() {
151
		};
152
	}
153
154
	/**
155
	 * @generated
156
	 */
157
	protected Command getCreateCompleteIncomingDependency4002Command(CreateRelationshipRequest req) {
158
		if (!(req.getSource() instanceof NamedElement)) {
159
			return UnexecutableCommand.INSTANCE;
160
		}
161
		final org.eclipse.uml2.uml.Package element = (org.eclipse.uml2.uml.Package) getRelationshipContainer(req.getSource(), UMLPackage.eINSTANCE.getPackage(), req.getElementType());
162
		if (element == null) {
163
			return UnexecutableCommand.INSTANCE;
164
		}
165
		if (req.getContainmentFeature() == null) {
166
			req.setContainmentFeature(UMLPackage.eINSTANCE.getPackage_PackagedElement());
167
		}
168
		return getMSLWrapper(new CreateIncomingDependency4002Command(req) {
169
170
			protected EObject getElementToEdit() {
171
				return element;
172
			}
173
		});
174
	}
175
176
	/**
177
	 * @generated
178
	 */
179
	private static class CreateIncomingDependency4002Command extends CreateRelationshipCommand {
180
181
		/**
182
		 * @generated
183
		 */
184
		public CreateIncomingDependency4002Command(CreateRelationshipRequest req) {
185
			super(req);
186
		}
187
188
		/**
189
		 * @generated
190
		 */
191
		protected EClass getEClassToEdit() {
192
			return UMLPackage.eINSTANCE.getPackage();
193
		};
194
195
		/**
196
		 * @generated
197
		 */
198
		protected void setElementToEdit(EObject element) {
199
			throw new UnsupportedOperationException();
200
		}
201
202
		/**
203
		 * @generated
204
		 */
205
		protected EObject doDefaultElementCreation() {
206
			Dependency newElement = (Dependency) super.doDefaultElementCreation();
207
			if (newElement != null) {
208
				newElement.getSuppliers().add((NamedElement) getTarget());
209
				newElement.getClients().add((NamedElement) getSource());
210
			}
211
			return newElement;
212
		}
213
	}
214
215
	/**
216
	 * @generated
217
	 */
218
	protected Command getCreateCompleteIncomingProperty4003Command(CreateRelationshipRequest req) {
219
		if (!(req.getSource() instanceof Association)) {
220
			return UnexecutableCommand.INSTANCE;
221
		}
222
		final Association element = (Association) req.getSource();
223
		if (req.getContainmentFeature() == null) {
224
			req.setContainmentFeature(UMLPackage.eINSTANCE.getAssociation_OwnedEnd());
225
		}
226
		return getMSLWrapper(new CreateIncomingProperty4003Command(req) {
227
228
			protected EObject getElementToEdit() {
229
				return element;
230
			}
231
		});
232
	}
233
234
	/**
235
	 * @generated
236
	 */
237
	private static class CreateIncomingProperty4003Command extends CreateRelationshipCommand {
238
239
		/**
240
		 * @generated
241
		 */
242
		public CreateIncomingProperty4003Command(CreateRelationshipRequest req) {
243
			super(req);
244
		}
245
246
		/**
247
		 * @generated
248
		 */
249
		protected EClass getEClassToEdit() {
250
			return UMLPackage.eINSTANCE.getAssociation();
251
		};
252
253
		/**
254
		 * @generated
255
		 */
256
		protected void setElementToEdit(EObject element) {
257
			throw new UnsupportedOperationException();
258
		}
259
260
		/**
261
		 * @generated
262
		 */
263
		protected EObject doDefaultElementCreation() {
264
			Property newElement = (Property) super.doDefaultElementCreation();
265
			if (newElement != null) {
266
				newElement.setType((Type) getTarget());
267
			}
268
			return newElement;
269
		}
270
	}
271
272
	/**
273
	 * @generated
274
	 */
275
	protected Command getCreateCompleteIncomingConstraint_ConstrainedElement4004Command(CreateRelationshipRequest req) {
276
		if (!(req.getSource() instanceof Constraint)) {
277
			return UnexecutableCommand.INSTANCE;
278
		}
279
		Constraint element = (Constraint) req.getSource();
280
		if (element.getConstrainedElements().contains(req.getTarget())) {
281
			return UnexecutableCommand.INSTANCE;
282
		}
283
		SetRequest setReq = new SetRequest(req.getSource(), UMLPackage.eINSTANCE.getConstraint_ConstrainedElement(), req.getTarget());
284
		return getMSLWrapper(new SetValueCommand(setReq));
285
	}
286
287
	/**
288
	 * @generated
289
	 */
290
	protected Command getCreateStartOutgoingAssociation4005Command(CreateRelationshipRequest req) {
291
		return new Command() {
292
		};
293
	}
294
295
	/**
296
	 * @generated
297
	 */
298
	protected Command getCreateCompleteIncomingAssociation4005Command(CreateRelationshipRequest req) {
299
		if (!(req.getSource() instanceof Type)) {
300
			return UnexecutableCommand.INSTANCE;
301
		}
302
		final org.eclipse.uml2.uml.Package element = (org.eclipse.uml2.uml.Package) getRelationshipContainer(req.getSource(), UMLPackage.eINSTANCE.getPackage(), req.getElementType());
303
		if (element == null) {
304
			return UnexecutableCommand.INSTANCE;
305
		}
306
		if (req.getContainmentFeature() == null) {
307
			req.setContainmentFeature(UMLPackage.eINSTANCE.getPackage_PackagedElement());
308
		}
309
		return getMSLWrapper(new CreateIncomingAssociation4005Command(req) {
310
311
			protected EObject getElementToEdit() {
312
				return element;
313
			}
314
		});
315
	}
316
317
	/**
318
	 * @generated NOT
319
	 */
320
	private static class CreateIncomingAssociation4005Command extends CreateAssociationCommand {
321
322
		/**
323
		 * @generated
324
		 */
325
		public CreateIncomingAssociation4005Command(CreateRelationshipRequest req) {
326
			super(req);
327
		}
328
329
		/**
330
		 * @generated
331
		 */
332
		protected EClass getEClassToEdit() {
333
			return UMLPackage.eINSTANCE.getPackage();
334
		};
335
336
		/**
337
		 * @generated
338
		 */
339
		protected void setElementToEdit(EObject element) {
340
			throw new UnsupportedOperationException();
341
		}
342
343
		/**
344
		 * @generated NOT
345
		 */
346
		protected EObject doDefaultElementCreation() {
347
			return super.doDefaultElementCreation();
348
		}
349
	}
350
351
	/**
352
	 * @generated
353
	 */
354
	protected Command getCreateCompleteIncomingDependency_Supplier4006Command(CreateRelationshipRequest req) {
355
		if (!(req.getSource() instanceof Dependency)) {
356
			return UnexecutableCommand.INSTANCE;
357
		}
358
		Dependency element = (Dependency) req.getSource();
359
		if (element.getSuppliers().contains(req.getTarget())) {
360
			return UnexecutableCommand.INSTANCE;
361
		}
362
		SetRequest setReq = new SetRequest(req.getSource(), UMLPackage.eINSTANCE.getDependency_Supplier(), req.getTarget());
363
		return getMSLWrapper(new SetValueCommand(setReq));
364
	}
365
366
	/**
367
	 * @generated
368
	 */
369
	protected Command getCreateCompleteIncomingDependency_Client4007Command(CreateRelationshipRequest req) {
370
		if (!(req.getSource() instanceof Dependency)) {
371
			return UnexecutableCommand.INSTANCE;
372
		}
373
		Dependency element = (Dependency) req.getSource();
374
		if (element.getClients().contains(req.getTarget())) {
375
			return UnexecutableCommand.INSTANCE;
376
		}
377
		SetRequest setReq = new SetRequest(req.getSource(), UMLPackage.eINSTANCE.getDependency_Client(), req.getTarget());
378
		return getMSLWrapper(new SetValueCommand(setReq));
379
	}
380
381
	/**
382
	 * @generated
383
	 */
384
	protected Command getCreateStartOutgoingUsage4009Command(CreateRelationshipRequest req) {
385
		if (!UMLBaseItemSemanticEditPolicy.LinkConstraints.Usage_4009.canCreateLink(req, false)) {
386
			return UnexecutableCommand.INSTANCE;
387
		}
388
		return new Command() {
389
		};
390
	}
391
392
	/**
393
	 * @generated
394
	 */
395
	protected Command getCreateCompleteIncomingUsage4009Command(CreateRelationshipRequest req) {
396
		if (!(req.getSource() instanceof NamedElement)) {
397
			return UnexecutableCommand.INSTANCE;
398
		}
399
		final org.eclipse.uml2.uml.Package element = (org.eclipse.uml2.uml.Package) getRelationshipContainer(req.getSource(), UMLPackage.eINSTANCE.getPackage(), req.getElementType());
400
		if (element == null) {
401
			return UnexecutableCommand.INSTANCE;
402
		}
403
		if (!UMLBaseItemSemanticEditPolicy.LinkConstraints.Usage_4009.canCreateLink(req, false)) {
404
			return UnexecutableCommand.INSTANCE;
405
		}
406
		if (req.getContainmentFeature() == null) {
407
			req.setContainmentFeature(UMLPackage.eINSTANCE.getPackage_PackagedElement());
408
		}
409
		return getMSLWrapper(new CreateIncomingUsage4009Command(req) {
410
411
			protected EObject getElementToEdit() {
412
				return element;
413
			}
414
		});
415
	}
416
417
	/**
418
	 * @generated
419
	 */
420
	private static class CreateIncomingUsage4009Command extends CreateRelationshipCommand {
421
422
		/**
423
		 * @generated
424
		 */
425
		public CreateIncomingUsage4009Command(CreateRelationshipRequest req) {
426
			super(req);
427
		}
428
429
		/**
430
		 * @generated
431
		 */
432
		protected EClass getEClassToEdit() {
433
			return UMLPackage.eINSTANCE.getPackage();
434
		};
435
436
		/**
437
		 * @generated
438
		 */
439
		protected void setElementToEdit(EObject element) {
440
			throw new UnsupportedOperationException();
441
		}
442
443
		/**
444
		 * @generated
445
		 */
446
		protected EObject doDefaultElementCreation() {
447
			Usage newElement = (Usage) super.doDefaultElementCreation();
448
			if (newElement != null) {
449
				newElement.getSuppliers().add((NamedElement) getTarget());
450
				newElement.getClients().add((NamedElement) getSource());
451
			}
452
			return newElement;
453
		}
454
	}
455
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/parts/Property5EditPart.java (+553 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.parts;
2
3
import java.util.Collections;
4
import java.util.List;
5
6
import org.eclipse.draw2d.IFigure;
7
import org.eclipse.draw2d.Label;
8
import org.eclipse.draw2d.geometry.Point;
9
import org.eclipse.emf.common.notify.Notification;
10
import org.eclipse.emf.ecore.EObject;
11
import org.eclipse.emf.transaction.RunnableWithResult;
12
import org.eclipse.gef.AccessibleEditPart;
13
import org.eclipse.gef.DragTracker;
14
import org.eclipse.gef.EditPolicy;
15
import org.eclipse.gef.Request;
16
import org.eclipse.gef.requests.DirectEditRequest;
17
import org.eclipse.gef.requests.SelectionRequest;
18
import org.eclipse.gef.tools.DirectEditManager;
19
import org.eclipse.gmf.runtime.common.ui.services.parser.IParser;
20
import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus;
21
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserEditStatus;
22
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions;
23
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserService;
24
import org.eclipse.gmf.runtime.diagram.ui.editparts.CompartmentEditPart;
25
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
26
import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart;
27
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
28
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy;
29
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.ListItemComponentEditPolicy;
30
import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry;
31
import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants;
32
import org.eclipse.gmf.runtime.diagram.ui.tools.DragEditPartsTrackerEx;
33
import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager;
34
import org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel;
35
import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
36
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
37
import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser;
38
import org.eclipse.gmf.runtime.emf.ui.services.parser.ParserHintAdapter;
39
import org.eclipse.gmf.runtime.notation.FontStyle;
40
import org.eclipse.gmf.runtime.notation.NotationPackage;
41
import org.eclipse.gmf.runtime.notation.View;
42
import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
43
import org.eclipse.jface.viewers.ICellEditorValidator;
44
import org.eclipse.swt.SWT;
45
import org.eclipse.swt.accessibility.AccessibleEvent;
46
import org.eclipse.swt.graphics.Color;
47
import org.eclipse.swt.graphics.FontData;
48
import org.eclipse.swt.graphics.Image;
49
import org.eclipse.uml2.diagram.clazz.edit.policies.Property5ItemSemanticEditPolicy;
50
import org.eclipse.uml2.diagram.clazz.edit.policies.UMLTextNonResizableEditPolicy;
51
import org.eclipse.uml2.diagram.clazz.edit.policies.UMLTextSelectionEditPolicy;
52
import org.eclipse.uml2.diagram.clazz.providers.UMLElementTypes;
53
54
/**
55
 * @generated
56
 */
57
public class Property5EditPart extends CompartmentEditPart implements ITextAwareEditPart {
58
59
	/**
60
	 * @generated
61
	 */
62
	public static final int VISUAL_ID = 3023;
63
64
	/**
65
	 * @generated
66
	 */
67
	private DirectEditManager manager;
68
69
	/**
70
	 * @generated
71
	 */
72
	private IParser parser;
73
74
	/**
75
	 * @generated
76
	 */
77
	private List parserElements;
78
79
	/**
80
	 * @generated
81
	 */
82
	private String defaultText;
83
84
	/**
85
	 * @generated
86
	 */
87
	public Property5EditPart(View view) {
88
		super(view);
89
	}
90
91
	/**
92
	 * @generated
93
	 */
94
	public DragTracker getDragTracker(Request request) {
95
		if (request instanceof SelectionRequest && ((SelectionRequest) request).getLastButtonPressed() == 3) {
96
			return null;
97
		}
98
		return new DragEditPartsTrackerEx(this);
99
	}
100
101
	/**
102
	 * @generated
103
	 */
104
	protected void createDefaultEditPolicies() {
105
		super.createDefaultEditPolicies();
106
		installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new Property5ItemSemanticEditPolicy());
107
		installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new UMLTextNonResizableEditPolicy());
108
		installEditPolicy(EditPolicy.COMPONENT_ROLE, new ListItemComponentEditPolicy());
109
		installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy());
110
111
	}
112
113
	/**
114
	 * @generated
115
	 */
116
	protected String getLabelTextHelper(IFigure figure) {
117
		if (figure instanceof WrapLabel) {
118
			return ((WrapLabel) figure).getText();
119
		} else {
120
			return ((Label) figure).getText();
121
		}
122
	}
123
124
	/**
125
	 * @generated
126
	 */
127
	protected void setLabelTextHelper(IFigure figure, String text) {
128
		if (figure instanceof WrapLabel) {
129
			((WrapLabel) figure).setText(text);
130
		} else {
131
			((Label) figure).setText(text);
132
		}
133
	}
134
135
	/**
136
	 * @generated
137
	 */
138
	protected Image getLabelIconHelper(IFigure figure) {
139
		if (figure instanceof WrapLabel) {
140
			return ((WrapLabel) figure).getIcon();
141
		} else {
142
			return ((Label) figure).getIcon();
143
		}
144
	}
145
146
	/**
147
	 * @generated
148
	 */
149
	protected void setLabelIconHelper(IFigure figure, Image icon) {
150
		if (figure instanceof WrapLabel) {
151
			((WrapLabel) figure).setIcon(icon);
152
		} else {
153
			((Label) figure).setIcon(icon);
154
		}
155
	}
156
157
	/**
158
	 * @generated
159
	 */
160
	public void setLabel(IFigure figure) {
161
		unregisterVisuals();
162
		setFigure(figure);
163
		defaultText = getLabelTextHelper(figure);
164
		registerVisuals();
165
		refreshVisuals();
166
	}
167
168
	/**
169
	 * @generated
170
	 */
171
	protected List getModelChildren() {
172
		return Collections.EMPTY_LIST;
173
	}
174
175
	/**
176
	 * @generated
177
	 */
178
	public IGraphicalEditPart getChildBySemanticHint(String semanticHint) {
179
		return null;
180
	}
181
182
	/**
183
	 * @generated
184
	 */
185
	protected EObject getParserElement() {
186
		EObject element = resolveSemanticElement();
187
		return element != null ? element : (View) getModel();
188
	}
189
190
	/**
191
	 * @generated
192
	 */
193
	protected Image getLabelIcon() {
194
		return null;
195
	}
196
197
	/**
198
	 * @generated
199
	 */
200
	protected String getLabelText() {
201
		String text = null;
202
		if (getParser() != null) {
203
			text = getParser().getPrintString(new EObjectAdapter(getParserElement()), getParserOptions().intValue());
204
		}
205
		if (text == null || text.length() == 0) {
206
			text = defaultText;
207
		}
208
		return text;
209
	}
210
211
	/**
212
	 * @generated
213
	 */
214
	public void setLabelText(String text) {
215
		setLabelTextHelper(getFigure(), text);
216
		Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
217
		if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) {
218
			((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback();
219
		}
220
	}
221
222
	/**
223
	 * @generated
224
	 */
225
	public String getEditText() {
226
		if (getParser() == null) {
227
			return ""; //$NON-NLS-1$
228
		}
229
		return getParser().getEditString(new EObjectAdapter(getParserElement()), getParserOptions().intValue());
230
	}
231
232
	/**
233
	 * @generated
234
	 */
235
	protected boolean isEditable() {
236
		return getEditText() != null;
237
	}
238
239
	/**
240
	 * @generated
241
	 */
242
	public ICellEditorValidator getEditTextValidator() {
243
		return new ICellEditorValidator() {
244
245
			public String isValid(final Object value) {
246
				if (value instanceof String) {
247
					final EObject element = getParserElement();
248
					final IParser parser = getParser();
249
					try {
250
						IParserEditStatus valid = (IParserEditStatus) getEditingDomain().runExclusive(new RunnableWithResult.Impl() {
251
252
							public void run() {
253
								setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value));
254
							}
255
						});
256
						return valid.getCode() == ParserEditStatus.EDITABLE ? null : valid.getMessage();
257
					} catch (InterruptedException ie) {
258
						ie.printStackTrace();
259
					}
260
				}
261
262
				// shouldn't get here
263
				return null;
264
			}
265
		};
266
	}
267
268
	/**
269
	 * @generated
270
	 */
271
	public IContentAssistProcessor getCompletionProcessor() {
272
		if (getParser() == null) {
273
			return null;
274
		}
275
		return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement()));
276
	}
277
278
	/**
279
	 * @generated
280
	 */
281
	public ParserOptions getParserOptions() {
282
		return ParserOptions.NONE;
283
	}
284
285
	/**
286
	 * @generated
287
	 */
288
	public IParser getParser() {
289
		if (parser == null) {
290
			String parserHint = ((View) getModel()).getType();
291
			ParserHintAdapter hintAdapter = new ParserHintAdapter(getParserElement(), parserHint) {
292
293
				public Object getAdapter(Class adapter) {
294
					if (IElementType.class.equals(adapter)) {
295
						return UMLElementTypes.Property_3023;
296
					}
297
					return super.getAdapter(adapter);
298
				}
299
			};
300
			parser = ParserService.getInstance().getParser(hintAdapter);
301
		}
302
		return parser;
303
	}
304
305
	/**
306
	 * @generated
307
	 */
308
	protected DirectEditManager getManager() {
309
		if (manager == null) {
310
			setManager(new TextDirectEditManager(this, TextDirectEditManager.getTextCellEditorClass(this), UMLEditPartFactory.getTextCellEditorLocator(this)));
311
		}
312
		return manager;
313
	}
314
315
	/**
316
	 * @generated
317
	 */
318
	protected void setManager(DirectEditManager manager) {
319
		this.manager = manager;
320
	}
321
322
	/**
323
	 * @generated
324
	 */
325
	protected void performDirectEdit() {
326
		getManager().show();
327
	}
328
329
	/**
330
	 * @generated
331
	 */
332
	protected void performDirectEdit(Point eventLocation) {
333
		if (getManager().getClass() == TextDirectEditManager.class) {
334
			((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint());
335
		}
336
	}
337
338
	/**
339
	 * @generated
340
	 */
341
	private void performDirectEdit(char initialCharacter) {
342
		if (getManager() instanceof TextDirectEditManager) {
343
			((TextDirectEditManager) getManager()).show(initialCharacter);
344
		} else {
345
			performDirectEdit();
346
		}
347
	}
348
349
	/**
350
	 * @generated
351
	 */
352
	protected void performDirectEditRequest(Request request) {
353
		final Request theRequest = request;
354
		try {
355
			getEditingDomain().runExclusive(new Runnable() {
356
357
				public void run() {
358
					if (isActive() && isEditable()) {
359
						if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) {
360
							Character initialChar = (Character) theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR);
361
							performDirectEdit(initialChar.charValue());
362
						} else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) {
363
							DirectEditRequest editRequest = (DirectEditRequest) theRequest;
364
							performDirectEdit(editRequest.getLocation());
365
						} else {
366
							performDirectEdit();
367
						}
368
					}
369
				}
370
			});
371
		} catch (InterruptedException e) {
372
			e.printStackTrace();
373
		}
374
	}
375
376
	/**
377
	 * @generated
378
	 */
379
	protected void refreshVisuals() {
380
		super.refreshVisuals();
381
		refreshLabel();
382
		refreshFont();
383
		refreshFontColor();
384
		refreshUnderline();
385
		refreshStrikeThrough();
386
	}
387
388
	/**
389
	 * @generated
390
	 */
391
	protected void refreshLabel() {
392
		setLabelTextHelper(getFigure(), getLabelText());
393
		setLabelIconHelper(getFigure(), getLabelIcon());
394
		Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
395
		if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) {
396
			((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback();
397
		}
398
	}
399
400
	/**
401
	 * @generated
402
	 */
403
	protected void refreshUnderline() {
404
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
405
		if (style != null && getFigure() instanceof WrapLabel) {
406
			((WrapLabel) getFigure()).setTextUnderline(style.isUnderline());
407
		}
408
	}
409
410
	/**
411
	 * @generated
412
	 */
413
	protected void refreshStrikeThrough() {
414
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
415
		if (style != null && getFigure() instanceof WrapLabel) {
416
			((WrapLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough());
417
		}
418
	}
419
420
	/**
421
	 * @generated
422
	 */
423
	protected void refreshFont() {
424
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
425
		if (style != null) {
426
			FontData fontData = new FontData(style.getFontName(), style.getFontHeight(), (style.isBold() ? SWT.BOLD : SWT.NORMAL) | (style.isItalic() ? SWT.ITALIC : SWT.NORMAL));
427
			setFont(fontData);
428
		}
429
	}
430
431
	/**
432
	 * @generated
433
	 */
434
	protected void setFontColor(Color color) {
435
		getFigure().setForegroundColor(color);
436
	}
437
438
	/**
439
	 * @generated
440
	 */
441
	protected void addSemanticListeners() {
442
		if (getParser() instanceof ISemanticParser) {
443
			EObject element = resolveSemanticElement();
444
			parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element);
445
			for (int i = 0; i < parserElements.size(); i++) {
446
				addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$
447
			}
448
		} else {
449
			super.addSemanticListeners();
450
		}
451
	}
452
453
	/**
454
	 * @generated
455
	 */
456
	protected void removeSemanticListeners() {
457
		if (parserElements != null) {
458
			for (int i = 0; i < parserElements.size(); i++) {
459
				removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$
460
			}
461
		} else {
462
			super.removeSemanticListeners();
463
		}
464
	}
465
466
	/**
467
	 * @generated
468
	 */
469
	protected AccessibleEditPart getAccessibleEditPart() {
470
		if (accessibleEP == null) {
471
			accessibleEP = new AccessibleGraphicalEditPart() {
472
473
				public void getName(AccessibleEvent e) {
474
					e.result = getLabelTextHelper(getFigure());
475
				}
476
			};
477
		}
478
		return accessibleEP;
479
	}
480
481
	/**
482
	 * @generated
483
	 */
484
	private View getFontStyleOwnerView() {
485
		return getPrimaryView();
486
	}
487
488
	/**
489
	 * @generated
490
	 */
491
	protected void addNotationalListeners() {
492
		super.addNotationalListeners();
493
		addListenerFilter("PrimaryView", this, getPrimaryView()); //$NON-NLS-1$
494
	}
495
496
	/**
497
	 * @generated
498
	 */
499
	protected void removeNotationalListeners() {
500
		super.removeNotationalListeners();
501
		removeListenerFilter("PrimaryView"); //$NON-NLS-1$
502
	}
503
504
	/**
505
	 * @generated
506
	 */
507
	protected void handleNotificationEvent(Notification event) {
508
		Object feature = event.getFeature();
509
		if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) {
510
			Integer c = (Integer) event.getNewValue();
511
			setFontColor(DiagramColorRegistry.getInstance().getColor(c));
512
		} else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) {
513
			refreshUnderline();
514
		} else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) {
515
			refreshStrikeThrough();
516
		} else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature)
517
				|| NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) {
518
			refreshFont();
519
		} else {
520
			if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) {
521
				refreshLabel();
522
			}
523
			if (getParser() instanceof ISemanticParser) {
524
				ISemanticParser modelParser = (ISemanticParser) getParser();
525
				if (modelParser.areSemanticElementsAffected(null, event)) {
526
					removeSemanticListeners();
527
					if (resolveSemanticElement() != null) {
528
						addSemanticListeners();
529
					}
530
					refreshLabel();
531
				}
532
			}
533
		}
534
		super.handleNotificationEvent(event);
535
	}
536
537
	/**
538
	 * @generated
539
	 */
540
	protected IFigure createFigure() {
541
		IFigure label = createFigurePrim();
542
		defaultText = getLabelTextHelper(label);
543
		return label;
544
	}
545
546
	/**
547
	 * @generated
548
	 */
549
	protected IFigure createFigurePrim() {
550
		return new WrapLabel();
551
	}
552
553
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/parts/PrimitiveTypeEditPart.java (+553 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.parts;
2
3
import java.util.Collections;
4
import java.util.List;
5
6
import org.eclipse.draw2d.IFigure;
7
import org.eclipse.draw2d.Label;
8
import org.eclipse.draw2d.geometry.Point;
9
import org.eclipse.emf.common.notify.Notification;
10
import org.eclipse.emf.ecore.EObject;
11
import org.eclipse.emf.transaction.RunnableWithResult;
12
import org.eclipse.gef.AccessibleEditPart;
13
import org.eclipse.gef.DragTracker;
14
import org.eclipse.gef.EditPolicy;
15
import org.eclipse.gef.Request;
16
import org.eclipse.gef.requests.DirectEditRequest;
17
import org.eclipse.gef.requests.SelectionRequest;
18
import org.eclipse.gef.tools.DirectEditManager;
19
import org.eclipse.gmf.runtime.common.ui.services.parser.IParser;
20
import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus;
21
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserEditStatus;
22
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions;
23
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserService;
24
import org.eclipse.gmf.runtime.diagram.ui.editparts.CompartmentEditPart;
25
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
26
import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart;
27
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
28
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy;
29
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.ListItemComponentEditPolicy;
30
import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry;
31
import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants;
32
import org.eclipse.gmf.runtime.diagram.ui.tools.DragEditPartsTrackerEx;
33
import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager;
34
import org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel;
35
import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
36
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
37
import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser;
38
import org.eclipse.gmf.runtime.emf.ui.services.parser.ParserHintAdapter;
39
import org.eclipse.gmf.runtime.notation.FontStyle;
40
import org.eclipse.gmf.runtime.notation.NotationPackage;
41
import org.eclipse.gmf.runtime.notation.View;
42
import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
43
import org.eclipse.jface.viewers.ICellEditorValidator;
44
import org.eclipse.swt.SWT;
45
import org.eclipse.swt.accessibility.AccessibleEvent;
46
import org.eclipse.swt.graphics.Color;
47
import org.eclipse.swt.graphics.FontData;
48
import org.eclipse.swt.graphics.Image;
49
import org.eclipse.uml2.diagram.clazz.edit.policies.PrimitiveTypeItemSemanticEditPolicy;
50
import org.eclipse.uml2.diagram.clazz.edit.policies.UMLTextNonResizableEditPolicy;
51
import org.eclipse.uml2.diagram.clazz.edit.policies.UMLTextSelectionEditPolicy;
52
import org.eclipse.uml2.diagram.clazz.providers.UMLElementTypes;
53
54
/**
55
 * @generated
56
 */
57
public class PrimitiveTypeEditPart extends CompartmentEditPart implements ITextAwareEditPart {
58
59
	/**
60
	 * @generated
61
	 */
62
	public static final int VISUAL_ID = 3009;
63
64
	/**
65
	 * @generated
66
	 */
67
	private DirectEditManager manager;
68
69
	/**
70
	 * @generated
71
	 */
72
	private IParser parser;
73
74
	/**
75
	 * @generated
76
	 */
77
	private List parserElements;
78
79
	/**
80
	 * @generated
81
	 */
82
	private String defaultText;
83
84
	/**
85
	 * @generated
86
	 */
87
	public PrimitiveTypeEditPart(View view) {
88
		super(view);
89
	}
90
91
	/**
92
	 * @generated
93
	 */
94
	public DragTracker getDragTracker(Request request) {
95
		if (request instanceof SelectionRequest && ((SelectionRequest) request).getLastButtonPressed() == 3) {
96
			return null;
97
		}
98
		return new DragEditPartsTrackerEx(this);
99
	}
100
101
	/**
102
	 * @generated
103
	 */
104
	protected void createDefaultEditPolicies() {
105
		super.createDefaultEditPolicies();
106
		installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new PrimitiveTypeItemSemanticEditPolicy());
107
		installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new UMLTextNonResizableEditPolicy());
108
		installEditPolicy(EditPolicy.COMPONENT_ROLE, new ListItemComponentEditPolicy());
109
		installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy());
110
111
	}
112
113
	/**
114
	 * @generated
115
	 */
116
	protected String getLabelTextHelper(IFigure figure) {
117
		if (figure instanceof WrapLabel) {
118
			return ((WrapLabel) figure).getText();
119
		} else {
120
			return ((Label) figure).getText();
121
		}
122
	}
123
124
	/**
125
	 * @generated
126
	 */
127
	protected void setLabelTextHelper(IFigure figure, String text) {
128
		if (figure instanceof WrapLabel) {
129
			((WrapLabel) figure).setText(text);
130
		} else {
131
			((Label) figure).setText(text);
132
		}
133
	}
134
135
	/**
136
	 * @generated
137
	 */
138
	protected Image getLabelIconHelper(IFigure figure) {
139
		if (figure instanceof WrapLabel) {
140
			return ((WrapLabel) figure).getIcon();
141
		} else {
142
			return ((Label) figure).getIcon();
143
		}
144
	}
145
146
	/**
147
	 * @generated
148
	 */
149
	protected void setLabelIconHelper(IFigure figure, Image icon) {
150
		if (figure instanceof WrapLabel) {
151
			((WrapLabel) figure).setIcon(icon);
152
		} else {
153
			((Label) figure).setIcon(icon);
154
		}
155
	}
156
157
	/**
158
	 * @generated
159
	 */
160
	public void setLabel(IFigure figure) {
161
		unregisterVisuals();
162
		setFigure(figure);
163
		defaultText = getLabelTextHelper(figure);
164
		registerVisuals();
165
		refreshVisuals();
166
	}
167
168
	/**
169
	 * @generated
170
	 */
171
	protected List getModelChildren() {
172
		return Collections.EMPTY_LIST;
173
	}
174
175
	/**
176
	 * @generated
177
	 */
178
	public IGraphicalEditPart getChildBySemanticHint(String semanticHint) {
179
		return null;
180
	}
181
182
	/**
183
	 * @generated
184
	 */
185
	protected EObject getParserElement() {
186
		EObject element = resolveSemanticElement();
187
		return element != null ? element : (View) getModel();
188
	}
189
190
	/**
191
	 * @generated
192
	 */
193
	protected Image getLabelIcon() {
194
		return null;
195
	}
196
197
	/**
198
	 * @generated
199
	 */
200
	protected String getLabelText() {
201
		String text = null;
202
		if (getParser() != null) {
203
			text = getParser().getPrintString(new EObjectAdapter(getParserElement()), getParserOptions().intValue());
204
		}
205
		if (text == null || text.length() == 0) {
206
			text = defaultText;
207
		}
208
		return text;
209
	}
210
211
	/**
212
	 * @generated
213
	 */
214
	public void setLabelText(String text) {
215
		setLabelTextHelper(getFigure(), text);
216
		Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
217
		if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) {
218
			((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback();
219
		}
220
	}
221
222
	/**
223
	 * @generated
224
	 */
225
	public String getEditText() {
226
		if (getParser() == null) {
227
			return ""; //$NON-NLS-1$
228
		}
229
		return getParser().getEditString(new EObjectAdapter(getParserElement()), getParserOptions().intValue());
230
	}
231
232
	/**
233
	 * @generated
234
	 */
235
	protected boolean isEditable() {
236
		return getEditText() != null;
237
	}
238
239
	/**
240
	 * @generated
241
	 */
242
	public ICellEditorValidator getEditTextValidator() {
243
		return new ICellEditorValidator() {
244
245
			public String isValid(final Object value) {
246
				if (value instanceof String) {
247
					final EObject element = getParserElement();
248
					final IParser parser = getParser();
249
					try {
250
						IParserEditStatus valid = (IParserEditStatus) getEditingDomain().runExclusive(new RunnableWithResult.Impl() {
251
252
							public void run() {
253
								setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value));
254
							}
255
						});
256
						return valid.getCode() == ParserEditStatus.EDITABLE ? null : valid.getMessage();
257
					} catch (InterruptedException ie) {
258
						ie.printStackTrace();
259
					}
260
				}
261
262
				// shouldn't get here
263
				return null;
264
			}
265
		};
266
	}
267
268
	/**
269
	 * @generated
270
	 */
271
	public IContentAssistProcessor getCompletionProcessor() {
272
		if (getParser() == null) {
273
			return null;
274
		}
275
		return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement()));
276
	}
277
278
	/**
279
	 * @generated
280
	 */
281
	public ParserOptions getParserOptions() {
282
		return ParserOptions.NONE;
283
	}
284
285
	/**
286
	 * @generated
287
	 */
288
	public IParser getParser() {
289
		if (parser == null) {
290
			String parserHint = ((View) getModel()).getType();
291
			ParserHintAdapter hintAdapter = new ParserHintAdapter(getParserElement(), parserHint) {
292
293
				public Object getAdapter(Class adapter) {
294
					if (IElementType.class.equals(adapter)) {
295
						return UMLElementTypes.PrimitiveType_3009;
296
					}
297
					return super.getAdapter(adapter);
298
				}
299
			};
300
			parser = ParserService.getInstance().getParser(hintAdapter);
301
		}
302
		return parser;
303
	}
304
305
	/**
306
	 * @generated
307
	 */
308
	protected DirectEditManager getManager() {
309
		if (manager == null) {
310
			setManager(new TextDirectEditManager(this, TextDirectEditManager.getTextCellEditorClass(this), UMLEditPartFactory.getTextCellEditorLocator(this)));
311
		}
312
		return manager;
313
	}
314
315
	/**
316
	 * @generated
317
	 */
318
	protected void setManager(DirectEditManager manager) {
319
		this.manager = manager;
320
	}
321
322
	/**
323
	 * @generated
324
	 */
325
	protected void performDirectEdit() {
326
		getManager().show();
327
	}
328
329
	/**
330
	 * @generated
331
	 */
332
	protected void performDirectEdit(Point eventLocation) {
333
		if (getManager().getClass() == TextDirectEditManager.class) {
334
			((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint());
335
		}
336
	}
337
338
	/**
339
	 * @generated
340
	 */
341
	private void performDirectEdit(char initialCharacter) {
342
		if (getManager() instanceof TextDirectEditManager) {
343
			((TextDirectEditManager) getManager()).show(initialCharacter);
344
		} else {
345
			performDirectEdit();
346
		}
347
	}
348
349
	/**
350
	 * @generated
351
	 */
352
	protected void performDirectEditRequest(Request request) {
353
		final Request theRequest = request;
354
		try {
355
			getEditingDomain().runExclusive(new Runnable() {
356
357
				public void run() {
358
					if (isActive() && isEditable()) {
359
						if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) {
360
							Character initialChar = (Character) theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR);
361
							performDirectEdit(initialChar.charValue());
362
						} else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) {
363
							DirectEditRequest editRequest = (DirectEditRequest) theRequest;
364
							performDirectEdit(editRequest.getLocation());
365
						} else {
366
							performDirectEdit();
367
						}
368
					}
369
				}
370
			});
371
		} catch (InterruptedException e) {
372
			e.printStackTrace();
373
		}
374
	}
375
376
	/**
377
	 * @generated
378
	 */
379
	protected void refreshVisuals() {
380
		super.refreshVisuals();
381
		refreshLabel();
382
		refreshFont();
383
		refreshFontColor();
384
		refreshUnderline();
385
		refreshStrikeThrough();
386
	}
387
388
	/**
389
	 * @generated
390
	 */
391
	protected void refreshLabel() {
392
		setLabelTextHelper(getFigure(), getLabelText());
393
		setLabelIconHelper(getFigure(), getLabelIcon());
394
		Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
395
		if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) {
396
			((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback();
397
		}
398
	}
399
400
	/**
401
	 * @generated
402
	 */
403
	protected void refreshUnderline() {
404
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
405
		if (style != null && getFigure() instanceof WrapLabel) {
406
			((WrapLabel) getFigure()).setTextUnderline(style.isUnderline());
407
		}
408
	}
409
410
	/**
411
	 * @generated
412
	 */
413
	protected void refreshStrikeThrough() {
414
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
415
		if (style != null && getFigure() instanceof WrapLabel) {
416
			((WrapLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough());
417
		}
418
	}
419
420
	/**
421
	 * @generated
422
	 */
423
	protected void refreshFont() {
424
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
425
		if (style != null) {
426
			FontData fontData = new FontData(style.getFontName(), style.getFontHeight(), (style.isBold() ? SWT.BOLD : SWT.NORMAL) | (style.isItalic() ? SWT.ITALIC : SWT.NORMAL));
427
			setFont(fontData);
428
		}
429
	}
430
431
	/**
432
	 * @generated
433
	 */
434
	protected void setFontColor(Color color) {
435
		getFigure().setForegroundColor(color);
436
	}
437
438
	/**
439
	 * @generated
440
	 */
441
	protected void addSemanticListeners() {
442
		if (getParser() instanceof ISemanticParser) {
443
			EObject element = resolveSemanticElement();
444
			parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element);
445
			for (int i = 0; i < parserElements.size(); i++) {
446
				addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$
447
			}
448
		} else {
449
			super.addSemanticListeners();
450
		}
451
	}
452
453
	/**
454
	 * @generated
455
	 */
456
	protected void removeSemanticListeners() {
457
		if (parserElements != null) {
458
			for (int i = 0; i < parserElements.size(); i++) {
459
				removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$
460
			}
461
		} else {
462
			super.removeSemanticListeners();
463
		}
464
	}
465
466
	/**
467
	 * @generated
468
	 */
469
	protected AccessibleEditPart getAccessibleEditPart() {
470
		if (accessibleEP == null) {
471
			accessibleEP = new AccessibleGraphicalEditPart() {
472
473
				public void getName(AccessibleEvent e) {
474
					e.result = getLabelTextHelper(getFigure());
475
				}
476
			};
477
		}
478
		return accessibleEP;
479
	}
480
481
	/**
482
	 * @generated
483
	 */
484
	private View getFontStyleOwnerView() {
485
		return getPrimaryView();
486
	}
487
488
	/**
489
	 * @generated
490
	 */
491
	protected void addNotationalListeners() {
492
		super.addNotationalListeners();
493
		addListenerFilter("PrimaryView", this, getPrimaryView()); //$NON-NLS-1$
494
	}
495
496
	/**
497
	 * @generated
498
	 */
499
	protected void removeNotationalListeners() {
500
		super.removeNotationalListeners();
501
		removeListenerFilter("PrimaryView"); //$NON-NLS-1$
502
	}
503
504
	/**
505
	 * @generated
506
	 */
507
	protected void handleNotificationEvent(Notification event) {
508
		Object feature = event.getFeature();
509
		if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) {
510
			Integer c = (Integer) event.getNewValue();
511
			setFontColor(DiagramColorRegistry.getInstance().getColor(c));
512
		} else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) {
513
			refreshUnderline();
514
		} else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) {
515
			refreshStrikeThrough();
516
		} else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature)
517
				|| NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) {
518
			refreshFont();
519
		} else {
520
			if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) {
521
				refreshLabel();
522
			}
523
			if (getParser() instanceof ISemanticParser) {
524
				ISemanticParser modelParser = (ISemanticParser) getParser();
525
				if (modelParser.areSemanticElementsAffected(null, event)) {
526
					removeSemanticListeners();
527
					if (resolveSemanticElement() != null) {
528
						addSemanticListeners();
529
					}
530
					refreshLabel();
531
				}
532
			}
533
		}
534
		super.handleNotificationEvent(event);
535
	}
536
537
	/**
538
	 * @generated
539
	 */
540
	protected IFigure createFigure() {
541
		IFigure label = createFigurePrim();
542
		defaultText = getLabelTextHelper(label);
543
		return label;
544
	}
545
546
	/**
547
	 * @generated
548
	 */
549
	protected IFigure createFigurePrim() {
550
		return new WrapLabel();
551
	}
552
553
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/parts/AssociationClassClassesEditPart.java (+67 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.parts;
2
3
import org.eclipse.emf.common.notify.Notification;
4
import org.eclipse.gef.EditPolicy;
5
import org.eclipse.gmf.runtime.diagram.ui.editparts.ListCompartmentEditPart;
6
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.CreationEditPolicy;
7
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.DragDropEditPolicy;
8
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
9
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.ResizableCompartmentEditPolicy;
10
import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout;
11
import org.eclipse.gmf.runtime.notation.View;
12
import org.eclipse.uml2.diagram.clazz.edit.policies.AssociationClassClassesCanonicalEditPolicy;
13
import org.eclipse.uml2.diagram.clazz.edit.policies.AssociationClassClassesItemSemanticEditPolicy;
14
15
/**
16
 * @generated
17
 */
18
public class AssociationClassClassesEditPart extends ListCompartmentEditPart {
19
20
	/**
21
	 * @generated
22
	 */
23
	public static final int VISUAL_ID = 7026;
24
25
	/**
26
	 * @generated
27
	 */
28
	public AssociationClassClassesEditPart(View view) {
29
		super(view);
30
	}
31
32
	/**
33
	 * @generated
34
	 */
35
	protected boolean hasModelChildrenChanged(Notification evt) {
36
		return false;
37
	}
38
39
	/**
40
	 * @generated
41
	 */
42
	public String getCompartmentName() {
43
		return "classes";
44
	}
45
46
	/**
47
	 * @generated
48
	 */
49
	protected void createDefaultEditPolicies() {
50
		super.createDefaultEditPolicies();
51
		installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ResizableCompartmentEditPolicy());
52
		installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new AssociationClassClassesItemSemanticEditPolicy());
53
		installEditPolicy(EditPolicyRoles.CREATION_ROLE, new CreationEditPolicy());
54
		installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, new DragDropEditPolicy());
55
		installEditPolicy(EditPolicyRoles.CANONICAL_ROLE, new AssociationClassClassesCanonicalEditPolicy());
56
57
	}
58
59
	/**
60
	 * @generated
61
	 */
62
	protected void setRatio(Double ratio) {
63
		if (getFigure().getParent().getLayoutManager() instanceof ConstrainedToolbarLayout) {
64
			super.setRatio(ratio);
65
		}
66
	}
67
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/parts/Class3EditPart.java (+553 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.parts;
2
3
import java.util.Collections;
4
import java.util.List;
5
6
import org.eclipse.draw2d.IFigure;
7
import org.eclipse.draw2d.Label;
8
import org.eclipse.draw2d.geometry.Point;
9
import org.eclipse.emf.common.notify.Notification;
10
import org.eclipse.emf.ecore.EObject;
11
import org.eclipse.emf.transaction.RunnableWithResult;
12
import org.eclipse.gef.AccessibleEditPart;
13
import org.eclipse.gef.DragTracker;
14
import org.eclipse.gef.EditPolicy;
15
import org.eclipse.gef.Request;
16
import org.eclipse.gef.requests.DirectEditRequest;
17
import org.eclipse.gef.requests.SelectionRequest;
18
import org.eclipse.gef.tools.DirectEditManager;
19
import org.eclipse.gmf.runtime.common.ui.services.parser.IParser;
20
import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus;
21
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserEditStatus;
22
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions;
23
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserService;
24
import org.eclipse.gmf.runtime.diagram.ui.editparts.CompartmentEditPart;
25
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
26
import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart;
27
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
28
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy;
29
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.ListItemComponentEditPolicy;
30
import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry;
31
import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants;
32
import org.eclipse.gmf.runtime.diagram.ui.tools.DragEditPartsTrackerEx;
33
import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager;
34
import org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel;
35
import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
36
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
37
import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser;
38
import org.eclipse.gmf.runtime.emf.ui.services.parser.ParserHintAdapter;
39
import org.eclipse.gmf.runtime.notation.FontStyle;
40
import org.eclipse.gmf.runtime.notation.NotationPackage;
41
import org.eclipse.gmf.runtime.notation.View;
42
import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
43
import org.eclipse.jface.viewers.ICellEditorValidator;
44
import org.eclipse.swt.SWT;
45
import org.eclipse.swt.accessibility.AccessibleEvent;
46
import org.eclipse.swt.graphics.Color;
47
import org.eclipse.swt.graphics.FontData;
48
import org.eclipse.swt.graphics.Image;
49
import org.eclipse.uml2.diagram.clazz.edit.policies.Class3ItemSemanticEditPolicy;
50
import org.eclipse.uml2.diagram.clazz.edit.policies.UMLTextNonResizableEditPolicy;
51
import org.eclipse.uml2.diagram.clazz.edit.policies.UMLTextSelectionEditPolicy;
52
import org.eclipse.uml2.diagram.clazz.providers.UMLElementTypes;
53
54
/**
55
 * @generated
56
 */
57
public class Class3EditPart extends CompartmentEditPart implements ITextAwareEditPart {
58
59
	/**
60
	 * @generated
61
	 */
62
	public static final int VISUAL_ID = 3003;
63
64
	/**
65
	 * @generated
66
	 */
67
	private DirectEditManager manager;
68
69
	/**
70
	 * @generated
71
	 */
72
	private IParser parser;
73
74
	/**
75
	 * @generated
76
	 */
77
	private List parserElements;
78
79
	/**
80
	 * @generated
81
	 */
82
	private String defaultText;
83
84
	/**
85
	 * @generated
86
	 */
87
	public Class3EditPart(View view) {
88
		super(view);
89
	}
90
91
	/**
92
	 * @generated
93
	 */
94
	public DragTracker getDragTracker(Request request) {
95
		if (request instanceof SelectionRequest && ((SelectionRequest) request).getLastButtonPressed() == 3) {
96
			return null;
97
		}
98
		return new DragEditPartsTrackerEx(this);
99
	}
100
101
	/**
102
	 * @generated
103
	 */
104
	protected void createDefaultEditPolicies() {
105
		super.createDefaultEditPolicies();
106
		installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new Class3ItemSemanticEditPolicy());
107
		installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new UMLTextNonResizableEditPolicy());
108
		installEditPolicy(EditPolicy.COMPONENT_ROLE, new ListItemComponentEditPolicy());
109
		installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy());
110
111
	}
112
113
	/**
114
	 * @generated
115
	 */
116
	protected String getLabelTextHelper(IFigure figure) {
117
		if (figure instanceof WrapLabel) {
118
			return ((WrapLabel) figure).getText();
119
		} else {
120
			return ((Label) figure).getText();
121
		}
122
	}
123
124
	/**
125
	 * @generated
126
	 */
127
	protected void setLabelTextHelper(IFigure figure, String text) {
128
		if (figure instanceof WrapLabel) {
129
			((WrapLabel) figure).setText(text);
130
		} else {
131
			((Label) figure).setText(text);
132
		}
133
	}
134
135
	/**
136
	 * @generated
137
	 */
138
	protected Image getLabelIconHelper(IFigure figure) {
139
		if (figure instanceof WrapLabel) {
140
			return ((WrapLabel) figure).getIcon();
141
		} else {
142
			return ((Label) figure).getIcon();
143
		}
144
	}
145
146
	/**
147
	 * @generated
148
	 */
149
	protected void setLabelIconHelper(IFigure figure, Image icon) {
150
		if (figure instanceof WrapLabel) {
151
			((WrapLabel) figure).setIcon(icon);
152
		} else {
153
			((Label) figure).setIcon(icon);
154
		}
155
	}
156
157
	/**
158
	 * @generated
159
	 */
160
	public void setLabel(IFigure figure) {
161
		unregisterVisuals();
162
		setFigure(figure);
163
		defaultText = getLabelTextHelper(figure);
164
		registerVisuals();
165
		refreshVisuals();
166
	}
167
168
	/**
169
	 * @generated
170
	 */
171
	protected List getModelChildren() {
172
		return Collections.EMPTY_LIST;
173
	}
174
175
	/**
176
	 * @generated
177
	 */
178
	public IGraphicalEditPart getChildBySemanticHint(String semanticHint) {
179
		return null;
180
	}
181
182
	/**
183
	 * @generated
184
	 */
185
	protected EObject getParserElement() {
186
		EObject element = resolveSemanticElement();
187
		return element != null ? element : (View) getModel();
188
	}
189
190
	/**
191
	 * @generated
192
	 */
193
	protected Image getLabelIcon() {
194
		return null;
195
	}
196
197
	/**
198
	 * @generated
199
	 */
200
	protected String getLabelText() {
201
		String text = null;
202
		if (getParser() != null) {
203
			text = getParser().getPrintString(new EObjectAdapter(getParserElement()), getParserOptions().intValue());
204
		}
205
		if (text == null || text.length() == 0) {
206
			text = defaultText;
207
		}
208
		return text;
209
	}
210
211
	/**
212
	 * @generated
213
	 */
214
	public void setLabelText(String text) {
215
		setLabelTextHelper(getFigure(), text);
216
		Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
217
		if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) {
218
			((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback();
219
		}
220
	}
221
222
	/**
223
	 * @generated
224
	 */
225
	public String getEditText() {
226
		if (getParser() == null) {
227
			return ""; //$NON-NLS-1$
228
		}
229
		return getParser().getEditString(new EObjectAdapter(getParserElement()), getParserOptions().intValue());
230
	}
231
232
	/**
233
	 * @generated
234
	 */
235
	protected boolean isEditable() {
236
		return getEditText() != null;
237
	}
238
239
	/**
240
	 * @generated
241
	 */
242
	public ICellEditorValidator getEditTextValidator() {
243
		return new ICellEditorValidator() {
244
245
			public String isValid(final Object value) {
246
				if (value instanceof String) {
247
					final EObject element = getParserElement();
248
					final IParser parser = getParser();
249
					try {
250
						IParserEditStatus valid = (IParserEditStatus) getEditingDomain().runExclusive(new RunnableWithResult.Impl() {
251
252
							public void run() {
253
								setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value));
254
							}
255
						});
256
						return valid.getCode() == ParserEditStatus.EDITABLE ? null : valid.getMessage();
257
					} catch (InterruptedException ie) {
258
						ie.printStackTrace();
259
					}
260
				}
261
262
				// shouldn't get here
263
				return null;
264
			}
265
		};
266
	}
267
268
	/**
269
	 * @generated
270
	 */
271
	public IContentAssistProcessor getCompletionProcessor() {
272
		if (getParser() == null) {
273
			return null;
274
		}
275
		return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement()));
276
	}
277
278
	/**
279
	 * @generated
280
	 */
281
	public ParserOptions getParserOptions() {
282
		return ParserOptions.NONE;
283
	}
284
285
	/**
286
	 * @generated
287
	 */
288
	public IParser getParser() {
289
		if (parser == null) {
290
			String parserHint = ((View) getModel()).getType();
291
			ParserHintAdapter hintAdapter = new ParserHintAdapter(getParserElement(), parserHint) {
292
293
				public Object getAdapter(Class adapter) {
294
					if (IElementType.class.equals(adapter)) {
295
						return UMLElementTypes.Class_3003;
296
					}
297
					return super.getAdapter(adapter);
298
				}
299
			};
300
			parser = ParserService.getInstance().getParser(hintAdapter);
301
		}
302
		return parser;
303
	}
304
305
	/**
306
	 * @generated
307
	 */
308
	protected DirectEditManager getManager() {
309
		if (manager == null) {
310
			setManager(new TextDirectEditManager(this, TextDirectEditManager.getTextCellEditorClass(this), UMLEditPartFactory.getTextCellEditorLocator(this)));
311
		}
312
		return manager;
313
	}
314
315
	/**
316
	 * @generated
317
	 */
318
	protected void setManager(DirectEditManager manager) {
319
		this.manager = manager;
320
	}
321
322
	/**
323
	 * @generated
324
	 */
325
	protected void performDirectEdit() {
326
		getManager().show();
327
	}
328
329
	/**
330
	 * @generated
331
	 */
332
	protected void performDirectEdit(Point eventLocation) {
333
		if (getManager().getClass() == TextDirectEditManager.class) {
334
			((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint());
335
		}
336
	}
337
338
	/**
339
	 * @generated
340
	 */
341
	private void performDirectEdit(char initialCharacter) {
342
		if (getManager() instanceof TextDirectEditManager) {
343
			((TextDirectEditManager) getManager()).show(initialCharacter);
344
		} else {
345
			performDirectEdit();
346
		}
347
	}
348
349
	/**
350
	 * @generated
351
	 */
352
	protected void performDirectEditRequest(Request request) {
353
		final Request theRequest = request;
354
		try {
355
			getEditingDomain().runExclusive(new Runnable() {
356
357
				public void run() {
358
					if (isActive() && isEditable()) {
359
						if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) {
360
							Character initialChar = (Character) theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR);
361
							performDirectEdit(initialChar.charValue());
362
						} else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) {
363
							DirectEditRequest editRequest = (DirectEditRequest) theRequest;
364
							performDirectEdit(editRequest.getLocation());
365
						} else {
366
							performDirectEdit();
367
						}
368
					}
369
				}
370
			});
371
		} catch (InterruptedException e) {
372
			e.printStackTrace();
373
		}
374
	}
375
376
	/**
377
	 * @generated
378
	 */
379
	protected void refreshVisuals() {
380
		super.refreshVisuals();
381
		refreshLabel();
382
		refreshFont();
383
		refreshFontColor();
384
		refreshUnderline();
385
		refreshStrikeThrough();
386
	}
387
388
	/**
389
	 * @generated
390
	 */
391
	protected void refreshLabel() {
392
		setLabelTextHelper(getFigure(), getLabelText());
393
		setLabelIconHelper(getFigure(), getLabelIcon());
394
		Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
395
		if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) {
396
			((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback();
397
		}
398
	}
399
400
	/**
401
	 * @generated
402
	 */
403
	protected void refreshUnderline() {
404
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
405
		if (style != null && getFigure() instanceof WrapLabel) {
406
			((WrapLabel) getFigure()).setTextUnderline(style.isUnderline());
407
		}
408
	}
409
410
	/**
411
	 * @generated
412
	 */
413
	protected void refreshStrikeThrough() {
414
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
415
		if (style != null && getFigure() instanceof WrapLabel) {
416
			((WrapLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough());
417
		}
418
	}
419
420
	/**
421
	 * @generated
422
	 */
423
	protected void refreshFont() {
424
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
425
		if (style != null) {
426
			FontData fontData = new FontData(style.getFontName(), style.getFontHeight(), (style.isBold() ? SWT.BOLD : SWT.NORMAL) | (style.isItalic() ? SWT.ITALIC : SWT.NORMAL));
427
			setFont(fontData);
428
		}
429
	}
430
431
	/**
432
	 * @generated
433
	 */
434
	protected void setFontColor(Color color) {
435
		getFigure().setForegroundColor(color);
436
	}
437
438
	/**
439
	 * @generated
440
	 */
441
	protected void addSemanticListeners() {
442
		if (getParser() instanceof ISemanticParser) {
443
			EObject element = resolveSemanticElement();
444
			parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element);
445
			for (int i = 0; i < parserElements.size(); i++) {
446
				addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$
447
			}
448
		} else {
449
			super.addSemanticListeners();
450
		}
451
	}
452
453
	/**
454
	 * @generated
455
	 */
456
	protected void removeSemanticListeners() {
457
		if (parserElements != null) {
458
			for (int i = 0; i < parserElements.size(); i++) {
459
				removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$
460
			}
461
		} else {
462
			super.removeSemanticListeners();
463
		}
464
	}
465
466
	/**
467
	 * @generated
468
	 */
469
	protected AccessibleEditPart getAccessibleEditPart() {
470
		if (accessibleEP == null) {
471
			accessibleEP = new AccessibleGraphicalEditPart() {
472
473
				public void getName(AccessibleEvent e) {
474
					e.result = getLabelTextHelper(getFigure());
475
				}
476
			};
477
		}
478
		return accessibleEP;
479
	}
480
481
	/**
482
	 * @generated
483
	 */
484
	private View getFontStyleOwnerView() {
485
		return getPrimaryView();
486
	}
487
488
	/**
489
	 * @generated
490
	 */
491
	protected void addNotationalListeners() {
492
		super.addNotationalListeners();
493
		addListenerFilter("PrimaryView", this, getPrimaryView()); //$NON-NLS-1$
494
	}
495
496
	/**
497
	 * @generated
498
	 */
499
	protected void removeNotationalListeners() {
500
		super.removeNotationalListeners();
501
		removeListenerFilter("PrimaryView"); //$NON-NLS-1$
502
	}
503
504
	/**
505
	 * @generated
506
	 */
507
	protected void handleNotificationEvent(Notification event) {
508
		Object feature = event.getFeature();
509
		if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) {
510
			Integer c = (Integer) event.getNewValue();
511
			setFontColor(DiagramColorRegistry.getInstance().getColor(c));
512
		} else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) {
513
			refreshUnderline();
514
		} else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) {
515
			refreshStrikeThrough();
516
		} else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature)
517
				|| NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) {
518
			refreshFont();
519
		} else {
520
			if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) {
521
				refreshLabel();
522
			}
523
			if (getParser() instanceof ISemanticParser) {
524
				ISemanticParser modelParser = (ISemanticParser) getParser();
525
				if (modelParser.areSemanticElementsAffected(null, event)) {
526
					removeSemanticListeners();
527
					if (resolveSemanticElement() != null) {
528
						addSemanticListeners();
529
					}
530
					refreshLabel();
531
				}
532
			}
533
		}
534
		super.handleNotificationEvent(event);
535
	}
536
537
	/**
538
	 * @generated
539
	 */
540
	protected IFigure createFigure() {
541
		IFigure label = createFigurePrim();
542
		defaultText = getLabelTextHelper(label);
543
		return label;
544
	}
545
546
	/**
547
	 * @generated
548
	 */
549
	protected IFigure createFigurePrim() {
550
		return new WrapLabel();
551
	}
552
553
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/parts/Property4EditPart.java (+553 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.parts;
2
3
import java.util.Collections;
4
import java.util.List;
5
6
import org.eclipse.draw2d.IFigure;
7
import org.eclipse.draw2d.Label;
8
import org.eclipse.draw2d.geometry.Point;
9
import org.eclipse.emf.common.notify.Notification;
10
import org.eclipse.emf.ecore.EObject;
11
import org.eclipse.emf.transaction.RunnableWithResult;
12
import org.eclipse.gef.AccessibleEditPart;
13
import org.eclipse.gef.DragTracker;
14
import org.eclipse.gef.EditPolicy;
15
import org.eclipse.gef.Request;
16
import org.eclipse.gef.requests.DirectEditRequest;
17
import org.eclipse.gef.requests.SelectionRequest;
18
import org.eclipse.gef.tools.DirectEditManager;
19
import org.eclipse.gmf.runtime.common.ui.services.parser.IParser;
20
import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus;
21
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserEditStatus;
22
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions;
23
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserService;
24
import org.eclipse.gmf.runtime.diagram.ui.editparts.CompartmentEditPart;
25
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
26
import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart;
27
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
28
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy;
29
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.ListItemComponentEditPolicy;
30
import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry;
31
import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants;
32
import org.eclipse.gmf.runtime.diagram.ui.tools.DragEditPartsTrackerEx;
33
import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager;
34
import org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel;
35
import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
36
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
37
import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser;
38
import org.eclipse.gmf.runtime.emf.ui.services.parser.ParserHintAdapter;
39
import org.eclipse.gmf.runtime.notation.FontStyle;
40
import org.eclipse.gmf.runtime.notation.NotationPackage;
41
import org.eclipse.gmf.runtime.notation.View;
42
import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
43
import org.eclipse.jface.viewers.ICellEditorValidator;
44
import org.eclipse.swt.SWT;
45
import org.eclipse.swt.accessibility.AccessibleEvent;
46
import org.eclipse.swt.graphics.Color;
47
import org.eclipse.swt.graphics.FontData;
48
import org.eclipse.swt.graphics.Image;
49
import org.eclipse.uml2.diagram.clazz.edit.policies.Property4ItemSemanticEditPolicy;
50
import org.eclipse.uml2.diagram.clazz.edit.policies.UMLTextNonResizableEditPolicy;
51
import org.eclipse.uml2.diagram.clazz.edit.policies.UMLTextSelectionEditPolicy;
52
import org.eclipse.uml2.diagram.clazz.providers.UMLElementTypes;
53
54
/**
55
 * @generated
56
 */
57
public class Property4EditPart extends CompartmentEditPart implements ITextAwareEditPart {
58
59
	/**
60
	 * @generated
61
	 */
62
	public static final int VISUAL_ID = 3021;
63
64
	/**
65
	 * @generated
66
	 */
67
	private DirectEditManager manager;
68
69
	/**
70
	 * @generated
71
	 */
72
	private IParser parser;
73
74
	/**
75
	 * @generated
76
	 */
77
	private List parserElements;
78
79
	/**
80
	 * @generated
81
	 */
82
	private String defaultText;
83
84
	/**
85
	 * @generated
86
	 */
87
	public Property4EditPart(View view) {
88
		super(view);
89
	}
90
91
	/**
92
	 * @generated
93
	 */
94
	public DragTracker getDragTracker(Request request) {
95
		if (request instanceof SelectionRequest && ((SelectionRequest) request).getLastButtonPressed() == 3) {
96
			return null;
97
		}
98
		return new DragEditPartsTrackerEx(this);
99
	}
100
101
	/**
102
	 * @generated
103
	 */
104
	protected void createDefaultEditPolicies() {
105
		super.createDefaultEditPolicies();
106
		installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new Property4ItemSemanticEditPolicy());
107
		installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new UMLTextNonResizableEditPolicy());
108
		installEditPolicy(EditPolicy.COMPONENT_ROLE, new ListItemComponentEditPolicy());
109
		installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy());
110
111
	}
112
113
	/**
114
	 * @generated
115
	 */
116
	protected String getLabelTextHelper(IFigure figure) {
117
		if (figure instanceof WrapLabel) {
118
			return ((WrapLabel) figure).getText();
119
		} else {
120
			return ((Label) figure).getText();
121
		}
122
	}
123
124
	/**
125
	 * @generated
126
	 */
127
	protected void setLabelTextHelper(IFigure figure, String text) {
128
		if (figure instanceof WrapLabel) {
129
			((WrapLabel) figure).setText(text);
130
		} else {
131
			((Label) figure).setText(text);
132
		}
133
	}
134
135
	/**
136
	 * @generated
137
	 */
138
	protected Image getLabelIconHelper(IFigure figure) {
139
		if (figure instanceof WrapLabel) {
140
			return ((WrapLabel) figure).getIcon();
141
		} else {
142
			return ((Label) figure).getIcon();
143
		}
144
	}
145
146
	/**
147
	 * @generated
148
	 */
149
	protected void setLabelIconHelper(IFigure figure, Image icon) {
150
		if (figure instanceof WrapLabel) {
151
			((WrapLabel) figure).setIcon(icon);
152
		} else {
153
			((Label) figure).setIcon(icon);
154
		}
155
	}
156
157
	/**
158
	 * @generated
159
	 */
160
	public void setLabel(IFigure figure) {
161
		unregisterVisuals();
162
		setFigure(figure);
163
		defaultText = getLabelTextHelper(figure);
164
		registerVisuals();
165
		refreshVisuals();
166
	}
167
168
	/**
169
	 * @generated
170
	 */
171
	protected List getModelChildren() {
172
		return Collections.EMPTY_LIST;
173
	}
174
175
	/**
176
	 * @generated
177
	 */
178
	public IGraphicalEditPart getChildBySemanticHint(String semanticHint) {
179
		return null;
180
	}
181
182
	/**
183
	 * @generated
184
	 */
185
	protected EObject getParserElement() {
186
		EObject element = resolveSemanticElement();
187
		return element != null ? element : (View) getModel();
188
	}
189
190
	/**
191
	 * @generated
192
	 */
193
	protected Image getLabelIcon() {
194
		return null;
195
	}
196
197
	/**
198
	 * @generated
199
	 */
200
	protected String getLabelText() {
201
		String text = null;
202
		if (getParser() != null) {
203
			text = getParser().getPrintString(new EObjectAdapter(getParserElement()), getParserOptions().intValue());
204
		}
205
		if (text == null || text.length() == 0) {
206
			text = defaultText;
207
		}
208
		return text;
209
	}
210
211
	/**
212
	 * @generated
213
	 */
214
	public void setLabelText(String text) {
215
		setLabelTextHelper(getFigure(), text);
216
		Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
217
		if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) {
218
			((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback();
219
		}
220
	}
221
222
	/**
223
	 * @generated
224
	 */
225
	public String getEditText() {
226
		if (getParser() == null) {
227
			return ""; //$NON-NLS-1$
228
		}
229
		return getParser().getEditString(new EObjectAdapter(getParserElement()), getParserOptions().intValue());
230
	}
231
232
	/**
233
	 * @generated
234
	 */
235
	protected boolean isEditable() {
236
		return getEditText() != null;
237
	}
238
239
	/**
240
	 * @generated
241
	 */
242
	public ICellEditorValidator getEditTextValidator() {
243
		return new ICellEditorValidator() {
244
245
			public String isValid(final Object value) {
246
				if (value instanceof String) {
247
					final EObject element = getParserElement();
248
					final IParser parser = getParser();
249
					try {
250
						IParserEditStatus valid = (IParserEditStatus) getEditingDomain().runExclusive(new RunnableWithResult.Impl() {
251
252
							public void run() {
253
								setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value));
254
							}
255
						});
256
						return valid.getCode() == ParserEditStatus.EDITABLE ? null : valid.getMessage();
257
					} catch (InterruptedException ie) {
258
						ie.printStackTrace();
259
					}
260
				}
261
262
				// shouldn't get here
263
				return null;
264
			}
265
		};
266
	}
267
268
	/**
269
	 * @generated
270
	 */
271
	public IContentAssistProcessor getCompletionProcessor() {
272
		if (getParser() == null) {
273
			return null;
274
		}
275
		return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement()));
276
	}
277
278
	/**
279
	 * @generated
280
	 */
281
	public ParserOptions getParserOptions() {
282
		return ParserOptions.NONE;
283
	}
284
285
	/**
286
	 * @generated
287
	 */
288
	public IParser getParser() {
289
		if (parser == null) {
290
			String parserHint = ((View) getModel()).getType();
291
			ParserHintAdapter hintAdapter = new ParserHintAdapter(getParserElement(), parserHint) {
292
293
				public Object getAdapter(Class adapter) {
294
					if (IElementType.class.equals(adapter)) {
295
						return UMLElementTypes.Property_3021;
296
					}
297
					return super.getAdapter(adapter);
298
				}
299
			};
300
			parser = ParserService.getInstance().getParser(hintAdapter);
301
		}
302
		return parser;
303
	}
304
305
	/**
306
	 * @generated
307
	 */
308
	protected DirectEditManager getManager() {
309
		if (manager == null) {
310
			setManager(new TextDirectEditManager(this, TextDirectEditManager.getTextCellEditorClass(this), UMLEditPartFactory.getTextCellEditorLocator(this)));
311
		}
312
		return manager;
313
	}
314
315
	/**
316
	 * @generated
317
	 */
318
	protected void setManager(DirectEditManager manager) {
319
		this.manager = manager;
320
	}
321
322
	/**
323
	 * @generated
324
	 */
325
	protected void performDirectEdit() {
326
		getManager().show();
327
	}
328
329
	/**
330
	 * @generated
331
	 */
332
	protected void performDirectEdit(Point eventLocation) {
333
		if (getManager().getClass() == TextDirectEditManager.class) {
334
			((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint());
335
		}
336
	}
337
338
	/**
339
	 * @generated
340
	 */
341
	private void performDirectEdit(char initialCharacter) {
342
		if (getManager() instanceof TextDirectEditManager) {
343
			((TextDirectEditManager) getManager()).show(initialCharacter);
344
		} else {
345
			performDirectEdit();
346
		}
347
	}
348
349
	/**
350
	 * @generated
351
	 */
352
	protected void performDirectEditRequest(Request request) {
353
		final Request theRequest = request;
354
		try {
355
			getEditingDomain().runExclusive(new Runnable() {
356
357
				public void run() {
358
					if (isActive() && isEditable()) {
359
						if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) {
360
							Character initialChar = (Character) theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR);
361
							performDirectEdit(initialChar.charValue());
362
						} else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) {
363
							DirectEditRequest editRequest = (DirectEditRequest) theRequest;
364
							performDirectEdit(editRequest.getLocation());
365
						} else {
366
							performDirectEdit();
367
						}
368
					}
369
				}
370
			});
371
		} catch (InterruptedException e) {
372
			e.printStackTrace();
373
		}
374
	}
375
376
	/**
377
	 * @generated
378
	 */
379
	protected void refreshVisuals() {
380
		super.refreshVisuals();
381
		refreshLabel();
382
		refreshFont();
383
		refreshFontColor();
384
		refreshUnderline();
385
		refreshStrikeThrough();
386
	}
387
388
	/**
389
	 * @generated
390
	 */
391
	protected void refreshLabel() {
392
		setLabelTextHelper(getFigure(), getLabelText());
393
		setLabelIconHelper(getFigure(), getLabelIcon());
394
		Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
395
		if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) {
396
			((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback();
397
		}
398
	}
399
400
	/**
401
	 * @generated
402
	 */
403
	protected void refreshUnderline() {
404
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
405
		if (style != null && getFigure() instanceof WrapLabel) {
406
			((WrapLabel) getFigure()).setTextUnderline(style.isUnderline());
407
		}
408
	}
409
410
	/**
411
	 * @generated
412
	 */
413
	protected void refreshStrikeThrough() {
414
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
415
		if (style != null && getFigure() instanceof WrapLabel) {
416
			((WrapLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough());
417
		}
418
	}
419
420
	/**
421
	 * @generated
422
	 */
423
	protected void refreshFont() {
424
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
425
		if (style != null) {
426
			FontData fontData = new FontData(style.getFontName(), style.getFontHeight(), (style.isBold() ? SWT.BOLD : SWT.NORMAL) | (style.isItalic() ? SWT.ITALIC : SWT.NORMAL));
427
			setFont(fontData);
428
		}
429
	}
430
431
	/**
432
	 * @generated
433
	 */
434
	protected void setFontColor(Color color) {
435
		getFigure().setForegroundColor(color);
436
	}
437
438
	/**
439
	 * @generated
440
	 */
441
	protected void addSemanticListeners() {
442
		if (getParser() instanceof ISemanticParser) {
443
			EObject element = resolveSemanticElement();
444
			parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element);
445
			for (int i = 0; i < parserElements.size(); i++) {
446
				addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$
447
			}
448
		} else {
449
			super.addSemanticListeners();
450
		}
451
	}
452
453
	/**
454
	 * @generated
455
	 */
456
	protected void removeSemanticListeners() {
457
		if (parserElements != null) {
458
			for (int i = 0; i < parserElements.size(); i++) {
459
				removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$
460
			}
461
		} else {
462
			super.removeSemanticListeners();
463
		}
464
	}
465
466
	/**
467
	 * @generated
468
	 */
469
	protected AccessibleEditPart getAccessibleEditPart() {
470
		if (accessibleEP == null) {
471
			accessibleEP = new AccessibleGraphicalEditPart() {
472
473
				public void getName(AccessibleEvent e) {
474
					e.result = getLabelTextHelper(getFigure());
475
				}
476
			};
477
		}
478
		return accessibleEP;
479
	}
480
481
	/**
482
	 * @generated
483
	 */
484
	private View getFontStyleOwnerView() {
485
		return getPrimaryView();
486
	}
487
488
	/**
489
	 * @generated
490
	 */
491
	protected void addNotationalListeners() {
492
		super.addNotationalListeners();
493
		addListenerFilter("PrimaryView", this, getPrimaryView()); //$NON-NLS-1$
494
	}
495
496
	/**
497
	 * @generated
498
	 */
499
	protected void removeNotationalListeners() {
500
		super.removeNotationalListeners();
501
		removeListenerFilter("PrimaryView"); //$NON-NLS-1$
502
	}
503
504
	/**
505
	 * @generated
506
	 */
507
	protected void handleNotificationEvent(Notification event) {
508
		Object feature = event.getFeature();
509
		if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) {
510
			Integer c = (Integer) event.getNewValue();
511
			setFontColor(DiagramColorRegistry.getInstance().getColor(c));
512
		} else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) {
513
			refreshUnderline();
514
		} else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) {
515
			refreshStrikeThrough();
516
		} else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature)
517
				|| NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) {
518
			refreshFont();
519
		} else {
520
			if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) {
521
				refreshLabel();
522
			}
523
			if (getParser() instanceof ISemanticParser) {
524
				ISemanticParser modelParser = (ISemanticParser) getParser();
525
				if (modelParser.areSemanticElementsAffected(null, event)) {
526
					removeSemanticListeners();
527
					if (resolveSemanticElement() != null) {
528
						addSemanticListeners();
529
					}
530
					refreshLabel();
531
				}
532
			}
533
		}
534
		super.handleNotificationEvent(event);
535
	}
536
537
	/**
538
	 * @generated
539
	 */
540
	protected IFigure createFigure() {
541
		IFigure label = createFigurePrim();
542
		defaultText = getLabelTextHelper(label);
543
		return label;
544
	}
545
546
	/**
547
	 * @generated
548
	 */
549
	protected IFigure createFigurePrim() {
550
		return new WrapLabel();
551
	}
552
553
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/policies/AssociationClassItemSemanticEditPolicy.java (+474 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.policies;
2
3
import org.eclipse.emf.ecore.EAnnotation;
4
import org.eclipse.emf.ecore.EClass;
5
import org.eclipse.emf.ecore.EObject;
6
import org.eclipse.gef.commands.Command;
7
import org.eclipse.gef.commands.UnexecutableCommand;
8
import org.eclipse.gmf.runtime.emf.type.core.commands.CreateRelationshipCommand;
9
import org.eclipse.gmf.runtime.emf.type.core.commands.DestroyElementCommand;
10
import org.eclipse.gmf.runtime.emf.type.core.commands.SetValueCommand;
11
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest;
12
import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest;
13
import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest;
14
import org.eclipse.gmf.runtime.notation.View;
15
import org.eclipse.uml2.diagram.clazz.providers.UMLElementTypes;
16
import org.eclipse.uml2.uml.Association;
17
import org.eclipse.uml2.uml.Classifier;
18
import org.eclipse.uml2.uml.Constraint;
19
import org.eclipse.uml2.uml.Dependency;
20
import org.eclipse.uml2.uml.Generalization;
21
import org.eclipse.uml2.uml.NamedElement;
22
import org.eclipse.uml2.uml.Property;
23
import org.eclipse.uml2.uml.Type;
24
import org.eclipse.uml2.uml.UMLPackage;
25
import org.eclipse.uml2.uml.Usage;
26
27
/**
28
 * @generated
29
 */
30
public class AssociationClassItemSemanticEditPolicy extends UMLBaseItemSemanticEditPolicy {
31
32
	/**
33
	 * @generated
34
	 */
35
	protected Command getDestroyElementCommand(DestroyElementRequest req) {
36
		return getMSLWrapper(new DestroyElementCommand(req) {
37
38
			protected EObject getElementToDestroy() {
39
				View view = (View) getHost().getModel();
40
				EAnnotation annotation = view.getEAnnotation("Shortcut"); //$NON-NLS-1$
41
				if (annotation != null) {
42
					return view;
43
				}
44
				return super.getElementToDestroy();
45
			}
46
47
		});
48
	}
49
50
	/**
51
	 * @generated
52
	 */
53
	protected Command getCreateRelationshipCommand(CreateRelationshipRequest req) {
54
		if (UMLElementTypes.Generalization_4001 == req.getElementType()) {
55
			return req.getTarget() == null ? getCreateStartOutgoingGeneralization4001Command(req) : getCreateCompleteIncomingGeneralization4001Command(req);
56
		}
57
		if (UMLElementTypes.Dependency_4002 == req.getElementType()) {
58
			return req.getTarget() == null ? getCreateStartOutgoingDependency4002Command(req) : getCreateCompleteIncomingDependency4002Command(req);
59
		}
60
		if (UMLElementTypes.Property_4003 == req.getElementType()) {
61
			return req.getTarget() == null ? getCreateStartOutgoingProperty4003Command(req) : getCreateCompleteIncomingProperty4003Command(req);
62
		}
63
		if (UMLElementTypes.ConstraintConstrainedElement_4004 == req.getElementType()) {
64
			return req.getTarget() == null ? null : getCreateCompleteIncomingConstraint_ConstrainedElement4004Command(req);
65
		}
66
		if (UMLElementTypes.Association_4005 == req.getElementType()) {
67
			return req.getTarget() == null ? getCreateStartOutgoingAssociation4005Command(req) : getCreateCompleteIncomingAssociation4005Command(req);
68
		}
69
		if (UMLElementTypes.DependencySupplier_4006 == req.getElementType()) {
70
			return req.getTarget() == null ? null : getCreateCompleteIncomingDependency_Supplier4006Command(req);
71
		}
72
		if (UMLElementTypes.DependencyClient_4007 == req.getElementType()) {
73
			return req.getTarget() == null ? null : getCreateCompleteIncomingDependency_Client4007Command(req);
74
		}
75
		if (UMLElementTypes.InterfaceRealization_4008 == req.getElementType()) {
76
			return req.getTarget() == null ? getCreateStartOutgoingInterfaceRealization4008Command(req) : null;
77
		}
78
		if (UMLElementTypes.Usage_4009 == req.getElementType()) {
79
			return req.getTarget() == null ? getCreateStartOutgoingUsage4009Command(req) : getCreateCompleteIncomingUsage4009Command(req);
80
		}
81
		return super.getCreateRelationshipCommand(req);
82
	}
83
84
	/**
85
	 * @generated
86
	 */
87
	protected Command getCreateStartOutgoingGeneralization4001Command(CreateRelationshipRequest req) {
88
		return new Command() {
89
		};
90
	}
91
92
	/**
93
	 * @generated
94
	 */
95
	protected Command getCreateCompleteIncomingGeneralization4001Command(CreateRelationshipRequest req) {
96
		if (!(req.getSource() instanceof Classifier)) {
97
			return UnexecutableCommand.INSTANCE;
98
		}
99
		final Classifier element = (Classifier) req.getSource();
100
		if (req.getContainmentFeature() == null) {
101
			req.setContainmentFeature(UMLPackage.eINSTANCE.getClassifier_Generalization());
102
		}
103
		return getMSLWrapper(new CreateIncomingGeneralization4001Command(req) {
104
105
			protected EObject getElementToEdit() {
106
				return element;
107
			}
108
		});
109
	}
110
111
	/**
112
	 * @generated
113
	 */
114
	private static class CreateIncomingGeneralization4001Command extends CreateRelationshipCommand {
115
116
		/**
117
		 * @generated
118
		 */
119
		public CreateIncomingGeneralization4001Command(CreateRelationshipRequest req) {
120
			super(req);
121
		}
122
123
		/**
124
		 * @generated
125
		 */
126
		protected EClass getEClassToEdit() {
127
			return UMLPackage.eINSTANCE.getClassifier();
128
		};
129
130
		/**
131
		 * @generated
132
		 */
133
		protected void setElementToEdit(EObject element) {
134
			throw new UnsupportedOperationException();
135
		}
136
137
		/**
138
		 * @generated
139
		 */
140
		protected EObject doDefaultElementCreation() {
141
			Generalization newElement = (Generalization) super.doDefaultElementCreation();
142
			if (newElement != null) {
143
				newElement.setGeneral((Classifier) getTarget());
144
			}
145
			return newElement;
146
		}
147
	}
148
149
	/**
150
	 * @generated
151
	 */
152
	protected Command getCreateStartOutgoingDependency4002Command(CreateRelationshipRequest req) {
153
		return new Command() {
154
		};
155
	}
156
157
	/**
158
	 * @generated
159
	 */
160
	protected Command getCreateCompleteIncomingDependency4002Command(CreateRelationshipRequest req) {
161
		if (!(req.getSource() instanceof NamedElement)) {
162
			return UnexecutableCommand.INSTANCE;
163
		}
164
		final org.eclipse.uml2.uml.Package element = (org.eclipse.uml2.uml.Package) getRelationshipContainer(req.getSource(), UMLPackage.eINSTANCE.getPackage(), req.getElementType());
165
		if (element == null) {
166
			return UnexecutableCommand.INSTANCE;
167
		}
168
		if (req.getContainmentFeature() == null) {
169
			req.setContainmentFeature(UMLPackage.eINSTANCE.getPackage_PackagedElement());
170
		}
171
		return getMSLWrapper(new CreateIncomingDependency4002Command(req) {
172
173
			protected EObject getElementToEdit() {
174
				return element;
175
			}
176
		});
177
	}
178
179
	/**
180
	 * @generated
181
	 */
182
	private static class CreateIncomingDependency4002Command extends CreateRelationshipCommand {
183
184
		/**
185
		 * @generated
186
		 */
187
		public CreateIncomingDependency4002Command(CreateRelationshipRequest req) {
188
			super(req);
189
		}
190
191
		/**
192
		 * @generated
193
		 */
194
		protected EClass getEClassToEdit() {
195
			return UMLPackage.eINSTANCE.getPackage();
196
		};
197
198
		/**
199
		 * @generated
200
		 */
201
		protected void setElementToEdit(EObject element) {
202
			throw new UnsupportedOperationException();
203
		}
204
205
		/**
206
		 * @generated
207
		 */
208
		protected EObject doDefaultElementCreation() {
209
			Dependency newElement = (Dependency) super.doDefaultElementCreation();
210
			if (newElement != null) {
211
				newElement.getSuppliers().add((NamedElement) getTarget());
212
				newElement.getClients().add((NamedElement) getSource());
213
			}
214
			return newElement;
215
		}
216
	}
217
218
	/**
219
	 * @generated
220
	 */
221
	protected Command getCreateStartOutgoingProperty4003Command(CreateRelationshipRequest req) {
222
		return new Command() {
223
		};
224
	}
225
226
	/**
227
	 * @generated
228
	 */
229
	protected Command getCreateCompleteIncomingProperty4003Command(CreateRelationshipRequest req) {
230
		if (!(req.getSource() instanceof Association)) {
231
			return UnexecutableCommand.INSTANCE;
232
		}
233
		final Association element = (Association) req.getSource();
234
		if (req.getContainmentFeature() == null) {
235
			req.setContainmentFeature(UMLPackage.eINSTANCE.getAssociation_OwnedEnd());
236
		}
237
		return getMSLWrapper(new CreateIncomingProperty4003Command(req) {
238
239
			protected EObject getElementToEdit() {
240
				return element;
241
			}
242
		});
243
	}
244
245
	/**
246
	 * @generated
247
	 */
248
	private static class CreateIncomingProperty4003Command extends CreateRelationshipCommand {
249
250
		/**
251
		 * @generated
252
		 */
253
		public CreateIncomingProperty4003Command(CreateRelationshipRequest req) {
254
			super(req);
255
		}
256
257
		/**
258
		 * @generated
259
		 */
260
		protected EClass getEClassToEdit() {
261
			return UMLPackage.eINSTANCE.getAssociation();
262
		};
263
264
		/**
265
		 * @generated
266
		 */
267
		protected void setElementToEdit(EObject element) {
268
			throw new UnsupportedOperationException();
269
		}
270
271
		/**
272
		 * @generated
273
		 */
274
		protected EObject doDefaultElementCreation() {
275
			Property newElement = (Property) super.doDefaultElementCreation();
276
			if (newElement != null) {
277
				newElement.setType((Type) getTarget());
278
			}
279
			return newElement;
280
		}
281
	}
282
283
	/**
284
	 * @generated
285
	 */
286
	protected Command getCreateCompleteIncomingConstraint_ConstrainedElement4004Command(CreateRelationshipRequest req) {
287
		if (!(req.getSource() instanceof Constraint)) {
288
			return UnexecutableCommand.INSTANCE;
289
		}
290
		Constraint element = (Constraint) req.getSource();
291
		if (element.getConstrainedElements().contains(req.getTarget())) {
292
			return UnexecutableCommand.INSTANCE;
293
		}
294
		SetRequest setReq = new SetRequest(req.getSource(), UMLPackage.eINSTANCE.getConstraint_ConstrainedElement(), req.getTarget());
295
		return getMSLWrapper(new SetValueCommand(setReq));
296
	}
297
298
	/**
299
	 * @generated
300
	 */
301
	protected Command getCreateStartOutgoingAssociation4005Command(CreateRelationshipRequest req) {
302
		return new Command() {
303
		};
304
	}
305
306
	/**
307
	 * @generated
308
	 */
309
	protected Command getCreateCompleteIncomingAssociation4005Command(CreateRelationshipRequest req) {
310
		if (!(req.getSource() instanceof Type)) {
311
			return UnexecutableCommand.INSTANCE;
312
		}
313
		final org.eclipse.uml2.uml.Package element = (org.eclipse.uml2.uml.Package) getRelationshipContainer(req.getSource(), UMLPackage.eINSTANCE.getPackage(), req.getElementType());
314
		if (element == null) {
315
			return UnexecutableCommand.INSTANCE;
316
		}
317
		if (req.getContainmentFeature() == null) {
318
			req.setContainmentFeature(UMLPackage.eINSTANCE.getPackage_PackagedElement());
319
		}
320
		return getMSLWrapper(new CreateIncomingAssociation4005Command(req) {
321
322
			protected EObject getElementToEdit() {
323
				return element;
324
			}
325
		});
326
	}
327
328
	/**
329
	 * @generated NOT
330
	 */
331
	private static class CreateIncomingAssociation4005Command extends CreateAssociationCommand {
332
333
		/**
334
		 * @generated
335
		 */
336
		public CreateIncomingAssociation4005Command(CreateRelationshipRequest req) {
337
			super(req);
338
		}
339
340
		/**
341
		 * @generated
342
		 */
343
		protected EClass getEClassToEdit() {
344
			return UMLPackage.eINSTANCE.getPackage();
345
		};
346
347
		/**
348
		 * @generated
349
		 */
350
		protected void setElementToEdit(EObject element) {
351
			throw new UnsupportedOperationException();
352
		}
353
354
		/**
355
		 * @generated NOT
356
		 */
357
		protected EObject doDefaultElementCreation() {
358
			return super.doDefaultElementCreation();
359
		}
360
	}
361
362
	/**
363
	 * @generated
364
	 */
365
	protected Command getCreateCompleteIncomingDependency_Supplier4006Command(CreateRelationshipRequest req) {
366
		if (!(req.getSource() instanceof Dependency)) {
367
			return UnexecutableCommand.INSTANCE;
368
		}
369
		Dependency element = (Dependency) req.getSource();
370
		if (element.getSuppliers().contains(req.getTarget())) {
371
			return UnexecutableCommand.INSTANCE;
372
		}
373
		SetRequest setReq = new SetRequest(req.getSource(), UMLPackage.eINSTANCE.getDependency_Supplier(), req.getTarget());
374
		return getMSLWrapper(new SetValueCommand(setReq));
375
	}
376
377
	/**
378
	 * @generated
379
	 */
380
	protected Command getCreateCompleteIncomingDependency_Client4007Command(CreateRelationshipRequest req) {
381
		if (!(req.getSource() instanceof Dependency)) {
382
			return UnexecutableCommand.INSTANCE;
383
		}
384
		Dependency element = (Dependency) req.getSource();
385
		if (element.getClients().contains(req.getTarget())) {
386
			return UnexecutableCommand.INSTANCE;
387
		}
388
		SetRequest setReq = new SetRequest(req.getSource(), UMLPackage.eINSTANCE.getDependency_Client(), req.getTarget());
389
		return getMSLWrapper(new SetValueCommand(setReq));
390
	}
391
392
	/**
393
	 * @generated
394
	 */
395
	protected Command getCreateStartOutgoingInterfaceRealization4008Command(CreateRelationshipRequest req) {
396
		return new Command() {
397
		};
398
	}
399
400
	/**
401
	 * @generated
402
	 */
403
	protected Command getCreateStartOutgoingUsage4009Command(CreateRelationshipRequest req) {
404
		if (!UMLBaseItemSemanticEditPolicy.LinkConstraints.Usage_4009.canCreateLink(req, false)) {
405
			return UnexecutableCommand.INSTANCE;
406
		}
407
		return new Command() {
408
		};
409
	}
410
411
	/**
412
	 * @generated
413
	 */
414
	protected Command getCreateCompleteIncomingUsage4009Command(CreateRelationshipRequest req) {
415
		if (!(req.getSource() instanceof NamedElement)) {
416
			return UnexecutableCommand.INSTANCE;
417
		}
418
		final org.eclipse.uml2.uml.Package element = (org.eclipse.uml2.uml.Package) getRelationshipContainer(req.getSource(), UMLPackage.eINSTANCE.getPackage(), req.getElementType());
419
		if (element == null) {
420
			return UnexecutableCommand.INSTANCE;
421
		}
422
		if (!UMLBaseItemSemanticEditPolicy.LinkConstraints.Usage_4009.canCreateLink(req, false)) {
423
			return UnexecutableCommand.INSTANCE;
424
		}
425
		if (req.getContainmentFeature() == null) {
426
			req.setContainmentFeature(UMLPackage.eINSTANCE.getPackage_PackagedElement());
427
		}
428
		return getMSLWrapper(new CreateIncomingUsage4009Command(req) {
429
430
			protected EObject getElementToEdit() {
431
				return element;
432
			}
433
		});
434
	}
435
436
	/**
437
	 * @generated
438
	 */
439
	private static class CreateIncomingUsage4009Command extends CreateRelationshipCommand {
440
441
		/**
442
		 * @generated
443
		 */
444
		public CreateIncomingUsage4009Command(CreateRelationshipRequest req) {
445
			super(req);
446
		}
447
448
		/**
449
		 * @generated
450
		 */
451
		protected EClass getEClassToEdit() {
452
			return UMLPackage.eINSTANCE.getPackage();
453
		};
454
455
		/**
456
		 * @generated
457
		 */
458
		protected void setElementToEdit(EObject element) {
459
			throw new UnsupportedOperationException();
460
		}
461
462
		/**
463
		 * @generated
464
		 */
465
		protected EObject doDefaultElementCreation() {
466
			Usage newElement = (Usage) super.doDefaultElementCreation();
467
			if (newElement != null) {
468
				newElement.getSuppliers().add((NamedElement) getTarget());
469
				newElement.getClients().add((NamedElement) getSource());
470
			}
471
			return newElement;
472
		}
473
	}
474
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/policies/Dependency2ItemSemanticEditPolicy.java (+18 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.policies;
2
3
import org.eclipse.gef.commands.Command;
4
import org.eclipse.gmf.runtime.emf.type.core.commands.DestroyElementCommand;
5
import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest;
6
7
/**
8
 * @generated
9
 */
10
public class Dependency2ItemSemanticEditPolicy extends UMLBaseItemSemanticEditPolicy {
11
12
	/**
13
	 * @generated
14
	 */
15
	protected Command getDestroyElementCommand(DestroyElementRequest req) {
16
		return getMSLWrapper(new DestroyElementCommand(req));
17
	}
18
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/parts/UMLExtNodeLabelEditPart.java (+85 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.parts;
2
3
import org.eclipse.draw2d.IFigure;
4
import org.eclipse.draw2d.geometry.Dimension;
5
import org.eclipse.draw2d.geometry.Point;
6
import org.eclipse.gef.EditPolicy;
7
import org.eclipse.gef.GraphicalEditPart;
8
import org.eclipse.gef.Handle;
9
import org.eclipse.gef.handles.AbstractHandle;
10
import org.eclipse.gmf.runtime.diagram.ui.editparts.LabelEditPart;
11
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.NonResizableLabelEditPolicy;
12
import org.eclipse.gmf.runtime.diagram.ui.figures.LabelLocator;
13
import org.eclipse.gmf.runtime.diagram.ui.tools.DragEditPartsTrackerEx;
14
import org.eclipse.gmf.runtime.notation.NotationPackage;
15
import org.eclipse.gmf.runtime.notation.View;
16
17
/**
18
 * @generated
19
 */
20
public class UMLExtNodeLabelEditPart extends LabelEditPart {
21
22
	/**
23
	 * @generated
24
	 */
25
	public UMLExtNodeLabelEditPart(View view) {
26
		super(view);
27
	}
28
29
	/**
30
	 * @generated
31
	 */
32
	protected void createDefaultEditPolicies() {
33
		super.createDefaultEditPolicies();
34
		installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new NonResizableLabelEditPolicy() {
35
36
			protected void replaceHandleDragEditPartsTracker(Handle handle) {
37
				if (handle instanceof AbstractHandle) {
38
					((AbstractHandle) handle).setDragTracker(new DragEditPartsTrackerEx(getHost()) {
39
40
						protected boolean isMove() {
41
							return true;
42
						}
43
					});
44
				}
45
			}
46
		});
47
	}
48
49
	/**
50
	 * @generated
51
	 */
52
	public void refreshBounds() {
53
		IFigure refFigure = ((GraphicalEditPart) getParent()).getFigure();
54
		int dx = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_X())).intValue();
55
		int dy = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_Y())).intValue();
56
		Point offset = new Point(dx, dy);
57
		getFigure().getParent().setConstraint(getFigure(), new LabelLocator(refFigure, offset, getKeyPoint()) {
58
59
			public void relocate(IFigure target) {
60
				Point location = getReferencePoint().getTranslated(getOffset());
61
				location.translate(-target.getBounds().width / 2, 0);
62
				target.setLocation(location);
63
				target.setSize(new Dimension(target.getPreferredSize().width, target.getPreferredSize().height));
64
			}
65
66
			protected Point getReferencePoint() {
67
				return getLabelLocation(parent);
68
			}
69
		});
70
	}
71
72
	/**
73
	 * @generated
74
	 */
75
	public Point getReferencePoint() {
76
		return getLabelLocation(((GraphicalEditPart) getParent()).getFigure());
77
	}
78
79
	/**
80
	 * @generated
81
	 */
82
	protected Point getLabelLocation(IFigure parent) {
83
		return parent.getBounds().getBottom();
84
	}
85
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/policies/PortItemSemanticEditPolicy.java (+255 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.policies;
2
3
import org.eclipse.emf.ecore.EAnnotation;
4
import org.eclipse.emf.ecore.EClass;
5
import org.eclipse.emf.ecore.EObject;
6
import org.eclipse.gef.commands.Command;
7
import org.eclipse.gef.commands.UnexecutableCommand;
8
import org.eclipse.gmf.runtime.emf.type.core.commands.CreateRelationshipCommand;
9
import org.eclipse.gmf.runtime.emf.type.core.commands.DestroyElementCommand;
10
import org.eclipse.gmf.runtime.emf.type.core.commands.SetValueCommand;
11
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest;
12
import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest;
13
import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest;
14
import org.eclipse.gmf.runtime.notation.View;
15
import org.eclipse.uml2.diagram.clazz.providers.UMLElementTypes;
16
import org.eclipse.uml2.uml.Constraint;
17
import org.eclipse.uml2.uml.Dependency;
18
import org.eclipse.uml2.uml.NamedElement;
19
import org.eclipse.uml2.uml.UMLPackage;
20
import org.eclipse.uml2.uml.Usage;
21
22
/**
23
 * @generated
24
 */
25
public class PortItemSemanticEditPolicy extends UMLBaseItemSemanticEditPolicy {
26
27
	/**
28
	 * @generated
29
	 */
30
	protected Command getDestroyElementCommand(DestroyElementRequest req) {
31
		return getMSLWrapper(new DestroyElementCommand(req) {
32
33
			protected EObject getElementToDestroy() {
34
				View view = (View) getHost().getModel();
35
				EAnnotation annotation = view.getEAnnotation("Shortcut"); //$NON-NLS-1$
36
				if (annotation != null) {
37
					return view;
38
				}
39
				return super.getElementToDestroy();
40
			}
41
42
		});
43
	}
44
45
	/**
46
	 * @generated
47
	 */
48
	protected Command getCreateRelationshipCommand(CreateRelationshipRequest req) {
49
		if (UMLElementTypes.Dependency_4002 == req.getElementType()) {
50
			return req.getTarget() == null ? getCreateStartOutgoingDependency4002Command(req) : getCreateCompleteIncomingDependency4002Command(req);
51
		}
52
		if (UMLElementTypes.ConstraintConstrainedElement_4004 == req.getElementType()) {
53
			return req.getTarget() == null ? null : getCreateCompleteIncomingConstraint_ConstrainedElement4004Command(req);
54
		}
55
		if (UMLElementTypes.DependencySupplier_4006 == req.getElementType()) {
56
			return req.getTarget() == null ? null : getCreateCompleteIncomingDependency_Supplier4006Command(req);
57
		}
58
		if (UMLElementTypes.DependencyClient_4007 == req.getElementType()) {
59
			return req.getTarget() == null ? null : getCreateCompleteIncomingDependency_Client4007Command(req);
60
		}
61
		if (UMLElementTypes.Usage_4009 == req.getElementType()) {
62
			return req.getTarget() == null ? getCreateStartOutgoingUsage4009Command(req) : getCreateCompleteIncomingUsage4009Command(req);
63
		}
64
		return super.getCreateRelationshipCommand(req);
65
	}
66
67
	/**
68
	 * @generated
69
	 */
70
	protected Command getCreateStartOutgoingDependency4002Command(CreateRelationshipRequest req) {
71
		return new Command() {
72
		};
73
	}
74
75
	/**
76
	 * @generated
77
	 */
78
	protected Command getCreateCompleteIncomingDependency4002Command(CreateRelationshipRequest req) {
79
		if (!(req.getSource() instanceof NamedElement)) {
80
			return UnexecutableCommand.INSTANCE;
81
		}
82
		final org.eclipse.uml2.uml.Package element = (org.eclipse.uml2.uml.Package) getRelationshipContainer(req.getSource(), UMLPackage.eINSTANCE.getPackage(), req.getElementType());
83
		if (element == null) {
84
			return UnexecutableCommand.INSTANCE;
85
		}
86
		if (req.getContainmentFeature() == null) {
87
			req.setContainmentFeature(UMLPackage.eINSTANCE.getPackage_PackagedElement());
88
		}
89
		return getMSLWrapper(new CreateIncomingDependency4002Command(req) {
90
91
			protected EObject getElementToEdit() {
92
				return element;
93
			}
94
		});
95
	}
96
97
	/**
98
	 * @generated
99
	 */
100
	private static class CreateIncomingDependency4002Command extends CreateRelationshipCommand {
101
102
		/**
103
		 * @generated
104
		 */
105
		public CreateIncomingDependency4002Command(CreateRelationshipRequest req) {
106
			super(req);
107
		}
108
109
		/**
110
		 * @generated
111
		 */
112
		protected EClass getEClassToEdit() {
113
			return UMLPackage.eINSTANCE.getPackage();
114
		};
115
116
		/**
117
		 * @generated
118
		 */
119
		protected void setElementToEdit(EObject element) {
120
			throw new UnsupportedOperationException();
121
		}
122
123
		/**
124
		 * @generated
125
		 */
126
		protected EObject doDefaultElementCreation() {
127
			Dependency newElement = (Dependency) super.doDefaultElementCreation();
128
			if (newElement != null) {
129
				newElement.getSuppliers().add((NamedElement) getTarget());
130
				newElement.getClients().add((NamedElement) getSource());
131
			}
132
			return newElement;
133
		}
134
	}
135
136
	/**
137
	 * @generated
138
	 */
139
	protected Command getCreateCompleteIncomingConstraint_ConstrainedElement4004Command(CreateRelationshipRequest req) {
140
		if (!(req.getSource() instanceof Constraint)) {
141
			return UnexecutableCommand.INSTANCE;
142
		}
143
		Constraint element = (Constraint) req.getSource();
144
		if (element.getConstrainedElements().contains(req.getTarget())) {
145
			return UnexecutableCommand.INSTANCE;
146
		}
147
		SetRequest setReq = new SetRequest(req.getSource(), UMLPackage.eINSTANCE.getConstraint_ConstrainedElement(), req.getTarget());
148
		return getMSLWrapper(new SetValueCommand(setReq));
149
	}
150
151
	/**
152
	 * @generated
153
	 */
154
	protected Command getCreateCompleteIncomingDependency_Supplier4006Command(CreateRelationshipRequest req) {
155
		if (!(req.getSource() instanceof Dependency)) {
156
			return UnexecutableCommand.INSTANCE;
157
		}
158
		Dependency element = (Dependency) req.getSource();
159
		if (element.getSuppliers().contains(req.getTarget())) {
160
			return UnexecutableCommand.INSTANCE;
161
		}
162
		SetRequest setReq = new SetRequest(req.getSource(), UMLPackage.eINSTANCE.getDependency_Supplier(), req.getTarget());
163
		return getMSLWrapper(new SetValueCommand(setReq));
164
	}
165
166
	/**
167
	 * @generated
168
	 */
169
	protected Command getCreateCompleteIncomingDependency_Client4007Command(CreateRelationshipRequest req) {
170
		if (!(req.getSource() instanceof Dependency)) {
171
			return UnexecutableCommand.INSTANCE;
172
		}
173
		Dependency element = (Dependency) req.getSource();
174
		if (element.getClients().contains(req.getTarget())) {
175
			return UnexecutableCommand.INSTANCE;
176
		}
177
		SetRequest setReq = new SetRequest(req.getSource(), UMLPackage.eINSTANCE.getDependency_Client(), req.getTarget());
178
		return getMSLWrapper(new SetValueCommand(setReq));
179
	}
180
181
	/**
182
	 * @generated
183
	 */
184
	protected Command getCreateStartOutgoingUsage4009Command(CreateRelationshipRequest req) {
185
		if (!UMLBaseItemSemanticEditPolicy.LinkConstraints.Usage_4009.canCreateLink(req, false)) {
186
			return UnexecutableCommand.INSTANCE;
187
		}
188
		return new Command() {
189
		};
190
	}
191
192
	/**
193
	 * @generated
194
	 */
195
	protected Command getCreateCompleteIncomingUsage4009Command(CreateRelationshipRequest req) {
196
		if (!(req.getSource() instanceof NamedElement)) {
197
			return UnexecutableCommand.INSTANCE;
198
		}
199
		final org.eclipse.uml2.uml.Package element = (org.eclipse.uml2.uml.Package) getRelationshipContainer(req.getSource(), UMLPackage.eINSTANCE.getPackage(), req.getElementType());
200
		if (element == null) {
201
			return UnexecutableCommand.INSTANCE;
202
		}
203
		if (!UMLBaseItemSemanticEditPolicy.LinkConstraints.Usage_4009.canCreateLink(req, false)) {
204
			return UnexecutableCommand.INSTANCE;
205
		}
206
		if (req.getContainmentFeature() == null) {
207
			req.setContainmentFeature(UMLPackage.eINSTANCE.getPackage_PackagedElement());
208
		}
209
		return getMSLWrapper(new CreateIncomingUsage4009Command(req) {
210
211
			protected EObject getElementToEdit() {
212
				return element;
213
			}
214
		});
215
	}
216
217
	/**
218
	 * @generated
219
	 */
220
	private static class CreateIncomingUsage4009Command extends CreateRelationshipCommand {
221
222
		/**
223
		 * @generated
224
		 */
225
		public CreateIncomingUsage4009Command(CreateRelationshipRequest req) {
226
			super(req);
227
		}
228
229
		/**
230
		 * @generated
231
		 */
232
		protected EClass getEClassToEdit() {
233
			return UMLPackage.eINSTANCE.getPackage();
234
		};
235
236
		/**
237
		 * @generated
238
		 */
239
		protected void setElementToEdit(EObject element) {
240
			throw new UnsupportedOperationException();
241
		}
242
243
		/**
244
		 * @generated
245
		 */
246
		protected EObject doDefaultElementCreation() {
247
			Usage newElement = (Usage) super.doDefaultElementCreation();
248
			if (newElement != null) {
249
				newElement.getSuppliers().add((NamedElement) getTarget());
250
				newElement.getClients().add((NamedElement) getSource());
251
			}
252
			return newElement;
253
		}
254
	}
255
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/policies/UMLReferenceConnectionEditPolicy.java (+150 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.policies;
2
3
import org.eclipse.emf.transaction.TransactionalEditingDomain;
4
import org.eclipse.gef.EditPart;
5
import org.eclipse.gef.Request;
6
import org.eclipse.gef.commands.Command;
7
import org.eclipse.gef.commands.CompoundCommand;
8
import org.eclipse.gef.commands.UnexecutableCommand;
9
import org.eclipse.gef.editparts.AbstractConnectionEditPart;
10
import org.eclipse.gef.editpolicies.ConnectionEditPolicy;
11
import org.eclipse.gef.requests.GroupRequest;
12
import org.eclipse.gmf.runtime.diagram.core.commands.DeleteCommand;
13
import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
14
import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart;
15
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
16
import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramUIMessages;
17
import org.eclipse.gmf.runtime.diagram.ui.preferences.IPreferenceConstants;
18
import org.eclipse.gmf.runtime.diagram.ui.requests.EditCommandRequestWrapper;
19
import org.eclipse.gmf.runtime.diagram.ui.requests.GroupRequestViaKeyboard;
20
import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest;
21
import org.eclipse.gmf.runtime.notation.View;
22
import org.eclipse.jface.dialogs.IDialogConstants;
23
import org.eclipse.jface.dialogs.MessageDialogWithToggle;
24
import org.eclipse.jface.preference.IPreferenceStore;
25
import org.eclipse.jface.util.Assert;
26
import org.eclipse.swt.widgets.Display;
27
28
/**
29
 * @generated
30
 */
31
public class UMLReferenceConnectionEditPolicy extends ConnectionEditPolicy {
32
33
	/**
34
	 * @generated
35
	 */
36
	private static final String DELETE_FROM_DIAGRAM_DLG_TITLE = DiagramUIMessages.PromptingDeleteAction_DeleteFromDiagramDialog_Title;
37
38
	/**
39
	 * @generated
40
	 */
41
	private static final String DELETE_FROM_DIAGRAM_DLG_MESSAGE = DiagramUIMessages.PromptingDeleteAction_DeleteFromDiagramDialog_Message;
42
43
	/**
44
	 * @generated
45
	 */
46
	private static final String DELETE_FROM_MODEL_DLG_TOGGLE_LABEL = DiagramUIMessages.MessageDialogWithToggle_DoNotPromptAgainToggle_label;
47
48
	/**
49
	 * @generated
50
	 */
51
	protected final Command getDeleteCommand(GroupRequest deleteRequest) {
52
		boolean isDeleteFromKeyBoard = deleteRequest instanceof GroupRequestViaKeyboard;
53
		if (shouldDeleteSemantic()) {
54
			return createDeleteSemanticCommand(deleteRequest);
55
		} else {
56
			boolean proceedToDeleteView = true;
57
			if (isDeleteFromKeyBoard) {
58
				GroupRequestViaKeyboard groupRequestViaKeyboard = (GroupRequestViaKeyboard) deleteRequest;
59
				if (groupRequestViaKeyboard.isShowInformationDialog()) {
60
					proceedToDeleteView = showPrompt();
61
					groupRequestViaKeyboard.setShowInformationDialog(false);
62
					if (!(proceedToDeleteView))
63
						return UnexecutableCommand.INSTANCE;
64
				}
65
			}
66
			return createDeleteViewCommand(deleteRequest);
67
		}
68
	}
69
70
	/**
71
	 * @generated
72
	 */
73
	protected boolean shouldDeleteSemantic() {
74
		Assert.isTrue(getHost() instanceof AbstractConnectionEditPart);
75
		AbstractConnectionEditPart cep = (AbstractConnectionEditPart) getHost();
76
		boolean isCanonical = false;
77
		if (cep.getSource() != null)
78
			isCanonical = IsCanonical(cep.getSource());
79
		if (cep.getTarget() != null)
80
			return isCanonical ? isCanonical : IsCanonical(cep.getTarget());
81
		return isCanonical;
82
	}
83
84
	/**
85
	 * @generated
86
	 */
87
	private boolean IsCanonical(EditPart ep) {
88
		EditPart parent = ep.getParent();
89
		return parent instanceof GraphicalEditPart ? ((GraphicalEditPart) parent).isCanonical() : false;
90
	}
91
92
	/**
93
	 * @generated
94
	 */
95
	protected Command createDeleteViewCommand(GroupRequest deleteRequest) {
96
		TransactionalEditingDomain editingDomain = ((IGraphicalEditPart) getHost()).getEditingDomain();
97
		return new ICommandProxy(new DeleteCommand(editingDomain, (View) getHost().getModel()));
98
	}
99
100
	/**
101
	 * @generated
102
	 */
103
	protected Command createDeleteSemanticCommand(GroupRequest deleteRequest) {
104
		TransactionalEditingDomain editingDomain = ((IGraphicalEditPart) getHost()).getEditingDomain();
105
		EditCommandRequestWrapper semReq = new EditCommandRequestWrapper(new DestroyElementRequest(editingDomain, false), deleteRequest.getExtendedData());
106
		Command semanticCmd = getHost().getCommand(semReq);
107
		if (semanticCmd != null && semanticCmd.canExecute()) {
108
			CompoundCommand cc = new CompoundCommand();
109
			cc.add(semanticCmd);
110
			return cc;
111
		}
112
		return null;
113
	}
114
115
	/**
116
	 * @generated
117
	 */
118
	private boolean showPrompt() {
119
		boolean prompt = ((IPreferenceStore) ((IGraphicalEditPart) getHost()).getDiagramPreferencesHint().getPreferenceStore()).getBoolean(IPreferenceConstants.PREF_PROMPT_ON_DEL_FROM_DIAGRAM);
120
		if (prompt)
121
			if (showMessageDialog())
122
				return true;
123
			else
124
				return false;
125
		return true;
126
	}
127
128
	/**
129
	 * @generated
130
	 */
131
	private boolean showMessageDialog() {
132
		MessageDialogWithToggle dialog = MessageDialogWithToggle.openYesNoQuestion(Display.getCurrent().getActiveShell(), DELETE_FROM_DIAGRAM_DLG_TITLE, DELETE_FROM_DIAGRAM_DLG_MESSAGE,
133
				DELETE_FROM_MODEL_DLG_TOGGLE_LABEL, false, (IPreferenceStore) ((IGraphicalEditPart) getHost()).getDiagramPreferencesHint().getPreferenceStore(),
134
				IPreferenceConstants.PREF_PROMPT_ON_DEL_FROM_DIAGRAM);
135
		if (dialog.getReturnCode() == IDialogConstants.YES_ID)
136
			return true;
137
		else
138
			return false;
139
	}
140
141
	/**
142
	 * @generated
143
	 */
144
	public Command getCommand(Request request) {
145
		if (request instanceof GroupRequestViaKeyboard) {
146
			return getDeleteCommand((GroupRequest) request);
147
		}
148
		return super.getCommand(request);
149
	}
150
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/parts/PrimitiveTypeAttributesEditPart.java (+67 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.parts;
2
3
import org.eclipse.emf.common.notify.Notification;
4
import org.eclipse.gef.EditPolicy;
5
import org.eclipse.gmf.runtime.diagram.ui.editparts.ListCompartmentEditPart;
6
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.CreationEditPolicy;
7
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.DragDropEditPolicy;
8
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
9
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.ResizableCompartmentEditPolicy;
10
import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout;
11
import org.eclipse.gmf.runtime.notation.View;
12
import org.eclipse.uml2.diagram.clazz.edit.policies.PrimitiveTypeAttributesCanonicalEditPolicy;
13
import org.eclipse.uml2.diagram.clazz.edit.policies.PrimitiveTypeAttributesItemSemanticEditPolicy;
14
15
/**
16
 * @generated
17
 */
18
public class PrimitiveTypeAttributesEditPart extends ListCompartmentEditPart {
19
20
	/**
21
	 * @generated
22
	 */
23
	public static final int VISUAL_ID = 7020;
24
25
	/**
26
	 * @generated
27
	 */
28
	public PrimitiveTypeAttributesEditPart(View view) {
29
		super(view);
30
	}
31
32
	/**
33
	 * @generated
34
	 */
35
	protected boolean hasModelChildrenChanged(Notification evt) {
36
		return false;
37
	}
38
39
	/**
40
	 * @generated
41
	 */
42
	public String getCompartmentName() {
43
		return "attributes";
44
	}
45
46
	/**
47
	 * @generated
48
	 */
49
	protected void createDefaultEditPolicies() {
50
		super.createDefaultEditPolicies();
51
		installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ResizableCompartmentEditPolicy());
52
		installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new PrimitiveTypeAttributesItemSemanticEditPolicy());
53
		installEditPolicy(EditPolicyRoles.CREATION_ROLE, new CreationEditPolicy());
54
		installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, new DragDropEditPolicy());
55
		installEditPolicy(EditPolicyRoles.CANONICAL_ROLE, new PrimitiveTypeAttributesCanonicalEditPolicy());
56
57
	}
58
59
	/**
60
	 * @generated
61
	 */
62
	protected void setRatio(Double ratio) {
63
		if (getFigure().getParent().getLayoutManager() instanceof ConstrainedToolbarLayout) {
64
			super.setRatio(ratio);
65
		}
66
	}
67
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/policies/InstanceSpecificationSlotsItemSemanticEditPolicy.java (+61 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.policies;
2
3
import org.eclipse.emf.ecore.EClass;
4
import org.eclipse.emf.ecore.EObject;
5
import org.eclipse.gef.commands.Command;
6
import org.eclipse.gmf.runtime.emf.type.core.commands.CreateElementCommand;
7
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest;
8
import org.eclipse.gmf.runtime.notation.View;
9
import org.eclipse.uml2.diagram.clazz.providers.UMLElementTypes;
10
import org.eclipse.uml2.uml.UMLPackage;
11
12
/**
13
 * @generated
14
 */
15
public class InstanceSpecificationSlotsItemSemanticEditPolicy extends UMLBaseItemSemanticEditPolicy {
16
17
	/**
18
	 * @generated
19
	 */
20
	protected Command getCreateCommand(CreateElementRequest req) {
21
		if (UMLElementTypes.Slot_3017 == req.getElementType()) {
22
			if (req.getContainmentFeature() == null) {
23
				req.setContainmentFeature(UMLPackage.eINSTANCE.getInstanceSpecification_Slot());
24
			}
25
			return getMSLWrapper(new CreateSlot_3017Command(req));
26
		}
27
		return super.getCreateCommand(req);
28
	}
29
30
	/**
31
	 * @generated
32
	 */
33
	private static class CreateSlot_3017Command extends CreateElementCommand {
34
35
		/**
36
		 * @generated
37
		 */
38
		public CreateSlot_3017Command(CreateElementRequest req) {
39
			super(req);
40
		}
41
42
		/**
43
		 * @generated
44
		 */
45
		protected EClass getEClassToEdit() {
46
			return UMLPackage.eINSTANCE.getInstanceSpecification();
47
		};
48
49
		/**
50
		 * @generated
51
		 */
52
		protected EObject getElementToEdit() {
53
			EObject container = ((CreateElementRequest) getRequest()).getContainer();
54
			if (container instanceof View) {
55
				container = ((View) container).getElement();
56
			}
57
			return container;
58
		}
59
	}
60
61
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/parts/EnumerationLiteralEditPart.java (+553 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.parts;
2
3
import java.util.Collections;
4
import java.util.List;
5
6
import org.eclipse.draw2d.IFigure;
7
import org.eclipse.draw2d.Label;
8
import org.eclipse.draw2d.geometry.Point;
9
import org.eclipse.emf.common.notify.Notification;
10
import org.eclipse.emf.ecore.EObject;
11
import org.eclipse.emf.transaction.RunnableWithResult;
12
import org.eclipse.gef.AccessibleEditPart;
13
import org.eclipse.gef.DragTracker;
14
import org.eclipse.gef.EditPolicy;
15
import org.eclipse.gef.Request;
16
import org.eclipse.gef.requests.DirectEditRequest;
17
import org.eclipse.gef.requests.SelectionRequest;
18
import org.eclipse.gef.tools.DirectEditManager;
19
import org.eclipse.gmf.runtime.common.ui.services.parser.IParser;
20
import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus;
21
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserEditStatus;
22
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions;
23
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserService;
24
import org.eclipse.gmf.runtime.diagram.ui.editparts.CompartmentEditPart;
25
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
26
import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart;
27
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
28
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy;
29
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.ListItemComponentEditPolicy;
30
import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry;
31
import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants;
32
import org.eclipse.gmf.runtime.diagram.ui.tools.DragEditPartsTrackerEx;
33
import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager;
34
import org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel;
35
import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
36
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
37
import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser;
38
import org.eclipse.gmf.runtime.emf.ui.services.parser.ParserHintAdapter;
39
import org.eclipse.gmf.runtime.notation.FontStyle;
40
import org.eclipse.gmf.runtime.notation.NotationPackage;
41
import org.eclipse.gmf.runtime.notation.View;
42
import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
43
import org.eclipse.jface.viewers.ICellEditorValidator;
44
import org.eclipse.swt.SWT;
45
import org.eclipse.swt.accessibility.AccessibleEvent;
46
import org.eclipse.swt.graphics.Color;
47
import org.eclipse.swt.graphics.FontData;
48
import org.eclipse.swt.graphics.Image;
49
import org.eclipse.uml2.diagram.clazz.edit.policies.EnumerationLiteralItemSemanticEditPolicy;
50
import org.eclipse.uml2.diagram.clazz.edit.policies.UMLTextNonResizableEditPolicy;
51
import org.eclipse.uml2.diagram.clazz.edit.policies.UMLTextSelectionEditPolicy;
52
import org.eclipse.uml2.diagram.clazz.providers.UMLElementTypes;
53
54
/**
55
 * @generated
56
 */
57
public class EnumerationLiteralEditPart extends CompartmentEditPart implements ITextAwareEditPart {
58
59
	/**
60
	 * @generated
61
	 */
62
	public static final int VISUAL_ID = 3016;
63
64
	/**
65
	 * @generated
66
	 */
67
	private DirectEditManager manager;
68
69
	/**
70
	 * @generated
71
	 */
72
	private IParser parser;
73
74
	/**
75
	 * @generated
76
	 */
77
	private List parserElements;
78
79
	/**
80
	 * @generated
81
	 */
82
	private String defaultText;
83
84
	/**
85
	 * @generated
86
	 */
87
	public EnumerationLiteralEditPart(View view) {
88
		super(view);
89
	}
90
91
	/**
92
	 * @generated
93
	 */
94
	public DragTracker getDragTracker(Request request) {
95
		if (request instanceof SelectionRequest && ((SelectionRequest) request).getLastButtonPressed() == 3) {
96
			return null;
97
		}
98
		return new DragEditPartsTrackerEx(this);
99
	}
100
101
	/**
102
	 * @generated
103
	 */
104
	protected void createDefaultEditPolicies() {
105
		super.createDefaultEditPolicies();
106
		installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new EnumerationLiteralItemSemanticEditPolicy());
107
		installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new UMLTextNonResizableEditPolicy());
108
		installEditPolicy(EditPolicy.COMPONENT_ROLE, new ListItemComponentEditPolicy());
109
		installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy());
110
111
	}
112
113
	/**
114
	 * @generated
115
	 */
116
	protected String getLabelTextHelper(IFigure figure) {
117
		if (figure instanceof WrapLabel) {
118
			return ((WrapLabel) figure).getText();
119
		} else {
120
			return ((Label) figure).getText();
121
		}
122
	}
123
124
	/**
125
	 * @generated
126
	 */
127
	protected void setLabelTextHelper(IFigure figure, String text) {
128
		if (figure instanceof WrapLabel) {
129
			((WrapLabel) figure).setText(text);
130
		} else {
131
			((Label) figure).setText(text);
132
		}
133
	}
134
135
	/**
136
	 * @generated
137
	 */
138
	protected Image getLabelIconHelper(IFigure figure) {
139
		if (figure instanceof WrapLabel) {
140
			return ((WrapLabel) figure).getIcon();
141
		} else {
142
			return ((Label) figure).getIcon();
143
		}
144
	}
145
146
	/**
147
	 * @generated
148
	 */
149
	protected void setLabelIconHelper(IFigure figure, Image icon) {
150
		if (figure instanceof WrapLabel) {
151
			((WrapLabel) figure).setIcon(icon);
152
		} else {
153
			((Label) figure).setIcon(icon);
154
		}
155
	}
156
157
	/**
158
	 * @generated
159
	 */
160
	public void setLabel(IFigure figure) {
161
		unregisterVisuals();
162
		setFigure(figure);
163
		defaultText = getLabelTextHelper(figure);
164
		registerVisuals();
165
		refreshVisuals();
166
	}
167
168
	/**
169
	 * @generated
170
	 */
171
	protected List getModelChildren() {
172
		return Collections.EMPTY_LIST;
173
	}
174
175
	/**
176
	 * @generated
177
	 */
178
	public IGraphicalEditPart getChildBySemanticHint(String semanticHint) {
179
		return null;
180
	}
181
182
	/**
183
	 * @generated
184
	 */
185
	protected EObject getParserElement() {
186
		EObject element = resolveSemanticElement();
187
		return element != null ? element : (View) getModel();
188
	}
189
190
	/**
191
	 * @generated
192
	 */
193
	protected Image getLabelIcon() {
194
		return null;
195
	}
196
197
	/**
198
	 * @generated
199
	 */
200
	protected String getLabelText() {
201
		String text = null;
202
		if (getParser() != null) {
203
			text = getParser().getPrintString(new EObjectAdapter(getParserElement()), getParserOptions().intValue());
204
		}
205
		if (text == null || text.length() == 0) {
206
			text = defaultText;
207
		}
208
		return text;
209
	}
210
211
	/**
212
	 * @generated
213
	 */
214
	public void setLabelText(String text) {
215
		setLabelTextHelper(getFigure(), text);
216
		Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
217
		if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) {
218
			((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback();
219
		}
220
	}
221
222
	/**
223
	 * @generated
224
	 */
225
	public String getEditText() {
226
		if (getParser() == null) {
227
			return ""; //$NON-NLS-1$
228
		}
229
		return getParser().getEditString(new EObjectAdapter(getParserElement()), getParserOptions().intValue());
230
	}
231
232
	/**
233
	 * @generated
234
	 */
235
	protected boolean isEditable() {
236
		return getEditText() != null;
237
	}
238
239
	/**
240
	 * @generated
241
	 */
242
	public ICellEditorValidator getEditTextValidator() {
243
		return new ICellEditorValidator() {
244
245
			public String isValid(final Object value) {
246
				if (value instanceof String) {
247
					final EObject element = getParserElement();
248
					final IParser parser = getParser();
249
					try {
250
						IParserEditStatus valid = (IParserEditStatus) getEditingDomain().runExclusive(new RunnableWithResult.Impl() {
251
252
							public void run() {
253
								setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value));
254
							}
255
						});
256
						return valid.getCode() == ParserEditStatus.EDITABLE ? null : valid.getMessage();
257
					} catch (InterruptedException ie) {
258
						ie.printStackTrace();
259
					}
260
				}
261
262
				// shouldn't get here
263
				return null;
264
			}
265
		};
266
	}
267
268
	/**
269
	 * @generated
270
	 */
271
	public IContentAssistProcessor getCompletionProcessor() {
272
		if (getParser() == null) {
273
			return null;
274
		}
275
		return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement()));
276
	}
277
278
	/**
279
	 * @generated
280
	 */
281
	public ParserOptions getParserOptions() {
282
		return ParserOptions.NONE;
283
	}
284
285
	/**
286
	 * @generated
287
	 */
288
	public IParser getParser() {
289
		if (parser == null) {
290
			String parserHint = ((View) getModel()).getType();
291
			ParserHintAdapter hintAdapter = new ParserHintAdapter(getParserElement(), parserHint) {
292
293
				public Object getAdapter(Class adapter) {
294
					if (IElementType.class.equals(adapter)) {
295
						return UMLElementTypes.EnumerationLiteral_3016;
296
					}
297
					return super.getAdapter(adapter);
298
				}
299
			};
300
			parser = ParserService.getInstance().getParser(hintAdapter);
301
		}
302
		return parser;
303
	}
304
305
	/**
306
	 * @generated
307
	 */
308
	protected DirectEditManager getManager() {
309
		if (manager == null) {
310
			setManager(new TextDirectEditManager(this, TextDirectEditManager.getTextCellEditorClass(this), UMLEditPartFactory.getTextCellEditorLocator(this)));
311
		}
312
		return manager;
313
	}
314
315
	/**
316
	 * @generated
317
	 */
318
	protected void setManager(DirectEditManager manager) {
319
		this.manager = manager;
320
	}
321
322
	/**
323
	 * @generated
324
	 */
325
	protected void performDirectEdit() {
326
		getManager().show();
327
	}
328
329
	/**
330
	 * @generated
331
	 */
332
	protected void performDirectEdit(Point eventLocation) {
333
		if (getManager().getClass() == TextDirectEditManager.class) {
334
			((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint());
335
		}
336
	}
337
338
	/**
339
	 * @generated
340
	 */
341
	private void performDirectEdit(char initialCharacter) {
342
		if (getManager() instanceof TextDirectEditManager) {
343
			((TextDirectEditManager) getManager()).show(initialCharacter);
344
		} else {
345
			performDirectEdit();
346
		}
347
	}
348
349
	/**
350
	 * @generated
351
	 */
352
	protected void performDirectEditRequest(Request request) {
353
		final Request theRequest = request;
354
		try {
355
			getEditingDomain().runExclusive(new Runnable() {
356
357
				public void run() {
358
					if (isActive() && isEditable()) {
359
						if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) {
360
							Character initialChar = (Character) theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR);
361
							performDirectEdit(initialChar.charValue());
362
						} else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) {
363
							DirectEditRequest editRequest = (DirectEditRequest) theRequest;
364
							performDirectEdit(editRequest.getLocation());
365
						} else {
366
							performDirectEdit();
367
						}
368
					}
369
				}
370
			});
371
		} catch (InterruptedException e) {
372
			e.printStackTrace();
373
		}
374
	}
375
376
	/**
377
	 * @generated
378
	 */
379
	protected void refreshVisuals() {
380
		super.refreshVisuals();
381
		refreshLabel();
382
		refreshFont();
383
		refreshFontColor();
384
		refreshUnderline();
385
		refreshStrikeThrough();
386
	}
387
388
	/**
389
	 * @generated
390
	 */
391
	protected void refreshLabel() {
392
		setLabelTextHelper(getFigure(), getLabelText());
393
		setLabelIconHelper(getFigure(), getLabelIcon());
394
		Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
395
		if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) {
396
			((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback();
397
		}
398
	}
399
400
	/**
401
	 * @generated
402
	 */
403
	protected void refreshUnderline() {
404
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
405
		if (style != null && getFigure() instanceof WrapLabel) {
406
			((WrapLabel) getFigure()).setTextUnderline(style.isUnderline());
407
		}
408
	}
409
410
	/**
411
	 * @generated
412
	 */
413
	protected void refreshStrikeThrough() {
414
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
415
		if (style != null && getFigure() instanceof WrapLabel) {
416
			((WrapLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough());
417
		}
418
	}
419
420
	/**
421
	 * @generated
422
	 */
423
	protected void refreshFont() {
424
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
425
		if (style != null) {
426
			FontData fontData = new FontData(style.getFontName(), style.getFontHeight(), (style.isBold() ? SWT.BOLD : SWT.NORMAL) | (style.isItalic() ? SWT.ITALIC : SWT.NORMAL));
427
			setFont(fontData);
428
		}
429
	}
430
431
	/**
432
	 * @generated
433
	 */
434
	protected void setFontColor(Color color) {
435
		getFigure().setForegroundColor(color);
436
	}
437
438
	/**
439
	 * @generated
440
	 */
441
	protected void addSemanticListeners() {
442
		if (getParser() instanceof ISemanticParser) {
443
			EObject element = resolveSemanticElement();
444
			parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element);
445
			for (int i = 0; i < parserElements.size(); i++) {
446
				addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$
447
			}
448
		} else {
449
			super.addSemanticListeners();
450
		}
451
	}
452
453
	/**
454
	 * @generated
455
	 */
456
	protected void removeSemanticListeners() {
457
		if (parserElements != null) {
458
			for (int i = 0; i < parserElements.size(); i++) {
459
				removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$
460
			}
461
		} else {
462
			super.removeSemanticListeners();
463
		}
464
	}
465
466
	/**
467
	 * @generated
468
	 */
469
	protected AccessibleEditPart getAccessibleEditPart() {
470
		if (accessibleEP == null) {
471
			accessibleEP = new AccessibleGraphicalEditPart() {
472
473
				public void getName(AccessibleEvent e) {
474
					e.result = getLabelTextHelper(getFigure());
475
				}
476
			};
477
		}
478
		return accessibleEP;
479
	}
480
481
	/**
482
	 * @generated
483
	 */
484
	private View getFontStyleOwnerView() {
485
		return getPrimaryView();
486
	}
487
488
	/**
489
	 * @generated
490
	 */
491
	protected void addNotationalListeners() {
492
		super.addNotationalListeners();
493
		addListenerFilter("PrimaryView", this, getPrimaryView()); //$NON-NLS-1$
494
	}
495
496
	/**
497
	 * @generated
498
	 */
499
	protected void removeNotationalListeners() {
500
		super.removeNotationalListeners();
501
		removeListenerFilter("PrimaryView"); //$NON-NLS-1$
502
	}
503
504
	/**
505
	 * @generated
506
	 */
507
	protected void handleNotificationEvent(Notification event) {
508
		Object feature = event.getFeature();
509
		if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) {
510
			Integer c = (Integer) event.getNewValue();
511
			setFontColor(DiagramColorRegistry.getInstance().getColor(c));
512
		} else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) {
513
			refreshUnderline();
514
		} else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) {
515
			refreshStrikeThrough();
516
		} else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature)
517
				|| NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) {
518
			refreshFont();
519
		} else {
520
			if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) {
521
				refreshLabel();
522
			}
523
			if (getParser() instanceof ISemanticParser) {
524
				ISemanticParser modelParser = (ISemanticParser) getParser();
525
				if (modelParser.areSemanticElementsAffected(null, event)) {
526
					removeSemanticListeners();
527
					if (resolveSemanticElement() != null) {
528
						addSemanticListeners();
529
					}
530
					refreshLabel();
531
				}
532
			}
533
		}
534
		super.handleNotificationEvent(event);
535
	}
536
537
	/**
538
	 * @generated
539
	 */
540
	protected IFigure createFigure() {
541
		IFigure label = createFigurePrim();
542
		defaultText = getLabelTextHelper(label);
543
		return label;
544
	}
545
546
	/**
547
	 * @generated
548
	 */
549
	protected IFigure createFigurePrim() {
550
		return new WrapLabel();
551
	}
552
553
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/parts/EnumerationNameEditPart.java (+551 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.parts;
2
3
import java.util.ArrayList;
4
import java.util.Collections;
5
import java.util.List;
6
7
import org.eclipse.draw2d.IFigure;
8
import org.eclipse.draw2d.Label;
9
import org.eclipse.draw2d.geometry.Point;
10
import org.eclipse.emf.common.notify.Notification;
11
import org.eclipse.emf.ecore.EObject;
12
import org.eclipse.emf.transaction.RunnableWithResult;
13
import org.eclipse.gef.AccessibleEditPart;
14
import org.eclipse.gef.EditPolicy;
15
import org.eclipse.gef.GraphicalEditPart;
16
import org.eclipse.gef.Request;
17
import org.eclipse.gef.commands.Command;
18
import org.eclipse.gef.editpolicies.NonResizableEditPolicy;
19
import org.eclipse.gef.handles.NonResizableHandleKit;
20
import org.eclipse.gef.requests.DirectEditRequest;
21
import org.eclipse.gef.tools.DirectEditManager;
22
import org.eclipse.gmf.runtime.common.ui.services.parser.IParser;
23
import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus;
24
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserEditStatus;
25
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions;
26
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserService;
27
import org.eclipse.gmf.runtime.diagram.ui.editparts.CompartmentEditPart;
28
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
29
import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart;
30
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy;
31
import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry;
32
import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants;
33
import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager;
34
import org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel;
35
import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
36
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
37
import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser;
38
import org.eclipse.gmf.runtime.emf.ui.services.parser.ParserHintAdapter;
39
import org.eclipse.gmf.runtime.notation.FontStyle;
40
import org.eclipse.gmf.runtime.notation.NotationPackage;
41
import org.eclipse.gmf.runtime.notation.View;
42
import org.eclipse.jface.resource.ImageDescriptor;
43
import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
44
import org.eclipse.jface.viewers.ICellEditorValidator;
45
import org.eclipse.swt.SWT;
46
import org.eclipse.swt.accessibility.AccessibleEvent;
47
import org.eclipse.swt.graphics.Color;
48
import org.eclipse.swt.graphics.FontData;
49
import org.eclipse.swt.graphics.Image;
50
import org.eclipse.uml2.diagram.clazz.edit.policies.UMLTextSelectionEditPolicy;
51
import org.eclipse.uml2.diagram.clazz.part.UMLDiagramEditorPlugin;
52
import org.eclipse.uml2.diagram.clazz.providers.UMLElementTypes;
53
54
/**
55
 * @generated
56
 */
57
public class EnumerationNameEditPart extends CompartmentEditPart implements ITextAwareEditPart {
58
59
	/**
60
	 * @generated
61
	 */
62
	public static final int VISUAL_ID = 5005;
63
64
	/**
65
	 * @generated
66
	 */
67
	private DirectEditManager manager;
68
69
	/**
70
	 * @generated
71
	 */
72
	private IParser parser;
73
74
	/**
75
	 * @generated
76
	 */
77
	private List parserElements;
78
79
	/**
80
	 * @generated
81
	 */
82
	private String defaultText;
83
84
	/**
85
	 * @generated
86
	 */
87
	public EnumerationNameEditPart(View view) {
88
		super(view);
89
	}
90
91
	/**
92
	 * @generated
93
	 */
94
	protected void createDefaultEditPolicies() {
95
		super.createDefaultEditPolicies();
96
		installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy());
97
		installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new NonResizableEditPolicy() {
98
99
			protected List createSelectionHandles() {
100
				List handles = new ArrayList();
101
				NonResizableHandleKit.addMoveHandle((GraphicalEditPart) getHost(), handles);
102
				return handles;
103
			}
104
105
			public Command getCommand(Request request) {
106
				return null;
107
			}
108
109
			public boolean understandsRequest(Request request) {
110
				return false;
111
			}
112
		});
113
114
	}
115
116
	/**
117
	 * @generated
118
	 */
119
	protected String getLabelTextHelper(IFigure figure) {
120
		if (figure instanceof WrapLabel) {
121
			return ((WrapLabel) figure).getText();
122
		} else {
123
			return ((Label) figure).getText();
124
		}
125
	}
126
127
	/**
128
	 * @generated
129
	 */
130
	protected void setLabelTextHelper(IFigure figure, String text) {
131
		if (figure instanceof WrapLabel) {
132
			((WrapLabel) figure).setText(text);
133
		} else {
134
			((Label) figure).setText(text);
135
		}
136
	}
137
138
	/**
139
	 * @generated
140
	 */
141
	protected Image getLabelIconHelper(IFigure figure) {
142
		if (figure instanceof WrapLabel) {
143
			return ((WrapLabel) figure).getIcon();
144
		} else {
145
			return ((Label) figure).getIcon();
146
		}
147
	}
148
149
	/**
150
	 * @generated
151
	 */
152
	protected void setLabelIconHelper(IFigure figure, Image icon) {
153
		if (figure instanceof WrapLabel) {
154
			((WrapLabel) figure).setIcon(icon);
155
		} else {
156
			((Label) figure).setIcon(icon);
157
		}
158
	}
159
160
	/**
161
	 * @generated
162
	 */
163
	public void setLabel(WrapLabel figure) {
164
		unregisterVisuals();
165
		setFigure(figure);
166
		defaultText = getLabelTextHelper(figure);
167
		registerVisuals();
168
		refreshVisuals();
169
	}
170
171
	/**
172
	 * @generated
173
	 */
174
	protected List getModelChildren() {
175
		return Collections.EMPTY_LIST;
176
	}
177
178
	/**
179
	 * @generated
180
	 */
181
	public IGraphicalEditPart getChildBySemanticHint(String semanticHint) {
182
		return null;
183
	}
184
185
	/**
186
	 * @generated
187
	 */
188
	protected EObject getParserElement() {
189
		EObject element = resolveSemanticElement();
190
		return element != null ? element : (View) getModel();
191
	}
192
193
	/**
194
	 * @generated
195
	 */
196
	protected Image getLabelIcon() {
197
		EObject parserElement = getParserElement();
198
		if (parserElement == null) {
199
			return null;
200
		}
201
		return UMLElementTypes.getImage(parserElement.eClass());
202
	}
203
204
	/**
205
	 * @generated
206
	 */
207
	protected String getLabelText() {
208
		String text = null;
209
		if (getParser() != null) {
210
			text = getParser().getPrintString(new EObjectAdapter(getParserElement()), getParserOptions().intValue());
211
		}
212
		if (text == null || text.length() == 0) {
213
			text = defaultText;
214
		}
215
		return text;
216
	}
217
218
	/**
219
	 * @generated
220
	 */
221
	public void setLabelText(String text) {
222
		setLabelTextHelper(getFigure(), text);
223
		Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
224
		if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) {
225
			((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback();
226
		}
227
	}
228
229
	/**
230
	 * @generated
231
	 */
232
	public String getEditText() {
233
		if (getParser() == null) {
234
			return ""; //$NON-NLS-1$
235
		}
236
		return getParser().getEditString(new EObjectAdapter(getParserElement()), getParserOptions().intValue());
237
	}
238
239
	/**
240
	 * @generated
241
	 */
242
	protected boolean isEditable() {
243
		return getEditText() != null;
244
	}
245
246
	/**
247
	 * @generated
248
	 */
249
	public ICellEditorValidator getEditTextValidator() {
250
		return new ICellEditorValidator() {
251
252
			public String isValid(final Object value) {
253
				if (value instanceof String) {
254
					final EObject element = getParserElement();
255
					final IParser parser = getParser();
256
					try {
257
						IParserEditStatus valid = (IParserEditStatus) getEditingDomain().runExclusive(new RunnableWithResult.Impl() {
258
259
							public void run() {
260
								setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value));
261
							}
262
						});
263
						return valid.getCode() == ParserEditStatus.EDITABLE ? null : valid.getMessage();
264
					} catch (InterruptedException ie) {
265
						ie.printStackTrace();
266
					}
267
				}
268
269
				// shouldn't get here
270
				return null;
271
			}
272
		};
273
	}
274
275
	/**
276
	 * @generated
277
	 */
278
	public IContentAssistProcessor getCompletionProcessor() {
279
		if (getParser() == null) {
280
			return null;
281
		}
282
		return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement()));
283
	}
284
285
	/**
286
	 * @generated
287
	 */
288
	public ParserOptions getParserOptions() {
289
		return ParserOptions.NONE;
290
	}
291
292
	/**
293
	 * @generated
294
	 */
295
	public IParser getParser() {
296
		if (parser == null) {
297
			String parserHint = ((View) getModel()).getType();
298
			ParserHintAdapter hintAdapter = new ParserHintAdapter(getParserElement(), parserHint) {
299
300
				public Object getAdapter(Class adapter) {
301
					if (IElementType.class.equals(adapter)) {
302
						return UMLElementTypes.Enumeration_2003;
303
					}
304
					return super.getAdapter(adapter);
305
				}
306
			};
307
			parser = ParserService.getInstance().getParser(hintAdapter);
308
		}
309
		return parser;
310
	}
311
312
	/**
313
	 * @generated
314
	 */
315
	protected DirectEditManager getManager() {
316
		if (manager == null) {
317
			setManager(new TextDirectEditManager(this, TextDirectEditManager.getTextCellEditorClass(this), UMLEditPartFactory.getTextCellEditorLocator(this)));
318
		}
319
		return manager;
320
	}
321
322
	/**
323
	 * @generated
324
	 */
325
	protected void setManager(DirectEditManager manager) {
326
		this.manager = manager;
327
	}
328
329
	/**
330
	 * @generated
331
	 */
332
	protected void performDirectEdit() {
333
		getManager().show();
334
	}
335
336
	/**
337
	 * @generated
338
	 */
339
	protected void performDirectEdit(Point eventLocation) {
340
		if (getManager().getClass() == TextDirectEditManager.class) {
341
			((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint());
342
		}
343
	}
344
345
	/**
346
	 * @generated
347
	 */
348
	private void performDirectEdit(char initialCharacter) {
349
		if (getManager() instanceof TextDirectEditManager) {
350
			((TextDirectEditManager) getManager()).show(initialCharacter);
351
		} else {
352
			performDirectEdit();
353
		}
354
	}
355
356
	/**
357
	 * @generated
358
	 */
359
	protected void performDirectEditRequest(Request request) {
360
		final Request theRequest = request;
361
		try {
362
			getEditingDomain().runExclusive(new Runnable() {
363
364
				public void run() {
365
					if (isActive() && isEditable()) {
366
						if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) {
367
							Character initialChar = (Character) theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR);
368
							performDirectEdit(initialChar.charValue());
369
						} else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) {
370
							DirectEditRequest editRequest = (DirectEditRequest) theRequest;
371
							performDirectEdit(editRequest.getLocation());
372
						} else {
373
							performDirectEdit();
374
						}
375
					}
376
				}
377
			});
378
		} catch (InterruptedException e) {
379
			e.printStackTrace();
380
		}
381
	}
382
383
	/**
384
	 * @generated
385
	 */
386
	protected void refreshVisuals() {
387
		super.refreshVisuals();
388
		refreshLabel();
389
		refreshFont();
390
		refreshFontColor();
391
		refreshUnderline();
392
		refreshStrikeThrough();
393
	}
394
395
	/**
396
	 * @generated
397
	 */
398
	protected void refreshLabel() {
399
		setLabelTextHelper(getFigure(), getLabelText());
400
		setLabelIconHelper(getFigure(), getLabelIcon());
401
		Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
402
		if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) {
403
			((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback();
404
		}
405
	}
406
407
	/**
408
	 * @generated
409
	 */
410
	protected void refreshUnderline() {
411
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
412
		if (style != null && getFigure() instanceof WrapLabel) {
413
			((WrapLabel) getFigure()).setTextUnderline(style.isUnderline());
414
		}
415
	}
416
417
	/**
418
	 * @generated
419
	 */
420
	protected void refreshStrikeThrough() {
421
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
422
		if (style != null && getFigure() instanceof WrapLabel) {
423
			((WrapLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough());
424
		}
425
	}
426
427
	/**
428
	 * @generated
429
	 */
430
	protected void refreshFont() {
431
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
432
		if (style != null) {
433
			FontData fontData = new FontData(style.getFontName(), style.getFontHeight(), (style.isBold() ? SWT.BOLD : SWT.NORMAL) | (style.isItalic() ? SWT.ITALIC : SWT.NORMAL));
434
			setFont(fontData);
435
		}
436
	}
437
438
	/**
439
	 * @generated
440
	 */
441
	protected void setFontColor(Color color) {
442
		getFigure().setForegroundColor(color);
443
	}
444
445
	/**
446
	 * @generated
447
	 */
448
	protected void addSemanticListeners() {
449
		if (getParser() instanceof ISemanticParser) {
450
			EObject element = resolveSemanticElement();
451
			parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element);
452
			for (int i = 0; i < parserElements.size(); i++) {
453
				addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$
454
			}
455
		} else {
456
			super.addSemanticListeners();
457
		}
458
	}
459
460
	/**
461
	 * @generated
462
	 */
463
	protected void removeSemanticListeners() {
464
		if (parserElements != null) {
465
			for (int i = 0; i < parserElements.size(); i++) {
466
				removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$
467
			}
468
		} else {
469
			super.removeSemanticListeners();
470
		}
471
	}
472
473
	/**
474
	 * @generated
475
	 */
476
	protected AccessibleEditPart getAccessibleEditPart() {
477
		if (accessibleEP == null) {
478
			accessibleEP = new AccessibleGraphicalEditPart() {
479
480
				public void getName(AccessibleEvent e) {
481
					e.result = getLabelTextHelper(getFigure());
482
				}
483
			};
484
		}
485
		return accessibleEP;
486
	}
487
488
	/**
489
	 * @generated
490
	 */
491
	private View getFontStyleOwnerView() {
492
		return getPrimaryView();
493
	}
494
495
	/**
496
	 * @generated
497
	 */
498
	protected void addNotationalListeners() {
499
		super.addNotationalListeners();
500
		addListenerFilter("PrimaryView", this, getPrimaryView()); //$NON-NLS-1$
501
	}
502
503
	/**
504
	 * @generated
505
	 */
506
	protected void removeNotationalListeners() {
507
		super.removeNotationalListeners();
508
		removeListenerFilter("PrimaryView"); //$NON-NLS-1$
509
	}
510
511
	/**
512
	 * @generated
513
	 */
514
	protected void handleNotificationEvent(Notification event) {
515
		Object feature = event.getFeature();
516
		if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) {
517
			Integer c = (Integer) event.getNewValue();
518
			setFontColor(DiagramColorRegistry.getInstance().getColor(c));
519
		} else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) {
520
			refreshUnderline();
521
		} else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) {
522
			refreshStrikeThrough();
523
		} else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature)
524
				|| NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) {
525
			refreshFont();
526
		} else {
527
			if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) {
528
				refreshLabel();
529
			}
530
			if (getParser() instanceof ISemanticParser) {
531
				ISemanticParser modelParser = (ISemanticParser) getParser();
532
				if (modelParser.areSemanticElementsAffected(null, event)) {
533
					removeSemanticListeners();
534
					if (resolveSemanticElement() != null) {
535
						addSemanticListeners();
536
					}
537
					refreshLabel();
538
				}
539
			}
540
		}
541
		super.handleNotificationEvent(event);
542
	}
543
544
	/**
545
	 * @generated
546
	 */
547
	protected IFigure createFigure() {
548
		// Parent should assign one using setLabel method
549
		return null;
550
	}
551
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/policies/DependencyClientItemSemanticEditPolicy.java (+18 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.policies;
2
3
import org.eclipse.gef.commands.Command;
4
import org.eclipse.gmf.runtime.emf.type.core.commands.DestroyReferenceCommand;
5
import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyReferenceRequest;
6
7
/**
8
 * @generated
9
 */
10
public class DependencyClientItemSemanticEditPolicy extends UMLBaseItemSemanticEditPolicy {
11
12
	/**
13
	 * @generated
14
	 */
15
	protected Command getDestroyReferenceCommand(DestroyReferenceRequest req) {
16
		return getMSLWrapper(new DestroyReferenceCommand(req));
17
	}
18
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/policies/ClassClassesItemSemanticEditPolicy.java (+72 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.policies;
2
3
import org.eclipse.emf.ecore.EClass;
4
import org.eclipse.emf.ecore.EObject;
5
import org.eclipse.gef.commands.Command;
6
import org.eclipse.gmf.runtime.emf.type.core.commands.CreateElementCommand;
7
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest;
8
import org.eclipse.gmf.runtime.notation.View;
9
import org.eclipse.uml2.diagram.clazz.providers.UMLElementTypes;
10
import org.eclipse.uml2.uml.UMLPackage;
11
12
/**
13
 * @generated
14
 */
15
public class ClassClassesItemSemanticEditPolicy extends UMLBaseItemSemanticEditPolicy {
16
17
	/**
18
	 * @generated
19
	 */
20
	protected Command getCreateCommand(CreateElementRequest req) {
21
		if (UMLElementTypes.Class_3003 == req.getElementType()) {
22
			if (req.getContainmentFeature() == null) {
23
				req.setContainmentFeature(UMLPackage.eINSTANCE.getClass_NestedClassifier());
24
			}
25
			return getMSLWrapper(new CreateClass_3003Command(req));
26
		}
27
		return super.getCreateCommand(req);
28
	}
29
30
	/**
31
	 * @generated
32
	 */
33
	private static class CreateClass_3003Command extends CreateElementCommand {
34
35
		/**
36
		 * @generated
37
		 */
38
		public CreateClass_3003Command(CreateElementRequest req) {
39
			super(req);
40
		}
41
42
		/**
43
		 * @generated
44
		 */
45
		protected EClass getEClassToEdit() {
46
			return UMLPackage.eINSTANCE.getClass_();
47
		};
48
49
		/**
50
		 * @generated
51
		 */
52
		protected EObject getElementToEdit() {
53
			EObject container = ((CreateElementRequest) getRequest()).getContainer();
54
			if (container instanceof View) {
55
				container = ((View) container).getElement();
56
			}
57
			return container;
58
		}
59
60
		/**
61
		 * @generated
62
		 */
63
		protected EObject doDefaultElementCreation() {
64
			org.eclipse.uml2.uml.Class newElement = (org.eclipse.uml2.uml.Class) super.doDefaultElementCreation();
65
			if (newElement != null) {
66
				UMLElementTypes.Initializers.Class_3003.init(newElement);
67
			}
68
			return newElement;
69
		}
70
	}
71
72
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/parts/Operation4EditPart.java (+553 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.parts;
2
3
import java.util.Collections;
4
import java.util.List;
5
6
import org.eclipse.draw2d.IFigure;
7
import org.eclipse.draw2d.Label;
8
import org.eclipse.draw2d.geometry.Point;
9
import org.eclipse.emf.common.notify.Notification;
10
import org.eclipse.emf.ecore.EObject;
11
import org.eclipse.emf.transaction.RunnableWithResult;
12
import org.eclipse.gef.AccessibleEditPart;
13
import org.eclipse.gef.DragTracker;
14
import org.eclipse.gef.EditPolicy;
15
import org.eclipse.gef.Request;
16
import org.eclipse.gef.requests.DirectEditRequest;
17
import org.eclipse.gef.requests.SelectionRequest;
18
import org.eclipse.gef.tools.DirectEditManager;
19
import org.eclipse.gmf.runtime.common.ui.services.parser.IParser;
20
import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus;
21
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserEditStatus;
22
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions;
23
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserService;
24
import org.eclipse.gmf.runtime.diagram.ui.editparts.CompartmentEditPart;
25
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
26
import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart;
27
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
28
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy;
29
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.ListItemComponentEditPolicy;
30
import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry;
31
import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants;
32
import org.eclipse.gmf.runtime.diagram.ui.tools.DragEditPartsTrackerEx;
33
import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager;
34
import org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel;
35
import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
36
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
37
import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser;
38
import org.eclipse.gmf.runtime.emf.ui.services.parser.ParserHintAdapter;
39
import org.eclipse.gmf.runtime.notation.FontStyle;
40
import org.eclipse.gmf.runtime.notation.NotationPackage;
41
import org.eclipse.gmf.runtime.notation.View;
42
import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
43
import org.eclipse.jface.viewers.ICellEditorValidator;
44
import org.eclipse.swt.SWT;
45
import org.eclipse.swt.accessibility.AccessibleEvent;
46
import org.eclipse.swt.graphics.Color;
47
import org.eclipse.swt.graphics.FontData;
48
import org.eclipse.swt.graphics.Image;
49
import org.eclipse.uml2.diagram.clazz.edit.policies.Operation4ItemSemanticEditPolicy;
50
import org.eclipse.uml2.diagram.clazz.edit.policies.UMLTextNonResizableEditPolicy;
51
import org.eclipse.uml2.diagram.clazz.edit.policies.UMLTextSelectionEditPolicy;
52
import org.eclipse.uml2.diagram.clazz.providers.UMLElementTypes;
53
54
/**
55
 * @generated
56
 */
57
public class Operation4EditPart extends CompartmentEditPart implements ITextAwareEditPart {
58
59
	/**
60
	 * @generated
61
	 */
62
	public static final int VISUAL_ID = 3022;
63
64
	/**
65
	 * @generated
66
	 */
67
	private DirectEditManager manager;
68
69
	/**
70
	 * @generated
71
	 */
72
	private IParser parser;
73
74
	/**
75
	 * @generated
76
	 */
77
	private List parserElements;
78
79
	/**
80
	 * @generated
81
	 */
82
	private String defaultText;
83
84
	/**
85
	 * @generated
86
	 */
87
	public Operation4EditPart(View view) {
88
		super(view);
89
	}
90
91
	/**
92
	 * @generated
93
	 */
94
	public DragTracker getDragTracker(Request request) {
95
		if (request instanceof SelectionRequest && ((SelectionRequest) request).getLastButtonPressed() == 3) {
96
			return null;
97
		}
98
		return new DragEditPartsTrackerEx(this);
99
	}
100
101
	/**
102
	 * @generated
103
	 */
104
	protected void createDefaultEditPolicies() {
105
		super.createDefaultEditPolicies();
106
		installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new Operation4ItemSemanticEditPolicy());
107
		installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new UMLTextNonResizableEditPolicy());
108
		installEditPolicy(EditPolicy.COMPONENT_ROLE, new ListItemComponentEditPolicy());
109
		installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy());
110
111
	}
112
113
	/**
114
	 * @generated
115
	 */
116
	protected String getLabelTextHelper(IFigure figure) {
117
		if (figure instanceof WrapLabel) {
118
			return ((WrapLabel) figure).getText();
119
		} else {
120
			return ((Label) figure).getText();
121
		}
122
	}
123
124
	/**
125
	 * @generated
126
	 */
127
	protected void setLabelTextHelper(IFigure figure, String text) {
128
		if (figure instanceof WrapLabel) {
129
			((WrapLabel) figure).setText(text);
130
		} else {
131
			((Label) figure).setText(text);
132
		}
133
	}
134
135
	/**
136
	 * @generated
137
	 */
138
	protected Image getLabelIconHelper(IFigure figure) {
139
		if (figure instanceof WrapLabel) {
140
			return ((WrapLabel) figure).getIcon();
141
		} else {
142
			return ((Label) figure).getIcon();
143
		}
144
	}
145
146
	/**
147
	 * @generated
148
	 */
149
	protected void setLabelIconHelper(IFigure figure, Image icon) {
150
		if (figure instanceof WrapLabel) {
151
			((WrapLabel) figure).setIcon(icon);
152
		} else {
153
			((Label) figure).setIcon(icon);
154
		}
155
	}
156
157
	/**
158
	 * @generated
159
	 */
160
	public void setLabel(IFigure figure) {
161
		unregisterVisuals();
162
		setFigure(figure);
163
		defaultText = getLabelTextHelper(figure);
164
		registerVisuals();
165
		refreshVisuals();
166
	}
167
168
	/**
169
	 * @generated
170
	 */
171
	protected List getModelChildren() {
172
		return Collections.EMPTY_LIST;
173
	}
174
175
	/**
176
	 * @generated
177
	 */
178
	public IGraphicalEditPart getChildBySemanticHint(String semanticHint) {
179
		return null;
180
	}
181
182
	/**
183
	 * @generated
184
	 */
185
	protected EObject getParserElement() {
186
		EObject element = resolveSemanticElement();
187
		return element != null ? element : (View) getModel();
188
	}
189
190
	/**
191
	 * @generated
192
	 */
193
	protected Image getLabelIcon() {
194
		return null;
195
	}
196
197
	/**
198
	 * @generated
199
	 */
200
	protected String getLabelText() {
201
		String text = null;
202
		if (getParser() != null) {
203
			text = getParser().getPrintString(new EObjectAdapter(getParserElement()), getParserOptions().intValue());
204
		}
205
		if (text == null || text.length() == 0) {
206
			text = defaultText;
207
		}
208
		return text;
209
	}
210
211
	/**
212
	 * @generated
213
	 */
214
	public void setLabelText(String text) {
215
		setLabelTextHelper(getFigure(), text);
216
		Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
217
		if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) {
218
			((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback();
219
		}
220
	}
221
222
	/**
223
	 * @generated
224
	 */
225
	public String getEditText() {
226
		if (getParser() == null) {
227
			return ""; //$NON-NLS-1$
228
		}
229
		return getParser().getEditString(new EObjectAdapter(getParserElement()), getParserOptions().intValue());
230
	}
231
232
	/**
233
	 * @generated
234
	 */
235
	protected boolean isEditable() {
236
		return getEditText() != null;
237
	}
238
239
	/**
240
	 * @generated
241
	 */
242
	public ICellEditorValidator getEditTextValidator() {
243
		return new ICellEditorValidator() {
244
245
			public String isValid(final Object value) {
246
				if (value instanceof String) {
247
					final EObject element = getParserElement();
248
					final IParser parser = getParser();
249
					try {
250
						IParserEditStatus valid = (IParserEditStatus) getEditingDomain().runExclusive(new RunnableWithResult.Impl() {
251
252
							public void run() {
253
								setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value));
254
							}
255
						});
256
						return valid.getCode() == ParserEditStatus.EDITABLE ? null : valid.getMessage();
257
					} catch (InterruptedException ie) {
258
						ie.printStackTrace();
259
					}
260
				}
261
262
				// shouldn't get here
263
				return null;
264
			}
265
		};
266
	}
267
268
	/**
269
	 * @generated
270
	 */
271
	public IContentAssistProcessor getCompletionProcessor() {
272
		if (getParser() == null) {
273
			return null;
274
		}
275
		return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement()));
276
	}
277
278
	/**
279
	 * @generated
280
	 */
281
	public ParserOptions getParserOptions() {
282
		return ParserOptions.NONE;
283
	}
284
285
	/**
286
	 * @generated
287
	 */
288
	public IParser getParser() {
289
		if (parser == null) {
290
			String parserHint = ((View) getModel()).getType();
291
			ParserHintAdapter hintAdapter = new ParserHintAdapter(getParserElement(), parserHint) {
292
293
				public Object getAdapter(Class adapter) {
294
					if (IElementType.class.equals(adapter)) {
295
						return UMLElementTypes.Operation_3022;
296
					}
297
					return super.getAdapter(adapter);
298
				}
299
			};
300
			parser = ParserService.getInstance().getParser(hintAdapter);
301
		}
302
		return parser;
303
	}
304
305
	/**
306
	 * @generated
307
	 */
308
	protected DirectEditManager getManager() {
309
		if (manager == null) {
310
			setManager(new TextDirectEditManager(this, TextDirectEditManager.getTextCellEditorClass(this), UMLEditPartFactory.getTextCellEditorLocator(this)));
311
		}
312
		return manager;
313
	}
314
315
	/**
316
	 * @generated
317
	 */
318
	protected void setManager(DirectEditManager manager) {
319
		this.manager = manager;
320
	}
321
322
	/**
323
	 * @generated
324
	 */
325
	protected void performDirectEdit() {
326
		getManager().show();
327
	}
328
329
	/**
330
	 * @generated
331
	 */
332
	protected void performDirectEdit(Point eventLocation) {
333
		if (getManager().getClass() == TextDirectEditManager.class) {
334
			((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint());
335
		}
336
	}
337
338
	/**
339
	 * @generated
340
	 */
341
	private void performDirectEdit(char initialCharacter) {
342
		if (getManager() instanceof TextDirectEditManager) {
343
			((TextDirectEditManager) getManager()).show(initialCharacter);
344
		} else {
345
			performDirectEdit();
346
		}
347
	}
348
349
	/**
350
	 * @generated
351
	 */
352
	protected void performDirectEditRequest(Request request) {
353
		final Request theRequest = request;
354
		try {
355
			getEditingDomain().runExclusive(new Runnable() {
356
357
				public void run() {
358
					if (isActive() && isEditable()) {
359
						if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) {
360
							Character initialChar = (Character) theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR);
361
							performDirectEdit(initialChar.charValue());
362
						} else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) {
363
							DirectEditRequest editRequest = (DirectEditRequest) theRequest;
364
							performDirectEdit(editRequest.getLocation());
365
						} else {
366
							performDirectEdit();
367
						}
368
					}
369
				}
370
			});
371
		} catch (InterruptedException e) {
372
			e.printStackTrace();
373
		}
374
	}
375
376
	/**
377
	 * @generated
378
	 */
379
	protected void refreshVisuals() {
380
		super.refreshVisuals();
381
		refreshLabel();
382
		refreshFont();
383
		refreshFontColor();
384
		refreshUnderline();
385
		refreshStrikeThrough();
386
	}
387
388
	/**
389
	 * @generated
390
	 */
391
	protected void refreshLabel() {
392
		setLabelTextHelper(getFigure(), getLabelText());
393
		setLabelIconHelper(getFigure(), getLabelIcon());
394
		Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
395
		if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) {
396
			((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback();
397
		}
398
	}
399
400
	/**
401
	 * @generated
402
	 */
403
	protected void refreshUnderline() {
404
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
405
		if (style != null && getFigure() instanceof WrapLabel) {
406
			((WrapLabel) getFigure()).setTextUnderline(style.isUnderline());
407
		}
408
	}
409
410
	/**
411
	 * @generated
412
	 */
413
	protected void refreshStrikeThrough() {
414
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
415
		if (style != null && getFigure() instanceof WrapLabel) {
416
			((WrapLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough());
417
		}
418
	}
419
420
	/**
421
	 * @generated
422
	 */
423
	protected void refreshFont() {
424
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
425
		if (style != null) {
426
			FontData fontData = new FontData(style.getFontName(), style.getFontHeight(), (style.isBold() ? SWT.BOLD : SWT.NORMAL) | (style.isItalic() ? SWT.ITALIC : SWT.NORMAL));
427
			setFont(fontData);
428
		}
429
	}
430
431
	/**
432
	 * @generated
433
	 */
434
	protected void setFontColor(Color color) {
435
		getFigure().setForegroundColor(color);
436
	}
437
438
	/**
439
	 * @generated
440
	 */
441
	protected void addSemanticListeners() {
442
		if (getParser() instanceof ISemanticParser) {
443
			EObject element = resolveSemanticElement();
444
			parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element);
445
			for (int i = 0; i < parserElements.size(); i++) {
446
				addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$
447
			}
448
		} else {
449
			super.addSemanticListeners();
450
		}
451
	}
452
453
	/**
454
	 * @generated
455
	 */
456
	protected void removeSemanticListeners() {
457
		if (parserElements != null) {
458
			for (int i = 0; i < parserElements.size(); i++) {
459
				removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$
460
			}
461
		} else {
462
			super.removeSemanticListeners();
463
		}
464
	}
465
466
	/**
467
	 * @generated
468
	 */
469
	protected AccessibleEditPart getAccessibleEditPart() {
470
		if (accessibleEP == null) {
471
			accessibleEP = new AccessibleGraphicalEditPart() {
472
473
				public void getName(AccessibleEvent e) {
474
					e.result = getLabelTextHelper(getFigure());
475
				}
476
			};
477
		}
478
		return accessibleEP;
479
	}
480
481
	/**
482
	 * @generated
483
	 */
484
	private View getFontStyleOwnerView() {
485
		return getPrimaryView();
486
	}
487
488
	/**
489
	 * @generated
490
	 */
491
	protected void addNotationalListeners() {
492
		super.addNotationalListeners();
493
		addListenerFilter("PrimaryView", this, getPrimaryView()); //$NON-NLS-1$
494
	}
495
496
	/**
497
	 * @generated
498
	 */
499
	protected void removeNotationalListeners() {
500
		super.removeNotationalListeners();
501
		removeListenerFilter("PrimaryView"); //$NON-NLS-1$
502
	}
503
504
	/**
505
	 * @generated
506
	 */
507
	protected void handleNotificationEvent(Notification event) {
508
		Object feature = event.getFeature();
509
		if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) {
510
			Integer c = (Integer) event.getNewValue();
511
			setFontColor(DiagramColorRegistry.getInstance().getColor(c));
512
		} else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) {
513
			refreshUnderline();
514
		} else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) {
515
			refreshStrikeThrough();
516
		} else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature)
517
				|| NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) {
518
			refreshFont();
519
		} else {
520
			if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) {
521
				refreshLabel();
522
			}
523
			if (getParser() instanceof ISemanticParser) {
524
				ISemanticParser modelParser = (ISemanticParser) getParser();
525
				if (modelParser.areSemanticElementsAffected(null, event)) {
526
					removeSemanticListeners();
527
					if (resolveSemanticElement() != null) {
528
						addSemanticListeners();
529
					}
530
					refreshLabel();
531
				}
532
			}
533
		}
534
		super.handleNotificationEvent(event);
535
	}
536
537
	/**
538
	 * @generated
539
	 */
540
	protected IFigure createFigure() {
541
		IFigure label = createFigurePrim();
542
		defaultText = getLabelTextHelper(label);
543
		return label;
544
	}
545
546
	/**
547
	 * @generated
548
	 */
549
	protected IFigure createFigurePrim() {
550
		return new WrapLabel();
551
	}
552
553
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/parts/EnumerationAttributesEditPart.java (+67 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.parts;
2
3
import org.eclipse.emf.common.notify.Notification;
4
import org.eclipse.gef.EditPolicy;
5
import org.eclipse.gmf.runtime.diagram.ui.editparts.ListCompartmentEditPart;
6
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.CreationEditPolicy;
7
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.DragDropEditPolicy;
8
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
9
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.ResizableCompartmentEditPolicy;
10
import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout;
11
import org.eclipse.gmf.runtime.notation.View;
12
import org.eclipse.uml2.diagram.clazz.edit.policies.EnumerationAttributesCanonicalEditPolicy;
13
import org.eclipse.uml2.diagram.clazz.edit.policies.EnumerationAttributesItemSemanticEditPolicy;
14
15
/**
16
 * @generated
17
 */
18
public class EnumerationAttributesEditPart extends ListCompartmentEditPart {
19
20
	/**
21
	 * @generated
22
	 */
23
	public static final int VISUAL_ID = 7014;
24
25
	/**
26
	 * @generated
27
	 */
28
	public EnumerationAttributesEditPart(View view) {
29
		super(view);
30
	}
31
32
	/**
33
	 * @generated
34
	 */
35
	protected boolean hasModelChildrenChanged(Notification evt) {
36
		return false;
37
	}
38
39
	/**
40
	 * @generated
41
	 */
42
	public String getCompartmentName() {
43
		return "attributes";
44
	}
45
46
	/**
47
	 * @generated
48
	 */
49
	protected void createDefaultEditPolicies() {
50
		super.createDefaultEditPolicies();
51
		installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ResizableCompartmentEditPolicy());
52
		installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new EnumerationAttributesItemSemanticEditPolicy());
53
		installEditPolicy(EditPolicyRoles.CREATION_ROLE, new CreationEditPolicy());
54
		installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, new DragDropEditPolicy());
55
		installEditPolicy(EditPolicyRoles.CANONICAL_ROLE, new EnumerationAttributesCanonicalEditPolicy());
56
57
	}
58
59
	/**
60
	 * @generated
61
	 */
62
	protected void setRatio(Double ratio) {
63
		if (getFigure().getParent().getLayoutManager() instanceof ConstrainedToolbarLayout) {
64
			super.setRatio(ratio);
65
		}
66
	}
67
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/policies/AssociationItemSemanticEditPolicy.java (+18 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.policies;
2
3
import org.eclipse.gef.commands.Command;
4
import org.eclipse.gmf.runtime.emf.type.core.commands.DestroyElementCommand;
5
import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest;
6
7
/**
8
 * @generated
9
 */
10
public class AssociationItemSemanticEditPolicy extends UMLBaseItemSemanticEditPolicy {
11
12
	/**
13
	 * @generated
14
	 */
15
	protected Command getDestroyElementCommand(DestroyElementRequest req) {
16
		return getMSLWrapper(new DestroyElementCommand(req));
17
	}
18
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/parts/EnumerationEditPart.java (+553 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.parts;
2
3
import java.util.Collections;
4
import java.util.List;
5
6
import org.eclipse.draw2d.IFigure;
7
import org.eclipse.draw2d.Label;
8
import org.eclipse.draw2d.geometry.Point;
9
import org.eclipse.emf.common.notify.Notification;
10
import org.eclipse.emf.ecore.EObject;
11
import org.eclipse.emf.transaction.RunnableWithResult;
12
import org.eclipse.gef.AccessibleEditPart;
13
import org.eclipse.gef.DragTracker;
14
import org.eclipse.gef.EditPolicy;
15
import org.eclipse.gef.Request;
16
import org.eclipse.gef.requests.DirectEditRequest;
17
import org.eclipse.gef.requests.SelectionRequest;
18
import org.eclipse.gef.tools.DirectEditManager;
19
import org.eclipse.gmf.runtime.common.ui.services.parser.IParser;
20
import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus;
21
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserEditStatus;
22
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions;
23
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserService;
24
import org.eclipse.gmf.runtime.diagram.ui.editparts.CompartmentEditPart;
25
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
26
import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart;
27
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
28
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy;
29
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.ListItemComponentEditPolicy;
30
import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry;
31
import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants;
32
import org.eclipse.gmf.runtime.diagram.ui.tools.DragEditPartsTrackerEx;
33
import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager;
34
import org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel;
35
import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
36
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
37
import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser;
38
import org.eclipse.gmf.runtime.emf.ui.services.parser.ParserHintAdapter;
39
import org.eclipse.gmf.runtime.notation.FontStyle;
40
import org.eclipse.gmf.runtime.notation.NotationPackage;
41
import org.eclipse.gmf.runtime.notation.View;
42
import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
43
import org.eclipse.jface.viewers.ICellEditorValidator;
44
import org.eclipse.swt.SWT;
45
import org.eclipse.swt.accessibility.AccessibleEvent;
46
import org.eclipse.swt.graphics.Color;
47
import org.eclipse.swt.graphics.FontData;
48
import org.eclipse.swt.graphics.Image;
49
import org.eclipse.uml2.diagram.clazz.edit.policies.EnumerationItemSemanticEditPolicy;
50
import org.eclipse.uml2.diagram.clazz.edit.policies.UMLTextNonResizableEditPolicy;
51
import org.eclipse.uml2.diagram.clazz.edit.policies.UMLTextSelectionEditPolicy;
52
import org.eclipse.uml2.diagram.clazz.providers.UMLElementTypes;
53
54
/**
55
 * @generated
56
 */
57
public class EnumerationEditPart extends CompartmentEditPart implements ITextAwareEditPart {
58
59
	/**
60
	 * @generated
61
	 */
62
	public static final int VISUAL_ID = 3011;
63
64
	/**
65
	 * @generated
66
	 */
67
	private DirectEditManager manager;
68
69
	/**
70
	 * @generated
71
	 */
72
	private IParser parser;
73
74
	/**
75
	 * @generated
76
	 */
77
	private List parserElements;
78
79
	/**
80
	 * @generated
81
	 */
82
	private String defaultText;
83
84
	/**
85
	 * @generated
86
	 */
87
	public EnumerationEditPart(View view) {
88
		super(view);
89
	}
90
91
	/**
92
	 * @generated
93
	 */
94
	public DragTracker getDragTracker(Request request) {
95
		if (request instanceof SelectionRequest && ((SelectionRequest) request).getLastButtonPressed() == 3) {
96
			return null;
97
		}
98
		return new DragEditPartsTrackerEx(this);
99
	}
100
101
	/**
102
	 * @generated
103
	 */
104
	protected void createDefaultEditPolicies() {
105
		super.createDefaultEditPolicies();
106
		installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new EnumerationItemSemanticEditPolicy());
107
		installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new UMLTextNonResizableEditPolicy());
108
		installEditPolicy(EditPolicy.COMPONENT_ROLE, new ListItemComponentEditPolicy());
109
		installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy());
110
111
	}
112
113
	/**
114
	 * @generated
115
	 */
116
	protected String getLabelTextHelper(IFigure figure) {
117
		if (figure instanceof WrapLabel) {
118
			return ((WrapLabel) figure).getText();
119
		} else {
120
			return ((Label) figure).getText();
121
		}
122
	}
123
124
	/**
125
	 * @generated
126
	 */
127
	protected void setLabelTextHelper(IFigure figure, String text) {
128
		if (figure instanceof WrapLabel) {
129
			((WrapLabel) figure).setText(text);
130
		} else {
131
			((Label) figure).setText(text);
132
		}
133
	}
134
135
	/**
136
	 * @generated
137
	 */
138
	protected Image getLabelIconHelper(IFigure figure) {
139
		if (figure instanceof WrapLabel) {
140
			return ((WrapLabel) figure).getIcon();
141
		} else {
142
			return ((Label) figure).getIcon();
143
		}
144
	}
145
146
	/**
147
	 * @generated
148
	 */
149
	protected void setLabelIconHelper(IFigure figure, Image icon) {
150
		if (figure instanceof WrapLabel) {
151
			((WrapLabel) figure).setIcon(icon);
152
		} else {
153
			((Label) figure).setIcon(icon);
154
		}
155
	}
156
157
	/**
158
	 * @generated
159
	 */
160
	public void setLabel(IFigure figure) {
161
		unregisterVisuals();
162
		setFigure(figure);
163
		defaultText = getLabelTextHelper(figure);
164
		registerVisuals();
165
		refreshVisuals();
166
	}
167
168
	/**
169
	 * @generated
170
	 */
171
	protected List getModelChildren() {
172
		return Collections.EMPTY_LIST;
173
	}
174
175
	/**
176
	 * @generated
177
	 */
178
	public IGraphicalEditPart getChildBySemanticHint(String semanticHint) {
179
		return null;
180
	}
181
182
	/**
183
	 * @generated
184
	 */
185
	protected EObject getParserElement() {
186
		EObject element = resolveSemanticElement();
187
		return element != null ? element : (View) getModel();
188
	}
189
190
	/**
191
	 * @generated
192
	 */
193
	protected Image getLabelIcon() {
194
		return null;
195
	}
196
197
	/**
198
	 * @generated
199
	 */
200
	protected String getLabelText() {
201
		String text = null;
202
		if (getParser() != null) {
203
			text = getParser().getPrintString(new EObjectAdapter(getParserElement()), getParserOptions().intValue());
204
		}
205
		if (text == null || text.length() == 0) {
206
			text = defaultText;
207
		}
208
		return text;
209
	}
210
211
	/**
212
	 * @generated
213
	 */
214
	public void setLabelText(String text) {
215
		setLabelTextHelper(getFigure(), text);
216
		Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
217
		if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) {
218
			((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback();
219
		}
220
	}
221
222
	/**
223
	 * @generated
224
	 */
225
	public String getEditText() {
226
		if (getParser() == null) {
227
			return ""; //$NON-NLS-1$
228
		}
229
		return getParser().getEditString(new EObjectAdapter(getParserElement()), getParserOptions().intValue());
230
	}
231
232
	/**
233
	 * @generated
234
	 */
235
	protected boolean isEditable() {
236
		return getEditText() != null;
237
	}
238
239
	/**
240
	 * @generated
241
	 */
242
	public ICellEditorValidator getEditTextValidator() {
243
		return new ICellEditorValidator() {
244
245
			public String isValid(final Object value) {
246
				if (value instanceof String) {
247
					final EObject element = getParserElement();
248
					final IParser parser = getParser();
249
					try {
250
						IParserEditStatus valid = (IParserEditStatus) getEditingDomain().runExclusive(new RunnableWithResult.Impl() {
251
252
							public void run() {
253
								setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value));
254
							}
255
						});
256
						return valid.getCode() == ParserEditStatus.EDITABLE ? null : valid.getMessage();
257
					} catch (InterruptedException ie) {
258
						ie.printStackTrace();
259
					}
260
				}
261
262
				// shouldn't get here
263
				return null;
264
			}
265
		};
266
	}
267
268
	/**
269
	 * @generated
270
	 */
271
	public IContentAssistProcessor getCompletionProcessor() {
272
		if (getParser() == null) {
273
			return null;
274
		}
275
		return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement()));
276
	}
277
278
	/**
279
	 * @generated
280
	 */
281
	public ParserOptions getParserOptions() {
282
		return ParserOptions.NONE;
283
	}
284
285
	/**
286
	 * @generated
287
	 */
288
	public IParser getParser() {
289
		if (parser == null) {
290
			String parserHint = ((View) getModel()).getType();
291
			ParserHintAdapter hintAdapter = new ParserHintAdapter(getParserElement(), parserHint) {
292
293
				public Object getAdapter(Class adapter) {
294
					if (IElementType.class.equals(adapter)) {
295
						return UMLElementTypes.Enumeration_3011;
296
					}
297
					return super.getAdapter(adapter);
298
				}
299
			};
300
			parser = ParserService.getInstance().getParser(hintAdapter);
301
		}
302
		return parser;
303
	}
304
305
	/**
306
	 * @generated
307
	 */
308
	protected DirectEditManager getManager() {
309
		if (manager == null) {
310
			setManager(new TextDirectEditManager(this, TextDirectEditManager.getTextCellEditorClass(this), UMLEditPartFactory.getTextCellEditorLocator(this)));
311
		}
312
		return manager;
313
	}
314
315
	/**
316
	 * @generated
317
	 */
318
	protected void setManager(DirectEditManager manager) {
319
		this.manager = manager;
320
	}
321
322
	/**
323
	 * @generated
324
	 */
325
	protected void performDirectEdit() {
326
		getManager().show();
327
	}
328
329
	/**
330
	 * @generated
331
	 */
332
	protected void performDirectEdit(Point eventLocation) {
333
		if (getManager().getClass() == TextDirectEditManager.class) {
334
			((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint());
335
		}
336
	}
337
338
	/**
339
	 * @generated
340
	 */
341
	private void performDirectEdit(char initialCharacter) {
342
		if (getManager() instanceof TextDirectEditManager) {
343
			((TextDirectEditManager) getManager()).show(initialCharacter);
344
		} else {
345
			performDirectEdit();
346
		}
347
	}
348
349
	/**
350
	 * @generated
351
	 */
352
	protected void performDirectEditRequest(Request request) {
353
		final Request theRequest = request;
354
		try {
355
			getEditingDomain().runExclusive(new Runnable() {
356
357
				public void run() {
358
					if (isActive() && isEditable()) {
359
						if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) {
360
							Character initialChar = (Character) theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR);
361
							performDirectEdit(initialChar.charValue());
362
						} else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) {
363
							DirectEditRequest editRequest = (DirectEditRequest) theRequest;
364
							performDirectEdit(editRequest.getLocation());
365
						} else {
366
							performDirectEdit();
367
						}
368
					}
369
				}
370
			});
371
		} catch (InterruptedException e) {
372
			e.printStackTrace();
373
		}
374
	}
375
376
	/**
377
	 * @generated
378
	 */
379
	protected void refreshVisuals() {
380
		super.refreshVisuals();
381
		refreshLabel();
382
		refreshFont();
383
		refreshFontColor();
384
		refreshUnderline();
385
		refreshStrikeThrough();
386
	}
387
388
	/**
389
	 * @generated
390
	 */
391
	protected void refreshLabel() {
392
		setLabelTextHelper(getFigure(), getLabelText());
393
		setLabelIconHelper(getFigure(), getLabelIcon());
394
		Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
395
		if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) {
396
			((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback();
397
		}
398
	}
399
400
	/**
401
	 * @generated
402
	 */
403
	protected void refreshUnderline() {
404
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
405
		if (style != null && getFigure() instanceof WrapLabel) {
406
			((WrapLabel) getFigure()).setTextUnderline(style.isUnderline());
407
		}
408
	}
409
410
	/**
411
	 * @generated
412
	 */
413
	protected void refreshStrikeThrough() {
414
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
415
		if (style != null && getFigure() instanceof WrapLabel) {
416
			((WrapLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough());
417
		}
418
	}
419
420
	/**
421
	 * @generated
422
	 */
423
	protected void refreshFont() {
424
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
425
		if (style != null) {
426
			FontData fontData = new FontData(style.getFontName(), style.getFontHeight(), (style.isBold() ? SWT.BOLD : SWT.NORMAL) | (style.isItalic() ? SWT.ITALIC : SWT.NORMAL));
427
			setFont(fontData);
428
		}
429
	}
430
431
	/**
432
	 * @generated
433
	 */
434
	protected void setFontColor(Color color) {
435
		getFigure().setForegroundColor(color);
436
	}
437
438
	/**
439
	 * @generated
440
	 */
441
	protected void addSemanticListeners() {
442
		if (getParser() instanceof ISemanticParser) {
443
			EObject element = resolveSemanticElement();
444
			parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element);
445
			for (int i = 0; i < parserElements.size(); i++) {
446
				addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$
447
			}
448
		} else {
449
			super.addSemanticListeners();
450
		}
451
	}
452
453
	/**
454
	 * @generated
455
	 */
456
	protected void removeSemanticListeners() {
457
		if (parserElements != null) {
458
			for (int i = 0; i < parserElements.size(); i++) {
459
				removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$
460
			}
461
		} else {
462
			super.removeSemanticListeners();
463
		}
464
	}
465
466
	/**
467
	 * @generated
468
	 */
469
	protected AccessibleEditPart getAccessibleEditPart() {
470
		if (accessibleEP == null) {
471
			accessibleEP = new AccessibleGraphicalEditPart() {
472
473
				public void getName(AccessibleEvent e) {
474
					e.result = getLabelTextHelper(getFigure());
475
				}
476
			};
477
		}
478
		return accessibleEP;
479
	}
480
481
	/**
482
	 * @generated
483
	 */
484
	private View getFontStyleOwnerView() {
485
		return getPrimaryView();
486
	}
487
488
	/**
489
	 * @generated
490
	 */
491
	protected void addNotationalListeners() {
492
		super.addNotationalListeners();
493
		addListenerFilter("PrimaryView", this, getPrimaryView()); //$NON-NLS-1$
494
	}
495
496
	/**
497
	 * @generated
498
	 */
499
	protected void removeNotationalListeners() {
500
		super.removeNotationalListeners();
501
		removeListenerFilter("PrimaryView"); //$NON-NLS-1$
502
	}
503
504
	/**
505
	 * @generated
506
	 */
507
	protected void handleNotificationEvent(Notification event) {
508
		Object feature = event.getFeature();
509
		if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) {
510
			Integer c = (Integer) event.getNewValue();
511
			setFontColor(DiagramColorRegistry.getInstance().getColor(c));
512
		} else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) {
513
			refreshUnderline();
514
		} else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) {
515
			refreshStrikeThrough();
516
		} else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature)
517
				|| NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) {
518
			refreshFont();
519
		} else {
520
			if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) {
521
				refreshLabel();
522
			}
523
			if (getParser() instanceof ISemanticParser) {
524
				ISemanticParser modelParser = (ISemanticParser) getParser();
525
				if (modelParser.areSemanticElementsAffected(null, event)) {
526
					removeSemanticListeners();
527
					if (resolveSemanticElement() != null) {
528
						addSemanticListeners();
529
					}
530
					refreshLabel();
531
				}
532
			}
533
		}
534
		super.handleNotificationEvent(event);
535
	}
536
537
	/**
538
	 * @generated
539
	 */
540
	protected IFigure createFigure() {
541
		IFigure label = createFigurePrim();
542
		defaultText = getLabelTextHelper(label);
543
		return label;
544
	}
545
546
	/**
547
	 * @generated
548
	 */
549
	protected IFigure createFigurePrim() {
550
		return new WrapLabel();
551
	}
552
553
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/parts/PropertyNameEditPart.java (+533 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.parts;
2
3
import java.util.Collections;
4
import java.util.List;
5
6
import org.eclipse.draw2d.ConnectionLocator;
7
import org.eclipse.draw2d.IFigure;
8
import org.eclipse.draw2d.Label;
9
import org.eclipse.draw2d.geometry.Point;
10
import org.eclipse.emf.common.notify.Notification;
11
import org.eclipse.emf.ecore.EObject;
12
import org.eclipse.emf.transaction.RunnableWithResult;
13
import org.eclipse.gef.AccessibleEditPart;
14
import org.eclipse.gef.EditPolicy;
15
import org.eclipse.gef.Request;
16
import org.eclipse.gef.requests.DirectEditRequest;
17
import org.eclipse.gef.tools.DirectEditManager;
18
import org.eclipse.gmf.runtime.common.ui.services.parser.IParser;
19
import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus;
20
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserEditStatus;
21
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions;
22
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserService;
23
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
24
import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart;
25
import org.eclipse.gmf.runtime.diagram.ui.editparts.LabelEditPart;
26
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy;
27
import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry;
28
import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants;
29
import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager;
30
import org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel;
31
import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
32
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
33
import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser;
34
import org.eclipse.gmf.runtime.emf.ui.services.parser.ParserHintAdapter;
35
import org.eclipse.gmf.runtime.notation.FontStyle;
36
import org.eclipse.gmf.runtime.notation.NotationPackage;
37
import org.eclipse.gmf.runtime.notation.View;
38
import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
39
import org.eclipse.jface.viewers.ICellEditorValidator;
40
import org.eclipse.swt.SWT;
41
import org.eclipse.swt.accessibility.AccessibleEvent;
42
import org.eclipse.swt.graphics.Color;
43
import org.eclipse.swt.graphics.FontData;
44
import org.eclipse.swt.graphics.Image;
45
import org.eclipse.uml2.diagram.clazz.edit.policies.UMLTextSelectionEditPolicy;
46
import org.eclipse.uml2.diagram.clazz.part.UMLVisualIDRegistry;
47
import org.eclipse.uml2.diagram.clazz.providers.UMLElementTypes;
48
49
/**
50
 * @generated
51
 */
52
public class PropertyNameEditPart extends LabelEditPart implements ITextAwareEditPart {
53
54
	/**
55
	 * @generated
56
	 */
57
	public static final int VISUAL_ID = 6002;
58
59
	/**
60
	 * @generated
61
	 */
62
	private DirectEditManager manager;
63
64
	/**
65
	 * @generated
66
	 */
67
	private IParser parser;
68
69
	/**
70
	 * @generated
71
	 */
72
	private List parserElements;
73
74
	/**
75
	 * @generated
76
	 */
77
	private String defaultText;
78
79
	/**
80
	 * @generated
81
	 */
82
	static {
83
		registerSnapBackPosition(UMLVisualIDRegistry.getType(PropertyNameEditPart.VISUAL_ID), new Point(0, 40));
84
	}
85
86
	/**
87
	 * @generated
88
	 */
89
	public PropertyNameEditPart(View view) {
90
		super(view);
91
	}
92
93
	/**
94
	 * @generated
95
	 */
96
	protected void createDefaultEditPolicies() {
97
		super.createDefaultEditPolicies();
98
		installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy());
99
100
	}
101
102
	/**
103
	 * @generated
104
	 */
105
	public int getKeyPoint() {
106
		return ConnectionLocator.MIDDLE;
107
	}
108
109
	/**
110
	 * @generated
111
	 */
112
	protected String getLabelTextHelper(IFigure figure) {
113
		if (figure instanceof WrapLabel) {
114
			return ((WrapLabel) figure).getText();
115
		} else {
116
			return ((Label) figure).getText();
117
		}
118
	}
119
120
	/**
121
	 * @generated
122
	 */
123
	protected void setLabelTextHelper(IFigure figure, String text) {
124
		if (figure instanceof WrapLabel) {
125
			((WrapLabel) figure).setText(text);
126
		} else {
127
			((Label) figure).setText(text);
128
		}
129
	}
130
131
	/**
132
	 * @generated
133
	 */
134
	protected Image getLabelIconHelper(IFigure figure) {
135
		if (figure instanceof WrapLabel) {
136
			return ((WrapLabel) figure).getIcon();
137
		} else {
138
			return ((Label) figure).getIcon();
139
		}
140
	}
141
142
	/**
143
	 * @generated
144
	 */
145
	protected void setLabelIconHelper(IFigure figure, Image icon) {
146
		if (figure instanceof WrapLabel) {
147
			((WrapLabel) figure).setIcon(icon);
148
		} else {
149
			((Label) figure).setIcon(icon);
150
		}
151
	}
152
153
	/**
154
	 * @generated
155
	 */
156
	public void setLabel(IFigure figure) {
157
		unregisterVisuals();
158
		setFigure(figure);
159
		defaultText = getLabelTextHelper(figure);
160
		registerVisuals();
161
		refreshVisuals();
162
	}
163
164
	/**
165
	 * @generated
166
	 */
167
	protected List getModelChildren() {
168
		return Collections.EMPTY_LIST;
169
	}
170
171
	/**
172
	 * @generated
173
	 */
174
	public IGraphicalEditPart getChildBySemanticHint(String semanticHint) {
175
		return null;
176
	}
177
178
	/**
179
	 * @generated
180
	 */
181
	protected EObject getParserElement() {
182
		EObject element = resolveSemanticElement();
183
		return element != null ? element : (View) getModel();
184
	}
185
186
	/**
187
	 * @generated
188
	 */
189
	protected Image getLabelIcon() {
190
		return null;
191
	}
192
193
	/**
194
	 * @generated
195
	 */
196
	protected String getLabelText() {
197
		String text = null;
198
		if (getParser() != null) {
199
			text = getParser().getPrintString(new EObjectAdapter(getParserElement()), getParserOptions().intValue());
200
		}
201
		if (text == null || text.length() == 0) {
202
			text = defaultText;
203
		}
204
		return text;
205
	}
206
207
	/**
208
	 * @generated
209
	 */
210
	public void setLabelText(String text) {
211
		setLabelTextHelper(getFigure(), text);
212
		Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
213
		if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) {
214
			((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback();
215
		}
216
	}
217
218
	/**
219
	 * @generated
220
	 */
221
	public String getEditText() {
222
		if (getParser() == null) {
223
			return ""; //$NON-NLS-1$
224
		}
225
		return getParser().getEditString(new EObjectAdapter(getParserElement()), getParserOptions().intValue());
226
	}
227
228
	/**
229
	 * @generated
230
	 */
231
	protected boolean isEditable() {
232
		return getEditText() != null;
233
	}
234
235
	/**
236
	 * @generated
237
	 */
238
	public ICellEditorValidator getEditTextValidator() {
239
		return new ICellEditorValidator() {
240
241
			public String isValid(final Object value) {
242
				if (value instanceof String) {
243
					final EObject element = getParserElement();
244
					final IParser parser = getParser();
245
					try {
246
						IParserEditStatus valid = (IParserEditStatus) getEditingDomain().runExclusive(new RunnableWithResult.Impl() {
247
248
							public void run() {
249
								setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value));
250
							}
251
						});
252
						return valid.getCode() == ParserEditStatus.EDITABLE ? null : valid.getMessage();
253
					} catch (InterruptedException ie) {
254
						ie.printStackTrace();
255
					}
256
				}
257
258
				// shouldn't get here
259
				return null;
260
			}
261
		};
262
	}
263
264
	/**
265
	 * @generated
266
	 */
267
	public IContentAssistProcessor getCompletionProcessor() {
268
		if (getParser() == null) {
269
			return null;
270
		}
271
		return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement()));
272
	}
273
274
	/**
275
	 * @generated
276
	 */
277
	public ParserOptions getParserOptions() {
278
		return ParserOptions.NONE;
279
	}
280
281
	/**
282
	 * @generated
283
	 */
284
	public IParser getParser() {
285
		if (parser == null) {
286
			String parserHint = ((View) getModel()).getType();
287
			ParserHintAdapter hintAdapter = new ParserHintAdapter(getParserElement(), parserHint) {
288
289
				public Object getAdapter(Class adapter) {
290
					if (IElementType.class.equals(adapter)) {
291
						return UMLElementTypes.Property_4003;
292
					}
293
					return super.getAdapter(adapter);
294
				}
295
			};
296
			parser = ParserService.getInstance().getParser(hintAdapter);
297
		}
298
		return parser;
299
	}
300
301
	/**
302
	 * @generated
303
	 */
304
	protected DirectEditManager getManager() {
305
		if (manager == null) {
306
			setManager(new TextDirectEditManager(this, TextDirectEditManager.getTextCellEditorClass(this), UMLEditPartFactory.getTextCellEditorLocator(this)));
307
		}
308
		return manager;
309
	}
310
311
	/**
312
	 * @generated
313
	 */
314
	protected void setManager(DirectEditManager manager) {
315
		this.manager = manager;
316
	}
317
318
	/**
319
	 * @generated
320
	 */
321
	protected void performDirectEdit() {
322
		getManager().show();
323
	}
324
325
	/**
326
	 * @generated
327
	 */
328
	protected void performDirectEdit(Point eventLocation) {
329
		if (getManager().getClass() == TextDirectEditManager.class) {
330
			((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint());
331
		}
332
	}
333
334
	/**
335
	 * @generated
336
	 */
337
	private void performDirectEdit(char initialCharacter) {
338
		if (getManager() instanceof TextDirectEditManager) {
339
			((TextDirectEditManager) getManager()).show(initialCharacter);
340
		} else {
341
			performDirectEdit();
342
		}
343
	}
344
345
	/**
346
	 * @generated
347
	 */
348
	protected void performDirectEditRequest(Request request) {
349
		final Request theRequest = request;
350
		try {
351
			getEditingDomain().runExclusive(new Runnable() {
352
353
				public void run() {
354
					if (isActive() && isEditable()) {
355
						if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) {
356
							Character initialChar = (Character) theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR);
357
							performDirectEdit(initialChar.charValue());
358
						} else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) {
359
							DirectEditRequest editRequest = (DirectEditRequest) theRequest;
360
							performDirectEdit(editRequest.getLocation());
361
						} else {
362
							performDirectEdit();
363
						}
364
					}
365
				}
366
			});
367
		} catch (InterruptedException e) {
368
			e.printStackTrace();
369
		}
370
	}
371
372
	/**
373
	 * @generated
374
	 */
375
	protected void refreshVisuals() {
376
		super.refreshVisuals();
377
		refreshLabel();
378
		refreshFont();
379
		refreshFontColor();
380
		refreshUnderline();
381
		refreshStrikeThrough();
382
	}
383
384
	/**
385
	 * @generated
386
	 */
387
	protected void refreshLabel() {
388
		setLabelTextHelper(getFigure(), getLabelText());
389
		setLabelIconHelper(getFigure(), getLabelIcon());
390
		Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
391
		if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) {
392
			((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback();
393
		}
394
	}
395
396
	/**
397
	 * @generated
398
	 */
399
	protected void refreshUnderline() {
400
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
401
		if (style != null && getFigure() instanceof WrapLabel) {
402
			((WrapLabel) getFigure()).setTextUnderline(style.isUnderline());
403
		}
404
	}
405
406
	/**
407
	 * @generated
408
	 */
409
	protected void refreshStrikeThrough() {
410
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
411
		if (style != null && getFigure() instanceof WrapLabel) {
412
			((WrapLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough());
413
		}
414
	}
415
416
	/**
417
	 * @generated
418
	 */
419
	protected void refreshFont() {
420
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
421
		if (style != null) {
422
			FontData fontData = new FontData(style.getFontName(), style.getFontHeight(), (style.isBold() ? SWT.BOLD : SWT.NORMAL) | (style.isItalic() ? SWT.ITALIC : SWT.NORMAL));
423
			setFont(fontData);
424
		}
425
	}
426
427
	/**
428
	 * @generated
429
	 */
430
	protected void setFontColor(Color color) {
431
		getFigure().setForegroundColor(color);
432
	}
433
434
	/**
435
	 * @generated
436
	 */
437
	protected void addSemanticListeners() {
438
		if (getParser() instanceof ISemanticParser) {
439
			EObject element = resolveSemanticElement();
440
			parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element);
441
			for (int i = 0; i < parserElements.size(); i++) {
442
				addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$
443
			}
444
		} else {
445
			super.addSemanticListeners();
446
		}
447
	}
448
449
	/**
450
	 * @generated
451
	 */
452
	protected void removeSemanticListeners() {
453
		if (parserElements != null) {
454
			for (int i = 0; i < parserElements.size(); i++) {
455
				removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$
456
			}
457
		} else {
458
			super.removeSemanticListeners();
459
		}
460
	}
461
462
	/**
463
	 * @generated
464
	 */
465
	protected AccessibleEditPart getAccessibleEditPart() {
466
		if (accessibleEP == null) {
467
			accessibleEP = new AccessibleGraphicalEditPart() {
468
469
				public void getName(AccessibleEvent e) {
470
					e.result = getLabelTextHelper(getFigure());
471
				}
472
			};
473
		}
474
		return accessibleEP;
475
	}
476
477
	/**
478
	 * @generated
479
	 */
480
	private View getFontStyleOwnerView() {
481
		return getPrimaryView();
482
	}
483
484
	/**
485
	 * @generated
486
	 */
487
	protected void handleNotificationEvent(Notification event) {
488
		Object feature = event.getFeature();
489
		if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) {
490
			Integer c = (Integer) event.getNewValue();
491
			setFontColor(DiagramColorRegistry.getInstance().getColor(c));
492
		} else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) {
493
			refreshUnderline();
494
		} else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) {
495
			refreshStrikeThrough();
496
		} else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature)
497
				|| NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) {
498
			refreshFont();
499
		} else {
500
			if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) {
501
				refreshLabel();
502
			}
503
			if (getParser() instanceof ISemanticParser) {
504
				ISemanticParser modelParser = (ISemanticParser) getParser();
505
				if (modelParser.areSemanticElementsAffected(null, event)) {
506
					removeSemanticListeners();
507
					if (resolveSemanticElement() != null) {
508
						addSemanticListeners();
509
					}
510
					refreshLabel();
511
				}
512
			}
513
		}
514
		super.handleNotificationEvent(event);
515
	}
516
517
	/**
518
	 * @generated
519
	 */
520
	protected IFigure createFigure() {
521
		IFigure label = createFigurePrim();
522
		defaultText = getLabelTextHelper(label);
523
		return label;
524
	}
525
526
	/**
527
	 * @generated
528
	 */
529
	protected IFigure createFigurePrim() {
530
		return new WrapLabel();
531
	}
532
533
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/policies/PrimitiveTypeItemSemanticEditPolicy.java (+455 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.policies;
2
3
import org.eclipse.emf.ecore.EAnnotation;
4
import org.eclipse.emf.ecore.EClass;
5
import org.eclipse.emf.ecore.EObject;
6
import org.eclipse.gef.commands.Command;
7
import org.eclipse.gef.commands.UnexecutableCommand;
8
import org.eclipse.gmf.runtime.emf.type.core.commands.CreateRelationshipCommand;
9
import org.eclipse.gmf.runtime.emf.type.core.commands.DestroyElementCommand;
10
import org.eclipse.gmf.runtime.emf.type.core.commands.SetValueCommand;
11
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest;
12
import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest;
13
import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest;
14
import org.eclipse.gmf.runtime.notation.View;
15
import org.eclipse.uml2.diagram.clazz.providers.UMLElementTypes;
16
import org.eclipse.uml2.uml.Association;
17
import org.eclipse.uml2.uml.Classifier;
18
import org.eclipse.uml2.uml.Constraint;
19
import org.eclipse.uml2.uml.Dependency;
20
import org.eclipse.uml2.uml.Generalization;
21
import org.eclipse.uml2.uml.NamedElement;
22
import org.eclipse.uml2.uml.Property;
23
import org.eclipse.uml2.uml.Type;
24
import org.eclipse.uml2.uml.UMLPackage;
25
import org.eclipse.uml2.uml.Usage;
26
27
/**
28
 * @generated
29
 */
30
public class PrimitiveTypeItemSemanticEditPolicy extends UMLBaseItemSemanticEditPolicy {
31
32
	/**
33
	 * @generated
34
	 */
35
	protected Command getDestroyElementCommand(DestroyElementRequest req) {
36
		return getMSLWrapper(new DestroyElementCommand(req) {
37
38
			protected EObject getElementToDestroy() {
39
				View view = (View) getHost().getModel();
40
				EAnnotation annotation = view.getEAnnotation("Shortcut"); //$NON-NLS-1$
41
				if (annotation != null) {
42
					return view;
43
				}
44
				return super.getElementToDestroy();
45
			}
46
47
		});
48
	}
49
50
	/**
51
	 * @generated
52
	 */
53
	protected Command getCreateRelationshipCommand(CreateRelationshipRequest req) {
54
		if (UMLElementTypes.Generalization_4001 == req.getElementType()) {
55
			return req.getTarget() == null ? getCreateStartOutgoingGeneralization4001Command(req) : getCreateCompleteIncomingGeneralization4001Command(req);
56
		}
57
		if (UMLElementTypes.Dependency_4002 == req.getElementType()) {
58
			return req.getTarget() == null ? getCreateStartOutgoingDependency4002Command(req) : getCreateCompleteIncomingDependency4002Command(req);
59
		}
60
		if (UMLElementTypes.Property_4003 == req.getElementType()) {
61
			return req.getTarget() == null ? null : getCreateCompleteIncomingProperty4003Command(req);
62
		}
63
		if (UMLElementTypes.ConstraintConstrainedElement_4004 == req.getElementType()) {
64
			return req.getTarget() == null ? null : getCreateCompleteIncomingConstraint_ConstrainedElement4004Command(req);
65
		}
66
		if (UMLElementTypes.Association_4005 == req.getElementType()) {
67
			return req.getTarget() == null ? getCreateStartOutgoingAssociation4005Command(req) : getCreateCompleteIncomingAssociation4005Command(req);
68
		}
69
		if (UMLElementTypes.DependencySupplier_4006 == req.getElementType()) {
70
			return req.getTarget() == null ? null : getCreateCompleteIncomingDependency_Supplier4006Command(req);
71
		}
72
		if (UMLElementTypes.DependencyClient_4007 == req.getElementType()) {
73
			return req.getTarget() == null ? null : getCreateCompleteIncomingDependency_Client4007Command(req);
74
		}
75
		if (UMLElementTypes.Usage_4009 == req.getElementType()) {
76
			return req.getTarget() == null ? getCreateStartOutgoingUsage4009Command(req) : getCreateCompleteIncomingUsage4009Command(req);
77
		}
78
		return super.getCreateRelationshipCommand(req);
79
	}
80
81
	/**
82
	 * @generated
83
	 */
84
	protected Command getCreateStartOutgoingGeneralization4001Command(CreateRelationshipRequest req) {
85
		return new Command() {
86
		};
87
	}
88
89
	/**
90
	 * @generated
91
	 */
92
	protected Command getCreateCompleteIncomingGeneralization4001Command(CreateRelationshipRequest req) {
93
		if (!(req.getSource() instanceof Classifier)) {
94
			return UnexecutableCommand.INSTANCE;
95
		}
96
		final Classifier element = (Classifier) req.getSource();
97
		if (req.getContainmentFeature() == null) {
98
			req.setContainmentFeature(UMLPackage.eINSTANCE.getClassifier_Generalization());
99
		}
100
		return getMSLWrapper(new CreateIncomingGeneralization4001Command(req) {
101
102
			protected EObject getElementToEdit() {
103
				return element;
104
			}
105
		});
106
	}
107
108
	/**
109
	 * @generated
110
	 */
111
	private static class CreateIncomingGeneralization4001Command extends CreateRelationshipCommand {
112
113
		/**
114
		 * @generated
115
		 */
116
		public CreateIncomingGeneralization4001Command(CreateRelationshipRequest req) {
117
			super(req);
118
		}
119
120
		/**
121
		 * @generated
122
		 */
123
		protected EClass getEClassToEdit() {
124
			return UMLPackage.eINSTANCE.getClassifier();
125
		};
126
127
		/**
128
		 * @generated
129
		 */
130
		protected void setElementToEdit(EObject element) {
131
			throw new UnsupportedOperationException();
132
		}
133
134
		/**
135
		 * @generated
136
		 */
137
		protected EObject doDefaultElementCreation() {
138
			Generalization newElement = (Generalization) super.doDefaultElementCreation();
139
			if (newElement != null) {
140
				newElement.setGeneral((Classifier) getTarget());
141
			}
142
			return newElement;
143
		}
144
	}
145
146
	/**
147
	 * @generated
148
	 */
149
	protected Command getCreateStartOutgoingDependency4002Command(CreateRelationshipRequest req) {
150
		return new Command() {
151
		};
152
	}
153
154
	/**
155
	 * @generated
156
	 */
157
	protected Command getCreateCompleteIncomingDependency4002Command(CreateRelationshipRequest req) {
158
		if (!(req.getSource() instanceof NamedElement)) {
159
			return UnexecutableCommand.INSTANCE;
160
		}
161
		final org.eclipse.uml2.uml.Package element = (org.eclipse.uml2.uml.Package) getRelationshipContainer(req.getSource(), UMLPackage.eINSTANCE.getPackage(), req.getElementType());
162
		if (element == null) {
163
			return UnexecutableCommand.INSTANCE;
164
		}
165
		if (req.getContainmentFeature() == null) {
166
			req.setContainmentFeature(UMLPackage.eINSTANCE.getPackage_PackagedElement());
167
		}
168
		return getMSLWrapper(new CreateIncomingDependency4002Command(req) {
169
170
			protected EObject getElementToEdit() {
171
				return element;
172
			}
173
		});
174
	}
175
176
	/**
177
	 * @generated
178
	 */
179
	private static class CreateIncomingDependency4002Command extends CreateRelationshipCommand {
180
181
		/**
182
		 * @generated
183
		 */
184
		public CreateIncomingDependency4002Command(CreateRelationshipRequest req) {
185
			super(req);
186
		}
187
188
		/**
189
		 * @generated
190
		 */
191
		protected EClass getEClassToEdit() {
192
			return UMLPackage.eINSTANCE.getPackage();
193
		};
194
195
		/**
196
		 * @generated
197
		 */
198
		protected void setElementToEdit(EObject element) {
199
			throw new UnsupportedOperationException();
200
		}
201
202
		/**
203
		 * @generated
204
		 */
205
		protected EObject doDefaultElementCreation() {
206
			Dependency newElement = (Dependency) super.doDefaultElementCreation();
207
			if (newElement != null) {
208
				newElement.getSuppliers().add((NamedElement) getTarget());
209
				newElement.getClients().add((NamedElement) getSource());
210
			}
211
			return newElement;
212
		}
213
	}
214
215
	/**
216
	 * @generated
217
	 */
218
	protected Command getCreateCompleteIncomingProperty4003Command(CreateRelationshipRequest req) {
219
		if (!(req.getSource() instanceof Association)) {
220
			return UnexecutableCommand.INSTANCE;
221
		}
222
		final Association element = (Association) req.getSource();
223
		if (req.getContainmentFeature() == null) {
224
			req.setContainmentFeature(UMLPackage.eINSTANCE.getAssociation_OwnedEnd());
225
		}
226
		return getMSLWrapper(new CreateIncomingProperty4003Command(req) {
227
228
			protected EObject getElementToEdit() {
229
				return element;
230
			}
231
		});
232
	}
233
234
	/**
235
	 * @generated
236
	 */
237
	private static class CreateIncomingProperty4003Command extends CreateRelationshipCommand {
238
239
		/**
240
		 * @generated
241
		 */
242
		public CreateIncomingProperty4003Command(CreateRelationshipRequest req) {
243
			super(req);
244
		}
245
246
		/**
247
		 * @generated
248
		 */
249
		protected EClass getEClassToEdit() {
250
			return UMLPackage.eINSTANCE.getAssociation();
251
		};
252
253
		/**
254
		 * @generated
255
		 */
256
		protected void setElementToEdit(EObject element) {
257
			throw new UnsupportedOperationException();
258
		}
259
260
		/**
261
		 * @generated
262
		 */
263
		protected EObject doDefaultElementCreation() {
264
			Property newElement = (Property) super.doDefaultElementCreation();
265
			if (newElement != null) {
266
				newElement.setType((Type) getTarget());
267
			}
268
			return newElement;
269
		}
270
	}
271
272
	/**
273
	 * @generated
274
	 */
275
	protected Command getCreateCompleteIncomingConstraint_ConstrainedElement4004Command(CreateRelationshipRequest req) {
276
		if (!(req.getSource() instanceof Constraint)) {
277
			return UnexecutableCommand.INSTANCE;
278
		}
279
		Constraint element = (Constraint) req.getSource();
280
		if (element.getConstrainedElements().contains(req.getTarget())) {
281
			return UnexecutableCommand.INSTANCE;
282
		}
283
		SetRequest setReq = new SetRequest(req.getSource(), UMLPackage.eINSTANCE.getConstraint_ConstrainedElement(), req.getTarget());
284
		return getMSLWrapper(new SetValueCommand(setReq));
285
	}
286
287
	/**
288
	 * @generated
289
	 */
290
	protected Command getCreateStartOutgoingAssociation4005Command(CreateRelationshipRequest req) {
291
		return new Command() {
292
		};
293
	}
294
295
	/**
296
	 * @generated
297
	 */
298
	protected Command getCreateCompleteIncomingAssociation4005Command(CreateRelationshipRequest req) {
299
		if (!(req.getSource() instanceof Type)) {
300
			return UnexecutableCommand.INSTANCE;
301
		}
302
		final org.eclipse.uml2.uml.Package element = (org.eclipse.uml2.uml.Package) getRelationshipContainer(req.getSource(), UMLPackage.eINSTANCE.getPackage(), req.getElementType());
303
		if (element == null) {
304
			return UnexecutableCommand.INSTANCE;
305
		}
306
		if (req.getContainmentFeature() == null) {
307
			req.setContainmentFeature(UMLPackage.eINSTANCE.getPackage_PackagedElement());
308
		}
309
		return getMSLWrapper(new CreateIncomingAssociation4005Command(req) {
310
311
			protected EObject getElementToEdit() {
312
				return element;
313
			}
314
		});
315
	}
316
317
	/**
318
	 * @generated NOT
319
	 */
320
	private static class CreateIncomingAssociation4005Command extends CreateAssociationCommand {
321
322
		/**
323
		 * @generated
324
		 */
325
		public CreateIncomingAssociation4005Command(CreateRelationshipRequest req) {
326
			super(req);
327
		}
328
329
		/**
330
		 * @generated
331
		 */
332
		protected EClass getEClassToEdit() {
333
			return UMLPackage.eINSTANCE.getPackage();
334
		};
335
336
		/**
337
		 * @generated
338
		 */
339
		protected void setElementToEdit(EObject element) {
340
			throw new UnsupportedOperationException();
341
		}
342
343
		/**
344
		 * @generated NOT
345
		 */
346
		protected EObject doDefaultElementCreation() {
347
			return super.doDefaultElementCreation();
348
		}
349
	}
350
351
	/**
352
	 * @generated
353
	 */
354
	protected Command getCreateCompleteIncomingDependency_Supplier4006Command(CreateRelationshipRequest req) {
355
		if (!(req.getSource() instanceof Dependency)) {
356
			return UnexecutableCommand.INSTANCE;
357
		}
358
		Dependency element = (Dependency) req.getSource();
359
		if (element.getSuppliers().contains(req.getTarget())) {
360
			return UnexecutableCommand.INSTANCE;
361
		}
362
		SetRequest setReq = new SetRequest(req.getSource(), UMLPackage.eINSTANCE.getDependency_Supplier(), req.getTarget());
363
		return getMSLWrapper(new SetValueCommand(setReq));
364
	}
365
366
	/**
367
	 * @generated
368
	 */
369
	protected Command getCreateCompleteIncomingDependency_Client4007Command(CreateRelationshipRequest req) {
370
		if (!(req.getSource() instanceof Dependency)) {
371
			return UnexecutableCommand.INSTANCE;
372
		}
373
		Dependency element = (Dependency) req.getSource();
374
		if (element.getClients().contains(req.getTarget())) {
375
			return UnexecutableCommand.INSTANCE;
376
		}
377
		SetRequest setReq = new SetRequest(req.getSource(), UMLPackage.eINSTANCE.getDependency_Client(), req.getTarget());
378
		return getMSLWrapper(new SetValueCommand(setReq));
379
	}
380
381
	/**
382
	 * @generated
383
	 */
384
	protected Command getCreateStartOutgoingUsage4009Command(CreateRelationshipRequest req) {
385
		if (!UMLBaseItemSemanticEditPolicy.LinkConstraints.Usage_4009.canCreateLink(req, false)) {
386
			return UnexecutableCommand.INSTANCE;
387
		}
388
		return new Command() {
389
		};
390
	}
391
392
	/**
393
	 * @generated
394
	 */
395
	protected Command getCreateCompleteIncomingUsage4009Command(CreateRelationshipRequest req) {
396
		if (!(req.getSource() instanceof NamedElement)) {
397
			return UnexecutableCommand.INSTANCE;
398
		}
399
		final org.eclipse.uml2.uml.Package element = (org.eclipse.uml2.uml.Package) getRelationshipContainer(req.getSource(), UMLPackage.eINSTANCE.getPackage(), req.getElementType());
400
		if (element == null) {
401
			return UnexecutableCommand.INSTANCE;
402
		}
403
		if (!UMLBaseItemSemanticEditPolicy.LinkConstraints.Usage_4009.canCreateLink(req, false)) {
404
			return UnexecutableCommand.INSTANCE;
405
		}
406
		if (req.getContainmentFeature() == null) {
407
			req.setContainmentFeature(UMLPackage.eINSTANCE.getPackage_PackagedElement());
408
		}
409
		return getMSLWrapper(new CreateIncomingUsage4009Command(req) {
410
411
			protected EObject getElementToEdit() {
412
				return element;
413
			}
414
		});
415
	}
416
417
	/**
418
	 * @generated
419
	 */
420
	private static class CreateIncomingUsage4009Command extends CreateRelationshipCommand {
421
422
		/**
423
		 * @generated
424
		 */
425
		public CreateIncomingUsage4009Command(CreateRelationshipRequest req) {
426
			super(req);
427
		}
428
429
		/**
430
		 * @generated
431
		 */
432
		protected EClass getEClassToEdit() {
433
			return UMLPackage.eINSTANCE.getPackage();
434
		};
435
436
		/**
437
		 * @generated
438
		 */
439
		protected void setElementToEdit(EObject element) {
440
			throw new UnsupportedOperationException();
441
		}
442
443
		/**
444
		 * @generated
445
		 */
446
		protected EObject doDefaultElementCreation() {
447
			Usage newElement = (Usage) super.doDefaultElementCreation();
448
			if (newElement != null) {
449
				newElement.getSuppliers().add((NamedElement) getTarget());
450
				newElement.getClients().add((NamedElement) getSource());
451
			}
452
			return newElement;
453
		}
454
	}
455
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/policies/PrimitiveTypeOperationsCanonicalEditPolicy.java (+52 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.policies;
2
3
import java.util.Iterator;
4
import java.util.LinkedList;
5
import java.util.List;
6
7
import org.eclipse.emf.ecore.EObject;
8
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.CanonicalEditPolicy;
9
import org.eclipse.gmf.runtime.notation.View;
10
import org.eclipse.uml2.diagram.clazz.edit.parts.Operation4EditPart;
11
import org.eclipse.uml2.diagram.clazz.part.UMLVisualIDRegistry;
12
import org.eclipse.uml2.uml.DataType;
13
14
/**
15
 * @generated
16
 */
17
public class PrimitiveTypeOperationsCanonicalEditPolicy extends CanonicalEditPolicy {
18
19
	/**
20
	 * @generated
21
	 */
22
	protected List getSemanticChildrenList() {
23
		List result = new LinkedList();
24
		EObject modelObject = ((View) getHost().getModel()).getElement();
25
		View viewObject = (View) getHost().getModel();
26
		EObject nextValue;
27
		int nodeVID;
28
		for (Iterator values = ((DataType) modelObject).getOwnedOperations().iterator(); values.hasNext();) {
29
			nextValue = (EObject) values.next();
30
			nodeVID = UMLVisualIDRegistry.getNodeVisualID(viewObject, nextValue);
31
			if (Operation4EditPart.VISUAL_ID == nodeVID) {
32
				result.add(nextValue);
33
			}
34
		}
35
		return result;
36
	}
37
38
	/**
39
	 * @generated
40
	 */
41
	protected boolean shouldDeleteView(View view) {
42
		return view.isSetElement() && view.getElement() != null && view.getElement().eIsProxy();
43
	}
44
45
	/**
46
	 * @generated
47
	 */
48
	protected String getDefaultFactoryHint() {
49
		return null;
50
	}
51
52
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/policies/PrimitiveTypeAttributesItemSemanticEditPolicy.java (+73 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.policies;
2
3
import org.eclipse.emf.ecore.EClass;
4
import org.eclipse.emf.ecore.EObject;
5
import org.eclipse.gef.commands.Command;
6
import org.eclipse.gmf.runtime.emf.type.core.commands.CreateElementCommand;
7
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest;
8
import org.eclipse.gmf.runtime.notation.View;
9
import org.eclipse.uml2.diagram.clazz.providers.UMLElementTypes;
10
import org.eclipse.uml2.uml.Property;
11
import org.eclipse.uml2.uml.UMLPackage;
12
13
/**
14
 * @generated
15
 */
16
public class PrimitiveTypeAttributesItemSemanticEditPolicy extends UMLBaseItemSemanticEditPolicy {
17
18
	/**
19
	 * @generated
20
	 */
21
	protected Command getCreateCommand(CreateElementRequest req) {
22
		if (UMLElementTypes.Property_3021 == req.getElementType()) {
23
			if (req.getContainmentFeature() == null) {
24
				req.setContainmentFeature(UMLPackage.eINSTANCE.getDataType_OwnedAttribute());
25
			}
26
			return getMSLWrapper(new CreateProperty_3021Command(req));
27
		}
28
		return super.getCreateCommand(req);
29
	}
30
31
	/**
32
	 * @generated
33
	 */
34
	private static class CreateProperty_3021Command extends CreateElementCommand {
35
36
		/**
37
		 * @generated
38
		 */
39
		public CreateProperty_3021Command(CreateElementRequest req) {
40
			super(req);
41
		}
42
43
		/**
44
		 * @generated
45
		 */
46
		protected EClass getEClassToEdit() {
47
			return UMLPackage.eINSTANCE.getPrimitiveType();
48
		};
49
50
		/**
51
		 * @generated
52
		 */
53
		protected EObject getElementToEdit() {
54
			EObject container = ((CreateElementRequest) getRequest()).getContainer();
55
			if (container instanceof View) {
56
				container = ((View) container).getElement();
57
			}
58
			return container;
59
		}
60
61
		/**
62
		 * @generated
63
		 */
64
		protected EObject doDefaultElementCreation() {
65
			Property newElement = (Property) super.doDefaultElementCreation();
66
			if (newElement != null) {
67
				UMLElementTypes.Initializers.Property_3021.init(newElement);
68
			}
69
			return newElement;
70
		}
71
	}
72
73
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/parts/Operation2EditPart.java (+553 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.parts;
2
3
import java.util.Collections;
4
import java.util.List;
5
6
import org.eclipse.draw2d.IFigure;
7
import org.eclipse.draw2d.Label;
8
import org.eclipse.draw2d.geometry.Point;
9
import org.eclipse.emf.common.notify.Notification;
10
import org.eclipse.emf.ecore.EObject;
11
import org.eclipse.emf.transaction.RunnableWithResult;
12
import org.eclipse.gef.AccessibleEditPart;
13
import org.eclipse.gef.DragTracker;
14
import org.eclipse.gef.EditPolicy;
15
import org.eclipse.gef.Request;
16
import org.eclipse.gef.requests.DirectEditRequest;
17
import org.eclipse.gef.requests.SelectionRequest;
18
import org.eclipse.gef.tools.DirectEditManager;
19
import org.eclipse.gmf.runtime.common.ui.services.parser.IParser;
20
import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus;
21
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserEditStatus;
22
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions;
23
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserService;
24
import org.eclipse.gmf.runtime.diagram.ui.editparts.CompartmentEditPart;
25
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
26
import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart;
27
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
28
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy;
29
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.ListItemComponentEditPolicy;
30
import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry;
31
import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants;
32
import org.eclipse.gmf.runtime.diagram.ui.tools.DragEditPartsTrackerEx;
33
import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager;
34
import org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel;
35
import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
36
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
37
import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser;
38
import org.eclipse.gmf.runtime.emf.ui.services.parser.ParserHintAdapter;
39
import org.eclipse.gmf.runtime.notation.FontStyle;
40
import org.eclipse.gmf.runtime.notation.NotationPackage;
41
import org.eclipse.gmf.runtime.notation.View;
42
import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
43
import org.eclipse.jface.viewers.ICellEditorValidator;
44
import org.eclipse.swt.SWT;
45
import org.eclipse.swt.accessibility.AccessibleEvent;
46
import org.eclipse.swt.graphics.Color;
47
import org.eclipse.swt.graphics.FontData;
48
import org.eclipse.swt.graphics.Image;
49
import org.eclipse.uml2.diagram.clazz.edit.policies.Operation2ItemSemanticEditPolicy;
50
import org.eclipse.uml2.diagram.clazz.edit.policies.UMLTextNonResizableEditPolicy;
51
import org.eclipse.uml2.diagram.clazz.edit.policies.UMLTextSelectionEditPolicy;
52
import org.eclipse.uml2.diagram.clazz.providers.UMLElementTypes;
53
54
/**
55
 * @generated
56
 */
57
public class Operation2EditPart extends CompartmentEditPart implements ITextAwareEditPart {
58
59
	/**
60
	 * @generated
61
	 */
62
	public static final int VISUAL_ID = 3020;
63
64
	/**
65
	 * @generated
66
	 */
67
	private DirectEditManager manager;
68
69
	/**
70
	 * @generated
71
	 */
72
	private IParser parser;
73
74
	/**
75
	 * @generated
76
	 */
77
	private List parserElements;
78
79
	/**
80
	 * @generated
81
	 */
82
	private String defaultText;
83
84
	/**
85
	 * @generated
86
	 */
87
	public Operation2EditPart(View view) {
88
		super(view);
89
	}
90
91
	/**
92
	 * @generated
93
	 */
94
	public DragTracker getDragTracker(Request request) {
95
		if (request instanceof SelectionRequest && ((SelectionRequest) request).getLastButtonPressed() == 3) {
96
			return null;
97
		}
98
		return new DragEditPartsTrackerEx(this);
99
	}
100
101
	/**
102
	 * @generated
103
	 */
104
	protected void createDefaultEditPolicies() {
105
		super.createDefaultEditPolicies();
106
		installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new Operation2ItemSemanticEditPolicy());
107
		installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new UMLTextNonResizableEditPolicy());
108
		installEditPolicy(EditPolicy.COMPONENT_ROLE, new ListItemComponentEditPolicy());
109
		installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy());
110
111
	}
112
113
	/**
114
	 * @generated
115
	 */
116
	protected String getLabelTextHelper(IFigure figure) {
117
		if (figure instanceof WrapLabel) {
118
			return ((WrapLabel) figure).getText();
119
		} else {
120
			return ((Label) figure).getText();
121
		}
122
	}
123
124
	/**
125
	 * @generated
126
	 */
127
	protected void setLabelTextHelper(IFigure figure, String text) {
128
		if (figure instanceof WrapLabel) {
129
			((WrapLabel) figure).setText(text);
130
		} else {
131
			((Label) figure).setText(text);
132
		}
133
	}
134
135
	/**
136
	 * @generated
137
	 */
138
	protected Image getLabelIconHelper(IFigure figure) {
139
		if (figure instanceof WrapLabel) {
140
			return ((WrapLabel) figure).getIcon();
141
		} else {
142
			return ((Label) figure).getIcon();
143
		}
144
	}
145
146
	/**
147
	 * @generated
148
	 */
149
	protected void setLabelIconHelper(IFigure figure, Image icon) {
150
		if (figure instanceof WrapLabel) {
151
			((WrapLabel) figure).setIcon(icon);
152
		} else {
153
			((Label) figure).setIcon(icon);
154
		}
155
	}
156
157
	/**
158
	 * @generated
159
	 */
160
	public void setLabel(IFigure figure) {
161
		unregisterVisuals();
162
		setFigure(figure);
163
		defaultText = getLabelTextHelper(figure);
164
		registerVisuals();
165
		refreshVisuals();
166
	}
167
168
	/**
169
	 * @generated
170
	 */
171
	protected List getModelChildren() {
172
		return Collections.EMPTY_LIST;
173
	}
174
175
	/**
176
	 * @generated
177
	 */
178
	public IGraphicalEditPart getChildBySemanticHint(String semanticHint) {
179
		return null;
180
	}
181
182
	/**
183
	 * @generated
184
	 */
185
	protected EObject getParserElement() {
186
		EObject element = resolveSemanticElement();
187
		return element != null ? element : (View) getModel();
188
	}
189
190
	/**
191
	 * @generated
192
	 */
193
	protected Image getLabelIcon() {
194
		return null;
195
	}
196
197
	/**
198
	 * @generated
199
	 */
200
	protected String getLabelText() {
201
		String text = null;
202
		if (getParser() != null) {
203
			text = getParser().getPrintString(new EObjectAdapter(getParserElement()), getParserOptions().intValue());
204
		}
205
		if (text == null || text.length() == 0) {
206
			text = defaultText;
207
		}
208
		return text;
209
	}
210
211
	/**
212
	 * @generated
213
	 */
214
	public void setLabelText(String text) {
215
		setLabelTextHelper(getFigure(), text);
216
		Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
217
		if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) {
218
			((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback();
219
		}
220
	}
221
222
	/**
223
	 * @generated
224
	 */
225
	public String getEditText() {
226
		if (getParser() == null) {
227
			return ""; //$NON-NLS-1$
228
		}
229
		return getParser().getEditString(new EObjectAdapter(getParserElement()), getParserOptions().intValue());
230
	}
231
232
	/**
233
	 * @generated
234
	 */
235
	protected boolean isEditable() {
236
		return getEditText() != null;
237
	}
238
239
	/**
240
	 * @generated
241
	 */
242
	public ICellEditorValidator getEditTextValidator() {
243
		return new ICellEditorValidator() {
244
245
			public String isValid(final Object value) {
246
				if (value instanceof String) {
247
					final EObject element = getParserElement();
248
					final IParser parser = getParser();
249
					try {
250
						IParserEditStatus valid = (IParserEditStatus) getEditingDomain().runExclusive(new RunnableWithResult.Impl() {
251
252
							public void run() {
253
								setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value));
254
							}
255
						});
256
						return valid.getCode() == ParserEditStatus.EDITABLE ? null : valid.getMessage();
257
					} catch (InterruptedException ie) {
258
						ie.printStackTrace();
259
					}
260
				}
261
262
				// shouldn't get here
263
				return null;
264
			}
265
		};
266
	}
267
268
	/**
269
	 * @generated
270
	 */
271
	public IContentAssistProcessor getCompletionProcessor() {
272
		if (getParser() == null) {
273
			return null;
274
		}
275
		return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement()));
276
	}
277
278
	/**
279
	 * @generated
280
	 */
281
	public ParserOptions getParserOptions() {
282
		return ParserOptions.NONE;
283
	}
284
285
	/**
286
	 * @generated
287
	 */
288
	public IParser getParser() {
289
		if (parser == null) {
290
			String parserHint = ((View) getModel()).getType();
291
			ParserHintAdapter hintAdapter = new ParserHintAdapter(getParserElement(), parserHint) {
292
293
				public Object getAdapter(Class adapter) {
294
					if (IElementType.class.equals(adapter)) {
295
						return UMLElementTypes.Operation_3020;
296
					}
297
					return super.getAdapter(adapter);
298
				}
299
			};
300
			parser = ParserService.getInstance().getParser(hintAdapter);
301
		}
302
		return parser;
303
	}
304
305
	/**
306
	 * @generated
307
	 */
308
	protected DirectEditManager getManager() {
309
		if (manager == null) {
310
			setManager(new TextDirectEditManager(this, TextDirectEditManager.getTextCellEditorClass(this), UMLEditPartFactory.getTextCellEditorLocator(this)));
311
		}
312
		return manager;
313
	}
314
315
	/**
316
	 * @generated
317
	 */
318
	protected void setManager(DirectEditManager manager) {
319
		this.manager = manager;
320
	}
321
322
	/**
323
	 * @generated
324
	 */
325
	protected void performDirectEdit() {
326
		getManager().show();
327
	}
328
329
	/**
330
	 * @generated
331
	 */
332
	protected void performDirectEdit(Point eventLocation) {
333
		if (getManager().getClass() == TextDirectEditManager.class) {
334
			((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint());
335
		}
336
	}
337
338
	/**
339
	 * @generated
340
	 */
341
	private void performDirectEdit(char initialCharacter) {
342
		if (getManager() instanceof TextDirectEditManager) {
343
			((TextDirectEditManager) getManager()).show(initialCharacter);
344
		} else {
345
			performDirectEdit();
346
		}
347
	}
348
349
	/**
350
	 * @generated
351
	 */
352
	protected void performDirectEditRequest(Request request) {
353
		final Request theRequest = request;
354
		try {
355
			getEditingDomain().runExclusive(new Runnable() {
356
357
				public void run() {
358
					if (isActive() && isEditable()) {
359
						if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) {
360
							Character initialChar = (Character) theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR);
361
							performDirectEdit(initialChar.charValue());
362
						} else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) {
363
							DirectEditRequest editRequest = (DirectEditRequest) theRequest;
364
							performDirectEdit(editRequest.getLocation());
365
						} else {
366
							performDirectEdit();
367
						}
368
					}
369
				}
370
			});
371
		} catch (InterruptedException e) {
372
			e.printStackTrace();
373
		}
374
	}
375
376
	/**
377
	 * @generated
378
	 */
379
	protected void refreshVisuals() {
380
		super.refreshVisuals();
381
		refreshLabel();
382
		refreshFont();
383
		refreshFontColor();
384
		refreshUnderline();
385
		refreshStrikeThrough();
386
	}
387
388
	/**
389
	 * @generated
390
	 */
391
	protected void refreshLabel() {
392
		setLabelTextHelper(getFigure(), getLabelText());
393
		setLabelIconHelper(getFigure(), getLabelIcon());
394
		Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
395
		if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) {
396
			((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback();
397
		}
398
	}
399
400
	/**
401
	 * @generated
402
	 */
403
	protected void refreshUnderline() {
404
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
405
		if (style != null && getFigure() instanceof WrapLabel) {
406
			((WrapLabel) getFigure()).setTextUnderline(style.isUnderline());
407
		}
408
	}
409
410
	/**
411
	 * @generated
412
	 */
413
	protected void refreshStrikeThrough() {
414
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
415
		if (style != null && getFigure() instanceof WrapLabel) {
416
			((WrapLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough());
417
		}
418
	}
419
420
	/**
421
	 * @generated
422
	 */
423
	protected void refreshFont() {
424
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
425
		if (style != null) {
426
			FontData fontData = new FontData(style.getFontName(), style.getFontHeight(), (style.isBold() ? SWT.BOLD : SWT.NORMAL) | (style.isItalic() ? SWT.ITALIC : SWT.NORMAL));
427
			setFont(fontData);
428
		}
429
	}
430
431
	/**
432
	 * @generated
433
	 */
434
	protected void setFontColor(Color color) {
435
		getFigure().setForegroundColor(color);
436
	}
437
438
	/**
439
	 * @generated
440
	 */
441
	protected void addSemanticListeners() {
442
		if (getParser() instanceof ISemanticParser) {
443
			EObject element = resolveSemanticElement();
444
			parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element);
445
			for (int i = 0; i < parserElements.size(); i++) {
446
				addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$
447
			}
448
		} else {
449
			super.addSemanticListeners();
450
		}
451
	}
452
453
	/**
454
	 * @generated
455
	 */
456
	protected void removeSemanticListeners() {
457
		if (parserElements != null) {
458
			for (int i = 0; i < parserElements.size(); i++) {
459
				removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$
460
			}
461
		} else {
462
			super.removeSemanticListeners();
463
		}
464
	}
465
466
	/**
467
	 * @generated
468
	 */
469
	protected AccessibleEditPart getAccessibleEditPart() {
470
		if (accessibleEP == null) {
471
			accessibleEP = new AccessibleGraphicalEditPart() {
472
473
				public void getName(AccessibleEvent e) {
474
					e.result = getLabelTextHelper(getFigure());
475
				}
476
			};
477
		}
478
		return accessibleEP;
479
	}
480
481
	/**
482
	 * @generated
483
	 */
484
	private View getFontStyleOwnerView() {
485
		return getPrimaryView();
486
	}
487
488
	/**
489
	 * @generated
490
	 */
491
	protected void addNotationalListeners() {
492
		super.addNotationalListeners();
493
		addListenerFilter("PrimaryView", this, getPrimaryView()); //$NON-NLS-1$
494
	}
495
496
	/**
497
	 * @generated
498
	 */
499
	protected void removeNotationalListeners() {
500
		super.removeNotationalListeners();
501
		removeListenerFilter("PrimaryView"); //$NON-NLS-1$
502
	}
503
504
	/**
505
	 * @generated
506
	 */
507
	protected void handleNotificationEvent(Notification event) {
508
		Object feature = event.getFeature();
509
		if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) {
510
			Integer c = (Integer) event.getNewValue();
511
			setFontColor(DiagramColorRegistry.getInstance().getColor(c));
512
		} else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) {
513
			refreshUnderline();
514
		} else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) {
515
			refreshStrikeThrough();
516
		} else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature)
517
				|| NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) {
518
			refreshFont();
519
		} else {
520
			if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) {
521
				refreshLabel();
522
			}
523
			if (getParser() instanceof ISemanticParser) {
524
				ISemanticParser modelParser = (ISemanticParser) getParser();
525
				if (modelParser.areSemanticElementsAffected(null, event)) {
526
					removeSemanticListeners();
527
					if (resolveSemanticElement() != null) {
528
						addSemanticListeners();
529
					}
530
					refreshLabel();
531
				}
532
			}
533
		}
534
		super.handleNotificationEvent(event);
535
	}
536
537
	/**
538
	 * @generated
539
	 */
540
	protected IFigure createFigure() {
541
		IFigure label = createFigurePrim();
542
		defaultText = getLabelTextHelper(label);
543
		return label;
544
	}
545
546
	/**
547
	 * @generated
548
	 */
549
	protected IFigure createFigurePrim() {
550
		return new WrapLabel();
551
	}
552
553
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/policies/Package3ItemSemanticEditPolicy.java (+255 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.policies;
2
3
import org.eclipse.emf.ecore.EAnnotation;
4
import org.eclipse.emf.ecore.EClass;
5
import org.eclipse.emf.ecore.EObject;
6
import org.eclipse.gef.commands.Command;
7
import org.eclipse.gef.commands.UnexecutableCommand;
8
import org.eclipse.gmf.runtime.emf.type.core.commands.CreateRelationshipCommand;
9
import org.eclipse.gmf.runtime.emf.type.core.commands.DestroyElementCommand;
10
import org.eclipse.gmf.runtime.emf.type.core.commands.SetValueCommand;
11
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest;
12
import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest;
13
import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest;
14
import org.eclipse.gmf.runtime.notation.View;
15
import org.eclipse.uml2.diagram.clazz.providers.UMLElementTypes;
16
import org.eclipse.uml2.uml.Constraint;
17
import org.eclipse.uml2.uml.Dependency;
18
import org.eclipse.uml2.uml.NamedElement;
19
import org.eclipse.uml2.uml.UMLPackage;
20
import org.eclipse.uml2.uml.Usage;
21
22
/**
23
 * @generated
24
 */
25
public class Package3ItemSemanticEditPolicy extends UMLBaseItemSemanticEditPolicy {
26
27
	/**
28
	 * @generated
29
	 */
30
	protected Command getDestroyElementCommand(DestroyElementRequest req) {
31
		return getMSLWrapper(new DestroyElementCommand(req) {
32
33
			protected EObject getElementToDestroy() {
34
				View view = (View) getHost().getModel();
35
				EAnnotation annotation = view.getEAnnotation("Shortcut"); //$NON-NLS-1$
36
				if (annotation != null) {
37
					return view;
38
				}
39
				return super.getElementToDestroy();
40
			}
41
42
		});
43
	}
44
45
	/**
46
	 * @generated
47
	 */
48
	protected Command getCreateRelationshipCommand(CreateRelationshipRequest req) {
49
		if (UMLElementTypes.Dependency_4002 == req.getElementType()) {
50
			return req.getTarget() == null ? getCreateStartOutgoingDependency4002Command(req) : getCreateCompleteIncomingDependency4002Command(req);
51
		}
52
		if (UMLElementTypes.ConstraintConstrainedElement_4004 == req.getElementType()) {
53
			return req.getTarget() == null ? null : getCreateCompleteIncomingConstraint_ConstrainedElement4004Command(req);
54
		}
55
		if (UMLElementTypes.DependencySupplier_4006 == req.getElementType()) {
56
			return req.getTarget() == null ? null : getCreateCompleteIncomingDependency_Supplier4006Command(req);
57
		}
58
		if (UMLElementTypes.DependencyClient_4007 == req.getElementType()) {
59
			return req.getTarget() == null ? null : getCreateCompleteIncomingDependency_Client4007Command(req);
60
		}
61
		if (UMLElementTypes.Usage_4009 == req.getElementType()) {
62
			return req.getTarget() == null ? getCreateStartOutgoingUsage4009Command(req) : getCreateCompleteIncomingUsage4009Command(req);
63
		}
64
		return super.getCreateRelationshipCommand(req);
65
	}
66
67
	/**
68
	 * @generated
69
	 */
70
	protected Command getCreateStartOutgoingDependency4002Command(CreateRelationshipRequest req) {
71
		return new Command() {
72
		};
73
	}
74
75
	/**
76
	 * @generated
77
	 */
78
	protected Command getCreateCompleteIncomingDependency4002Command(CreateRelationshipRequest req) {
79
		if (!(req.getSource() instanceof NamedElement)) {
80
			return UnexecutableCommand.INSTANCE;
81
		}
82
		final org.eclipse.uml2.uml.Package element = (org.eclipse.uml2.uml.Package) getRelationshipContainer(req.getSource(), UMLPackage.eINSTANCE.getPackage(), req.getElementType());
83
		if (element == null) {
84
			return UnexecutableCommand.INSTANCE;
85
		}
86
		if (req.getContainmentFeature() == null) {
87
			req.setContainmentFeature(UMLPackage.eINSTANCE.getPackage_PackagedElement());
88
		}
89
		return getMSLWrapper(new CreateIncomingDependency4002Command(req) {
90
91
			protected EObject getElementToEdit() {
92
				return element;
93
			}
94
		});
95
	}
96
97
	/**
98
	 * @generated
99
	 */
100
	private static class CreateIncomingDependency4002Command extends CreateRelationshipCommand {
101
102
		/**
103
		 * @generated
104
		 */
105
		public CreateIncomingDependency4002Command(CreateRelationshipRequest req) {
106
			super(req);
107
		}
108
109
		/**
110
		 * @generated
111
		 */
112
		protected EClass getEClassToEdit() {
113
			return UMLPackage.eINSTANCE.getPackage();
114
		};
115
116
		/**
117
		 * @generated
118
		 */
119
		protected void setElementToEdit(EObject element) {
120
			throw new UnsupportedOperationException();
121
		}
122
123
		/**
124
		 * @generated
125
		 */
126
		protected EObject doDefaultElementCreation() {
127
			Dependency newElement = (Dependency) super.doDefaultElementCreation();
128
			if (newElement != null) {
129
				newElement.getSuppliers().add((NamedElement) getTarget());
130
				newElement.getClients().add((NamedElement) getSource());
131
			}
132
			return newElement;
133
		}
134
	}
135
136
	/**
137
	 * @generated
138
	 */
139
	protected Command getCreateCompleteIncomingConstraint_ConstrainedElement4004Command(CreateRelationshipRequest req) {
140
		if (!(req.getSource() instanceof Constraint)) {
141
			return UnexecutableCommand.INSTANCE;
142
		}
143
		Constraint element = (Constraint) req.getSource();
144
		if (element.getConstrainedElements().contains(req.getTarget())) {
145
			return UnexecutableCommand.INSTANCE;
146
		}
147
		SetRequest setReq = new SetRequest(req.getSource(), UMLPackage.eINSTANCE.getConstraint_ConstrainedElement(), req.getTarget());
148
		return getMSLWrapper(new SetValueCommand(setReq));
149
	}
150
151
	/**
152
	 * @generated
153
	 */
154
	protected Command getCreateCompleteIncomingDependency_Supplier4006Command(CreateRelationshipRequest req) {
155
		if (!(req.getSource() instanceof Dependency)) {
156
			return UnexecutableCommand.INSTANCE;
157
		}
158
		Dependency element = (Dependency) req.getSource();
159
		if (element.getSuppliers().contains(req.getTarget())) {
160
			return UnexecutableCommand.INSTANCE;
161
		}
162
		SetRequest setReq = new SetRequest(req.getSource(), UMLPackage.eINSTANCE.getDependency_Supplier(), req.getTarget());
163
		return getMSLWrapper(new SetValueCommand(setReq));
164
	}
165
166
	/**
167
	 * @generated
168
	 */
169
	protected Command getCreateCompleteIncomingDependency_Client4007Command(CreateRelationshipRequest req) {
170
		if (!(req.getSource() instanceof Dependency)) {
171
			return UnexecutableCommand.INSTANCE;
172
		}
173
		Dependency element = (Dependency) req.getSource();
174
		if (element.getClients().contains(req.getTarget())) {
175
			return UnexecutableCommand.INSTANCE;
176
		}
177
		SetRequest setReq = new SetRequest(req.getSource(), UMLPackage.eINSTANCE.getDependency_Client(), req.getTarget());
178
		return getMSLWrapper(new SetValueCommand(setReq));
179
	}
180
181
	/**
182
	 * @generated
183
	 */
184
	protected Command getCreateStartOutgoingUsage4009Command(CreateRelationshipRequest req) {
185
		if (!UMLBaseItemSemanticEditPolicy.LinkConstraints.Usage_4009.canCreateLink(req, false)) {
186
			return UnexecutableCommand.INSTANCE;
187
		}
188
		return new Command() {
189
		};
190
	}
191
192
	/**
193
	 * @generated
194
	 */
195
	protected Command getCreateCompleteIncomingUsage4009Command(CreateRelationshipRequest req) {
196
		if (!(req.getSource() instanceof NamedElement)) {
197
			return UnexecutableCommand.INSTANCE;
198
		}
199
		final org.eclipse.uml2.uml.Package element = (org.eclipse.uml2.uml.Package) getRelationshipContainer(req.getSource(), UMLPackage.eINSTANCE.getPackage(), req.getElementType());
200
		if (element == null) {
201
			return UnexecutableCommand.INSTANCE;
202
		}
203
		if (!UMLBaseItemSemanticEditPolicy.LinkConstraints.Usage_4009.canCreateLink(req, false)) {
204
			return UnexecutableCommand.INSTANCE;
205
		}
206
		if (req.getContainmentFeature() == null) {
207
			req.setContainmentFeature(UMLPackage.eINSTANCE.getPackage_PackagedElement());
208
		}
209
		return getMSLWrapper(new CreateIncomingUsage4009Command(req) {
210
211
			protected EObject getElementToEdit() {
212
				return element;
213
			}
214
		});
215
	}
216
217
	/**
218
	 * @generated
219
	 */
220
	private static class CreateIncomingUsage4009Command extends CreateRelationshipCommand {
221
222
		/**
223
		 * @generated
224
		 */
225
		public CreateIncomingUsage4009Command(CreateRelationshipRequest req) {
226
			super(req);
227
		}
228
229
		/**
230
		 * @generated
231
		 */
232
		protected EClass getEClassToEdit() {
233
			return UMLPackage.eINSTANCE.getPackage();
234
		};
235
236
		/**
237
		 * @generated
238
		 */
239
		protected void setElementToEdit(EObject element) {
240
			throw new UnsupportedOperationException();
241
		}
242
243
		/**
244
		 * @generated
245
		 */
246
		protected EObject doDefaultElementCreation() {
247
			Usage newElement = (Usage) super.doDefaultElementCreation();
248
			if (newElement != null) {
249
				newElement.getSuppliers().add((NamedElement) getTarget());
250
				newElement.getClients().add((NamedElement) getSource());
251
			}
252
			return newElement;
253
		}
254
	}
255
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/parts/ConstraintEditPart.java (+292 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.parts;
2
3
import org.eclipse.draw2d.IFigure;
4
import org.eclipse.draw2d.StackLayout;
5
import org.eclipse.gef.EditPart;
6
import org.eclipse.gef.EditPolicy;
7
import org.eclipse.gef.Request;
8
import org.eclipse.gef.commands.Command;
9
import org.eclipse.gef.editpolicies.LayoutEditPolicy;
10
import org.eclipse.gmf.runtime.diagram.core.edithelpers.CreateElementRequestAdapter;
11
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
12
import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart;
13
import org.eclipse.gmf.runtime.diagram.ui.editparts.ShapeNodeEditPart;
14
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.ConstrainedToolbarLayoutEditPolicy;
15
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.CreationEditPolicy;
16
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
17
import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewAndElementRequest;
18
import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout;
19
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
20
import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure;
21
import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure;
22
import org.eclipse.gmf.runtime.notation.View;
23
import org.eclipse.uml2.diagram.clazz.edit.policies.ConstraintItemSemanticEditPolicy;
24
import org.eclipse.uml2.diagram.clazz.edit.policies.UMLTextSelectionEditPolicy;
25
import org.eclipse.uml2.diagram.clazz.part.UMLVisualIDRegistry;
26
import org.eclipse.uml2.diagram.clazz.providers.UMLElementTypes;
27
28
/**
29
 * @generated
30
 */
31
public class ConstraintEditPart extends ShapeNodeEditPart {
32
33
	/**
34
	 * @generated
35
	 */
36
	public static final int VISUAL_ID = 2006;
37
38
	/**
39
	 * @generated
40
	 */
41
	protected IFigure contentPane;
42
43
	/**
44
	 * @generated
45
	 */
46
	protected IFigure primaryShape;
47
48
	/**
49
	 * @generated
50
	 */
51
	public ConstraintEditPart(View view) {
52
		super(view);
53
	}
54
55
	/**
56
	 * @generated
57
	 */
58
	protected void createDefaultEditPolicies() {
59
		installEditPolicy(EditPolicyRoles.CREATION_ROLE, new CreationEditPolicy() {
60
61
			public Command getCommand(Request request) {
62
				if (understandsRequest(request)) {
63
					if (request instanceof CreateViewAndElementRequest) {
64
						CreateElementRequestAdapter adapter = ((CreateViewAndElementRequest) request).getViewAndElementDescriptor().getCreateElementRequestAdapter();
65
						IElementType type = (IElementType) adapter.getAdapter(IElementType.class);
66
						if (type == UMLElementTypes.LiteralString_3005) {
67
							EditPart compartmentEditPart = getChildBySemanticHint(UMLVisualIDRegistry.getType(ConstraintCompartmentEditPart.VISUAL_ID));
68
							return compartmentEditPart == null ? null : compartmentEditPart.getCommand(request);
69
						}
70
					}
71
					return super.getCommand(request);
72
				}
73
				return null;
74
			}
75
		});
76
		super.createDefaultEditPolicies();
77
		installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new ConstraintItemSemanticEditPolicy());
78
		installEditPolicy(EditPolicy.LAYOUT_ROLE, createLayoutEditPolicy());
79
80
	}
81
82
	/**
83
	 * @generated
84
	 */
85
	protected LayoutEditPolicy createLayoutEditPolicy() {
86
		ConstrainedToolbarLayoutEditPolicy lep = new ConstrainedToolbarLayoutEditPolicy() {
87
88
			protected EditPolicy createChildEditPolicy(EditPart child) {
89
				if (child.getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE) == null) {
90
					if (child instanceof ITextAwareEditPart) {
91
						return new UMLTextSelectionEditPolicy();
92
					}
93
				}
94
				return super.createChildEditPolicy(child);
95
			}
96
		};
97
		return lep;
98
	}
99
100
	/**
101
	 * @generated
102
	 */
103
	protected IFigure createNodeShape() {
104
		NamedNodeRectangle figure = new NamedNodeRectangle();
105
		return primaryShape = figure;
106
	}
107
108
	/**
109
	 * @generated
110
	 */
111
	public NamedNodeRectangle getPrimaryShape() {
112
		return (NamedNodeRectangle) primaryShape;
113
	}
114
115
	/**
116
	 * @generated 
117
	 */
118
	protected IFigure getContentPaneFor(IGraphicalEditPart editPart) {
119
120
		return super.getContentPaneFor(editPart);
121
	}
122
123
	/**
124
	 * @generated
125
	 */
126
	protected boolean addFixedChild(EditPart childEditPart) {
127
		if (childEditPart instanceof ConstraintNameEditPart) {
128
			((ConstraintNameEditPart) childEditPart).setLabel(getPrimaryShape().getFigureNamedNode_NameLabelFigure());
129
			return true;
130
		}
131
		return false;
132
	}
133
134
	/**
135
	 * @generated
136
	 */
137
	protected boolean removeFixedChild(EditPart childEditPart) {
138
		return false;
139
	}
140
141
	/**
142
	 * @generated
143
	 */
144
	protected NodeFigure createNodePlate() {
145
		DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(getMapMode().DPtoLP(40), getMapMode().DPtoLP(40));
146
		return result;
147
	}
148
149
	/**
150
	 * Creates figure for this edit part.
151
	 * 
152
	 * Body of this method does not depend on settings in generation model
153
	 * so you may safely remove <i>generated</i> tag and modify it.
154
	 * 
155
	 * @generated
156
	 */
157
	protected NodeFigure createNodeFigure() {
158
		NodeFigure figure = createNodePlate();
159
		figure.setLayoutManager(new StackLayout());
160
		IFigure shape = createNodeShape();
161
		figure.add(shape);
162
		contentPane = setupContentPane(shape);
163
		return figure;
164
	}
165
166
	/**
167
	 * Default implementation treats passed figure as content pane.
168
	 * Respects layout one may have set for generated figure.
169
	 * @param nodeShape instance of generated figure class
170
	 * @generated
171
	 */
172
	protected IFigure setupContentPane(IFigure nodeShape) {
173
		if (nodeShape.getLayoutManager() == null) {
174
			ConstrainedToolbarLayout layout = new ConstrainedToolbarLayout();
175
			layout.setSpacing(getMapMode().DPtoLP(5));
176
			nodeShape.setLayoutManager(layout);
177
		}
178
		return nodeShape; // use nodeShape itself as contentPane
179
	}
180
181
	/**
182
	 * @generated
183
	 */
184
	public IFigure getContentPane() {
185
		if (contentPane != null) {
186
			return contentPane;
187
		}
188
		return super.getContentPane();
189
	}
190
191
	/**
192
	 * @generated
193
	 */
194
	public EditPart getPrimaryChildEditPart() {
195
		return getChildBySemanticHint(UMLVisualIDRegistry.getType(ConstraintNameEditPart.VISUAL_ID));
196
	}
197
198
	/**
199
	 * @generated
200
	 */
201
	protected void addChildVisual(EditPart childEditPart, int index) {
202
		if (addFixedChild(childEditPart)) {
203
			return;
204
		}
205
		super.addChildVisual(childEditPart, -1);
206
	}
207
208
	/**
209
	 * @generated
210
	 */
211
	protected void removeChildVisual(EditPart childEditPart) {
212
		if (removeFixedChild(childEditPart)) {
213
			return;
214
		}
215
		super.removeChildVisual(childEditPart);
216
	}
217
218
	/**
219
	 * @generated
220
	 */
221
	public class NamedNodeRectangle extends org.eclipse.draw2d.RectangleFigure {
222
223
		/**
224
		 * @generated
225
		 */
226
		public NamedNodeRectangle() {
227
228
			org.eclipse.draw2d.ToolbarLayout myGenLayoutManager = new org.eclipse.draw2d.ToolbarLayout();
229
			myGenLayoutManager.setStretchMinorAxis(true);
230
			myGenLayoutManager.setMinorAlignment(org.eclipse.draw2d.ToolbarLayout.ALIGN_CENTER);
231
			myGenLayoutManager.setSpacing(0);
232
			myGenLayoutManager.setVertical(true);
233
234
			this.setLayoutManager(myGenLayoutManager);
235
236
			createContents();
237
		}
238
239
		/**
240
		 * @generated
241
		 */
242
		private void createContents() {
243
			org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel fig_0 = new org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel();
244
245
			setFigureNamedNode_NameLabelFigure(fig_0);
246
247
			Object layData0 = null;
248
249
			this.add(fig_0, layData0);
250
		}
251
252
		/**
253
		 * @generated
254
		 */
255
		private org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel fNamedNode_NameLabelFigure;
256
257
		/**
258
		 * @generated
259
		 */
260
		public org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel getFigureNamedNode_NameLabelFigure() {
261
			return fNamedNode_NameLabelFigure;
262
		}
263
264
		/**
265
		 * @generated
266
		 */
267
		private void setFigureNamedNode_NameLabelFigure(org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel fig) {
268
			fNamedNode_NameLabelFigure = fig;
269
		}
270
271
		/**
272
		 * @generated
273
		 */
274
		private boolean myUseLocalCoordinates = false;
275
276
		/**
277
		 * @generated
278
		 */
279
		protected boolean useLocalCoordinates() {
280
			return myUseLocalCoordinates;
281
		}
282
283
		/**
284
		 * @generated
285
		 */
286
		protected void setUseLocalCoordinates(boolean useLocalCoordinates) {
287
			myUseLocalCoordinates = useLocalCoordinates;
288
		}
289
290
	}
291
292
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/policies/Property3ItemSemanticEditPolicy.java (+255 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.policies;
2
3
import org.eclipse.emf.ecore.EAnnotation;
4
import org.eclipse.emf.ecore.EClass;
5
import org.eclipse.emf.ecore.EObject;
6
import org.eclipse.gef.commands.Command;
7
import org.eclipse.gef.commands.UnexecutableCommand;
8
import org.eclipse.gmf.runtime.emf.type.core.commands.CreateRelationshipCommand;
9
import org.eclipse.gmf.runtime.emf.type.core.commands.DestroyElementCommand;
10
import org.eclipse.gmf.runtime.emf.type.core.commands.SetValueCommand;
11
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest;
12
import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest;
13
import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest;
14
import org.eclipse.gmf.runtime.notation.View;
15
import org.eclipse.uml2.diagram.clazz.providers.UMLElementTypes;
16
import org.eclipse.uml2.uml.Constraint;
17
import org.eclipse.uml2.uml.Dependency;
18
import org.eclipse.uml2.uml.NamedElement;
19
import org.eclipse.uml2.uml.UMLPackage;
20
import org.eclipse.uml2.uml.Usage;
21
22
/**
23
 * @generated
24
 */
25
public class Property3ItemSemanticEditPolicy extends UMLBaseItemSemanticEditPolicy {
26
27
	/**
28
	 * @generated
29
	 */
30
	protected Command getDestroyElementCommand(DestroyElementRequest req) {
31
		return getMSLWrapper(new DestroyElementCommand(req) {
32
33
			protected EObject getElementToDestroy() {
34
				View view = (View) getHost().getModel();
35
				EAnnotation annotation = view.getEAnnotation("Shortcut"); //$NON-NLS-1$
36
				if (annotation != null) {
37
					return view;
38
				}
39
				return super.getElementToDestroy();
40
			}
41
42
		});
43
	}
44
45
	/**
46
	 * @generated
47
	 */
48
	protected Command getCreateRelationshipCommand(CreateRelationshipRequest req) {
49
		if (UMLElementTypes.Dependency_4002 == req.getElementType()) {
50
			return req.getTarget() == null ? getCreateStartOutgoingDependency4002Command(req) : getCreateCompleteIncomingDependency4002Command(req);
51
		}
52
		if (UMLElementTypes.ConstraintConstrainedElement_4004 == req.getElementType()) {
53
			return req.getTarget() == null ? null : getCreateCompleteIncomingConstraint_ConstrainedElement4004Command(req);
54
		}
55
		if (UMLElementTypes.DependencySupplier_4006 == req.getElementType()) {
56
			return req.getTarget() == null ? null : getCreateCompleteIncomingDependency_Supplier4006Command(req);
57
		}
58
		if (UMLElementTypes.DependencyClient_4007 == req.getElementType()) {
59
			return req.getTarget() == null ? null : getCreateCompleteIncomingDependency_Client4007Command(req);
60
		}
61
		if (UMLElementTypes.Usage_4009 == req.getElementType()) {
62
			return req.getTarget() == null ? getCreateStartOutgoingUsage4009Command(req) : getCreateCompleteIncomingUsage4009Command(req);
63
		}
64
		return super.getCreateRelationshipCommand(req);
65
	}
66
67
	/**
68
	 * @generated
69
	 */
70
	protected Command getCreateStartOutgoingDependency4002Command(CreateRelationshipRequest req) {
71
		return new Command() {
72
		};
73
	}
74
75
	/**
76
	 * @generated
77
	 */
78
	protected Command getCreateCompleteIncomingDependency4002Command(CreateRelationshipRequest req) {
79
		if (!(req.getSource() instanceof NamedElement)) {
80
			return UnexecutableCommand.INSTANCE;
81
		}
82
		final org.eclipse.uml2.uml.Package element = (org.eclipse.uml2.uml.Package) getRelationshipContainer(req.getSource(), UMLPackage.eINSTANCE.getPackage(), req.getElementType());
83
		if (element == null) {
84
			return UnexecutableCommand.INSTANCE;
85
		}
86
		if (req.getContainmentFeature() == null) {
87
			req.setContainmentFeature(UMLPackage.eINSTANCE.getPackage_PackagedElement());
88
		}
89
		return getMSLWrapper(new CreateIncomingDependency4002Command(req) {
90
91
			protected EObject getElementToEdit() {
92
				return element;
93
			}
94
		});
95
	}
96
97
	/**
98
	 * @generated
99
	 */
100
	private static class CreateIncomingDependency4002Command extends CreateRelationshipCommand {
101
102
		/**
103
		 * @generated
104
		 */
105
		public CreateIncomingDependency4002Command(CreateRelationshipRequest req) {
106
			super(req);
107
		}
108
109
		/**
110
		 * @generated
111
		 */
112
		protected EClass getEClassToEdit() {
113
			return UMLPackage.eINSTANCE.getPackage();
114
		};
115
116
		/**
117
		 * @generated
118
		 */
119
		protected void setElementToEdit(EObject element) {
120
			throw new UnsupportedOperationException();
121
		}
122
123
		/**
124
		 * @generated
125
		 */
126
		protected EObject doDefaultElementCreation() {
127
			Dependency newElement = (Dependency) super.doDefaultElementCreation();
128
			if (newElement != null) {
129
				newElement.getSuppliers().add((NamedElement) getTarget());
130
				newElement.getClients().add((NamedElement) getSource());
131
			}
132
			return newElement;
133
		}
134
	}
135
136
	/**
137
	 * @generated
138
	 */
139
	protected Command getCreateCompleteIncomingConstraint_ConstrainedElement4004Command(CreateRelationshipRequest req) {
140
		if (!(req.getSource() instanceof Constraint)) {
141
			return UnexecutableCommand.INSTANCE;
142
		}
143
		Constraint element = (Constraint) req.getSource();
144
		if (element.getConstrainedElements().contains(req.getTarget())) {
145
			return UnexecutableCommand.INSTANCE;
146
		}
147
		SetRequest setReq = new SetRequest(req.getSource(), UMLPackage.eINSTANCE.getConstraint_ConstrainedElement(), req.getTarget());
148
		return getMSLWrapper(new SetValueCommand(setReq));
149
	}
150
151
	/**
152
	 * @generated
153
	 */
154
	protected Command getCreateCompleteIncomingDependency_Supplier4006Command(CreateRelationshipRequest req) {
155
		if (!(req.getSource() instanceof Dependency)) {
156
			return UnexecutableCommand.INSTANCE;
157
		}
158
		Dependency element = (Dependency) req.getSource();
159
		if (element.getSuppliers().contains(req.getTarget())) {
160
			return UnexecutableCommand.INSTANCE;
161
		}
162
		SetRequest setReq = new SetRequest(req.getSource(), UMLPackage.eINSTANCE.getDependency_Supplier(), req.getTarget());
163
		return getMSLWrapper(new SetValueCommand(setReq));
164
	}
165
166
	/**
167
	 * @generated
168
	 */
169
	protected Command getCreateCompleteIncomingDependency_Client4007Command(CreateRelationshipRequest req) {
170
		if (!(req.getSource() instanceof Dependency)) {
171
			return UnexecutableCommand.INSTANCE;
172
		}
173
		Dependency element = (Dependency) req.getSource();
174
		if (element.getClients().contains(req.getTarget())) {
175
			return UnexecutableCommand.INSTANCE;
176
		}
177
		SetRequest setReq = new SetRequest(req.getSource(), UMLPackage.eINSTANCE.getDependency_Client(), req.getTarget());
178
		return getMSLWrapper(new SetValueCommand(setReq));
179
	}
180
181
	/**
182
	 * @generated
183
	 */
184
	protected Command getCreateStartOutgoingUsage4009Command(CreateRelationshipRequest req) {
185
		if (!UMLBaseItemSemanticEditPolicy.LinkConstraints.Usage_4009.canCreateLink(req, false)) {
186
			return UnexecutableCommand.INSTANCE;
187
		}
188
		return new Command() {
189
		};
190
	}
191
192
	/**
193
	 * @generated
194
	 */
195
	protected Command getCreateCompleteIncomingUsage4009Command(CreateRelationshipRequest req) {
196
		if (!(req.getSource() instanceof NamedElement)) {
197
			return UnexecutableCommand.INSTANCE;
198
		}
199
		final org.eclipse.uml2.uml.Package element = (org.eclipse.uml2.uml.Package) getRelationshipContainer(req.getSource(), UMLPackage.eINSTANCE.getPackage(), req.getElementType());
200
		if (element == null) {
201
			return UnexecutableCommand.INSTANCE;
202
		}
203
		if (!UMLBaseItemSemanticEditPolicy.LinkConstraints.Usage_4009.canCreateLink(req, false)) {
204
			return UnexecutableCommand.INSTANCE;
205
		}
206
		if (req.getContainmentFeature() == null) {
207
			req.setContainmentFeature(UMLPackage.eINSTANCE.getPackage_PackagedElement());
208
		}
209
		return getMSLWrapper(new CreateIncomingUsage4009Command(req) {
210
211
			protected EObject getElementToEdit() {
212
				return element;
213
			}
214
		});
215
	}
216
217
	/**
218
	 * @generated
219
	 */
220
	private static class CreateIncomingUsage4009Command extends CreateRelationshipCommand {
221
222
		/**
223
		 * @generated
224
		 */
225
		public CreateIncomingUsage4009Command(CreateRelationshipRequest req) {
226
			super(req);
227
		}
228
229
		/**
230
		 * @generated
231
		 */
232
		protected EClass getEClassToEdit() {
233
			return UMLPackage.eINSTANCE.getPackage();
234
		};
235
236
		/**
237
		 * @generated
238
		 */
239
		protected void setElementToEdit(EObject element) {
240
			throw new UnsupportedOperationException();
241
		}
242
243
		/**
244
		 * @generated
245
		 */
246
		protected EObject doDefaultElementCreation() {
247
			Usage newElement = (Usage) super.doDefaultElementCreation();
248
			if (newElement != null) {
249
				newElement.getSuppliers().add((NamedElement) getTarget());
250
				newElement.getClients().add((NamedElement) getSource());
251
			}
252
			return newElement;
253
		}
254
	}
255
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/parts/DependencyName2EditPart.java (+539 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.parts;
2
3
import java.util.Collections;
4
import java.util.List;
5
6
import org.eclipse.draw2d.ConnectionLocator;
7
import org.eclipse.draw2d.IFigure;
8
import org.eclipse.draw2d.Label;
9
import org.eclipse.draw2d.geometry.Point;
10
import org.eclipse.emf.common.notify.Notification;
11
import org.eclipse.emf.ecore.EObject;
12
import org.eclipse.emf.transaction.RunnableWithResult;
13
import org.eclipse.gef.AccessibleEditPart;
14
import org.eclipse.gef.EditPolicy;
15
import org.eclipse.gef.Request;
16
import org.eclipse.gef.requests.DirectEditRequest;
17
import org.eclipse.gef.tools.DirectEditManager;
18
import org.eclipse.gmf.runtime.common.ui.services.parser.IParser;
19
import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus;
20
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserEditStatus;
21
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions;
22
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserService;
23
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
24
import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart;
25
import org.eclipse.gmf.runtime.diagram.ui.editparts.LabelEditPart;
26
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy;
27
import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry;
28
import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants;
29
import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager;
30
import org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel;
31
import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
32
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
33
import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser;
34
import org.eclipse.gmf.runtime.emf.ui.services.parser.ParserHintAdapter;
35
import org.eclipse.gmf.runtime.notation.FontStyle;
36
import org.eclipse.gmf.runtime.notation.NotationPackage;
37
import org.eclipse.gmf.runtime.notation.View;
38
import org.eclipse.jface.resource.ImageDescriptor;
39
import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
40
import org.eclipse.jface.viewers.ICellEditorValidator;
41
import org.eclipse.swt.SWT;
42
import org.eclipse.swt.accessibility.AccessibleEvent;
43
import org.eclipse.swt.graphics.Color;
44
import org.eclipse.swt.graphics.FontData;
45
import org.eclipse.swt.graphics.Image;
46
import org.eclipse.uml2.diagram.clazz.edit.policies.UMLTextSelectionEditPolicy;
47
import org.eclipse.uml2.diagram.clazz.part.UMLDiagramEditorPlugin;
48
import org.eclipse.uml2.diagram.clazz.part.UMLVisualIDRegistry;
49
import org.eclipse.uml2.diagram.clazz.providers.UMLElementTypes;
50
51
/**
52
 * @generated
53
 */
54
public class DependencyName2EditPart extends LabelEditPart implements ITextAwareEditPart {
55
56
	/**
57
	 * @generated
58
	 */
59
	public static final int VISUAL_ID = 6001;
60
61
	/**
62
	 * @generated
63
	 */
64
	private DirectEditManager manager;
65
66
	/**
67
	 * @generated
68
	 */
69
	private IParser parser;
70
71
	/**
72
	 * @generated
73
	 */
74
	private List parserElements;
75
76
	/**
77
	 * @generated
78
	 */
79
	private String defaultText;
80
81
	/**
82
	 * @generated
83
	 */
84
	static {
85
		registerSnapBackPosition(UMLVisualIDRegistry.getType(DependencyName2EditPart.VISUAL_ID), new Point(0, 40));
86
	}
87
88
	/**
89
	 * @generated
90
	 */
91
	public DependencyName2EditPart(View view) {
92
		super(view);
93
	}
94
95
	/**
96
	 * @generated
97
	 */
98
	protected void createDefaultEditPolicies() {
99
		super.createDefaultEditPolicies();
100
		installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy());
101
102
	}
103
104
	/**
105
	 * @generated
106
	 */
107
	public int getKeyPoint() {
108
		return ConnectionLocator.MIDDLE;
109
	}
110
111
	/**
112
	 * @generated
113
	 */
114
	protected String getLabelTextHelper(IFigure figure) {
115
		if (figure instanceof WrapLabel) {
116
			return ((WrapLabel) figure).getText();
117
		} else {
118
			return ((Label) figure).getText();
119
		}
120
	}
121
122
	/**
123
	 * @generated
124
	 */
125
	protected void setLabelTextHelper(IFigure figure, String text) {
126
		if (figure instanceof WrapLabel) {
127
			((WrapLabel) figure).setText(text);
128
		} else {
129
			((Label) figure).setText(text);
130
		}
131
	}
132
133
	/**
134
	 * @generated
135
	 */
136
	protected Image getLabelIconHelper(IFigure figure) {
137
		if (figure instanceof WrapLabel) {
138
			return ((WrapLabel) figure).getIcon();
139
		} else {
140
			return ((Label) figure).getIcon();
141
		}
142
	}
143
144
	/**
145
	 * @generated
146
	 */
147
	protected void setLabelIconHelper(IFigure figure, Image icon) {
148
		if (figure instanceof WrapLabel) {
149
			((WrapLabel) figure).setIcon(icon);
150
		} else {
151
			((Label) figure).setIcon(icon);
152
		}
153
	}
154
155
	/**
156
	 * @generated
157
	 */
158
	public void setLabel(IFigure figure) {
159
		unregisterVisuals();
160
		setFigure(figure);
161
		defaultText = getLabelTextHelper(figure);
162
		registerVisuals();
163
		refreshVisuals();
164
	}
165
166
	/**
167
	 * @generated
168
	 */
169
	protected List getModelChildren() {
170
		return Collections.EMPTY_LIST;
171
	}
172
173
	/**
174
	 * @generated
175
	 */
176
	public IGraphicalEditPart getChildBySemanticHint(String semanticHint) {
177
		return null;
178
	}
179
180
	/**
181
	 * @generated
182
	 */
183
	protected EObject getParserElement() {
184
		EObject element = resolveSemanticElement();
185
		return element != null ? element : (View) getModel();
186
	}
187
188
	/**
189
	 * @generated
190
	 */
191
	protected Image getLabelIcon() {
192
		EObject parserElement = getParserElement();
193
		if (parserElement == null) {
194
			return null;
195
		}
196
		return UMLElementTypes.getImage(parserElement.eClass());
197
	}
198
199
	/**
200
	 * @generated
201
	 */
202
	protected String getLabelText() {
203
		String text = null;
204
		if (getParser() != null) {
205
			text = getParser().getPrintString(new EObjectAdapter(getParserElement()), getParserOptions().intValue());
206
		}
207
		if (text == null || text.length() == 0) {
208
			text = defaultText;
209
		}
210
		return text;
211
	}
212
213
	/**
214
	 * @generated
215
	 */
216
	public void setLabelText(String text) {
217
		setLabelTextHelper(getFigure(), text);
218
		Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
219
		if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) {
220
			((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback();
221
		}
222
	}
223
224
	/**
225
	 * @generated
226
	 */
227
	public String getEditText() {
228
		if (getParser() == null) {
229
			return ""; //$NON-NLS-1$
230
		}
231
		return getParser().getEditString(new EObjectAdapter(getParserElement()), getParserOptions().intValue());
232
	}
233
234
	/**
235
	 * @generated
236
	 */
237
	protected boolean isEditable() {
238
		return getEditText() != null;
239
	}
240
241
	/**
242
	 * @generated
243
	 */
244
	public ICellEditorValidator getEditTextValidator() {
245
		return new ICellEditorValidator() {
246
247
			public String isValid(final Object value) {
248
				if (value instanceof String) {
249
					final EObject element = getParserElement();
250
					final IParser parser = getParser();
251
					try {
252
						IParserEditStatus valid = (IParserEditStatus) getEditingDomain().runExclusive(new RunnableWithResult.Impl() {
253
254
							public void run() {
255
								setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value));
256
							}
257
						});
258
						return valid.getCode() == ParserEditStatus.EDITABLE ? null : valid.getMessage();
259
					} catch (InterruptedException ie) {
260
						ie.printStackTrace();
261
					}
262
				}
263
264
				// shouldn't get here
265
				return null;
266
			}
267
		};
268
	}
269
270
	/**
271
	 * @generated
272
	 */
273
	public IContentAssistProcessor getCompletionProcessor() {
274
		if (getParser() == null) {
275
			return null;
276
		}
277
		return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement()));
278
	}
279
280
	/**
281
	 * @generated
282
	 */
283
	public ParserOptions getParserOptions() {
284
		return ParserOptions.NONE;
285
	}
286
287
	/**
288
	 * @generated
289
	 */
290
	public IParser getParser() {
291
		if (parser == null) {
292
			String parserHint = ((View) getModel()).getType();
293
			ParserHintAdapter hintAdapter = new ParserHintAdapter(getParserElement(), parserHint) {
294
295
				public Object getAdapter(Class adapter) {
296
					if (IElementType.class.equals(adapter)) {
297
						return UMLElementTypes.Dependency_4002;
298
					}
299
					return super.getAdapter(adapter);
300
				}
301
			};
302
			parser = ParserService.getInstance().getParser(hintAdapter);
303
		}
304
		return parser;
305
	}
306
307
	/**
308
	 * @generated
309
	 */
310
	protected DirectEditManager getManager() {
311
		if (manager == null) {
312
			setManager(new TextDirectEditManager(this, TextDirectEditManager.getTextCellEditorClass(this), UMLEditPartFactory.getTextCellEditorLocator(this)));
313
		}
314
		return manager;
315
	}
316
317
	/**
318
	 * @generated
319
	 */
320
	protected void setManager(DirectEditManager manager) {
321
		this.manager = manager;
322
	}
323
324
	/**
325
	 * @generated
326
	 */
327
	protected void performDirectEdit() {
328
		getManager().show();
329
	}
330
331
	/**
332
	 * @generated
333
	 */
334
	protected void performDirectEdit(Point eventLocation) {
335
		if (getManager().getClass() == TextDirectEditManager.class) {
336
			((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint());
337
		}
338
	}
339
340
	/**
341
	 * @generated
342
	 */
343
	private void performDirectEdit(char initialCharacter) {
344
		if (getManager() instanceof TextDirectEditManager) {
345
			((TextDirectEditManager) getManager()).show(initialCharacter);
346
		} else {
347
			performDirectEdit();
348
		}
349
	}
350
351
	/**
352
	 * @generated
353
	 */
354
	protected void performDirectEditRequest(Request request) {
355
		final Request theRequest = request;
356
		try {
357
			getEditingDomain().runExclusive(new Runnable() {
358
359
				public void run() {
360
					if (isActive() && isEditable()) {
361
						if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) {
362
							Character initialChar = (Character) theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR);
363
							performDirectEdit(initialChar.charValue());
364
						} else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) {
365
							DirectEditRequest editRequest = (DirectEditRequest) theRequest;
366
							performDirectEdit(editRequest.getLocation());
367
						} else {
368
							performDirectEdit();
369
						}
370
					}
371
				}
372
			});
373
		} catch (InterruptedException e) {
374
			e.printStackTrace();
375
		}
376
	}
377
378
	/**
379
	 * @generated
380
	 */
381
	protected void refreshVisuals() {
382
		super.refreshVisuals();
383
		refreshLabel();
384
		refreshFont();
385
		refreshFontColor();
386
		refreshUnderline();
387
		refreshStrikeThrough();
388
	}
389
390
	/**
391
	 * @generated
392
	 */
393
	protected void refreshLabel() {
394
		setLabelTextHelper(getFigure(), getLabelText());
395
		setLabelIconHelper(getFigure(), getLabelIcon());
396
		Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
397
		if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) {
398
			((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback();
399
		}
400
	}
401
402
	/**
403
	 * @generated
404
	 */
405
	protected void refreshUnderline() {
406
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
407
		if (style != null && getFigure() instanceof WrapLabel) {
408
			((WrapLabel) getFigure()).setTextUnderline(style.isUnderline());
409
		}
410
	}
411
412
	/**
413
	 * @generated
414
	 */
415
	protected void refreshStrikeThrough() {
416
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
417
		if (style != null && getFigure() instanceof WrapLabel) {
418
			((WrapLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough());
419
		}
420
	}
421
422
	/**
423
	 * @generated
424
	 */
425
	protected void refreshFont() {
426
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
427
		if (style != null) {
428
			FontData fontData = new FontData(style.getFontName(), style.getFontHeight(), (style.isBold() ? SWT.BOLD : SWT.NORMAL) | (style.isItalic() ? SWT.ITALIC : SWT.NORMAL));
429
			setFont(fontData);
430
		}
431
	}
432
433
	/**
434
	 * @generated
435
	 */
436
	protected void setFontColor(Color color) {
437
		getFigure().setForegroundColor(color);
438
	}
439
440
	/**
441
	 * @generated
442
	 */
443
	protected void addSemanticListeners() {
444
		if (getParser() instanceof ISemanticParser) {
445
			EObject element = resolveSemanticElement();
446
			parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element);
447
			for (int i = 0; i < parserElements.size(); i++) {
448
				addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$
449
			}
450
		} else {
451
			super.addSemanticListeners();
452
		}
453
	}
454
455
	/**
456
	 * @generated
457
	 */
458
	protected void removeSemanticListeners() {
459
		if (parserElements != null) {
460
			for (int i = 0; i < parserElements.size(); i++) {
461
				removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$
462
			}
463
		} else {
464
			super.removeSemanticListeners();
465
		}
466
	}
467
468
	/**
469
	 * @generated
470
	 */
471
	protected AccessibleEditPart getAccessibleEditPart() {
472
		if (accessibleEP == null) {
473
			accessibleEP = new AccessibleGraphicalEditPart() {
474
475
				public void getName(AccessibleEvent e) {
476
					e.result = getLabelTextHelper(getFigure());
477
				}
478
			};
479
		}
480
		return accessibleEP;
481
	}
482
483
	/**
484
	 * @generated
485
	 */
486
	private View getFontStyleOwnerView() {
487
		return getPrimaryView();
488
	}
489
490
	/**
491
	 * @generated
492
	 */
493
	protected void handleNotificationEvent(Notification event) {
494
		Object feature = event.getFeature();
495
		if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) {
496
			Integer c = (Integer) event.getNewValue();
497
			setFontColor(DiagramColorRegistry.getInstance().getColor(c));
498
		} else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) {
499
			refreshUnderline();
500
		} else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) {
501
			refreshStrikeThrough();
502
		} else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature)
503
				|| NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) {
504
			refreshFont();
505
		} else {
506
			if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) {
507
				refreshLabel();
508
			}
509
			if (getParser() instanceof ISemanticParser) {
510
				ISemanticParser modelParser = (ISemanticParser) getParser();
511
				if (modelParser.areSemanticElementsAffected(null, event)) {
512
					removeSemanticListeners();
513
					if (resolveSemanticElement() != null) {
514
						addSemanticListeners();
515
					}
516
					refreshLabel();
517
				}
518
			}
519
		}
520
		super.handleNotificationEvent(event);
521
	}
522
523
	/**
524
	 * @generated
525
	 */
526
	protected IFigure createFigure() {
527
		IFigure label = createFigurePrim();
528
		defaultText = getLabelTextHelper(label);
529
		return label;
530
	}
531
532
	/**
533
	 * @generated
534
	 */
535
	protected IFigure createFigurePrim() {
536
		return new WrapLabel();
537
	}
538
539
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/parts/AssociationClassAttributesEditPart.java (+67 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.parts;
2
3
import org.eclipse.emf.common.notify.Notification;
4
import org.eclipse.gef.EditPolicy;
5
import org.eclipse.gmf.runtime.diagram.ui.editparts.ListCompartmentEditPart;
6
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.CreationEditPolicy;
7
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.DragDropEditPolicy;
8
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
9
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.ResizableCompartmentEditPolicy;
10
import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout;
11
import org.eclipse.gmf.runtime.notation.View;
12
import org.eclipse.uml2.diagram.clazz.edit.policies.AssociationClassAttributesCanonicalEditPolicy;
13
import org.eclipse.uml2.diagram.clazz.edit.policies.AssociationClassAttributesItemSemanticEditPolicy;
14
15
/**
16
 * @generated
17
 */
18
public class AssociationClassAttributesEditPart extends ListCompartmentEditPart {
19
20
	/**
21
	 * @generated
22
	 */
23
	public static final int VISUAL_ID = 7024;
24
25
	/**
26
	 * @generated
27
	 */
28
	public AssociationClassAttributesEditPart(View view) {
29
		super(view);
30
	}
31
32
	/**
33
	 * @generated
34
	 */
35
	protected boolean hasModelChildrenChanged(Notification evt) {
36
		return false;
37
	}
38
39
	/**
40
	 * @generated
41
	 */
42
	public String getCompartmentName() {
43
		return "attributes";
44
	}
45
46
	/**
47
	 * @generated
48
	 */
49
	protected void createDefaultEditPolicies() {
50
		super.createDefaultEditPolicies();
51
		installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ResizableCompartmentEditPolicy());
52
		installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new AssociationClassAttributesItemSemanticEditPolicy());
53
		installEditPolicy(EditPolicyRoles.CREATION_ROLE, new CreationEditPolicy());
54
		installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, new DragDropEditPolicy());
55
		installEditPolicy(EditPolicyRoles.CANONICAL_ROLE, new AssociationClassAttributesCanonicalEditPolicy());
56
57
	}
58
59
	/**
60
	 * @generated
61
	 */
62
	protected void setRatio(Double ratio) {
63
		if (getFigure().getParent().getLayoutManager() instanceof ConstrainedToolbarLayout) {
64
			super.setRatio(ratio);
65
		}
66
	}
67
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/policies/PackageItemSemanticEditPolicy.java (+536 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.policies;
2
3
import org.eclipse.emf.ecore.EClass;
4
import org.eclipse.emf.ecore.EObject;
5
import org.eclipse.emf.transaction.TransactionalEditingDomain;
6
import org.eclipse.gef.commands.Command;
7
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
8
import org.eclipse.gmf.runtime.emf.commands.core.commands.DuplicateEObjectsCommand;
9
import org.eclipse.gmf.runtime.emf.type.core.commands.CreateElementCommand;
10
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest;
11
import org.eclipse.gmf.runtime.emf.type.core.requests.DuplicateElementsRequest;
12
import org.eclipse.gmf.runtime.notation.View;
13
import org.eclipse.uml2.diagram.clazz.providers.UMLElementTypes;
14
import org.eclipse.uml2.uml.AssociationClass;
15
import org.eclipse.uml2.uml.Constraint;
16
import org.eclipse.uml2.uml.DataType;
17
import org.eclipse.uml2.uml.Dependency;
18
import org.eclipse.uml2.uml.Enumeration;
19
import org.eclipse.uml2.uml.InstanceSpecification;
20
import org.eclipse.uml2.uml.Interface;
21
import org.eclipse.uml2.uml.PrimitiveType;
22
import org.eclipse.uml2.uml.UMLPackage;
23
24
/**
25
 * @generated
26
 */
27
public class PackageItemSemanticEditPolicy extends UMLBaseItemSemanticEditPolicy {
28
29
	/**
30
	 * @generated
31
	 */
32
	protected Command getCreateCommand(CreateElementRequest req) {
33
		if (UMLElementTypes.Package_2002 == req.getElementType()) {
34
			if (req.getContainmentFeature() == null) {
35
				req.setContainmentFeature(UMLPackage.eINSTANCE.getPackage_PackagedElement());
36
			}
37
			return getMSLWrapper(new CreatePackage_2002Command(req));
38
		}
39
		if (UMLElementTypes.Class_2001 == req.getElementType()) {
40
			if (req.getContainmentFeature() == null) {
41
				req.setContainmentFeature(UMLPackage.eINSTANCE.getPackage_PackagedElement());
42
			}
43
			return getMSLWrapper(new CreateClass_2001Command(req));
44
		}
45
		if (UMLElementTypes.AssociationClass_2007 == req.getElementType()) {
46
			if (req.getContainmentFeature() == null) {
47
				req.setContainmentFeature(UMLPackage.eINSTANCE.getPackage_PackagedElement());
48
			}
49
			return getMSLWrapper(new CreateAssociationClass_2007Command(req));
50
		}
51
		if (UMLElementTypes.DataType_2004 == req.getElementType()) {
52
			if (req.getContainmentFeature() == null) {
53
				req.setContainmentFeature(UMLPackage.eINSTANCE.getPackage_PackagedElement());
54
			}
55
			return getMSLWrapper(new CreateDataType_2004Command(req));
56
		}
57
		if (UMLElementTypes.PrimitiveType_2005 == req.getElementType()) {
58
			if (req.getContainmentFeature() == null) {
59
				req.setContainmentFeature(UMLPackage.eINSTANCE.getPackage_PackagedElement());
60
			}
61
			return getMSLWrapper(new CreatePrimitiveType_2005Command(req));
62
		}
63
		if (UMLElementTypes.Enumeration_2003 == req.getElementType()) {
64
			if (req.getContainmentFeature() == null) {
65
				req.setContainmentFeature(UMLPackage.eINSTANCE.getPackage_PackagedElement());
66
			}
67
			return getMSLWrapper(new CreateEnumeration_2003Command(req));
68
		}
69
		if (UMLElementTypes.Interface_2010 == req.getElementType()) {
70
			if (req.getContainmentFeature() == null) {
71
				req.setContainmentFeature(UMLPackage.eINSTANCE.getPackage_PackagedElement());
72
			}
73
			return getMSLWrapper(new CreateInterface_2010Command(req));
74
		}
75
		if (UMLElementTypes.Constraint_2006 == req.getElementType()) {
76
			if (req.getContainmentFeature() == null) {
77
				req.setContainmentFeature(UMLPackage.eINSTANCE.getPackage_PackagedElement());
78
			}
79
			return getMSLWrapper(new CreateConstraint_2006Command(req));
80
		}
81
		if (UMLElementTypes.InstanceSpecification_2008 == req.getElementType()) {
82
			if (req.getContainmentFeature() == null) {
83
				req.setContainmentFeature(UMLPackage.eINSTANCE.getPackage_PackagedElement());
84
			}
85
			return getMSLWrapper(new CreateInstanceSpecification_2008Command(req));
86
		}
87
		if (UMLElementTypes.Dependency_2009 == req.getElementType()) {
88
			if (req.getContainmentFeature() == null) {
89
				req.setContainmentFeature(UMLPackage.eINSTANCE.getPackage_PackagedElement());
90
			}
91
			return getMSLWrapper(new CreateDependency_2009Command(req));
92
		}
93
		return super.getCreateCommand(req);
94
	}
95
96
	/**
97
	 * @generated
98
	 */
99
	private static class CreatePackage_2002Command extends CreateElementCommand {
100
101
		/**
102
		 * @generated
103
		 */
104
		public CreatePackage_2002Command(CreateElementRequest req) {
105
			super(req);
106
		}
107
108
		/**
109
		 * @generated
110
		 */
111
		protected EClass getEClassToEdit() {
112
			return UMLPackage.eINSTANCE.getPackage();
113
		};
114
115
		/**
116
		 * @generated
117
		 */
118
		protected EObject getElementToEdit() {
119
			EObject container = ((CreateElementRequest) getRequest()).getContainer();
120
			if (container instanceof View) {
121
				container = ((View) container).getElement();
122
			}
123
			return container;
124
		}
125
126
		/**
127
		 * @generated
128
		 */
129
		protected EObject doDefaultElementCreation() {
130
			org.eclipse.uml2.uml.Package newElement = (org.eclipse.uml2.uml.Package) super.doDefaultElementCreation();
131
			if (newElement != null) {
132
				UMLElementTypes.Initializers.Package_2002.init(newElement);
133
			}
134
			return newElement;
135
		}
136
	}
137
138
	/**
139
	 * @generated
140
	 */
141
	private static class CreateClass_2001Command extends CreateElementCommand {
142
143
		/**
144
		 * @generated
145
		 */
146
		public CreateClass_2001Command(CreateElementRequest req) {
147
			super(req);
148
		}
149
150
		/**
151
		 * @generated
152
		 */
153
		protected EClass getEClassToEdit() {
154
			return UMLPackage.eINSTANCE.getPackage();
155
		};
156
157
		/**
158
		 * @generated
159
		 */
160
		protected EObject getElementToEdit() {
161
			EObject container = ((CreateElementRequest) getRequest()).getContainer();
162
			if (container instanceof View) {
163
				container = ((View) container).getElement();
164
			}
165
			return container;
166
		}
167
168
		/**
169
		 * @generated
170
		 */
171
		protected EObject doDefaultElementCreation() {
172
			org.eclipse.uml2.uml.Class newElement = (org.eclipse.uml2.uml.Class) super.doDefaultElementCreation();
173
			if (newElement != null) {
174
				UMLElementTypes.Initializers.Class_2001.init(newElement);
175
			}
176
			return newElement;
177
		}
178
	}
179
180
	/**
181
	 * @generated
182
	 */
183
	private static class CreateAssociationClass_2007Command extends CreateElementCommand {
184
185
		/**
186
		 * @generated
187
		 */
188
		public CreateAssociationClass_2007Command(CreateElementRequest req) {
189
			super(req);
190
		}
191
192
		/**
193
		 * @generated
194
		 */
195
		protected EClass getEClassToEdit() {
196
			return UMLPackage.eINSTANCE.getPackage();
197
		};
198
199
		/**
200
		 * @generated
201
		 */
202
		protected EObject getElementToEdit() {
203
			EObject container = ((CreateElementRequest) getRequest()).getContainer();
204
			if (container instanceof View) {
205
				container = ((View) container).getElement();
206
			}
207
			return container;
208
		}
209
210
		/**
211
		 * @generated
212
		 */
213
		protected EObject doDefaultElementCreation() {
214
			AssociationClass newElement = (AssociationClass) super.doDefaultElementCreation();
215
			if (newElement != null) {
216
				UMLElementTypes.Initializers.AssociationClass_2007.init(newElement);
217
			}
218
			return newElement;
219
		}
220
	}
221
222
	/**
223
	 * @generated
224
	 */
225
	private static class CreateDataType_2004Command extends CreateElementCommand {
226
227
		/**
228
		 * @generated
229
		 */
230
		public CreateDataType_2004Command(CreateElementRequest req) {
231
			super(req);
232
		}
233
234
		/**
235
		 * @generated
236
		 */
237
		protected EClass getEClassToEdit() {
238
			return UMLPackage.eINSTANCE.getPackage();
239
		};
240
241
		/**
242
		 * @generated
243
		 */
244
		protected EObject getElementToEdit() {
245
			EObject container = ((CreateElementRequest) getRequest()).getContainer();
246
			if (container instanceof View) {
247
				container = ((View) container).getElement();
248
			}
249
			return container;
250
		}
251
252
		/**
253
		 * @generated
254
		 */
255
		protected EObject doDefaultElementCreation() {
256
			DataType newElement = (DataType) super.doDefaultElementCreation();
257
			if (newElement != null) {
258
				UMLElementTypes.Initializers.DataType_2004.init(newElement);
259
			}
260
			return newElement;
261
		}
262
	}
263
264
	/**
265
	 * @generated
266
	 */
267
	private static class CreatePrimitiveType_2005Command extends CreateElementCommand {
268
269
		/**
270
		 * @generated
271
		 */
272
		public CreatePrimitiveType_2005Command(CreateElementRequest req) {
273
			super(req);
274
		}
275
276
		/**
277
		 * @generated
278
		 */
279
		protected EClass getEClassToEdit() {
280
			return UMLPackage.eINSTANCE.getPackage();
281
		};
282
283
		/**
284
		 * @generated
285
		 */
286
		protected EObject getElementToEdit() {
287
			EObject container = ((CreateElementRequest) getRequest()).getContainer();
288
			if (container instanceof View) {
289
				container = ((View) container).getElement();
290
			}
291
			return container;
292
		}
293
294
		/**
295
		 * @generated
296
		 */
297
		protected EObject doDefaultElementCreation() {
298
			PrimitiveType newElement = (PrimitiveType) super.doDefaultElementCreation();
299
			if (newElement != null) {
300
				UMLElementTypes.Initializers.PrimitiveType_2005.init(newElement);
301
			}
302
			return newElement;
303
		}
304
	}
305
306
	/**
307
	 * @generated
308
	 */
309
	private static class CreateEnumeration_2003Command extends CreateElementCommand {
310
311
		/**
312
		 * @generated
313
		 */
314
		public CreateEnumeration_2003Command(CreateElementRequest req) {
315
			super(req);
316
		}
317
318
		/**
319
		 * @generated
320
		 */
321
		protected EClass getEClassToEdit() {
322
			return UMLPackage.eINSTANCE.getPackage();
323
		};
324
325
		/**
326
		 * @generated
327
		 */
328
		protected EObject getElementToEdit() {
329
			EObject container = ((CreateElementRequest) getRequest()).getContainer();
330
			if (container instanceof View) {
331
				container = ((View) container).getElement();
332
			}
333
			return container;
334
		}
335
336
		/**
337
		 * @generated
338
		 */
339
		protected EObject doDefaultElementCreation() {
340
			Enumeration newElement = (Enumeration) super.doDefaultElementCreation();
341
			if (newElement != null) {
342
				UMLElementTypes.Initializers.Enumeration_2003.init(newElement);
343
			}
344
			return newElement;
345
		}
346
	}
347
348
	/**
349
	 * @generated
350
	 */
351
	private static class CreateInterface_2010Command extends CreateElementCommand {
352
353
		/**
354
		 * @generated
355
		 */
356
		public CreateInterface_2010Command(CreateElementRequest req) {
357
			super(req);
358
		}
359
360
		/**
361
		 * @generated
362
		 */
363
		protected EClass getEClassToEdit() {
364
			return UMLPackage.eINSTANCE.getPackage();
365
		};
366
367
		/**
368
		 * @generated
369
		 */
370
		protected EObject getElementToEdit() {
371
			EObject container = ((CreateElementRequest) getRequest()).getContainer();
372
			if (container instanceof View) {
373
				container = ((View) container).getElement();
374
			}
375
			return container;
376
		}
377
378
		/**
379
		 * @generated
380
		 */
381
		protected EObject doDefaultElementCreation() {
382
			Interface newElement = (Interface) super.doDefaultElementCreation();
383
			if (newElement != null) {
384
				UMLElementTypes.Initializers.Interface_2010.init(newElement);
385
			}
386
			return newElement;
387
		}
388
	}
389
390
	/**
391
	 * @generated
392
	 */
393
	private static class CreateConstraint_2006Command extends CreateElementCommand {
394
395
		/**
396
		 * @generated
397
		 */
398
		public CreateConstraint_2006Command(CreateElementRequest req) {
399
			super(req);
400
		}
401
402
		/**
403
		 * @generated
404
		 */
405
		protected EClass getEClassToEdit() {
406
			return UMLPackage.eINSTANCE.getPackage();
407
		};
408
409
		/**
410
		 * @generated
411
		 */
412
		protected EObject getElementToEdit() {
413
			EObject container = ((CreateElementRequest) getRequest()).getContainer();
414
			if (container instanceof View) {
415
				container = ((View) container).getElement();
416
			}
417
			return container;
418
		}
419
420
		/**
421
		 * @generated
422
		 */
423
		protected EObject doDefaultElementCreation() {
424
			Constraint newElement = (Constraint) super.doDefaultElementCreation();
425
			if (newElement != null) {
426
				UMLElementTypes.Initializers.Constraint_2006.init(newElement);
427
			}
428
			return newElement;
429
		}
430
	}
431
432
	/**
433
	 * @generated
434
	 */
435
	private static class CreateInstanceSpecification_2008Command extends CreateElementCommand {
436
437
		/**
438
		 * @generated
439
		 */
440
		public CreateInstanceSpecification_2008Command(CreateElementRequest req) {
441
			super(req);
442
		}
443
444
		/**
445
		 * @generated
446
		 */
447
		protected EClass getEClassToEdit() {
448
			return UMLPackage.eINSTANCE.getPackage();
449
		};
450
451
		/**
452
		 * @generated
453
		 */
454
		protected EObject getElementToEdit() {
455
			EObject container = ((CreateElementRequest) getRequest()).getContainer();
456
			if (container instanceof View) {
457
				container = ((View) container).getElement();
458
			}
459
			return container;
460
		}
461
462
		/**
463
		 * @generated
464
		 */
465
		protected EObject doDefaultElementCreation() {
466
			InstanceSpecification newElement = (InstanceSpecification) super.doDefaultElementCreation();
467
			if (newElement != null) {
468
				UMLElementTypes.Initializers.InstanceSpecification_2008.init(newElement);
469
			}
470
			return newElement;
471
		}
472
	}
473
474
	/**
475
	 * @generated
476
	 */
477
	private static class CreateDependency_2009Command extends CreateElementCommand {
478
479
		/**
480
		 * @generated
481
		 */
482
		public CreateDependency_2009Command(CreateElementRequest req) {
483
			super(req);
484
		}
485
486
		/**
487
		 * @generated
488
		 */
489
		protected EClass getEClassToEdit() {
490
			return UMLPackage.eINSTANCE.getPackage();
491
		};
492
493
		/**
494
		 * @generated
495
		 */
496
		protected EObject getElementToEdit() {
497
			EObject container = ((CreateElementRequest) getRequest()).getContainer();
498
			if (container instanceof View) {
499
				container = ((View) container).getElement();
500
			}
501
			return container;
502
		}
503
504
		/**
505
		 * @generated
506
		 */
507
		protected EObject doDefaultElementCreation() {
508
			Dependency newElement = (Dependency) super.doDefaultElementCreation();
509
			if (newElement != null) {
510
				UMLElementTypes.Initializers.Dependency_2009.init(newElement);
511
			}
512
			return newElement;
513
		}
514
	}
515
516
	/**
517
	 * @generated
518
	 */
519
	protected Command getDuplicateCommand(DuplicateElementsRequest req) {
520
		TransactionalEditingDomain editingDomain = ((IGraphicalEditPart) getHost()).getEditingDomain();
521
		return getMSLWrapper(new DuplicateAnythingCommand(editingDomain, req));
522
	}
523
524
	/**
525
	 * @generated
526
	 */
527
	private static class DuplicateAnythingCommand extends DuplicateEObjectsCommand {
528
529
		/**
530
		 * @generated
531
		 */
532
		public DuplicateAnythingCommand(TransactionalEditingDomain editingDomain, DuplicateElementsRequest req) {
533
			super(editingDomain, req.getLabel(), req.getElementsToBeDuplicated(), req.getAllDuplicatedElementsMap());
534
		}
535
	}
536
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/policies/Property2ItemSemanticEditPolicy.java (+255 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.policies;
2
3
import org.eclipse.emf.ecore.EAnnotation;
4
import org.eclipse.emf.ecore.EClass;
5
import org.eclipse.emf.ecore.EObject;
6
import org.eclipse.gef.commands.Command;
7
import org.eclipse.gef.commands.UnexecutableCommand;
8
import org.eclipse.gmf.runtime.emf.type.core.commands.CreateRelationshipCommand;
9
import org.eclipse.gmf.runtime.emf.type.core.commands.DestroyElementCommand;
10
import org.eclipse.gmf.runtime.emf.type.core.commands.SetValueCommand;
11
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest;
12
import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest;
13
import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest;
14
import org.eclipse.gmf.runtime.notation.View;
15
import org.eclipse.uml2.diagram.clazz.providers.UMLElementTypes;
16
import org.eclipse.uml2.uml.Constraint;
17
import org.eclipse.uml2.uml.Dependency;
18
import org.eclipse.uml2.uml.NamedElement;
19
import org.eclipse.uml2.uml.UMLPackage;
20
import org.eclipse.uml2.uml.Usage;
21
22
/**
23
 * @generated
24
 */
25
public class Property2ItemSemanticEditPolicy extends UMLBaseItemSemanticEditPolicy {
26
27
	/**
28
	 * @generated
29
	 */
30
	protected Command getDestroyElementCommand(DestroyElementRequest req) {
31
		return getMSLWrapper(new DestroyElementCommand(req) {
32
33
			protected EObject getElementToDestroy() {
34
				View view = (View) getHost().getModel();
35
				EAnnotation annotation = view.getEAnnotation("Shortcut"); //$NON-NLS-1$
36
				if (annotation != null) {
37
					return view;
38
				}
39
				return super.getElementToDestroy();
40
			}
41
42
		});
43
	}
44
45
	/**
46
	 * @generated
47
	 */
48
	protected Command getCreateRelationshipCommand(CreateRelationshipRequest req) {
49
		if (UMLElementTypes.Dependency_4002 == req.getElementType()) {
50
			return req.getTarget() == null ? getCreateStartOutgoingDependency4002Command(req) : getCreateCompleteIncomingDependency4002Command(req);
51
		}
52
		if (UMLElementTypes.ConstraintConstrainedElement_4004 == req.getElementType()) {
53
			return req.getTarget() == null ? null : getCreateCompleteIncomingConstraint_ConstrainedElement4004Command(req);
54
		}
55
		if (UMLElementTypes.DependencySupplier_4006 == req.getElementType()) {
56
			return req.getTarget() == null ? null : getCreateCompleteIncomingDependency_Supplier4006Command(req);
57
		}
58
		if (UMLElementTypes.DependencyClient_4007 == req.getElementType()) {
59
			return req.getTarget() == null ? null : getCreateCompleteIncomingDependency_Client4007Command(req);
60
		}
61
		if (UMLElementTypes.Usage_4009 == req.getElementType()) {
62
			return req.getTarget() == null ? getCreateStartOutgoingUsage4009Command(req) : getCreateCompleteIncomingUsage4009Command(req);
63
		}
64
		return super.getCreateRelationshipCommand(req);
65
	}
66
67
	/**
68
	 * @generated
69
	 */
70
	protected Command getCreateStartOutgoingDependency4002Command(CreateRelationshipRequest req) {
71
		return new Command() {
72
		};
73
	}
74
75
	/**
76
	 * @generated
77
	 */
78
	protected Command getCreateCompleteIncomingDependency4002Command(CreateRelationshipRequest req) {
79
		if (!(req.getSource() instanceof NamedElement)) {
80
			return UnexecutableCommand.INSTANCE;
81
		}
82
		final org.eclipse.uml2.uml.Package element = (org.eclipse.uml2.uml.Package) getRelationshipContainer(req.getSource(), UMLPackage.eINSTANCE.getPackage(), req.getElementType());
83
		if (element == null) {
84
			return UnexecutableCommand.INSTANCE;
85
		}
86
		if (req.getContainmentFeature() == null) {
87
			req.setContainmentFeature(UMLPackage.eINSTANCE.getPackage_PackagedElement());
88
		}
89
		return getMSLWrapper(new CreateIncomingDependency4002Command(req) {
90
91
			protected EObject getElementToEdit() {
92
				return element;
93
			}
94
		});
95
	}
96
97
	/**
98
	 * @generated
99
	 */
100
	private static class CreateIncomingDependency4002Command extends CreateRelationshipCommand {
101
102
		/**
103
		 * @generated
104
		 */
105
		public CreateIncomingDependency4002Command(CreateRelationshipRequest req) {
106
			super(req);
107
		}
108
109
		/**
110
		 * @generated
111
		 */
112
		protected EClass getEClassToEdit() {
113
			return UMLPackage.eINSTANCE.getPackage();
114
		};
115
116
		/**
117
		 * @generated
118
		 */
119
		protected void setElementToEdit(EObject element) {
120
			throw new UnsupportedOperationException();
121
		}
122
123
		/**
124
		 * @generated
125
		 */
126
		protected EObject doDefaultElementCreation() {
127
			Dependency newElement = (Dependency) super.doDefaultElementCreation();
128
			if (newElement != null) {
129
				newElement.getSuppliers().add((NamedElement) getTarget());
130
				newElement.getClients().add((NamedElement) getSource());
131
			}
132
			return newElement;
133
		}
134
	}
135
136
	/**
137
	 * @generated
138
	 */
139
	protected Command getCreateCompleteIncomingConstraint_ConstrainedElement4004Command(CreateRelationshipRequest req) {
140
		if (!(req.getSource() instanceof Constraint)) {
141
			return UnexecutableCommand.INSTANCE;
142
		}
143
		Constraint element = (Constraint) req.getSource();
144
		if (element.getConstrainedElements().contains(req.getTarget())) {
145
			return UnexecutableCommand.INSTANCE;
146
		}
147
		SetRequest setReq = new SetRequest(req.getSource(), UMLPackage.eINSTANCE.getConstraint_ConstrainedElement(), req.getTarget());
148
		return getMSLWrapper(new SetValueCommand(setReq));
149
	}
150
151
	/**
152
	 * @generated
153
	 */
154
	protected Command getCreateCompleteIncomingDependency_Supplier4006Command(CreateRelationshipRequest req) {
155
		if (!(req.getSource() instanceof Dependency)) {
156
			return UnexecutableCommand.INSTANCE;
157
		}
158
		Dependency element = (Dependency) req.getSource();
159
		if (element.getSuppliers().contains(req.getTarget())) {
160
			return UnexecutableCommand.INSTANCE;
161
		}
162
		SetRequest setReq = new SetRequest(req.getSource(), UMLPackage.eINSTANCE.getDependency_Supplier(), req.getTarget());
163
		return getMSLWrapper(new SetValueCommand(setReq));
164
	}
165
166
	/**
167
	 * @generated
168
	 */
169
	protected Command getCreateCompleteIncomingDependency_Client4007Command(CreateRelationshipRequest req) {
170
		if (!(req.getSource() instanceof Dependency)) {
171
			return UnexecutableCommand.INSTANCE;
172
		}
173
		Dependency element = (Dependency) req.getSource();
174
		if (element.getClients().contains(req.getTarget())) {
175
			return UnexecutableCommand.INSTANCE;
176
		}
177
		SetRequest setReq = new SetRequest(req.getSource(), UMLPackage.eINSTANCE.getDependency_Client(), req.getTarget());
178
		return getMSLWrapper(new SetValueCommand(setReq));
179
	}
180
181
	/**
182
	 * @generated
183
	 */
184
	protected Command getCreateStartOutgoingUsage4009Command(CreateRelationshipRequest req) {
185
		if (!UMLBaseItemSemanticEditPolicy.LinkConstraints.Usage_4009.canCreateLink(req, false)) {
186
			return UnexecutableCommand.INSTANCE;
187
		}
188
		return new Command() {
189
		};
190
	}
191
192
	/**
193
	 * @generated
194
	 */
195
	protected Command getCreateCompleteIncomingUsage4009Command(CreateRelationshipRequest req) {
196
		if (!(req.getSource() instanceof NamedElement)) {
197
			return UnexecutableCommand.INSTANCE;
198
		}
199
		final org.eclipse.uml2.uml.Package element = (org.eclipse.uml2.uml.Package) getRelationshipContainer(req.getSource(), UMLPackage.eINSTANCE.getPackage(), req.getElementType());
200
		if (element == null) {
201
			return UnexecutableCommand.INSTANCE;
202
		}
203
		if (!UMLBaseItemSemanticEditPolicy.LinkConstraints.Usage_4009.canCreateLink(req, false)) {
204
			return UnexecutableCommand.INSTANCE;
205
		}
206
		if (req.getContainmentFeature() == null) {
207
			req.setContainmentFeature(UMLPackage.eINSTANCE.getPackage_PackagedElement());
208
		}
209
		return getMSLWrapper(new CreateIncomingUsage4009Command(req) {
210
211
			protected EObject getElementToEdit() {
212
				return element;
213
			}
214
		});
215
	}
216
217
	/**
218
	 * @generated
219
	 */
220
	private static class CreateIncomingUsage4009Command extends CreateRelationshipCommand {
221
222
		/**
223
		 * @generated
224
		 */
225
		public CreateIncomingUsage4009Command(CreateRelationshipRequest req) {
226
			super(req);
227
		}
228
229
		/**
230
		 * @generated
231
		 */
232
		protected EClass getEClassToEdit() {
233
			return UMLPackage.eINSTANCE.getPackage();
234
		};
235
236
		/**
237
		 * @generated
238
		 */
239
		protected void setElementToEdit(EObject element) {
240
			throw new UnsupportedOperationException();
241
		}
242
243
		/**
244
		 * @generated
245
		 */
246
		protected EObject doDefaultElementCreation() {
247
			Usage newElement = (Usage) super.doDefaultElementCreation();
248
			if (newElement != null) {
249
				newElement.getSuppliers().add((NamedElement) getTarget());
250
				newElement.getClients().add((NamedElement) getSource());
251
			}
252
			return newElement;
253
		}
254
	}
255
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/policies/Property6ItemSemanticEditPolicy.java (+18 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.policies;
2
3
import org.eclipse.gef.commands.Command;
4
import org.eclipse.gmf.runtime.emf.type.core.commands.DestroyElementCommand;
5
import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest;
6
7
/**
8
 * @generated
9
 */
10
public class Property6ItemSemanticEditPolicy extends UMLBaseItemSemanticEditPolicy {
11
12
	/**
13
	 * @generated
14
	 */
15
	protected Command getDestroyElementCommand(DestroyElementRequest req) {
16
		return getMSLWrapper(new DestroyElementCommand(req));
17
	}
18
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/policies/EnumerationLiteralsItemSemanticEditPolicy.java (+73 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.policies;
2
3
import org.eclipse.emf.ecore.EClass;
4
import org.eclipse.emf.ecore.EObject;
5
import org.eclipse.gef.commands.Command;
6
import org.eclipse.gmf.runtime.emf.type.core.commands.CreateElementCommand;
7
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest;
8
import org.eclipse.gmf.runtime.notation.View;
9
import org.eclipse.uml2.diagram.clazz.providers.UMLElementTypes;
10
import org.eclipse.uml2.uml.EnumerationLiteral;
11
import org.eclipse.uml2.uml.UMLPackage;
12
13
/**
14
 * @generated
15
 */
16
public class EnumerationLiteralsItemSemanticEditPolicy extends UMLBaseItemSemanticEditPolicy {
17
18
	/**
19
	 * @generated
20
	 */
21
	protected Command getCreateCommand(CreateElementRequest req) {
22
		if (UMLElementTypes.EnumerationLiteral_3016 == req.getElementType()) {
23
			if (req.getContainmentFeature() == null) {
24
				req.setContainmentFeature(UMLPackage.eINSTANCE.getEnumeration_OwnedLiteral());
25
			}
26
			return getMSLWrapper(new CreateEnumerationLiteral_3016Command(req));
27
		}
28
		return super.getCreateCommand(req);
29
	}
30
31
	/**
32
	 * @generated
33
	 */
34
	private static class CreateEnumerationLiteral_3016Command extends CreateElementCommand {
35
36
		/**
37
		 * @generated
38
		 */
39
		public CreateEnumerationLiteral_3016Command(CreateElementRequest req) {
40
			super(req);
41
		}
42
43
		/**
44
		 * @generated
45
		 */
46
		protected EClass getEClassToEdit() {
47
			return UMLPackage.eINSTANCE.getEnumeration();
48
		};
49
50
		/**
51
		 * @generated
52
		 */
53
		protected EObject getElementToEdit() {
54
			EObject container = ((CreateElementRequest) getRequest()).getContainer();
55
			if (container instanceof View) {
56
				container = ((View) container).getElement();
57
			}
58
			return container;
59
		}
60
61
		/**
62
		 * @generated
63
		 */
64
		protected EObject doDefaultElementCreation() {
65
			EnumerationLiteral newElement = (EnumerationLiteral) super.doDefaultElementCreation();
66
			if (newElement != null) {
67
				UMLElementTypes.Initializers.EnumerationLiteral_3016.init(newElement);
68
			}
69
			return newElement;
70
		}
71
	}
72
73
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/parts/ClassClassesEditPart.java (+67 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.parts;
2
3
import org.eclipse.emf.common.notify.Notification;
4
import org.eclipse.gef.EditPolicy;
5
import org.eclipse.gmf.runtime.diagram.ui.editparts.ListCompartmentEditPart;
6
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.CreationEditPolicy;
7
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.DragDropEditPolicy;
8
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
9
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.ResizableCompartmentEditPolicy;
10
import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout;
11
import org.eclipse.gmf.runtime.notation.View;
12
import org.eclipse.uml2.diagram.clazz.edit.policies.ClassClassesCanonicalEditPolicy;
13
import org.eclipse.uml2.diagram.clazz.edit.policies.ClassClassesItemSemanticEditPolicy;
14
15
/**
16
 * @generated
17
 */
18
public class ClassClassesEditPart extends ListCompartmentEditPart {
19
20
	/**
21
	 * @generated
22
	 */
23
	public static final int VISUAL_ID = 7003;
24
25
	/**
26
	 * @generated
27
	 */
28
	public ClassClassesEditPart(View view) {
29
		super(view);
30
	}
31
32
	/**
33
	 * @generated
34
	 */
35
	protected boolean hasModelChildrenChanged(Notification evt) {
36
		return false;
37
	}
38
39
	/**
40
	 * @generated
41
	 */
42
	public String getCompartmentName() {
43
		return "classes";
44
	}
45
46
	/**
47
	 * @generated
48
	 */
49
	protected void createDefaultEditPolicies() {
50
		super.createDefaultEditPolicies();
51
		installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ResizableCompartmentEditPolicy());
52
		installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new ClassClassesItemSemanticEditPolicy());
53
		installEditPolicy(EditPolicyRoles.CREATION_ROLE, new CreationEditPolicy());
54
		installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, new DragDropEditPolicy());
55
		installEditPolicy(EditPolicyRoles.CANONICAL_ROLE, new ClassClassesCanonicalEditPolicy());
56
57
	}
58
59
	/**
60
	 * @generated
61
	 */
62
	protected void setRatio(Double ratio) {
63
		if (getFigure().getParent().getLayoutManager() instanceof ConstrainedToolbarLayout) {
64
			super.setRatio(ratio);
65
		}
66
	}
67
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/policies/ClassAttributesCanonicalEditPolicy.java (+52 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.policies;
2
3
import java.util.Iterator;
4
import java.util.LinkedList;
5
import java.util.List;
6
7
import org.eclipse.emf.ecore.EObject;
8
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.CanonicalEditPolicy;
9
import org.eclipse.gmf.runtime.notation.View;
10
import org.eclipse.uml2.diagram.clazz.edit.parts.PropertyEditPart;
11
import org.eclipse.uml2.diagram.clazz.part.UMLVisualIDRegistry;
12
import org.eclipse.uml2.uml.StructuredClassifier;
13
14
/**
15
 * @generated
16
 */
17
public class ClassAttributesCanonicalEditPolicy extends CanonicalEditPolicy {
18
19
	/**
20
	 * @generated
21
	 */
22
	protected List getSemanticChildrenList() {
23
		List result = new LinkedList();
24
		EObject modelObject = ((View) getHost().getModel()).getElement();
25
		View viewObject = (View) getHost().getModel();
26
		EObject nextValue;
27
		int nodeVID;
28
		for (Iterator values = ((StructuredClassifier) modelObject).getOwnedAttributes().iterator(); values.hasNext();) {
29
			nextValue = (EObject) values.next();
30
			nodeVID = UMLVisualIDRegistry.getNodeVisualID(viewObject, nextValue);
31
			if (PropertyEditPart.VISUAL_ID == nodeVID) {
32
				result.add(nextValue);
33
			}
34
		}
35
		return result;
36
	}
37
38
	/**
39
	 * @generated
40
	 */
41
	protected boolean shouldDeleteView(View view) {
42
		return view.isSetElement() && view.getElement() != null && view.getElement().eIsProxy();
43
	}
44
45
	/**
46
	 * @generated
47
	 */
48
	protected String getDefaultFactoryHint() {
49
		return null;
50
	}
51
52
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/policies/PackagePackagesCanonicalEditPolicy.java (+51 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.policies;
2
3
import java.util.Iterator;
4
import java.util.LinkedList;
5
import java.util.List;
6
7
import org.eclipse.emf.ecore.EObject;
8
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.CanonicalEditPolicy;
9
import org.eclipse.gmf.runtime.notation.View;
10
import org.eclipse.uml2.diagram.clazz.edit.parts.Package3EditPart;
11
import org.eclipse.uml2.diagram.clazz.part.UMLVisualIDRegistry;
12
13
/**
14
 * @generated
15
 */
16
public class PackagePackagesCanonicalEditPolicy extends CanonicalEditPolicy {
17
18
	/**
19
	 * @generated
20
	 */
21
	protected List getSemanticChildrenList() {
22
		List result = new LinkedList();
23
		EObject modelObject = ((View) getHost().getModel()).getElement();
24
		View viewObject = (View) getHost().getModel();
25
		EObject nextValue;
26
		int nodeVID;
27
		for (Iterator values = ((org.eclipse.uml2.uml.Package) modelObject).getNestedPackages().iterator(); values.hasNext();) {
28
			nextValue = (EObject) values.next();
29
			nodeVID = UMLVisualIDRegistry.getNodeVisualID(viewObject, nextValue);
30
			if (Package3EditPart.VISUAL_ID == nodeVID) {
31
				result.add(nextValue);
32
			}
33
		}
34
		return result;
35
	}
36
37
	/**
38
	 * @generated
39
	 */
40
	protected boolean shouldDeleteView(View view) {
41
		return view.isSetElement() && view.getElement() != null && view.getElement().eIsProxy();
42
	}
43
44
	/**
45
	 * @generated
46
	 */
47
	protected String getDefaultFactoryHint() {
48
		return null;
49
	}
50
51
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/policies/AssociationClassAttributesCanonicalEditPolicy.java (+52 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.policies;
2
3
import java.util.Iterator;
4
import java.util.LinkedList;
5
import java.util.List;
6
7
import org.eclipse.emf.ecore.EObject;
8
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.CanonicalEditPolicy;
9
import org.eclipse.gmf.runtime.notation.View;
10
import org.eclipse.uml2.diagram.clazz.edit.parts.Property2EditPart;
11
import org.eclipse.uml2.diagram.clazz.part.UMLVisualIDRegistry;
12
import org.eclipse.uml2.uml.StructuredClassifier;
13
14
/**
15
 * @generated
16
 */
17
public class AssociationClassAttributesCanonicalEditPolicy extends CanonicalEditPolicy {
18
19
	/**
20
	 * @generated
21
	 */
22
	protected List getSemanticChildrenList() {
23
		List result = new LinkedList();
24
		EObject modelObject = ((View) getHost().getModel()).getElement();
25
		View viewObject = (View) getHost().getModel();
26
		EObject nextValue;
27
		int nodeVID;
28
		for (Iterator values = ((StructuredClassifier) modelObject).getOwnedAttributes().iterator(); values.hasNext();) {
29
			nextValue = (EObject) values.next();
30
			nodeVID = UMLVisualIDRegistry.getNodeVisualID(viewObject, nextValue);
31
			if (Property2EditPart.VISUAL_ID == nodeVID) {
32
				result.add(nextValue);
33
			}
34
		}
35
		return result;
36
	}
37
38
	/**
39
	 * @generated
40
	 */
41
	protected boolean shouldDeleteView(View view) {
42
		return view.isSetElement() && view.getElement() != null && view.getElement().eIsProxy();
43
	}
44
45
	/**
46
	 * @generated
47
	 */
48
	protected String getDefaultFactoryHint() {
49
		return null;
50
	}
51
52
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/parts/InterfaceNameEditPart.java (+524 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.parts;
2
3
import java.util.Collections;
4
import java.util.List;
5
6
import org.eclipse.draw2d.IFigure;
7
import org.eclipse.draw2d.Label;
8
import org.eclipse.draw2d.geometry.Point;
9
import org.eclipse.emf.common.notify.Notification;
10
import org.eclipse.emf.ecore.EObject;
11
import org.eclipse.emf.transaction.RunnableWithResult;
12
import org.eclipse.gef.AccessibleEditPart;
13
import org.eclipse.gef.EditPolicy;
14
import org.eclipse.gef.Request;
15
import org.eclipse.gef.requests.DirectEditRequest;
16
import org.eclipse.gef.tools.DirectEditManager;
17
import org.eclipse.gmf.runtime.common.ui.services.parser.IParser;
18
import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus;
19
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserEditStatus;
20
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions;
21
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserService;
22
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
23
import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart;
24
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy;
25
import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry;
26
import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants;
27
import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager;
28
import org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel;
29
import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
30
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
31
import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser;
32
import org.eclipse.gmf.runtime.emf.ui.services.parser.ParserHintAdapter;
33
import org.eclipse.gmf.runtime.notation.FontStyle;
34
import org.eclipse.gmf.runtime.notation.NotationPackage;
35
import org.eclipse.gmf.runtime.notation.View;
36
import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
37
import org.eclipse.jface.viewers.ICellEditorValidator;
38
import org.eclipse.swt.SWT;
39
import org.eclipse.swt.accessibility.AccessibleEvent;
40
import org.eclipse.swt.graphics.Color;
41
import org.eclipse.swt.graphics.FontData;
42
import org.eclipse.swt.graphics.Image;
43
import org.eclipse.uml2.diagram.clazz.edit.policies.UMLTextSelectionEditPolicy;
44
import org.eclipse.uml2.diagram.clazz.part.UMLVisualIDRegistry;
45
import org.eclipse.uml2.diagram.clazz.providers.UMLElementTypes;
46
47
/**
48
 * @generated
49
 */
50
public class InterfaceNameEditPart extends UMLExtNodeLabelEditPart implements ITextAwareEditPart {
51
52
	/**
53
	 * @generated
54
	 */
55
	public static final int VISUAL_ID = 5012;
56
57
	/**
58
	 * @generated
59
	 */
60
	private DirectEditManager manager;
61
62
	/**
63
	 * @generated
64
	 */
65
	private IParser parser;
66
67
	/**
68
	 * @generated
69
	 */
70
	private List parserElements;
71
72
	/**
73
	 * @generated
74
	 */
75
	private String defaultText;
76
77
	/**
78
	 * @generated
79
	 */
80
	static {
81
		registerSnapBackPosition(UMLVisualIDRegistry.getType(InterfaceNameEditPart.VISUAL_ID), new Point(0, 0));
82
	}
83
84
	/**
85
	 * @generated
86
	 */
87
	public InterfaceNameEditPart(View view) {
88
		super(view);
89
	}
90
91
	/**
92
	 * @generated
93
	 */
94
	protected void createDefaultEditPolicies() {
95
		super.createDefaultEditPolicies();
96
		installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy());
97
98
	}
99
100
	/**
101
	 * @generated
102
	 */
103
	protected String getLabelTextHelper(IFigure figure) {
104
		if (figure instanceof WrapLabel) {
105
			return ((WrapLabel) figure).getText();
106
		} else {
107
			return ((Label) figure).getText();
108
		}
109
	}
110
111
	/**
112
	 * @generated
113
	 */
114
	protected void setLabelTextHelper(IFigure figure, String text) {
115
		if (figure instanceof WrapLabel) {
116
			((WrapLabel) figure).setText(text);
117
		} else {
118
			((Label) figure).setText(text);
119
		}
120
	}
121
122
	/**
123
	 * @generated
124
	 */
125
	protected Image getLabelIconHelper(IFigure figure) {
126
		if (figure instanceof WrapLabel) {
127
			return ((WrapLabel) figure).getIcon();
128
		} else {
129
			return ((Label) figure).getIcon();
130
		}
131
	}
132
133
	/**
134
	 * @generated
135
	 */
136
	protected void setLabelIconHelper(IFigure figure, Image icon) {
137
		if (figure instanceof WrapLabel) {
138
			((WrapLabel) figure).setIcon(icon);
139
		} else {
140
			((Label) figure).setIcon(icon);
141
		}
142
	}
143
144
	/**
145
	 * @generated
146
	 */
147
	public void setLabel(IFigure figure) {
148
		unregisterVisuals();
149
		setFigure(figure);
150
		defaultText = getLabelTextHelper(figure);
151
		registerVisuals();
152
		refreshVisuals();
153
	}
154
155
	/**
156
	 * @generated
157
	 */
158
	protected List getModelChildren() {
159
		return Collections.EMPTY_LIST;
160
	}
161
162
	/**
163
	 * @generated
164
	 */
165
	public IGraphicalEditPart getChildBySemanticHint(String semanticHint) {
166
		return null;
167
	}
168
169
	/**
170
	 * @generated
171
	 */
172
	protected EObject getParserElement() {
173
		EObject element = resolveSemanticElement();
174
		return element != null ? element : (View) getModel();
175
	}
176
177
	/**
178
	 * @generated
179
	 */
180
	protected Image getLabelIcon() {
181
		return null;
182
	}
183
184
	/**
185
	 * @generated
186
	 */
187
	protected String getLabelText() {
188
		String text = null;
189
		if (getParser() != null) {
190
			text = getParser().getPrintString(new EObjectAdapter(getParserElement()), getParserOptions().intValue());
191
		}
192
		if (text == null || text.length() == 0) {
193
			text = defaultText;
194
		}
195
		return text;
196
	}
197
198
	/**
199
	 * @generated
200
	 */
201
	public void setLabelText(String text) {
202
		setLabelTextHelper(getFigure(), text);
203
		Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
204
		if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) {
205
			((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback();
206
		}
207
	}
208
209
	/**
210
	 * @generated
211
	 */
212
	public String getEditText() {
213
		if (getParser() == null) {
214
			return ""; //$NON-NLS-1$
215
		}
216
		return getParser().getEditString(new EObjectAdapter(getParserElement()), getParserOptions().intValue());
217
	}
218
219
	/**
220
	 * @generated
221
	 */
222
	protected boolean isEditable() {
223
		return getEditText() != null;
224
	}
225
226
	/**
227
	 * @generated
228
	 */
229
	public ICellEditorValidator getEditTextValidator() {
230
		return new ICellEditorValidator() {
231
232
			public String isValid(final Object value) {
233
				if (value instanceof String) {
234
					final EObject element = getParserElement();
235
					final IParser parser = getParser();
236
					try {
237
						IParserEditStatus valid = (IParserEditStatus) getEditingDomain().runExclusive(new RunnableWithResult.Impl() {
238
239
							public void run() {
240
								setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value));
241
							}
242
						});
243
						return valid.getCode() == ParserEditStatus.EDITABLE ? null : valid.getMessage();
244
					} catch (InterruptedException ie) {
245
						ie.printStackTrace();
246
					}
247
				}
248
249
				// shouldn't get here
250
				return null;
251
			}
252
		};
253
	}
254
255
	/**
256
	 * @generated
257
	 */
258
	public IContentAssistProcessor getCompletionProcessor() {
259
		if (getParser() == null) {
260
			return null;
261
		}
262
		return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement()));
263
	}
264
265
	/**
266
	 * @generated
267
	 */
268
	public ParserOptions getParserOptions() {
269
		return ParserOptions.NONE;
270
	}
271
272
	/**
273
	 * @generated
274
	 */
275
	public IParser getParser() {
276
		if (parser == null) {
277
			String parserHint = ((View) getModel()).getType();
278
			ParserHintAdapter hintAdapter = new ParserHintAdapter(getParserElement(), parserHint) {
279
280
				public Object getAdapter(Class adapter) {
281
					if (IElementType.class.equals(adapter)) {
282
						return UMLElementTypes.Interface_2010;
283
					}
284
					return super.getAdapter(adapter);
285
				}
286
			};
287
			parser = ParserService.getInstance().getParser(hintAdapter);
288
		}
289
		return parser;
290
	}
291
292
	/**
293
	 * @generated
294
	 */
295
	protected DirectEditManager getManager() {
296
		if (manager == null) {
297
			setManager(new TextDirectEditManager(this, TextDirectEditManager.getTextCellEditorClass(this), UMLEditPartFactory.getTextCellEditorLocator(this)));
298
		}
299
		return manager;
300
	}
301
302
	/**
303
	 * @generated
304
	 */
305
	protected void setManager(DirectEditManager manager) {
306
		this.manager = manager;
307
	}
308
309
	/**
310
	 * @generated
311
	 */
312
	protected void performDirectEdit() {
313
		getManager().show();
314
	}
315
316
	/**
317
	 * @generated
318
	 */
319
	protected void performDirectEdit(Point eventLocation) {
320
		if (getManager().getClass() == TextDirectEditManager.class) {
321
			((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint());
322
		}
323
	}
324
325
	/**
326
	 * @generated
327
	 */
328
	private void performDirectEdit(char initialCharacter) {
329
		if (getManager() instanceof TextDirectEditManager) {
330
			((TextDirectEditManager) getManager()).show(initialCharacter);
331
		} else {
332
			performDirectEdit();
333
		}
334
	}
335
336
	/**
337
	 * @generated
338
	 */
339
	protected void performDirectEditRequest(Request request) {
340
		final Request theRequest = request;
341
		try {
342
			getEditingDomain().runExclusive(new Runnable() {
343
344
				public void run() {
345
					if (isActive() && isEditable()) {
346
						if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) {
347
							Character initialChar = (Character) theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR);
348
							performDirectEdit(initialChar.charValue());
349
						} else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) {
350
							DirectEditRequest editRequest = (DirectEditRequest) theRequest;
351
							performDirectEdit(editRequest.getLocation());
352
						} else {
353
							performDirectEdit();
354
						}
355
					}
356
				}
357
			});
358
		} catch (InterruptedException e) {
359
			e.printStackTrace();
360
		}
361
	}
362
363
	/**
364
	 * @generated
365
	 */
366
	protected void refreshVisuals() {
367
		super.refreshVisuals();
368
		refreshLabel();
369
		refreshFont();
370
		refreshFontColor();
371
		refreshUnderline();
372
		refreshStrikeThrough();
373
	}
374
375
	/**
376
	 * @generated
377
	 */
378
	protected void refreshLabel() {
379
		setLabelTextHelper(getFigure(), getLabelText());
380
		setLabelIconHelper(getFigure(), getLabelIcon());
381
		Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
382
		if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) {
383
			((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback();
384
		}
385
	}
386
387
	/**
388
	 * @generated
389
	 */
390
	protected void refreshUnderline() {
391
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
392
		if (style != null && getFigure() instanceof WrapLabel) {
393
			((WrapLabel) getFigure()).setTextUnderline(style.isUnderline());
394
		}
395
	}
396
397
	/**
398
	 * @generated
399
	 */
400
	protected void refreshStrikeThrough() {
401
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
402
		if (style != null && getFigure() instanceof WrapLabel) {
403
			((WrapLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough());
404
		}
405
	}
406
407
	/**
408
	 * @generated
409
	 */
410
	protected void refreshFont() {
411
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
412
		if (style != null) {
413
			FontData fontData = new FontData(style.getFontName(), style.getFontHeight(), (style.isBold() ? SWT.BOLD : SWT.NORMAL) | (style.isItalic() ? SWT.ITALIC : SWT.NORMAL));
414
			setFont(fontData);
415
		}
416
	}
417
418
	/**
419
	 * @generated
420
	 */
421
	protected void setFontColor(Color color) {
422
		getFigure().setForegroundColor(color);
423
	}
424
425
	/**
426
	 * @generated
427
	 */
428
	protected void addSemanticListeners() {
429
		if (getParser() instanceof ISemanticParser) {
430
			EObject element = resolveSemanticElement();
431
			parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element);
432
			for (int i = 0; i < parserElements.size(); i++) {
433
				addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$
434
			}
435
		} else {
436
			super.addSemanticListeners();
437
		}
438
	}
439
440
	/**
441
	 * @generated
442
	 */
443
	protected void removeSemanticListeners() {
444
		if (parserElements != null) {
445
			for (int i = 0; i < parserElements.size(); i++) {
446
				removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$
447
			}
448
		} else {
449
			super.removeSemanticListeners();
450
		}
451
	}
452
453
	/**
454
	 * @generated
455
	 */
456
	protected AccessibleEditPart getAccessibleEditPart() {
457
		if (accessibleEP == null) {
458
			accessibleEP = new AccessibleGraphicalEditPart() {
459
460
				public void getName(AccessibleEvent e) {
461
					e.result = getLabelTextHelper(getFigure());
462
				}
463
			};
464
		}
465
		return accessibleEP;
466
	}
467
468
	/**
469
	 * @generated
470
	 */
471
	private View getFontStyleOwnerView() {
472
		return getPrimaryView();
473
	}
474
475
	/**
476
	 * @generated
477
	 */
478
	protected void handleNotificationEvent(Notification event) {
479
		Object feature = event.getFeature();
480
		if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) {
481
			Integer c = (Integer) event.getNewValue();
482
			setFontColor(DiagramColorRegistry.getInstance().getColor(c));
483
		} else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) {
484
			refreshUnderline();
485
		} else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) {
486
			refreshStrikeThrough();
487
		} else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature)
488
				|| NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) {
489
			refreshFont();
490
		} else {
491
			if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) {
492
				refreshLabel();
493
			}
494
			if (getParser() instanceof ISemanticParser) {
495
				ISemanticParser modelParser = (ISemanticParser) getParser();
496
				if (modelParser.areSemanticElementsAffected(null, event)) {
497
					removeSemanticListeners();
498
					if (resolveSemanticElement() != null) {
499
						addSemanticListeners();
500
					}
501
					refreshLabel();
502
				}
503
			}
504
		}
505
		super.handleNotificationEvent(event);
506
	}
507
508
	/**
509
	 * @generated
510
	 */
511
	protected IFigure createFigure() {
512
		IFigure label = createFigurePrim();
513
		defaultText = getLabelTextHelper(label);
514
		return label;
515
	}
516
517
	/**
518
	 * @generated
519
	 */
520
	protected IFigure createFigurePrim() {
521
		return new WrapLabel();
522
	}
523
524
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/parts/AssociationEditPart.java (+144 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.parts;
2
3
import java.util.Iterator;
4
5
import org.eclipse.draw2d.Connection;
6
import org.eclipse.emf.common.notify.Notification;
7
import org.eclipse.gmf.runtime.diagram.ui.editparts.ConnectionNodeEditPart;
8
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
9
import org.eclipse.gmf.runtime.notation.View;
10
import org.eclipse.uml2.diagram.clazz.association.AssociationEndConvention;
11
import org.eclipse.uml2.diagram.clazz.edit.policies.AssociationItemSemanticEditPolicy;
12
import org.eclipse.uml2.uml.Association;
13
import org.eclipse.uml2.uml.Property;
14
15
/**
16
 * @generated
17
 */
18
public class AssociationEditPart extends ConnectionNodeEditPart {
19
20
	/**
21
	 * @generated
22
	 */
23
	public static final int VISUAL_ID = 4005;
24
25
	/**
26
	 * @generated
27
	 */
28
	public AssociationEditPart(View view) {
29
		super(view);
30
	}
31
32
	/**
33
	 * @generated
34
	 */
35
	protected void createDefaultEditPolicies() {
36
		super.createDefaultEditPolicies();
37
		installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new AssociationItemSemanticEditPolicy());
38
39
	}
40
41
	/**
42
	 * Creates figure for this edit part.
43
	 * 
44
	 * Body of this method does not depend on settings in generation model
45
	 * so you may safely remove <i>generated</i> tag and modify it.
46
	 * 
47
	 * @generated
48
	 */
49
	protected Connection createConnectionFigureGen() {
50
		return new AssociationLinkFigure();
51
	}
52
53
	/**
54
	 * @generated NOT
55
	 */
56
	protected Connection createConnectionFigure() {
57
		Connection result = createConnectionFigureGen();
58
		refreshDecorations((AssociationLinkFigure) result);
59
		return result;
60
	}
61
62
	/**
63
	 * @NOT-GENERATED
64
	 */
65
	protected void addSemanticListeners() {
66
		super.addSemanticListeners();
67
		Association association = (Association) resolveSemanticElement();
68
		for (Iterator ends = association.getMemberEnds().iterator(); ends.hasNext();) {
69
			Property next = (Property) ends.next();
70
			addListenerFilter("SemanticModel", this, next);
71
		}
72
	}
73
74
	/**
75
	 * @NOT-GENERATED
76
	 */
77
	protected void handleNotificationEvent(Notification notification) {
78
		super.handleNotificationEvent(notification);
79
		if (notification.getNotifier() instanceof Property) {
80
			refreshDecorations((AssociationLinkFigure) getConnectionFigure());
81
		}
82
	}
83
84
	/**
85
	 * @NOT-GENERATED
86
	 */
87
	private void refreshDecorations(AssociationLinkFigure linkFigure) {
88
		Association association = (Association) resolveSemanticElement();
89
		Property sourceEnd = AssociationEndConvention.getSourceEnd(association);
90
		Property targetEnd = AssociationEndConvention.getTargetEnd(association);
91
92
		linkFigure.getSourceDecorationImpl().update(association, sourceEnd);
93
		linkFigure.getTargetDecorationImpl().update(association, targetEnd);
94
	}
95
96
	/**
97
	 * @generated
98
	 */
99
	public class AssociationLinkFigure extends org.eclipse.gmf.runtime.draw2d.ui.figures.PolylineConnectionEx {
100
101
		/**
102
		 * @generated
103
		 */
104
		public AssociationLinkFigure() {
105
			this.setForegroundColor(org.eclipse.draw2d.ColorConstants.blue);
106
			setSourceDecoration(createSourceDecoration());
107
			setTargetDecoration(createTargetDecoration());
108
		}
109
110
		/**
111
		 * @generated
112
		 */
113
		private org.eclipse.uml2.diagram.common.draw2d.AssociationDecoration createSourceDecoration() {
114
			org.eclipse.uml2.diagram.common.draw2d.AssociationDecoration df = new org.eclipse.uml2.diagram.common.draw2d.AssociationDecoration();
115
116
			return df;
117
		}
118
119
		/**
120
		 * @generated
121
		 */
122
		private org.eclipse.uml2.diagram.common.draw2d.AssociationDecoration createTargetDecoration() {
123
			org.eclipse.uml2.diagram.common.draw2d.AssociationDecoration df = new org.eclipse.uml2.diagram.common.draw2d.AssociationDecoration();
124
125
			return df;
126
		}
127
128
		/**
129
		 * @generated NOT
130
		 */
131
		private org.eclipse.uml2.diagram.common.draw2d.AssociationDecoration getTargetDecorationImpl() {
132
			return (org.eclipse.uml2.diagram.common.draw2d.AssociationDecoration) getTargetDecoration();
133
		}
134
135
		/**
136
		 * @generated NOT
137
		 */
138
		private org.eclipse.uml2.diagram.common.draw2d.AssociationDecoration getSourceDecorationImpl() {
139
			return (org.eclipse.uml2.diagram.common.draw2d.AssociationDecoration) getSourceDecoration();
140
		}
141
142
	}
143
144
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/parts/Class2EditPart.java (+578 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.parts;
2
3
import org.eclipse.draw2d.IFigure;
4
import org.eclipse.draw2d.PositionConstants;
5
import org.eclipse.draw2d.StackLayout;
6
import org.eclipse.gef.EditPart;
7
import org.eclipse.gef.EditPolicy;
8
import org.eclipse.gef.Request;
9
import org.eclipse.gef.commands.Command;
10
import org.eclipse.gef.editpolicies.LayoutEditPolicy;
11
import org.eclipse.gef.editpolicies.NonResizableEditPolicy;
12
import org.eclipse.gef.requests.CreateRequest;
13
import org.eclipse.gmf.runtime.diagram.core.edithelpers.CreateElementRequestAdapter;
14
import org.eclipse.gmf.runtime.diagram.ui.editparts.AbstractBorderedShapeEditPart;
15
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
16
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.CreationEditPolicy;
17
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.DragDropEditPolicy;
18
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
19
import org.eclipse.gmf.runtime.diagram.ui.figures.BorderItemLocator;
20
import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewAndElementRequest;
21
import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout;
22
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
23
import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure;
24
import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure;
25
import org.eclipse.gmf.runtime.notation.View;
26
import org.eclipse.uml2.diagram.clazz.edit.policies.Class2CanonicalEditPolicy;
27
import org.eclipse.uml2.diagram.clazz.edit.policies.Class2ItemSemanticEditPolicy;
28
import org.eclipse.uml2.diagram.clazz.part.UMLVisualIDRegistry;
29
import org.eclipse.uml2.diagram.clazz.providers.UMLElementTypes;
30
31
/**
32
 * @generated
33
 */
34
public class Class2EditPart extends AbstractBorderedShapeEditPart {
35
36
	/**
37
	 * @generated
38
	 */
39
	public static final int VISUAL_ID = 2001;
40
41
	/**
42
	 * @generated
43
	 */
44
	protected IFigure contentPane;
45
46
	/**
47
	 * @generated
48
	 */
49
	protected IFigure primaryShape;
50
51
	/**
52
	 * @generated
53
	 */
54
	public Class2EditPart(View view) {
55
		super(view);
56
	}
57
58
	/**
59
	 * @generated
60
	 */
61
	protected void createDefaultEditPolicies() {
62
		installEditPolicy(EditPolicyRoles.CREATION_ROLE, new CreationEditPolicy() {
63
64
			public Command getCommand(Request request) {
65
				if (understandsRequest(request)) {
66
					if (request instanceof CreateViewAndElementRequest) {
67
						CreateElementRequestAdapter adapter = ((CreateViewAndElementRequest) request).getViewAndElementDescriptor().getCreateElementRequestAdapter();
68
						IElementType type = (IElementType) adapter.getAdapter(IElementType.class);
69
						if (type == UMLElementTypes.Property_3001) {
70
							EditPart compartmentEditPart = getChildBySemanticHint(UMLVisualIDRegistry.getType(ClassAttributesEditPart.VISUAL_ID));
71
							return compartmentEditPart == null ? null : compartmentEditPart.getCommand(request);
72
						}
73
						if (type == UMLElementTypes.Operation_3002) {
74
							EditPart compartmentEditPart = getChildBySemanticHint(UMLVisualIDRegistry.getType(ClassOperationsEditPart.VISUAL_ID));
75
							return compartmentEditPart == null ? null : compartmentEditPart.getCommand(request);
76
						}
77
						if (type == UMLElementTypes.Class_3003) {
78
							EditPart compartmentEditPart = getChildBySemanticHint(UMLVisualIDRegistry.getType(ClassClassesEditPart.VISUAL_ID));
79
							return compartmentEditPart == null ? null : compartmentEditPart.getCommand(request);
80
						}
81
					}
82
					return super.getCommand(request);
83
				}
84
				return null;
85
			}
86
		});
87
		super.createDefaultEditPolicies();
88
		installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new Class2ItemSemanticEditPolicy());
89
		installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, new DragDropEditPolicy());
90
		installEditPolicy(EditPolicyRoles.CANONICAL_ROLE, new Class2CanonicalEditPolicy());
91
		installEditPolicy(EditPolicy.LAYOUT_ROLE, createLayoutEditPolicy());
92
93
	}
94
95
	/**
96
	 * @generated
97
	 */
98
	protected LayoutEditPolicy createLayoutEditPolicy() {
99
		LayoutEditPolicy lep = new LayoutEditPolicy() {
100
101
			protected EditPolicy createChildEditPolicy(EditPart child) {
102
				EditPolicy result = child.getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
103
				if (result == null) {
104
					result = new NonResizableEditPolicy();
105
				}
106
				return result;
107
			}
108
109
			protected Command getMoveChildrenCommand(Request request) {
110
				return null;
111
			}
112
113
			protected Command getCreateCommand(CreateRequest request) {
114
				return null;
115
			}
116
		};
117
		return lep;
118
	}
119
120
	/**
121
	 * @generated
122
	 */
123
	protected IFigure createNodeShape() {
124
		ClassFigure figure = new ClassFigure();
125
		return primaryShape = figure;
126
	}
127
128
	/**
129
	 * @generated
130
	 */
131
	public ClassFigure getPrimaryShape() {
132
		return (ClassFigure) primaryShape;
133
	}
134
135
	/**
136
	 * @generated 
137
	 */
138
	protected IFigure getContentPaneFor(IGraphicalEditPart editPart) {
139
		if (editPart instanceof ClassAttributesEditPart) {
140
			return getPrimaryShape().getFigureClassFigure_PropertiesCompartment();
141
		}
142
		if (editPart instanceof ClassOperationsEditPart) {
143
			return getPrimaryShape().getFigureClassFigure_OperationsCompartment();
144
		}
145
		if (editPart instanceof ClassClassesEditPart) {
146
			return getPrimaryShape().getFigureClassFigure_ClassesCompartment();
147
		}
148
		if (editPart instanceof PortEditPart) {
149
			return getBorderedFigure().getBorderItemContainer();
150
		}
151
152
		return super.getContentPaneFor(editPart);
153
	}
154
155
	/**
156
	 * @generated
157
	 */
158
	protected boolean addFixedChild(EditPart childEditPart) {
159
		if (childEditPart instanceof ClassNameEditPart) {
160
			((ClassNameEditPart) childEditPart).setLabel(getPrimaryShape().getFigureClassFigure_name());
161
			return true;
162
		}
163
		if (childEditPart instanceof ClassAttributesEditPart) {
164
			IFigure pane = getPrimaryShape().getFigureClassFigure_PropertiesCompartment();
165
			setupContentPane(pane); // FIXME each comparment should handle his content pane in his own way 
166
			pane.add(((ClassAttributesEditPart) childEditPart).getFigure());
167
			return true;
168
		}
169
		if (childEditPart instanceof ClassOperationsEditPart) {
170
			IFigure pane = getPrimaryShape().getFigureClassFigure_OperationsCompartment();
171
			setupContentPane(pane); // FIXME each comparment should handle his content pane in his own way 
172
			pane.add(((ClassOperationsEditPart) childEditPart).getFigure());
173
			return true;
174
		}
175
		if (childEditPart instanceof ClassClassesEditPart) {
176
			IFigure pane = getPrimaryShape().getFigureClassFigure_ClassesCompartment();
177
			setupContentPane(pane); // FIXME each comparment should handle his content pane in his own way 
178
			pane.add(((ClassClassesEditPart) childEditPart).getFigure());
179
			return true;
180
		}
181
		if (childEditPart instanceof PortEditPart) {
182
			BorderItemLocator locator = new BorderItemLocator(getMainFigure(), PositionConstants.NONE);
183
			getBorderedFigure().getBorderItemContainer().add(((PortEditPart) childEditPart).getFigure(), locator);
184
			return true;
185
		}
186
		return false;
187
	}
188
189
	/**
190
	 * @generated
191
	 */
192
	protected boolean removeFixedChild(EditPart childEditPart) {
193
		if (childEditPart instanceof ClassAttributesEditPart) {
194
			IFigure pane = getPrimaryShape().getFigureClassFigure_PropertiesCompartment();
195
			pane.remove(((ClassAttributesEditPart) childEditPart).getFigure());
196
			return true;
197
		}
198
		if (childEditPart instanceof ClassOperationsEditPart) {
199
			IFigure pane = getPrimaryShape().getFigureClassFigure_OperationsCompartment();
200
			pane.remove(((ClassOperationsEditPart) childEditPart).getFigure());
201
			return true;
202
		}
203
		if (childEditPart instanceof ClassClassesEditPart) {
204
			IFigure pane = getPrimaryShape().getFigureClassFigure_ClassesCompartment();
205
			pane.remove(((ClassClassesEditPart) childEditPart).getFigure());
206
			return true;
207
		}
208
		if (childEditPart instanceof PortEditPart) {
209
			getBorderedFigure().getBorderItemContainer().remove(((PortEditPart) childEditPart).getFigure());
210
			return true;
211
		}
212
		return false;
213
	}
214
215
	/**
216
	 * @generated
217
	 */
218
	protected NodeFigure createNodePlate() {
219
		DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(getMapMode().DPtoLP(100), getMapMode().DPtoLP(60));
220
		return result;
221
	}
222
223
	/**
224
	 * Creates figure for this edit part.
225
	 * 
226
	 * Body of this method does not depend on settings in generation model
227
	 * so you may safely remove <i>generated</i> tag and modify it.
228
	 * 
229
	 * @generated
230
	 */
231
	protected NodeFigure createMainFigure() {
232
		NodeFigure figure = createNodePlate();
233
		figure.setLayoutManager(new StackLayout());
234
		IFigure shape = createNodeShape();
235
		figure.add(shape);
236
		contentPane = setupContentPane(shape);
237
		return figure;
238
	}
239
240
	/**
241
	 * Default implementation treats passed figure as content pane.
242
	 * Respects layout one may have set for generated figure.
243
	 * @param nodeShape instance of generated figure class
244
	 * @generated
245
	 */
246
	protected IFigure setupContentPane(IFigure nodeShape) {
247
		if (nodeShape.getLayoutManager() == null) {
248
			ConstrainedToolbarLayout layout = new ConstrainedToolbarLayout();
249
			layout.setSpacing(getMapMode().DPtoLP(5));
250
			nodeShape.setLayoutManager(layout);
251
		}
252
		return nodeShape; // use nodeShape itself as contentPane
253
	}
254
255
	/**
256
	 * @generated
257
	 */
258
	public IFigure getContentPane() {
259
		if (contentPane != null) {
260
			return contentPane;
261
		}
262
		return super.getContentPane();
263
	}
264
265
	/**
266
	 * @generated
267
	 */
268
	public EditPart getPrimaryChildEditPart() {
269
		return getChildBySemanticHint(UMLVisualIDRegistry.getType(ClassNameEditPart.VISUAL_ID));
270
	}
271
272
	/**
273
	 * @generated
274
	 */
275
	protected void addChildVisual(EditPart childEditPart, int index) {
276
		if (addFixedChild(childEditPart)) {
277
			return;
278
		}
279
		super.addChildVisual(childEditPart, -1);
280
	}
281
282
	/**
283
	 * @generated
284
	 */
285
	protected void removeChildVisual(EditPart childEditPart) {
286
		if (removeFixedChild(childEditPart)) {
287
			return;
288
		}
289
		super.removeChildVisual(childEditPart);
290
	}
291
292
	/**
293
	 * @generated
294
	 */
295
	public class ClassFigure extends org.eclipse.draw2d.RectangleFigure {
296
297
		/**
298
		 * @generated
299
		 */
300
		public ClassFigure() {
301
302
			org.eclipse.gmf.internal.codegen.draw2d.GridLayout myGenLayoutManager = new org.eclipse.gmf.internal.codegen.draw2d.GridLayout();
303
			myGenLayoutManager.numColumns = 1;
304
			myGenLayoutManager.makeColumnsEqualWidth = true;
305
			myGenLayoutManager.marginWidth = 0;
306
			myGenLayoutManager.marginHeight = 0;
307
			myGenLayoutManager.horizontalSpacing = 0;
308
			myGenLayoutManager.verticalSpacing = 0;
309
310
			this.setLayoutManager(myGenLayoutManager);
311
312
			this.setFill(false);
313
			this.setOutline(false);
314
			createContents();
315
		}
316
317
		/**
318
		 * @generated
319
		 */
320
		private void createContents() {
321
			org.eclipse.draw2d.RectangleFigure fig_0 = new org.eclipse.draw2d.RectangleFigure();
322
323
			fig_0.setMinimumSize(new org.eclipse.draw2d.geometry.Dimension(getMapMode().DPtoLP(0), getMapMode().DPtoLP(25)));
324
325
			org.eclipse.uml2.diagram.common.draw2d.CenterLayout layouter0 = new org.eclipse.uml2.diagram.common.draw2d.CenterLayout();
326
327
			fig_0.setLayoutManager(layouter0);
328
329
			setFigureClassFigure_NameContainer(fig_0);
330
			org.eclipse.gmf.internal.codegen.draw2d.GridLayoutData layData0 = new org.eclipse.gmf.internal.codegen.draw2d.GridLayoutData();
331
			layData0.verticalAlignment = org.eclipse.gmf.internal.codegen.draw2d.GridLayoutData.FILL;
332
			layData0.horizontalAlignment = org.eclipse.gmf.internal.codegen.draw2d.GridLayoutData.FILL;
333
			layData0.horizontalIndent = 0;
334
			layData0.horizontalSpan = 2;
335
			layData0.verticalSpan = 1;
336
			layData0.grabExcessHorizontalSpace = true;
337
			layData0.grabExcessVerticalSpace = false;
338
339
			this.add(fig_0, layData0);
340
			org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel fig_1 = new org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel();
341
342
			setFigureClassFigure_name(fig_1);
343
344
			Object layData1 = null;
345
346
			fig_0.add(fig_1, layData1);
347
			org.eclipse.draw2d.RectangleFigure fig_2 = new org.eclipse.draw2d.RectangleFigure();
348
349
			org.eclipse.draw2d.ToolbarLayout layouter2 = new org.eclipse.draw2d.ToolbarLayout();
350
			layouter2.setStretchMinorAxis(true);
351
			layouter2.setMinorAlignment(org.eclipse.draw2d.ToolbarLayout.ALIGN_CENTER);
352
			layouter2.setSpacing(0);
353
			layouter2.setVertical(true);
354
355
			fig_2.setLayoutManager(layouter2);
356
357
			setFigureClassFigure_Body(fig_2);
358
			org.eclipse.gmf.internal.codegen.draw2d.GridLayoutData layData2 = new org.eclipse.gmf.internal.codegen.draw2d.GridLayoutData();
359
			layData2.verticalAlignment = org.eclipse.gmf.internal.codegen.draw2d.GridLayoutData.FILL;
360
			layData2.horizontalAlignment = org.eclipse.gmf.internal.codegen.draw2d.GridLayoutData.FILL;
361
			layData2.horizontalIndent = 0;
362
			layData2.horizontalSpan = 2;
363
			layData2.verticalSpan = 1;
364
			layData2.grabExcessHorizontalSpace = true;
365
			layData2.grabExcessVerticalSpace = true;
366
367
			this.add(fig_2, layData2);
368
			org.eclipse.draw2d.RectangleFigure fig_3 = new org.eclipse.draw2d.RectangleFigure();
369
370
			setFigureClassFigure_PropertiesCompartment(fig_3);
371
372
			Object layData3 = null;
373
374
			fig_2.add(fig_3, layData3);
375
			org.eclipse.draw2d.RectangleFigure fig_4 = new org.eclipse.draw2d.RectangleFigure();
376
377
			setFigureClassFigure_OperationsCompartment(fig_4);
378
379
			Object layData4 = null;
380
381
			fig_2.add(fig_4, layData4);
382
			org.eclipse.draw2d.RectangleFigure fig_5 = new org.eclipse.draw2d.RectangleFigure();
383
384
			setFigureClassFigure_ClassesCompartment(fig_5);
385
386
			Object layData5 = null;
387
388
			fig_2.add(fig_5, layData5);
389
			org.eclipse.draw2d.RectangleFigure fig_6 = new org.eclipse.draw2d.RectangleFigure();
390
391
			setFigureClassFigure_LiteralsCompartment(fig_6);
392
393
			Object layData6 = null;
394
395
			fig_2.add(fig_6, layData6);
396
			org.eclipse.draw2d.RectangleFigure fig_7 = new org.eclipse.draw2d.RectangleFigure();
397
398
			setFigureClassFigure_OthersCompartment(fig_7);
399
400
			Object layData7 = null;
401
402
			fig_2.add(fig_7, layData7);
403
		}
404
405
		/**
406
		 * @generated
407
		 */
408
		private org.eclipse.draw2d.RectangleFigure fClassFigure_NameContainer;
409
410
		/**
411
		 * @generated
412
		 */
413
		public org.eclipse.draw2d.RectangleFigure getFigureClassFigure_NameContainer() {
414
			return fClassFigure_NameContainer;
415
		}
416
417
		/**
418
		 * @generated
419
		 */
420
		private void setFigureClassFigure_NameContainer(org.eclipse.draw2d.RectangleFigure fig) {
421
			fClassFigure_NameContainer = fig;
422
		}
423
424
		/**
425
		 * @generated
426
		 */
427
		private org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel fClassFigure_name;
428
429
		/**
430
		 * @generated
431
		 */
432
		public org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel getFigureClassFigure_name() {
433
			return fClassFigure_name;
434
		}
435
436
		/**
437
		 * @generated
438
		 */
439
		private void setFigureClassFigure_name(org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel fig) {
440
			fClassFigure_name = fig;
441
		}
442
443
		/**
444
		 * @generated
445
		 */
446
		private org.eclipse.draw2d.RectangleFigure fClassFigure_Body;
447
448
		/**
449
		 * @generated
450
		 */
451
		public org.eclipse.draw2d.RectangleFigure getFigureClassFigure_Body() {
452
			return fClassFigure_Body;
453
		}
454
455
		/**
456
		 * @generated
457
		 */
458
		private void setFigureClassFigure_Body(org.eclipse.draw2d.RectangleFigure fig) {
459
			fClassFigure_Body = fig;
460
		}
461
462
		/**
463
		 * @generated
464
		 */
465
		private org.eclipse.draw2d.RectangleFigure fClassFigure_PropertiesCompartment;
466
467
		/**
468
		 * @generated
469
		 */
470
		public org.eclipse.draw2d.RectangleFigure getFigureClassFigure_PropertiesCompartment() {
471
			return fClassFigure_PropertiesCompartment;
472
		}
473
474
		/**
475
		 * @generated
476
		 */
477
		private void setFigureClassFigure_PropertiesCompartment(org.eclipse.draw2d.RectangleFigure fig) {
478
			fClassFigure_PropertiesCompartment = fig;
479
		}
480
481
		/**
482
		 * @generated
483
		 */
484
		private org.eclipse.draw2d.RectangleFigure fClassFigure_OperationsCompartment;
485
486
		/**
487
		 * @generated
488
		 */
489
		public org.eclipse.draw2d.RectangleFigure getFigureClassFigure_OperationsCompartment() {
490
			return fClassFigure_OperationsCompartment;
491
		}
492
493
		/**
494
		 * @generated
495
		 */
496
		private void setFigureClassFigure_OperationsCompartment(org.eclipse.draw2d.RectangleFigure fig) {
497
			fClassFigure_OperationsCompartment = fig;
498
		}
499
500
		/**
501
		 * @generated
502
		 */
503
		private org.eclipse.draw2d.RectangleFigure fClassFigure_ClassesCompartment;
504
505
		/**
506
		 * @generated
507
		 */
508
		public org.eclipse.draw2d.RectangleFigure getFigureClassFigure_ClassesCompartment() {
509
			return fClassFigure_ClassesCompartment;
510
		}
511
512
		/**
513
		 * @generated
514
		 */
515
		private void setFigureClassFigure_ClassesCompartment(org.eclipse.draw2d.RectangleFigure fig) {
516
			fClassFigure_ClassesCompartment = fig;
517
		}
518
519
		/**
520
		 * @generated
521
		 */
522
		private org.eclipse.draw2d.RectangleFigure fClassFigure_LiteralsCompartment;
523
524
		/**
525
		 * @generated
526
		 */
527
		public org.eclipse.draw2d.RectangleFigure getFigureClassFigure_LiteralsCompartment() {
528
			return fClassFigure_LiteralsCompartment;
529
		}
530
531
		/**
532
		 * @generated
533
		 */
534
		private void setFigureClassFigure_LiteralsCompartment(org.eclipse.draw2d.RectangleFigure fig) {
535
			fClassFigure_LiteralsCompartment = fig;
536
		}
537
538
		/**
539
		 * @generated
540
		 */
541
		private org.eclipse.draw2d.RectangleFigure fClassFigure_OthersCompartment;
542
543
		/**
544
		 * @generated
545
		 */
546
		public org.eclipse.draw2d.RectangleFigure getFigureClassFigure_OthersCompartment() {
547
			return fClassFigure_OthersCompartment;
548
		}
549
550
		/**
551
		 * @generated
552
		 */
553
		private void setFigureClassFigure_OthersCompartment(org.eclipse.draw2d.RectangleFigure fig) {
554
			fClassFigure_OthersCompartment = fig;
555
		}
556
557
		/**
558
		 * @generated
559
		 */
560
		private boolean myUseLocalCoordinates = false;
561
562
		/**
563
		 * @generated
564
		 */
565
		protected boolean useLocalCoordinates() {
566
			return myUseLocalCoordinates;
567
		}
568
569
		/**
570
		 * @generated
571
		 */
572
		protected void setUseLocalCoordinates(boolean useLocalCoordinates) {
573
			myUseLocalCoordinates = useLocalCoordinates;
574
		}
575
576
	}
577
578
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/policies/PrimitiveType2ItemSemanticEditPolicy.java (+455 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.policies;
2
3
import org.eclipse.emf.ecore.EAnnotation;
4
import org.eclipse.emf.ecore.EClass;
5
import org.eclipse.emf.ecore.EObject;
6
import org.eclipse.gef.commands.Command;
7
import org.eclipse.gef.commands.UnexecutableCommand;
8
import org.eclipse.gmf.runtime.emf.type.core.commands.CreateRelationshipCommand;
9
import org.eclipse.gmf.runtime.emf.type.core.commands.DestroyElementCommand;
10
import org.eclipse.gmf.runtime.emf.type.core.commands.SetValueCommand;
11
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest;
12
import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest;
13
import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest;
14
import org.eclipse.gmf.runtime.notation.View;
15
import org.eclipse.uml2.diagram.clazz.providers.UMLElementTypes;
16
import org.eclipse.uml2.uml.Association;
17
import org.eclipse.uml2.uml.Classifier;
18
import org.eclipse.uml2.uml.Constraint;
19
import org.eclipse.uml2.uml.Dependency;
20
import org.eclipse.uml2.uml.Generalization;
21
import org.eclipse.uml2.uml.NamedElement;
22
import org.eclipse.uml2.uml.Property;
23
import org.eclipse.uml2.uml.Type;
24
import org.eclipse.uml2.uml.UMLPackage;
25
import org.eclipse.uml2.uml.Usage;
26
27
/**
28
 * @generated
29
 */
30
public class PrimitiveType2ItemSemanticEditPolicy extends UMLBaseItemSemanticEditPolicy {
31
32
	/**
33
	 * @generated
34
	 */
35
	protected Command getDestroyElementCommand(DestroyElementRequest req) {
36
		return getMSLWrapper(new DestroyElementCommand(req) {
37
38
			protected EObject getElementToDestroy() {
39
				View view = (View) getHost().getModel();
40
				EAnnotation annotation = view.getEAnnotation("Shortcut"); //$NON-NLS-1$
41
				if (annotation != null) {
42
					return view;
43
				}
44
				return super.getElementToDestroy();
45
			}
46
47
		});
48
	}
49
50
	/**
51
	 * @generated
52
	 */
53
	protected Command getCreateRelationshipCommand(CreateRelationshipRequest req) {
54
		if (UMLElementTypes.Generalization_4001 == req.getElementType()) {
55
			return req.getTarget() == null ? getCreateStartOutgoingGeneralization4001Command(req) : getCreateCompleteIncomingGeneralization4001Command(req);
56
		}
57
		if (UMLElementTypes.Dependency_4002 == req.getElementType()) {
58
			return req.getTarget() == null ? getCreateStartOutgoingDependency4002Command(req) : getCreateCompleteIncomingDependency4002Command(req);
59
		}
60
		if (UMLElementTypes.Property_4003 == req.getElementType()) {
61
			return req.getTarget() == null ? null : getCreateCompleteIncomingProperty4003Command(req);
62
		}
63
		if (UMLElementTypes.ConstraintConstrainedElement_4004 == req.getElementType()) {
64
			return req.getTarget() == null ? null : getCreateCompleteIncomingConstraint_ConstrainedElement4004Command(req);
65
		}
66
		if (UMLElementTypes.Association_4005 == req.getElementType()) {
67
			return req.getTarget() == null ? getCreateStartOutgoingAssociation4005Command(req) : getCreateCompleteIncomingAssociation4005Command(req);
68
		}
69
		if (UMLElementTypes.DependencySupplier_4006 == req.getElementType()) {
70
			return req.getTarget() == null ? null : getCreateCompleteIncomingDependency_Supplier4006Command(req);
71
		}
72
		if (UMLElementTypes.DependencyClient_4007 == req.getElementType()) {
73
			return req.getTarget() == null ? null : getCreateCompleteIncomingDependency_Client4007Command(req);
74
		}
75
		if (UMLElementTypes.Usage_4009 == req.getElementType()) {
76
			return req.getTarget() == null ? getCreateStartOutgoingUsage4009Command(req) : getCreateCompleteIncomingUsage4009Command(req);
77
		}
78
		return super.getCreateRelationshipCommand(req);
79
	}
80
81
	/**
82
	 * @generated
83
	 */
84
	protected Command getCreateStartOutgoingGeneralization4001Command(CreateRelationshipRequest req) {
85
		return new Command() {
86
		};
87
	}
88
89
	/**
90
	 * @generated
91
	 */
92
	protected Command getCreateCompleteIncomingGeneralization4001Command(CreateRelationshipRequest req) {
93
		if (!(req.getSource() instanceof Classifier)) {
94
			return UnexecutableCommand.INSTANCE;
95
		}
96
		final Classifier element = (Classifier) req.getSource();
97
		if (req.getContainmentFeature() == null) {
98
			req.setContainmentFeature(UMLPackage.eINSTANCE.getClassifier_Generalization());
99
		}
100
		return getMSLWrapper(new CreateIncomingGeneralization4001Command(req) {
101
102
			protected EObject getElementToEdit() {
103
				return element;
104
			}
105
		});
106
	}
107
108
	/**
109
	 * @generated
110
	 */
111
	private static class CreateIncomingGeneralization4001Command extends CreateRelationshipCommand {
112
113
		/**
114
		 * @generated
115
		 */
116
		public CreateIncomingGeneralization4001Command(CreateRelationshipRequest req) {
117
			super(req);
118
		}
119
120
		/**
121
		 * @generated
122
		 */
123
		protected EClass getEClassToEdit() {
124
			return UMLPackage.eINSTANCE.getClassifier();
125
		};
126
127
		/**
128
		 * @generated
129
		 */
130
		protected void setElementToEdit(EObject element) {
131
			throw new UnsupportedOperationException();
132
		}
133
134
		/**
135
		 * @generated
136
		 */
137
		protected EObject doDefaultElementCreation() {
138
			Generalization newElement = (Generalization) super.doDefaultElementCreation();
139
			if (newElement != null) {
140
				newElement.setGeneral((Classifier) getTarget());
141
			}
142
			return newElement;
143
		}
144
	}
145
146
	/**
147
	 * @generated
148
	 */
149
	protected Command getCreateStartOutgoingDependency4002Command(CreateRelationshipRequest req) {
150
		return new Command() {
151
		};
152
	}
153
154
	/**
155
	 * @generated
156
	 */
157
	protected Command getCreateCompleteIncomingDependency4002Command(CreateRelationshipRequest req) {
158
		if (!(req.getSource() instanceof NamedElement)) {
159
			return UnexecutableCommand.INSTANCE;
160
		}
161
		final org.eclipse.uml2.uml.Package element = (org.eclipse.uml2.uml.Package) getRelationshipContainer(req.getSource(), UMLPackage.eINSTANCE.getPackage(), req.getElementType());
162
		if (element == null) {
163
			return UnexecutableCommand.INSTANCE;
164
		}
165
		if (req.getContainmentFeature() == null) {
166
			req.setContainmentFeature(UMLPackage.eINSTANCE.getPackage_PackagedElement());
167
		}
168
		return getMSLWrapper(new CreateIncomingDependency4002Command(req) {
169
170
			protected EObject getElementToEdit() {
171
				return element;
172
			}
173
		});
174
	}
175
176
	/**
177
	 * @generated
178
	 */
179
	private static class CreateIncomingDependency4002Command extends CreateRelationshipCommand {
180
181
		/**
182
		 * @generated
183
		 */
184
		public CreateIncomingDependency4002Command(CreateRelationshipRequest req) {
185
			super(req);
186
		}
187
188
		/**
189
		 * @generated
190
		 */
191
		protected EClass getEClassToEdit() {
192
			return UMLPackage.eINSTANCE.getPackage();
193
		};
194
195
		/**
196
		 * @generated
197
		 */
198
		protected void setElementToEdit(EObject element) {
199
			throw new UnsupportedOperationException();
200
		}
201
202
		/**
203
		 * @generated
204
		 */
205
		protected EObject doDefaultElementCreation() {
206
			Dependency newElement = (Dependency) super.doDefaultElementCreation();
207
			if (newElement != null) {
208
				newElement.getSuppliers().add((NamedElement) getTarget());
209
				newElement.getClients().add((NamedElement) getSource());
210
			}
211
			return newElement;
212
		}
213
	}
214
215
	/**
216
	 * @generated
217
	 */
218
	protected Command getCreateCompleteIncomingProperty4003Command(CreateRelationshipRequest req) {
219
		if (!(req.getSource() instanceof Association)) {
220
			return UnexecutableCommand.INSTANCE;
221
		}
222
		final Association element = (Association) req.getSource();
223
		if (req.getContainmentFeature() == null) {
224
			req.setContainmentFeature(UMLPackage.eINSTANCE.getAssociation_OwnedEnd());
225
		}
226
		return getMSLWrapper(new CreateIncomingProperty4003Command(req) {
227
228
			protected EObject getElementToEdit() {
229
				return element;
230
			}
231
		});
232
	}
233
234
	/**
235
	 * @generated
236
	 */
237
	private static class CreateIncomingProperty4003Command extends CreateRelationshipCommand {
238
239
		/**
240
		 * @generated
241
		 */
242
		public CreateIncomingProperty4003Command(CreateRelationshipRequest req) {
243
			super(req);
244
		}
245
246
		/**
247
		 * @generated
248
		 */
249
		protected EClass getEClassToEdit() {
250
			return UMLPackage.eINSTANCE.getAssociation();
251
		};
252
253
		/**
254
		 * @generated
255
		 */
256
		protected void setElementToEdit(EObject element) {
257
			throw new UnsupportedOperationException();
258
		}
259
260
		/**
261
		 * @generated
262
		 */
263
		protected EObject doDefaultElementCreation() {
264
			Property newElement = (Property) super.doDefaultElementCreation();
265
			if (newElement != null) {
266
				newElement.setType((Type) getTarget());
267
			}
268
			return newElement;
269
		}
270
	}
271
272
	/**
273
	 * @generated
274
	 */
275
	protected Command getCreateCompleteIncomingConstraint_ConstrainedElement4004Command(CreateRelationshipRequest req) {
276
		if (!(req.getSource() instanceof Constraint)) {
277
			return UnexecutableCommand.INSTANCE;
278
		}
279
		Constraint element = (Constraint) req.getSource();
280
		if (element.getConstrainedElements().contains(req.getTarget())) {
281
			return UnexecutableCommand.INSTANCE;
282
		}
283
		SetRequest setReq = new SetRequest(req.getSource(), UMLPackage.eINSTANCE.getConstraint_ConstrainedElement(), req.getTarget());
284
		return getMSLWrapper(new SetValueCommand(setReq));
285
	}
286
287
	/**
288
	 * @generated
289
	 */
290
	protected Command getCreateStartOutgoingAssociation4005Command(CreateRelationshipRequest req) {
291
		return new Command() {
292
		};
293
	}
294
295
	/**
296
	 * @generated
297
	 */
298
	protected Command getCreateCompleteIncomingAssociation4005Command(CreateRelationshipRequest req) {
299
		if (!(req.getSource() instanceof Type)) {
300
			return UnexecutableCommand.INSTANCE;
301
		}
302
		final org.eclipse.uml2.uml.Package element = (org.eclipse.uml2.uml.Package) getRelationshipContainer(req.getSource(), UMLPackage.eINSTANCE.getPackage(), req.getElementType());
303
		if (element == null) {
304
			return UnexecutableCommand.INSTANCE;
305
		}
306
		if (req.getContainmentFeature() == null) {
307
			req.setContainmentFeature(UMLPackage.eINSTANCE.getPackage_PackagedElement());
308
		}
309
		return getMSLWrapper(new CreateIncomingAssociation4005Command(req) {
310
311
			protected EObject getElementToEdit() {
312
				return element;
313
			}
314
		});
315
	}
316
317
	/**
318
	 * @generated NOT
319
	 */
320
	private static class CreateIncomingAssociation4005Command extends CreateAssociationCommand {
321
322
		/**
323
		 * @generated
324
		 */
325
		public CreateIncomingAssociation4005Command(CreateRelationshipRequest req) {
326
			super(req);
327
		}
328
329
		/**
330
		 * @generated
331
		 */
332
		protected EClass getEClassToEdit() {
333
			return UMLPackage.eINSTANCE.getPackage();
334
		};
335
336
		/**
337
		 * @generated
338
		 */
339
		protected void setElementToEdit(EObject element) {
340
			throw new UnsupportedOperationException();
341
		}
342
343
		/**
344
		 * @generated NOT
345
		 */
346
		protected EObject doDefaultElementCreation() {
347
			return super.doDefaultElementCreation();
348
		}
349
	}
350
351
	/**
352
	 * @generated
353
	 */
354
	protected Command getCreateCompleteIncomingDependency_Supplier4006Command(CreateRelationshipRequest req) {
355
		if (!(req.getSource() instanceof Dependency)) {
356
			return UnexecutableCommand.INSTANCE;
357
		}
358
		Dependency element = (Dependency) req.getSource();
359
		if (element.getSuppliers().contains(req.getTarget())) {
360
			return UnexecutableCommand.INSTANCE;
361
		}
362
		SetRequest setReq = new SetRequest(req.getSource(), UMLPackage.eINSTANCE.getDependency_Supplier(), req.getTarget());
363
		return getMSLWrapper(new SetValueCommand(setReq));
364
	}
365
366
	/**
367
	 * @generated
368
	 */
369
	protected Command getCreateCompleteIncomingDependency_Client4007Command(CreateRelationshipRequest req) {
370
		if (!(req.getSource() instanceof Dependency)) {
371
			return UnexecutableCommand.INSTANCE;
372
		}
373
		Dependency element = (Dependency) req.getSource();
374
		if (element.getClients().contains(req.getTarget())) {
375
			return UnexecutableCommand.INSTANCE;
376
		}
377
		SetRequest setReq = new SetRequest(req.getSource(), UMLPackage.eINSTANCE.getDependency_Client(), req.getTarget());
378
		return getMSLWrapper(new SetValueCommand(setReq));
379
	}
380
381
	/**
382
	 * @generated
383
	 */
384
	protected Command getCreateStartOutgoingUsage4009Command(CreateRelationshipRequest req) {
385
		if (!UMLBaseItemSemanticEditPolicy.LinkConstraints.Usage_4009.canCreateLink(req, false)) {
386
			return UnexecutableCommand.INSTANCE;
387
		}
388
		return new Command() {
389
		};
390
	}
391
392
	/**
393
	 * @generated
394
	 */
395
	protected Command getCreateCompleteIncomingUsage4009Command(CreateRelationshipRequest req) {
396
		if (!(req.getSource() instanceof NamedElement)) {
397
			return UnexecutableCommand.INSTANCE;
398
		}
399
		final org.eclipse.uml2.uml.Package element = (org.eclipse.uml2.uml.Package) getRelationshipContainer(req.getSource(), UMLPackage.eINSTANCE.getPackage(), req.getElementType());
400
		if (element == null) {
401
			return UnexecutableCommand.INSTANCE;
402
		}
403
		if (!UMLBaseItemSemanticEditPolicy.LinkConstraints.Usage_4009.canCreateLink(req, false)) {
404
			return UnexecutableCommand.INSTANCE;
405
		}
406
		if (req.getContainmentFeature() == null) {
407
			req.setContainmentFeature(UMLPackage.eINSTANCE.getPackage_PackagedElement());
408
		}
409
		return getMSLWrapper(new CreateIncomingUsage4009Command(req) {
410
411
			protected EObject getElementToEdit() {
412
				return element;
413
			}
414
		});
415
	}
416
417
	/**
418
	 * @generated
419
	 */
420
	private static class CreateIncomingUsage4009Command extends CreateRelationshipCommand {
421
422
		/**
423
		 * @generated
424
		 */
425
		public CreateIncomingUsage4009Command(CreateRelationshipRequest req) {
426
			super(req);
427
		}
428
429
		/**
430
		 * @generated
431
		 */
432
		protected EClass getEClassToEdit() {
433
			return UMLPackage.eINSTANCE.getPackage();
434
		};
435
436
		/**
437
		 * @generated
438
		 */
439
		protected void setElementToEdit(EObject element) {
440
			throw new UnsupportedOperationException();
441
		}
442
443
		/**
444
		 * @generated
445
		 */
446
		protected EObject doDefaultElementCreation() {
447
			Usage newElement = (Usage) super.doDefaultElementCreation();
448
			if (newElement != null) {
449
				newElement.getSuppliers().add((NamedElement) getTarget());
450
				newElement.getClients().add((NamedElement) getSource());
451
			}
452
			return newElement;
453
		}
454
	}
455
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/parts/PackageNameEditPart.java (+551 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.parts;
2
3
import java.util.ArrayList;
4
import java.util.Collections;
5
import java.util.List;
6
7
import org.eclipse.draw2d.IFigure;
8
import org.eclipse.draw2d.Label;
9
import org.eclipse.draw2d.geometry.Point;
10
import org.eclipse.emf.common.notify.Notification;
11
import org.eclipse.emf.ecore.EObject;
12
import org.eclipse.emf.transaction.RunnableWithResult;
13
import org.eclipse.gef.AccessibleEditPart;
14
import org.eclipse.gef.EditPolicy;
15
import org.eclipse.gef.GraphicalEditPart;
16
import org.eclipse.gef.Request;
17
import org.eclipse.gef.commands.Command;
18
import org.eclipse.gef.editpolicies.NonResizableEditPolicy;
19
import org.eclipse.gef.handles.NonResizableHandleKit;
20
import org.eclipse.gef.requests.DirectEditRequest;
21
import org.eclipse.gef.tools.DirectEditManager;
22
import org.eclipse.gmf.runtime.common.ui.services.parser.IParser;
23
import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus;
24
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserEditStatus;
25
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions;
26
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserService;
27
import org.eclipse.gmf.runtime.diagram.ui.editparts.CompartmentEditPart;
28
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
29
import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart;
30
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy;
31
import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry;
32
import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants;
33
import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager;
34
import org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel;
35
import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
36
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
37
import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser;
38
import org.eclipse.gmf.runtime.emf.ui.services.parser.ParserHintAdapter;
39
import org.eclipse.gmf.runtime.notation.FontStyle;
40
import org.eclipse.gmf.runtime.notation.NotationPackage;
41
import org.eclipse.gmf.runtime.notation.View;
42
import org.eclipse.jface.resource.ImageDescriptor;
43
import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
44
import org.eclipse.jface.viewers.ICellEditorValidator;
45
import org.eclipse.swt.SWT;
46
import org.eclipse.swt.accessibility.AccessibleEvent;
47
import org.eclipse.swt.graphics.Color;
48
import org.eclipse.swt.graphics.FontData;
49
import org.eclipse.swt.graphics.Image;
50
import org.eclipse.uml2.diagram.clazz.edit.policies.UMLTextSelectionEditPolicy;
51
import org.eclipse.uml2.diagram.clazz.part.UMLDiagramEditorPlugin;
52
import org.eclipse.uml2.diagram.clazz.providers.UMLElementTypes;
53
54
/**
55
 * @generated
56
 */
57
public class PackageNameEditPart extends CompartmentEditPart implements ITextAwareEditPart {
58
59
	/**
60
	 * @generated
61
	 */
62
	public static final int VISUAL_ID = 5004;
63
64
	/**
65
	 * @generated
66
	 */
67
	private DirectEditManager manager;
68
69
	/**
70
	 * @generated
71
	 */
72
	private IParser parser;
73
74
	/**
75
	 * @generated
76
	 */
77
	private List parserElements;
78
79
	/**
80
	 * @generated
81
	 */
82
	private String defaultText;
83
84
	/**
85
	 * @generated
86
	 */
87
	public PackageNameEditPart(View view) {
88
		super(view);
89
	}
90
91
	/**
92
	 * @generated
93
	 */
94
	protected void createDefaultEditPolicies() {
95
		super.createDefaultEditPolicies();
96
		installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy());
97
		installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new NonResizableEditPolicy() {
98
99
			protected List createSelectionHandles() {
100
				List handles = new ArrayList();
101
				NonResizableHandleKit.addMoveHandle((GraphicalEditPart) getHost(), handles);
102
				return handles;
103
			}
104
105
			public Command getCommand(Request request) {
106
				return null;
107
			}
108
109
			public boolean understandsRequest(Request request) {
110
				return false;
111
			}
112
		});
113
114
	}
115
116
	/**
117
	 * @generated
118
	 */
119
	protected String getLabelTextHelper(IFigure figure) {
120
		if (figure instanceof WrapLabel) {
121
			return ((WrapLabel) figure).getText();
122
		} else {
123
			return ((Label) figure).getText();
124
		}
125
	}
126
127
	/**
128
	 * @generated
129
	 */
130
	protected void setLabelTextHelper(IFigure figure, String text) {
131
		if (figure instanceof WrapLabel) {
132
			((WrapLabel) figure).setText(text);
133
		} else {
134
			((Label) figure).setText(text);
135
		}
136
	}
137
138
	/**
139
	 * @generated
140
	 */
141
	protected Image getLabelIconHelper(IFigure figure) {
142
		if (figure instanceof WrapLabel) {
143
			return ((WrapLabel) figure).getIcon();
144
		} else {
145
			return ((Label) figure).getIcon();
146
		}
147
	}
148
149
	/**
150
	 * @generated
151
	 */
152
	protected void setLabelIconHelper(IFigure figure, Image icon) {
153
		if (figure instanceof WrapLabel) {
154
			((WrapLabel) figure).setIcon(icon);
155
		} else {
156
			((Label) figure).setIcon(icon);
157
		}
158
	}
159
160
	/**
161
	 * @generated
162
	 */
163
	public void setLabel(WrapLabel figure) {
164
		unregisterVisuals();
165
		setFigure(figure);
166
		defaultText = getLabelTextHelper(figure);
167
		registerVisuals();
168
		refreshVisuals();
169
	}
170
171
	/**
172
	 * @generated
173
	 */
174
	protected List getModelChildren() {
175
		return Collections.EMPTY_LIST;
176
	}
177
178
	/**
179
	 * @generated
180
	 */
181
	public IGraphicalEditPart getChildBySemanticHint(String semanticHint) {
182
		return null;
183
	}
184
185
	/**
186
	 * @generated
187
	 */
188
	protected EObject getParserElement() {
189
		EObject element = resolveSemanticElement();
190
		return element != null ? element : (View) getModel();
191
	}
192
193
	/**
194
	 * @generated
195
	 */
196
	protected Image getLabelIcon() {
197
		EObject parserElement = getParserElement();
198
		if (parserElement == null) {
199
			return null;
200
		}
201
		return UMLElementTypes.getImage(parserElement.eClass());
202
	}
203
204
	/**
205
	 * @generated
206
	 */
207
	protected String getLabelText() {
208
		String text = null;
209
		if (getParser() != null) {
210
			text = getParser().getPrintString(new EObjectAdapter(getParserElement()), getParserOptions().intValue());
211
		}
212
		if (text == null || text.length() == 0) {
213
			text = defaultText;
214
		}
215
		return text;
216
	}
217
218
	/**
219
	 * @generated
220
	 */
221
	public void setLabelText(String text) {
222
		setLabelTextHelper(getFigure(), text);
223
		Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
224
		if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) {
225
			((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback();
226
		}
227
	}
228
229
	/**
230
	 * @generated
231
	 */
232
	public String getEditText() {
233
		if (getParser() == null) {
234
			return ""; //$NON-NLS-1$
235
		}
236
		return getParser().getEditString(new EObjectAdapter(getParserElement()), getParserOptions().intValue());
237
	}
238
239
	/**
240
	 * @generated
241
	 */
242
	protected boolean isEditable() {
243
		return getEditText() != null;
244
	}
245
246
	/**
247
	 * @generated
248
	 */
249
	public ICellEditorValidator getEditTextValidator() {
250
		return new ICellEditorValidator() {
251
252
			public String isValid(final Object value) {
253
				if (value instanceof String) {
254
					final EObject element = getParserElement();
255
					final IParser parser = getParser();
256
					try {
257
						IParserEditStatus valid = (IParserEditStatus) getEditingDomain().runExclusive(new RunnableWithResult.Impl() {
258
259
							public void run() {
260
								setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value));
261
							}
262
						});
263
						return valid.getCode() == ParserEditStatus.EDITABLE ? null : valid.getMessage();
264
					} catch (InterruptedException ie) {
265
						ie.printStackTrace();
266
					}
267
				}
268
269
				// shouldn't get here
270
				return null;
271
			}
272
		};
273
	}
274
275
	/**
276
	 * @generated
277
	 */
278
	public IContentAssistProcessor getCompletionProcessor() {
279
		if (getParser() == null) {
280
			return null;
281
		}
282
		return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement()));
283
	}
284
285
	/**
286
	 * @generated
287
	 */
288
	public ParserOptions getParserOptions() {
289
		return ParserOptions.NONE;
290
	}
291
292
	/**
293
	 * @generated
294
	 */
295
	public IParser getParser() {
296
		if (parser == null) {
297
			String parserHint = ((View) getModel()).getType();
298
			ParserHintAdapter hintAdapter = new ParserHintAdapter(getParserElement(), parserHint) {
299
300
				public Object getAdapter(Class adapter) {
301
					if (IElementType.class.equals(adapter)) {
302
						return UMLElementTypes.Package_2002;
303
					}
304
					return super.getAdapter(adapter);
305
				}
306
			};
307
			parser = ParserService.getInstance().getParser(hintAdapter);
308
		}
309
		return parser;
310
	}
311
312
	/**
313
	 * @generated
314
	 */
315
	protected DirectEditManager getManager() {
316
		if (manager == null) {
317
			setManager(new TextDirectEditManager(this, TextDirectEditManager.getTextCellEditorClass(this), UMLEditPartFactory.getTextCellEditorLocator(this)));
318
		}
319
		return manager;
320
	}
321
322
	/**
323
	 * @generated
324
	 */
325
	protected void setManager(DirectEditManager manager) {
326
		this.manager = manager;
327
	}
328
329
	/**
330
	 * @generated
331
	 */
332
	protected void performDirectEdit() {
333
		getManager().show();
334
	}
335
336
	/**
337
	 * @generated
338
	 */
339
	protected void performDirectEdit(Point eventLocation) {
340
		if (getManager().getClass() == TextDirectEditManager.class) {
341
			((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint());
342
		}
343
	}
344
345
	/**
346
	 * @generated
347
	 */
348
	private void performDirectEdit(char initialCharacter) {
349
		if (getManager() instanceof TextDirectEditManager) {
350
			((TextDirectEditManager) getManager()).show(initialCharacter);
351
		} else {
352
			performDirectEdit();
353
		}
354
	}
355
356
	/**
357
	 * @generated
358
	 */
359
	protected void performDirectEditRequest(Request request) {
360
		final Request theRequest = request;
361
		try {
362
			getEditingDomain().runExclusive(new Runnable() {
363
364
				public void run() {
365
					if (isActive() && isEditable()) {
366
						if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) {
367
							Character initialChar = (Character) theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR);
368
							performDirectEdit(initialChar.charValue());
369
						} else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) {
370
							DirectEditRequest editRequest = (DirectEditRequest) theRequest;
371
							performDirectEdit(editRequest.getLocation());
372
						} else {
373
							performDirectEdit();
374
						}
375
					}
376
				}
377
			});
378
		} catch (InterruptedException e) {
379
			e.printStackTrace();
380
		}
381
	}
382
383
	/**
384
	 * @generated
385
	 */
386
	protected void refreshVisuals() {
387
		super.refreshVisuals();
388
		refreshLabel();
389
		refreshFont();
390
		refreshFontColor();
391
		refreshUnderline();
392
		refreshStrikeThrough();
393
	}
394
395
	/**
396
	 * @generated
397
	 */
398
	protected void refreshLabel() {
399
		setLabelTextHelper(getFigure(), getLabelText());
400
		setLabelIconHelper(getFigure(), getLabelIcon());
401
		Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
402
		if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) {
403
			((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback();
404
		}
405
	}
406
407
	/**
408
	 * @generated
409
	 */
410
	protected void refreshUnderline() {
411
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
412
		if (style != null && getFigure() instanceof WrapLabel) {
413
			((WrapLabel) getFigure()).setTextUnderline(style.isUnderline());
414
		}
415
	}
416
417
	/**
418
	 * @generated
419
	 */
420
	protected void refreshStrikeThrough() {
421
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
422
		if (style != null && getFigure() instanceof WrapLabel) {
423
			((WrapLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough());
424
		}
425
	}
426
427
	/**
428
	 * @generated
429
	 */
430
	protected void refreshFont() {
431
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
432
		if (style != null) {
433
			FontData fontData = new FontData(style.getFontName(), style.getFontHeight(), (style.isBold() ? SWT.BOLD : SWT.NORMAL) | (style.isItalic() ? SWT.ITALIC : SWT.NORMAL));
434
			setFont(fontData);
435
		}
436
	}
437
438
	/**
439
	 * @generated
440
	 */
441
	protected void setFontColor(Color color) {
442
		getFigure().setForegroundColor(color);
443
	}
444
445
	/**
446
	 * @generated
447
	 */
448
	protected void addSemanticListeners() {
449
		if (getParser() instanceof ISemanticParser) {
450
			EObject element = resolveSemanticElement();
451
			parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element);
452
			for (int i = 0; i < parserElements.size(); i++) {
453
				addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$
454
			}
455
		} else {
456
			super.addSemanticListeners();
457
		}
458
	}
459
460
	/**
461
	 * @generated
462
	 */
463
	protected void removeSemanticListeners() {
464
		if (parserElements != null) {
465
			for (int i = 0; i < parserElements.size(); i++) {
466
				removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$
467
			}
468
		} else {
469
			super.removeSemanticListeners();
470
		}
471
	}
472
473
	/**
474
	 * @generated
475
	 */
476
	protected AccessibleEditPart getAccessibleEditPart() {
477
		if (accessibleEP == null) {
478
			accessibleEP = new AccessibleGraphicalEditPart() {
479
480
				public void getName(AccessibleEvent e) {
481
					e.result = getLabelTextHelper(getFigure());
482
				}
483
			};
484
		}
485
		return accessibleEP;
486
	}
487
488
	/**
489
	 * @generated
490
	 */
491
	private View getFontStyleOwnerView() {
492
		return getPrimaryView();
493
	}
494
495
	/**
496
	 * @generated
497
	 */
498
	protected void addNotationalListeners() {
499
		super.addNotationalListeners();
500
		addListenerFilter("PrimaryView", this, getPrimaryView()); //$NON-NLS-1$
501
	}
502
503
	/**
504
	 * @generated
505
	 */
506
	protected void removeNotationalListeners() {
507
		super.removeNotationalListeners();
508
		removeListenerFilter("PrimaryView"); //$NON-NLS-1$
509
	}
510
511
	/**
512
	 * @generated
513
	 */
514
	protected void handleNotificationEvent(Notification event) {
515
		Object feature = event.getFeature();
516
		if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) {
517
			Integer c = (Integer) event.getNewValue();
518
			setFontColor(DiagramColorRegistry.getInstance().getColor(c));
519
		} else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) {
520
			refreshUnderline();
521
		} else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) {
522
			refreshStrikeThrough();
523
		} else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature)
524
				|| NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) {
525
			refreshFont();
526
		} else {
527
			if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) {
528
				refreshLabel();
529
			}
530
			if (getParser() instanceof ISemanticParser) {
531
				ISemanticParser modelParser = (ISemanticParser) getParser();
532
				if (modelParser.areSemanticElementsAffected(null, event)) {
533
					removeSemanticListeners();
534
					if (resolveSemanticElement() != null) {
535
						addSemanticListeners();
536
					}
537
					refreshLabel();
538
				}
539
			}
540
		}
541
		super.handleNotificationEvent(event);
542
	}
543
544
	/**
545
	 * @generated
546
	 */
547
	protected IFigure createFigure() {
548
		// Parent should assign one using setLabel method
549
		return null;
550
	}
551
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/policies/PackageOtherItemSemanticEditPolicy.java (+73 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.policies;
2
3
import org.eclipse.emf.ecore.EClass;
4
import org.eclipse.emf.ecore.EObject;
5
import org.eclipse.gef.commands.Command;
6
import org.eclipse.gmf.runtime.emf.type.core.commands.CreateElementCommand;
7
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest;
8
import org.eclipse.gmf.runtime.notation.View;
9
import org.eclipse.uml2.diagram.clazz.providers.UMLElementTypes;
10
import org.eclipse.uml2.uml.InstanceSpecification;
11
import org.eclipse.uml2.uml.UMLPackage;
12
13
/**
14
 * @generated
15
 */
16
public class PackageOtherItemSemanticEditPolicy extends UMLBaseItemSemanticEditPolicy {
17
18
	/**
19
	 * @generated
20
	 */
21
	protected Command getCreateCommand(CreateElementRequest req) {
22
		if (UMLElementTypes.InstanceSpecification_3013 == req.getElementType()) {
23
			if (req.getContainmentFeature() == null) {
24
				req.setContainmentFeature(UMLPackage.eINSTANCE.getPackage_PackagedElement());
25
			}
26
			return getMSLWrapper(new CreateInstanceSpecification_3013Command(req));
27
		}
28
		return super.getCreateCommand(req);
29
	}
30
31
	/**
32
	 * @generated
33
	 */
34
	private static class CreateInstanceSpecification_3013Command extends CreateElementCommand {
35
36
		/**
37
		 * @generated
38
		 */
39
		public CreateInstanceSpecification_3013Command(CreateElementRequest req) {
40
			super(req);
41
		}
42
43
		/**
44
		 * @generated
45
		 */
46
		protected EClass getEClassToEdit() {
47
			return UMLPackage.eINSTANCE.getPackage();
48
		};
49
50
		/**
51
		 * @generated
52
		 */
53
		protected EObject getElementToEdit() {
54
			EObject container = ((CreateElementRequest) getRequest()).getContainer();
55
			if (container instanceof View) {
56
				container = ((View) container).getElement();
57
			}
58
			return container;
59
		}
60
61
		/**
62
		 * @generated
63
		 */
64
		protected EObject doDefaultElementCreation() {
65
			InstanceSpecification newElement = (InstanceSpecification) super.doDefaultElementCreation();
66
			if (newElement != null) {
67
				UMLElementTypes.Initializers.InstanceSpecification_3013.init(newElement);
68
			}
69
			return newElement;
70
		}
71
	}
72
73
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/policies/AssociationClassOperationsItemSemanticEditPolicy.java (+73 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.policies;
2
3
import org.eclipse.emf.ecore.EClass;
4
import org.eclipse.emf.ecore.EObject;
5
import org.eclipse.gef.commands.Command;
6
import org.eclipse.gmf.runtime.emf.type.core.commands.CreateElementCommand;
7
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest;
8
import org.eclipse.gmf.runtime.notation.View;
9
import org.eclipse.uml2.diagram.clazz.providers.UMLElementTypes;
10
import org.eclipse.uml2.uml.Operation;
11
import org.eclipse.uml2.uml.UMLPackage;
12
13
/**
14
 * @generated
15
 */
16
public class AssociationClassOperationsItemSemanticEditPolicy extends UMLBaseItemSemanticEditPolicy {
17
18
	/**
19
	 * @generated
20
	 */
21
	protected Command getCreateCommand(CreateElementRequest req) {
22
		if (UMLElementTypes.Operation_3020 == req.getElementType()) {
23
			if (req.getContainmentFeature() == null) {
24
				req.setContainmentFeature(UMLPackage.eINSTANCE.getClass_OwnedOperation());
25
			}
26
			return getMSLWrapper(new CreateOperation_3020Command(req));
27
		}
28
		return super.getCreateCommand(req);
29
	}
30
31
	/**
32
	 * @generated
33
	 */
34
	private static class CreateOperation_3020Command extends CreateElementCommand {
35
36
		/**
37
		 * @generated
38
		 */
39
		public CreateOperation_3020Command(CreateElementRequest req) {
40
			super(req);
41
		}
42
43
		/**
44
		 * @generated
45
		 */
46
		protected EClass getEClassToEdit() {
47
			return UMLPackage.eINSTANCE.getAssociationClass();
48
		};
49
50
		/**
51
		 * @generated
52
		 */
53
		protected EObject getElementToEdit() {
54
			EObject container = ((CreateElementRequest) getRequest()).getContainer();
55
			if (container instanceof View) {
56
				container = ((View) container).getElement();
57
			}
58
			return container;
59
		}
60
61
		/**
62
		 * @generated
63
		 */
64
		protected EObject doDefaultElementCreation() {
65
			Operation newElement = (Operation) super.doDefaultElementCreation();
66
			if (newElement != null) {
67
				UMLElementTypes.Initializers.Operation_3020.init(newElement);
68
			}
69
			return newElement;
70
		}
71
	}
72
73
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/parts/DataTypeOperationsEditPart.java (+67 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.parts;
2
3
import org.eclipse.emf.common.notify.Notification;
4
import org.eclipse.gef.EditPolicy;
5
import org.eclipse.gmf.runtime.diagram.ui.editparts.ListCompartmentEditPart;
6
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.CreationEditPolicy;
7
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.DragDropEditPolicy;
8
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
9
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.ResizableCompartmentEditPolicy;
10
import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout;
11
import org.eclipse.gmf.runtime.notation.View;
12
import org.eclipse.uml2.diagram.clazz.edit.policies.DataTypeOperationsCanonicalEditPolicy;
13
import org.eclipse.uml2.diagram.clazz.edit.policies.DataTypeOperationsItemSemanticEditPolicy;
14
15
/**
16
 * @generated
17
 */
18
public class DataTypeOperationsEditPart extends ListCompartmentEditPart {
19
20
	/**
21
	 * @generated
22
	 */
23
	public static final int VISUAL_ID = 7018;
24
25
	/**
26
	 * @generated
27
	 */
28
	public DataTypeOperationsEditPart(View view) {
29
		super(view);
30
	}
31
32
	/**
33
	 * @generated
34
	 */
35
	protected boolean hasModelChildrenChanged(Notification evt) {
36
		return false;
37
	}
38
39
	/**
40
	 * @generated
41
	 */
42
	public String getCompartmentName() {
43
		return "operations";
44
	}
45
46
	/**
47
	 * @generated
48
	 */
49
	protected void createDefaultEditPolicies() {
50
		super.createDefaultEditPolicies();
51
		installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ResizableCompartmentEditPolicy());
52
		installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new DataTypeOperationsItemSemanticEditPolicy());
53
		installEditPolicy(EditPolicyRoles.CREATION_ROLE, new CreationEditPolicy());
54
		installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, new DragDropEditPolicy());
55
		installEditPolicy(EditPolicyRoles.CANONICAL_ROLE, new DataTypeOperationsCanonicalEditPolicy());
56
57
	}
58
59
	/**
60
	 * @generated
61
	 */
62
	protected void setRatio(Double ratio) {
63
		if (getFigure().getParent().getLayoutManager() instanceof ConstrainedToolbarLayout) {
64
			super.setRatio(ratio);
65
		}
66
	}
67
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/parts/ConstraintCompartmentEditPart.java (+65 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.parts;
2
3
import org.eclipse.emf.common.notify.Notification;
4
import org.eclipse.gef.EditPolicy;
5
import org.eclipse.gmf.runtime.diagram.ui.editparts.ListCompartmentEditPart;
6
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.CreationEditPolicy;
7
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.DragDropEditPolicy;
8
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
9
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.ResizableCompartmentEditPolicy;
10
import org.eclipse.gmf.runtime.notation.View;
11
import org.eclipse.uml2.diagram.clazz.edit.policies.ConstraintCompartmentCanonicalEditPolicy;
12
import org.eclipse.uml2.diagram.clazz.edit.policies.ConstraintCompartmentItemSemanticEditPolicy;
13
14
/**
15
 * @generated
16
 */
17
public class ConstraintCompartmentEditPart extends ListCompartmentEditPart {
18
19
	/**
20
	 * @generated
21
	 */
22
	public static final int VISUAL_ID = 7023;
23
24
	/**
25
	 * @generated
26
	 */
27
	public ConstraintCompartmentEditPart(View view) {
28
		super(view);
29
	}
30
31
	/**
32
	 * @generated
33
	 */
34
	protected boolean hasModelChildrenChanged(Notification evt) {
35
		return false;
36
	}
37
38
	/**
39
	 * @generated
40
	 */
41
	public String getCompartmentName() {
42
		return "Compartment";
43
	}
44
45
	/**
46
	 * @generated
47
	 */
48
	protected void createDefaultEditPolicies() {
49
		super.createDefaultEditPolicies();
50
		installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ResizableCompartmentEditPolicy());
51
		installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new ConstraintCompartmentItemSemanticEditPolicy());
52
		installEditPolicy(EditPolicyRoles.CREATION_ROLE, new CreationEditPolicy());
53
		installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, new DragDropEditPolicy());
54
		installEditPolicy(EditPolicyRoles.CANONICAL_ROLE, new ConstraintCompartmentCanonicalEditPolicy());
55
56
	}
57
58
	/**
59
	 * @generated
60
	 */
61
	protected void setRatio(Double ratio) {
62
		// nothing to do -- parent layout does not accept Double constraints as ratio
63
		// super.setRatio(ratio); 
64
	}
65
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/parts/PortEditPart.java (+289 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.parts;
2
3
import java.util.Iterator;
4
5
import org.eclipse.draw2d.IFigure;
6
import org.eclipse.draw2d.StackLayout;
7
import org.eclipse.gef.EditPart;
8
import org.eclipse.gef.EditPolicy;
9
import org.eclipse.gef.GraphicalEditPart;
10
import org.eclipse.gef.Request;
11
import org.eclipse.gef.commands.Command;
12
import org.eclipse.gef.editparts.LayerManager;
13
import org.eclipse.gef.editpolicies.LayoutEditPolicy;
14
import org.eclipse.gef.editpolicies.NonResizableEditPolicy;
15
import org.eclipse.gef.requests.CreateRequest;
16
import org.eclipse.gmf.runtime.diagram.ui.editparts.AbstractBorderItemEditPart;
17
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
18
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
19
import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout;
20
import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure;
21
import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure;
22
import org.eclipse.gmf.runtime.notation.View;
23
import org.eclipse.uml2.diagram.clazz.edit.policies.PortItemSemanticEditPolicy;
24
import org.eclipse.uml2.diagram.clazz.edit.policies.UMLExtNodeLabelHostLayoutEditPolicy;
25
import org.eclipse.uml2.diagram.clazz.part.UMLVisualIDRegistry;
26
27
/**
28
 * @generated
29
 */
30
public class PortEditPart extends AbstractBorderItemEditPart {
31
32
	/**
33
	 * @generated
34
	 */
35
	public static final int VISUAL_ID = 3025;
36
37
	/**
38
	 * @generated
39
	 */
40
	protected IFigure contentPane;
41
42
	/**
43
	 * @generated
44
	 */
45
	protected IFigure primaryShape;
46
47
	/**
48
	 * @generated
49
	 */
50
	public PortEditPart(View view) {
51
		super(view);
52
	}
53
54
	/**
55
	 * @generated
56
	 */
57
	protected void createDefaultEditPolicies() {
58
		super.createDefaultEditPolicies();
59
		installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, getPrimaryDragEditPolicy());
60
		installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new PortItemSemanticEditPolicy());
61
		installEditPolicy(EditPolicy.LAYOUT_ROLE, createLayoutEditPolicy());
62
63
	}
64
65
	/**
66
	 * @generated
67
	 */
68
	protected LayoutEditPolicy createLayoutEditPolicy() {
69
		LayoutEditPolicy lep = new LayoutEditPolicy() {
70
71
			protected void decorateChild(EditPart child) {
72
				if (isExternalLabel(child)) {
73
					return;
74
				}
75
				super.decorateChild(child);
76
			}
77
78
			protected EditPolicy createChildEditPolicy(EditPart child) {
79
				EditPolicy result = child.getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
80
				if (result == null) {
81
					result = new NonResizableEditPolicy();
82
				}
83
				return result;
84
			}
85
86
			protected Command getMoveChildrenCommand(Request request) {
87
				return null;
88
			}
89
90
			protected Command getCreateCommand(CreateRequest request) {
91
				return null;
92
			}
93
		};
94
		UMLExtNodeLabelHostLayoutEditPolicy xlep = new UMLExtNodeLabelHostLayoutEditPolicy() {
95
96
			protected boolean isExternalLabel(EditPart editPart) {
97
				return PortEditPart.this.isExternalLabel(editPart);
98
			}
99
		};
100
		xlep.setRealLayoutEditPolicy(lep);
101
		return xlep;
102
	}
103
104
	/**
105
	 * @generated
106
	 */
107
	protected IFigure createNodeShape() {
108
		PortFigure figure = new PortFigure();
109
		return primaryShape = figure;
110
	}
111
112
	/**
113
	 * @generated
114
	 */
115
	public PortFigure getPrimaryShape() {
116
		return (PortFigure) primaryShape;
117
	}
118
119
	/**
120
	 * @generated 
121
	 */
122
	protected IFigure getContentPaneFor(IGraphicalEditPart editPart) {
123
		if (isExternalLabel(editPart)) {
124
			return getExternalLabelsContainer();
125
		}
126
127
		return super.getContentPaneFor(editPart);
128
	}
129
130
	/**
131
	 * @generated
132
	 */
133
	protected NodeFigure createNodePlate() {
134
		DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(getMapMode().DPtoLP(15), getMapMode().DPtoLP(15));
135
		//FIXME: workaround for #154536
136
		result.getBounds().setSize(result.getPreferredSize());
137
		return result;
138
	}
139
140
	/**
141
	 * Creates figure for this edit part.
142
	 * 
143
	 * Body of this method does not depend on settings in generation model
144
	 * so you may safely remove <i>generated</i> tag and modify it.
145
	 * 
146
	 * @generated
147
	 */
148
	protected NodeFigure createNodeFigure() {
149
		NodeFigure figure = createNodePlate();
150
		figure.setLayoutManager(new StackLayout());
151
		IFigure shape = createNodeShape();
152
		figure.add(shape);
153
		contentPane = setupContentPane(shape);
154
		return figure;
155
	}
156
157
	/**
158
	 * Default implementation treats passed figure as content pane.
159
	 * Respects layout one may have set for generated figure.
160
	 * @param nodeShape instance of generated figure class
161
	 * @generated
162
	 */
163
	protected IFigure setupContentPane(IFigure nodeShape) {
164
		if (nodeShape.getLayoutManager() == null) {
165
			ConstrainedToolbarLayout layout = new ConstrainedToolbarLayout();
166
			layout.setSpacing(getMapMode().DPtoLP(5));
167
			nodeShape.setLayoutManager(layout);
168
		}
169
		return nodeShape; // use nodeShape itself as contentPane
170
	}
171
172
	/**
173
	 * @generated
174
	 */
175
	public IFigure getContentPane() {
176
		if (contentPane != null) {
177
			return contentPane;
178
		}
179
		return super.getContentPane();
180
	}
181
182
	/**
183
	 * @generated
184
	 */
185
	public EditPart getPrimaryChildEditPart() {
186
		return getChildBySemanticHint(UMLVisualIDRegistry.getType(PortNameEditPart.VISUAL_ID));
187
	}
188
189
	/**
190
	 * @generated
191
	 */
192
	protected boolean isExternalLabel(EditPart childEditPart) {
193
		if (childEditPart instanceof PortNameEditPart) {
194
			return true;
195
		}
196
		return false;
197
	}
198
199
	/**
200
	 * @generated
201
	 */
202
	protected IFigure getExternalLabelsContainer() {
203
		LayerManager root = (LayerManager) getRoot();
204
		return root.getLayer(UMLEditPartFactory.EXTERNAL_NODE_LABELS_LAYER);
205
	}
206
207
	/**
208
	 * @generated
209
	 */
210
	protected void addChildVisual(EditPart childEditPart, int index) {
211
		if (isExternalLabel(childEditPart)) {
212
			IFigure labelFigure = ((GraphicalEditPart) childEditPart).getFigure();
213
			getExternalLabelsContainer().add(labelFigure);
214
			return;
215
		}
216
		super.addChildVisual(childEditPart, -1);
217
	}
218
219
	/**
220
	 * @generated
221
	 */
222
	protected void removeChildVisual(EditPart childEditPart) {
223
		if (isExternalLabel(childEditPart)) {
224
			IFigure labelFigure = ((GraphicalEditPart) childEditPart).getFigure();
225
			getExternalLabelsContainer().remove(labelFigure);
226
			return;
227
		}
228
		super.removeChildVisual(childEditPart);
229
	}
230
231
	/**
232
	 * @generated
233
	 */
234
	public void removeNotify() {
235
		for (Iterator it = getChildren().iterator(); it.hasNext();) {
236
			EditPart childEditPart = (EditPart) it.next();
237
			if (isExternalLabel(childEditPart)) {
238
				IFigure labelFigure = ((GraphicalEditPart) childEditPart).getFigure();
239
				getExternalLabelsContainer().remove(labelFigure);
240
			}
241
		}
242
		super.removeNotify();
243
	}
244
245
	/**
246
	 * @generated
247
	 */
248
	public class PortFigure extends org.eclipse.draw2d.RectangleFigure {
249
250
		/**
251
		 * @generated
252
		 */
253
		public PortFigure() {
254
255
			this.setForegroundColor(org.eclipse.draw2d.ColorConstants.gray);
256
			this.setPreferredSize(getMapMode().DPtoLP(15), getMapMode().DPtoLP(15));
257
			this.setMaximumSize(new org.eclipse.draw2d.geometry.Dimension(getMapMode().DPtoLP(15), getMapMode().DPtoLP(15)));
258
			this.setMinimumSize(new org.eclipse.draw2d.geometry.Dimension(getMapMode().DPtoLP(15), getMapMode().DPtoLP(15)));
259
			createContents();
260
		}
261
262
		/**
263
		 * @generated
264
		 */
265
		private void createContents() {
266
		}
267
268
		/**
269
		 * @generated
270
		 */
271
		private boolean myUseLocalCoordinates = false;
272
273
		/**
274
		 * @generated
275
		 */
276
		protected boolean useLocalCoordinates() {
277
			return myUseLocalCoordinates;
278
		}
279
280
		/**
281
		 * @generated
282
		 */
283
		protected void setUseLocalCoordinates(boolean useLocalCoordinates) {
284
			myUseLocalCoordinates = useLocalCoordinates;
285
		}
286
287
	}
288
289
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/policies/EnumerationLiteralItemSemanticEditPolicy.java (+255 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.policies;
2
3
import org.eclipse.emf.ecore.EAnnotation;
4
import org.eclipse.emf.ecore.EClass;
5
import org.eclipse.emf.ecore.EObject;
6
import org.eclipse.gef.commands.Command;
7
import org.eclipse.gef.commands.UnexecutableCommand;
8
import org.eclipse.gmf.runtime.emf.type.core.commands.CreateRelationshipCommand;
9
import org.eclipse.gmf.runtime.emf.type.core.commands.DestroyElementCommand;
10
import org.eclipse.gmf.runtime.emf.type.core.commands.SetValueCommand;
11
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest;
12
import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest;
13
import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest;
14
import org.eclipse.gmf.runtime.notation.View;
15
import org.eclipse.uml2.diagram.clazz.providers.UMLElementTypes;
16
import org.eclipse.uml2.uml.Constraint;
17
import org.eclipse.uml2.uml.Dependency;
18
import org.eclipse.uml2.uml.NamedElement;
19
import org.eclipse.uml2.uml.UMLPackage;
20
import org.eclipse.uml2.uml.Usage;
21
22
/**
23
 * @generated
24
 */
25
public class EnumerationLiteralItemSemanticEditPolicy extends UMLBaseItemSemanticEditPolicy {
26
27
	/**
28
	 * @generated
29
	 */
30
	protected Command getDestroyElementCommand(DestroyElementRequest req) {
31
		return getMSLWrapper(new DestroyElementCommand(req) {
32
33
			protected EObject getElementToDestroy() {
34
				View view = (View) getHost().getModel();
35
				EAnnotation annotation = view.getEAnnotation("Shortcut"); //$NON-NLS-1$
36
				if (annotation != null) {
37
					return view;
38
				}
39
				return super.getElementToDestroy();
40
			}
41
42
		});
43
	}
44
45
	/**
46
	 * @generated
47
	 */
48
	protected Command getCreateRelationshipCommand(CreateRelationshipRequest req) {
49
		if (UMLElementTypes.Dependency_4002 == req.getElementType()) {
50
			return req.getTarget() == null ? getCreateStartOutgoingDependency4002Command(req) : getCreateCompleteIncomingDependency4002Command(req);
51
		}
52
		if (UMLElementTypes.ConstraintConstrainedElement_4004 == req.getElementType()) {
53
			return req.getTarget() == null ? null : getCreateCompleteIncomingConstraint_ConstrainedElement4004Command(req);
54
		}
55
		if (UMLElementTypes.DependencySupplier_4006 == req.getElementType()) {
56
			return req.getTarget() == null ? null : getCreateCompleteIncomingDependency_Supplier4006Command(req);
57
		}
58
		if (UMLElementTypes.DependencyClient_4007 == req.getElementType()) {
59
			return req.getTarget() == null ? null : getCreateCompleteIncomingDependency_Client4007Command(req);
60
		}
61
		if (UMLElementTypes.Usage_4009 == req.getElementType()) {
62
			return req.getTarget() == null ? getCreateStartOutgoingUsage4009Command(req) : getCreateCompleteIncomingUsage4009Command(req);
63
		}
64
		return super.getCreateRelationshipCommand(req);
65
	}
66
67
	/**
68
	 * @generated
69
	 */
70
	protected Command getCreateStartOutgoingDependency4002Command(CreateRelationshipRequest req) {
71
		return new Command() {
72
		};
73
	}
74
75
	/**
76
	 * @generated
77
	 */
78
	protected Command getCreateCompleteIncomingDependency4002Command(CreateRelationshipRequest req) {
79
		if (!(req.getSource() instanceof NamedElement)) {
80
			return UnexecutableCommand.INSTANCE;
81
		}
82
		final org.eclipse.uml2.uml.Package element = (org.eclipse.uml2.uml.Package) getRelationshipContainer(req.getSource(), UMLPackage.eINSTANCE.getPackage(), req.getElementType());
83
		if (element == null) {
84
			return UnexecutableCommand.INSTANCE;
85
		}
86
		if (req.getContainmentFeature() == null) {
87
			req.setContainmentFeature(UMLPackage.eINSTANCE.getPackage_PackagedElement());
88
		}
89
		return getMSLWrapper(new CreateIncomingDependency4002Command(req) {
90
91
			protected EObject getElementToEdit() {
92
				return element;
93
			}
94
		});
95
	}
96
97
	/**
98
	 * @generated
99
	 */
100
	private static class CreateIncomingDependency4002Command extends CreateRelationshipCommand {
101
102
		/**
103
		 * @generated
104
		 */
105
		public CreateIncomingDependency4002Command(CreateRelationshipRequest req) {
106
			super(req);
107
		}
108
109
		/**
110
		 * @generated
111
		 */
112
		protected EClass getEClassToEdit() {
113
			return UMLPackage.eINSTANCE.getPackage();
114
		};
115
116
		/**
117
		 * @generated
118
		 */
119
		protected void setElementToEdit(EObject element) {
120
			throw new UnsupportedOperationException();
121
		}
122
123
		/**
124
		 * @generated
125
		 */
126
		protected EObject doDefaultElementCreation() {
127
			Dependency newElement = (Dependency) super.doDefaultElementCreation();
128
			if (newElement != null) {
129
				newElement.getSuppliers().add((NamedElement) getTarget());
130
				newElement.getClients().add((NamedElement) getSource());
131
			}
132
			return newElement;
133
		}
134
	}
135
136
	/**
137
	 * @generated
138
	 */
139
	protected Command getCreateCompleteIncomingConstraint_ConstrainedElement4004Command(CreateRelationshipRequest req) {
140
		if (!(req.getSource() instanceof Constraint)) {
141
			return UnexecutableCommand.INSTANCE;
142
		}
143
		Constraint element = (Constraint) req.getSource();
144
		if (element.getConstrainedElements().contains(req.getTarget())) {
145
			return UnexecutableCommand.INSTANCE;
146
		}
147
		SetRequest setReq = new SetRequest(req.getSource(), UMLPackage.eINSTANCE.getConstraint_ConstrainedElement(), req.getTarget());
148
		return getMSLWrapper(new SetValueCommand(setReq));
149
	}
150
151
	/**
152
	 * @generated
153
	 */
154
	protected Command getCreateCompleteIncomingDependency_Supplier4006Command(CreateRelationshipRequest req) {
155
		if (!(req.getSource() instanceof Dependency)) {
156
			return UnexecutableCommand.INSTANCE;
157
		}
158
		Dependency element = (Dependency) req.getSource();
159
		if (element.getSuppliers().contains(req.getTarget())) {
160
			return UnexecutableCommand.INSTANCE;
161
		}
162
		SetRequest setReq = new SetRequest(req.getSource(), UMLPackage.eINSTANCE.getDependency_Supplier(), req.getTarget());
163
		return getMSLWrapper(new SetValueCommand(setReq));
164
	}
165
166
	/**
167
	 * @generated
168
	 */
169
	protected Command getCreateCompleteIncomingDependency_Client4007Command(CreateRelationshipRequest req) {
170
		if (!(req.getSource() instanceof Dependency)) {
171
			return UnexecutableCommand.INSTANCE;
172
		}
173
		Dependency element = (Dependency) req.getSource();
174
		if (element.getClients().contains(req.getTarget())) {
175
			return UnexecutableCommand.INSTANCE;
176
		}
177
		SetRequest setReq = new SetRequest(req.getSource(), UMLPackage.eINSTANCE.getDependency_Client(), req.getTarget());
178
		return getMSLWrapper(new SetValueCommand(setReq));
179
	}
180
181
	/**
182
	 * @generated
183
	 */
184
	protected Command getCreateStartOutgoingUsage4009Command(CreateRelationshipRequest req) {
185
		if (!UMLBaseItemSemanticEditPolicy.LinkConstraints.Usage_4009.canCreateLink(req, false)) {
186
			return UnexecutableCommand.INSTANCE;
187
		}
188
		return new Command() {
189
		};
190
	}
191
192
	/**
193
	 * @generated
194
	 */
195
	protected Command getCreateCompleteIncomingUsage4009Command(CreateRelationshipRequest req) {
196
		if (!(req.getSource() instanceof NamedElement)) {
197
			return UnexecutableCommand.INSTANCE;
198
		}
199
		final org.eclipse.uml2.uml.Package element = (org.eclipse.uml2.uml.Package) getRelationshipContainer(req.getSource(), UMLPackage.eINSTANCE.getPackage(), req.getElementType());
200
		if (element == null) {
201
			return UnexecutableCommand.INSTANCE;
202
		}
203
		if (!UMLBaseItemSemanticEditPolicy.LinkConstraints.Usage_4009.canCreateLink(req, false)) {
204
			return UnexecutableCommand.INSTANCE;
205
		}
206
		if (req.getContainmentFeature() == null) {
207
			req.setContainmentFeature(UMLPackage.eINSTANCE.getPackage_PackagedElement());
208
		}
209
		return getMSLWrapper(new CreateIncomingUsage4009Command(req) {
210
211
			protected EObject getElementToEdit() {
212
				return element;
213
			}
214
		});
215
	}
216
217
	/**
218
	 * @generated
219
	 */
220
	private static class CreateIncomingUsage4009Command extends CreateRelationshipCommand {
221
222
		/**
223
		 * @generated
224
		 */
225
		public CreateIncomingUsage4009Command(CreateRelationshipRequest req) {
226
			super(req);
227
		}
228
229
		/**
230
		 * @generated
231
		 */
232
		protected EClass getEClassToEdit() {
233
			return UMLPackage.eINSTANCE.getPackage();
234
		};
235
236
		/**
237
		 * @generated
238
		 */
239
		protected void setElementToEdit(EObject element) {
240
			throw new UnsupportedOperationException();
241
		}
242
243
		/**
244
		 * @generated
245
		 */
246
		protected EObject doDefaultElementCreation() {
247
			Usage newElement = (Usage) super.doDefaultElementCreation();
248
			if (newElement != null) {
249
				newElement.getSuppliers().add((NamedElement) getTarget());
250
				newElement.getClients().add((NamedElement) getSource());
251
			}
252
			return newElement;
253
		}
254
	}
255
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/parts/Property2EditPart.java (+553 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.parts;
2
3
import java.util.Collections;
4
import java.util.List;
5
6
import org.eclipse.draw2d.IFigure;
7
import org.eclipse.draw2d.Label;
8
import org.eclipse.draw2d.geometry.Point;
9
import org.eclipse.emf.common.notify.Notification;
10
import org.eclipse.emf.ecore.EObject;
11
import org.eclipse.emf.transaction.RunnableWithResult;
12
import org.eclipse.gef.AccessibleEditPart;
13
import org.eclipse.gef.DragTracker;
14
import org.eclipse.gef.EditPolicy;
15
import org.eclipse.gef.Request;
16
import org.eclipse.gef.requests.DirectEditRequest;
17
import org.eclipse.gef.requests.SelectionRequest;
18
import org.eclipse.gef.tools.DirectEditManager;
19
import org.eclipse.gmf.runtime.common.ui.services.parser.IParser;
20
import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus;
21
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserEditStatus;
22
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions;
23
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserService;
24
import org.eclipse.gmf.runtime.diagram.ui.editparts.CompartmentEditPart;
25
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
26
import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart;
27
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
28
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy;
29
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.ListItemComponentEditPolicy;
30
import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry;
31
import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants;
32
import org.eclipse.gmf.runtime.diagram.ui.tools.DragEditPartsTrackerEx;
33
import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager;
34
import org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel;
35
import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
36
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
37
import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser;
38
import org.eclipse.gmf.runtime.emf.ui.services.parser.ParserHintAdapter;
39
import org.eclipse.gmf.runtime.notation.FontStyle;
40
import org.eclipse.gmf.runtime.notation.NotationPackage;
41
import org.eclipse.gmf.runtime.notation.View;
42
import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
43
import org.eclipse.jface.viewers.ICellEditorValidator;
44
import org.eclipse.swt.SWT;
45
import org.eclipse.swt.accessibility.AccessibleEvent;
46
import org.eclipse.swt.graphics.Color;
47
import org.eclipse.swt.graphics.FontData;
48
import org.eclipse.swt.graphics.Image;
49
import org.eclipse.uml2.diagram.clazz.edit.policies.Property2ItemSemanticEditPolicy;
50
import org.eclipse.uml2.diagram.clazz.edit.policies.UMLTextNonResizableEditPolicy;
51
import org.eclipse.uml2.diagram.clazz.edit.policies.UMLTextSelectionEditPolicy;
52
import org.eclipse.uml2.diagram.clazz.providers.UMLElementTypes;
53
54
/**
55
 * @generated
56
 */
57
public class Property2EditPart extends CompartmentEditPart implements ITextAwareEditPart {
58
59
	/**
60
	 * @generated
61
	 */
62
	public static final int VISUAL_ID = 3019;
63
64
	/**
65
	 * @generated
66
	 */
67
	private DirectEditManager manager;
68
69
	/**
70
	 * @generated
71
	 */
72
	private IParser parser;
73
74
	/**
75
	 * @generated
76
	 */
77
	private List parserElements;
78
79
	/**
80
	 * @generated
81
	 */
82
	private String defaultText;
83
84
	/**
85
	 * @generated
86
	 */
87
	public Property2EditPart(View view) {
88
		super(view);
89
	}
90
91
	/**
92
	 * @generated
93
	 */
94
	public DragTracker getDragTracker(Request request) {
95
		if (request instanceof SelectionRequest && ((SelectionRequest) request).getLastButtonPressed() == 3) {
96
			return null;
97
		}
98
		return new DragEditPartsTrackerEx(this);
99
	}
100
101
	/**
102
	 * @generated
103
	 */
104
	protected void createDefaultEditPolicies() {
105
		super.createDefaultEditPolicies();
106
		installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new Property2ItemSemanticEditPolicy());
107
		installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new UMLTextNonResizableEditPolicy());
108
		installEditPolicy(EditPolicy.COMPONENT_ROLE, new ListItemComponentEditPolicy());
109
		installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy());
110
111
	}
112
113
	/**
114
	 * @generated
115
	 */
116
	protected String getLabelTextHelper(IFigure figure) {
117
		if (figure instanceof WrapLabel) {
118
			return ((WrapLabel) figure).getText();
119
		} else {
120
			return ((Label) figure).getText();
121
		}
122
	}
123
124
	/**
125
	 * @generated
126
	 */
127
	protected void setLabelTextHelper(IFigure figure, String text) {
128
		if (figure instanceof WrapLabel) {
129
			((WrapLabel) figure).setText(text);
130
		} else {
131
			((Label) figure).setText(text);
132
		}
133
	}
134
135
	/**
136
	 * @generated
137
	 */
138
	protected Image getLabelIconHelper(IFigure figure) {
139
		if (figure instanceof WrapLabel) {
140
			return ((WrapLabel) figure).getIcon();
141
		} else {
142
			return ((Label) figure).getIcon();
143
		}
144
	}
145
146
	/**
147
	 * @generated
148
	 */
149
	protected void setLabelIconHelper(IFigure figure, Image icon) {
150
		if (figure instanceof WrapLabel) {
151
			((WrapLabel) figure).setIcon(icon);
152
		} else {
153
			((Label) figure).setIcon(icon);
154
		}
155
	}
156
157
	/**
158
	 * @generated
159
	 */
160
	public void setLabel(IFigure figure) {
161
		unregisterVisuals();
162
		setFigure(figure);
163
		defaultText = getLabelTextHelper(figure);
164
		registerVisuals();
165
		refreshVisuals();
166
	}
167
168
	/**
169
	 * @generated
170
	 */
171
	protected List getModelChildren() {
172
		return Collections.EMPTY_LIST;
173
	}
174
175
	/**
176
	 * @generated
177
	 */
178
	public IGraphicalEditPart getChildBySemanticHint(String semanticHint) {
179
		return null;
180
	}
181
182
	/**
183
	 * @generated
184
	 */
185
	protected EObject getParserElement() {
186
		EObject element = resolveSemanticElement();
187
		return element != null ? element : (View) getModel();
188
	}
189
190
	/**
191
	 * @generated
192
	 */
193
	protected Image getLabelIcon() {
194
		return null;
195
	}
196
197
	/**
198
	 * @generated
199
	 */
200
	protected String getLabelText() {
201
		String text = null;
202
		if (getParser() != null) {
203
			text = getParser().getPrintString(new EObjectAdapter(getParserElement()), getParserOptions().intValue());
204
		}
205
		if (text == null || text.length() == 0) {
206
			text = defaultText;
207
		}
208
		return text;
209
	}
210
211
	/**
212
	 * @generated
213
	 */
214
	public void setLabelText(String text) {
215
		setLabelTextHelper(getFigure(), text);
216
		Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
217
		if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) {
218
			((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback();
219
		}
220
	}
221
222
	/**
223
	 * @generated
224
	 */
225
	public String getEditText() {
226
		if (getParser() == null) {
227
			return ""; //$NON-NLS-1$
228
		}
229
		return getParser().getEditString(new EObjectAdapter(getParserElement()), getParserOptions().intValue());
230
	}
231
232
	/**
233
	 * @generated
234
	 */
235
	protected boolean isEditable() {
236
		return getEditText() != null;
237
	}
238
239
	/**
240
	 * @generated
241
	 */
242
	public ICellEditorValidator getEditTextValidator() {
243
		return new ICellEditorValidator() {
244
245
			public String isValid(final Object value) {
246
				if (value instanceof String) {
247
					final EObject element = getParserElement();
248
					final IParser parser = getParser();
249
					try {
250
						IParserEditStatus valid = (IParserEditStatus) getEditingDomain().runExclusive(new RunnableWithResult.Impl() {
251
252
							public void run() {
253
								setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value));
254
							}
255
						});
256
						return valid.getCode() == ParserEditStatus.EDITABLE ? null : valid.getMessage();
257
					} catch (InterruptedException ie) {
258
						ie.printStackTrace();
259
					}
260
				}
261
262
				// shouldn't get here
263
				return null;
264
			}
265
		};
266
	}
267
268
	/**
269
	 * @generated
270
	 */
271
	public IContentAssistProcessor getCompletionProcessor() {
272
		if (getParser() == null) {
273
			return null;
274
		}
275
		return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement()));
276
	}
277
278
	/**
279
	 * @generated
280
	 */
281
	public ParserOptions getParserOptions() {
282
		return ParserOptions.NONE;
283
	}
284
285
	/**
286
	 * @generated
287
	 */
288
	public IParser getParser() {
289
		if (parser == null) {
290
			String parserHint = ((View) getModel()).getType();
291
			ParserHintAdapter hintAdapter = new ParserHintAdapter(getParserElement(), parserHint) {
292
293
				public Object getAdapter(Class adapter) {
294
					if (IElementType.class.equals(adapter)) {
295
						return UMLElementTypes.Property_3019;
296
					}
297
					return super.getAdapter(adapter);
298
				}
299
			};
300
			parser = ParserService.getInstance().getParser(hintAdapter);
301
		}
302
		return parser;
303
	}
304
305
	/**
306
	 * @generated
307
	 */
308
	protected DirectEditManager getManager() {
309
		if (manager == null) {
310
			setManager(new TextDirectEditManager(this, TextDirectEditManager.getTextCellEditorClass(this), UMLEditPartFactory.getTextCellEditorLocator(this)));
311
		}
312
		return manager;
313
	}
314
315
	/**
316
	 * @generated
317
	 */
318
	protected void setManager(DirectEditManager manager) {
319
		this.manager = manager;
320
	}
321
322
	/**
323
	 * @generated
324
	 */
325
	protected void performDirectEdit() {
326
		getManager().show();
327
	}
328
329
	/**
330
	 * @generated
331
	 */
332
	protected void performDirectEdit(Point eventLocation) {
333
		if (getManager().getClass() == TextDirectEditManager.class) {
334
			((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint());
335
		}
336
	}
337
338
	/**
339
	 * @generated
340
	 */
341
	private void performDirectEdit(char initialCharacter) {
342
		if (getManager() instanceof TextDirectEditManager) {
343
			((TextDirectEditManager) getManager()).show(initialCharacter);
344
		} else {
345
			performDirectEdit();
346
		}
347
	}
348
349
	/**
350
	 * @generated
351
	 */
352
	protected void performDirectEditRequest(Request request) {
353
		final Request theRequest = request;
354
		try {
355
			getEditingDomain().runExclusive(new Runnable() {
356
357
				public void run() {
358
					if (isActive() && isEditable()) {
359
						if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) {
360
							Character initialChar = (Character) theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR);
361
							performDirectEdit(initialChar.charValue());
362
						} else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) {
363
							DirectEditRequest editRequest = (DirectEditRequest) theRequest;
364
							performDirectEdit(editRequest.getLocation());
365
						} else {
366
							performDirectEdit();
367
						}
368
					}
369
				}
370
			});
371
		} catch (InterruptedException e) {
372
			e.printStackTrace();
373
		}
374
	}
375
376
	/**
377
	 * @generated
378
	 */
379
	protected void refreshVisuals() {
380
		super.refreshVisuals();
381
		refreshLabel();
382
		refreshFont();
383
		refreshFontColor();
384
		refreshUnderline();
385
		refreshStrikeThrough();
386
	}
387
388
	/**
389
	 * @generated
390
	 */
391
	protected void refreshLabel() {
392
		setLabelTextHelper(getFigure(), getLabelText());
393
		setLabelIconHelper(getFigure(), getLabelIcon());
394
		Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
395
		if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) {
396
			((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback();
397
		}
398
	}
399
400
	/**
401
	 * @generated
402
	 */
403
	protected void refreshUnderline() {
404
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
405
		if (style != null && getFigure() instanceof WrapLabel) {
406
			((WrapLabel) getFigure()).setTextUnderline(style.isUnderline());
407
		}
408
	}
409
410
	/**
411
	 * @generated
412
	 */
413
	protected void refreshStrikeThrough() {
414
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
415
		if (style != null && getFigure() instanceof WrapLabel) {
416
			((WrapLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough());
417
		}
418
	}
419
420
	/**
421
	 * @generated
422
	 */
423
	protected void refreshFont() {
424
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
425
		if (style != null) {
426
			FontData fontData = new FontData(style.getFontName(), style.getFontHeight(), (style.isBold() ? SWT.BOLD : SWT.NORMAL) | (style.isItalic() ? SWT.ITALIC : SWT.NORMAL));
427
			setFont(fontData);
428
		}
429
	}
430
431
	/**
432
	 * @generated
433
	 */
434
	protected void setFontColor(Color color) {
435
		getFigure().setForegroundColor(color);
436
	}
437
438
	/**
439
	 * @generated
440
	 */
441
	protected void addSemanticListeners() {
442
		if (getParser() instanceof ISemanticParser) {
443
			EObject element = resolveSemanticElement();
444
			parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element);
445
			for (int i = 0; i < parserElements.size(); i++) {
446
				addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$
447
			}
448
		} else {
449
			super.addSemanticListeners();
450
		}
451
	}
452
453
	/**
454
	 * @generated
455
	 */
456
	protected void removeSemanticListeners() {
457
		if (parserElements != null) {
458
			for (int i = 0; i < parserElements.size(); i++) {
459
				removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$
460
			}
461
		} else {
462
			super.removeSemanticListeners();
463
		}
464
	}
465
466
	/**
467
	 * @generated
468
	 */
469
	protected AccessibleEditPart getAccessibleEditPart() {
470
		if (accessibleEP == null) {
471
			accessibleEP = new AccessibleGraphicalEditPart() {
472
473
				public void getName(AccessibleEvent e) {
474
					e.result = getLabelTextHelper(getFigure());
475
				}
476
			};
477
		}
478
		return accessibleEP;
479
	}
480
481
	/**
482
	 * @generated
483
	 */
484
	private View getFontStyleOwnerView() {
485
		return getPrimaryView();
486
	}
487
488
	/**
489
	 * @generated
490
	 */
491
	protected void addNotationalListeners() {
492
		super.addNotationalListeners();
493
		addListenerFilter("PrimaryView", this, getPrimaryView()); //$NON-NLS-1$
494
	}
495
496
	/**
497
	 * @generated
498
	 */
499
	protected void removeNotationalListeners() {
500
		super.removeNotationalListeners();
501
		removeListenerFilter("PrimaryView"); //$NON-NLS-1$
502
	}
503
504
	/**
505
	 * @generated
506
	 */
507
	protected void handleNotificationEvent(Notification event) {
508
		Object feature = event.getFeature();
509
		if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) {
510
			Integer c = (Integer) event.getNewValue();
511
			setFontColor(DiagramColorRegistry.getInstance().getColor(c));
512
		} else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) {
513
			refreshUnderline();
514
		} else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) {
515
			refreshStrikeThrough();
516
		} else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature)
517
				|| NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) {
518
			refreshFont();
519
		} else {
520
			if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) {
521
				refreshLabel();
522
			}
523
			if (getParser() instanceof ISemanticParser) {
524
				ISemanticParser modelParser = (ISemanticParser) getParser();
525
				if (modelParser.areSemanticElementsAffected(null, event)) {
526
					removeSemanticListeners();
527
					if (resolveSemanticElement() != null) {
528
						addSemanticListeners();
529
					}
530
					refreshLabel();
531
				}
532
			}
533
		}
534
		super.handleNotificationEvent(event);
535
	}
536
537
	/**
538
	 * @generated
539
	 */
540
	protected IFigure createFigure() {
541
		IFigure label = createFigurePrim();
542
		defaultText = getLabelTextHelper(label);
543
		return label;
544
	}
545
546
	/**
547
	 * @generated
548
	 */
549
	protected IFigure createFigurePrim() {
550
		return new WrapLabel();
551
	}
552
553
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/policies/PackageClassifiersCanonicalEditPolicy.java (+74 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.policies;
2
3
import java.util.Iterator;
4
import java.util.LinkedList;
5
import java.util.List;
6
7
import org.eclipse.emf.ecore.EObject;
8
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.CanonicalEditPolicy;
9
import org.eclipse.gmf.runtime.notation.View;
10
import org.eclipse.uml2.diagram.clazz.edit.parts.AssociationClassEditPart;
11
import org.eclipse.uml2.diagram.clazz.edit.parts.ClassEditPart;
12
import org.eclipse.uml2.diagram.clazz.edit.parts.DataTypeEditPart;
13
import org.eclipse.uml2.diagram.clazz.edit.parts.EnumerationEditPart;
14
import org.eclipse.uml2.diagram.clazz.edit.parts.PrimitiveTypeEditPart;
15
import org.eclipse.uml2.diagram.clazz.part.UMLVisualIDRegistry;
16
17
/**
18
 * @generated
19
 */
20
public class PackageClassifiersCanonicalEditPolicy extends CanonicalEditPolicy {
21
22
	/**
23
	 * @generated
24
	 */
25
	protected List getSemanticChildrenList() {
26
		List result = new LinkedList();
27
		EObject modelObject = ((View) getHost().getModel()).getElement();
28
		View viewObject = (View) getHost().getModel();
29
		EObject nextValue;
30
		int nodeVID;
31
		for (Iterator values = ((org.eclipse.uml2.uml.Package) modelObject).getOwnedTypes().iterator(); values.hasNext();) {
32
			nextValue = (EObject) values.next();
33
			nodeVID = UMLVisualIDRegistry.getNodeVisualID(viewObject, nextValue);
34
			switch (nodeVID) {
35
			case ClassEditPart.VISUAL_ID: {
36
				result.add(nextValue);
37
				break;
38
			}
39
			case DataTypeEditPart.VISUAL_ID: {
40
				result.add(nextValue);
41
				break;
42
			}
43
			case PrimitiveTypeEditPart.VISUAL_ID: {
44
				result.add(nextValue);
45
				break;
46
			}
47
			case EnumerationEditPart.VISUAL_ID: {
48
				result.add(nextValue);
49
				break;
50
			}
51
			case AssociationClassEditPart.VISUAL_ID: {
52
				result.add(nextValue);
53
				break;
54
			}
55
			}
56
		}
57
		return result;
58
	}
59
60
	/**
61
	 * @generated
62
	 */
63
	protected boolean shouldDeleteView(View view) {
64
		return view.isSetElement() && view.getElement() != null && view.getElement().eIsProxy();
65
	}
66
67
	/**
68
	 * @generated
69
	 */
70
	protected String getDefaultFactoryHint() {
71
		return null;
72
	}
73
74
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/parts/SlotEditPart.java (+559 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.parts;
2
3
import java.util.Collections;
4
import java.util.List;
5
6
import org.eclipse.draw2d.IFigure;
7
import org.eclipse.draw2d.Label;
8
import org.eclipse.draw2d.geometry.Point;
9
import org.eclipse.emf.common.notify.Notification;
10
import org.eclipse.emf.ecore.EObject;
11
import org.eclipse.emf.transaction.RunnableWithResult;
12
import org.eclipse.gef.AccessibleEditPart;
13
import org.eclipse.gef.DragTracker;
14
import org.eclipse.gef.EditPolicy;
15
import org.eclipse.gef.Request;
16
import org.eclipse.gef.requests.DirectEditRequest;
17
import org.eclipse.gef.requests.SelectionRequest;
18
import org.eclipse.gef.tools.DirectEditManager;
19
import org.eclipse.gmf.runtime.common.ui.services.parser.IParser;
20
import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus;
21
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserEditStatus;
22
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions;
23
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserService;
24
import org.eclipse.gmf.runtime.diagram.ui.editparts.CompartmentEditPart;
25
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
26
import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart;
27
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
28
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy;
29
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.ListItemComponentEditPolicy;
30
import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry;
31
import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants;
32
import org.eclipse.gmf.runtime.diagram.ui.tools.DragEditPartsTrackerEx;
33
import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager;
34
import org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel;
35
import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
36
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
37
import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser;
38
import org.eclipse.gmf.runtime.emf.ui.services.parser.ParserHintAdapter;
39
import org.eclipse.gmf.runtime.notation.FontStyle;
40
import org.eclipse.gmf.runtime.notation.NotationPackage;
41
import org.eclipse.gmf.runtime.notation.View;
42
import org.eclipse.jface.resource.ImageDescriptor;
43
import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
44
import org.eclipse.jface.viewers.ICellEditorValidator;
45
import org.eclipse.swt.SWT;
46
import org.eclipse.swt.accessibility.AccessibleEvent;
47
import org.eclipse.swt.graphics.Color;
48
import org.eclipse.swt.graphics.FontData;
49
import org.eclipse.swt.graphics.Image;
50
import org.eclipse.uml2.diagram.clazz.edit.policies.SlotItemSemanticEditPolicy;
51
import org.eclipse.uml2.diagram.clazz.edit.policies.UMLTextNonResizableEditPolicy;
52
import org.eclipse.uml2.diagram.clazz.edit.policies.UMLTextSelectionEditPolicy;
53
import org.eclipse.uml2.diagram.clazz.part.UMLDiagramEditorPlugin;
54
import org.eclipse.uml2.diagram.clazz.providers.UMLElementTypes;
55
56
/**
57
 * @generated
58
 */
59
public class SlotEditPart extends CompartmentEditPart implements ITextAwareEditPart {
60
61
	/**
62
	 * @generated
63
	 */
64
	public static final int VISUAL_ID = 3017;
65
66
	/**
67
	 * @generated
68
	 */
69
	private DirectEditManager manager;
70
71
	/**
72
	 * @generated
73
	 */
74
	private IParser parser;
75
76
	/**
77
	 * @generated
78
	 */
79
	private List parserElements;
80
81
	/**
82
	 * @generated
83
	 */
84
	private String defaultText;
85
86
	/**
87
	 * @generated
88
	 */
89
	public SlotEditPart(View view) {
90
		super(view);
91
	}
92
93
	/**
94
	 * @generated
95
	 */
96
	public DragTracker getDragTracker(Request request) {
97
		if (request instanceof SelectionRequest && ((SelectionRequest) request).getLastButtonPressed() == 3) {
98
			return null;
99
		}
100
		return new DragEditPartsTrackerEx(this);
101
	}
102
103
	/**
104
	 * @generated
105
	 */
106
	protected void createDefaultEditPolicies() {
107
		super.createDefaultEditPolicies();
108
		installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new SlotItemSemanticEditPolicy());
109
		installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new UMLTextNonResizableEditPolicy());
110
		installEditPolicy(EditPolicy.COMPONENT_ROLE, new ListItemComponentEditPolicy());
111
		installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy());
112
113
	}
114
115
	/**
116
	 * @generated
117
	 */
118
	protected String getLabelTextHelper(IFigure figure) {
119
		if (figure instanceof WrapLabel) {
120
			return ((WrapLabel) figure).getText();
121
		} else {
122
			return ((Label) figure).getText();
123
		}
124
	}
125
126
	/**
127
	 * @generated
128
	 */
129
	protected void setLabelTextHelper(IFigure figure, String text) {
130
		if (figure instanceof WrapLabel) {
131
			((WrapLabel) figure).setText(text);
132
		} else {
133
			((Label) figure).setText(text);
134
		}
135
	}
136
137
	/**
138
	 * @generated
139
	 */
140
	protected Image getLabelIconHelper(IFigure figure) {
141
		if (figure instanceof WrapLabel) {
142
			return ((WrapLabel) figure).getIcon();
143
		} else {
144
			return ((Label) figure).getIcon();
145
		}
146
	}
147
148
	/**
149
	 * @generated
150
	 */
151
	protected void setLabelIconHelper(IFigure figure, Image icon) {
152
		if (figure instanceof WrapLabel) {
153
			((WrapLabel) figure).setIcon(icon);
154
		} else {
155
			((Label) figure).setIcon(icon);
156
		}
157
	}
158
159
	/**
160
	 * @generated
161
	 */
162
	public void setLabel(IFigure figure) {
163
		unregisterVisuals();
164
		setFigure(figure);
165
		defaultText = getLabelTextHelper(figure);
166
		registerVisuals();
167
		refreshVisuals();
168
	}
169
170
	/**
171
	 * @generated
172
	 */
173
	protected List getModelChildren() {
174
		return Collections.EMPTY_LIST;
175
	}
176
177
	/**
178
	 * @generated
179
	 */
180
	public IGraphicalEditPart getChildBySemanticHint(String semanticHint) {
181
		return null;
182
	}
183
184
	/**
185
	 * @generated
186
	 */
187
	protected EObject getParserElement() {
188
		EObject element = resolveSemanticElement();
189
		return element != null ? element : (View) getModel();
190
	}
191
192
	/**
193
	 * @generated
194
	 */
195
	protected Image getLabelIcon() {
196
		EObject parserElement = getParserElement();
197
		if (parserElement == null) {
198
			return null;
199
		}
200
		return UMLElementTypes.getImage(parserElement.eClass());
201
	}
202
203
	/**
204
	 * @generated
205
	 */
206
	protected String getLabelText() {
207
		String text = null;
208
		if (getParser() != null) {
209
			text = getParser().getPrintString(new EObjectAdapter(getParserElement()), getParserOptions().intValue());
210
		}
211
		if (text == null || text.length() == 0) {
212
			text = defaultText;
213
		}
214
		return text;
215
	}
216
217
	/**
218
	 * @generated
219
	 */
220
	public void setLabelText(String text) {
221
		setLabelTextHelper(getFigure(), text);
222
		Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
223
		if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) {
224
			((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback();
225
		}
226
	}
227
228
	/**
229
	 * @generated
230
	 */
231
	public String getEditText() {
232
		if (getParser() == null) {
233
			return ""; //$NON-NLS-1$
234
		}
235
		return getParser().getEditString(new EObjectAdapter(getParserElement()), getParserOptions().intValue());
236
	}
237
238
	/**
239
	 * @generated
240
	 */
241
	protected boolean isEditable() {
242
		return getEditText() != null;
243
	}
244
245
	/**
246
	 * @generated
247
	 */
248
	public ICellEditorValidator getEditTextValidator() {
249
		return new ICellEditorValidator() {
250
251
			public String isValid(final Object value) {
252
				if (value instanceof String) {
253
					final EObject element = getParserElement();
254
					final IParser parser = getParser();
255
					try {
256
						IParserEditStatus valid = (IParserEditStatus) getEditingDomain().runExclusive(new RunnableWithResult.Impl() {
257
258
							public void run() {
259
								setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value));
260
							}
261
						});
262
						return valid.getCode() == ParserEditStatus.EDITABLE ? null : valid.getMessage();
263
					} catch (InterruptedException ie) {
264
						ie.printStackTrace();
265
					}
266
				}
267
268
				// shouldn't get here
269
				return null;
270
			}
271
		};
272
	}
273
274
	/**
275
	 * @generated
276
	 */
277
	public IContentAssistProcessor getCompletionProcessor() {
278
		if (getParser() == null) {
279
			return null;
280
		}
281
		return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement()));
282
	}
283
284
	/**
285
	 * @generated
286
	 */
287
	public ParserOptions getParserOptions() {
288
		return ParserOptions.NONE;
289
	}
290
291
	/**
292
	 * @generated
293
	 */
294
	public IParser getParser() {
295
		if (parser == null) {
296
			String parserHint = ((View) getModel()).getType();
297
			ParserHintAdapter hintAdapter = new ParserHintAdapter(getParserElement(), parserHint) {
298
299
				public Object getAdapter(Class adapter) {
300
					if (IElementType.class.equals(adapter)) {
301
						return UMLElementTypes.Slot_3017;
302
					}
303
					return super.getAdapter(adapter);
304
				}
305
			};
306
			parser = ParserService.getInstance().getParser(hintAdapter);
307
		}
308
		return parser;
309
	}
310
311
	/**
312
	 * @generated
313
	 */
314
	protected DirectEditManager getManager() {
315
		if (manager == null) {
316
			setManager(new TextDirectEditManager(this, TextDirectEditManager.getTextCellEditorClass(this), UMLEditPartFactory.getTextCellEditorLocator(this)));
317
		}
318
		return manager;
319
	}
320
321
	/**
322
	 * @generated
323
	 */
324
	protected void setManager(DirectEditManager manager) {
325
		this.manager = manager;
326
	}
327
328
	/**
329
	 * @generated
330
	 */
331
	protected void performDirectEdit() {
332
		getManager().show();
333
	}
334
335
	/**
336
	 * @generated
337
	 */
338
	protected void performDirectEdit(Point eventLocation) {
339
		if (getManager().getClass() == TextDirectEditManager.class) {
340
			((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint());
341
		}
342
	}
343
344
	/**
345
	 * @generated
346
	 */
347
	private void performDirectEdit(char initialCharacter) {
348
		if (getManager() instanceof TextDirectEditManager) {
349
			((TextDirectEditManager) getManager()).show(initialCharacter);
350
		} else {
351
			performDirectEdit();
352
		}
353
	}
354
355
	/**
356
	 * @generated
357
	 */
358
	protected void performDirectEditRequest(Request request) {
359
		final Request theRequest = request;
360
		try {
361
			getEditingDomain().runExclusive(new Runnable() {
362
363
				public void run() {
364
					if (isActive() && isEditable()) {
365
						if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) {
366
							Character initialChar = (Character) theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR);
367
							performDirectEdit(initialChar.charValue());
368
						} else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) {
369
							DirectEditRequest editRequest = (DirectEditRequest) theRequest;
370
							performDirectEdit(editRequest.getLocation());
371
						} else {
372
							performDirectEdit();
373
						}
374
					}
375
				}
376
			});
377
		} catch (InterruptedException e) {
378
			e.printStackTrace();
379
		}
380
	}
381
382
	/**
383
	 * @generated
384
	 */
385
	protected void refreshVisuals() {
386
		super.refreshVisuals();
387
		refreshLabel();
388
		refreshFont();
389
		refreshFontColor();
390
		refreshUnderline();
391
		refreshStrikeThrough();
392
	}
393
394
	/**
395
	 * @generated
396
	 */
397
	protected void refreshLabel() {
398
		setLabelTextHelper(getFigure(), getLabelText());
399
		setLabelIconHelper(getFigure(), getLabelIcon());
400
		Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
401
		if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) {
402
			((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback();
403
		}
404
	}
405
406
	/**
407
	 * @generated
408
	 */
409
	protected void refreshUnderline() {
410
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
411
		if (style != null && getFigure() instanceof WrapLabel) {
412
			((WrapLabel) getFigure()).setTextUnderline(style.isUnderline());
413
		}
414
	}
415
416
	/**
417
	 * @generated
418
	 */
419
	protected void refreshStrikeThrough() {
420
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
421
		if (style != null && getFigure() instanceof WrapLabel) {
422
			((WrapLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough());
423
		}
424
	}
425
426
	/**
427
	 * @generated
428
	 */
429
	protected void refreshFont() {
430
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
431
		if (style != null) {
432
			FontData fontData = new FontData(style.getFontName(), style.getFontHeight(), (style.isBold() ? SWT.BOLD : SWT.NORMAL) | (style.isItalic() ? SWT.ITALIC : SWT.NORMAL));
433
			setFont(fontData);
434
		}
435
	}
436
437
	/**
438
	 * @generated
439
	 */
440
	protected void setFontColor(Color color) {
441
		getFigure().setForegroundColor(color);
442
	}
443
444
	/**
445
	 * @generated
446
	 */
447
	protected void addSemanticListeners() {
448
		if (getParser() instanceof ISemanticParser) {
449
			EObject element = resolveSemanticElement();
450
			parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element);
451
			for (int i = 0; i < parserElements.size(); i++) {
452
				addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$
453
			}
454
		} else {
455
			super.addSemanticListeners();
456
		}
457
	}
458
459
	/**
460
	 * @generated
461
	 */
462
	protected void removeSemanticListeners() {
463
		if (parserElements != null) {
464
			for (int i = 0; i < parserElements.size(); i++) {
465
				removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$
466
			}
467
		} else {
468
			super.removeSemanticListeners();
469
		}
470
	}
471
472
	/**
473
	 * @generated
474
	 */
475
	protected AccessibleEditPart getAccessibleEditPart() {
476
		if (accessibleEP == null) {
477
			accessibleEP = new AccessibleGraphicalEditPart() {
478
479
				public void getName(AccessibleEvent e) {
480
					e.result = getLabelTextHelper(getFigure());
481
				}
482
			};
483
		}
484
		return accessibleEP;
485
	}
486
487
	/**
488
	 * @generated
489
	 */
490
	private View getFontStyleOwnerView() {
491
		return getPrimaryView();
492
	}
493
494
	/**
495
	 * @generated
496
	 */
497
	protected void addNotationalListeners() {
498
		super.addNotationalListeners();
499
		addListenerFilter("PrimaryView", this, getPrimaryView()); //$NON-NLS-1$
500
	}
501
502
	/**
503
	 * @generated
504
	 */
505
	protected void removeNotationalListeners() {
506
		super.removeNotationalListeners();
507
		removeListenerFilter("PrimaryView"); //$NON-NLS-1$
508
	}
509
510
	/**
511
	 * @generated
512
	 */
513
	protected void handleNotificationEvent(Notification event) {
514
		Object feature = event.getFeature();
515
		if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) {
516
			Integer c = (Integer) event.getNewValue();
517
			setFontColor(DiagramColorRegistry.getInstance().getColor(c));
518
		} else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) {
519
			refreshUnderline();
520
		} else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) {
521
			refreshStrikeThrough();
522
		} else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature)
523
				|| NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) {
524
			refreshFont();
525
		} else {
526
			if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) {
527
				refreshLabel();
528
			}
529
			if (getParser() instanceof ISemanticParser) {
530
				ISemanticParser modelParser = (ISemanticParser) getParser();
531
				if (modelParser.areSemanticElementsAffected(null, event)) {
532
					removeSemanticListeners();
533
					if (resolveSemanticElement() != null) {
534
						addSemanticListeners();
535
					}
536
					refreshLabel();
537
				}
538
			}
539
		}
540
		super.handleNotificationEvent(event);
541
	}
542
543
	/**
544
	 * @generated
545
	 */
546
	protected IFigure createFigure() {
547
		IFigure label = createFigurePrim();
548
		defaultText = getLabelTextHelper(label);
549
		return label;
550
	}
551
552
	/**
553
	 * @generated
554
	 */
555
	protected IFigure createFigurePrim() {
556
		return new WrapLabel();
557
	}
558
559
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/policies/EnumerationAttributesCanonicalEditPolicy.java (+52 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.policies;
2
3
import java.util.Iterator;
4
import java.util.LinkedList;
5
import java.util.List;
6
7
import org.eclipse.emf.ecore.EObject;
8
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.CanonicalEditPolicy;
9
import org.eclipse.gmf.runtime.notation.View;
10
import org.eclipse.uml2.diagram.clazz.edit.parts.Property5EditPart;
11
import org.eclipse.uml2.diagram.clazz.part.UMLVisualIDRegistry;
12
import org.eclipse.uml2.uml.DataType;
13
14
/**
15
 * @generated
16
 */
17
public class EnumerationAttributesCanonicalEditPolicy extends CanonicalEditPolicy {
18
19
	/**
20
	 * @generated
21
	 */
22
	protected List getSemanticChildrenList() {
23
		List result = new LinkedList();
24
		EObject modelObject = ((View) getHost().getModel()).getElement();
25
		View viewObject = (View) getHost().getModel();
26
		EObject nextValue;
27
		int nodeVID;
28
		for (Iterator values = ((DataType) modelObject).getOwnedAttributes().iterator(); values.hasNext();) {
29
			nextValue = (EObject) values.next();
30
			nodeVID = UMLVisualIDRegistry.getNodeVisualID(viewObject, nextValue);
31
			if (Property5EditPart.VISUAL_ID == nodeVID) {
32
				result.add(nextValue);
33
			}
34
		}
35
		return result;
36
	}
37
38
	/**
39
	 * @generated
40
	 */
41
	protected boolean shouldDeleteView(View view) {
42
		return view.isSetElement() && view.getElement() != null && view.getElement().eIsProxy();
43
	}
44
45
	/**
46
	 * @generated
47
	 */
48
	protected String getDefaultFactoryHint() {
49
		return null;
50
	}
51
52
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/parts/Property6EditPart.java (+48 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.parts;
2
3
import org.eclipse.draw2d.Connection;
4
import org.eclipse.gmf.runtime.diagram.ui.editparts.ConnectionNodeEditPart;
5
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
6
import org.eclipse.gmf.runtime.draw2d.ui.figures.PolylineConnectionEx;
7
import org.eclipse.gmf.runtime.notation.View;
8
import org.eclipse.uml2.diagram.clazz.edit.policies.Property6ItemSemanticEditPolicy;
9
10
/**
11
 * @generated
12
 */
13
public class Property6EditPart extends ConnectionNodeEditPart {
14
15
	/**
16
	 * @generated
17
	 */
18
	public static final int VISUAL_ID = 4003;
19
20
	/**
21
	 * @generated
22
	 */
23
	public Property6EditPart(View view) {
24
		super(view);
25
	}
26
27
	/**
28
	 * @generated
29
	 */
30
	protected void createDefaultEditPolicies() {
31
		super.createDefaultEditPolicies();
32
		installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new Property6ItemSemanticEditPolicy());
33
34
	}
35
36
	/**
37
	 * Creates figure for this edit part.
38
	 * 
39
	 * Body of this method does not depend on settings in generation model
40
	 * so you may safely remove <i>generated</i> tag and modify it.
41
	 * 
42
	 * @generated
43
	 */
44
	protected Connection createConnectionFigure() {
45
		return new PolylineConnectionEx();
46
	}
47
48
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/policies/PrimitiveTypeOperationsItemSemanticEditPolicy.java (+73 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.policies;
2
3
import org.eclipse.emf.ecore.EClass;
4
import org.eclipse.emf.ecore.EObject;
5
import org.eclipse.gef.commands.Command;
6
import org.eclipse.gmf.runtime.emf.type.core.commands.CreateElementCommand;
7
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest;
8
import org.eclipse.gmf.runtime.notation.View;
9
import org.eclipse.uml2.diagram.clazz.providers.UMLElementTypes;
10
import org.eclipse.uml2.uml.Operation;
11
import org.eclipse.uml2.uml.UMLPackage;
12
13
/**
14
 * @generated
15
 */
16
public class PrimitiveTypeOperationsItemSemanticEditPolicy extends UMLBaseItemSemanticEditPolicy {
17
18
	/**
19
	 * @generated
20
	 */
21
	protected Command getCreateCommand(CreateElementRequest req) {
22
		if (UMLElementTypes.Operation_3022 == req.getElementType()) {
23
			if (req.getContainmentFeature() == null) {
24
				req.setContainmentFeature(UMLPackage.eINSTANCE.getDataType_OwnedOperation());
25
			}
26
			return getMSLWrapper(new CreateOperation_3022Command(req));
27
		}
28
		return super.getCreateCommand(req);
29
	}
30
31
	/**
32
	 * @generated
33
	 */
34
	private static class CreateOperation_3022Command extends CreateElementCommand {
35
36
		/**
37
		 * @generated
38
		 */
39
		public CreateOperation_3022Command(CreateElementRequest req) {
40
			super(req);
41
		}
42
43
		/**
44
		 * @generated
45
		 */
46
		protected EClass getEClassToEdit() {
47
			return UMLPackage.eINSTANCE.getPrimitiveType();
48
		};
49
50
		/**
51
		 * @generated
52
		 */
53
		protected EObject getElementToEdit() {
54
			EObject container = ((CreateElementRequest) getRequest()).getContainer();
55
			if (container instanceof View) {
56
				container = ((View) container).getElement();
57
			}
58
			return container;
59
		}
60
61
		/**
62
		 * @generated
63
		 */
64
		protected EObject doDefaultElementCreation() {
65
			Operation newElement = (Operation) super.doDefaultElementCreation();
66
			if (newElement != null) {
67
				UMLElementTypes.Initializers.Operation_3022.init(newElement);
68
			}
69
			return newElement;
70
		}
71
	}
72
73
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/policies/ClassOperationsItemSemanticEditPolicy.java (+73 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.policies;
2
3
import org.eclipse.emf.ecore.EClass;
4
import org.eclipse.emf.ecore.EObject;
5
import org.eclipse.gef.commands.Command;
6
import org.eclipse.gmf.runtime.emf.type.core.commands.CreateElementCommand;
7
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest;
8
import org.eclipse.gmf.runtime.notation.View;
9
import org.eclipse.uml2.diagram.clazz.providers.UMLElementTypes;
10
import org.eclipse.uml2.uml.Operation;
11
import org.eclipse.uml2.uml.UMLPackage;
12
13
/**
14
 * @generated
15
 */
16
public class ClassOperationsItemSemanticEditPolicy extends UMLBaseItemSemanticEditPolicy {
17
18
	/**
19
	 * @generated
20
	 */
21
	protected Command getCreateCommand(CreateElementRequest req) {
22
		if (UMLElementTypes.Operation_3002 == req.getElementType()) {
23
			if (req.getContainmentFeature() == null) {
24
				req.setContainmentFeature(UMLPackage.eINSTANCE.getClass_OwnedOperation());
25
			}
26
			return getMSLWrapper(new CreateOperation_3002Command(req));
27
		}
28
		return super.getCreateCommand(req);
29
	}
30
31
	/**
32
	 * @generated
33
	 */
34
	private static class CreateOperation_3002Command extends CreateElementCommand {
35
36
		/**
37
		 * @generated
38
		 */
39
		public CreateOperation_3002Command(CreateElementRequest req) {
40
			super(req);
41
		}
42
43
		/**
44
		 * @generated
45
		 */
46
		protected EClass getEClassToEdit() {
47
			return UMLPackage.eINSTANCE.getClass_();
48
		};
49
50
		/**
51
		 * @generated
52
		 */
53
		protected EObject getElementToEdit() {
54
			EObject container = ((CreateElementRequest) getRequest()).getContainer();
55
			if (container instanceof View) {
56
				container = ((View) container).getElement();
57
			}
58
			return container;
59
		}
60
61
		/**
62
		 * @generated
63
		 */
64
		protected EObject doDefaultElementCreation() {
65
			Operation newElement = (Operation) super.doDefaultElementCreation();
66
			if (newElement != null) {
67
				UMLElementTypes.Initializers.Operation_3002.init(newElement);
68
			}
69
			return newElement;
70
		}
71
	}
72
73
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/parts/AssociationName2EditPart.java (+533 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.parts;
2
3
import java.util.Collections;
4
import java.util.List;
5
6
import org.eclipse.draw2d.ConnectionLocator;
7
import org.eclipse.draw2d.IFigure;
8
import org.eclipse.draw2d.Label;
9
import org.eclipse.draw2d.geometry.Point;
10
import org.eclipse.emf.common.notify.Notification;
11
import org.eclipse.emf.ecore.EObject;
12
import org.eclipse.emf.transaction.RunnableWithResult;
13
import org.eclipse.gef.AccessibleEditPart;
14
import org.eclipse.gef.EditPolicy;
15
import org.eclipse.gef.Request;
16
import org.eclipse.gef.requests.DirectEditRequest;
17
import org.eclipse.gef.tools.DirectEditManager;
18
import org.eclipse.gmf.runtime.common.ui.services.parser.IParser;
19
import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus;
20
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserEditStatus;
21
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions;
22
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserService;
23
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
24
import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart;
25
import org.eclipse.gmf.runtime.diagram.ui.editparts.LabelEditPart;
26
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy;
27
import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry;
28
import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants;
29
import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager;
30
import org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel;
31
import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
32
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
33
import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser;
34
import org.eclipse.gmf.runtime.emf.ui.services.parser.ParserHintAdapter;
35
import org.eclipse.gmf.runtime.notation.FontStyle;
36
import org.eclipse.gmf.runtime.notation.NotationPackage;
37
import org.eclipse.gmf.runtime.notation.View;
38
import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
39
import org.eclipse.jface.viewers.ICellEditorValidator;
40
import org.eclipse.swt.SWT;
41
import org.eclipse.swt.accessibility.AccessibleEvent;
42
import org.eclipse.swt.graphics.Color;
43
import org.eclipse.swt.graphics.FontData;
44
import org.eclipse.swt.graphics.Image;
45
import org.eclipse.uml2.diagram.clazz.edit.policies.UMLTextSelectionEditPolicy;
46
import org.eclipse.uml2.diagram.clazz.part.UMLVisualIDRegistry;
47
import org.eclipse.uml2.diagram.clazz.providers.UMLElementTypes;
48
49
/**
50
 * @generated
51
 */
52
public class AssociationName2EditPart extends LabelEditPart implements ITextAwareEditPart {
53
54
	/**
55
	 * @generated
56
	 */
57
	public static final int VISUAL_ID = 6004;
58
59
	/**
60
	 * @generated
61
	 */
62
	private DirectEditManager manager;
63
64
	/**
65
	 * @generated
66
	 */
67
	private IParser parser;
68
69
	/**
70
	 * @generated
71
	 */
72
	private List parserElements;
73
74
	/**
75
	 * @generated
76
	 */
77
	private String defaultText;
78
79
	/**
80
	 * @generated
81
	 */
82
	static {
83
		registerSnapBackPosition(UMLVisualIDRegistry.getType(AssociationName2EditPart.VISUAL_ID), new Point(0, -15));
84
	}
85
86
	/**
87
	 * @generated
88
	 */
89
	public AssociationName2EditPart(View view) {
90
		super(view);
91
	}
92
93
	/**
94
	 * @generated
95
	 */
96
	protected void createDefaultEditPolicies() {
97
		super.createDefaultEditPolicies();
98
		installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy());
99
100
	}
101
102
	/**
103
	 * @generated
104
	 */
105
	public int getKeyPoint() {
106
		return ConnectionLocator.TARGET;
107
	}
108
109
	/**
110
	 * @generated
111
	 */
112
	protected String getLabelTextHelper(IFigure figure) {
113
		if (figure instanceof WrapLabel) {
114
			return ((WrapLabel) figure).getText();
115
		} else {
116
			return ((Label) figure).getText();
117
		}
118
	}
119
120
	/**
121
	 * @generated
122
	 */
123
	protected void setLabelTextHelper(IFigure figure, String text) {
124
		if (figure instanceof WrapLabel) {
125
			((WrapLabel) figure).setText(text);
126
		} else {
127
			((Label) figure).setText(text);
128
		}
129
	}
130
131
	/**
132
	 * @generated
133
	 */
134
	protected Image getLabelIconHelper(IFigure figure) {
135
		if (figure instanceof WrapLabel) {
136
			return ((WrapLabel) figure).getIcon();
137
		} else {
138
			return ((Label) figure).getIcon();
139
		}
140
	}
141
142
	/**
143
	 * @generated
144
	 */
145
	protected void setLabelIconHelper(IFigure figure, Image icon) {
146
		if (figure instanceof WrapLabel) {
147
			((WrapLabel) figure).setIcon(icon);
148
		} else {
149
			((Label) figure).setIcon(icon);
150
		}
151
	}
152
153
	/**
154
	 * @generated
155
	 */
156
	public void setLabel(IFigure figure) {
157
		unregisterVisuals();
158
		setFigure(figure);
159
		defaultText = getLabelTextHelper(figure);
160
		registerVisuals();
161
		refreshVisuals();
162
	}
163
164
	/**
165
	 * @generated
166
	 */
167
	protected List getModelChildren() {
168
		return Collections.EMPTY_LIST;
169
	}
170
171
	/**
172
	 * @generated
173
	 */
174
	public IGraphicalEditPart getChildBySemanticHint(String semanticHint) {
175
		return null;
176
	}
177
178
	/**
179
	 * @generated
180
	 */
181
	protected EObject getParserElement() {
182
		EObject element = resolveSemanticElement();
183
		return element != null ? element : (View) getModel();
184
	}
185
186
	/**
187
	 * @generated
188
	 */
189
	protected Image getLabelIcon() {
190
		return null;
191
	}
192
193
	/**
194
	 * @generated
195
	 */
196
	protected String getLabelText() {
197
		String text = null;
198
		if (getParser() != null) {
199
			text = getParser().getPrintString(new EObjectAdapter(getParserElement()), getParserOptions().intValue());
200
		}
201
		if (text == null || text.length() == 0) {
202
			text = defaultText;
203
		}
204
		return text;
205
	}
206
207
	/**
208
	 * @generated
209
	 */
210
	public void setLabelText(String text) {
211
		setLabelTextHelper(getFigure(), text);
212
		Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
213
		if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) {
214
			((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback();
215
		}
216
	}
217
218
	/**
219
	 * @generated
220
	 */
221
	public String getEditText() {
222
		if (getParser() == null) {
223
			return ""; //$NON-NLS-1$
224
		}
225
		return getParser().getEditString(new EObjectAdapter(getParserElement()), getParserOptions().intValue());
226
	}
227
228
	/**
229
	 * @generated
230
	 */
231
	protected boolean isEditable() {
232
		return getEditText() != null;
233
	}
234
235
	/**
236
	 * @generated
237
	 */
238
	public ICellEditorValidator getEditTextValidator() {
239
		return new ICellEditorValidator() {
240
241
			public String isValid(final Object value) {
242
				if (value instanceof String) {
243
					final EObject element = getParserElement();
244
					final IParser parser = getParser();
245
					try {
246
						IParserEditStatus valid = (IParserEditStatus) getEditingDomain().runExclusive(new RunnableWithResult.Impl() {
247
248
							public void run() {
249
								setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value));
250
							}
251
						});
252
						return valid.getCode() == ParserEditStatus.EDITABLE ? null : valid.getMessage();
253
					} catch (InterruptedException ie) {
254
						ie.printStackTrace();
255
					}
256
				}
257
258
				// shouldn't get here
259
				return null;
260
			}
261
		};
262
	}
263
264
	/**
265
	 * @generated
266
	 */
267
	public IContentAssistProcessor getCompletionProcessor() {
268
		if (getParser() == null) {
269
			return null;
270
		}
271
		return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement()));
272
	}
273
274
	/**
275
	 * @generated
276
	 */
277
	public ParserOptions getParserOptions() {
278
		return ParserOptions.NONE;
279
	}
280
281
	/**
282
	 * @generated
283
	 */
284
	public IParser getParser() {
285
		if (parser == null) {
286
			String parserHint = ((View) getModel()).getType();
287
			ParserHintAdapter hintAdapter = new ParserHintAdapter(getParserElement(), parserHint) {
288
289
				public Object getAdapter(Class adapter) {
290
					if (IElementType.class.equals(adapter)) {
291
						return UMLElementTypes.Association_4005;
292
					}
293
					return super.getAdapter(adapter);
294
				}
295
			};
296
			parser = ParserService.getInstance().getParser(hintAdapter);
297
		}
298
		return parser;
299
	}
300
301
	/**
302
	 * @generated
303
	 */
304
	protected DirectEditManager getManager() {
305
		if (manager == null) {
306
			setManager(new TextDirectEditManager(this, TextDirectEditManager.getTextCellEditorClass(this), UMLEditPartFactory.getTextCellEditorLocator(this)));
307
		}
308
		return manager;
309
	}
310
311
	/**
312
	 * @generated
313
	 */
314
	protected void setManager(DirectEditManager manager) {
315
		this.manager = manager;
316
	}
317
318
	/**
319
	 * @generated
320
	 */
321
	protected void performDirectEdit() {
322
		getManager().show();
323
	}
324
325
	/**
326
	 * @generated
327
	 */
328
	protected void performDirectEdit(Point eventLocation) {
329
		if (getManager().getClass() == TextDirectEditManager.class) {
330
			((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint());
331
		}
332
	}
333
334
	/**
335
	 * @generated
336
	 */
337
	private void performDirectEdit(char initialCharacter) {
338
		if (getManager() instanceof TextDirectEditManager) {
339
			((TextDirectEditManager) getManager()).show(initialCharacter);
340
		} else {
341
			performDirectEdit();
342
		}
343
	}
344
345
	/**
346
	 * @generated
347
	 */
348
	protected void performDirectEditRequest(Request request) {
349
		final Request theRequest = request;
350
		try {
351
			getEditingDomain().runExclusive(new Runnable() {
352
353
				public void run() {
354
					if (isActive() && isEditable()) {
355
						if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) {
356
							Character initialChar = (Character) theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR);
357
							performDirectEdit(initialChar.charValue());
358
						} else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) {
359
							DirectEditRequest editRequest = (DirectEditRequest) theRequest;
360
							performDirectEdit(editRequest.getLocation());
361
						} else {
362
							performDirectEdit();
363
						}
364
					}
365
				}
366
			});
367
		} catch (InterruptedException e) {
368
			e.printStackTrace();
369
		}
370
	}
371
372
	/**
373
	 * @generated
374
	 */
375
	protected void refreshVisuals() {
376
		super.refreshVisuals();
377
		refreshLabel();
378
		refreshFont();
379
		refreshFontColor();
380
		refreshUnderline();
381
		refreshStrikeThrough();
382
	}
383
384
	/**
385
	 * @generated
386
	 */
387
	protected void refreshLabel() {
388
		setLabelTextHelper(getFigure(), getLabelText());
389
		setLabelIconHelper(getFigure(), getLabelIcon());
390
		Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
391
		if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) {
392
			((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback();
393
		}
394
	}
395
396
	/**
397
	 * @generated
398
	 */
399
	protected void refreshUnderline() {
400
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
401
		if (style != null && getFigure() instanceof WrapLabel) {
402
			((WrapLabel) getFigure()).setTextUnderline(style.isUnderline());
403
		}
404
	}
405
406
	/**
407
	 * @generated
408
	 */
409
	protected void refreshStrikeThrough() {
410
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
411
		if (style != null && getFigure() instanceof WrapLabel) {
412
			((WrapLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough());
413
		}
414
	}
415
416
	/**
417
	 * @generated
418
	 */
419
	protected void refreshFont() {
420
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
421
		if (style != null) {
422
			FontData fontData = new FontData(style.getFontName(), style.getFontHeight(), (style.isBold() ? SWT.BOLD : SWT.NORMAL) | (style.isItalic() ? SWT.ITALIC : SWT.NORMAL));
423
			setFont(fontData);
424
		}
425
	}
426
427
	/**
428
	 * @generated
429
	 */
430
	protected void setFontColor(Color color) {
431
		getFigure().setForegroundColor(color);
432
	}
433
434
	/**
435
	 * @generated
436
	 */
437
	protected void addSemanticListeners() {
438
		if (getParser() instanceof ISemanticParser) {
439
			EObject element = resolveSemanticElement();
440
			parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element);
441
			for (int i = 0; i < parserElements.size(); i++) {
442
				addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$
443
			}
444
		} else {
445
			super.addSemanticListeners();
446
		}
447
	}
448
449
	/**
450
	 * @generated
451
	 */
452
	protected void removeSemanticListeners() {
453
		if (parserElements != null) {
454
			for (int i = 0; i < parserElements.size(); i++) {
455
				removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$
456
			}
457
		} else {
458
			super.removeSemanticListeners();
459
		}
460
	}
461
462
	/**
463
	 * @generated
464
	 */
465
	protected AccessibleEditPart getAccessibleEditPart() {
466
		if (accessibleEP == null) {
467
			accessibleEP = new AccessibleGraphicalEditPart() {
468
469
				public void getName(AccessibleEvent e) {
470
					e.result = getLabelTextHelper(getFigure());
471
				}
472
			};
473
		}
474
		return accessibleEP;
475
	}
476
477
	/**
478
	 * @generated
479
	 */
480
	private View getFontStyleOwnerView() {
481
		return getPrimaryView();
482
	}
483
484
	/**
485
	 * @generated
486
	 */
487
	protected void handleNotificationEvent(Notification event) {
488
		Object feature = event.getFeature();
489
		if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) {
490
			Integer c = (Integer) event.getNewValue();
491
			setFontColor(DiagramColorRegistry.getInstance().getColor(c));
492
		} else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) {
493
			refreshUnderline();
494
		} else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) {
495
			refreshStrikeThrough();
496
		} else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature)
497
				|| NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) {
498
			refreshFont();
499
		} else {
500
			if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) {
501
				refreshLabel();
502
			}
503
			if (getParser() instanceof ISemanticParser) {
504
				ISemanticParser modelParser = (ISemanticParser) getParser();
505
				if (modelParser.areSemanticElementsAffected(null, event)) {
506
					removeSemanticListeners();
507
					if (resolveSemanticElement() != null) {
508
						addSemanticListeners();
509
					}
510
					refreshLabel();
511
				}
512
			}
513
		}
514
		super.handleNotificationEvent(event);
515
	}
516
517
	/**
518
	 * @generated
519
	 */
520
	protected IFigure createFigure() {
521
		IFigure label = createFigurePrim();
522
		defaultText = getLabelTextHelper(label);
523
		return label;
524
	}
525
526
	/**
527
	 * @generated
528
	 */
529
	protected IFigure createFigurePrim() {
530
		return new WrapLabel();
531
	}
532
533
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/parts/DataTypeNameEditPart.java (+551 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.parts;
2
3
import java.util.ArrayList;
4
import java.util.Collections;
5
import java.util.List;
6
7
import org.eclipse.draw2d.IFigure;
8
import org.eclipse.draw2d.Label;
9
import org.eclipse.draw2d.geometry.Point;
10
import org.eclipse.emf.common.notify.Notification;
11
import org.eclipse.emf.ecore.EObject;
12
import org.eclipse.emf.transaction.RunnableWithResult;
13
import org.eclipse.gef.AccessibleEditPart;
14
import org.eclipse.gef.EditPolicy;
15
import org.eclipse.gef.GraphicalEditPart;
16
import org.eclipse.gef.Request;
17
import org.eclipse.gef.commands.Command;
18
import org.eclipse.gef.editpolicies.NonResizableEditPolicy;
19
import org.eclipse.gef.handles.NonResizableHandleKit;
20
import org.eclipse.gef.requests.DirectEditRequest;
21
import org.eclipse.gef.tools.DirectEditManager;
22
import org.eclipse.gmf.runtime.common.ui.services.parser.IParser;
23
import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus;
24
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserEditStatus;
25
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions;
26
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserService;
27
import org.eclipse.gmf.runtime.diagram.ui.editparts.CompartmentEditPart;
28
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
29
import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart;
30
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy;
31
import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry;
32
import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants;
33
import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager;
34
import org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel;
35
import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
36
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
37
import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser;
38
import org.eclipse.gmf.runtime.emf.ui.services.parser.ParserHintAdapter;
39
import org.eclipse.gmf.runtime.notation.FontStyle;
40
import org.eclipse.gmf.runtime.notation.NotationPackage;
41
import org.eclipse.gmf.runtime.notation.View;
42
import org.eclipse.jface.resource.ImageDescriptor;
43
import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
44
import org.eclipse.jface.viewers.ICellEditorValidator;
45
import org.eclipse.swt.SWT;
46
import org.eclipse.swt.accessibility.AccessibleEvent;
47
import org.eclipse.swt.graphics.Color;
48
import org.eclipse.swt.graphics.FontData;
49
import org.eclipse.swt.graphics.Image;
50
import org.eclipse.uml2.diagram.clazz.edit.policies.UMLTextSelectionEditPolicy;
51
import org.eclipse.uml2.diagram.clazz.part.UMLDiagramEditorPlugin;
52
import org.eclipse.uml2.diagram.clazz.providers.UMLElementTypes;
53
54
/**
55
 * @generated
56
 */
57
public class DataTypeNameEditPart extends CompartmentEditPart implements ITextAwareEditPart {
58
59
	/**
60
	 * @generated
61
	 */
62
	public static final int VISUAL_ID = 5006;
63
64
	/**
65
	 * @generated
66
	 */
67
	private DirectEditManager manager;
68
69
	/**
70
	 * @generated
71
	 */
72
	private IParser parser;
73
74
	/**
75
	 * @generated
76
	 */
77
	private List parserElements;
78
79
	/**
80
	 * @generated
81
	 */
82
	private String defaultText;
83
84
	/**
85
	 * @generated
86
	 */
87
	public DataTypeNameEditPart(View view) {
88
		super(view);
89
	}
90
91
	/**
92
	 * @generated
93
	 */
94
	protected void createDefaultEditPolicies() {
95
		super.createDefaultEditPolicies();
96
		installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy());
97
		installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new NonResizableEditPolicy() {
98
99
			protected List createSelectionHandles() {
100
				List handles = new ArrayList();
101
				NonResizableHandleKit.addMoveHandle((GraphicalEditPart) getHost(), handles);
102
				return handles;
103
			}
104
105
			public Command getCommand(Request request) {
106
				return null;
107
			}
108
109
			public boolean understandsRequest(Request request) {
110
				return false;
111
			}
112
		});
113
114
	}
115
116
	/**
117
	 * @generated
118
	 */
119
	protected String getLabelTextHelper(IFigure figure) {
120
		if (figure instanceof WrapLabel) {
121
			return ((WrapLabel) figure).getText();
122
		} else {
123
			return ((Label) figure).getText();
124
		}
125
	}
126
127
	/**
128
	 * @generated
129
	 */
130
	protected void setLabelTextHelper(IFigure figure, String text) {
131
		if (figure instanceof WrapLabel) {
132
			((WrapLabel) figure).setText(text);
133
		} else {
134
			((Label) figure).setText(text);
135
		}
136
	}
137
138
	/**
139
	 * @generated
140
	 */
141
	protected Image getLabelIconHelper(IFigure figure) {
142
		if (figure instanceof WrapLabel) {
143
			return ((WrapLabel) figure).getIcon();
144
		} else {
145
			return ((Label) figure).getIcon();
146
		}
147
	}
148
149
	/**
150
	 * @generated
151
	 */
152
	protected void setLabelIconHelper(IFigure figure, Image icon) {
153
		if (figure instanceof WrapLabel) {
154
			((WrapLabel) figure).setIcon(icon);
155
		} else {
156
			((Label) figure).setIcon(icon);
157
		}
158
	}
159
160
	/**
161
	 * @generated
162
	 */
163
	public void setLabel(WrapLabel figure) {
164
		unregisterVisuals();
165
		setFigure(figure);
166
		defaultText = getLabelTextHelper(figure);
167
		registerVisuals();
168
		refreshVisuals();
169
	}
170
171
	/**
172
	 * @generated
173
	 */
174
	protected List getModelChildren() {
175
		return Collections.EMPTY_LIST;
176
	}
177
178
	/**
179
	 * @generated
180
	 */
181
	public IGraphicalEditPart getChildBySemanticHint(String semanticHint) {
182
		return null;
183
	}
184
185
	/**
186
	 * @generated
187
	 */
188
	protected EObject getParserElement() {
189
		EObject element = resolveSemanticElement();
190
		return element != null ? element : (View) getModel();
191
	}
192
193
	/**
194
	 * @generated
195
	 */
196
	protected Image getLabelIcon() {
197
		EObject parserElement = getParserElement();
198
		if (parserElement == null) {
199
			return null;
200
		}
201
		return UMLElementTypes.getImage(parserElement.eClass());
202
	}
203
204
	/**
205
	 * @generated
206
	 */
207
	protected String getLabelText() {
208
		String text = null;
209
		if (getParser() != null) {
210
			text = getParser().getPrintString(new EObjectAdapter(getParserElement()), getParserOptions().intValue());
211
		}
212
		if (text == null || text.length() == 0) {
213
			text = defaultText;
214
		}
215
		return text;
216
	}
217
218
	/**
219
	 * @generated
220
	 */
221
	public void setLabelText(String text) {
222
		setLabelTextHelper(getFigure(), text);
223
		Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
224
		if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) {
225
			((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback();
226
		}
227
	}
228
229
	/**
230
	 * @generated
231
	 */
232
	public String getEditText() {
233
		if (getParser() == null) {
234
			return ""; //$NON-NLS-1$
235
		}
236
		return getParser().getEditString(new EObjectAdapter(getParserElement()), getParserOptions().intValue());
237
	}
238
239
	/**
240
	 * @generated
241
	 */
242
	protected boolean isEditable() {
243
		return getEditText() != null;
244
	}
245
246
	/**
247
	 * @generated
248
	 */
249
	public ICellEditorValidator getEditTextValidator() {
250
		return new ICellEditorValidator() {
251
252
			public String isValid(final Object value) {
253
				if (value instanceof String) {
254
					final EObject element = getParserElement();
255
					final IParser parser = getParser();
256
					try {
257
						IParserEditStatus valid = (IParserEditStatus) getEditingDomain().runExclusive(new RunnableWithResult.Impl() {
258
259
							public void run() {
260
								setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value));
261
							}
262
						});
263
						return valid.getCode() == ParserEditStatus.EDITABLE ? null : valid.getMessage();
264
					} catch (InterruptedException ie) {
265
						ie.printStackTrace();
266
					}
267
				}
268
269
				// shouldn't get here
270
				return null;
271
			}
272
		};
273
	}
274
275
	/**
276
	 * @generated
277
	 */
278
	public IContentAssistProcessor getCompletionProcessor() {
279
		if (getParser() == null) {
280
			return null;
281
		}
282
		return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement()));
283
	}
284
285
	/**
286
	 * @generated
287
	 */
288
	public ParserOptions getParserOptions() {
289
		return ParserOptions.NONE;
290
	}
291
292
	/**
293
	 * @generated
294
	 */
295
	public IParser getParser() {
296
		if (parser == null) {
297
			String parserHint = ((View) getModel()).getType();
298
			ParserHintAdapter hintAdapter = new ParserHintAdapter(getParserElement(), parserHint) {
299
300
				public Object getAdapter(Class adapter) {
301
					if (IElementType.class.equals(adapter)) {
302
						return UMLElementTypes.DataType_2004;
303
					}
304
					return super.getAdapter(adapter);
305
				}
306
			};
307
			parser = ParserService.getInstance().getParser(hintAdapter);
308
		}
309
		return parser;
310
	}
311
312
	/**
313
	 * @generated
314
	 */
315
	protected DirectEditManager getManager() {
316
		if (manager == null) {
317
			setManager(new TextDirectEditManager(this, TextDirectEditManager.getTextCellEditorClass(this), UMLEditPartFactory.getTextCellEditorLocator(this)));
318
		}
319
		return manager;
320
	}
321
322
	/**
323
	 * @generated
324
	 */
325
	protected void setManager(DirectEditManager manager) {
326
		this.manager = manager;
327
	}
328
329
	/**
330
	 * @generated
331
	 */
332
	protected void performDirectEdit() {
333
		getManager().show();
334
	}
335
336
	/**
337
	 * @generated
338
	 */
339
	protected void performDirectEdit(Point eventLocation) {
340
		if (getManager().getClass() == TextDirectEditManager.class) {
341
			((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint());
342
		}
343
	}
344
345
	/**
346
	 * @generated
347
	 */
348
	private void performDirectEdit(char initialCharacter) {
349
		if (getManager() instanceof TextDirectEditManager) {
350
			((TextDirectEditManager) getManager()).show(initialCharacter);
351
		} else {
352
			performDirectEdit();
353
		}
354
	}
355
356
	/**
357
	 * @generated
358
	 */
359
	protected void performDirectEditRequest(Request request) {
360
		final Request theRequest = request;
361
		try {
362
			getEditingDomain().runExclusive(new Runnable() {
363
364
				public void run() {
365
					if (isActive() && isEditable()) {
366
						if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) {
367
							Character initialChar = (Character) theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR);
368
							performDirectEdit(initialChar.charValue());
369
						} else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) {
370
							DirectEditRequest editRequest = (DirectEditRequest) theRequest;
371
							performDirectEdit(editRequest.getLocation());
372
						} else {
373
							performDirectEdit();
374
						}
375
					}
376
				}
377
			});
378
		} catch (InterruptedException e) {
379
			e.printStackTrace();
380
		}
381
	}
382
383
	/**
384
	 * @generated
385
	 */
386
	protected void refreshVisuals() {
387
		super.refreshVisuals();
388
		refreshLabel();
389
		refreshFont();
390
		refreshFontColor();
391
		refreshUnderline();
392
		refreshStrikeThrough();
393
	}
394
395
	/**
396
	 * @generated
397
	 */
398
	protected void refreshLabel() {
399
		setLabelTextHelper(getFigure(), getLabelText());
400
		setLabelIconHelper(getFigure(), getLabelIcon());
401
		Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
402
		if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) {
403
			((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback();
404
		}
405
	}
406
407
	/**
408
	 * @generated
409
	 */
410
	protected void refreshUnderline() {
411
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
412
		if (style != null && getFigure() instanceof WrapLabel) {
413
			((WrapLabel) getFigure()).setTextUnderline(style.isUnderline());
414
		}
415
	}
416
417
	/**
418
	 * @generated
419
	 */
420
	protected void refreshStrikeThrough() {
421
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
422
		if (style != null && getFigure() instanceof WrapLabel) {
423
			((WrapLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough());
424
		}
425
	}
426
427
	/**
428
	 * @generated
429
	 */
430
	protected void refreshFont() {
431
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
432
		if (style != null) {
433
			FontData fontData = new FontData(style.getFontName(), style.getFontHeight(), (style.isBold() ? SWT.BOLD : SWT.NORMAL) | (style.isItalic() ? SWT.ITALIC : SWT.NORMAL));
434
			setFont(fontData);
435
		}
436
	}
437
438
	/**
439
	 * @generated
440
	 */
441
	protected void setFontColor(Color color) {
442
		getFigure().setForegroundColor(color);
443
	}
444
445
	/**
446
	 * @generated
447
	 */
448
	protected void addSemanticListeners() {
449
		if (getParser() instanceof ISemanticParser) {
450
			EObject element = resolveSemanticElement();
451
			parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element);
452
			for (int i = 0; i < parserElements.size(); i++) {
453
				addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$
454
			}
455
		} else {
456
			super.addSemanticListeners();
457
		}
458
	}
459
460
	/**
461
	 * @generated
462
	 */
463
	protected void removeSemanticListeners() {
464
		if (parserElements != null) {
465
			for (int i = 0; i < parserElements.size(); i++) {
466
				removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$
467
			}
468
		} else {
469
			super.removeSemanticListeners();
470
		}
471
	}
472
473
	/**
474
	 * @generated
475
	 */
476
	protected AccessibleEditPart getAccessibleEditPart() {
477
		if (accessibleEP == null) {
478
			accessibleEP = new AccessibleGraphicalEditPart() {
479
480
				public void getName(AccessibleEvent e) {
481
					e.result = getLabelTextHelper(getFigure());
482
				}
483
			};
484
		}
485
		return accessibleEP;
486
	}
487
488
	/**
489
	 * @generated
490
	 */
491
	private View getFontStyleOwnerView() {
492
		return getPrimaryView();
493
	}
494
495
	/**
496
	 * @generated
497
	 */
498
	protected void addNotationalListeners() {
499
		super.addNotationalListeners();
500
		addListenerFilter("PrimaryView", this, getPrimaryView()); //$NON-NLS-1$
501
	}
502
503
	/**
504
	 * @generated
505
	 */
506
	protected void removeNotationalListeners() {
507
		super.removeNotationalListeners();
508
		removeListenerFilter("PrimaryView"); //$NON-NLS-1$
509
	}
510
511
	/**
512
	 * @generated
513
	 */
514
	protected void handleNotificationEvent(Notification event) {
515
		Object feature = event.getFeature();
516
		if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) {
517
			Integer c = (Integer) event.getNewValue();
518
			setFontColor(DiagramColorRegistry.getInstance().getColor(c));
519
		} else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) {
520
			refreshUnderline();
521
		} else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) {
522
			refreshStrikeThrough();
523
		} else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature)
524
				|| NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) {
525
			refreshFont();
526
		} else {
527
			if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) {
528
				refreshLabel();
529
			}
530
			if (getParser() instanceof ISemanticParser) {
531
				ISemanticParser modelParser = (ISemanticParser) getParser();
532
				if (modelParser.areSemanticElementsAffected(null, event)) {
533
					removeSemanticListeners();
534
					if (resolveSemanticElement() != null) {
535
						addSemanticListeners();
536
					}
537
					refreshLabel();
538
				}
539
			}
540
		}
541
		super.handleNotificationEvent(event);
542
	}
543
544
	/**
545
	 * @generated
546
	 */
547
	protected IFigure createFigure() {
548
		// Parent should assign one using setLabel method
549
		return null;
550
	}
551
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/parts/DependencyNameEditPart.java (+530 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.parts;
2
3
import java.util.Collections;
4
import java.util.List;
5
6
import org.eclipse.draw2d.IFigure;
7
import org.eclipse.draw2d.Label;
8
import org.eclipse.draw2d.geometry.Point;
9
import org.eclipse.emf.common.notify.Notification;
10
import org.eclipse.emf.ecore.EObject;
11
import org.eclipse.emf.transaction.RunnableWithResult;
12
import org.eclipse.gef.AccessibleEditPart;
13
import org.eclipse.gef.EditPolicy;
14
import org.eclipse.gef.Request;
15
import org.eclipse.gef.requests.DirectEditRequest;
16
import org.eclipse.gef.tools.DirectEditManager;
17
import org.eclipse.gmf.runtime.common.ui.services.parser.IParser;
18
import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus;
19
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserEditStatus;
20
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions;
21
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserService;
22
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
23
import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart;
24
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy;
25
import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry;
26
import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants;
27
import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager;
28
import org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel;
29
import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
30
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
31
import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser;
32
import org.eclipse.gmf.runtime.emf.ui.services.parser.ParserHintAdapter;
33
import org.eclipse.gmf.runtime.notation.FontStyle;
34
import org.eclipse.gmf.runtime.notation.NotationPackage;
35
import org.eclipse.gmf.runtime.notation.View;
36
import org.eclipse.jface.resource.ImageDescriptor;
37
import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
38
import org.eclipse.jface.viewers.ICellEditorValidator;
39
import org.eclipse.swt.SWT;
40
import org.eclipse.swt.accessibility.AccessibleEvent;
41
import org.eclipse.swt.graphics.Color;
42
import org.eclipse.swt.graphics.FontData;
43
import org.eclipse.swt.graphics.Image;
44
import org.eclipse.uml2.diagram.clazz.edit.policies.UMLTextSelectionEditPolicy;
45
import org.eclipse.uml2.diagram.clazz.part.UMLDiagramEditorPlugin;
46
import org.eclipse.uml2.diagram.clazz.part.UMLVisualIDRegistry;
47
import org.eclipse.uml2.diagram.clazz.providers.UMLElementTypes;
48
49
/**
50
 * @generated
51
 */
52
public class DependencyNameEditPart extends UMLExtNodeLabelEditPart implements ITextAwareEditPart {
53
54
	/**
55
	 * @generated
56
	 */
57
	public static final int VISUAL_ID = 5011;
58
59
	/**
60
	 * @generated
61
	 */
62
	private DirectEditManager manager;
63
64
	/**
65
	 * @generated
66
	 */
67
	private IParser parser;
68
69
	/**
70
	 * @generated
71
	 */
72
	private List parserElements;
73
74
	/**
75
	 * @generated
76
	 */
77
	private String defaultText;
78
79
	/**
80
	 * @generated
81
	 */
82
	static {
83
		registerSnapBackPosition(UMLVisualIDRegistry.getType(DependencyNameEditPart.VISUAL_ID), new Point(0, 0));
84
	}
85
86
	/**
87
	 * @generated
88
	 */
89
	public DependencyNameEditPart(View view) {
90
		super(view);
91
	}
92
93
	/**
94
	 * @generated
95
	 */
96
	protected void createDefaultEditPolicies() {
97
		super.createDefaultEditPolicies();
98
		installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy());
99
100
	}
101
102
	/**
103
	 * @generated
104
	 */
105
	protected String getLabelTextHelper(IFigure figure) {
106
		if (figure instanceof WrapLabel) {
107
			return ((WrapLabel) figure).getText();
108
		} else {
109
			return ((Label) figure).getText();
110
		}
111
	}
112
113
	/**
114
	 * @generated
115
	 */
116
	protected void setLabelTextHelper(IFigure figure, String text) {
117
		if (figure instanceof WrapLabel) {
118
			((WrapLabel) figure).setText(text);
119
		} else {
120
			((Label) figure).setText(text);
121
		}
122
	}
123
124
	/**
125
	 * @generated
126
	 */
127
	protected Image getLabelIconHelper(IFigure figure) {
128
		if (figure instanceof WrapLabel) {
129
			return ((WrapLabel) figure).getIcon();
130
		} else {
131
			return ((Label) figure).getIcon();
132
		}
133
	}
134
135
	/**
136
	 * @generated
137
	 */
138
	protected void setLabelIconHelper(IFigure figure, Image icon) {
139
		if (figure instanceof WrapLabel) {
140
			((WrapLabel) figure).setIcon(icon);
141
		} else {
142
			((Label) figure).setIcon(icon);
143
		}
144
	}
145
146
	/**
147
	 * @generated
148
	 */
149
	public void setLabel(IFigure figure) {
150
		unregisterVisuals();
151
		setFigure(figure);
152
		defaultText = getLabelTextHelper(figure);
153
		registerVisuals();
154
		refreshVisuals();
155
	}
156
157
	/**
158
	 * @generated
159
	 */
160
	protected List getModelChildren() {
161
		return Collections.EMPTY_LIST;
162
	}
163
164
	/**
165
	 * @generated
166
	 */
167
	public IGraphicalEditPart getChildBySemanticHint(String semanticHint) {
168
		return null;
169
	}
170
171
	/**
172
	 * @generated
173
	 */
174
	protected EObject getParserElement() {
175
		EObject element = resolveSemanticElement();
176
		return element != null ? element : (View) getModel();
177
	}
178
179
	/**
180
	 * @generated
181
	 */
182
	protected Image getLabelIcon() {
183
		EObject parserElement = getParserElement();
184
		if (parserElement == null) {
185
			return null;
186
		}
187
		return UMLElementTypes.getImage(parserElement.eClass());
188
	}
189
190
	/**
191
	 * @generated
192
	 */
193
	protected String getLabelText() {
194
		String text = null;
195
		if (getParser() != null) {
196
			text = getParser().getPrintString(new EObjectAdapter(getParserElement()), getParserOptions().intValue());
197
		}
198
		if (text == null || text.length() == 0) {
199
			text = defaultText;
200
		}
201
		return text;
202
	}
203
204
	/**
205
	 * @generated
206
	 */
207
	public void setLabelText(String text) {
208
		setLabelTextHelper(getFigure(), text);
209
		Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
210
		if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) {
211
			((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback();
212
		}
213
	}
214
215
	/**
216
	 * @generated
217
	 */
218
	public String getEditText() {
219
		if (getParser() == null) {
220
			return ""; //$NON-NLS-1$
221
		}
222
		return getParser().getEditString(new EObjectAdapter(getParserElement()), getParserOptions().intValue());
223
	}
224
225
	/**
226
	 * @generated
227
	 */
228
	protected boolean isEditable() {
229
		return getEditText() != null;
230
	}
231
232
	/**
233
	 * @generated
234
	 */
235
	public ICellEditorValidator getEditTextValidator() {
236
		return new ICellEditorValidator() {
237
238
			public String isValid(final Object value) {
239
				if (value instanceof String) {
240
					final EObject element = getParserElement();
241
					final IParser parser = getParser();
242
					try {
243
						IParserEditStatus valid = (IParserEditStatus) getEditingDomain().runExclusive(new RunnableWithResult.Impl() {
244
245
							public void run() {
246
								setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value));
247
							}
248
						});
249
						return valid.getCode() == ParserEditStatus.EDITABLE ? null : valid.getMessage();
250
					} catch (InterruptedException ie) {
251
						ie.printStackTrace();
252
					}
253
				}
254
255
				// shouldn't get here
256
				return null;
257
			}
258
		};
259
	}
260
261
	/**
262
	 * @generated
263
	 */
264
	public IContentAssistProcessor getCompletionProcessor() {
265
		if (getParser() == null) {
266
			return null;
267
		}
268
		return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement()));
269
	}
270
271
	/**
272
	 * @generated
273
	 */
274
	public ParserOptions getParserOptions() {
275
		return ParserOptions.NONE;
276
	}
277
278
	/**
279
	 * @generated
280
	 */
281
	public IParser getParser() {
282
		if (parser == null) {
283
			String parserHint = ((View) getModel()).getType();
284
			ParserHintAdapter hintAdapter = new ParserHintAdapter(getParserElement(), parserHint) {
285
286
				public Object getAdapter(Class adapter) {
287
					if (IElementType.class.equals(adapter)) {
288
						return UMLElementTypes.Dependency_2009;
289
					}
290
					return super.getAdapter(adapter);
291
				}
292
			};
293
			parser = ParserService.getInstance().getParser(hintAdapter);
294
		}
295
		return parser;
296
	}
297
298
	/**
299
	 * @generated
300
	 */
301
	protected DirectEditManager getManager() {
302
		if (manager == null) {
303
			setManager(new TextDirectEditManager(this, TextDirectEditManager.getTextCellEditorClass(this), UMLEditPartFactory.getTextCellEditorLocator(this)));
304
		}
305
		return manager;
306
	}
307
308
	/**
309
	 * @generated
310
	 */
311
	protected void setManager(DirectEditManager manager) {
312
		this.manager = manager;
313
	}
314
315
	/**
316
	 * @generated
317
	 */
318
	protected void performDirectEdit() {
319
		getManager().show();
320
	}
321
322
	/**
323
	 * @generated
324
	 */
325
	protected void performDirectEdit(Point eventLocation) {
326
		if (getManager().getClass() == TextDirectEditManager.class) {
327
			((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint());
328
		}
329
	}
330
331
	/**
332
	 * @generated
333
	 */
334
	private void performDirectEdit(char initialCharacter) {
335
		if (getManager() instanceof TextDirectEditManager) {
336
			((TextDirectEditManager) getManager()).show(initialCharacter);
337
		} else {
338
			performDirectEdit();
339
		}
340
	}
341
342
	/**
343
	 * @generated
344
	 */
345
	protected void performDirectEditRequest(Request request) {
346
		final Request theRequest = request;
347
		try {
348
			getEditingDomain().runExclusive(new Runnable() {
349
350
				public void run() {
351
					if (isActive() && isEditable()) {
352
						if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) {
353
							Character initialChar = (Character) theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR);
354
							performDirectEdit(initialChar.charValue());
355
						} else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) {
356
							DirectEditRequest editRequest = (DirectEditRequest) theRequest;
357
							performDirectEdit(editRequest.getLocation());
358
						} else {
359
							performDirectEdit();
360
						}
361
					}
362
				}
363
			});
364
		} catch (InterruptedException e) {
365
			e.printStackTrace();
366
		}
367
	}
368
369
	/**
370
	 * @generated
371
	 */
372
	protected void refreshVisuals() {
373
		super.refreshVisuals();
374
		refreshLabel();
375
		refreshFont();
376
		refreshFontColor();
377
		refreshUnderline();
378
		refreshStrikeThrough();
379
	}
380
381
	/**
382
	 * @generated
383
	 */
384
	protected void refreshLabel() {
385
		setLabelTextHelper(getFigure(), getLabelText());
386
		setLabelIconHelper(getFigure(), getLabelIcon());
387
		Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
388
		if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) {
389
			((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback();
390
		}
391
	}
392
393
	/**
394
	 * @generated
395
	 */
396
	protected void refreshUnderline() {
397
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
398
		if (style != null && getFigure() instanceof WrapLabel) {
399
			((WrapLabel) getFigure()).setTextUnderline(style.isUnderline());
400
		}
401
	}
402
403
	/**
404
	 * @generated
405
	 */
406
	protected void refreshStrikeThrough() {
407
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
408
		if (style != null && getFigure() instanceof WrapLabel) {
409
			((WrapLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough());
410
		}
411
	}
412
413
	/**
414
	 * @generated
415
	 */
416
	protected void refreshFont() {
417
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
418
		if (style != null) {
419
			FontData fontData = new FontData(style.getFontName(), style.getFontHeight(), (style.isBold() ? SWT.BOLD : SWT.NORMAL) | (style.isItalic() ? SWT.ITALIC : SWT.NORMAL));
420
			setFont(fontData);
421
		}
422
	}
423
424
	/**
425
	 * @generated
426
	 */
427
	protected void setFontColor(Color color) {
428
		getFigure().setForegroundColor(color);
429
	}
430
431
	/**
432
	 * @generated
433
	 */
434
	protected void addSemanticListeners() {
435
		if (getParser() instanceof ISemanticParser) {
436
			EObject element = resolveSemanticElement();
437
			parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element);
438
			for (int i = 0; i < parserElements.size(); i++) {
439
				addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$
440
			}
441
		} else {
442
			super.addSemanticListeners();
443
		}
444
	}
445
446
	/**
447
	 * @generated
448
	 */
449
	protected void removeSemanticListeners() {
450
		if (parserElements != null) {
451
			for (int i = 0; i < parserElements.size(); i++) {
452
				removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$
453
			}
454
		} else {
455
			super.removeSemanticListeners();
456
		}
457
	}
458
459
	/**
460
	 * @generated
461
	 */
462
	protected AccessibleEditPart getAccessibleEditPart() {
463
		if (accessibleEP == null) {
464
			accessibleEP = new AccessibleGraphicalEditPart() {
465
466
				public void getName(AccessibleEvent e) {
467
					e.result = getLabelTextHelper(getFigure());
468
				}
469
			};
470
		}
471
		return accessibleEP;
472
	}
473
474
	/**
475
	 * @generated
476
	 */
477
	private View getFontStyleOwnerView() {
478
		return getPrimaryView();
479
	}
480
481
	/**
482
	 * @generated
483
	 */
484
	protected void handleNotificationEvent(Notification event) {
485
		Object feature = event.getFeature();
486
		if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) {
487
			Integer c = (Integer) event.getNewValue();
488
			setFontColor(DiagramColorRegistry.getInstance().getColor(c));
489
		} else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) {
490
			refreshUnderline();
491
		} else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) {
492
			refreshStrikeThrough();
493
		} else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature)
494
				|| NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) {
495
			refreshFont();
496
		} else {
497
			if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) {
498
				refreshLabel();
499
			}
500
			if (getParser() instanceof ISemanticParser) {
501
				ISemanticParser modelParser = (ISemanticParser) getParser();
502
				if (modelParser.areSemanticElementsAffected(null, event)) {
503
					removeSemanticListeners();
504
					if (resolveSemanticElement() != null) {
505
						addSemanticListeners();
506
					}
507
					refreshLabel();
508
				}
509
			}
510
		}
511
		super.handleNotificationEvent(event);
512
	}
513
514
	/**
515
	 * @generated
516
	 */
517
	protected IFigure createFigure() {
518
		IFigure label = createFigurePrim();
519
		defaultText = getLabelTextHelper(label);
520
		return label;
521
	}
522
523
	/**
524
	 * @generated
525
	 */
526
	protected IFigure createFigurePrim() {
527
		return new WrapLabel();
528
	}
529
530
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/parts/Operation3EditPart.java (+553 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.parts;
2
3
import java.util.Collections;
4
import java.util.List;
5
6
import org.eclipse.draw2d.IFigure;
7
import org.eclipse.draw2d.Label;
8
import org.eclipse.draw2d.geometry.Point;
9
import org.eclipse.emf.common.notify.Notification;
10
import org.eclipse.emf.ecore.EObject;
11
import org.eclipse.emf.transaction.RunnableWithResult;
12
import org.eclipse.gef.AccessibleEditPart;
13
import org.eclipse.gef.DragTracker;
14
import org.eclipse.gef.EditPolicy;
15
import org.eclipse.gef.Request;
16
import org.eclipse.gef.requests.DirectEditRequest;
17
import org.eclipse.gef.requests.SelectionRequest;
18
import org.eclipse.gef.tools.DirectEditManager;
19
import org.eclipse.gmf.runtime.common.ui.services.parser.IParser;
20
import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus;
21
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserEditStatus;
22
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions;
23
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserService;
24
import org.eclipse.gmf.runtime.diagram.ui.editparts.CompartmentEditPart;
25
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
26
import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart;
27
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
28
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy;
29
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.ListItemComponentEditPolicy;
30
import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry;
31
import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants;
32
import org.eclipse.gmf.runtime.diagram.ui.tools.DragEditPartsTrackerEx;
33
import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager;
34
import org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel;
35
import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
36
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
37
import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser;
38
import org.eclipse.gmf.runtime.emf.ui.services.parser.ParserHintAdapter;
39
import org.eclipse.gmf.runtime.notation.FontStyle;
40
import org.eclipse.gmf.runtime.notation.NotationPackage;
41
import org.eclipse.gmf.runtime.notation.View;
42
import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
43
import org.eclipse.jface.viewers.ICellEditorValidator;
44
import org.eclipse.swt.SWT;
45
import org.eclipse.swt.accessibility.AccessibleEvent;
46
import org.eclipse.swt.graphics.Color;
47
import org.eclipse.swt.graphics.FontData;
48
import org.eclipse.swt.graphics.Image;
49
import org.eclipse.uml2.diagram.clazz.edit.policies.Operation3ItemSemanticEditPolicy;
50
import org.eclipse.uml2.diagram.clazz.edit.policies.UMLTextNonResizableEditPolicy;
51
import org.eclipse.uml2.diagram.clazz.edit.policies.UMLTextSelectionEditPolicy;
52
import org.eclipse.uml2.diagram.clazz.providers.UMLElementTypes;
53
54
/**
55
 * @generated
56
 */
57
public class Operation3EditPart extends CompartmentEditPart implements ITextAwareEditPart {
58
59
	/**
60
	 * @generated
61
	 */
62
	public static final int VISUAL_ID = 3015;
63
64
	/**
65
	 * @generated
66
	 */
67
	private DirectEditManager manager;
68
69
	/**
70
	 * @generated
71
	 */
72
	private IParser parser;
73
74
	/**
75
	 * @generated
76
	 */
77
	private List parserElements;
78
79
	/**
80
	 * @generated
81
	 */
82
	private String defaultText;
83
84
	/**
85
	 * @generated
86
	 */
87
	public Operation3EditPart(View view) {
88
		super(view);
89
	}
90
91
	/**
92
	 * @generated
93
	 */
94
	public DragTracker getDragTracker(Request request) {
95
		if (request instanceof SelectionRequest && ((SelectionRequest) request).getLastButtonPressed() == 3) {
96
			return null;
97
		}
98
		return new DragEditPartsTrackerEx(this);
99
	}
100
101
	/**
102
	 * @generated
103
	 */
104
	protected void createDefaultEditPolicies() {
105
		super.createDefaultEditPolicies();
106
		installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new Operation3ItemSemanticEditPolicy());
107
		installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new UMLTextNonResizableEditPolicy());
108
		installEditPolicy(EditPolicy.COMPONENT_ROLE, new ListItemComponentEditPolicy());
109
		installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy());
110
111
	}
112
113
	/**
114
	 * @generated
115
	 */
116
	protected String getLabelTextHelper(IFigure figure) {
117
		if (figure instanceof WrapLabel) {
118
			return ((WrapLabel) figure).getText();
119
		} else {
120
			return ((Label) figure).getText();
121
		}
122
	}
123
124
	/**
125
	 * @generated
126
	 */
127
	protected void setLabelTextHelper(IFigure figure, String text) {
128
		if (figure instanceof WrapLabel) {
129
			((WrapLabel) figure).setText(text);
130
		} else {
131
			((Label) figure).setText(text);
132
		}
133
	}
134
135
	/**
136
	 * @generated
137
	 */
138
	protected Image getLabelIconHelper(IFigure figure) {
139
		if (figure instanceof WrapLabel) {
140
			return ((WrapLabel) figure).getIcon();
141
		} else {
142
			return ((Label) figure).getIcon();
143
		}
144
	}
145
146
	/**
147
	 * @generated
148
	 */
149
	protected void setLabelIconHelper(IFigure figure, Image icon) {
150
		if (figure instanceof WrapLabel) {
151
			((WrapLabel) figure).setIcon(icon);
152
		} else {
153
			((Label) figure).setIcon(icon);
154
		}
155
	}
156
157
	/**
158
	 * @generated
159
	 */
160
	public void setLabel(IFigure figure) {
161
		unregisterVisuals();
162
		setFigure(figure);
163
		defaultText = getLabelTextHelper(figure);
164
		registerVisuals();
165
		refreshVisuals();
166
	}
167
168
	/**
169
	 * @generated
170
	 */
171
	protected List getModelChildren() {
172
		return Collections.EMPTY_LIST;
173
	}
174
175
	/**
176
	 * @generated
177
	 */
178
	public IGraphicalEditPart getChildBySemanticHint(String semanticHint) {
179
		return null;
180
	}
181
182
	/**
183
	 * @generated
184
	 */
185
	protected EObject getParserElement() {
186
		EObject element = resolveSemanticElement();
187
		return element != null ? element : (View) getModel();
188
	}
189
190
	/**
191
	 * @generated
192
	 */
193
	protected Image getLabelIcon() {
194
		return null;
195
	}
196
197
	/**
198
	 * @generated
199
	 */
200
	protected String getLabelText() {
201
		String text = null;
202
		if (getParser() != null) {
203
			text = getParser().getPrintString(new EObjectAdapter(getParserElement()), getParserOptions().intValue());
204
		}
205
		if (text == null || text.length() == 0) {
206
			text = defaultText;
207
		}
208
		return text;
209
	}
210
211
	/**
212
	 * @generated
213
	 */
214
	public void setLabelText(String text) {
215
		setLabelTextHelper(getFigure(), text);
216
		Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
217
		if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) {
218
			((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback();
219
		}
220
	}
221
222
	/**
223
	 * @generated
224
	 */
225
	public String getEditText() {
226
		if (getParser() == null) {
227
			return ""; //$NON-NLS-1$
228
		}
229
		return getParser().getEditString(new EObjectAdapter(getParserElement()), getParserOptions().intValue());
230
	}
231
232
	/**
233
	 * @generated
234
	 */
235
	protected boolean isEditable() {
236
		return getEditText() != null;
237
	}
238
239
	/**
240
	 * @generated
241
	 */
242
	public ICellEditorValidator getEditTextValidator() {
243
		return new ICellEditorValidator() {
244
245
			public String isValid(final Object value) {
246
				if (value instanceof String) {
247
					final EObject element = getParserElement();
248
					final IParser parser = getParser();
249
					try {
250
						IParserEditStatus valid = (IParserEditStatus) getEditingDomain().runExclusive(new RunnableWithResult.Impl() {
251
252
							public void run() {
253
								setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value));
254
							}
255
						});
256
						return valid.getCode() == ParserEditStatus.EDITABLE ? null : valid.getMessage();
257
					} catch (InterruptedException ie) {
258
						ie.printStackTrace();
259
					}
260
				}
261
262
				// shouldn't get here
263
				return null;
264
			}
265
		};
266
	}
267
268
	/**
269
	 * @generated
270
	 */
271
	public IContentAssistProcessor getCompletionProcessor() {
272
		if (getParser() == null) {
273
			return null;
274
		}
275
		return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement()));
276
	}
277
278
	/**
279
	 * @generated
280
	 */
281
	public ParserOptions getParserOptions() {
282
		return ParserOptions.NONE;
283
	}
284
285
	/**
286
	 * @generated
287
	 */
288
	public IParser getParser() {
289
		if (parser == null) {
290
			String parserHint = ((View) getModel()).getType();
291
			ParserHintAdapter hintAdapter = new ParserHintAdapter(getParserElement(), parserHint) {
292
293
				public Object getAdapter(Class adapter) {
294
					if (IElementType.class.equals(adapter)) {
295
						return UMLElementTypes.Operation_3015;
296
					}
297
					return super.getAdapter(adapter);
298
				}
299
			};
300
			parser = ParserService.getInstance().getParser(hintAdapter);
301
		}
302
		return parser;
303
	}
304
305
	/**
306
	 * @generated
307
	 */
308
	protected DirectEditManager getManager() {
309
		if (manager == null) {
310
			setManager(new TextDirectEditManager(this, TextDirectEditManager.getTextCellEditorClass(this), UMLEditPartFactory.getTextCellEditorLocator(this)));
311
		}
312
		return manager;
313
	}
314
315
	/**
316
	 * @generated
317
	 */
318
	protected void setManager(DirectEditManager manager) {
319
		this.manager = manager;
320
	}
321
322
	/**
323
	 * @generated
324
	 */
325
	protected void performDirectEdit() {
326
		getManager().show();
327
	}
328
329
	/**
330
	 * @generated
331
	 */
332
	protected void performDirectEdit(Point eventLocation) {
333
		if (getManager().getClass() == TextDirectEditManager.class) {
334
			((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint());
335
		}
336
	}
337
338
	/**
339
	 * @generated
340
	 */
341
	private void performDirectEdit(char initialCharacter) {
342
		if (getManager() instanceof TextDirectEditManager) {
343
			((TextDirectEditManager) getManager()).show(initialCharacter);
344
		} else {
345
			performDirectEdit();
346
		}
347
	}
348
349
	/**
350
	 * @generated
351
	 */
352
	protected void performDirectEditRequest(Request request) {
353
		final Request theRequest = request;
354
		try {
355
			getEditingDomain().runExclusive(new Runnable() {
356
357
				public void run() {
358
					if (isActive() && isEditable()) {
359
						if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) {
360
							Character initialChar = (Character) theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR);
361
							performDirectEdit(initialChar.charValue());
362
						} else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) {
363
							DirectEditRequest editRequest = (DirectEditRequest) theRequest;
364
							performDirectEdit(editRequest.getLocation());
365
						} else {
366
							performDirectEdit();
367
						}
368
					}
369
				}
370
			});
371
		} catch (InterruptedException e) {
372
			e.printStackTrace();
373
		}
374
	}
375
376
	/**
377
	 * @generated
378
	 */
379
	protected void refreshVisuals() {
380
		super.refreshVisuals();
381
		refreshLabel();
382
		refreshFont();
383
		refreshFontColor();
384
		refreshUnderline();
385
		refreshStrikeThrough();
386
	}
387
388
	/**
389
	 * @generated
390
	 */
391
	protected void refreshLabel() {
392
		setLabelTextHelper(getFigure(), getLabelText());
393
		setLabelIconHelper(getFigure(), getLabelIcon());
394
		Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
395
		if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) {
396
			((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback();
397
		}
398
	}
399
400
	/**
401
	 * @generated
402
	 */
403
	protected void refreshUnderline() {
404
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
405
		if (style != null && getFigure() instanceof WrapLabel) {
406
			((WrapLabel) getFigure()).setTextUnderline(style.isUnderline());
407
		}
408
	}
409
410
	/**
411
	 * @generated
412
	 */
413
	protected void refreshStrikeThrough() {
414
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
415
		if (style != null && getFigure() instanceof WrapLabel) {
416
			((WrapLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough());
417
		}
418
	}
419
420
	/**
421
	 * @generated
422
	 */
423
	protected void refreshFont() {
424
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
425
		if (style != null) {
426
			FontData fontData = new FontData(style.getFontName(), style.getFontHeight(), (style.isBold() ? SWT.BOLD : SWT.NORMAL) | (style.isItalic() ? SWT.ITALIC : SWT.NORMAL));
427
			setFont(fontData);
428
		}
429
	}
430
431
	/**
432
	 * @generated
433
	 */
434
	protected void setFontColor(Color color) {
435
		getFigure().setForegroundColor(color);
436
	}
437
438
	/**
439
	 * @generated
440
	 */
441
	protected void addSemanticListeners() {
442
		if (getParser() instanceof ISemanticParser) {
443
			EObject element = resolveSemanticElement();
444
			parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element);
445
			for (int i = 0; i < parserElements.size(); i++) {
446
				addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$
447
			}
448
		} else {
449
			super.addSemanticListeners();
450
		}
451
	}
452
453
	/**
454
	 * @generated
455
	 */
456
	protected void removeSemanticListeners() {
457
		if (parserElements != null) {
458
			for (int i = 0; i < parserElements.size(); i++) {
459
				removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$
460
			}
461
		} else {
462
			super.removeSemanticListeners();
463
		}
464
	}
465
466
	/**
467
	 * @generated
468
	 */
469
	protected AccessibleEditPart getAccessibleEditPart() {
470
		if (accessibleEP == null) {
471
			accessibleEP = new AccessibleGraphicalEditPart() {
472
473
				public void getName(AccessibleEvent e) {
474
					e.result = getLabelTextHelper(getFigure());
475
				}
476
			};
477
		}
478
		return accessibleEP;
479
	}
480
481
	/**
482
	 * @generated
483
	 */
484
	private View getFontStyleOwnerView() {
485
		return getPrimaryView();
486
	}
487
488
	/**
489
	 * @generated
490
	 */
491
	protected void addNotationalListeners() {
492
		super.addNotationalListeners();
493
		addListenerFilter("PrimaryView", this, getPrimaryView()); //$NON-NLS-1$
494
	}
495
496
	/**
497
	 * @generated
498
	 */
499
	protected void removeNotationalListeners() {
500
		super.removeNotationalListeners();
501
		removeListenerFilter("PrimaryView"); //$NON-NLS-1$
502
	}
503
504
	/**
505
	 * @generated
506
	 */
507
	protected void handleNotificationEvent(Notification event) {
508
		Object feature = event.getFeature();
509
		if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) {
510
			Integer c = (Integer) event.getNewValue();
511
			setFontColor(DiagramColorRegistry.getInstance().getColor(c));
512
		} else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) {
513
			refreshUnderline();
514
		} else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) {
515
			refreshStrikeThrough();
516
		} else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature)
517
				|| NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) {
518
			refreshFont();
519
		} else {
520
			if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) {
521
				refreshLabel();
522
			}
523
			if (getParser() instanceof ISemanticParser) {
524
				ISemanticParser modelParser = (ISemanticParser) getParser();
525
				if (modelParser.areSemanticElementsAffected(null, event)) {
526
					removeSemanticListeners();
527
					if (resolveSemanticElement() != null) {
528
						addSemanticListeners();
529
					}
530
					refreshLabel();
531
				}
532
			}
533
		}
534
		super.handleNotificationEvent(event);
535
	}
536
537
	/**
538
	 * @generated
539
	 */
540
	protected IFigure createFigure() {
541
		IFigure label = createFigurePrim();
542
		defaultText = getLabelTextHelper(label);
543
		return label;
544
	}
545
546
	/**
547
	 * @generated
548
	 */
549
	protected IFigure createFigurePrim() {
550
		return new WrapLabel();
551
	}
552
553
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/policies/AssociationClassOperationsCanonicalEditPolicy.java (+51 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.policies;
2
3
import java.util.Iterator;
4
import java.util.LinkedList;
5
import java.util.List;
6
7
import org.eclipse.emf.ecore.EObject;
8
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.CanonicalEditPolicy;
9
import org.eclipse.gmf.runtime.notation.View;
10
import org.eclipse.uml2.diagram.clazz.edit.parts.Operation2EditPart;
11
import org.eclipse.uml2.diagram.clazz.part.UMLVisualIDRegistry;
12
13
/**
14
 * @generated
15
 */
16
public class AssociationClassOperationsCanonicalEditPolicy extends CanonicalEditPolicy {
17
18
	/**
19
	 * @generated
20
	 */
21
	protected List getSemanticChildrenList() {
22
		List result = new LinkedList();
23
		EObject modelObject = ((View) getHost().getModel()).getElement();
24
		View viewObject = (View) getHost().getModel();
25
		EObject nextValue;
26
		int nodeVID;
27
		for (Iterator values = ((org.eclipse.uml2.uml.Class) modelObject).getOwnedOperations().iterator(); values.hasNext();) {
28
			nextValue = (EObject) values.next();
29
			nodeVID = UMLVisualIDRegistry.getNodeVisualID(viewObject, nextValue);
30
			if (Operation2EditPart.VISUAL_ID == nodeVID) {
31
				result.add(nextValue);
32
			}
33
		}
34
		return result;
35
	}
36
37
	/**
38
	 * @generated
39
	 */
40
	protected boolean shouldDeleteView(View view) {
41
		return view.isSetElement() && view.getElement() != null && view.getElement().eIsProxy();
42
	}
43
44
	/**
45
	 * @generated
46
	 */
47
	protected String getDefaultFactoryHint() {
48
		return null;
49
	}
50
51
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/policies/ClassOperationsCanonicalEditPolicy.java (+51 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.policies;
2
3
import java.util.Iterator;
4
import java.util.LinkedList;
5
import java.util.List;
6
7
import org.eclipse.emf.ecore.EObject;
8
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.CanonicalEditPolicy;
9
import org.eclipse.gmf.runtime.notation.View;
10
import org.eclipse.uml2.diagram.clazz.edit.parts.OperationEditPart;
11
import org.eclipse.uml2.diagram.clazz.part.UMLVisualIDRegistry;
12
13
/**
14
 * @generated
15
 */
16
public class ClassOperationsCanonicalEditPolicy extends CanonicalEditPolicy {
17
18
	/**
19
	 * @generated
20
	 */
21
	protected List getSemanticChildrenList() {
22
		List result = new LinkedList();
23
		EObject modelObject = ((View) getHost().getModel()).getElement();
24
		View viewObject = (View) getHost().getModel();
25
		EObject nextValue;
26
		int nodeVID;
27
		for (Iterator values = ((org.eclipse.uml2.uml.Class) modelObject).getOwnedOperations().iterator(); values.hasNext();) {
28
			nextValue = (EObject) values.next();
29
			nodeVID = UMLVisualIDRegistry.getNodeVisualID(viewObject, nextValue);
30
			if (OperationEditPart.VISUAL_ID == nodeVID) {
31
				result.add(nextValue);
32
			}
33
		}
34
		return result;
35
	}
36
37
	/**
38
	 * @generated
39
	 */
40
	protected boolean shouldDeleteView(View view) {
41
		return view.isSetElement() && view.getElement() != null && view.getElement().eIsProxy();
42
	}
43
44
	/**
45
	 * @generated
46
	 */
47
	protected String getDefaultFactoryHint() {
48
		return null;
49
	}
50
51
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/policies/PackageClassifiersItemSemanticEditPolicy.java (+268 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.policies;
2
3
import org.eclipse.emf.ecore.EClass;
4
import org.eclipse.emf.ecore.EObject;
5
import org.eclipse.gef.commands.Command;
6
import org.eclipse.gmf.runtime.emf.type.core.commands.CreateElementCommand;
7
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest;
8
import org.eclipse.gmf.runtime.notation.View;
9
import org.eclipse.uml2.diagram.clazz.providers.UMLElementTypes;
10
import org.eclipse.uml2.uml.AssociationClass;
11
import org.eclipse.uml2.uml.DataType;
12
import org.eclipse.uml2.uml.Enumeration;
13
import org.eclipse.uml2.uml.PrimitiveType;
14
import org.eclipse.uml2.uml.UMLPackage;
15
16
/**
17
 * @generated
18
 */
19
public class PackageClassifiersItemSemanticEditPolicy extends UMLBaseItemSemanticEditPolicy {
20
21
	/**
22
	 * @generated
23
	 */
24
	protected Command getCreateCommand(CreateElementRequest req) {
25
		if (UMLElementTypes.Class_3007 == req.getElementType()) {
26
			if (req.getContainmentFeature() == null) {
27
				req.setContainmentFeature(UMLPackage.eINSTANCE.getPackage_PackagedElement());
28
			}
29
			return getMSLWrapper(new CreateClass_3007Command(req));
30
		}
31
		if (UMLElementTypes.DataType_3008 == req.getElementType()) {
32
			if (req.getContainmentFeature() == null) {
33
				req.setContainmentFeature(UMLPackage.eINSTANCE.getPackage_PackagedElement());
34
			}
35
			return getMSLWrapper(new CreateDataType_3008Command(req));
36
		}
37
		if (UMLElementTypes.PrimitiveType_3009 == req.getElementType()) {
38
			if (req.getContainmentFeature() == null) {
39
				req.setContainmentFeature(UMLPackage.eINSTANCE.getPackage_PackagedElement());
40
			}
41
			return getMSLWrapper(new CreatePrimitiveType_3009Command(req));
42
		}
43
		if (UMLElementTypes.Enumeration_3011 == req.getElementType()) {
44
			if (req.getContainmentFeature() == null) {
45
				req.setContainmentFeature(UMLPackage.eINSTANCE.getPackage_PackagedElement());
46
			}
47
			return getMSLWrapper(new CreateEnumeration_3011Command(req));
48
		}
49
		if (UMLElementTypes.AssociationClass_3012 == req.getElementType()) {
50
			if (req.getContainmentFeature() == null) {
51
				req.setContainmentFeature(UMLPackage.eINSTANCE.getPackage_PackagedElement());
52
			}
53
			return getMSLWrapper(new CreateAssociationClass_3012Command(req));
54
		}
55
		return super.getCreateCommand(req);
56
	}
57
58
	/**
59
	 * @generated
60
	 */
61
	private static class CreateClass_3007Command extends CreateElementCommand {
62
63
		/**
64
		 * @generated
65
		 */
66
		public CreateClass_3007Command(CreateElementRequest req) {
67
			super(req);
68
		}
69
70
		/**
71
		 * @generated
72
		 */
73
		protected EClass getEClassToEdit() {
74
			return UMLPackage.eINSTANCE.getPackage();
75
		};
76
77
		/**
78
		 * @generated
79
		 */
80
		protected EObject getElementToEdit() {
81
			EObject container = ((CreateElementRequest) getRequest()).getContainer();
82
			if (container instanceof View) {
83
				container = ((View) container).getElement();
84
			}
85
			return container;
86
		}
87
88
		/**
89
		 * @generated
90
		 */
91
		protected EObject doDefaultElementCreation() {
92
			org.eclipse.uml2.uml.Class newElement = (org.eclipse.uml2.uml.Class) super.doDefaultElementCreation();
93
			if (newElement != null) {
94
				UMLElementTypes.Initializers.Class_3007.init(newElement);
95
			}
96
			return newElement;
97
		}
98
	}
99
100
	/**
101
	 * @generated
102
	 */
103
	private static class CreateDataType_3008Command extends CreateElementCommand {
104
105
		/**
106
		 * @generated
107
		 */
108
		public CreateDataType_3008Command(CreateElementRequest req) {
109
			super(req);
110
		}
111
112
		/**
113
		 * @generated
114
		 */
115
		protected EClass getEClassToEdit() {
116
			return UMLPackage.eINSTANCE.getPackage();
117
		};
118
119
		/**
120
		 * @generated
121
		 */
122
		protected EObject getElementToEdit() {
123
			EObject container = ((CreateElementRequest) getRequest()).getContainer();
124
			if (container instanceof View) {
125
				container = ((View) container).getElement();
126
			}
127
			return container;
128
		}
129
130
		/**
131
		 * @generated
132
		 */
133
		protected EObject doDefaultElementCreation() {
134
			DataType newElement = (DataType) super.doDefaultElementCreation();
135
			if (newElement != null) {
136
				UMLElementTypes.Initializers.DataType_3008.init(newElement);
137
			}
138
			return newElement;
139
		}
140
	}
141
142
	/**
143
	 * @generated
144
	 */
145
	private static class CreatePrimitiveType_3009Command extends CreateElementCommand {
146
147
		/**
148
		 * @generated
149
		 */
150
		public CreatePrimitiveType_3009Command(CreateElementRequest req) {
151
			super(req);
152
		}
153
154
		/**
155
		 * @generated
156
		 */
157
		protected EClass getEClassToEdit() {
158
			return UMLPackage.eINSTANCE.getPackage();
159
		};
160
161
		/**
162
		 * @generated
163
		 */
164
		protected EObject getElementToEdit() {
165
			EObject container = ((CreateElementRequest) getRequest()).getContainer();
166
			if (container instanceof View) {
167
				container = ((View) container).getElement();
168
			}
169
			return container;
170
		}
171
172
		/**
173
		 * @generated
174
		 */
175
		protected EObject doDefaultElementCreation() {
176
			PrimitiveType newElement = (PrimitiveType) super.doDefaultElementCreation();
177
			if (newElement != null) {
178
				UMLElementTypes.Initializers.PrimitiveType_3009.init(newElement);
179
			}
180
			return newElement;
181
		}
182
	}
183
184
	/**
185
	 * @generated
186
	 */
187
	private static class CreateEnumeration_3011Command extends CreateElementCommand {
188
189
		/**
190
		 * @generated
191
		 */
192
		public CreateEnumeration_3011Command(CreateElementRequest req) {
193
			super(req);
194
		}
195
196
		/**
197
		 * @generated
198
		 */
199
		protected EClass getEClassToEdit() {
200
			return UMLPackage.eINSTANCE.getPackage();
201
		};
202
203
		/**
204
		 * @generated
205
		 */
206
		protected EObject getElementToEdit() {
207
			EObject container = ((CreateElementRequest) getRequest()).getContainer();
208
			if (container instanceof View) {
209
				container = ((View) container).getElement();
210
			}
211
			return container;
212
		}
213
214
		/**
215
		 * @generated
216
		 */
217
		protected EObject doDefaultElementCreation() {
218
			Enumeration newElement = (Enumeration) super.doDefaultElementCreation();
219
			if (newElement != null) {
220
				UMLElementTypes.Initializers.Enumeration_3011.init(newElement);
221
			}
222
			return newElement;
223
		}
224
	}
225
226
	/**
227
	 * @generated
228
	 */
229
	private static class CreateAssociationClass_3012Command extends CreateElementCommand {
230
231
		/**
232
		 * @generated
233
		 */
234
		public CreateAssociationClass_3012Command(CreateElementRequest req) {
235
			super(req);
236
		}
237
238
		/**
239
		 * @generated
240
		 */
241
		protected EClass getEClassToEdit() {
242
			return UMLPackage.eINSTANCE.getPackage();
243
		};
244
245
		/**
246
		 * @generated
247
		 */
248
		protected EObject getElementToEdit() {
249
			EObject container = ((CreateElementRequest) getRequest()).getContainer();
250
			if (container instanceof View) {
251
				container = ((View) container).getElement();
252
			}
253
			return container;
254
		}
255
256
		/**
257
		 * @generated
258
		 */
259
		protected EObject doDefaultElementCreation() {
260
			AssociationClass newElement = (AssociationClass) super.doDefaultElementCreation();
261
			if (newElement != null) {
262
				UMLElementTypes.Initializers.AssociationClass_3012.init(newElement);
263
			}
264
			return newElement;
265
		}
266
	}
267
268
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/policies/InterfaceItemSemanticEditPolicy.java (+522 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.policies;
2
3
import org.eclipse.emf.ecore.EAnnotation;
4
import org.eclipse.emf.ecore.EClass;
5
import org.eclipse.emf.ecore.EObject;
6
import org.eclipse.gef.commands.Command;
7
import org.eclipse.gef.commands.UnexecutableCommand;
8
import org.eclipse.gmf.runtime.emf.type.core.commands.CreateRelationshipCommand;
9
import org.eclipse.gmf.runtime.emf.type.core.commands.DestroyElementCommand;
10
import org.eclipse.gmf.runtime.emf.type.core.commands.SetValueCommand;
11
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest;
12
import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest;
13
import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest;
14
import org.eclipse.gmf.runtime.notation.View;
15
import org.eclipse.uml2.diagram.clazz.providers.UMLElementTypes;
16
import org.eclipse.uml2.uml.Association;
17
import org.eclipse.uml2.uml.BehavioredClassifier;
18
import org.eclipse.uml2.uml.Classifier;
19
import org.eclipse.uml2.uml.Constraint;
20
import org.eclipse.uml2.uml.Dependency;
21
import org.eclipse.uml2.uml.Generalization;
22
import org.eclipse.uml2.uml.Interface;
23
import org.eclipse.uml2.uml.InterfaceRealization;
24
import org.eclipse.uml2.uml.NamedElement;
25
import org.eclipse.uml2.uml.Property;
26
import org.eclipse.uml2.uml.Type;
27
import org.eclipse.uml2.uml.UMLPackage;
28
import org.eclipse.uml2.uml.Usage;
29
30
/**
31
 * @generated
32
 */
33
public class InterfaceItemSemanticEditPolicy extends UMLBaseItemSemanticEditPolicy {
34
35
	/**
36
	 * @generated
37
	 */
38
	protected Command getDestroyElementCommand(DestroyElementRequest req) {
39
		return getMSLWrapper(new DestroyElementCommand(req) {
40
41
			protected EObject getElementToDestroy() {
42
				View view = (View) getHost().getModel();
43
				EAnnotation annotation = view.getEAnnotation("Shortcut"); //$NON-NLS-1$
44
				if (annotation != null) {
45
					return view;
46
				}
47
				return super.getElementToDestroy();
48
			}
49
50
		});
51
	}
52
53
	/**
54
	 * @generated
55
	 */
56
	protected Command getCreateRelationshipCommand(CreateRelationshipRequest req) {
57
		if (UMLElementTypes.Generalization_4001 == req.getElementType()) {
58
			return req.getTarget() == null ? getCreateStartOutgoingGeneralization4001Command(req) : getCreateCompleteIncomingGeneralization4001Command(req);
59
		}
60
		if (UMLElementTypes.Dependency_4002 == req.getElementType()) {
61
			return req.getTarget() == null ? getCreateStartOutgoingDependency4002Command(req) : getCreateCompleteIncomingDependency4002Command(req);
62
		}
63
		if (UMLElementTypes.Property_4003 == req.getElementType()) {
64
			return req.getTarget() == null ? null : getCreateCompleteIncomingProperty4003Command(req);
65
		}
66
		if (UMLElementTypes.ConstraintConstrainedElement_4004 == req.getElementType()) {
67
			return req.getTarget() == null ? null : getCreateCompleteIncomingConstraint_ConstrainedElement4004Command(req);
68
		}
69
		if (UMLElementTypes.Association_4005 == req.getElementType()) {
70
			return req.getTarget() == null ? getCreateStartOutgoingAssociation4005Command(req) : getCreateCompleteIncomingAssociation4005Command(req);
71
		}
72
		if (UMLElementTypes.DependencySupplier_4006 == req.getElementType()) {
73
			return req.getTarget() == null ? null : getCreateCompleteIncomingDependency_Supplier4006Command(req);
74
		}
75
		if (UMLElementTypes.DependencyClient_4007 == req.getElementType()) {
76
			return req.getTarget() == null ? null : getCreateCompleteIncomingDependency_Client4007Command(req);
77
		}
78
		if (UMLElementTypes.InterfaceRealization_4008 == req.getElementType()) {
79
			return req.getTarget() == null ? null : getCreateCompleteIncomingInterfaceRealization4008Command(req);
80
		}
81
		if (UMLElementTypes.Usage_4009 == req.getElementType()) {
82
			return req.getTarget() == null ? getCreateStartOutgoingUsage4009Command(req) : getCreateCompleteIncomingUsage4009Command(req);
83
		}
84
		return super.getCreateRelationshipCommand(req);
85
	}
86
87
	/**
88
	 * @generated
89
	 */
90
	protected Command getCreateStartOutgoingGeneralization4001Command(CreateRelationshipRequest req) {
91
		return new Command() {
92
		};
93
	}
94
95
	/**
96
	 * @generated
97
	 */
98
	protected Command getCreateCompleteIncomingGeneralization4001Command(CreateRelationshipRequest req) {
99
		if (!(req.getSource() instanceof Classifier)) {
100
			return UnexecutableCommand.INSTANCE;
101
		}
102
		final Classifier element = (Classifier) req.getSource();
103
		if (req.getContainmentFeature() == null) {
104
			req.setContainmentFeature(UMLPackage.eINSTANCE.getClassifier_Generalization());
105
		}
106
		return getMSLWrapper(new CreateIncomingGeneralization4001Command(req) {
107
108
			protected EObject getElementToEdit() {
109
				return element;
110
			}
111
		});
112
	}
113
114
	/**
115
	 * @generated
116
	 */
117
	private static class CreateIncomingGeneralization4001Command extends CreateRelationshipCommand {
118
119
		/**
120
		 * @generated
121
		 */
122
		public CreateIncomingGeneralization4001Command(CreateRelationshipRequest req) {
123
			super(req);
124
		}
125
126
		/**
127
		 * @generated
128
		 */
129
		protected EClass getEClassToEdit() {
130
			return UMLPackage.eINSTANCE.getClassifier();
131
		};
132
133
		/**
134
		 * @generated
135
		 */
136
		protected void setElementToEdit(EObject element) {
137
			throw new UnsupportedOperationException();
138
		}
139
140
		/**
141
		 * @generated
142
		 */
143
		protected EObject doDefaultElementCreation() {
144
			Generalization newElement = (Generalization) super.doDefaultElementCreation();
145
			if (newElement != null) {
146
				newElement.setGeneral((Classifier) getTarget());
147
			}
148
			return newElement;
149
		}
150
	}
151
152
	/**
153
	 * @generated
154
	 */
155
	protected Command getCreateStartOutgoingDependency4002Command(CreateRelationshipRequest req) {
156
		return new Command() {
157
		};
158
	}
159
160
	/**
161
	 * @generated
162
	 */
163
	protected Command getCreateCompleteIncomingDependency4002Command(CreateRelationshipRequest req) {
164
		if (!(req.getSource() instanceof NamedElement)) {
165
			return UnexecutableCommand.INSTANCE;
166
		}
167
		final org.eclipse.uml2.uml.Package element = (org.eclipse.uml2.uml.Package) getRelationshipContainer(req.getSource(), UMLPackage.eINSTANCE.getPackage(), req.getElementType());
168
		if (element == null) {
169
			return UnexecutableCommand.INSTANCE;
170
		}
171
		if (req.getContainmentFeature() == null) {
172
			req.setContainmentFeature(UMLPackage.eINSTANCE.getPackage_PackagedElement());
173
		}
174
		return getMSLWrapper(new CreateIncomingDependency4002Command(req) {
175
176
			protected EObject getElementToEdit() {
177
				return element;
178
			}
179
		});
180
	}
181
182
	/**
183
	 * @generated
184
	 */
185
	private static class CreateIncomingDependency4002Command extends CreateRelationshipCommand {
186
187
		/**
188
		 * @generated
189
		 */
190
		public CreateIncomingDependency4002Command(CreateRelationshipRequest req) {
191
			super(req);
192
		}
193
194
		/**
195
		 * @generated
196
		 */
197
		protected EClass getEClassToEdit() {
198
			return UMLPackage.eINSTANCE.getPackage();
199
		};
200
201
		/**
202
		 * @generated
203
		 */
204
		protected void setElementToEdit(EObject element) {
205
			throw new UnsupportedOperationException();
206
		}
207
208
		/**
209
		 * @generated
210
		 */
211
		protected EObject doDefaultElementCreation() {
212
			Dependency newElement = (Dependency) super.doDefaultElementCreation();
213
			if (newElement != null) {
214
				newElement.getSuppliers().add((NamedElement) getTarget());
215
				newElement.getClients().add((NamedElement) getSource());
216
			}
217
			return newElement;
218
		}
219
	}
220
221
	/**
222
	 * @generated
223
	 */
224
	protected Command getCreateCompleteIncomingProperty4003Command(CreateRelationshipRequest req) {
225
		if (!(req.getSource() instanceof Association)) {
226
			return UnexecutableCommand.INSTANCE;
227
		}
228
		final Association element = (Association) req.getSource();
229
		if (req.getContainmentFeature() == null) {
230
			req.setContainmentFeature(UMLPackage.eINSTANCE.getAssociation_OwnedEnd());
231
		}
232
		return getMSLWrapper(new CreateIncomingProperty4003Command(req) {
233
234
			protected EObject getElementToEdit() {
235
				return element;
236
			}
237
		});
238
	}
239
240
	/**
241
	 * @generated
242
	 */
243
	private static class CreateIncomingProperty4003Command extends CreateRelationshipCommand {
244
245
		/**
246
		 * @generated
247
		 */
248
		public CreateIncomingProperty4003Command(CreateRelationshipRequest req) {
249
			super(req);
250
		}
251
252
		/**
253
		 * @generated
254
		 */
255
		protected EClass getEClassToEdit() {
256
			return UMLPackage.eINSTANCE.getAssociation();
257
		};
258
259
		/**
260
		 * @generated
261
		 */
262
		protected void setElementToEdit(EObject element) {
263
			throw new UnsupportedOperationException();
264
		}
265
266
		/**
267
		 * @generated
268
		 */
269
		protected EObject doDefaultElementCreation() {
270
			Property newElement = (Property) super.doDefaultElementCreation();
271
			if (newElement != null) {
272
				newElement.setType((Type) getTarget());
273
			}
274
			return newElement;
275
		}
276
	}
277
278
	/**
279
	 * @generated
280
	 */
281
	protected Command getCreateCompleteIncomingConstraint_ConstrainedElement4004Command(CreateRelationshipRequest req) {
282
		if (!(req.getSource() instanceof Constraint)) {
283
			return UnexecutableCommand.INSTANCE;
284
		}
285
		Constraint element = (Constraint) req.getSource();
286
		if (element.getConstrainedElements().contains(req.getTarget())) {
287
			return UnexecutableCommand.INSTANCE;
288
		}
289
		SetRequest setReq = new SetRequest(req.getSource(), UMLPackage.eINSTANCE.getConstraint_ConstrainedElement(), req.getTarget());
290
		return getMSLWrapper(new SetValueCommand(setReq));
291
	}
292
293
	/**
294
	 * @generated
295
	 */
296
	protected Command getCreateStartOutgoingAssociation4005Command(CreateRelationshipRequest req) {
297
		return new Command() {
298
		};
299
	}
300
301
	/**
302
	 * @generated
303
	 */
304
	protected Command getCreateCompleteIncomingAssociation4005Command(CreateRelationshipRequest req) {
305
		if (!(req.getSource() instanceof Type)) {
306
			return UnexecutableCommand.INSTANCE;
307
		}
308
		final org.eclipse.uml2.uml.Package element = (org.eclipse.uml2.uml.Package) getRelationshipContainer(req.getSource(), UMLPackage.eINSTANCE.getPackage(), req.getElementType());
309
		if (element == null) {
310
			return UnexecutableCommand.INSTANCE;
311
		}
312
		if (req.getContainmentFeature() == null) {
313
			req.setContainmentFeature(UMLPackage.eINSTANCE.getPackage_PackagedElement());
314
		}
315
		return getMSLWrapper(new CreateIncomingAssociation4005Command(req) {
316
317
			protected EObject getElementToEdit() {
318
				return element;
319
			}
320
		});
321
	}
322
323
	/**
324
	 * @generated NOT
325
	 */
326
	private static class CreateIncomingAssociation4005Command extends CreateAssociationCommand {
327
328
		/**
329
		 * @generated
330
		 */
331
		public CreateIncomingAssociation4005Command(CreateRelationshipRequest req) {
332
			super(req);
333
		}
334
335
		/**
336
		 * @generated
337
		 */
338
		protected EClass getEClassToEdit() {
339
			return UMLPackage.eINSTANCE.getPackage();
340
		};
341
342
		/**
343
		 * @generated
344
		 */
345
		protected void setElementToEdit(EObject element) {
346
			throw new UnsupportedOperationException();
347
		}
348
349
		/**
350
		 * @generated NOT
351
		 */
352
		protected EObject doDefaultElementCreation() {
353
			return super.doDefaultElementCreation();
354
		}
355
	}
356
357
	/**
358
	 * @generated
359
	 */
360
	protected Command getCreateCompleteIncomingDependency_Supplier4006Command(CreateRelationshipRequest req) {
361
		if (!(req.getSource() instanceof Dependency)) {
362
			return UnexecutableCommand.INSTANCE;
363
		}
364
		Dependency element = (Dependency) req.getSource();
365
		if (element.getSuppliers().contains(req.getTarget())) {
366
			return UnexecutableCommand.INSTANCE;
367
		}
368
		SetRequest setReq = new SetRequest(req.getSource(), UMLPackage.eINSTANCE.getDependency_Supplier(), req.getTarget());
369
		return getMSLWrapper(new SetValueCommand(setReq));
370
	}
371
372
	/**
373
	 * @generated
374
	 */
375
	protected Command getCreateCompleteIncomingDependency_Client4007Command(CreateRelationshipRequest req) {
376
		if (!(req.getSource() instanceof Dependency)) {
377
			return UnexecutableCommand.INSTANCE;
378
		}
379
		Dependency element = (Dependency) req.getSource();
380
		if (element.getClients().contains(req.getTarget())) {
381
			return UnexecutableCommand.INSTANCE;
382
		}
383
		SetRequest setReq = new SetRequest(req.getSource(), UMLPackage.eINSTANCE.getDependency_Client(), req.getTarget());
384
		return getMSLWrapper(new SetValueCommand(setReq));
385
	}
386
387
	/**
388
	 * @generated
389
	 */
390
	protected Command getCreateCompleteIncomingInterfaceRealization4008Command(CreateRelationshipRequest req) {
391
		if (!(req.getSource() instanceof BehavioredClassifier)) {
392
			return UnexecutableCommand.INSTANCE;
393
		}
394
		final BehavioredClassifier element = (BehavioredClassifier) getRelationshipContainer(req.getSource(), UMLPackage.eINSTANCE.getBehavioredClassifier(), req.getElementType());
395
		if (element == null) {
396
			return UnexecutableCommand.INSTANCE;
397
		}
398
		if (req.getContainmentFeature() == null) {
399
			req.setContainmentFeature(UMLPackage.eINSTANCE.getBehavioredClassifier_InterfaceRealization());
400
		}
401
		return getMSLWrapper(new CreateIncomingInterfaceRealization4008Command(req) {
402
403
			protected EObject getElementToEdit() {
404
				return element;
405
			}
406
		});
407
	}
408
409
	/**
410
	 * @generated
411
	 */
412
	private static class CreateIncomingInterfaceRealization4008Command extends CreateRelationshipCommand {
413
414
		/**
415
		 * @generated
416
		 */
417
		public CreateIncomingInterfaceRealization4008Command(CreateRelationshipRequest req) {
418
			super(req);
419
		}
420
421
		/**
422
		 * @generated
423
		 */
424
		protected EClass getEClassToEdit() {
425
			return UMLPackage.eINSTANCE.getBehavioredClassifier();
426
		};
427
428
		/**
429
		 * @generated
430
		 */
431
		protected void setElementToEdit(EObject element) {
432
			throw new UnsupportedOperationException();
433
		}
434
435
		/**
436
		 * @generated
437
		 */
438
		protected EObject doDefaultElementCreation() {
439
			InterfaceRealization newElement = (InterfaceRealization) super.doDefaultElementCreation();
440
			if (newElement != null) {
441
				newElement.setContract((Interface) getTarget());
442
				newElement.setImplementingClassifier((BehavioredClassifier) getSource());
443
			}
444
			return newElement;
445
		}
446
	}
447
448
	/**
449
	 * @generated
450
	 */
451
	protected Command getCreateStartOutgoingUsage4009Command(CreateRelationshipRequest req) {
452
		if (!UMLBaseItemSemanticEditPolicy.LinkConstraints.Usage_4009.canCreateLink(req, false)) {
453
			return UnexecutableCommand.INSTANCE;
454
		}
455
		return new Command() {
456
		};
457
	}
458
459
	/**
460
	 * @generated
461
	 */
462
	protected Command getCreateCompleteIncomingUsage4009Command(CreateRelationshipRequest req) {
463
		if (!(req.getSource() instanceof NamedElement)) {
464
			return UnexecutableCommand.INSTANCE;
465
		}
466
		final org.eclipse.uml2.uml.Package element = (org.eclipse.uml2.uml.Package) getRelationshipContainer(req.getSource(), UMLPackage.eINSTANCE.getPackage(), req.getElementType());
467
		if (element == null) {
468
			return UnexecutableCommand.INSTANCE;
469
		}
470
		if (!UMLBaseItemSemanticEditPolicy.LinkConstraints.Usage_4009.canCreateLink(req, false)) {
471
			return UnexecutableCommand.INSTANCE;
472
		}
473
		if (req.getContainmentFeature() == null) {
474
			req.setContainmentFeature(UMLPackage.eINSTANCE.getPackage_PackagedElement());
475
		}
476
		return getMSLWrapper(new CreateIncomingUsage4009Command(req) {
477
478
			protected EObject getElementToEdit() {
479
				return element;
480
			}
481
		});
482
	}
483
484
	/**
485
	 * @generated
486
	 */
487
	private static class CreateIncomingUsage4009Command extends CreateRelationshipCommand {
488
489
		/**
490
		 * @generated
491
		 */
492
		public CreateIncomingUsage4009Command(CreateRelationshipRequest req) {
493
			super(req);
494
		}
495
496
		/**
497
		 * @generated
498
		 */
499
		protected EClass getEClassToEdit() {
500
			return UMLPackage.eINSTANCE.getPackage();
501
		};
502
503
		/**
504
		 * @generated
505
		 */
506
		protected void setElementToEdit(EObject element) {
507
			throw new UnsupportedOperationException();
508
		}
509
510
		/**
511
		 * @generated
512
		 */
513
		protected EObject doDefaultElementCreation() {
514
			Usage newElement = (Usage) super.doDefaultElementCreation();
515
			if (newElement != null) {
516
				newElement.getSuppliers().add((NamedElement) getTarget());
517
				newElement.getClients().add((NamedElement) getSource());
518
			}
519
			return newElement;
520
		}
521
	}
522
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/policies/EnumerationAttributesItemSemanticEditPolicy.java (+73 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.policies;
2
3
import org.eclipse.emf.ecore.EClass;
4
import org.eclipse.emf.ecore.EObject;
5
import org.eclipse.gef.commands.Command;
6
import org.eclipse.gmf.runtime.emf.type.core.commands.CreateElementCommand;
7
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest;
8
import org.eclipse.gmf.runtime.notation.View;
9
import org.eclipse.uml2.diagram.clazz.providers.UMLElementTypes;
10
import org.eclipse.uml2.uml.Property;
11
import org.eclipse.uml2.uml.UMLPackage;
12
13
/**
14
 * @generated
15
 */
16
public class EnumerationAttributesItemSemanticEditPolicy extends UMLBaseItemSemanticEditPolicy {
17
18
	/**
19
	 * @generated
20
	 */
21
	protected Command getCreateCommand(CreateElementRequest req) {
22
		if (UMLElementTypes.Property_3023 == req.getElementType()) {
23
			if (req.getContainmentFeature() == null) {
24
				req.setContainmentFeature(UMLPackage.eINSTANCE.getDataType_OwnedAttribute());
25
			}
26
			return getMSLWrapper(new CreateProperty_3023Command(req));
27
		}
28
		return super.getCreateCommand(req);
29
	}
30
31
	/**
32
	 * @generated
33
	 */
34
	private static class CreateProperty_3023Command extends CreateElementCommand {
35
36
		/**
37
		 * @generated
38
		 */
39
		public CreateProperty_3023Command(CreateElementRequest req) {
40
			super(req);
41
		}
42
43
		/**
44
		 * @generated
45
		 */
46
		protected EClass getEClassToEdit() {
47
			return UMLPackage.eINSTANCE.getEnumeration();
48
		};
49
50
		/**
51
		 * @generated
52
		 */
53
		protected EObject getElementToEdit() {
54
			EObject container = ((CreateElementRequest) getRequest()).getContainer();
55
			if (container instanceof View) {
56
				container = ((View) container).getElement();
57
			}
58
			return container;
59
		}
60
61
		/**
62
		 * @generated
63
		 */
64
		protected EObject doDefaultElementCreation() {
65
			Property newElement = (Property) super.doDefaultElementCreation();
66
			if (newElement != null) {
67
				UMLElementTypes.Initializers.Property_3023.init(newElement);
68
			}
69
			return newElement;
70
		}
71
	}
72
73
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/parts/ConstraintNameEditPart.java (+551 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.parts;
2
3
import java.util.ArrayList;
4
import java.util.Collections;
5
import java.util.List;
6
7
import org.eclipse.draw2d.IFigure;
8
import org.eclipse.draw2d.Label;
9
import org.eclipse.draw2d.geometry.Point;
10
import org.eclipse.emf.common.notify.Notification;
11
import org.eclipse.emf.ecore.EObject;
12
import org.eclipse.emf.transaction.RunnableWithResult;
13
import org.eclipse.gef.AccessibleEditPart;
14
import org.eclipse.gef.EditPolicy;
15
import org.eclipse.gef.GraphicalEditPart;
16
import org.eclipse.gef.Request;
17
import org.eclipse.gef.commands.Command;
18
import org.eclipse.gef.editpolicies.NonResizableEditPolicy;
19
import org.eclipse.gef.handles.NonResizableHandleKit;
20
import org.eclipse.gef.requests.DirectEditRequest;
21
import org.eclipse.gef.tools.DirectEditManager;
22
import org.eclipse.gmf.runtime.common.ui.services.parser.IParser;
23
import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus;
24
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserEditStatus;
25
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions;
26
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserService;
27
import org.eclipse.gmf.runtime.diagram.ui.editparts.CompartmentEditPart;
28
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
29
import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart;
30
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy;
31
import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry;
32
import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants;
33
import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager;
34
import org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel;
35
import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
36
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
37
import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser;
38
import org.eclipse.gmf.runtime.emf.ui.services.parser.ParserHintAdapter;
39
import org.eclipse.gmf.runtime.notation.FontStyle;
40
import org.eclipse.gmf.runtime.notation.NotationPackage;
41
import org.eclipse.gmf.runtime.notation.View;
42
import org.eclipse.jface.resource.ImageDescriptor;
43
import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
44
import org.eclipse.jface.viewers.ICellEditorValidator;
45
import org.eclipse.swt.SWT;
46
import org.eclipse.swt.accessibility.AccessibleEvent;
47
import org.eclipse.swt.graphics.Color;
48
import org.eclipse.swt.graphics.FontData;
49
import org.eclipse.swt.graphics.Image;
50
import org.eclipse.uml2.diagram.clazz.edit.policies.UMLTextSelectionEditPolicy;
51
import org.eclipse.uml2.diagram.clazz.part.UMLDiagramEditorPlugin;
52
import org.eclipse.uml2.diagram.clazz.providers.UMLElementTypes;
53
54
/**
55
 * @generated
56
 */
57
public class ConstraintNameEditPart extends CompartmentEditPart implements ITextAwareEditPart {
58
59
	/**
60
	 * @generated
61
	 */
62
	public static final int VISUAL_ID = 5008;
63
64
	/**
65
	 * @generated
66
	 */
67
	private DirectEditManager manager;
68
69
	/**
70
	 * @generated
71
	 */
72
	private IParser parser;
73
74
	/**
75
	 * @generated
76
	 */
77
	private List parserElements;
78
79
	/**
80
	 * @generated
81
	 */
82
	private String defaultText;
83
84
	/**
85
	 * @generated
86
	 */
87
	public ConstraintNameEditPart(View view) {
88
		super(view);
89
	}
90
91
	/**
92
	 * @generated
93
	 */
94
	protected void createDefaultEditPolicies() {
95
		super.createDefaultEditPolicies();
96
		installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy());
97
		installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new NonResizableEditPolicy() {
98
99
			protected List createSelectionHandles() {
100
				List handles = new ArrayList();
101
				NonResizableHandleKit.addMoveHandle((GraphicalEditPart) getHost(), handles);
102
				return handles;
103
			}
104
105
			public Command getCommand(Request request) {
106
				return null;
107
			}
108
109
			public boolean understandsRequest(Request request) {
110
				return false;
111
			}
112
		});
113
114
	}
115
116
	/**
117
	 * @generated
118
	 */
119
	protected String getLabelTextHelper(IFigure figure) {
120
		if (figure instanceof WrapLabel) {
121
			return ((WrapLabel) figure).getText();
122
		} else {
123
			return ((Label) figure).getText();
124
		}
125
	}
126
127
	/**
128
	 * @generated
129
	 */
130
	protected void setLabelTextHelper(IFigure figure, String text) {
131
		if (figure instanceof WrapLabel) {
132
			((WrapLabel) figure).setText(text);
133
		} else {
134
			((Label) figure).setText(text);
135
		}
136
	}
137
138
	/**
139
	 * @generated
140
	 */
141
	protected Image getLabelIconHelper(IFigure figure) {
142
		if (figure instanceof WrapLabel) {
143
			return ((WrapLabel) figure).getIcon();
144
		} else {
145
			return ((Label) figure).getIcon();
146
		}
147
	}
148
149
	/**
150
	 * @generated
151
	 */
152
	protected void setLabelIconHelper(IFigure figure, Image icon) {
153
		if (figure instanceof WrapLabel) {
154
			((WrapLabel) figure).setIcon(icon);
155
		} else {
156
			((Label) figure).setIcon(icon);
157
		}
158
	}
159
160
	/**
161
	 * @generated
162
	 */
163
	public void setLabel(WrapLabel figure) {
164
		unregisterVisuals();
165
		setFigure(figure);
166
		defaultText = getLabelTextHelper(figure);
167
		registerVisuals();
168
		refreshVisuals();
169
	}
170
171
	/**
172
	 * @generated
173
	 */
174
	protected List getModelChildren() {
175
		return Collections.EMPTY_LIST;
176
	}
177
178
	/**
179
	 * @generated
180
	 */
181
	public IGraphicalEditPart getChildBySemanticHint(String semanticHint) {
182
		return null;
183
	}
184
185
	/**
186
	 * @generated
187
	 */
188
	protected EObject getParserElement() {
189
		EObject element = resolveSemanticElement();
190
		return element != null ? element : (View) getModel();
191
	}
192
193
	/**
194
	 * @generated
195
	 */
196
	protected Image getLabelIcon() {
197
		EObject parserElement = getParserElement();
198
		if (parserElement == null) {
199
			return null;
200
		}
201
		return UMLElementTypes.getImage(parserElement.eClass());
202
	}
203
204
	/**
205
	 * @generated
206
	 */
207
	protected String getLabelText() {
208
		String text = null;
209
		if (getParser() != null) {
210
			text = getParser().getPrintString(new EObjectAdapter(getParserElement()), getParserOptions().intValue());
211
		}
212
		if (text == null || text.length() == 0) {
213
			text = defaultText;
214
		}
215
		return text;
216
	}
217
218
	/**
219
	 * @generated
220
	 */
221
	public void setLabelText(String text) {
222
		setLabelTextHelper(getFigure(), text);
223
		Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
224
		if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) {
225
			((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback();
226
		}
227
	}
228
229
	/**
230
	 * @generated
231
	 */
232
	public String getEditText() {
233
		if (getParser() == null) {
234
			return ""; //$NON-NLS-1$
235
		}
236
		return getParser().getEditString(new EObjectAdapter(getParserElement()), getParserOptions().intValue());
237
	}
238
239
	/**
240
	 * @generated
241
	 */
242
	protected boolean isEditable() {
243
		return getEditText() != null;
244
	}
245
246
	/**
247
	 * @generated
248
	 */
249
	public ICellEditorValidator getEditTextValidator() {
250
		return new ICellEditorValidator() {
251
252
			public String isValid(final Object value) {
253
				if (value instanceof String) {
254
					final EObject element = getParserElement();
255
					final IParser parser = getParser();
256
					try {
257
						IParserEditStatus valid = (IParserEditStatus) getEditingDomain().runExclusive(new RunnableWithResult.Impl() {
258
259
							public void run() {
260
								setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value));
261
							}
262
						});
263
						return valid.getCode() == ParserEditStatus.EDITABLE ? null : valid.getMessage();
264
					} catch (InterruptedException ie) {
265
						ie.printStackTrace();
266
					}
267
				}
268
269
				// shouldn't get here
270
				return null;
271
			}
272
		};
273
	}
274
275
	/**
276
	 * @generated
277
	 */
278
	public IContentAssistProcessor getCompletionProcessor() {
279
		if (getParser() == null) {
280
			return null;
281
		}
282
		return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement()));
283
	}
284
285
	/**
286
	 * @generated
287
	 */
288
	public ParserOptions getParserOptions() {
289
		return ParserOptions.NONE;
290
	}
291
292
	/**
293
	 * @generated
294
	 */
295
	public IParser getParser() {
296
		if (parser == null) {
297
			String parserHint = ((View) getModel()).getType();
298
			ParserHintAdapter hintAdapter = new ParserHintAdapter(getParserElement(), parserHint) {
299
300
				public Object getAdapter(Class adapter) {
301
					if (IElementType.class.equals(adapter)) {
302
						return UMLElementTypes.Constraint_2006;
303
					}
304
					return super.getAdapter(adapter);
305
				}
306
			};
307
			parser = ParserService.getInstance().getParser(hintAdapter);
308
		}
309
		return parser;
310
	}
311
312
	/**
313
	 * @generated
314
	 */
315
	protected DirectEditManager getManager() {
316
		if (manager == null) {
317
			setManager(new TextDirectEditManager(this, TextDirectEditManager.getTextCellEditorClass(this), UMLEditPartFactory.getTextCellEditorLocator(this)));
318
		}
319
		return manager;
320
	}
321
322
	/**
323
	 * @generated
324
	 */
325
	protected void setManager(DirectEditManager manager) {
326
		this.manager = manager;
327
	}
328
329
	/**
330
	 * @generated
331
	 */
332
	protected void performDirectEdit() {
333
		getManager().show();
334
	}
335
336
	/**
337
	 * @generated
338
	 */
339
	protected void performDirectEdit(Point eventLocation) {
340
		if (getManager().getClass() == TextDirectEditManager.class) {
341
			((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint());
342
		}
343
	}
344
345
	/**
346
	 * @generated
347
	 */
348
	private void performDirectEdit(char initialCharacter) {
349
		if (getManager() instanceof TextDirectEditManager) {
350
			((TextDirectEditManager) getManager()).show(initialCharacter);
351
		} else {
352
			performDirectEdit();
353
		}
354
	}
355
356
	/**
357
	 * @generated
358
	 */
359
	protected void performDirectEditRequest(Request request) {
360
		final Request theRequest = request;
361
		try {
362
			getEditingDomain().runExclusive(new Runnable() {
363
364
				public void run() {
365
					if (isActive() && isEditable()) {
366
						if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) {
367
							Character initialChar = (Character) theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR);
368
							performDirectEdit(initialChar.charValue());
369
						} else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) {
370
							DirectEditRequest editRequest = (DirectEditRequest) theRequest;
371
							performDirectEdit(editRequest.getLocation());
372
						} else {
373
							performDirectEdit();
374
						}
375
					}
376
				}
377
			});
378
		} catch (InterruptedException e) {
379
			e.printStackTrace();
380
		}
381
	}
382
383
	/**
384
	 * @generated
385
	 */
386
	protected void refreshVisuals() {
387
		super.refreshVisuals();
388
		refreshLabel();
389
		refreshFont();
390
		refreshFontColor();
391
		refreshUnderline();
392
		refreshStrikeThrough();
393
	}
394
395
	/**
396
	 * @generated
397
	 */
398
	protected void refreshLabel() {
399
		setLabelTextHelper(getFigure(), getLabelText());
400
		setLabelIconHelper(getFigure(), getLabelIcon());
401
		Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
402
		if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) {
403
			((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback();
404
		}
405
	}
406
407
	/**
408
	 * @generated
409
	 */
410
	protected void refreshUnderline() {
411
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
412
		if (style != null && getFigure() instanceof WrapLabel) {
413
			((WrapLabel) getFigure()).setTextUnderline(style.isUnderline());
414
		}
415
	}
416
417
	/**
418
	 * @generated
419
	 */
420
	protected void refreshStrikeThrough() {
421
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
422
		if (style != null && getFigure() instanceof WrapLabel) {
423
			((WrapLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough());
424
		}
425
	}
426
427
	/**
428
	 * @generated
429
	 */
430
	protected void refreshFont() {
431
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
432
		if (style != null) {
433
			FontData fontData = new FontData(style.getFontName(), style.getFontHeight(), (style.isBold() ? SWT.BOLD : SWT.NORMAL) | (style.isItalic() ? SWT.ITALIC : SWT.NORMAL));
434
			setFont(fontData);
435
		}
436
	}
437
438
	/**
439
	 * @generated
440
	 */
441
	protected void setFontColor(Color color) {
442
		getFigure().setForegroundColor(color);
443
	}
444
445
	/**
446
	 * @generated
447
	 */
448
	protected void addSemanticListeners() {
449
		if (getParser() instanceof ISemanticParser) {
450
			EObject element = resolveSemanticElement();
451
			parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element);
452
			for (int i = 0; i < parserElements.size(); i++) {
453
				addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$
454
			}
455
		} else {
456
			super.addSemanticListeners();
457
		}
458
	}
459
460
	/**
461
	 * @generated
462
	 */
463
	protected void removeSemanticListeners() {
464
		if (parserElements != null) {
465
			for (int i = 0; i < parserElements.size(); i++) {
466
				removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$
467
			}
468
		} else {
469
			super.removeSemanticListeners();
470
		}
471
	}
472
473
	/**
474
	 * @generated
475
	 */
476
	protected AccessibleEditPart getAccessibleEditPart() {
477
		if (accessibleEP == null) {
478
			accessibleEP = new AccessibleGraphicalEditPart() {
479
480
				public void getName(AccessibleEvent e) {
481
					e.result = getLabelTextHelper(getFigure());
482
				}
483
			};
484
		}
485
		return accessibleEP;
486
	}
487
488
	/**
489
	 * @generated
490
	 */
491
	private View getFontStyleOwnerView() {
492
		return getPrimaryView();
493
	}
494
495
	/**
496
	 * @generated
497
	 */
498
	protected void addNotationalListeners() {
499
		super.addNotationalListeners();
500
		addListenerFilter("PrimaryView", this, getPrimaryView()); //$NON-NLS-1$
501
	}
502
503
	/**
504
	 * @generated
505
	 */
506
	protected void removeNotationalListeners() {
507
		super.removeNotationalListeners();
508
		removeListenerFilter("PrimaryView"); //$NON-NLS-1$
509
	}
510
511
	/**
512
	 * @generated
513
	 */
514
	protected void handleNotificationEvent(Notification event) {
515
		Object feature = event.getFeature();
516
		if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) {
517
			Integer c = (Integer) event.getNewValue();
518
			setFontColor(DiagramColorRegistry.getInstance().getColor(c));
519
		} else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) {
520
			refreshUnderline();
521
		} else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) {
522
			refreshStrikeThrough();
523
		} else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature)
524
				|| NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) {
525
			refreshFont();
526
		} else {
527
			if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) {
528
				refreshLabel();
529
			}
530
			if (getParser() instanceof ISemanticParser) {
531
				ISemanticParser modelParser = (ISemanticParser) getParser();
532
				if (modelParser.areSemanticElementsAffected(null, event)) {
533
					removeSemanticListeners();
534
					if (resolveSemanticElement() != null) {
535
						addSemanticListeners();
536
					}
537
					refreshLabel();
538
				}
539
			}
540
		}
541
		super.handleNotificationEvent(event);
542
	}
543
544
	/**
545
	 * @generated
546
	 */
547
	protected IFigure createFigure() {
548
		// Parent should assign one using setLabel method
549
		return null;
550
	}
551
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/parts/LiteralStringEditPart.java (+553 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.parts;
2
3
import java.util.Collections;
4
import java.util.List;
5
6
import org.eclipse.draw2d.IFigure;
7
import org.eclipse.draw2d.Label;
8
import org.eclipse.draw2d.geometry.Point;
9
import org.eclipse.emf.common.notify.Notification;
10
import org.eclipse.emf.ecore.EObject;
11
import org.eclipse.emf.transaction.RunnableWithResult;
12
import org.eclipse.gef.AccessibleEditPart;
13
import org.eclipse.gef.DragTracker;
14
import org.eclipse.gef.EditPolicy;
15
import org.eclipse.gef.Request;
16
import org.eclipse.gef.requests.DirectEditRequest;
17
import org.eclipse.gef.requests.SelectionRequest;
18
import org.eclipse.gef.tools.DirectEditManager;
19
import org.eclipse.gmf.runtime.common.ui.services.parser.IParser;
20
import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus;
21
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserEditStatus;
22
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions;
23
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserService;
24
import org.eclipse.gmf.runtime.diagram.ui.editparts.CompartmentEditPart;
25
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
26
import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart;
27
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
28
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy;
29
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.ListItemComponentEditPolicy;
30
import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry;
31
import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants;
32
import org.eclipse.gmf.runtime.diagram.ui.tools.DragEditPartsTrackerEx;
33
import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager;
34
import org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel;
35
import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
36
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
37
import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser;
38
import org.eclipse.gmf.runtime.emf.ui.services.parser.ParserHintAdapter;
39
import org.eclipse.gmf.runtime.notation.FontStyle;
40
import org.eclipse.gmf.runtime.notation.NotationPackage;
41
import org.eclipse.gmf.runtime.notation.View;
42
import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
43
import org.eclipse.jface.viewers.ICellEditorValidator;
44
import org.eclipse.swt.SWT;
45
import org.eclipse.swt.accessibility.AccessibleEvent;
46
import org.eclipse.swt.graphics.Color;
47
import org.eclipse.swt.graphics.FontData;
48
import org.eclipse.swt.graphics.Image;
49
import org.eclipse.uml2.diagram.clazz.edit.policies.LiteralStringItemSemanticEditPolicy;
50
import org.eclipse.uml2.diagram.clazz.edit.policies.UMLTextNonResizableEditPolicy;
51
import org.eclipse.uml2.diagram.clazz.edit.policies.UMLTextSelectionEditPolicy;
52
import org.eclipse.uml2.diagram.clazz.providers.UMLElementTypes;
53
54
/**
55
 * @generated
56
 */
57
public class LiteralStringEditPart extends CompartmentEditPart implements ITextAwareEditPart {
58
59
	/**
60
	 * @generated
61
	 */
62
	public static final int VISUAL_ID = 3005;
63
64
	/**
65
	 * @generated
66
	 */
67
	private DirectEditManager manager;
68
69
	/**
70
	 * @generated
71
	 */
72
	private IParser parser;
73
74
	/**
75
	 * @generated
76
	 */
77
	private List parserElements;
78
79
	/**
80
	 * @generated
81
	 */
82
	private String defaultText;
83
84
	/**
85
	 * @generated
86
	 */
87
	public LiteralStringEditPart(View view) {
88
		super(view);
89
	}
90
91
	/**
92
	 * @generated
93
	 */
94
	public DragTracker getDragTracker(Request request) {
95
		if (request instanceof SelectionRequest && ((SelectionRequest) request).getLastButtonPressed() == 3) {
96
			return null;
97
		}
98
		return new DragEditPartsTrackerEx(this);
99
	}
100
101
	/**
102
	 * @generated
103
	 */
104
	protected void createDefaultEditPolicies() {
105
		super.createDefaultEditPolicies();
106
		installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new LiteralStringItemSemanticEditPolicy());
107
		installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new UMLTextNonResizableEditPolicy());
108
		installEditPolicy(EditPolicy.COMPONENT_ROLE, new ListItemComponentEditPolicy());
109
		installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy());
110
111
	}
112
113
	/**
114
	 * @generated
115
	 */
116
	protected String getLabelTextHelper(IFigure figure) {
117
		if (figure instanceof WrapLabel) {
118
			return ((WrapLabel) figure).getText();
119
		} else {
120
			return ((Label) figure).getText();
121
		}
122
	}
123
124
	/**
125
	 * @generated
126
	 */
127
	protected void setLabelTextHelper(IFigure figure, String text) {
128
		if (figure instanceof WrapLabel) {
129
			((WrapLabel) figure).setText(text);
130
		} else {
131
			((Label) figure).setText(text);
132
		}
133
	}
134
135
	/**
136
	 * @generated
137
	 */
138
	protected Image getLabelIconHelper(IFigure figure) {
139
		if (figure instanceof WrapLabel) {
140
			return ((WrapLabel) figure).getIcon();
141
		} else {
142
			return ((Label) figure).getIcon();
143
		}
144
	}
145
146
	/**
147
	 * @generated
148
	 */
149
	protected void setLabelIconHelper(IFigure figure, Image icon) {
150
		if (figure instanceof WrapLabel) {
151
			((WrapLabel) figure).setIcon(icon);
152
		} else {
153
			((Label) figure).setIcon(icon);
154
		}
155
	}
156
157
	/**
158
	 * @generated
159
	 */
160
	public void setLabel(IFigure figure) {
161
		unregisterVisuals();
162
		setFigure(figure);
163
		defaultText = getLabelTextHelper(figure);
164
		registerVisuals();
165
		refreshVisuals();
166
	}
167
168
	/**
169
	 * @generated
170
	 */
171
	protected List getModelChildren() {
172
		return Collections.EMPTY_LIST;
173
	}
174
175
	/**
176
	 * @generated
177
	 */
178
	public IGraphicalEditPart getChildBySemanticHint(String semanticHint) {
179
		return null;
180
	}
181
182
	/**
183
	 * @generated
184
	 */
185
	protected EObject getParserElement() {
186
		EObject element = resolveSemanticElement();
187
		return element != null ? element : (View) getModel();
188
	}
189
190
	/**
191
	 * @generated
192
	 */
193
	protected Image getLabelIcon() {
194
		return null;
195
	}
196
197
	/**
198
	 * @generated
199
	 */
200
	protected String getLabelText() {
201
		String text = null;
202
		if (getParser() != null) {
203
			text = getParser().getPrintString(new EObjectAdapter(getParserElement()), getParserOptions().intValue());
204
		}
205
		if (text == null || text.length() == 0) {
206
			text = defaultText;
207
		}
208
		return text;
209
	}
210
211
	/**
212
	 * @generated
213
	 */
214
	public void setLabelText(String text) {
215
		setLabelTextHelper(getFigure(), text);
216
		Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
217
		if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) {
218
			((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback();
219
		}
220
	}
221
222
	/**
223
	 * @generated
224
	 */
225
	public String getEditText() {
226
		if (getParser() == null) {
227
			return ""; //$NON-NLS-1$
228
		}
229
		return getParser().getEditString(new EObjectAdapter(getParserElement()), getParserOptions().intValue());
230
	}
231
232
	/**
233
	 * @generated
234
	 */
235
	protected boolean isEditable() {
236
		return getEditText() != null;
237
	}
238
239
	/**
240
	 * @generated
241
	 */
242
	public ICellEditorValidator getEditTextValidator() {
243
		return new ICellEditorValidator() {
244
245
			public String isValid(final Object value) {
246
				if (value instanceof String) {
247
					final EObject element = getParserElement();
248
					final IParser parser = getParser();
249
					try {
250
						IParserEditStatus valid = (IParserEditStatus) getEditingDomain().runExclusive(new RunnableWithResult.Impl() {
251
252
							public void run() {
253
								setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value));
254
							}
255
						});
256
						return valid.getCode() == ParserEditStatus.EDITABLE ? null : valid.getMessage();
257
					} catch (InterruptedException ie) {
258
						ie.printStackTrace();
259
					}
260
				}
261
262
				// shouldn't get here
263
				return null;
264
			}
265
		};
266
	}
267
268
	/**
269
	 * @generated
270
	 */
271
	public IContentAssistProcessor getCompletionProcessor() {
272
		if (getParser() == null) {
273
			return null;
274
		}
275
		return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement()));
276
	}
277
278
	/**
279
	 * @generated
280
	 */
281
	public ParserOptions getParserOptions() {
282
		return ParserOptions.NONE;
283
	}
284
285
	/**
286
	 * @generated
287
	 */
288
	public IParser getParser() {
289
		if (parser == null) {
290
			String parserHint = ((View) getModel()).getType();
291
			ParserHintAdapter hintAdapter = new ParserHintAdapter(getParserElement(), parserHint) {
292
293
				public Object getAdapter(Class adapter) {
294
					if (IElementType.class.equals(adapter)) {
295
						return UMLElementTypes.LiteralString_3005;
296
					}
297
					return super.getAdapter(adapter);
298
				}
299
			};
300
			parser = ParserService.getInstance().getParser(hintAdapter);
301
		}
302
		return parser;
303
	}
304
305
	/**
306
	 * @generated
307
	 */
308
	protected DirectEditManager getManager() {
309
		if (manager == null) {
310
			setManager(new TextDirectEditManager(this, TextDirectEditManager.getTextCellEditorClass(this), UMLEditPartFactory.getTextCellEditorLocator(this)));
311
		}
312
		return manager;
313
	}
314
315
	/**
316
	 * @generated
317
	 */
318
	protected void setManager(DirectEditManager manager) {
319
		this.manager = manager;
320
	}
321
322
	/**
323
	 * @generated
324
	 */
325
	protected void performDirectEdit() {
326
		getManager().show();
327
	}
328
329
	/**
330
	 * @generated
331
	 */
332
	protected void performDirectEdit(Point eventLocation) {
333
		if (getManager().getClass() == TextDirectEditManager.class) {
334
			((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint());
335
		}
336
	}
337
338
	/**
339
	 * @generated
340
	 */
341
	private void performDirectEdit(char initialCharacter) {
342
		if (getManager() instanceof TextDirectEditManager) {
343
			((TextDirectEditManager) getManager()).show(initialCharacter);
344
		} else {
345
			performDirectEdit();
346
		}
347
	}
348
349
	/**
350
	 * @generated
351
	 */
352
	protected void performDirectEditRequest(Request request) {
353
		final Request theRequest = request;
354
		try {
355
			getEditingDomain().runExclusive(new Runnable() {
356
357
				public void run() {
358
					if (isActive() && isEditable()) {
359
						if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) {
360
							Character initialChar = (Character) theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR);
361
							performDirectEdit(initialChar.charValue());
362
						} else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) {
363
							DirectEditRequest editRequest = (DirectEditRequest) theRequest;
364
							performDirectEdit(editRequest.getLocation());
365
						} else {
366
							performDirectEdit();
367
						}
368
					}
369
				}
370
			});
371
		} catch (InterruptedException e) {
372
			e.printStackTrace();
373
		}
374
	}
375
376
	/**
377
	 * @generated
378
	 */
379
	protected void refreshVisuals() {
380
		super.refreshVisuals();
381
		refreshLabel();
382
		refreshFont();
383
		refreshFontColor();
384
		refreshUnderline();
385
		refreshStrikeThrough();
386
	}
387
388
	/**
389
	 * @generated
390
	 */
391
	protected void refreshLabel() {
392
		setLabelTextHelper(getFigure(), getLabelText());
393
		setLabelIconHelper(getFigure(), getLabelIcon());
394
		Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
395
		if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) {
396
			((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback();
397
		}
398
	}
399
400
	/**
401
	 * @generated
402
	 */
403
	protected void refreshUnderline() {
404
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
405
		if (style != null && getFigure() instanceof WrapLabel) {
406
			((WrapLabel) getFigure()).setTextUnderline(style.isUnderline());
407
		}
408
	}
409
410
	/**
411
	 * @generated
412
	 */
413
	protected void refreshStrikeThrough() {
414
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
415
		if (style != null && getFigure() instanceof WrapLabel) {
416
			((WrapLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough());
417
		}
418
	}
419
420
	/**
421
	 * @generated
422
	 */
423
	protected void refreshFont() {
424
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
425
		if (style != null) {
426
			FontData fontData = new FontData(style.getFontName(), style.getFontHeight(), (style.isBold() ? SWT.BOLD : SWT.NORMAL) | (style.isItalic() ? SWT.ITALIC : SWT.NORMAL));
427
			setFont(fontData);
428
		}
429
	}
430
431
	/**
432
	 * @generated
433
	 */
434
	protected void setFontColor(Color color) {
435
		getFigure().setForegroundColor(color);
436
	}
437
438
	/**
439
	 * @generated
440
	 */
441
	protected void addSemanticListeners() {
442
		if (getParser() instanceof ISemanticParser) {
443
			EObject element = resolveSemanticElement();
444
			parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element);
445
			for (int i = 0; i < parserElements.size(); i++) {
446
				addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$
447
			}
448
		} else {
449
			super.addSemanticListeners();
450
		}
451
	}
452
453
	/**
454
	 * @generated
455
	 */
456
	protected void removeSemanticListeners() {
457
		if (parserElements != null) {
458
			for (int i = 0; i < parserElements.size(); i++) {
459
				removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$
460
			}
461
		} else {
462
			super.removeSemanticListeners();
463
		}
464
	}
465
466
	/**
467
	 * @generated
468
	 */
469
	protected AccessibleEditPart getAccessibleEditPart() {
470
		if (accessibleEP == null) {
471
			accessibleEP = new AccessibleGraphicalEditPart() {
472
473
				public void getName(AccessibleEvent e) {
474
					e.result = getLabelTextHelper(getFigure());
475
				}
476
			};
477
		}
478
		return accessibleEP;
479
	}
480
481
	/**
482
	 * @generated
483
	 */
484
	private View getFontStyleOwnerView() {
485
		return getPrimaryView();
486
	}
487
488
	/**
489
	 * @generated
490
	 */
491
	protected void addNotationalListeners() {
492
		super.addNotationalListeners();
493
		addListenerFilter("PrimaryView", this, getPrimaryView()); //$NON-NLS-1$
494
	}
495
496
	/**
497
	 * @generated
498
	 */
499
	protected void removeNotationalListeners() {
500
		super.removeNotationalListeners();
501
		removeListenerFilter("PrimaryView"); //$NON-NLS-1$
502
	}
503
504
	/**
505
	 * @generated
506
	 */
507
	protected void handleNotificationEvent(Notification event) {
508
		Object feature = event.getFeature();
509
		if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) {
510
			Integer c = (Integer) event.getNewValue();
511
			setFontColor(DiagramColorRegistry.getInstance().getColor(c));
512
		} else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) {
513
			refreshUnderline();
514
		} else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) {
515
			refreshStrikeThrough();
516
		} else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature)
517
				|| NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) {
518
			refreshFont();
519
		} else {
520
			if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) {
521
				refreshLabel();
522
			}
523
			if (getParser() instanceof ISemanticParser) {
524
				ISemanticParser modelParser = (ISemanticParser) getParser();
525
				if (modelParser.areSemanticElementsAffected(null, event)) {
526
					removeSemanticListeners();
527
					if (resolveSemanticElement() != null) {
528
						addSemanticListeners();
529
					}
530
					refreshLabel();
531
				}
532
			}
533
		}
534
		super.handleNotificationEvent(event);
535
	}
536
537
	/**
538
	 * @generated
539
	 */
540
	protected IFigure createFigure() {
541
		IFigure label = createFigurePrim();
542
		defaultText = getLabelTextHelper(label);
543
		return label;
544
	}
545
546
	/**
547
	 * @generated
548
	 */
549
	protected IFigure createFigurePrim() {
550
		return new WrapLabel();
551
	}
552
553
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/policies/UMLBaseItemSemanticEditPolicy.java (+342 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.policies;
2
3
import java.util.Collections;
4
import java.util.HashMap;
5
import java.util.Map;
6
7
import org.eclipse.emf.ecore.EClass;
8
import org.eclipse.emf.ecore.EObject;
9
import org.eclipse.emf.transaction.TransactionalEditingDomain;
10
import org.eclipse.gef.commands.Command;
11
import org.eclipse.gef.commands.UnexecutableCommand;
12
import org.eclipse.gmf.runtime.common.core.command.ICommand;
13
import org.eclipse.gmf.runtime.diagram.core.commands.DeleteCommand;
14
import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil;
15
import org.eclipse.gmf.runtime.diagram.ui.commands.CommandProxy;
16
import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
17
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
18
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.SemanticEditPolicy;
19
import org.eclipse.gmf.runtime.emf.commands.core.command.CompositeTransactionalCommand;
20
import org.eclipse.gmf.runtime.emf.type.core.ElementTypeRegistry;
21
import org.eclipse.gmf.runtime.emf.type.core.IEditHelperContext;
22
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
23
import org.eclipse.gmf.runtime.emf.type.core.commands.CreateRelationshipCommand;
24
import org.eclipse.gmf.runtime.emf.type.core.requests.ConfigureRequest;
25
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest;
26
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest;
27
import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest;
28
import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyReferenceRequest;
29
import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyRequest;
30
import org.eclipse.gmf.runtime.emf.type.core.requests.DuplicateElementsRequest;
31
import org.eclipse.gmf.runtime.emf.type.core.requests.GetEditContextRequest;
32
import org.eclipse.gmf.runtime.emf.type.core.requests.IEditCommandRequest;
33
import org.eclipse.gmf.runtime.emf.type.core.requests.MoveRequest;
34
import org.eclipse.gmf.runtime.emf.type.core.requests.ReorientReferenceRelationshipRequest;
35
import org.eclipse.gmf.runtime.emf.type.core.requests.ReorientRelationshipRequest;
36
import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest;
37
import org.eclipse.gmf.runtime.notation.View;
38
import org.eclipse.uml2.diagram.clazz.edit.helpers.UMLBaseEditHelper;
39
import org.eclipse.uml2.diagram.clazz.expressions.UMLAbstractExpression;
40
import org.eclipse.uml2.diagram.clazz.expressions.UMLOCLFactory;
41
import org.eclipse.uml2.diagram.clazz.part.UMLDiagramEditorPlugin;
42
import org.eclipse.uml2.uml.AggregationKind;
43
import org.eclipse.uml2.uml.Association;
44
import org.eclipse.uml2.uml.Type;
45
import org.eclipse.uml2.uml.UMLPackage;
46
47
/**
48
 * @generated
49
 */
50
public class UMLBaseItemSemanticEditPolicy extends SemanticEditPolicy {
51
52
	/**
53
	 * @generated
54
	 */
55
	protected Command getSemanticCommand(IEditCommandRequest request) {
56
		IEditCommandRequest completedRequest = completeRequest(request);
57
		Object editHelperContext = completedRequest.getEditHelperContext();
58
		if (editHelperContext instanceof View || (editHelperContext instanceof IEditHelperContext && ((IEditHelperContext) editHelperContext).getEObject() instanceof View)) {
59
			// no semantic commands are provided for pure design elements
60
			return null;
61
		}
62
		if (editHelperContext == null) {
63
			editHelperContext = ViewUtil.resolveSemanticElement((View) getHost().getModel());
64
		}
65
		IElementType elementType = ElementTypeRegistry.getInstance().getElementType(editHelperContext);
66
		if (elementType == ElementTypeRegistry.getInstance().getType("org.eclipse.gmf.runtime.emf.type.core.default")) { //$NON-NLS-1$ 
67
			elementType = null;
68
		}
69
		Command epCommand = getSemanticCommandSwitch(completedRequest);
70
		if (epCommand != null) {
71
			ICommand command = epCommand instanceof ICommandProxy ? ((ICommandProxy) epCommand).getICommand() : new CommandProxy(epCommand);
72
			completedRequest.setParameter(UMLBaseEditHelper.EDIT_POLICY_COMMAND, command);
73
		}
74
		Command ehCommand = null;
75
		if (elementType != null) {
76
			ICommand command = elementType.getEditCommand(completedRequest);
77
			if (command != null) {
78
				if (!(command instanceof CompositeTransactionalCommand)) {
79
					TransactionalEditingDomain editingDomain = ((IGraphicalEditPart) getHost()).getEditingDomain();
80
					command = new CompositeTransactionalCommand(editingDomain, null).compose(command);
81
				}
82
				ehCommand = new ICommandProxy(command);
83
			}
84
		}
85
		boolean shouldProceed = true;
86
		if (completedRequest instanceof DestroyRequest) {
87
			shouldProceed = shouldProceed((DestroyRequest) completedRequest);
88
		}
89
		if (shouldProceed) {
90
			if (completedRequest instanceof DestroyRequest) {
91
				TransactionalEditingDomain editingDomain = ((IGraphicalEditPart) getHost()).getEditingDomain();
92
				Command deleteViewCommand = new ICommandProxy(new DeleteCommand(editingDomain, (View) getHost().getModel()));
93
				ehCommand = ehCommand == null ? deleteViewCommand : ehCommand.chain(deleteViewCommand);
94
			}
95
			return ehCommand;
96
		}
97
		return null;
98
	}
99
100
	/**
101
	 * @generated
102
	 */
103
	protected Command getSemanticCommandSwitch(IEditCommandRequest req) {
104
		if (req instanceof CreateRelationshipRequest) {
105
			return getCreateRelationshipCommand((CreateRelationshipRequest) req);
106
		} else if (req instanceof CreateElementRequest) {
107
			return getCreateCommand((CreateElementRequest) req);
108
		} else if (req instanceof ConfigureRequest) {
109
			return getConfigureCommand((ConfigureRequest) req);
110
		} else if (req instanceof DestroyElementRequest) {
111
			return getDestroyElementCommand((DestroyElementRequest) req);
112
		} else if (req instanceof DestroyReferenceRequest) {
113
			return getDestroyReferenceCommand((DestroyReferenceRequest) req);
114
		} else if (req instanceof DuplicateElementsRequest) {
115
			return getDuplicateCommand((DuplicateElementsRequest) req);
116
		} else if (req instanceof GetEditContextRequest) {
117
			return getEditContextCommand((GetEditContextRequest) req);
118
		} else if (req instanceof MoveRequest) {
119
			return getMoveCommand((MoveRequest) req);
120
		} else if (req instanceof ReorientReferenceRelationshipRequest) {
121
			return getReorientReferenceRelationshipCommand((ReorientReferenceRelationshipRequest) req);
122
		} else if (req instanceof ReorientRelationshipRequest) {
123
			return getReorientRelationshipCommand((ReorientRelationshipRequest) req);
124
		} else if (req instanceof SetRequest) {
125
			return getSetCommand((SetRequest) req);
126
		}
127
		return null;
128
	}
129
130
	/**
131
	 * @generated
132
	 */
133
	protected Command getConfigureCommand(ConfigureRequest req) {
134
		return null;
135
	}
136
137
	/**
138
	 * @generated
139
	 */
140
	protected Command getCreateRelationshipCommand(CreateRelationshipRequest req) {
141
		return null;
142
	}
143
144
	/**
145
	 * @generated
146
	 */
147
	protected Command getCreateCommand(CreateElementRequest req) {
148
		return null;
149
	}
150
151
	/**
152
	 * @generated
153
	 */
154
	protected Command getSetCommand(SetRequest req) {
155
		return null;
156
	}
157
158
	/**
159
	 * @generated
160
	 */
161
	protected Command getEditContextCommand(GetEditContextRequest req) {
162
		return null;
163
	}
164
165
	/**
166
	 * @generated
167
	 */
168
	protected Command getDestroyElementCommand(DestroyElementRequest req) {
169
		return null;
170
	}
171
172
	/**
173
	 * @generated
174
	 */
175
	protected Command getDestroyReferenceCommand(DestroyReferenceRequest req) {
176
		return null;
177
	}
178
179
	/**
180
	 * @generated
181
	 */
182
	protected Command getDuplicateCommand(DuplicateElementsRequest req) {
183
		return null;
184
	}
185
186
	/**
187
	 * @generated
188
	 */
189
	protected Command getMoveCommand(MoveRequest req) {
190
		return null;
191
	}
192
193
	/**
194
	 * @generated
195
	 */
196
	protected Command getReorientReferenceRelationshipCommand(ReorientReferenceRelationshipRequest req) {
197
		return UnexecutableCommand.INSTANCE;
198
	}
199
200
	/**
201
	 * @generated
202
	 */
203
	protected Command getReorientRelationshipCommand(ReorientRelationshipRequest req) {
204
		return UnexecutableCommand.INSTANCE;
205
	}
206
207
	/**
208
	 * @generated
209
	 */
210
	protected Command getMSLWrapper(ICommand cmd) {
211
		return new ICommandProxy(cmd);
212
	}
213
214
	/**
215
	 * @generated
216
	 */
217
	protected EObject getSemanticElement() {
218
		return ViewUtil.resolveSemanticElement((View) getHost().getModel());
219
	}
220
221
	/**
222
	 * Finds container element for the new relationship of the specified type.
223
	 * Default implementation goes up by containment hierarchy starting from
224
	 * the specified element and returns the first element that is instance of
225
	 * the specified container class.
226
	 * 
227
	 * @generated
228
	 */
229
	protected EObject getRelationshipContainer(EObject element, EClass containerClass, IElementType relationshipType) {
230
		for (; element != null; element = element.eContainer()) {
231
			if (containerClass.isSuperTypeOf(element.eClass())) {
232
				return element;
233
			}
234
		}
235
		return null;
236
	}
237
238
	/**
239
	 * @generated 
240
	 */
241
	protected static class LinkConstraints {
242
243
		/**
244
		 * @generated 
245
		 */
246
		public static final LinkConstraints Usage_4009 = createUsage_4009();
247
248
		/**
249
		 * @generated 
250
		 */
251
		private static LinkConstraints createUsage_4009() {
252
			Map sourceEnv = new HashMap(3);
253
			sourceEnv.put("oppositeEnd", org.eclipse.uml2.uml.UMLPackage.eINSTANCE.getNamedElement()); //$NON-NLS-1$				
254
			UMLAbstractExpression sourceExpression = UMLOCLFactory.getExpression("self.oclIsKindOf(uml::Classifier)", //$NON-NLS-1$
255
					UMLPackage.eINSTANCE.getNamedElement(), sourceEnv);
256
			UMLAbstractExpression targetExpression = null;
257
			return new LinkConstraints(sourceExpression, targetExpression);
258
		}
259
260
		/**
261
		 * @generated 
262
		 */
263
		private static final String OPPOSITE_END_VAR = "oppositeEnd"; //$NON-NLS-1$
264
265
		/**
266
		 * @generated 
267
		 */
268
		private UMLAbstractExpression srcEndInv;
269
270
		/**
271
		 * @generated 
272
		 */
273
		private UMLAbstractExpression targetEndInv;
274
275
		/**
276
		 * @generated 
277
		 */
278
		public LinkConstraints(UMLAbstractExpression sourceEnd, UMLAbstractExpression targetEnd) {
279
			this.srcEndInv = sourceEnd;
280
			this.targetEndInv = targetEnd;
281
		}
282
283
		/**
284
		 * @generated 
285
		 */
286
		public boolean canCreateLink(CreateRelationshipRequest req, boolean isBackDirected) {
287
			Object source = req.getSource();
288
			Object target = req.getTarget();
289
290
			UMLAbstractExpression sourceConstraint = isBackDirected ? targetEndInv : srcEndInv;
291
			UMLAbstractExpression targetConstraint = null;
292
			if (req.getTarget() != null) {
293
				targetConstraint = isBackDirected ? srcEndInv : targetEndInv;
294
			}
295
			boolean isSourceAccepted = sourceConstraint != null ? evaluate(sourceConstraint, source, target, false) : true;
296
			if (isSourceAccepted && targetConstraint != null) {
297
				return evaluate(targetConstraint, target, source, true);
298
			}
299
			return isSourceAccepted;
300
		}
301
302
		/**
303
		 * @generated 
304
		 */
305
		private static boolean evaluate(UMLAbstractExpression constraint, Object sourceEnd, Object oppositeEnd, boolean clearEnv) {
306
			Map evalEnv = Collections.singletonMap(OPPOSITE_END_VAR, oppositeEnd);
307
			try {
308
				Object val = constraint.evaluate(sourceEnd, evalEnv);
309
				return (val instanceof Boolean) ? ((Boolean) val).booleanValue() : false;
310
			} catch (Exception e) {
311
				UMLDiagramEditorPlugin.getInstance().logError("Link constraint evaluation error", e); //$NON-NLS-1$
312
				return false;
313
			}
314
		}
315
	}
316
317
	/**
318
	 * @NOT-GENERATED
319
	 */
320
	protected static abstract class CreateAssociationCommand extends CreateRelationshipCommand {
321
322
		public CreateAssociationCommand(CreateRelationshipRequest request) {
323
			super(request);
324
		}
325
326
		protected EObject doDefaultElementCreation() {
327
			Type sourceType = (Type) getSource();
328
			Type targetType = (Type) getTarget();
329
330
			//due to association end conventiontions (see AssociationEndConvention) 
331
			//we need to have member end of type SourceType to be the first one created
332
			//thus, we are calling UML2 createAssociation() in opposite order
333
			Association result = targetType.createAssociation(//
334
					false, AggregationKind.NONE_LITERAL, "src", 1, 1, // 
335
					sourceType, false, AggregationKind.NONE_LITERAL, "dst", 1, 1);
336
337
			return result;
338
		}
339
340
	}
341
342
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/policies/Property4ItemSemanticEditPolicy.java (+255 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.policies;
2
3
import org.eclipse.emf.ecore.EAnnotation;
4
import org.eclipse.emf.ecore.EClass;
5
import org.eclipse.emf.ecore.EObject;
6
import org.eclipse.gef.commands.Command;
7
import org.eclipse.gef.commands.UnexecutableCommand;
8
import org.eclipse.gmf.runtime.emf.type.core.commands.CreateRelationshipCommand;
9
import org.eclipse.gmf.runtime.emf.type.core.commands.DestroyElementCommand;
10
import org.eclipse.gmf.runtime.emf.type.core.commands.SetValueCommand;
11
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest;
12
import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest;
13
import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest;
14
import org.eclipse.gmf.runtime.notation.View;
15
import org.eclipse.uml2.diagram.clazz.providers.UMLElementTypes;
16
import org.eclipse.uml2.uml.Constraint;
17
import org.eclipse.uml2.uml.Dependency;
18
import org.eclipse.uml2.uml.NamedElement;
19
import org.eclipse.uml2.uml.UMLPackage;
20
import org.eclipse.uml2.uml.Usage;
21
22
/**
23
 * @generated
24
 */
25
public class Property4ItemSemanticEditPolicy extends UMLBaseItemSemanticEditPolicy {
26
27
	/**
28
	 * @generated
29
	 */
30
	protected Command getDestroyElementCommand(DestroyElementRequest req) {
31
		return getMSLWrapper(new DestroyElementCommand(req) {
32
33
			protected EObject getElementToDestroy() {
34
				View view = (View) getHost().getModel();
35
				EAnnotation annotation = view.getEAnnotation("Shortcut"); //$NON-NLS-1$
36
				if (annotation != null) {
37
					return view;
38
				}
39
				return super.getElementToDestroy();
40
			}
41
42
		});
43
	}
44
45
	/**
46
	 * @generated
47
	 */
48
	protected Command getCreateRelationshipCommand(CreateRelationshipRequest req) {
49
		if (UMLElementTypes.Dependency_4002 == req.getElementType()) {
50
			return req.getTarget() == null ? getCreateStartOutgoingDependency4002Command(req) : getCreateCompleteIncomingDependency4002Command(req);
51
		}
52
		if (UMLElementTypes.ConstraintConstrainedElement_4004 == req.getElementType()) {
53
			return req.getTarget() == null ? null : getCreateCompleteIncomingConstraint_ConstrainedElement4004Command(req);
54
		}
55
		if (UMLElementTypes.DependencySupplier_4006 == req.getElementType()) {
56
			return req.getTarget() == null ? null : getCreateCompleteIncomingDependency_Supplier4006Command(req);
57
		}
58
		if (UMLElementTypes.DependencyClient_4007 == req.getElementType()) {
59
			return req.getTarget() == null ? null : getCreateCompleteIncomingDependency_Client4007Command(req);
60
		}
61
		if (UMLElementTypes.Usage_4009 == req.getElementType()) {
62
			return req.getTarget() == null ? getCreateStartOutgoingUsage4009Command(req) : getCreateCompleteIncomingUsage4009Command(req);
63
		}
64
		return super.getCreateRelationshipCommand(req);
65
	}
66
67
	/**
68
	 * @generated
69
	 */
70
	protected Command getCreateStartOutgoingDependency4002Command(CreateRelationshipRequest req) {
71
		return new Command() {
72
		};
73
	}
74
75
	/**
76
	 * @generated
77
	 */
78
	protected Command getCreateCompleteIncomingDependency4002Command(CreateRelationshipRequest req) {
79
		if (!(req.getSource() instanceof NamedElement)) {
80
			return UnexecutableCommand.INSTANCE;
81
		}
82
		final org.eclipse.uml2.uml.Package element = (org.eclipse.uml2.uml.Package) getRelationshipContainer(req.getSource(), UMLPackage.eINSTANCE.getPackage(), req.getElementType());
83
		if (element == null) {
84
			return UnexecutableCommand.INSTANCE;
85
		}
86
		if (req.getContainmentFeature() == null) {
87
			req.setContainmentFeature(UMLPackage.eINSTANCE.getPackage_PackagedElement());
88
		}
89
		return getMSLWrapper(new CreateIncomingDependency4002Command(req) {
90
91
			protected EObject getElementToEdit() {
92
				return element;
93
			}
94
		});
95
	}
96
97
	/**
98
	 * @generated
99
	 */
100
	private static class CreateIncomingDependency4002Command extends CreateRelationshipCommand {
101
102
		/**
103
		 * @generated
104
		 */
105
		public CreateIncomingDependency4002Command(CreateRelationshipRequest req) {
106
			super(req);
107
		}
108
109
		/**
110
		 * @generated
111
		 */
112
		protected EClass getEClassToEdit() {
113
			return UMLPackage.eINSTANCE.getPackage();
114
		};
115
116
		/**
117
		 * @generated
118
		 */
119
		protected void setElementToEdit(EObject element) {
120
			throw new UnsupportedOperationException();
121
		}
122
123
		/**
124
		 * @generated
125
		 */
126
		protected EObject doDefaultElementCreation() {
127
			Dependency newElement = (Dependency) super.doDefaultElementCreation();
128
			if (newElement != null) {
129
				newElement.getSuppliers().add((NamedElement) getTarget());
130
				newElement.getClients().add((NamedElement) getSource());
131
			}
132
			return newElement;
133
		}
134
	}
135
136
	/**
137
	 * @generated
138
	 */
139
	protected Command getCreateCompleteIncomingConstraint_ConstrainedElement4004Command(CreateRelationshipRequest req) {
140
		if (!(req.getSource() instanceof Constraint)) {
141
			return UnexecutableCommand.INSTANCE;
142
		}
143
		Constraint element = (Constraint) req.getSource();
144
		if (element.getConstrainedElements().contains(req.getTarget())) {
145
			return UnexecutableCommand.INSTANCE;
146
		}
147
		SetRequest setReq = new SetRequest(req.getSource(), UMLPackage.eINSTANCE.getConstraint_ConstrainedElement(), req.getTarget());
148
		return getMSLWrapper(new SetValueCommand(setReq));
149
	}
150
151
	/**
152
	 * @generated
153
	 */
154
	protected Command getCreateCompleteIncomingDependency_Supplier4006Command(CreateRelationshipRequest req) {
155
		if (!(req.getSource() instanceof Dependency)) {
156
			return UnexecutableCommand.INSTANCE;
157
		}
158
		Dependency element = (Dependency) req.getSource();
159
		if (element.getSuppliers().contains(req.getTarget())) {
160
			return UnexecutableCommand.INSTANCE;
161
		}
162
		SetRequest setReq = new SetRequest(req.getSource(), UMLPackage.eINSTANCE.getDependency_Supplier(), req.getTarget());
163
		return getMSLWrapper(new SetValueCommand(setReq));
164
	}
165
166
	/**
167
	 * @generated
168
	 */
169
	protected Command getCreateCompleteIncomingDependency_Client4007Command(CreateRelationshipRequest req) {
170
		if (!(req.getSource() instanceof Dependency)) {
171
			return UnexecutableCommand.INSTANCE;
172
		}
173
		Dependency element = (Dependency) req.getSource();
174
		if (element.getClients().contains(req.getTarget())) {
175
			return UnexecutableCommand.INSTANCE;
176
		}
177
		SetRequest setReq = new SetRequest(req.getSource(), UMLPackage.eINSTANCE.getDependency_Client(), req.getTarget());
178
		return getMSLWrapper(new SetValueCommand(setReq));
179
	}
180
181
	/**
182
	 * @generated
183
	 */
184
	protected Command getCreateStartOutgoingUsage4009Command(CreateRelationshipRequest req) {
185
		if (!UMLBaseItemSemanticEditPolicy.LinkConstraints.Usage_4009.canCreateLink(req, false)) {
186
			return UnexecutableCommand.INSTANCE;
187
		}
188
		return new Command() {
189
		};
190
	}
191
192
	/**
193
	 * @generated
194
	 */
195
	protected Command getCreateCompleteIncomingUsage4009Command(CreateRelationshipRequest req) {
196
		if (!(req.getSource() instanceof NamedElement)) {
197
			return UnexecutableCommand.INSTANCE;
198
		}
199
		final org.eclipse.uml2.uml.Package element = (org.eclipse.uml2.uml.Package) getRelationshipContainer(req.getSource(), UMLPackage.eINSTANCE.getPackage(), req.getElementType());
200
		if (element == null) {
201
			return UnexecutableCommand.INSTANCE;
202
		}
203
		if (!UMLBaseItemSemanticEditPolicy.LinkConstraints.Usage_4009.canCreateLink(req, false)) {
204
			return UnexecutableCommand.INSTANCE;
205
		}
206
		if (req.getContainmentFeature() == null) {
207
			req.setContainmentFeature(UMLPackage.eINSTANCE.getPackage_PackagedElement());
208
		}
209
		return getMSLWrapper(new CreateIncomingUsage4009Command(req) {
210
211
			protected EObject getElementToEdit() {
212
				return element;
213
			}
214
		});
215
	}
216
217
	/**
218
	 * @generated
219
	 */
220
	private static class CreateIncomingUsage4009Command extends CreateRelationshipCommand {
221
222
		/**
223
		 * @generated
224
		 */
225
		public CreateIncomingUsage4009Command(CreateRelationshipRequest req) {
226
			super(req);
227
		}
228
229
		/**
230
		 * @generated
231
		 */
232
		protected EClass getEClassToEdit() {
233
			return UMLPackage.eINSTANCE.getPackage();
234
		};
235
236
		/**
237
		 * @generated
238
		 */
239
		protected void setElementToEdit(EObject element) {
240
			throw new UnsupportedOperationException();
241
		}
242
243
		/**
244
		 * @generated
245
		 */
246
		protected EObject doDefaultElementCreation() {
247
			Usage newElement = (Usage) super.doDefaultElementCreation();
248
			if (newElement != null) {
249
				newElement.getSuppliers().add((NamedElement) getTarget());
250
				newElement.getClients().add((NamedElement) getSource());
251
			}
252
			return newElement;
253
		}
254
	}
255
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/policies/DataTypeAttributesItemSemanticEditPolicy.java (+73 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.policies;
2
3
import org.eclipse.emf.ecore.EClass;
4
import org.eclipse.emf.ecore.EObject;
5
import org.eclipse.gef.commands.Command;
6
import org.eclipse.gmf.runtime.emf.type.core.commands.CreateElementCommand;
7
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest;
8
import org.eclipse.gmf.runtime.notation.View;
9
import org.eclipse.uml2.diagram.clazz.providers.UMLElementTypes;
10
import org.eclipse.uml2.uml.Property;
11
import org.eclipse.uml2.uml.UMLPackage;
12
13
/**
14
 * @generated
15
 */
16
public class DataTypeAttributesItemSemanticEditPolicy extends UMLBaseItemSemanticEditPolicy {
17
18
	/**
19
	 * @generated
20
	 */
21
	protected Command getCreateCommand(CreateElementRequest req) {
22
		if (UMLElementTypes.Property_3014 == req.getElementType()) {
23
			if (req.getContainmentFeature() == null) {
24
				req.setContainmentFeature(UMLPackage.eINSTANCE.getDataType_OwnedAttribute());
25
			}
26
			return getMSLWrapper(new CreateProperty_3014Command(req));
27
		}
28
		return super.getCreateCommand(req);
29
	}
30
31
	/**
32
	 * @generated
33
	 */
34
	private static class CreateProperty_3014Command extends CreateElementCommand {
35
36
		/**
37
		 * @generated
38
		 */
39
		public CreateProperty_3014Command(CreateElementRequest req) {
40
			super(req);
41
		}
42
43
		/**
44
		 * @generated
45
		 */
46
		protected EClass getEClassToEdit() {
47
			return UMLPackage.eINSTANCE.getDataType();
48
		};
49
50
		/**
51
		 * @generated
52
		 */
53
		protected EObject getElementToEdit() {
54
			EObject container = ((CreateElementRequest) getRequest()).getContainer();
55
			if (container instanceof View) {
56
				container = ((View) container).getElement();
57
			}
58
			return container;
59
		}
60
61
		/**
62
		 * @generated
63
		 */
64
		protected EObject doDefaultElementCreation() {
65
			Property newElement = (Property) super.doDefaultElementCreation();
66
			if (newElement != null) {
67
				UMLElementTypes.Initializers.Property_3014.init(newElement);
68
			}
69
			return newElement;
70
		}
71
	}
72
73
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/policies/ConstraintCompartmentCanonicalEditPolicy.java (+49 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.policies;
2
3
import java.util.LinkedList;
4
import java.util.List;
5
6
import org.eclipse.emf.ecore.EObject;
7
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.CanonicalEditPolicy;
8
import org.eclipse.gmf.runtime.notation.View;
9
import org.eclipse.uml2.diagram.clazz.edit.parts.LiteralStringEditPart;
10
import org.eclipse.uml2.diagram.clazz.part.UMLVisualIDRegistry;
11
import org.eclipse.uml2.uml.Constraint;
12
13
/**
14
 * @generated
15
 */
16
public class ConstraintCompartmentCanonicalEditPolicy extends CanonicalEditPolicy {
17
18
	/**
19
	 * @generated
20
	 */
21
	protected List getSemanticChildrenList() {
22
		List result = new LinkedList();
23
		EObject modelObject = ((View) getHost().getModel()).getElement();
24
		View viewObject = (View) getHost().getModel();
25
		EObject nextValue;
26
		int nodeVID;
27
		nextValue = ((Constraint) modelObject).getSpecification();
28
		nodeVID = UMLVisualIDRegistry.getNodeVisualID(viewObject, nextValue);
29
		if (LiteralStringEditPart.VISUAL_ID == nodeVID) {
30
			result.add(nextValue);
31
		}
32
		return result;
33
	}
34
35
	/**
36
	 * @generated
37
	 */
38
	protected boolean shouldDeleteView(View view) {
39
		return view.isSetElement() && view.getElement() != null && view.getElement().eIsProxy();
40
	}
41
42
	/**
43
	 * @generated
44
	 */
45
	protected String getDefaultFactoryHint() {
46
		return null;
47
	}
48
49
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/parts/DataTypeEditPart.java (+553 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.parts;
2
3
import java.util.Collections;
4
import java.util.List;
5
6
import org.eclipse.draw2d.IFigure;
7
import org.eclipse.draw2d.Label;
8
import org.eclipse.draw2d.geometry.Point;
9
import org.eclipse.emf.common.notify.Notification;
10
import org.eclipse.emf.ecore.EObject;
11
import org.eclipse.emf.transaction.RunnableWithResult;
12
import org.eclipse.gef.AccessibleEditPart;
13
import org.eclipse.gef.DragTracker;
14
import org.eclipse.gef.EditPolicy;
15
import org.eclipse.gef.Request;
16
import org.eclipse.gef.requests.DirectEditRequest;
17
import org.eclipse.gef.requests.SelectionRequest;
18
import org.eclipse.gef.tools.DirectEditManager;
19
import org.eclipse.gmf.runtime.common.ui.services.parser.IParser;
20
import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus;
21
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserEditStatus;
22
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions;
23
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserService;
24
import org.eclipse.gmf.runtime.diagram.ui.editparts.CompartmentEditPart;
25
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
26
import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart;
27
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
28
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy;
29
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.ListItemComponentEditPolicy;
30
import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry;
31
import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants;
32
import org.eclipse.gmf.runtime.diagram.ui.tools.DragEditPartsTrackerEx;
33
import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager;
34
import org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel;
35
import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
36
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
37
import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser;
38
import org.eclipse.gmf.runtime.emf.ui.services.parser.ParserHintAdapter;
39
import org.eclipse.gmf.runtime.notation.FontStyle;
40
import org.eclipse.gmf.runtime.notation.NotationPackage;
41
import org.eclipse.gmf.runtime.notation.View;
42
import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
43
import org.eclipse.jface.viewers.ICellEditorValidator;
44
import org.eclipse.swt.SWT;
45
import org.eclipse.swt.accessibility.AccessibleEvent;
46
import org.eclipse.swt.graphics.Color;
47
import org.eclipse.swt.graphics.FontData;
48
import org.eclipse.swt.graphics.Image;
49
import org.eclipse.uml2.diagram.clazz.edit.policies.DataTypeItemSemanticEditPolicy;
50
import org.eclipse.uml2.diagram.clazz.edit.policies.UMLTextNonResizableEditPolicy;
51
import org.eclipse.uml2.diagram.clazz.edit.policies.UMLTextSelectionEditPolicy;
52
import org.eclipse.uml2.diagram.clazz.providers.UMLElementTypes;
53
54
/**
55
 * @generated
56
 */
57
public class DataTypeEditPart extends CompartmentEditPart implements ITextAwareEditPart {
58
59
	/**
60
	 * @generated
61
	 */
62
	public static final int VISUAL_ID = 3008;
63
64
	/**
65
	 * @generated
66
	 */
67
	private DirectEditManager manager;
68
69
	/**
70
	 * @generated
71
	 */
72
	private IParser parser;
73
74
	/**
75
	 * @generated
76
	 */
77
	private List parserElements;
78
79
	/**
80
	 * @generated
81
	 */
82
	private String defaultText;
83
84
	/**
85
	 * @generated
86
	 */
87
	public DataTypeEditPart(View view) {
88
		super(view);
89
	}
90
91
	/**
92
	 * @generated
93
	 */
94
	public DragTracker getDragTracker(Request request) {
95
		if (request instanceof SelectionRequest && ((SelectionRequest) request).getLastButtonPressed() == 3) {
96
			return null;
97
		}
98
		return new DragEditPartsTrackerEx(this);
99
	}
100
101
	/**
102
	 * @generated
103
	 */
104
	protected void createDefaultEditPolicies() {
105
		super.createDefaultEditPolicies();
106
		installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new DataTypeItemSemanticEditPolicy());
107
		installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new UMLTextNonResizableEditPolicy());
108
		installEditPolicy(EditPolicy.COMPONENT_ROLE, new ListItemComponentEditPolicy());
109
		installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy());
110
111
	}
112
113
	/**
114
	 * @generated
115
	 */
116
	protected String getLabelTextHelper(IFigure figure) {
117
		if (figure instanceof WrapLabel) {
118
			return ((WrapLabel) figure).getText();
119
		} else {
120
			return ((Label) figure).getText();
121
		}
122
	}
123
124
	/**
125
	 * @generated
126
	 */
127
	protected void setLabelTextHelper(IFigure figure, String text) {
128
		if (figure instanceof WrapLabel) {
129
			((WrapLabel) figure).setText(text);
130
		} else {
131
			((Label) figure).setText(text);
132
		}
133
	}
134
135
	/**
136
	 * @generated
137
	 */
138
	protected Image getLabelIconHelper(IFigure figure) {
139
		if (figure instanceof WrapLabel) {
140
			return ((WrapLabel) figure).getIcon();
141
		} else {
142
			return ((Label) figure).getIcon();
143
		}
144
	}
145
146
	/**
147
	 * @generated
148
	 */
149
	protected void setLabelIconHelper(IFigure figure, Image icon) {
150
		if (figure instanceof WrapLabel) {
151
			((WrapLabel) figure).setIcon(icon);
152
		} else {
153
			((Label) figure).setIcon(icon);
154
		}
155
	}
156
157
	/**
158
	 * @generated
159
	 */
160
	public void setLabel(IFigure figure) {
161
		unregisterVisuals();
162
		setFigure(figure);
163
		defaultText = getLabelTextHelper(figure);
164
		registerVisuals();
165
		refreshVisuals();
166
	}
167
168
	/**
169
	 * @generated
170
	 */
171
	protected List getModelChildren() {
172
		return Collections.EMPTY_LIST;
173
	}
174
175
	/**
176
	 * @generated
177
	 */
178
	public IGraphicalEditPart getChildBySemanticHint(String semanticHint) {
179
		return null;
180
	}
181
182
	/**
183
	 * @generated
184
	 */
185
	protected EObject getParserElement() {
186
		EObject element = resolveSemanticElement();
187
		return element != null ? element : (View) getModel();
188
	}
189
190
	/**
191
	 * @generated
192
	 */
193
	protected Image getLabelIcon() {
194
		return null;
195
	}
196
197
	/**
198
	 * @generated
199
	 */
200
	protected String getLabelText() {
201
		String text = null;
202
		if (getParser() != null) {
203
			text = getParser().getPrintString(new EObjectAdapter(getParserElement()), getParserOptions().intValue());
204
		}
205
		if (text == null || text.length() == 0) {
206
			text = defaultText;
207
		}
208
		return text;
209
	}
210
211
	/**
212
	 * @generated
213
	 */
214
	public void setLabelText(String text) {
215
		setLabelTextHelper(getFigure(), text);
216
		Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
217
		if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) {
218
			((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback();
219
		}
220
	}
221
222
	/**
223
	 * @generated
224
	 */
225
	public String getEditText() {
226
		if (getParser() == null) {
227
			return ""; //$NON-NLS-1$
228
		}
229
		return getParser().getEditString(new EObjectAdapter(getParserElement()), getParserOptions().intValue());
230
	}
231
232
	/**
233
	 * @generated
234
	 */
235
	protected boolean isEditable() {
236
		return getEditText() != null;
237
	}
238
239
	/**
240
	 * @generated
241
	 */
242
	public ICellEditorValidator getEditTextValidator() {
243
		return new ICellEditorValidator() {
244
245
			public String isValid(final Object value) {
246
				if (value instanceof String) {
247
					final EObject element = getParserElement();
248
					final IParser parser = getParser();
249
					try {
250
						IParserEditStatus valid = (IParserEditStatus) getEditingDomain().runExclusive(new RunnableWithResult.Impl() {
251
252
							public void run() {
253
								setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value));
254
							}
255
						});
256
						return valid.getCode() == ParserEditStatus.EDITABLE ? null : valid.getMessage();
257
					} catch (InterruptedException ie) {
258
						ie.printStackTrace();
259
					}
260
				}
261
262
				// shouldn't get here
263
				return null;
264
			}
265
		};
266
	}
267
268
	/**
269
	 * @generated
270
	 */
271
	public IContentAssistProcessor getCompletionProcessor() {
272
		if (getParser() == null) {
273
			return null;
274
		}
275
		return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement()));
276
	}
277
278
	/**
279
	 * @generated
280
	 */
281
	public ParserOptions getParserOptions() {
282
		return ParserOptions.NONE;
283
	}
284
285
	/**
286
	 * @generated
287
	 */
288
	public IParser getParser() {
289
		if (parser == null) {
290
			String parserHint = ((View) getModel()).getType();
291
			ParserHintAdapter hintAdapter = new ParserHintAdapter(getParserElement(), parserHint) {
292
293
				public Object getAdapter(Class adapter) {
294
					if (IElementType.class.equals(adapter)) {
295
						return UMLElementTypes.DataType_3008;
296
					}
297
					return super.getAdapter(adapter);
298
				}
299
			};
300
			parser = ParserService.getInstance().getParser(hintAdapter);
301
		}
302
		return parser;
303
	}
304
305
	/**
306
	 * @generated
307
	 */
308
	protected DirectEditManager getManager() {
309
		if (manager == null) {
310
			setManager(new TextDirectEditManager(this, TextDirectEditManager.getTextCellEditorClass(this), UMLEditPartFactory.getTextCellEditorLocator(this)));
311
		}
312
		return manager;
313
	}
314
315
	/**
316
	 * @generated
317
	 */
318
	protected void setManager(DirectEditManager manager) {
319
		this.manager = manager;
320
	}
321
322
	/**
323
	 * @generated
324
	 */
325
	protected void performDirectEdit() {
326
		getManager().show();
327
	}
328
329
	/**
330
	 * @generated
331
	 */
332
	protected void performDirectEdit(Point eventLocation) {
333
		if (getManager().getClass() == TextDirectEditManager.class) {
334
			((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint());
335
		}
336
	}
337
338
	/**
339
	 * @generated
340
	 */
341
	private void performDirectEdit(char initialCharacter) {
342
		if (getManager() instanceof TextDirectEditManager) {
343
			((TextDirectEditManager) getManager()).show(initialCharacter);
344
		} else {
345
			performDirectEdit();
346
		}
347
	}
348
349
	/**
350
	 * @generated
351
	 */
352
	protected void performDirectEditRequest(Request request) {
353
		final Request theRequest = request;
354
		try {
355
			getEditingDomain().runExclusive(new Runnable() {
356
357
				public void run() {
358
					if (isActive() && isEditable()) {
359
						if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) {
360
							Character initialChar = (Character) theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR);
361
							performDirectEdit(initialChar.charValue());
362
						} else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) {
363
							DirectEditRequest editRequest = (DirectEditRequest) theRequest;
364
							performDirectEdit(editRequest.getLocation());
365
						} else {
366
							performDirectEdit();
367
						}
368
					}
369
				}
370
			});
371
		} catch (InterruptedException e) {
372
			e.printStackTrace();
373
		}
374
	}
375
376
	/**
377
	 * @generated
378
	 */
379
	protected void refreshVisuals() {
380
		super.refreshVisuals();
381
		refreshLabel();
382
		refreshFont();
383
		refreshFontColor();
384
		refreshUnderline();
385
		refreshStrikeThrough();
386
	}
387
388
	/**
389
	 * @generated
390
	 */
391
	protected void refreshLabel() {
392
		setLabelTextHelper(getFigure(), getLabelText());
393
		setLabelIconHelper(getFigure(), getLabelIcon());
394
		Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
395
		if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) {
396
			((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback();
397
		}
398
	}
399
400
	/**
401
	 * @generated
402
	 */
403
	protected void refreshUnderline() {
404
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
405
		if (style != null && getFigure() instanceof WrapLabel) {
406
			((WrapLabel) getFigure()).setTextUnderline(style.isUnderline());
407
		}
408
	}
409
410
	/**
411
	 * @generated
412
	 */
413
	protected void refreshStrikeThrough() {
414
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
415
		if (style != null && getFigure() instanceof WrapLabel) {
416
			((WrapLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough());
417
		}
418
	}
419
420
	/**
421
	 * @generated
422
	 */
423
	protected void refreshFont() {
424
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
425
		if (style != null) {
426
			FontData fontData = new FontData(style.getFontName(), style.getFontHeight(), (style.isBold() ? SWT.BOLD : SWT.NORMAL) | (style.isItalic() ? SWT.ITALIC : SWT.NORMAL));
427
			setFont(fontData);
428
		}
429
	}
430
431
	/**
432
	 * @generated
433
	 */
434
	protected void setFontColor(Color color) {
435
		getFigure().setForegroundColor(color);
436
	}
437
438
	/**
439
	 * @generated
440
	 */
441
	protected void addSemanticListeners() {
442
		if (getParser() instanceof ISemanticParser) {
443
			EObject element = resolveSemanticElement();
444
			parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element);
445
			for (int i = 0; i < parserElements.size(); i++) {
446
				addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$
447
			}
448
		} else {
449
			super.addSemanticListeners();
450
		}
451
	}
452
453
	/**
454
	 * @generated
455
	 */
456
	protected void removeSemanticListeners() {
457
		if (parserElements != null) {
458
			for (int i = 0; i < parserElements.size(); i++) {
459
				removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$
460
			}
461
		} else {
462
			super.removeSemanticListeners();
463
		}
464
	}
465
466
	/**
467
	 * @generated
468
	 */
469
	protected AccessibleEditPart getAccessibleEditPart() {
470
		if (accessibleEP == null) {
471
			accessibleEP = new AccessibleGraphicalEditPart() {
472
473
				public void getName(AccessibleEvent e) {
474
					e.result = getLabelTextHelper(getFigure());
475
				}
476
			};
477
		}
478
		return accessibleEP;
479
	}
480
481
	/**
482
	 * @generated
483
	 */
484
	private View getFontStyleOwnerView() {
485
		return getPrimaryView();
486
	}
487
488
	/**
489
	 * @generated
490
	 */
491
	protected void addNotationalListeners() {
492
		super.addNotationalListeners();
493
		addListenerFilter("PrimaryView", this, getPrimaryView()); //$NON-NLS-1$
494
	}
495
496
	/**
497
	 * @generated
498
	 */
499
	protected void removeNotationalListeners() {
500
		super.removeNotationalListeners();
501
		removeListenerFilter("PrimaryView"); //$NON-NLS-1$
502
	}
503
504
	/**
505
	 * @generated
506
	 */
507
	protected void handleNotificationEvent(Notification event) {
508
		Object feature = event.getFeature();
509
		if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) {
510
			Integer c = (Integer) event.getNewValue();
511
			setFontColor(DiagramColorRegistry.getInstance().getColor(c));
512
		} else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) {
513
			refreshUnderline();
514
		} else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) {
515
			refreshStrikeThrough();
516
		} else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature)
517
				|| NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) {
518
			refreshFont();
519
		} else {
520
			if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) {
521
				refreshLabel();
522
			}
523
			if (getParser() instanceof ISemanticParser) {
524
				ISemanticParser modelParser = (ISemanticParser) getParser();
525
				if (modelParser.areSemanticElementsAffected(null, event)) {
526
					removeSemanticListeners();
527
					if (resolveSemanticElement() != null) {
528
						addSemanticListeners();
529
					}
530
					refreshLabel();
531
				}
532
			}
533
		}
534
		super.handleNotificationEvent(event);
535
	}
536
537
	/**
538
	 * @generated
539
	 */
540
	protected IFigure createFigure() {
541
		IFigure label = createFigurePrim();
542
		defaultText = getLabelTextHelper(label);
543
		return label;
544
	}
545
546
	/**
547
	 * @generated
548
	 */
549
	protected IFigure createFigurePrim() {
550
		return new WrapLabel();
551
	}
552
553
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/parts/PropertyEditPart.java (+553 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.parts;
2
3
import java.util.Collections;
4
import java.util.List;
5
6
import org.eclipse.draw2d.IFigure;
7
import org.eclipse.draw2d.Label;
8
import org.eclipse.draw2d.geometry.Point;
9
import org.eclipse.emf.common.notify.Notification;
10
import org.eclipse.emf.ecore.EObject;
11
import org.eclipse.emf.transaction.RunnableWithResult;
12
import org.eclipse.gef.AccessibleEditPart;
13
import org.eclipse.gef.DragTracker;
14
import org.eclipse.gef.EditPolicy;
15
import org.eclipse.gef.Request;
16
import org.eclipse.gef.requests.DirectEditRequest;
17
import org.eclipse.gef.requests.SelectionRequest;
18
import org.eclipse.gef.tools.DirectEditManager;
19
import org.eclipse.gmf.runtime.common.ui.services.parser.IParser;
20
import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus;
21
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserEditStatus;
22
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions;
23
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserService;
24
import org.eclipse.gmf.runtime.diagram.ui.editparts.CompartmentEditPart;
25
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
26
import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart;
27
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
28
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy;
29
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.ListItemComponentEditPolicy;
30
import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry;
31
import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants;
32
import org.eclipse.gmf.runtime.diagram.ui.tools.DragEditPartsTrackerEx;
33
import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager;
34
import org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel;
35
import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
36
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
37
import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser;
38
import org.eclipse.gmf.runtime.emf.ui.services.parser.ParserHintAdapter;
39
import org.eclipse.gmf.runtime.notation.FontStyle;
40
import org.eclipse.gmf.runtime.notation.NotationPackage;
41
import org.eclipse.gmf.runtime.notation.View;
42
import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
43
import org.eclipse.jface.viewers.ICellEditorValidator;
44
import org.eclipse.swt.SWT;
45
import org.eclipse.swt.accessibility.AccessibleEvent;
46
import org.eclipse.swt.graphics.Color;
47
import org.eclipse.swt.graphics.FontData;
48
import org.eclipse.swt.graphics.Image;
49
import org.eclipse.uml2.diagram.clazz.edit.policies.PropertyItemSemanticEditPolicy;
50
import org.eclipse.uml2.diagram.clazz.edit.policies.UMLTextNonResizableEditPolicy;
51
import org.eclipse.uml2.diagram.clazz.edit.policies.UMLTextSelectionEditPolicy;
52
import org.eclipse.uml2.diagram.clazz.providers.UMLElementTypes;
53
54
/**
55
 * @generated
56
 */
57
public class PropertyEditPart extends CompartmentEditPart implements ITextAwareEditPart {
58
59
	/**
60
	 * @generated
61
	 */
62
	public static final int VISUAL_ID = 3001;
63
64
	/**
65
	 * @generated
66
	 */
67
	private DirectEditManager manager;
68
69
	/**
70
	 * @generated
71
	 */
72
	private IParser parser;
73
74
	/**
75
	 * @generated
76
	 */
77
	private List parserElements;
78
79
	/**
80
	 * @generated
81
	 */
82
	private String defaultText;
83
84
	/**
85
	 * @generated
86
	 */
87
	public PropertyEditPart(View view) {
88
		super(view);
89
	}
90
91
	/**
92
	 * @generated
93
	 */
94
	public DragTracker getDragTracker(Request request) {
95
		if (request instanceof SelectionRequest && ((SelectionRequest) request).getLastButtonPressed() == 3) {
96
			return null;
97
		}
98
		return new DragEditPartsTrackerEx(this);
99
	}
100
101
	/**
102
	 * @generated
103
	 */
104
	protected void createDefaultEditPolicies() {
105
		super.createDefaultEditPolicies();
106
		installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new PropertyItemSemanticEditPolicy());
107
		installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new UMLTextNonResizableEditPolicy());
108
		installEditPolicy(EditPolicy.COMPONENT_ROLE, new ListItemComponentEditPolicy());
109
		installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy());
110
111
	}
112
113
	/**
114
	 * @generated
115
	 */
116
	protected String getLabelTextHelper(IFigure figure) {
117
		if (figure instanceof WrapLabel) {
118
			return ((WrapLabel) figure).getText();
119
		} else {
120
			return ((Label) figure).getText();
121
		}
122
	}
123
124
	/**
125
	 * @generated
126
	 */
127
	protected void setLabelTextHelper(IFigure figure, String text) {
128
		if (figure instanceof WrapLabel) {
129
			((WrapLabel) figure).setText(text);
130
		} else {
131
			((Label) figure).setText(text);
132
		}
133
	}
134
135
	/**
136
	 * @generated
137
	 */
138
	protected Image getLabelIconHelper(IFigure figure) {
139
		if (figure instanceof WrapLabel) {
140
			return ((WrapLabel) figure).getIcon();
141
		} else {
142
			return ((Label) figure).getIcon();
143
		}
144
	}
145
146
	/**
147
	 * @generated
148
	 */
149
	protected void setLabelIconHelper(IFigure figure, Image icon) {
150
		if (figure instanceof WrapLabel) {
151
			((WrapLabel) figure).setIcon(icon);
152
		} else {
153
			((Label) figure).setIcon(icon);
154
		}
155
	}
156
157
	/**
158
	 * @generated
159
	 */
160
	public void setLabel(IFigure figure) {
161
		unregisterVisuals();
162
		setFigure(figure);
163
		defaultText = getLabelTextHelper(figure);
164
		registerVisuals();
165
		refreshVisuals();
166
	}
167
168
	/**
169
	 * @generated
170
	 */
171
	protected List getModelChildren() {
172
		return Collections.EMPTY_LIST;
173
	}
174
175
	/**
176
	 * @generated
177
	 */
178
	public IGraphicalEditPart getChildBySemanticHint(String semanticHint) {
179
		return null;
180
	}
181
182
	/**
183
	 * @generated
184
	 */
185
	protected EObject getParserElement() {
186
		EObject element = resolveSemanticElement();
187
		return element != null ? element : (View) getModel();
188
	}
189
190
	/**
191
	 * @generated
192
	 */
193
	protected Image getLabelIcon() {
194
		return null;
195
	}
196
197
	/**
198
	 * @generated
199
	 */
200
	protected String getLabelText() {
201
		String text = null;
202
		if (getParser() != null) {
203
			text = getParser().getPrintString(new EObjectAdapter(getParserElement()), getParserOptions().intValue());
204
		}
205
		if (text == null || text.length() == 0) {
206
			text = defaultText;
207
		}
208
		return text;
209
	}
210
211
	/**
212
	 * @generated
213
	 */
214
	public void setLabelText(String text) {
215
		setLabelTextHelper(getFigure(), text);
216
		Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
217
		if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) {
218
			((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback();
219
		}
220
	}
221
222
	/**
223
	 * @generated
224
	 */
225
	public String getEditText() {
226
		if (getParser() == null) {
227
			return ""; //$NON-NLS-1$
228
		}
229
		return getParser().getEditString(new EObjectAdapter(getParserElement()), getParserOptions().intValue());
230
	}
231
232
	/**
233
	 * @generated
234
	 */
235
	protected boolean isEditable() {
236
		return getEditText() != null;
237
	}
238
239
	/**
240
	 * @generated
241
	 */
242
	public ICellEditorValidator getEditTextValidator() {
243
		return new ICellEditorValidator() {
244
245
			public String isValid(final Object value) {
246
				if (value instanceof String) {
247
					final EObject element = getParserElement();
248
					final IParser parser = getParser();
249
					try {
250
						IParserEditStatus valid = (IParserEditStatus) getEditingDomain().runExclusive(new RunnableWithResult.Impl() {
251
252
							public void run() {
253
								setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value));
254
							}
255
						});
256
						return valid.getCode() == ParserEditStatus.EDITABLE ? null : valid.getMessage();
257
					} catch (InterruptedException ie) {
258
						ie.printStackTrace();
259
					}
260
				}
261
262
				// shouldn't get here
263
				return null;
264
			}
265
		};
266
	}
267
268
	/**
269
	 * @generated
270
	 */
271
	public IContentAssistProcessor getCompletionProcessor() {
272
		if (getParser() == null) {
273
			return null;
274
		}
275
		return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement()));
276
	}
277
278
	/**
279
	 * @generated
280
	 */
281
	public ParserOptions getParserOptions() {
282
		return ParserOptions.NONE;
283
	}
284
285
	/**
286
	 * @generated
287
	 */
288
	public IParser getParser() {
289
		if (parser == null) {
290
			String parserHint = ((View) getModel()).getType();
291
			ParserHintAdapter hintAdapter = new ParserHintAdapter(getParserElement(), parserHint) {
292
293
				public Object getAdapter(Class adapter) {
294
					if (IElementType.class.equals(adapter)) {
295
						return UMLElementTypes.Property_3001;
296
					}
297
					return super.getAdapter(adapter);
298
				}
299
			};
300
			parser = ParserService.getInstance().getParser(hintAdapter);
301
		}
302
		return parser;
303
	}
304
305
	/**
306
	 * @generated
307
	 */
308
	protected DirectEditManager getManager() {
309
		if (manager == null) {
310
			setManager(new TextDirectEditManager(this, TextDirectEditManager.getTextCellEditorClass(this), UMLEditPartFactory.getTextCellEditorLocator(this)));
311
		}
312
		return manager;
313
	}
314
315
	/**
316
	 * @generated
317
	 */
318
	protected void setManager(DirectEditManager manager) {
319
		this.manager = manager;
320
	}
321
322
	/**
323
	 * @generated
324
	 */
325
	protected void performDirectEdit() {
326
		getManager().show();
327
	}
328
329
	/**
330
	 * @generated
331
	 */
332
	protected void performDirectEdit(Point eventLocation) {
333
		if (getManager().getClass() == TextDirectEditManager.class) {
334
			((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint());
335
		}
336
	}
337
338
	/**
339
	 * @generated
340
	 */
341
	private void performDirectEdit(char initialCharacter) {
342
		if (getManager() instanceof TextDirectEditManager) {
343
			((TextDirectEditManager) getManager()).show(initialCharacter);
344
		} else {
345
			performDirectEdit();
346
		}
347
	}
348
349
	/**
350
	 * @generated
351
	 */
352
	protected void performDirectEditRequest(Request request) {
353
		final Request theRequest = request;
354
		try {
355
			getEditingDomain().runExclusive(new Runnable() {
356
357
				public void run() {
358
					if (isActive() && isEditable()) {
359
						if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) {
360
							Character initialChar = (Character) theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR);
361
							performDirectEdit(initialChar.charValue());
362
						} else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) {
363
							DirectEditRequest editRequest = (DirectEditRequest) theRequest;
364
							performDirectEdit(editRequest.getLocation());
365
						} else {
366
							performDirectEdit();
367
						}
368
					}
369
				}
370
			});
371
		} catch (InterruptedException e) {
372
			e.printStackTrace();
373
		}
374
	}
375
376
	/**
377
	 * @generated
378
	 */
379
	protected void refreshVisuals() {
380
		super.refreshVisuals();
381
		refreshLabel();
382
		refreshFont();
383
		refreshFontColor();
384
		refreshUnderline();
385
		refreshStrikeThrough();
386
	}
387
388
	/**
389
	 * @generated
390
	 */
391
	protected void refreshLabel() {
392
		setLabelTextHelper(getFigure(), getLabelText());
393
		setLabelIconHelper(getFigure(), getLabelIcon());
394
		Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
395
		if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) {
396
			((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback();
397
		}
398
	}
399
400
	/**
401
	 * @generated
402
	 */
403
	protected void refreshUnderline() {
404
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
405
		if (style != null && getFigure() instanceof WrapLabel) {
406
			((WrapLabel) getFigure()).setTextUnderline(style.isUnderline());
407
		}
408
	}
409
410
	/**
411
	 * @generated
412
	 */
413
	protected void refreshStrikeThrough() {
414
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
415
		if (style != null && getFigure() instanceof WrapLabel) {
416
			((WrapLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough());
417
		}
418
	}
419
420
	/**
421
	 * @generated
422
	 */
423
	protected void refreshFont() {
424
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
425
		if (style != null) {
426
			FontData fontData = new FontData(style.getFontName(), style.getFontHeight(), (style.isBold() ? SWT.BOLD : SWT.NORMAL) | (style.isItalic() ? SWT.ITALIC : SWT.NORMAL));
427
			setFont(fontData);
428
		}
429
	}
430
431
	/**
432
	 * @generated
433
	 */
434
	protected void setFontColor(Color color) {
435
		getFigure().setForegroundColor(color);
436
	}
437
438
	/**
439
	 * @generated
440
	 */
441
	protected void addSemanticListeners() {
442
		if (getParser() instanceof ISemanticParser) {
443
			EObject element = resolveSemanticElement();
444
			parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element);
445
			for (int i = 0; i < parserElements.size(); i++) {
446
				addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$
447
			}
448
		} else {
449
			super.addSemanticListeners();
450
		}
451
	}
452
453
	/**
454
	 * @generated
455
	 */
456
	protected void removeSemanticListeners() {
457
		if (parserElements != null) {
458
			for (int i = 0; i < parserElements.size(); i++) {
459
				removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$
460
			}
461
		} else {
462
			super.removeSemanticListeners();
463
		}
464
	}
465
466
	/**
467
	 * @generated
468
	 */
469
	protected AccessibleEditPart getAccessibleEditPart() {
470
		if (accessibleEP == null) {
471
			accessibleEP = new AccessibleGraphicalEditPart() {
472
473
				public void getName(AccessibleEvent e) {
474
					e.result = getLabelTextHelper(getFigure());
475
				}
476
			};
477
		}
478
		return accessibleEP;
479
	}
480
481
	/**
482
	 * @generated
483
	 */
484
	private View getFontStyleOwnerView() {
485
		return getPrimaryView();
486
	}
487
488
	/**
489
	 * @generated
490
	 */
491
	protected void addNotationalListeners() {
492
		super.addNotationalListeners();
493
		addListenerFilter("PrimaryView", this, getPrimaryView()); //$NON-NLS-1$
494
	}
495
496
	/**
497
	 * @generated
498
	 */
499
	protected void removeNotationalListeners() {
500
		super.removeNotationalListeners();
501
		removeListenerFilter("PrimaryView"); //$NON-NLS-1$
502
	}
503
504
	/**
505
	 * @generated
506
	 */
507
	protected void handleNotificationEvent(Notification event) {
508
		Object feature = event.getFeature();
509
		if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) {
510
			Integer c = (Integer) event.getNewValue();
511
			setFontColor(DiagramColorRegistry.getInstance().getColor(c));
512
		} else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) {
513
			refreshUnderline();
514
		} else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) {
515
			refreshStrikeThrough();
516
		} else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature)
517
				|| NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) {
518
			refreshFont();
519
		} else {
520
			if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) {
521
				refreshLabel();
522
			}
523
			if (getParser() instanceof ISemanticParser) {
524
				ISemanticParser modelParser = (ISemanticParser) getParser();
525
				if (modelParser.areSemanticElementsAffected(null, event)) {
526
					removeSemanticListeners();
527
					if (resolveSemanticElement() != null) {
528
						addSemanticListeners();
529
					}
530
					refreshLabel();
531
				}
532
			}
533
		}
534
		super.handleNotificationEvent(event);
535
	}
536
537
	/**
538
	 * @generated
539
	 */
540
	protected IFigure createFigure() {
541
		IFigure label = createFigurePrim();
542
		defaultText = getLabelTextHelper(label);
543
		return label;
544
	}
545
546
	/**
547
	 * @generated
548
	 */
549
	protected IFigure createFigurePrim() {
550
		return new WrapLabel();
551
	}
552
553
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/policies/Operation3ItemSemanticEditPolicy.java (+255 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.policies;
2
3
import org.eclipse.emf.ecore.EAnnotation;
4
import org.eclipse.emf.ecore.EClass;
5
import org.eclipse.emf.ecore.EObject;
6
import org.eclipse.gef.commands.Command;
7
import org.eclipse.gef.commands.UnexecutableCommand;
8
import org.eclipse.gmf.runtime.emf.type.core.commands.CreateRelationshipCommand;
9
import org.eclipse.gmf.runtime.emf.type.core.commands.DestroyElementCommand;
10
import org.eclipse.gmf.runtime.emf.type.core.commands.SetValueCommand;
11
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest;
12
import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest;
13
import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest;
14
import org.eclipse.gmf.runtime.notation.View;
15
import org.eclipse.uml2.diagram.clazz.providers.UMLElementTypes;
16
import org.eclipse.uml2.uml.Constraint;
17
import org.eclipse.uml2.uml.Dependency;
18
import org.eclipse.uml2.uml.NamedElement;
19
import org.eclipse.uml2.uml.UMLPackage;
20
import org.eclipse.uml2.uml.Usage;
21
22
/**
23
 * @generated
24
 */
25
public class Operation3ItemSemanticEditPolicy extends UMLBaseItemSemanticEditPolicy {
26
27
	/**
28
	 * @generated
29
	 */
30
	protected Command getDestroyElementCommand(DestroyElementRequest req) {
31
		return getMSLWrapper(new DestroyElementCommand(req) {
32
33
			protected EObject getElementToDestroy() {
34
				View view = (View) getHost().getModel();
35
				EAnnotation annotation = view.getEAnnotation("Shortcut"); //$NON-NLS-1$
36
				if (annotation != null) {
37
					return view;
38
				}
39
				return super.getElementToDestroy();
40
			}
41
42
		});
43
	}
44
45
	/**
46
	 * @generated
47
	 */
48
	protected Command getCreateRelationshipCommand(CreateRelationshipRequest req) {
49
		if (UMLElementTypes.Dependency_4002 == req.getElementType()) {
50
			return req.getTarget() == null ? getCreateStartOutgoingDependency4002Command(req) : getCreateCompleteIncomingDependency4002Command(req);
51
		}
52
		if (UMLElementTypes.ConstraintConstrainedElement_4004 == req.getElementType()) {
53
			return req.getTarget() == null ? null : getCreateCompleteIncomingConstraint_ConstrainedElement4004Command(req);
54
		}
55
		if (UMLElementTypes.DependencySupplier_4006 == req.getElementType()) {
56
			return req.getTarget() == null ? null : getCreateCompleteIncomingDependency_Supplier4006Command(req);
57
		}
58
		if (UMLElementTypes.DependencyClient_4007 == req.getElementType()) {
59
			return req.getTarget() == null ? null : getCreateCompleteIncomingDependency_Client4007Command(req);
60
		}
61
		if (UMLElementTypes.Usage_4009 == req.getElementType()) {
62
			return req.getTarget() == null ? getCreateStartOutgoingUsage4009Command(req) : getCreateCompleteIncomingUsage4009Command(req);
63
		}
64
		return super.getCreateRelationshipCommand(req);
65
	}
66
67
	/**
68
	 * @generated
69
	 */
70
	protected Command getCreateStartOutgoingDependency4002Command(CreateRelationshipRequest req) {
71
		return new Command() {
72
		};
73
	}
74
75
	/**
76
	 * @generated
77
	 */
78
	protected Command getCreateCompleteIncomingDependency4002Command(CreateRelationshipRequest req) {
79
		if (!(req.getSource() instanceof NamedElement)) {
80
			return UnexecutableCommand.INSTANCE;
81
		}
82
		final org.eclipse.uml2.uml.Package element = (org.eclipse.uml2.uml.Package) getRelationshipContainer(req.getSource(), UMLPackage.eINSTANCE.getPackage(), req.getElementType());
83
		if (element == null) {
84
			return UnexecutableCommand.INSTANCE;
85
		}
86
		if (req.getContainmentFeature() == null) {
87
			req.setContainmentFeature(UMLPackage.eINSTANCE.getPackage_PackagedElement());
88
		}
89
		return getMSLWrapper(new CreateIncomingDependency4002Command(req) {
90
91
			protected EObject getElementToEdit() {
92
				return element;
93
			}
94
		});
95
	}
96
97
	/**
98
	 * @generated
99
	 */
100
	private static class CreateIncomingDependency4002Command extends CreateRelationshipCommand {
101
102
		/**
103
		 * @generated
104
		 */
105
		public CreateIncomingDependency4002Command(CreateRelationshipRequest req) {
106
			super(req);
107
		}
108
109
		/**
110
		 * @generated
111
		 */
112
		protected EClass getEClassToEdit() {
113
			return UMLPackage.eINSTANCE.getPackage();
114
		};
115
116
		/**
117
		 * @generated
118
		 */
119
		protected void setElementToEdit(EObject element) {
120
			throw new UnsupportedOperationException();
121
		}
122
123
		/**
124
		 * @generated
125
		 */
126
		protected EObject doDefaultElementCreation() {
127
			Dependency newElement = (Dependency) super.doDefaultElementCreation();
128
			if (newElement != null) {
129
				newElement.getSuppliers().add((NamedElement) getTarget());
130
				newElement.getClients().add((NamedElement) getSource());
131
			}
132
			return newElement;
133
		}
134
	}
135
136
	/**
137
	 * @generated
138
	 */
139
	protected Command getCreateCompleteIncomingConstraint_ConstrainedElement4004Command(CreateRelationshipRequest req) {
140
		if (!(req.getSource() instanceof Constraint)) {
141
			return UnexecutableCommand.INSTANCE;
142
		}
143
		Constraint element = (Constraint) req.getSource();
144
		if (element.getConstrainedElements().contains(req.getTarget())) {
145
			return UnexecutableCommand.INSTANCE;
146
		}
147
		SetRequest setReq = new SetRequest(req.getSource(), UMLPackage.eINSTANCE.getConstraint_ConstrainedElement(), req.getTarget());
148
		return getMSLWrapper(new SetValueCommand(setReq));
149
	}
150
151
	/**
152
	 * @generated
153
	 */
154
	protected Command getCreateCompleteIncomingDependency_Supplier4006Command(CreateRelationshipRequest req) {
155
		if (!(req.getSource() instanceof Dependency)) {
156
			return UnexecutableCommand.INSTANCE;
157
		}
158
		Dependency element = (Dependency) req.getSource();
159
		if (element.getSuppliers().contains(req.getTarget())) {
160
			return UnexecutableCommand.INSTANCE;
161
		}
162
		SetRequest setReq = new SetRequest(req.getSource(), UMLPackage.eINSTANCE.getDependency_Supplier(), req.getTarget());
163
		return getMSLWrapper(new SetValueCommand(setReq));
164
	}
165
166
	/**
167
	 * @generated
168
	 */
169
	protected Command getCreateCompleteIncomingDependency_Client4007Command(CreateRelationshipRequest req) {
170
		if (!(req.getSource() instanceof Dependency)) {
171
			return UnexecutableCommand.INSTANCE;
172
		}
173
		Dependency element = (Dependency) req.getSource();
174
		if (element.getClients().contains(req.getTarget())) {
175
			return UnexecutableCommand.INSTANCE;
176
		}
177
		SetRequest setReq = new SetRequest(req.getSource(), UMLPackage.eINSTANCE.getDependency_Client(), req.getTarget());
178
		return getMSLWrapper(new SetValueCommand(setReq));
179
	}
180
181
	/**
182
	 * @generated
183
	 */
184
	protected Command getCreateStartOutgoingUsage4009Command(CreateRelationshipRequest req) {
185
		if (!UMLBaseItemSemanticEditPolicy.LinkConstraints.Usage_4009.canCreateLink(req, false)) {
186
			return UnexecutableCommand.INSTANCE;
187
		}
188
		return new Command() {
189
		};
190
	}
191
192
	/**
193
	 * @generated
194
	 */
195
	protected Command getCreateCompleteIncomingUsage4009Command(CreateRelationshipRequest req) {
196
		if (!(req.getSource() instanceof NamedElement)) {
197
			return UnexecutableCommand.INSTANCE;
198
		}
199
		final org.eclipse.uml2.uml.Package element = (org.eclipse.uml2.uml.Package) getRelationshipContainer(req.getSource(), UMLPackage.eINSTANCE.getPackage(), req.getElementType());
200
		if (element == null) {
201
			return UnexecutableCommand.INSTANCE;
202
		}
203
		if (!UMLBaseItemSemanticEditPolicy.LinkConstraints.Usage_4009.canCreateLink(req, false)) {
204
			return UnexecutableCommand.INSTANCE;
205
		}
206
		if (req.getContainmentFeature() == null) {
207
			req.setContainmentFeature(UMLPackage.eINSTANCE.getPackage_PackagedElement());
208
		}
209
		return getMSLWrapper(new CreateIncomingUsage4009Command(req) {
210
211
			protected EObject getElementToEdit() {
212
				return element;
213
			}
214
		});
215
	}
216
217
	/**
218
	 * @generated
219
	 */
220
	private static class CreateIncomingUsage4009Command extends CreateRelationshipCommand {
221
222
		/**
223
		 * @generated
224
		 */
225
		public CreateIncomingUsage4009Command(CreateRelationshipRequest req) {
226
			super(req);
227
		}
228
229
		/**
230
		 * @generated
231
		 */
232
		protected EClass getEClassToEdit() {
233
			return UMLPackage.eINSTANCE.getPackage();
234
		};
235
236
		/**
237
		 * @generated
238
		 */
239
		protected void setElementToEdit(EObject element) {
240
			throw new UnsupportedOperationException();
241
		}
242
243
		/**
244
		 * @generated
245
		 */
246
		protected EObject doDefaultElementCreation() {
247
			Usage newElement = (Usage) super.doDefaultElementCreation();
248
			if (newElement != null) {
249
				newElement.getSuppliers().add((NamedElement) getTarget());
250
				newElement.getClients().add((NamedElement) getSource());
251
			}
252
			return newElement;
253
		}
254
	}
255
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/parts/PackageOtherEditPart.java (+67 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.parts;
2
3
import org.eclipse.emf.common.notify.Notification;
4
import org.eclipse.gef.EditPolicy;
5
import org.eclipse.gmf.runtime.diagram.ui.editparts.ListCompartmentEditPart;
6
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.CreationEditPolicy;
7
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.DragDropEditPolicy;
8
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
9
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.ResizableCompartmentEditPolicy;
10
import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout;
11
import org.eclipse.gmf.runtime.notation.View;
12
import org.eclipse.uml2.diagram.clazz.edit.policies.PackageOtherCanonicalEditPolicy;
13
import org.eclipse.uml2.diagram.clazz.edit.policies.PackageOtherItemSemanticEditPolicy;
14
15
/**
16
 * @generated
17
 */
18
public class PackageOtherEditPart extends ListCompartmentEditPart {
19
20
	/**
21
	 * @generated
22
	 */
23
	public static final int VISUAL_ID = 7012;
24
25
	/**
26
	 * @generated
27
	 */
28
	public PackageOtherEditPart(View view) {
29
		super(view);
30
	}
31
32
	/**
33
	 * @generated
34
	 */
35
	protected boolean hasModelChildrenChanged(Notification evt) {
36
		return false;
37
	}
38
39
	/**
40
	 * @generated
41
	 */
42
	public String getCompartmentName() {
43
		return "other";
44
	}
45
46
	/**
47
	 * @generated
48
	 */
49
	protected void createDefaultEditPolicies() {
50
		super.createDefaultEditPolicies();
51
		installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ResizableCompartmentEditPolicy());
52
		installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new PackageOtherItemSemanticEditPolicy());
53
		installEditPolicy(EditPolicyRoles.CREATION_ROLE, new CreationEditPolicy());
54
		installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, new DragDropEditPolicy());
55
		installEditPolicy(EditPolicyRoles.CANONICAL_ROLE, new PackageOtherCanonicalEditPolicy());
56
57
	}
58
59
	/**
60
	 * @generated
61
	 */
62
	protected void setRatio(Double ratio) {
63
		if (getFigure().getParent().getLayoutManager() instanceof ConstrainedToolbarLayout) {
64
			super.setRatio(ratio);
65
		}
66
	}
67
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/policies/Operation5ItemSemanticEditPolicy.java (+255 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.policies;
2
3
import org.eclipse.emf.ecore.EAnnotation;
4
import org.eclipse.emf.ecore.EClass;
5
import org.eclipse.emf.ecore.EObject;
6
import org.eclipse.gef.commands.Command;
7
import org.eclipse.gef.commands.UnexecutableCommand;
8
import org.eclipse.gmf.runtime.emf.type.core.commands.CreateRelationshipCommand;
9
import org.eclipse.gmf.runtime.emf.type.core.commands.DestroyElementCommand;
10
import org.eclipse.gmf.runtime.emf.type.core.commands.SetValueCommand;
11
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest;
12
import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest;
13
import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest;
14
import org.eclipse.gmf.runtime.notation.View;
15
import org.eclipse.uml2.diagram.clazz.providers.UMLElementTypes;
16
import org.eclipse.uml2.uml.Constraint;
17
import org.eclipse.uml2.uml.Dependency;
18
import org.eclipse.uml2.uml.NamedElement;
19
import org.eclipse.uml2.uml.UMLPackage;
20
import org.eclipse.uml2.uml.Usage;
21
22
/**
23
 * @generated
24
 */
25
public class Operation5ItemSemanticEditPolicy extends UMLBaseItemSemanticEditPolicy {
26
27
	/**
28
	 * @generated
29
	 */
30
	protected Command getDestroyElementCommand(DestroyElementRequest req) {
31
		return getMSLWrapper(new DestroyElementCommand(req) {
32
33
			protected EObject getElementToDestroy() {
34
				View view = (View) getHost().getModel();
35
				EAnnotation annotation = view.getEAnnotation("Shortcut"); //$NON-NLS-1$
36
				if (annotation != null) {
37
					return view;
38
				}
39
				return super.getElementToDestroy();
40
			}
41
42
		});
43
	}
44
45
	/**
46
	 * @generated
47
	 */
48
	protected Command getCreateRelationshipCommand(CreateRelationshipRequest req) {
49
		if (UMLElementTypes.Dependency_4002 == req.getElementType()) {
50
			return req.getTarget() == null ? getCreateStartOutgoingDependency4002Command(req) : getCreateCompleteIncomingDependency4002Command(req);
51
		}
52
		if (UMLElementTypes.ConstraintConstrainedElement_4004 == req.getElementType()) {
53
			return req.getTarget() == null ? null : getCreateCompleteIncomingConstraint_ConstrainedElement4004Command(req);
54
		}
55
		if (UMLElementTypes.DependencySupplier_4006 == req.getElementType()) {
56
			return req.getTarget() == null ? null : getCreateCompleteIncomingDependency_Supplier4006Command(req);
57
		}
58
		if (UMLElementTypes.DependencyClient_4007 == req.getElementType()) {
59
			return req.getTarget() == null ? null : getCreateCompleteIncomingDependency_Client4007Command(req);
60
		}
61
		if (UMLElementTypes.Usage_4009 == req.getElementType()) {
62
			return req.getTarget() == null ? getCreateStartOutgoingUsage4009Command(req) : getCreateCompleteIncomingUsage4009Command(req);
63
		}
64
		return super.getCreateRelationshipCommand(req);
65
	}
66
67
	/**
68
	 * @generated
69
	 */
70
	protected Command getCreateStartOutgoingDependency4002Command(CreateRelationshipRequest req) {
71
		return new Command() {
72
		};
73
	}
74
75
	/**
76
	 * @generated
77
	 */
78
	protected Command getCreateCompleteIncomingDependency4002Command(CreateRelationshipRequest req) {
79
		if (!(req.getSource() instanceof NamedElement)) {
80
			return UnexecutableCommand.INSTANCE;
81
		}
82
		final org.eclipse.uml2.uml.Package element = (org.eclipse.uml2.uml.Package) getRelationshipContainer(req.getSource(), UMLPackage.eINSTANCE.getPackage(), req.getElementType());
83
		if (element == null) {
84
			return UnexecutableCommand.INSTANCE;
85
		}
86
		if (req.getContainmentFeature() == null) {
87
			req.setContainmentFeature(UMLPackage.eINSTANCE.getPackage_PackagedElement());
88
		}
89
		return getMSLWrapper(new CreateIncomingDependency4002Command(req) {
90
91
			protected EObject getElementToEdit() {
92
				return element;
93
			}
94
		});
95
	}
96
97
	/**
98
	 * @generated
99
	 */
100
	private static class CreateIncomingDependency4002Command extends CreateRelationshipCommand {
101
102
		/**
103
		 * @generated
104
		 */
105
		public CreateIncomingDependency4002Command(CreateRelationshipRequest req) {
106
			super(req);
107
		}
108
109
		/**
110
		 * @generated
111
		 */
112
		protected EClass getEClassToEdit() {
113
			return UMLPackage.eINSTANCE.getPackage();
114
		};
115
116
		/**
117
		 * @generated
118
		 */
119
		protected void setElementToEdit(EObject element) {
120
			throw new UnsupportedOperationException();
121
		}
122
123
		/**
124
		 * @generated
125
		 */
126
		protected EObject doDefaultElementCreation() {
127
			Dependency newElement = (Dependency) super.doDefaultElementCreation();
128
			if (newElement != null) {
129
				newElement.getSuppliers().add((NamedElement) getTarget());
130
				newElement.getClients().add((NamedElement) getSource());
131
			}
132
			return newElement;
133
		}
134
	}
135
136
	/**
137
	 * @generated
138
	 */
139
	protected Command getCreateCompleteIncomingConstraint_ConstrainedElement4004Command(CreateRelationshipRequest req) {
140
		if (!(req.getSource() instanceof Constraint)) {
141
			return UnexecutableCommand.INSTANCE;
142
		}
143
		Constraint element = (Constraint) req.getSource();
144
		if (element.getConstrainedElements().contains(req.getTarget())) {
145
			return UnexecutableCommand.INSTANCE;
146
		}
147
		SetRequest setReq = new SetRequest(req.getSource(), UMLPackage.eINSTANCE.getConstraint_ConstrainedElement(), req.getTarget());
148
		return getMSLWrapper(new SetValueCommand(setReq));
149
	}
150
151
	/**
152
	 * @generated
153
	 */
154
	protected Command getCreateCompleteIncomingDependency_Supplier4006Command(CreateRelationshipRequest req) {
155
		if (!(req.getSource() instanceof Dependency)) {
156
			return UnexecutableCommand.INSTANCE;
157
		}
158
		Dependency element = (Dependency) req.getSource();
159
		if (element.getSuppliers().contains(req.getTarget())) {
160
			return UnexecutableCommand.INSTANCE;
161
		}
162
		SetRequest setReq = new SetRequest(req.getSource(), UMLPackage.eINSTANCE.getDependency_Supplier(), req.getTarget());
163
		return getMSLWrapper(new SetValueCommand(setReq));
164
	}
165
166
	/**
167
	 * @generated
168
	 */
169
	protected Command getCreateCompleteIncomingDependency_Client4007Command(CreateRelationshipRequest req) {
170
		if (!(req.getSource() instanceof Dependency)) {
171
			return UnexecutableCommand.INSTANCE;
172
		}
173
		Dependency element = (Dependency) req.getSource();
174
		if (element.getClients().contains(req.getTarget())) {
175
			return UnexecutableCommand.INSTANCE;
176
		}
177
		SetRequest setReq = new SetRequest(req.getSource(), UMLPackage.eINSTANCE.getDependency_Client(), req.getTarget());
178
		return getMSLWrapper(new SetValueCommand(setReq));
179
	}
180
181
	/**
182
	 * @generated
183
	 */
184
	protected Command getCreateStartOutgoingUsage4009Command(CreateRelationshipRequest req) {
185
		if (!UMLBaseItemSemanticEditPolicy.LinkConstraints.Usage_4009.canCreateLink(req, false)) {
186
			return UnexecutableCommand.INSTANCE;
187
		}
188
		return new Command() {
189
		};
190
	}
191
192
	/**
193
	 * @generated
194
	 */
195
	protected Command getCreateCompleteIncomingUsage4009Command(CreateRelationshipRequest req) {
196
		if (!(req.getSource() instanceof NamedElement)) {
197
			return UnexecutableCommand.INSTANCE;
198
		}
199
		final org.eclipse.uml2.uml.Package element = (org.eclipse.uml2.uml.Package) getRelationshipContainer(req.getSource(), UMLPackage.eINSTANCE.getPackage(), req.getElementType());
200
		if (element == null) {
201
			return UnexecutableCommand.INSTANCE;
202
		}
203
		if (!UMLBaseItemSemanticEditPolicy.LinkConstraints.Usage_4009.canCreateLink(req, false)) {
204
			return UnexecutableCommand.INSTANCE;
205
		}
206
		if (req.getContainmentFeature() == null) {
207
			req.setContainmentFeature(UMLPackage.eINSTANCE.getPackage_PackagedElement());
208
		}
209
		return getMSLWrapper(new CreateIncomingUsage4009Command(req) {
210
211
			protected EObject getElementToEdit() {
212
				return element;
213
			}
214
		});
215
	}
216
217
	/**
218
	 * @generated
219
	 */
220
	private static class CreateIncomingUsage4009Command extends CreateRelationshipCommand {
221
222
		/**
223
		 * @generated
224
		 */
225
		public CreateIncomingUsage4009Command(CreateRelationshipRequest req) {
226
			super(req);
227
		}
228
229
		/**
230
		 * @generated
231
		 */
232
		protected EClass getEClassToEdit() {
233
			return UMLPackage.eINSTANCE.getPackage();
234
		};
235
236
		/**
237
		 * @generated
238
		 */
239
		protected void setElementToEdit(EObject element) {
240
			throw new UnsupportedOperationException();
241
		}
242
243
		/**
244
		 * @generated
245
		 */
246
		protected EObject doDefaultElementCreation() {
247
			Usage newElement = (Usage) super.doDefaultElementCreation();
248
			if (newElement != null) {
249
				newElement.getSuppliers().add((NamedElement) getTarget());
250
				newElement.getClients().add((NamedElement) getSource());
251
			}
252
			return newElement;
253
		}
254
	}
255
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/policies/Property5ItemSemanticEditPolicy.java (+255 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.policies;
2
3
import org.eclipse.emf.ecore.EAnnotation;
4
import org.eclipse.emf.ecore.EClass;
5
import org.eclipse.emf.ecore.EObject;
6
import org.eclipse.gef.commands.Command;
7
import org.eclipse.gef.commands.UnexecutableCommand;
8
import org.eclipse.gmf.runtime.emf.type.core.commands.CreateRelationshipCommand;
9
import org.eclipse.gmf.runtime.emf.type.core.commands.DestroyElementCommand;
10
import org.eclipse.gmf.runtime.emf.type.core.commands.SetValueCommand;
11
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest;
12
import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest;
13
import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest;
14
import org.eclipse.gmf.runtime.notation.View;
15
import org.eclipse.uml2.diagram.clazz.providers.UMLElementTypes;
16
import org.eclipse.uml2.uml.Constraint;
17
import org.eclipse.uml2.uml.Dependency;
18
import org.eclipse.uml2.uml.NamedElement;
19
import org.eclipse.uml2.uml.UMLPackage;
20
import org.eclipse.uml2.uml.Usage;
21
22
/**
23
 * @generated
24
 */
25
public class Property5ItemSemanticEditPolicy extends UMLBaseItemSemanticEditPolicy {
26
27
	/**
28
	 * @generated
29
	 */
30
	protected Command getDestroyElementCommand(DestroyElementRequest req) {
31
		return getMSLWrapper(new DestroyElementCommand(req) {
32
33
			protected EObject getElementToDestroy() {
34
				View view = (View) getHost().getModel();
35
				EAnnotation annotation = view.getEAnnotation("Shortcut"); //$NON-NLS-1$
36
				if (annotation != null) {
37
					return view;
38
				}
39
				return super.getElementToDestroy();
40
			}
41
42
		});
43
	}
44
45
	/**
46
	 * @generated
47
	 */
48
	protected Command getCreateRelationshipCommand(CreateRelationshipRequest req) {
49
		if (UMLElementTypes.Dependency_4002 == req.getElementType()) {
50
			return req.getTarget() == null ? getCreateStartOutgoingDependency4002Command(req) : getCreateCompleteIncomingDependency4002Command(req);
51
		}
52
		if (UMLElementTypes.ConstraintConstrainedElement_4004 == req.getElementType()) {
53
			return req.getTarget() == null ? null : getCreateCompleteIncomingConstraint_ConstrainedElement4004Command(req);
54
		}
55
		if (UMLElementTypes.DependencySupplier_4006 == req.getElementType()) {
56
			return req.getTarget() == null ? null : getCreateCompleteIncomingDependency_Supplier4006Command(req);
57
		}
58
		if (UMLElementTypes.DependencyClient_4007 == req.getElementType()) {
59
			return req.getTarget() == null ? null : getCreateCompleteIncomingDependency_Client4007Command(req);
60
		}
61
		if (UMLElementTypes.Usage_4009 == req.getElementType()) {
62
			return req.getTarget() == null ? getCreateStartOutgoingUsage4009Command(req) : getCreateCompleteIncomingUsage4009Command(req);
63
		}
64
		return super.getCreateRelationshipCommand(req);
65
	}
66
67
	/**
68
	 * @generated
69
	 */
70
	protected Command getCreateStartOutgoingDependency4002Command(CreateRelationshipRequest req) {
71
		return new Command() {
72
		};
73
	}
74
75
	/**
76
	 * @generated
77
	 */
78
	protected Command getCreateCompleteIncomingDependency4002Command(CreateRelationshipRequest req) {
79
		if (!(req.getSource() instanceof NamedElement)) {
80
			return UnexecutableCommand.INSTANCE;
81
		}
82
		final org.eclipse.uml2.uml.Package element = (org.eclipse.uml2.uml.Package) getRelationshipContainer(req.getSource(), UMLPackage.eINSTANCE.getPackage(), req.getElementType());
83
		if (element == null) {
84
			return UnexecutableCommand.INSTANCE;
85
		}
86
		if (req.getContainmentFeature() == null) {
87
			req.setContainmentFeature(UMLPackage.eINSTANCE.getPackage_PackagedElement());
88
		}
89
		return getMSLWrapper(new CreateIncomingDependency4002Command(req) {
90
91
			protected EObject getElementToEdit() {
92
				return element;
93
			}
94
		});
95
	}
96
97
	/**
98
	 * @generated
99
	 */
100
	private static class CreateIncomingDependency4002Command extends CreateRelationshipCommand {
101
102
		/**
103
		 * @generated
104
		 */
105
		public CreateIncomingDependency4002Command(CreateRelationshipRequest req) {
106
			super(req);
107
		}
108
109
		/**
110
		 * @generated
111
		 */
112
		protected EClass getEClassToEdit() {
113
			return UMLPackage.eINSTANCE.getPackage();
114
		};
115
116
		/**
117
		 * @generated
118
		 */
119
		protected void setElementToEdit(EObject element) {
120
			throw new UnsupportedOperationException();
121
		}
122
123
		/**
124
		 * @generated
125
		 */
126
		protected EObject doDefaultElementCreation() {
127
			Dependency newElement = (Dependency) super.doDefaultElementCreation();
128
			if (newElement != null) {
129
				newElement.getSuppliers().add((NamedElement) getTarget());
130
				newElement.getClients().add((NamedElement) getSource());
131
			}
132
			return newElement;
133
		}
134
	}
135
136
	/**
137
	 * @generated
138
	 */
139
	protected Command getCreateCompleteIncomingConstraint_ConstrainedElement4004Command(CreateRelationshipRequest req) {
140
		if (!(req.getSource() instanceof Constraint)) {
141
			return UnexecutableCommand.INSTANCE;
142
		}
143
		Constraint element = (Constraint) req.getSource();
144
		if (element.getConstrainedElements().contains(req.getTarget())) {
145
			return UnexecutableCommand.INSTANCE;
146
		}
147
		SetRequest setReq = new SetRequest(req.getSource(), UMLPackage.eINSTANCE.getConstraint_ConstrainedElement(), req.getTarget());
148
		return getMSLWrapper(new SetValueCommand(setReq));
149
	}
150
151
	/**
152
	 * @generated
153
	 */
154
	protected Command getCreateCompleteIncomingDependency_Supplier4006Command(CreateRelationshipRequest req) {
155
		if (!(req.getSource() instanceof Dependency)) {
156
			return UnexecutableCommand.INSTANCE;
157
		}
158
		Dependency element = (Dependency) req.getSource();
159
		if (element.getSuppliers().contains(req.getTarget())) {
160
			return UnexecutableCommand.INSTANCE;
161
		}
162
		SetRequest setReq = new SetRequest(req.getSource(), UMLPackage.eINSTANCE.getDependency_Supplier(), req.getTarget());
163
		return getMSLWrapper(new SetValueCommand(setReq));
164
	}
165
166
	/**
167
	 * @generated
168
	 */
169
	protected Command getCreateCompleteIncomingDependency_Client4007Command(CreateRelationshipRequest req) {
170
		if (!(req.getSource() instanceof Dependency)) {
171
			return UnexecutableCommand.INSTANCE;
172
		}
173
		Dependency element = (Dependency) req.getSource();
174
		if (element.getClients().contains(req.getTarget())) {
175
			return UnexecutableCommand.INSTANCE;
176
		}
177
		SetRequest setReq = new SetRequest(req.getSource(), UMLPackage.eINSTANCE.getDependency_Client(), req.getTarget());
178
		return getMSLWrapper(new SetValueCommand(setReq));
179
	}
180
181
	/**
182
	 * @generated
183
	 */
184
	protected Command getCreateStartOutgoingUsage4009Command(CreateRelationshipRequest req) {
185
		if (!UMLBaseItemSemanticEditPolicy.LinkConstraints.Usage_4009.canCreateLink(req, false)) {
186
			return UnexecutableCommand.INSTANCE;
187
		}
188
		return new Command() {
189
		};
190
	}
191
192
	/**
193
	 * @generated
194
	 */
195
	protected Command getCreateCompleteIncomingUsage4009Command(CreateRelationshipRequest req) {
196
		if (!(req.getSource() instanceof NamedElement)) {
197
			return UnexecutableCommand.INSTANCE;
198
		}
199
		final org.eclipse.uml2.uml.Package element = (org.eclipse.uml2.uml.Package) getRelationshipContainer(req.getSource(), UMLPackage.eINSTANCE.getPackage(), req.getElementType());
200
		if (element == null) {
201
			return UnexecutableCommand.INSTANCE;
202
		}
203
		if (!UMLBaseItemSemanticEditPolicy.LinkConstraints.Usage_4009.canCreateLink(req, false)) {
204
			return UnexecutableCommand.INSTANCE;
205
		}
206
		if (req.getContainmentFeature() == null) {
207
			req.setContainmentFeature(UMLPackage.eINSTANCE.getPackage_PackagedElement());
208
		}
209
		return getMSLWrapper(new CreateIncomingUsage4009Command(req) {
210
211
			protected EObject getElementToEdit() {
212
				return element;
213
			}
214
		});
215
	}
216
217
	/**
218
	 * @generated
219
	 */
220
	private static class CreateIncomingUsage4009Command extends CreateRelationshipCommand {
221
222
		/**
223
		 * @generated
224
		 */
225
		public CreateIncomingUsage4009Command(CreateRelationshipRequest req) {
226
			super(req);
227
		}
228
229
		/**
230
		 * @generated
231
		 */
232
		protected EClass getEClassToEdit() {
233
			return UMLPackage.eINSTANCE.getPackage();
234
		};
235
236
		/**
237
		 * @generated
238
		 */
239
		protected void setElementToEdit(EObject element) {
240
			throw new UnsupportedOperationException();
241
		}
242
243
		/**
244
		 * @generated
245
		 */
246
		protected EObject doDefaultElementCreation() {
247
			Usage newElement = (Usage) super.doDefaultElementCreation();
248
			if (newElement != null) {
249
				newElement.getSuppliers().add((NamedElement) getTarget());
250
				newElement.getClients().add((NamedElement) getSource());
251
			}
252
			return newElement;
253
		}
254
	}
255
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/policies/SlotItemSemanticEditPolicy.java (+64 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.policies;
2
3
import org.eclipse.emf.ecore.EAnnotation;
4
import org.eclipse.emf.ecore.EObject;
5
import org.eclipse.gef.commands.Command;
6
import org.eclipse.gef.commands.UnexecutableCommand;
7
import org.eclipse.gmf.runtime.emf.type.core.commands.DestroyElementCommand;
8
import org.eclipse.gmf.runtime.emf.type.core.commands.SetValueCommand;
9
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest;
10
import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest;
11
import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest;
12
import org.eclipse.gmf.runtime.notation.View;
13
import org.eclipse.uml2.diagram.clazz.providers.UMLElementTypes;
14
import org.eclipse.uml2.uml.Constraint;
15
import org.eclipse.uml2.uml.UMLPackage;
16
17
/**
18
 * @generated
19
 */
20
public class SlotItemSemanticEditPolicy extends UMLBaseItemSemanticEditPolicy {
21
22
	/**
23
	 * @generated
24
	 */
25
	protected Command getDestroyElementCommand(DestroyElementRequest req) {
26
		return getMSLWrapper(new DestroyElementCommand(req) {
27
28
			protected EObject getElementToDestroy() {
29
				View view = (View) getHost().getModel();
30
				EAnnotation annotation = view.getEAnnotation("Shortcut"); //$NON-NLS-1$
31
				if (annotation != null) {
32
					return view;
33
				}
34
				return super.getElementToDestroy();
35
			}
36
37
		});
38
	}
39
40
	/**
41
	 * @generated
42
	 */
43
	protected Command getCreateRelationshipCommand(CreateRelationshipRequest req) {
44
		if (UMLElementTypes.ConstraintConstrainedElement_4004 == req.getElementType()) {
45
			return req.getTarget() == null ? null : getCreateCompleteIncomingConstraint_ConstrainedElement4004Command(req);
46
		}
47
		return super.getCreateRelationshipCommand(req);
48
	}
49
50
	/**
51
	 * @generated
52
	 */
53
	protected Command getCreateCompleteIncomingConstraint_ConstrainedElement4004Command(CreateRelationshipRequest req) {
54
		if (!(req.getSource() instanceof Constraint)) {
55
			return UnexecutableCommand.INSTANCE;
56
		}
57
		Constraint element = (Constraint) req.getSource();
58
		if (element.getConstrainedElements().contains(req.getTarget())) {
59
			return UnexecutableCommand.INSTANCE;
60
		}
61
		SetRequest setReq = new SetRequest(req.getSource(), UMLPackage.eINSTANCE.getConstraint_ConstrainedElement(), req.getTarget());
62
		return getMSLWrapper(new SetValueCommand(setReq));
63
	}
64
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/parts/OperationEditPart.java (+553 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.parts;
2
3
import java.util.Collections;
4
import java.util.List;
5
6
import org.eclipse.draw2d.IFigure;
7
import org.eclipse.draw2d.Label;
8
import org.eclipse.draw2d.geometry.Point;
9
import org.eclipse.emf.common.notify.Notification;
10
import org.eclipse.emf.ecore.EObject;
11
import org.eclipse.emf.transaction.RunnableWithResult;
12
import org.eclipse.gef.AccessibleEditPart;
13
import org.eclipse.gef.DragTracker;
14
import org.eclipse.gef.EditPolicy;
15
import org.eclipse.gef.Request;
16
import org.eclipse.gef.requests.DirectEditRequest;
17
import org.eclipse.gef.requests.SelectionRequest;
18
import org.eclipse.gef.tools.DirectEditManager;
19
import org.eclipse.gmf.runtime.common.ui.services.parser.IParser;
20
import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus;
21
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserEditStatus;
22
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions;
23
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserService;
24
import org.eclipse.gmf.runtime.diagram.ui.editparts.CompartmentEditPart;
25
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
26
import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart;
27
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
28
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy;
29
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.ListItemComponentEditPolicy;
30
import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry;
31
import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants;
32
import org.eclipse.gmf.runtime.diagram.ui.tools.DragEditPartsTrackerEx;
33
import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager;
34
import org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel;
35
import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
36
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
37
import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser;
38
import org.eclipse.gmf.runtime.emf.ui.services.parser.ParserHintAdapter;
39
import org.eclipse.gmf.runtime.notation.FontStyle;
40
import org.eclipse.gmf.runtime.notation.NotationPackage;
41
import org.eclipse.gmf.runtime.notation.View;
42
import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
43
import org.eclipse.jface.viewers.ICellEditorValidator;
44
import org.eclipse.swt.SWT;
45
import org.eclipse.swt.accessibility.AccessibleEvent;
46
import org.eclipse.swt.graphics.Color;
47
import org.eclipse.swt.graphics.FontData;
48
import org.eclipse.swt.graphics.Image;
49
import org.eclipse.uml2.diagram.clazz.edit.policies.OperationItemSemanticEditPolicy;
50
import org.eclipse.uml2.diagram.clazz.edit.policies.UMLTextNonResizableEditPolicy;
51
import org.eclipse.uml2.diagram.clazz.edit.policies.UMLTextSelectionEditPolicy;
52
import org.eclipse.uml2.diagram.clazz.providers.UMLElementTypes;
53
54
/**
55
 * @generated
56
 */
57
public class OperationEditPart extends CompartmentEditPart implements ITextAwareEditPart {
58
59
	/**
60
	 * @generated
61
	 */
62
	public static final int VISUAL_ID = 3002;
63
64
	/**
65
	 * @generated
66
	 */
67
	private DirectEditManager manager;
68
69
	/**
70
	 * @generated
71
	 */
72
	private IParser parser;
73
74
	/**
75
	 * @generated
76
	 */
77
	private List parserElements;
78
79
	/**
80
	 * @generated
81
	 */
82
	private String defaultText;
83
84
	/**
85
	 * @generated
86
	 */
87
	public OperationEditPart(View view) {
88
		super(view);
89
	}
90
91
	/**
92
	 * @generated
93
	 */
94
	public DragTracker getDragTracker(Request request) {
95
		if (request instanceof SelectionRequest && ((SelectionRequest) request).getLastButtonPressed() == 3) {
96
			return null;
97
		}
98
		return new DragEditPartsTrackerEx(this);
99
	}
100
101
	/**
102
	 * @generated
103
	 */
104
	protected void createDefaultEditPolicies() {
105
		super.createDefaultEditPolicies();
106
		installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new OperationItemSemanticEditPolicy());
107
		installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new UMLTextNonResizableEditPolicy());
108
		installEditPolicy(EditPolicy.COMPONENT_ROLE, new ListItemComponentEditPolicy());
109
		installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy());
110
111
	}
112
113
	/**
114
	 * @generated
115
	 */
116
	protected String getLabelTextHelper(IFigure figure) {
117
		if (figure instanceof WrapLabel) {
118
			return ((WrapLabel) figure).getText();
119
		} else {
120
			return ((Label) figure).getText();
121
		}
122
	}
123
124
	/**
125
	 * @generated
126
	 */
127
	protected void setLabelTextHelper(IFigure figure, String text) {
128
		if (figure instanceof WrapLabel) {
129
			((WrapLabel) figure).setText(text);
130
		} else {
131
			((Label) figure).setText(text);
132
		}
133
	}
134
135
	/**
136
	 * @generated
137
	 */
138
	protected Image getLabelIconHelper(IFigure figure) {
139
		if (figure instanceof WrapLabel) {
140
			return ((WrapLabel) figure).getIcon();
141
		} else {
142
			return ((Label) figure).getIcon();
143
		}
144
	}
145
146
	/**
147
	 * @generated
148
	 */
149
	protected void setLabelIconHelper(IFigure figure, Image icon) {
150
		if (figure instanceof WrapLabel) {
151
			((WrapLabel) figure).setIcon(icon);
152
		} else {
153
			((Label) figure).setIcon(icon);
154
		}
155
	}
156
157
	/**
158
	 * @generated
159
	 */
160
	public void setLabel(IFigure figure) {
161
		unregisterVisuals();
162
		setFigure(figure);
163
		defaultText = getLabelTextHelper(figure);
164
		registerVisuals();
165
		refreshVisuals();
166
	}
167
168
	/**
169
	 * @generated
170
	 */
171
	protected List getModelChildren() {
172
		return Collections.EMPTY_LIST;
173
	}
174
175
	/**
176
	 * @generated
177
	 */
178
	public IGraphicalEditPart getChildBySemanticHint(String semanticHint) {
179
		return null;
180
	}
181
182
	/**
183
	 * @generated
184
	 */
185
	protected EObject getParserElement() {
186
		EObject element = resolveSemanticElement();
187
		return element != null ? element : (View) getModel();
188
	}
189
190
	/**
191
	 * @generated
192
	 */
193
	protected Image getLabelIcon() {
194
		return null;
195
	}
196
197
	/**
198
	 * @generated
199
	 */
200
	protected String getLabelText() {
201
		String text = null;
202
		if (getParser() != null) {
203
			text = getParser().getPrintString(new EObjectAdapter(getParserElement()), getParserOptions().intValue());
204
		}
205
		if (text == null || text.length() == 0) {
206
			text = defaultText;
207
		}
208
		return text;
209
	}
210
211
	/**
212
	 * @generated
213
	 */
214
	public void setLabelText(String text) {
215
		setLabelTextHelper(getFigure(), text);
216
		Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
217
		if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) {
218
			((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback();
219
		}
220
	}
221
222
	/**
223
	 * @generated
224
	 */
225
	public String getEditText() {
226
		if (getParser() == null) {
227
			return ""; //$NON-NLS-1$
228
		}
229
		return getParser().getEditString(new EObjectAdapter(getParserElement()), getParserOptions().intValue());
230
	}
231
232
	/**
233
	 * @generated
234
	 */
235
	protected boolean isEditable() {
236
		return getEditText() != null;
237
	}
238
239
	/**
240
	 * @generated
241
	 */
242
	public ICellEditorValidator getEditTextValidator() {
243
		return new ICellEditorValidator() {
244
245
			public String isValid(final Object value) {
246
				if (value instanceof String) {
247
					final EObject element = getParserElement();
248
					final IParser parser = getParser();
249
					try {
250
						IParserEditStatus valid = (IParserEditStatus) getEditingDomain().runExclusive(new RunnableWithResult.Impl() {
251
252
							public void run() {
253
								setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value));
254
							}
255
						});
256
						return valid.getCode() == ParserEditStatus.EDITABLE ? null : valid.getMessage();
257
					} catch (InterruptedException ie) {
258
						ie.printStackTrace();
259
					}
260
				}
261
262
				// shouldn't get here
263
				return null;
264
			}
265
		};
266
	}
267
268
	/**
269
	 * @generated
270
	 */
271
	public IContentAssistProcessor getCompletionProcessor() {
272
		if (getParser() == null) {
273
			return null;
274
		}
275
		return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement()));
276
	}
277
278
	/**
279
	 * @generated
280
	 */
281
	public ParserOptions getParserOptions() {
282
		return ParserOptions.NONE;
283
	}
284
285
	/**
286
	 * @generated
287
	 */
288
	public IParser getParser() {
289
		if (parser == null) {
290
			String parserHint = ((View) getModel()).getType();
291
			ParserHintAdapter hintAdapter = new ParserHintAdapter(getParserElement(), parserHint) {
292
293
				public Object getAdapter(Class adapter) {
294
					if (IElementType.class.equals(adapter)) {
295
						return UMLElementTypes.Operation_3002;
296
					}
297
					return super.getAdapter(adapter);
298
				}
299
			};
300
			parser = ParserService.getInstance().getParser(hintAdapter);
301
		}
302
		return parser;
303
	}
304
305
	/**
306
	 * @generated
307
	 */
308
	protected DirectEditManager getManager() {
309
		if (manager == null) {
310
			setManager(new TextDirectEditManager(this, TextDirectEditManager.getTextCellEditorClass(this), UMLEditPartFactory.getTextCellEditorLocator(this)));
311
		}
312
		return manager;
313
	}
314
315
	/**
316
	 * @generated
317
	 */
318
	protected void setManager(DirectEditManager manager) {
319
		this.manager = manager;
320
	}
321
322
	/**
323
	 * @generated
324
	 */
325
	protected void performDirectEdit() {
326
		getManager().show();
327
	}
328
329
	/**
330
	 * @generated
331
	 */
332
	protected void performDirectEdit(Point eventLocation) {
333
		if (getManager().getClass() == TextDirectEditManager.class) {
334
			((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint());
335
		}
336
	}
337
338
	/**
339
	 * @generated
340
	 */
341
	private void performDirectEdit(char initialCharacter) {
342
		if (getManager() instanceof TextDirectEditManager) {
343
			((TextDirectEditManager) getManager()).show(initialCharacter);
344
		} else {
345
			performDirectEdit();
346
		}
347
	}
348
349
	/**
350
	 * @generated
351
	 */
352
	protected void performDirectEditRequest(Request request) {
353
		final Request theRequest = request;
354
		try {
355
			getEditingDomain().runExclusive(new Runnable() {
356
357
				public void run() {
358
					if (isActive() && isEditable()) {
359
						if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) {
360
							Character initialChar = (Character) theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR);
361
							performDirectEdit(initialChar.charValue());
362
						} else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) {
363
							DirectEditRequest editRequest = (DirectEditRequest) theRequest;
364
							performDirectEdit(editRequest.getLocation());
365
						} else {
366
							performDirectEdit();
367
						}
368
					}
369
				}
370
			});
371
		} catch (InterruptedException e) {
372
			e.printStackTrace();
373
		}
374
	}
375
376
	/**
377
	 * @generated
378
	 */
379
	protected void refreshVisuals() {
380
		super.refreshVisuals();
381
		refreshLabel();
382
		refreshFont();
383
		refreshFontColor();
384
		refreshUnderline();
385
		refreshStrikeThrough();
386
	}
387
388
	/**
389
	 * @generated
390
	 */
391
	protected void refreshLabel() {
392
		setLabelTextHelper(getFigure(), getLabelText());
393
		setLabelIconHelper(getFigure(), getLabelIcon());
394
		Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
395
		if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) {
396
			((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback();
397
		}
398
	}
399
400
	/**
401
	 * @generated
402
	 */
403
	protected void refreshUnderline() {
404
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
405
		if (style != null && getFigure() instanceof WrapLabel) {
406
			((WrapLabel) getFigure()).setTextUnderline(style.isUnderline());
407
		}
408
	}
409
410
	/**
411
	 * @generated
412
	 */
413
	protected void refreshStrikeThrough() {
414
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
415
		if (style != null && getFigure() instanceof WrapLabel) {
416
			((WrapLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough());
417
		}
418
	}
419
420
	/**
421
	 * @generated
422
	 */
423
	protected void refreshFont() {
424
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
425
		if (style != null) {
426
			FontData fontData = new FontData(style.getFontName(), style.getFontHeight(), (style.isBold() ? SWT.BOLD : SWT.NORMAL) | (style.isItalic() ? SWT.ITALIC : SWT.NORMAL));
427
			setFont(fontData);
428
		}
429
	}
430
431
	/**
432
	 * @generated
433
	 */
434
	protected void setFontColor(Color color) {
435
		getFigure().setForegroundColor(color);
436
	}
437
438
	/**
439
	 * @generated
440
	 */
441
	protected void addSemanticListeners() {
442
		if (getParser() instanceof ISemanticParser) {
443
			EObject element = resolveSemanticElement();
444
			parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element);
445
			for (int i = 0; i < parserElements.size(); i++) {
446
				addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$
447
			}
448
		} else {
449
			super.addSemanticListeners();
450
		}
451
	}
452
453
	/**
454
	 * @generated
455
	 */
456
	protected void removeSemanticListeners() {
457
		if (parserElements != null) {
458
			for (int i = 0; i < parserElements.size(); i++) {
459
				removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$
460
			}
461
		} else {
462
			super.removeSemanticListeners();
463
		}
464
	}
465
466
	/**
467
	 * @generated
468
	 */
469
	protected AccessibleEditPart getAccessibleEditPart() {
470
		if (accessibleEP == null) {
471
			accessibleEP = new AccessibleGraphicalEditPart() {
472
473
				public void getName(AccessibleEvent e) {
474
					e.result = getLabelTextHelper(getFigure());
475
				}
476
			};
477
		}
478
		return accessibleEP;
479
	}
480
481
	/**
482
	 * @generated
483
	 */
484
	private View getFontStyleOwnerView() {
485
		return getPrimaryView();
486
	}
487
488
	/**
489
	 * @generated
490
	 */
491
	protected void addNotationalListeners() {
492
		super.addNotationalListeners();
493
		addListenerFilter("PrimaryView", this, getPrimaryView()); //$NON-NLS-1$
494
	}
495
496
	/**
497
	 * @generated
498
	 */
499
	protected void removeNotationalListeners() {
500
		super.removeNotationalListeners();
501
		removeListenerFilter("PrimaryView"); //$NON-NLS-1$
502
	}
503
504
	/**
505
	 * @generated
506
	 */
507
	protected void handleNotificationEvent(Notification event) {
508
		Object feature = event.getFeature();
509
		if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) {
510
			Integer c = (Integer) event.getNewValue();
511
			setFontColor(DiagramColorRegistry.getInstance().getColor(c));
512
		} else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) {
513
			refreshUnderline();
514
		} else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) {
515
			refreshStrikeThrough();
516
		} else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature)
517
				|| NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) {
518
			refreshFont();
519
		} else {
520
			if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) {
521
				refreshLabel();
522
			}
523
			if (getParser() instanceof ISemanticParser) {
524
				ISemanticParser modelParser = (ISemanticParser) getParser();
525
				if (modelParser.areSemanticElementsAffected(null, event)) {
526
					removeSemanticListeners();
527
					if (resolveSemanticElement() != null) {
528
						addSemanticListeners();
529
					}
530
					refreshLabel();
531
				}
532
			}
533
		}
534
		super.handleNotificationEvent(event);
535
	}
536
537
	/**
538
	 * @generated
539
	 */
540
	protected IFigure createFigure() {
541
		IFigure label = createFigurePrim();
542
		defaultText = getLabelTextHelper(label);
543
		return label;
544
	}
545
546
	/**
547
	 * @generated
548
	 */
549
	protected IFigure createFigurePrim() {
550
		return new WrapLabel();
551
	}
552
553
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/parts/Operation5EditPart.java (+553 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.parts;
2
3
import java.util.Collections;
4
import java.util.List;
5
6
import org.eclipse.draw2d.IFigure;
7
import org.eclipse.draw2d.Label;
8
import org.eclipse.draw2d.geometry.Point;
9
import org.eclipse.emf.common.notify.Notification;
10
import org.eclipse.emf.ecore.EObject;
11
import org.eclipse.emf.transaction.RunnableWithResult;
12
import org.eclipse.gef.AccessibleEditPart;
13
import org.eclipse.gef.DragTracker;
14
import org.eclipse.gef.EditPolicy;
15
import org.eclipse.gef.Request;
16
import org.eclipse.gef.requests.DirectEditRequest;
17
import org.eclipse.gef.requests.SelectionRequest;
18
import org.eclipse.gef.tools.DirectEditManager;
19
import org.eclipse.gmf.runtime.common.ui.services.parser.IParser;
20
import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus;
21
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserEditStatus;
22
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions;
23
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserService;
24
import org.eclipse.gmf.runtime.diagram.ui.editparts.CompartmentEditPart;
25
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
26
import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart;
27
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
28
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy;
29
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.ListItemComponentEditPolicy;
30
import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry;
31
import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants;
32
import org.eclipse.gmf.runtime.diagram.ui.tools.DragEditPartsTrackerEx;
33
import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager;
34
import org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel;
35
import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
36
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
37
import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser;
38
import org.eclipse.gmf.runtime.emf.ui.services.parser.ParserHintAdapter;
39
import org.eclipse.gmf.runtime.notation.FontStyle;
40
import org.eclipse.gmf.runtime.notation.NotationPackage;
41
import org.eclipse.gmf.runtime.notation.View;
42
import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
43
import org.eclipse.jface.viewers.ICellEditorValidator;
44
import org.eclipse.swt.SWT;
45
import org.eclipse.swt.accessibility.AccessibleEvent;
46
import org.eclipse.swt.graphics.Color;
47
import org.eclipse.swt.graphics.FontData;
48
import org.eclipse.swt.graphics.Image;
49
import org.eclipse.uml2.diagram.clazz.edit.policies.Operation5ItemSemanticEditPolicy;
50
import org.eclipse.uml2.diagram.clazz.edit.policies.UMLTextNonResizableEditPolicy;
51
import org.eclipse.uml2.diagram.clazz.edit.policies.UMLTextSelectionEditPolicy;
52
import org.eclipse.uml2.diagram.clazz.providers.UMLElementTypes;
53
54
/**
55
 * @generated
56
 */
57
public class Operation5EditPart extends CompartmentEditPart implements ITextAwareEditPart {
58
59
	/**
60
	 * @generated
61
	 */
62
	public static final int VISUAL_ID = 3024;
63
64
	/**
65
	 * @generated
66
	 */
67
	private DirectEditManager manager;
68
69
	/**
70
	 * @generated
71
	 */
72
	private IParser parser;
73
74
	/**
75
	 * @generated
76
	 */
77
	private List parserElements;
78
79
	/**
80
	 * @generated
81
	 */
82
	private String defaultText;
83
84
	/**
85
	 * @generated
86
	 */
87
	public Operation5EditPart(View view) {
88
		super(view);
89
	}
90
91
	/**
92
	 * @generated
93
	 */
94
	public DragTracker getDragTracker(Request request) {
95
		if (request instanceof SelectionRequest && ((SelectionRequest) request).getLastButtonPressed() == 3) {
96
			return null;
97
		}
98
		return new DragEditPartsTrackerEx(this);
99
	}
100
101
	/**
102
	 * @generated
103
	 */
104
	protected void createDefaultEditPolicies() {
105
		super.createDefaultEditPolicies();
106
		installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new Operation5ItemSemanticEditPolicy());
107
		installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new UMLTextNonResizableEditPolicy());
108
		installEditPolicy(EditPolicy.COMPONENT_ROLE, new ListItemComponentEditPolicy());
109
		installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy());
110
111
	}
112
113
	/**
114
	 * @generated
115
	 */
116
	protected String getLabelTextHelper(IFigure figure) {
117
		if (figure instanceof WrapLabel) {
118
			return ((WrapLabel) figure).getText();
119
		} else {
120
			return ((Label) figure).getText();
121
		}
122
	}
123
124
	/**
125
	 * @generated
126
	 */
127
	protected void setLabelTextHelper(IFigure figure, String text) {
128
		if (figure instanceof WrapLabel) {
129
			((WrapLabel) figure).setText(text);
130
		} else {
131
			((Label) figure).setText(text);
132
		}
133
	}
134
135
	/**
136
	 * @generated
137
	 */
138
	protected Image getLabelIconHelper(IFigure figure) {
139
		if (figure instanceof WrapLabel) {
140
			return ((WrapLabel) figure).getIcon();
141
		} else {
142
			return ((Label) figure).getIcon();
143
		}
144
	}
145
146
	/**
147
	 * @generated
148
	 */
149
	protected void setLabelIconHelper(IFigure figure, Image icon) {
150
		if (figure instanceof WrapLabel) {
151
			((WrapLabel) figure).setIcon(icon);
152
		} else {
153
			((Label) figure).setIcon(icon);
154
		}
155
	}
156
157
	/**
158
	 * @generated
159
	 */
160
	public void setLabel(IFigure figure) {
161
		unregisterVisuals();
162
		setFigure(figure);
163
		defaultText = getLabelTextHelper(figure);
164
		registerVisuals();
165
		refreshVisuals();
166
	}
167
168
	/**
169
	 * @generated
170
	 */
171
	protected List getModelChildren() {
172
		return Collections.EMPTY_LIST;
173
	}
174
175
	/**
176
	 * @generated
177
	 */
178
	public IGraphicalEditPart getChildBySemanticHint(String semanticHint) {
179
		return null;
180
	}
181
182
	/**
183
	 * @generated
184
	 */
185
	protected EObject getParserElement() {
186
		EObject element = resolveSemanticElement();
187
		return element != null ? element : (View) getModel();
188
	}
189
190
	/**
191
	 * @generated
192
	 */
193
	protected Image getLabelIcon() {
194
		return null;
195
	}
196
197
	/**
198
	 * @generated
199
	 */
200
	protected String getLabelText() {
201
		String text = null;
202
		if (getParser() != null) {
203
			text = getParser().getPrintString(new EObjectAdapter(getParserElement()), getParserOptions().intValue());
204
		}
205
		if (text == null || text.length() == 0) {
206
			text = defaultText;
207
		}
208
		return text;
209
	}
210
211
	/**
212
	 * @generated
213
	 */
214
	public void setLabelText(String text) {
215
		setLabelTextHelper(getFigure(), text);
216
		Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
217
		if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) {
218
			((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback();
219
		}
220
	}
221
222
	/**
223
	 * @generated
224
	 */
225
	public String getEditText() {
226
		if (getParser() == null) {
227
			return ""; //$NON-NLS-1$
228
		}
229
		return getParser().getEditString(new EObjectAdapter(getParserElement()), getParserOptions().intValue());
230
	}
231
232
	/**
233
	 * @generated
234
	 */
235
	protected boolean isEditable() {
236
		return getEditText() != null;
237
	}
238
239
	/**
240
	 * @generated
241
	 */
242
	public ICellEditorValidator getEditTextValidator() {
243
		return new ICellEditorValidator() {
244
245
			public String isValid(final Object value) {
246
				if (value instanceof String) {
247
					final EObject element = getParserElement();
248
					final IParser parser = getParser();
249
					try {
250
						IParserEditStatus valid = (IParserEditStatus) getEditingDomain().runExclusive(new RunnableWithResult.Impl() {
251
252
							public void run() {
253
								setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value));
254
							}
255
						});
256
						return valid.getCode() == ParserEditStatus.EDITABLE ? null : valid.getMessage();
257
					} catch (InterruptedException ie) {
258
						ie.printStackTrace();
259
					}
260
				}
261
262
				// shouldn't get here
263
				return null;
264
			}
265
		};
266
	}
267
268
	/**
269
	 * @generated
270
	 */
271
	public IContentAssistProcessor getCompletionProcessor() {
272
		if (getParser() == null) {
273
			return null;
274
		}
275
		return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement()));
276
	}
277
278
	/**
279
	 * @generated
280
	 */
281
	public ParserOptions getParserOptions() {
282
		return ParserOptions.NONE;
283
	}
284
285
	/**
286
	 * @generated
287
	 */
288
	public IParser getParser() {
289
		if (parser == null) {
290
			String parserHint = ((View) getModel()).getType();
291
			ParserHintAdapter hintAdapter = new ParserHintAdapter(getParserElement(), parserHint) {
292
293
				public Object getAdapter(Class adapter) {
294
					if (IElementType.class.equals(adapter)) {
295
						return UMLElementTypes.Operation_3024;
296
					}
297
					return super.getAdapter(adapter);
298
				}
299
			};
300
			parser = ParserService.getInstance().getParser(hintAdapter);
301
		}
302
		return parser;
303
	}
304
305
	/**
306
	 * @generated
307
	 */
308
	protected DirectEditManager getManager() {
309
		if (manager == null) {
310
			setManager(new TextDirectEditManager(this, TextDirectEditManager.getTextCellEditorClass(this), UMLEditPartFactory.getTextCellEditorLocator(this)));
311
		}
312
		return manager;
313
	}
314
315
	/**
316
	 * @generated
317
	 */
318
	protected void setManager(DirectEditManager manager) {
319
		this.manager = manager;
320
	}
321
322
	/**
323
	 * @generated
324
	 */
325
	protected void performDirectEdit() {
326
		getManager().show();
327
	}
328
329
	/**
330
	 * @generated
331
	 */
332
	protected void performDirectEdit(Point eventLocation) {
333
		if (getManager().getClass() == TextDirectEditManager.class) {
334
			((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint());
335
		}
336
	}
337
338
	/**
339
	 * @generated
340
	 */
341
	private void performDirectEdit(char initialCharacter) {
342
		if (getManager() instanceof TextDirectEditManager) {
343
			((TextDirectEditManager) getManager()).show(initialCharacter);
344
		} else {
345
			performDirectEdit();
346
		}
347
	}
348
349
	/**
350
	 * @generated
351
	 */
352
	protected void performDirectEditRequest(Request request) {
353
		final Request theRequest = request;
354
		try {
355
			getEditingDomain().runExclusive(new Runnable() {
356
357
				public void run() {
358
					if (isActive() && isEditable()) {
359
						if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) {
360
							Character initialChar = (Character) theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR);
361
							performDirectEdit(initialChar.charValue());
362
						} else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) {
363
							DirectEditRequest editRequest = (DirectEditRequest) theRequest;
364
							performDirectEdit(editRequest.getLocation());
365
						} else {
366
							performDirectEdit();
367
						}
368
					}
369
				}
370
			});
371
		} catch (InterruptedException e) {
372
			e.printStackTrace();
373
		}
374
	}
375
376
	/**
377
	 * @generated
378
	 */
379
	protected void refreshVisuals() {
380
		super.refreshVisuals();
381
		refreshLabel();
382
		refreshFont();
383
		refreshFontColor();
384
		refreshUnderline();
385
		refreshStrikeThrough();
386
	}
387
388
	/**
389
	 * @generated
390
	 */
391
	protected void refreshLabel() {
392
		setLabelTextHelper(getFigure(), getLabelText());
393
		setLabelIconHelper(getFigure(), getLabelIcon());
394
		Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
395
		if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) {
396
			((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback();
397
		}
398
	}
399
400
	/**
401
	 * @generated
402
	 */
403
	protected void refreshUnderline() {
404
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
405
		if (style != null && getFigure() instanceof WrapLabel) {
406
			((WrapLabel) getFigure()).setTextUnderline(style.isUnderline());
407
		}
408
	}
409
410
	/**
411
	 * @generated
412
	 */
413
	protected void refreshStrikeThrough() {
414
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
415
		if (style != null && getFigure() instanceof WrapLabel) {
416
			((WrapLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough());
417
		}
418
	}
419
420
	/**
421
	 * @generated
422
	 */
423
	protected void refreshFont() {
424
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
425
		if (style != null) {
426
			FontData fontData = new FontData(style.getFontName(), style.getFontHeight(), (style.isBold() ? SWT.BOLD : SWT.NORMAL) | (style.isItalic() ? SWT.ITALIC : SWT.NORMAL));
427
			setFont(fontData);
428
		}
429
	}
430
431
	/**
432
	 * @generated
433
	 */
434
	protected void setFontColor(Color color) {
435
		getFigure().setForegroundColor(color);
436
	}
437
438
	/**
439
	 * @generated
440
	 */
441
	protected void addSemanticListeners() {
442
		if (getParser() instanceof ISemanticParser) {
443
			EObject element = resolveSemanticElement();
444
			parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element);
445
			for (int i = 0; i < parserElements.size(); i++) {
446
				addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$
447
			}
448
		} else {
449
			super.addSemanticListeners();
450
		}
451
	}
452
453
	/**
454
	 * @generated
455
	 */
456
	protected void removeSemanticListeners() {
457
		if (parserElements != null) {
458
			for (int i = 0; i < parserElements.size(); i++) {
459
				removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$
460
			}
461
		} else {
462
			super.removeSemanticListeners();
463
		}
464
	}
465
466
	/**
467
	 * @generated
468
	 */
469
	protected AccessibleEditPart getAccessibleEditPart() {
470
		if (accessibleEP == null) {
471
			accessibleEP = new AccessibleGraphicalEditPart() {
472
473
				public void getName(AccessibleEvent e) {
474
					e.result = getLabelTextHelper(getFigure());
475
				}
476
			};
477
		}
478
		return accessibleEP;
479
	}
480
481
	/**
482
	 * @generated
483
	 */
484
	private View getFontStyleOwnerView() {
485
		return getPrimaryView();
486
	}
487
488
	/**
489
	 * @generated
490
	 */
491
	protected void addNotationalListeners() {
492
		super.addNotationalListeners();
493
		addListenerFilter("PrimaryView", this, getPrimaryView()); //$NON-NLS-1$
494
	}
495
496
	/**
497
	 * @generated
498
	 */
499
	protected void removeNotationalListeners() {
500
		super.removeNotationalListeners();
501
		removeListenerFilter("PrimaryView"); //$NON-NLS-1$
502
	}
503
504
	/**
505
	 * @generated
506
	 */
507
	protected void handleNotificationEvent(Notification event) {
508
		Object feature = event.getFeature();
509
		if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) {
510
			Integer c = (Integer) event.getNewValue();
511
			setFontColor(DiagramColorRegistry.getInstance().getColor(c));
512
		} else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) {
513
			refreshUnderline();
514
		} else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) {
515
			refreshStrikeThrough();
516
		} else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature)
517
				|| NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) {
518
			refreshFont();
519
		} else {
520
			if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) {
521
				refreshLabel();
522
			}
523
			if (getParser() instanceof ISemanticParser) {
524
				ISemanticParser modelParser = (ISemanticParser) getParser();
525
				if (modelParser.areSemanticElementsAffected(null, event)) {
526
					removeSemanticListeners();
527
					if (resolveSemanticElement() != null) {
528
						addSemanticListeners();
529
					}
530
					refreshLabel();
531
				}
532
			}
533
		}
534
		super.handleNotificationEvent(event);
535
	}
536
537
	/**
538
	 * @generated
539
	 */
540
	protected IFigure createFigure() {
541
		IFigure label = createFigurePrim();
542
		defaultText = getLabelTextHelper(label);
543
		return label;
544
	}
545
546
	/**
547
	 * @generated
548
	 */
549
	protected IFigure createFigurePrim() {
550
		return new WrapLabel();
551
	}
552
553
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/parts/UsageEditPart.java (+73 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.parts;
2
3
import org.eclipse.draw2d.Connection;
4
import org.eclipse.gmf.runtime.diagram.ui.editparts.ConnectionNodeEditPart;
5
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
6
import org.eclipse.gmf.runtime.notation.View;
7
import org.eclipse.uml2.diagram.clazz.edit.policies.UsageItemSemanticEditPolicy;
8
9
/**
10
 * @generated
11
 */
12
public class UsageEditPart extends ConnectionNodeEditPart {
13
14
	/**
15
	 * @generated
16
	 */
17
	public static final int VISUAL_ID = 4009;
18
19
	/**
20
	 * @generated
21
	 */
22
	public UsageEditPart(View view) {
23
		super(view);
24
	}
25
26
	/**
27
	 * @generated
28
	 */
29
	protected void createDefaultEditPolicies() {
30
		super.createDefaultEditPolicies();
31
		installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new UsageItemSemanticEditPolicy());
32
33
	}
34
35
	/**
36
	 * Creates figure for this edit part.
37
	 * 
38
	 * Body of this method does not depend on settings in generation model
39
	 * so you may safely remove <i>generated</i> tag and modify it.
40
	 * 
41
	 * @generated
42
	 */
43
	protected Connection createConnectionFigure() {
44
		return new RequiredInterfaceConnectionFigure();
45
	}
46
47
	/**
48
	 * @generated
49
	 */
50
	public class RequiredInterfaceConnectionFigure extends org.eclipse.gmf.runtime.draw2d.ui.figures.PolylineConnectionEx {
51
52
		/**
53
		 * @generated
54
		 */
55
		public RequiredInterfaceConnectionFigure() {
56
57
			setTargetDecoration(createTargetDecoration());
58
		}
59
60
		/**
61
		 * @generated
62
		 */
63
		private org.eclipse.uml2.diagram.common.draw2d.RequiredInterfaceDecoration createTargetDecoration() {
64
			org.eclipse.uml2.diagram.common.draw2d.RequiredInterfaceDecoration df = new org.eclipse.uml2.diagram.common.draw2d.RequiredInterfaceDecoration();
65
66
			df.setRadius(10);
67
68
			return df;
69
		}
70
71
	}
72
73
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/policies/EnumerationItemSemanticEditPolicy.java (+455 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.policies;
2
3
import org.eclipse.emf.ecore.EAnnotation;
4
import org.eclipse.emf.ecore.EClass;
5
import org.eclipse.emf.ecore.EObject;
6
import org.eclipse.gef.commands.Command;
7
import org.eclipse.gef.commands.UnexecutableCommand;
8
import org.eclipse.gmf.runtime.emf.type.core.commands.CreateRelationshipCommand;
9
import org.eclipse.gmf.runtime.emf.type.core.commands.DestroyElementCommand;
10
import org.eclipse.gmf.runtime.emf.type.core.commands.SetValueCommand;
11
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest;
12
import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest;
13
import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest;
14
import org.eclipse.gmf.runtime.notation.View;
15
import org.eclipse.uml2.diagram.clazz.providers.UMLElementTypes;
16
import org.eclipse.uml2.uml.Association;
17
import org.eclipse.uml2.uml.Classifier;
18
import org.eclipse.uml2.uml.Constraint;
19
import org.eclipse.uml2.uml.Dependency;
20
import org.eclipse.uml2.uml.Generalization;
21
import org.eclipse.uml2.uml.NamedElement;
22
import org.eclipse.uml2.uml.Property;
23
import org.eclipse.uml2.uml.Type;
24
import org.eclipse.uml2.uml.UMLPackage;
25
import org.eclipse.uml2.uml.Usage;
26
27
/**
28
 * @generated
29
 */
30
public class EnumerationItemSemanticEditPolicy extends UMLBaseItemSemanticEditPolicy {
31
32
	/**
33
	 * @generated
34
	 */
35
	protected Command getDestroyElementCommand(DestroyElementRequest req) {
36
		return getMSLWrapper(new DestroyElementCommand(req) {
37
38
			protected EObject getElementToDestroy() {
39
				View view = (View) getHost().getModel();
40
				EAnnotation annotation = view.getEAnnotation("Shortcut"); //$NON-NLS-1$
41
				if (annotation != null) {
42
					return view;
43
				}
44
				return super.getElementToDestroy();
45
			}
46
47
		});
48
	}
49
50
	/**
51
	 * @generated
52
	 */
53
	protected Command getCreateRelationshipCommand(CreateRelationshipRequest req) {
54
		if (UMLElementTypes.Generalization_4001 == req.getElementType()) {
55
			return req.getTarget() == null ? getCreateStartOutgoingGeneralization4001Command(req) : getCreateCompleteIncomingGeneralization4001Command(req);
56
		}
57
		if (UMLElementTypes.Dependency_4002 == req.getElementType()) {
58
			return req.getTarget() == null ? getCreateStartOutgoingDependency4002Command(req) : getCreateCompleteIncomingDependency4002Command(req);
59
		}
60
		if (UMLElementTypes.Property_4003 == req.getElementType()) {
61
			return req.getTarget() == null ? null : getCreateCompleteIncomingProperty4003Command(req);
62
		}
63
		if (UMLElementTypes.ConstraintConstrainedElement_4004 == req.getElementType()) {
64
			return req.getTarget() == null ? null : getCreateCompleteIncomingConstraint_ConstrainedElement4004Command(req);
65
		}
66
		if (UMLElementTypes.Association_4005 == req.getElementType()) {
67
			return req.getTarget() == null ? getCreateStartOutgoingAssociation4005Command(req) : getCreateCompleteIncomingAssociation4005Command(req);
68
		}
69
		if (UMLElementTypes.DependencySupplier_4006 == req.getElementType()) {
70
			return req.getTarget() == null ? null : getCreateCompleteIncomingDependency_Supplier4006Command(req);
71
		}
72
		if (UMLElementTypes.DependencyClient_4007 == req.getElementType()) {
73
			return req.getTarget() == null ? null : getCreateCompleteIncomingDependency_Client4007Command(req);
74
		}
75
		if (UMLElementTypes.Usage_4009 == req.getElementType()) {
76
			return req.getTarget() == null ? getCreateStartOutgoingUsage4009Command(req) : getCreateCompleteIncomingUsage4009Command(req);
77
		}
78
		return super.getCreateRelationshipCommand(req);
79
	}
80
81
	/**
82
	 * @generated
83
	 */
84
	protected Command getCreateStartOutgoingGeneralization4001Command(CreateRelationshipRequest req) {
85
		return new Command() {
86
		};
87
	}
88
89
	/**
90
	 * @generated
91
	 */
92
	protected Command getCreateCompleteIncomingGeneralization4001Command(CreateRelationshipRequest req) {
93
		if (!(req.getSource() instanceof Classifier)) {
94
			return UnexecutableCommand.INSTANCE;
95
		}
96
		final Classifier element = (Classifier) req.getSource();
97
		if (req.getContainmentFeature() == null) {
98
			req.setContainmentFeature(UMLPackage.eINSTANCE.getClassifier_Generalization());
99
		}
100
		return getMSLWrapper(new CreateIncomingGeneralization4001Command(req) {
101
102
			protected EObject getElementToEdit() {
103
				return element;
104
			}
105
		});
106
	}
107
108
	/**
109
	 * @generated
110
	 */
111
	private static class CreateIncomingGeneralization4001Command extends CreateRelationshipCommand {
112
113
		/**
114
		 * @generated
115
		 */
116
		public CreateIncomingGeneralization4001Command(CreateRelationshipRequest req) {
117
			super(req);
118
		}
119
120
		/**
121
		 * @generated
122
		 */
123
		protected EClass getEClassToEdit() {
124
			return UMLPackage.eINSTANCE.getClassifier();
125
		};
126
127
		/**
128
		 * @generated
129
		 */
130
		protected void setElementToEdit(EObject element) {
131
			throw new UnsupportedOperationException();
132
		}
133
134
		/**
135
		 * @generated
136
		 */
137
		protected EObject doDefaultElementCreation() {
138
			Generalization newElement = (Generalization) super.doDefaultElementCreation();
139
			if (newElement != null) {
140
				newElement.setGeneral((Classifier) getTarget());
141
			}
142
			return newElement;
143
		}
144
	}
145
146
	/**
147
	 * @generated
148
	 */
149
	protected Command getCreateStartOutgoingDependency4002Command(CreateRelationshipRequest req) {
150
		return new Command() {
151
		};
152
	}
153
154
	/**
155
	 * @generated
156
	 */
157
	protected Command getCreateCompleteIncomingDependency4002Command(CreateRelationshipRequest req) {
158
		if (!(req.getSource() instanceof NamedElement)) {
159
			return UnexecutableCommand.INSTANCE;
160
		}
161
		final org.eclipse.uml2.uml.Package element = (org.eclipse.uml2.uml.Package) getRelationshipContainer(req.getSource(), UMLPackage.eINSTANCE.getPackage(), req.getElementType());
162
		if (element == null) {
163
			return UnexecutableCommand.INSTANCE;
164
		}
165
		if (req.getContainmentFeature() == null) {
166
			req.setContainmentFeature(UMLPackage.eINSTANCE.getPackage_PackagedElement());
167
		}
168
		return getMSLWrapper(new CreateIncomingDependency4002Command(req) {
169
170
			protected EObject getElementToEdit() {
171
				return element;
172
			}
173
		});
174
	}
175
176
	/**
177
	 * @generated
178
	 */
179
	private static class CreateIncomingDependency4002Command extends CreateRelationshipCommand {
180
181
		/**
182
		 * @generated
183
		 */
184
		public CreateIncomingDependency4002Command(CreateRelationshipRequest req) {
185
			super(req);
186
		}
187
188
		/**
189
		 * @generated
190
		 */
191
		protected EClass getEClassToEdit() {
192
			return UMLPackage.eINSTANCE.getPackage();
193
		};
194
195
		/**
196
		 * @generated
197
		 */
198
		protected void setElementToEdit(EObject element) {
199
			throw new UnsupportedOperationException();
200
		}
201
202
		/**
203
		 * @generated
204
		 */
205
		protected EObject doDefaultElementCreation() {
206
			Dependency newElement = (Dependency) super.doDefaultElementCreation();
207
			if (newElement != null) {
208
				newElement.getSuppliers().add((NamedElement) getTarget());
209
				newElement.getClients().add((NamedElement) getSource());
210
			}
211
			return newElement;
212
		}
213
	}
214
215
	/**
216
	 * @generated
217
	 */
218
	protected Command getCreateCompleteIncomingProperty4003Command(CreateRelationshipRequest req) {
219
		if (!(req.getSource() instanceof Association)) {
220
			return UnexecutableCommand.INSTANCE;
221
		}
222
		final Association element = (Association) req.getSource();
223
		if (req.getContainmentFeature() == null) {
224
			req.setContainmentFeature(UMLPackage.eINSTANCE.getAssociation_OwnedEnd());
225
		}
226
		return getMSLWrapper(new CreateIncomingProperty4003Command(req) {
227
228
			protected EObject getElementToEdit() {
229
				return element;
230
			}
231
		});
232
	}
233
234
	/**
235
	 * @generated
236
	 */
237
	private static class CreateIncomingProperty4003Command extends CreateRelationshipCommand {
238
239
		/**
240
		 * @generated
241
		 */
242
		public CreateIncomingProperty4003Command(CreateRelationshipRequest req) {
243
			super(req);
244
		}
245
246
		/**
247
		 * @generated
248
		 */
249
		protected EClass getEClassToEdit() {
250
			return UMLPackage.eINSTANCE.getAssociation();
251
		};
252
253
		/**
254
		 * @generated
255
		 */
256
		protected void setElementToEdit(EObject element) {
257
			throw new UnsupportedOperationException();
258
		}
259
260
		/**
261
		 * @generated
262
		 */
263
		protected EObject doDefaultElementCreation() {
264
			Property newElement = (Property) super.doDefaultElementCreation();
265
			if (newElement != null) {
266
				newElement.setType((Type) getTarget());
267
			}
268
			return newElement;
269
		}
270
	}
271
272
	/**
273
	 * @generated
274
	 */
275
	protected Command getCreateCompleteIncomingConstraint_ConstrainedElement4004Command(CreateRelationshipRequest req) {
276
		if (!(req.getSource() instanceof Constraint)) {
277
			return UnexecutableCommand.INSTANCE;
278
		}
279
		Constraint element = (Constraint) req.getSource();
280
		if (element.getConstrainedElements().contains(req.getTarget())) {
281
			return UnexecutableCommand.INSTANCE;
282
		}
283
		SetRequest setReq = new SetRequest(req.getSource(), UMLPackage.eINSTANCE.getConstraint_ConstrainedElement(), req.getTarget());
284
		return getMSLWrapper(new SetValueCommand(setReq));
285
	}
286
287
	/**
288
	 * @generated
289
	 */
290
	protected Command getCreateStartOutgoingAssociation4005Command(CreateRelationshipRequest req) {
291
		return new Command() {
292
		};
293
	}
294
295
	/**
296
	 * @generated
297
	 */
298
	protected Command getCreateCompleteIncomingAssociation4005Command(CreateRelationshipRequest req) {
299
		if (!(req.getSource() instanceof Type)) {
300
			return UnexecutableCommand.INSTANCE;
301
		}
302
		final org.eclipse.uml2.uml.Package element = (org.eclipse.uml2.uml.Package) getRelationshipContainer(req.getSource(), UMLPackage.eINSTANCE.getPackage(), req.getElementType());
303
		if (element == null) {
304
			return UnexecutableCommand.INSTANCE;
305
		}
306
		if (req.getContainmentFeature() == null) {
307
			req.setContainmentFeature(UMLPackage.eINSTANCE.getPackage_PackagedElement());
308
		}
309
		return getMSLWrapper(new CreateIncomingAssociation4005Command(req) {
310
311
			protected EObject getElementToEdit() {
312
				return element;
313
			}
314
		});
315
	}
316
317
	/**
318
	 * @generated NOT
319
	 */
320
	private static class CreateIncomingAssociation4005Command extends CreateAssociationCommand {
321
322
		/**
323
		 * @generated
324
		 */
325
		public CreateIncomingAssociation4005Command(CreateRelationshipRequest req) {
326
			super(req);
327
		}
328
329
		/**
330
		 * @generated
331
		 */
332
		protected EClass getEClassToEdit() {
333
			return UMLPackage.eINSTANCE.getPackage();
334
		};
335
336
		/**
337
		 * @generated
338
		 */
339
		protected void setElementToEdit(EObject element) {
340
			throw new UnsupportedOperationException();
341
		}
342
343
		/**
344
		 * @generated NOT
345
		 */
346
		protected EObject doDefaultElementCreation() {
347
			return super.doDefaultElementCreation();
348
		}
349
	}
350
351
	/**
352
	 * @generated
353
	 */
354
	protected Command getCreateCompleteIncomingDependency_Supplier4006Command(CreateRelationshipRequest req) {
355
		if (!(req.getSource() instanceof Dependency)) {
356
			return UnexecutableCommand.INSTANCE;
357
		}
358
		Dependency element = (Dependency) req.getSource();
359
		if (element.getSuppliers().contains(req.getTarget())) {
360
			return UnexecutableCommand.INSTANCE;
361
		}
362
		SetRequest setReq = new SetRequest(req.getSource(), UMLPackage.eINSTANCE.getDependency_Supplier(), req.getTarget());
363
		return getMSLWrapper(new SetValueCommand(setReq));
364
	}
365
366
	/**
367
	 * @generated
368
	 */
369
	protected Command getCreateCompleteIncomingDependency_Client4007Command(CreateRelationshipRequest req) {
370
		if (!(req.getSource() instanceof Dependency)) {
371
			return UnexecutableCommand.INSTANCE;
372
		}
373
		Dependency element = (Dependency) req.getSource();
374
		if (element.getClients().contains(req.getTarget())) {
375
			return UnexecutableCommand.INSTANCE;
376
		}
377
		SetRequest setReq = new SetRequest(req.getSource(), UMLPackage.eINSTANCE.getDependency_Client(), req.getTarget());
378
		return getMSLWrapper(new SetValueCommand(setReq));
379
	}
380
381
	/**
382
	 * @generated
383
	 */
384
	protected Command getCreateStartOutgoingUsage4009Command(CreateRelationshipRequest req) {
385
		if (!UMLBaseItemSemanticEditPolicy.LinkConstraints.Usage_4009.canCreateLink(req, false)) {
386
			return UnexecutableCommand.INSTANCE;
387
		}
388
		return new Command() {
389
		};
390
	}
391
392
	/**
393
	 * @generated
394
	 */
395
	protected Command getCreateCompleteIncomingUsage4009Command(CreateRelationshipRequest req) {
396
		if (!(req.getSource() instanceof NamedElement)) {
397
			return UnexecutableCommand.INSTANCE;
398
		}
399
		final org.eclipse.uml2.uml.Package element = (org.eclipse.uml2.uml.Package) getRelationshipContainer(req.getSource(), UMLPackage.eINSTANCE.getPackage(), req.getElementType());
400
		if (element == null) {
401
			return UnexecutableCommand.INSTANCE;
402
		}
403
		if (!UMLBaseItemSemanticEditPolicy.LinkConstraints.Usage_4009.canCreateLink(req, false)) {
404
			return UnexecutableCommand.INSTANCE;
405
		}
406
		if (req.getContainmentFeature() == null) {
407
			req.setContainmentFeature(UMLPackage.eINSTANCE.getPackage_PackagedElement());
408
		}
409
		return getMSLWrapper(new CreateIncomingUsage4009Command(req) {
410
411
			protected EObject getElementToEdit() {
412
				return element;
413
			}
414
		});
415
	}
416
417
	/**
418
	 * @generated
419
	 */
420
	private static class CreateIncomingUsage4009Command extends CreateRelationshipCommand {
421
422
		/**
423
		 * @generated
424
		 */
425
		public CreateIncomingUsage4009Command(CreateRelationshipRequest req) {
426
			super(req);
427
		}
428
429
		/**
430
		 * @generated
431
		 */
432
		protected EClass getEClassToEdit() {
433
			return UMLPackage.eINSTANCE.getPackage();
434
		};
435
436
		/**
437
		 * @generated
438
		 */
439
		protected void setElementToEdit(EObject element) {
440
			throw new UnsupportedOperationException();
441
		}
442
443
		/**
444
		 * @generated
445
		 */
446
		protected EObject doDefaultElementCreation() {
447
			Usage newElement = (Usage) super.doDefaultElementCreation();
448
			if (newElement != null) {
449
				newElement.getSuppliers().add((NamedElement) getTarget());
450
				newElement.getClients().add((NamedElement) getSource());
451
			}
452
			return newElement;
453
		}
454
	}
455
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/parts/PrimitiveType2EditPart.java (+542 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.parts;
2
3
import org.eclipse.draw2d.IFigure;
4
import org.eclipse.draw2d.StackLayout;
5
import org.eclipse.gef.EditPart;
6
import org.eclipse.gef.EditPolicy;
7
import org.eclipse.gef.Request;
8
import org.eclipse.gef.commands.Command;
9
import org.eclipse.gef.editpolicies.LayoutEditPolicy;
10
import org.eclipse.gef.editpolicies.NonResizableEditPolicy;
11
import org.eclipse.gef.requests.CreateRequest;
12
import org.eclipse.gmf.runtime.diagram.core.edithelpers.CreateElementRequestAdapter;
13
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
14
import org.eclipse.gmf.runtime.diagram.ui.editparts.ShapeNodeEditPart;
15
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.CreationEditPolicy;
16
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
17
import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewAndElementRequest;
18
import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout;
19
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
20
import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure;
21
import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure;
22
import org.eclipse.gmf.runtime.notation.View;
23
import org.eclipse.uml2.diagram.clazz.edit.policies.PrimitiveType2ItemSemanticEditPolicy;
24
import org.eclipse.uml2.diagram.clazz.part.UMLVisualIDRegistry;
25
import org.eclipse.uml2.diagram.clazz.providers.UMLElementTypes;
26
27
/**
28
 * @generated
29
 */
30
public class PrimitiveType2EditPart extends ShapeNodeEditPart {
31
32
	/**
33
	 * @generated
34
	 */
35
	public static final int VISUAL_ID = 2005;
36
37
	/**
38
	 * @generated
39
	 */
40
	protected IFigure contentPane;
41
42
	/**
43
	 * @generated
44
	 */
45
	protected IFigure primaryShape;
46
47
	/**
48
	 * @generated
49
	 */
50
	public PrimitiveType2EditPart(View view) {
51
		super(view);
52
	}
53
54
	/**
55
	 * @generated
56
	 */
57
	protected void createDefaultEditPolicies() {
58
		installEditPolicy(EditPolicyRoles.CREATION_ROLE, new CreationEditPolicy() {
59
60
			public Command getCommand(Request request) {
61
				if (understandsRequest(request)) {
62
					if (request instanceof CreateViewAndElementRequest) {
63
						CreateElementRequestAdapter adapter = ((CreateViewAndElementRequest) request).getViewAndElementDescriptor().getCreateElementRequestAdapter();
64
						IElementType type = (IElementType) adapter.getAdapter(IElementType.class);
65
						if (type == UMLElementTypes.Property_3021) {
66
							EditPart compartmentEditPart = getChildBySemanticHint(UMLVisualIDRegistry.getType(PrimitiveTypeAttributesEditPart.VISUAL_ID));
67
							return compartmentEditPart == null ? null : compartmentEditPart.getCommand(request);
68
						}
69
						if (type == UMLElementTypes.Operation_3022) {
70
							EditPart compartmentEditPart = getChildBySemanticHint(UMLVisualIDRegistry.getType(PrimitiveTypeOperationsEditPart.VISUAL_ID));
71
							return compartmentEditPart == null ? null : compartmentEditPart.getCommand(request);
72
						}
73
					}
74
					return super.getCommand(request);
75
				}
76
				return null;
77
			}
78
		});
79
		super.createDefaultEditPolicies();
80
		installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new PrimitiveType2ItemSemanticEditPolicy());
81
		installEditPolicy(EditPolicy.LAYOUT_ROLE, createLayoutEditPolicy());
82
83
	}
84
85
	/**
86
	 * @generated
87
	 */
88
	protected LayoutEditPolicy createLayoutEditPolicy() {
89
		LayoutEditPolicy lep = new LayoutEditPolicy() {
90
91
			protected EditPolicy createChildEditPolicy(EditPart child) {
92
				EditPolicy result = child.getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
93
				if (result == null) {
94
					result = new NonResizableEditPolicy();
95
				}
96
				return result;
97
			}
98
99
			protected Command getMoveChildrenCommand(Request request) {
100
				return null;
101
			}
102
103
			protected Command getCreateCommand(CreateRequest request) {
104
				return null;
105
			}
106
		};
107
		return lep;
108
	}
109
110
	/**
111
	 * @generated
112
	 */
113
	protected IFigure createNodeShape() {
114
		ClassFigure figure = new ClassFigure();
115
		return primaryShape = figure;
116
	}
117
118
	/**
119
	 * @generated
120
	 */
121
	public ClassFigure getPrimaryShape() {
122
		return (ClassFigure) primaryShape;
123
	}
124
125
	/**
126
	 * @generated 
127
	 */
128
	protected IFigure getContentPaneFor(IGraphicalEditPart editPart) {
129
		if (editPart instanceof PrimitiveTypeAttributesEditPart) {
130
			return getPrimaryShape().getFigureClassFigure_PropertiesCompartment();
131
		}
132
		if (editPart instanceof PrimitiveTypeOperationsEditPart) {
133
			return getPrimaryShape().getFigureClassFigure_OperationsCompartment();
134
		}
135
136
		return super.getContentPaneFor(editPart);
137
	}
138
139
	/**
140
	 * @generated
141
	 */
142
	protected boolean addFixedChild(EditPart childEditPart) {
143
		if (childEditPart instanceof PrimitiveTypeNameEditPart) {
144
			((PrimitiveTypeNameEditPart) childEditPart).setLabel(getPrimaryShape().getFigureClassFigure_name());
145
			return true;
146
		}
147
		if (childEditPart instanceof PrimitiveTypeAttributesEditPart) {
148
			IFigure pane = getPrimaryShape().getFigureClassFigure_PropertiesCompartment();
149
			setupContentPane(pane); // FIXME each comparment should handle his content pane in his own way 
150
			pane.add(((PrimitiveTypeAttributesEditPart) childEditPart).getFigure());
151
			return true;
152
		}
153
		if (childEditPart instanceof PrimitiveTypeOperationsEditPart) {
154
			IFigure pane = getPrimaryShape().getFigureClassFigure_OperationsCompartment();
155
			setupContentPane(pane); // FIXME each comparment should handle his content pane in his own way 
156
			pane.add(((PrimitiveTypeOperationsEditPart) childEditPart).getFigure());
157
			return true;
158
		}
159
		return false;
160
	}
161
162
	/**
163
	 * @generated
164
	 */
165
	protected boolean removeFixedChild(EditPart childEditPart) {
166
		if (childEditPart instanceof PrimitiveTypeAttributesEditPart) {
167
			IFigure pane = getPrimaryShape().getFigureClassFigure_PropertiesCompartment();
168
			pane.remove(((PrimitiveTypeAttributesEditPart) childEditPart).getFigure());
169
			return true;
170
		}
171
		if (childEditPart instanceof PrimitiveTypeOperationsEditPart) {
172
			IFigure pane = getPrimaryShape().getFigureClassFigure_OperationsCompartment();
173
			pane.remove(((PrimitiveTypeOperationsEditPart) childEditPart).getFigure());
174
			return true;
175
		}
176
		return false;
177
	}
178
179
	/**
180
	 * @generated
181
	 */
182
	protected NodeFigure createNodePlate() {
183
		DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(getMapMode().DPtoLP(100), getMapMode().DPtoLP(60));
184
		return result;
185
	}
186
187
	/**
188
	 * Creates figure for this edit part.
189
	 * 
190
	 * Body of this method does not depend on settings in generation model
191
	 * so you may safely remove <i>generated</i> tag and modify it.
192
	 * 
193
	 * @generated
194
	 */
195
	protected NodeFigure createNodeFigure() {
196
		NodeFigure figure = createNodePlate();
197
		figure.setLayoutManager(new StackLayout());
198
		IFigure shape = createNodeShape();
199
		figure.add(shape);
200
		contentPane = setupContentPane(shape);
201
		return figure;
202
	}
203
204
	/**
205
	 * Default implementation treats passed figure as content pane.
206
	 * Respects layout one may have set for generated figure.
207
	 * @param nodeShape instance of generated figure class
208
	 * @generated
209
	 */
210
	protected IFigure setupContentPane(IFigure nodeShape) {
211
		if (nodeShape.getLayoutManager() == null) {
212
			ConstrainedToolbarLayout layout = new ConstrainedToolbarLayout();
213
			layout.setSpacing(getMapMode().DPtoLP(5));
214
			nodeShape.setLayoutManager(layout);
215
		}
216
		return nodeShape; // use nodeShape itself as contentPane
217
	}
218
219
	/**
220
	 * @generated
221
	 */
222
	public IFigure getContentPane() {
223
		if (contentPane != null) {
224
			return contentPane;
225
		}
226
		return super.getContentPane();
227
	}
228
229
	/**
230
	 * @generated
231
	 */
232
	public EditPart getPrimaryChildEditPart() {
233
		return getChildBySemanticHint(UMLVisualIDRegistry.getType(PrimitiveTypeNameEditPart.VISUAL_ID));
234
	}
235
236
	/**
237
	 * @generated
238
	 */
239
	protected void addChildVisual(EditPart childEditPart, int index) {
240
		if (addFixedChild(childEditPart)) {
241
			return;
242
		}
243
		super.addChildVisual(childEditPart, -1);
244
	}
245
246
	/**
247
	 * @generated
248
	 */
249
	protected void removeChildVisual(EditPart childEditPart) {
250
		if (removeFixedChild(childEditPart)) {
251
			return;
252
		}
253
		super.removeChildVisual(childEditPart);
254
	}
255
256
	/**
257
	 * @generated
258
	 */
259
	public class ClassFigure extends org.eclipse.draw2d.RectangleFigure {
260
261
		/**
262
		 * @generated
263
		 */
264
		public ClassFigure() {
265
266
			org.eclipse.gmf.internal.codegen.draw2d.GridLayout myGenLayoutManager = new org.eclipse.gmf.internal.codegen.draw2d.GridLayout();
267
			myGenLayoutManager.numColumns = 1;
268
			myGenLayoutManager.makeColumnsEqualWidth = true;
269
			myGenLayoutManager.marginWidth = 0;
270
			myGenLayoutManager.marginHeight = 0;
271
			myGenLayoutManager.horizontalSpacing = 0;
272
			myGenLayoutManager.verticalSpacing = 0;
273
274
			this.setLayoutManager(myGenLayoutManager);
275
276
			this.setFill(false);
277
			this.setOutline(false);
278
			createContents();
279
		}
280
281
		/**
282
		 * @generated
283
		 */
284
		private void createContents() {
285
			org.eclipse.draw2d.RectangleFigure fig_0 = new org.eclipse.draw2d.RectangleFigure();
286
287
			fig_0.setMinimumSize(new org.eclipse.draw2d.geometry.Dimension(getMapMode().DPtoLP(0), getMapMode().DPtoLP(25)));
288
289
			org.eclipse.uml2.diagram.common.draw2d.CenterLayout layouter0 = new org.eclipse.uml2.diagram.common.draw2d.CenterLayout();
290
291
			fig_0.setLayoutManager(layouter0);
292
293
			setFigureClassFigure_NameContainer(fig_0);
294
			org.eclipse.gmf.internal.codegen.draw2d.GridLayoutData layData0 = new org.eclipse.gmf.internal.codegen.draw2d.GridLayoutData();
295
			layData0.verticalAlignment = org.eclipse.gmf.internal.codegen.draw2d.GridLayoutData.FILL;
296
			layData0.horizontalAlignment = org.eclipse.gmf.internal.codegen.draw2d.GridLayoutData.FILL;
297
			layData0.horizontalIndent = 0;
298
			layData0.horizontalSpan = 2;
299
			layData0.verticalSpan = 1;
300
			layData0.grabExcessHorizontalSpace = true;
301
			layData0.grabExcessVerticalSpace = false;
302
303
			this.add(fig_0, layData0);
304
			org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel fig_1 = new org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel();
305
306
			setFigureClassFigure_name(fig_1);
307
308
			Object layData1 = null;
309
310
			fig_0.add(fig_1, layData1);
311
			org.eclipse.draw2d.RectangleFigure fig_2 = new org.eclipse.draw2d.RectangleFigure();
312
313
			org.eclipse.draw2d.ToolbarLayout layouter2 = new org.eclipse.draw2d.ToolbarLayout();
314
			layouter2.setStretchMinorAxis(true);
315
			layouter2.setMinorAlignment(org.eclipse.draw2d.ToolbarLayout.ALIGN_CENTER);
316
			layouter2.setSpacing(0);
317
			layouter2.setVertical(true);
318
319
			fig_2.setLayoutManager(layouter2);
320
321
			setFigureClassFigure_Body(fig_2);
322
			org.eclipse.gmf.internal.codegen.draw2d.GridLayoutData layData2 = new org.eclipse.gmf.internal.codegen.draw2d.GridLayoutData();
323
			layData2.verticalAlignment = org.eclipse.gmf.internal.codegen.draw2d.GridLayoutData.FILL;
324
			layData2.horizontalAlignment = org.eclipse.gmf.internal.codegen.draw2d.GridLayoutData.FILL;
325
			layData2.horizontalIndent = 0;
326
			layData2.horizontalSpan = 2;
327
			layData2.verticalSpan = 1;
328
			layData2.grabExcessHorizontalSpace = true;
329
			layData2.grabExcessVerticalSpace = true;
330
331
			this.add(fig_2, layData2);
332
			org.eclipse.draw2d.RectangleFigure fig_3 = new org.eclipse.draw2d.RectangleFigure();
333
334
			setFigureClassFigure_PropertiesCompartment(fig_3);
335
336
			Object layData3 = null;
337
338
			fig_2.add(fig_3, layData3);
339
			org.eclipse.draw2d.RectangleFigure fig_4 = new org.eclipse.draw2d.RectangleFigure();
340
341
			setFigureClassFigure_OperationsCompartment(fig_4);
342
343
			Object layData4 = null;
344
345
			fig_2.add(fig_4, layData4);
346
			org.eclipse.draw2d.RectangleFigure fig_5 = new org.eclipse.draw2d.RectangleFigure();
347
348
			setFigureClassFigure_ClassesCompartment(fig_5);
349
350
			Object layData5 = null;
351
352
			fig_2.add(fig_5, layData5);
353
			org.eclipse.draw2d.RectangleFigure fig_6 = new org.eclipse.draw2d.RectangleFigure();
354
355
			setFigureClassFigure_LiteralsCompartment(fig_6);
356
357
			Object layData6 = null;
358
359
			fig_2.add(fig_6, layData6);
360
			org.eclipse.draw2d.RectangleFigure fig_7 = new org.eclipse.draw2d.RectangleFigure();
361
362
			setFigureClassFigure_OthersCompartment(fig_7);
363
364
			Object layData7 = null;
365
366
			fig_2.add(fig_7, layData7);
367
		}
368
369
		/**
370
		 * @generated
371
		 */
372
		private org.eclipse.draw2d.RectangleFigure fClassFigure_NameContainer;
373
374
		/**
375
		 * @generated
376
		 */
377
		public org.eclipse.draw2d.RectangleFigure getFigureClassFigure_NameContainer() {
378
			return fClassFigure_NameContainer;
379
		}
380
381
		/**
382
		 * @generated
383
		 */
384
		private void setFigureClassFigure_NameContainer(org.eclipse.draw2d.RectangleFigure fig) {
385
			fClassFigure_NameContainer = fig;
386
		}
387
388
		/**
389
		 * @generated
390
		 */
391
		private org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel fClassFigure_name;
392
393
		/**
394
		 * @generated
395
		 */
396
		public org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel getFigureClassFigure_name() {
397
			return fClassFigure_name;
398
		}
399
400
		/**
401
		 * @generated
402
		 */
403
		private void setFigureClassFigure_name(org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel fig) {
404
			fClassFigure_name = fig;
405
		}
406
407
		/**
408
		 * @generated
409
		 */
410
		private org.eclipse.draw2d.RectangleFigure fClassFigure_Body;
411
412
		/**
413
		 * @generated
414
		 */
415
		public org.eclipse.draw2d.RectangleFigure getFigureClassFigure_Body() {
416
			return fClassFigure_Body;
417
		}
418
419
		/**
420
		 * @generated
421
		 */
422
		private void setFigureClassFigure_Body(org.eclipse.draw2d.RectangleFigure fig) {
423
			fClassFigure_Body = fig;
424
		}
425
426
		/**
427
		 * @generated
428
		 */
429
		private org.eclipse.draw2d.RectangleFigure fClassFigure_PropertiesCompartment;
430
431
		/**
432
		 * @generated
433
		 */
434
		public org.eclipse.draw2d.RectangleFigure getFigureClassFigure_PropertiesCompartment() {
435
			return fClassFigure_PropertiesCompartment;
436
		}
437
438
		/**
439
		 * @generated
440
		 */
441
		private void setFigureClassFigure_PropertiesCompartment(org.eclipse.draw2d.RectangleFigure fig) {
442
			fClassFigure_PropertiesCompartment = fig;
443
		}
444
445
		/**
446
		 * @generated
447
		 */
448
		private org.eclipse.draw2d.RectangleFigure fClassFigure_OperationsCompartment;
449
450
		/**
451
		 * @generated
452
		 */
453
		public org.eclipse.draw2d.RectangleFigure getFigureClassFigure_OperationsCompartment() {
454
			return fClassFigure_OperationsCompartment;
455
		}
456
457
		/**
458
		 * @generated
459
		 */
460
		private void setFigureClassFigure_OperationsCompartment(org.eclipse.draw2d.RectangleFigure fig) {
461
			fClassFigure_OperationsCompartment = fig;
462
		}
463
464
		/**
465
		 * @generated
466
		 */
467
		private org.eclipse.draw2d.RectangleFigure fClassFigure_ClassesCompartment;
468
469
		/**
470
		 * @generated
471
		 */
472
		public org.eclipse.draw2d.RectangleFigure getFigureClassFigure_ClassesCompartment() {
473
			return fClassFigure_ClassesCompartment;
474
		}
475
476
		/**
477
		 * @generated
478
		 */
479
		private void setFigureClassFigure_ClassesCompartment(org.eclipse.draw2d.RectangleFigure fig) {
480
			fClassFigure_ClassesCompartment = fig;
481
		}
482
483
		/**
484
		 * @generated
485
		 */
486
		private org.eclipse.draw2d.RectangleFigure fClassFigure_LiteralsCompartment;
487
488
		/**
489
		 * @generated
490
		 */
491
		public org.eclipse.draw2d.RectangleFigure getFigureClassFigure_LiteralsCompartment() {
492
			return fClassFigure_LiteralsCompartment;
493
		}
494
495
		/**
496
		 * @generated
497
		 */
498
		private void setFigureClassFigure_LiteralsCompartment(org.eclipse.draw2d.RectangleFigure fig) {
499
			fClassFigure_LiteralsCompartment = fig;
500
		}
501
502
		/**
503
		 * @generated
504
		 */
505
		private org.eclipse.draw2d.RectangleFigure fClassFigure_OthersCompartment;
506
507
		/**
508
		 * @generated
509
		 */
510
		public org.eclipse.draw2d.RectangleFigure getFigureClassFigure_OthersCompartment() {
511
			return fClassFigure_OthersCompartment;
512
		}
513
514
		/**
515
		 * @generated
516
		 */
517
		private void setFigureClassFigure_OthersCompartment(org.eclipse.draw2d.RectangleFigure fig) {
518
			fClassFigure_OthersCompartment = fig;
519
		}
520
521
		/**
522
		 * @generated
523
		 */
524
		private boolean myUseLocalCoordinates = false;
525
526
		/**
527
		 * @generated
528
		 */
529
		protected boolean useLocalCoordinates() {
530
			return myUseLocalCoordinates;
531
		}
532
533
		/**
534
		 * @generated
535
		 */
536
		protected void setUseLocalCoordinates(boolean useLocalCoordinates) {
537
			myUseLocalCoordinates = useLocalCoordinates;
538
		}
539
540
	}
541
542
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/policies/ClassItemSemanticEditPolicy.java (+466 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.policies;
2
3
import org.eclipse.emf.ecore.EAnnotation;
4
import org.eclipse.emf.ecore.EClass;
5
import org.eclipse.emf.ecore.EObject;
6
import org.eclipse.gef.commands.Command;
7
import org.eclipse.gef.commands.UnexecutableCommand;
8
import org.eclipse.gmf.runtime.emf.type.core.commands.CreateRelationshipCommand;
9
import org.eclipse.gmf.runtime.emf.type.core.commands.DestroyElementCommand;
10
import org.eclipse.gmf.runtime.emf.type.core.commands.SetValueCommand;
11
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest;
12
import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest;
13
import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest;
14
import org.eclipse.gmf.runtime.notation.View;
15
import org.eclipse.uml2.diagram.clazz.providers.UMLElementTypes;
16
import org.eclipse.uml2.uml.Association;
17
import org.eclipse.uml2.uml.Classifier;
18
import org.eclipse.uml2.uml.Constraint;
19
import org.eclipse.uml2.uml.Dependency;
20
import org.eclipse.uml2.uml.Generalization;
21
import org.eclipse.uml2.uml.NamedElement;
22
import org.eclipse.uml2.uml.Property;
23
import org.eclipse.uml2.uml.Type;
24
import org.eclipse.uml2.uml.UMLPackage;
25
import org.eclipse.uml2.uml.Usage;
26
27
/**
28
 * @generated
29
 */
30
public class ClassItemSemanticEditPolicy extends UMLBaseItemSemanticEditPolicy {
31
32
	/**
33
	 * @generated
34
	 */
35
	protected Command getDestroyElementCommand(DestroyElementRequest req) {
36
		return getMSLWrapper(new DestroyElementCommand(req) {
37
38
			protected EObject getElementToDestroy() {
39
				View view = (View) getHost().getModel();
40
				EAnnotation annotation = view.getEAnnotation("Shortcut"); //$NON-NLS-1$
41
				if (annotation != null) {
42
					return view;
43
				}
44
				return super.getElementToDestroy();
45
			}
46
47
		});
48
	}
49
50
	/**
51
	 * @generated
52
	 */
53
	protected Command getCreateRelationshipCommand(CreateRelationshipRequest req) {
54
		if (UMLElementTypes.Generalization_4001 == req.getElementType()) {
55
			return req.getTarget() == null ? getCreateStartOutgoingGeneralization4001Command(req) : getCreateCompleteIncomingGeneralization4001Command(req);
56
		}
57
		if (UMLElementTypes.Dependency_4002 == req.getElementType()) {
58
			return req.getTarget() == null ? getCreateStartOutgoingDependency4002Command(req) : getCreateCompleteIncomingDependency4002Command(req);
59
		}
60
		if (UMLElementTypes.Property_4003 == req.getElementType()) {
61
			return req.getTarget() == null ? null : getCreateCompleteIncomingProperty4003Command(req);
62
		}
63
		if (UMLElementTypes.ConstraintConstrainedElement_4004 == req.getElementType()) {
64
			return req.getTarget() == null ? null : getCreateCompleteIncomingConstraint_ConstrainedElement4004Command(req);
65
		}
66
		if (UMLElementTypes.Association_4005 == req.getElementType()) {
67
			return req.getTarget() == null ? getCreateStartOutgoingAssociation4005Command(req) : getCreateCompleteIncomingAssociation4005Command(req);
68
		}
69
		if (UMLElementTypes.DependencySupplier_4006 == req.getElementType()) {
70
			return req.getTarget() == null ? null : getCreateCompleteIncomingDependency_Supplier4006Command(req);
71
		}
72
		if (UMLElementTypes.DependencyClient_4007 == req.getElementType()) {
73
			return req.getTarget() == null ? null : getCreateCompleteIncomingDependency_Client4007Command(req);
74
		}
75
		if (UMLElementTypes.InterfaceRealization_4008 == req.getElementType()) {
76
			return req.getTarget() == null ? getCreateStartOutgoingInterfaceRealization4008Command(req) : null;
77
		}
78
		if (UMLElementTypes.Usage_4009 == req.getElementType()) {
79
			return req.getTarget() == null ? getCreateStartOutgoingUsage4009Command(req) : getCreateCompleteIncomingUsage4009Command(req);
80
		}
81
		return super.getCreateRelationshipCommand(req);
82
	}
83
84
	/**
85
	 * @generated
86
	 */
87
	protected Command getCreateStartOutgoingGeneralization4001Command(CreateRelationshipRequest req) {
88
		return new Command() {
89
		};
90
	}
91
92
	/**
93
	 * @generated
94
	 */
95
	protected Command getCreateCompleteIncomingGeneralization4001Command(CreateRelationshipRequest req) {
96
		if (!(req.getSource() instanceof Classifier)) {
97
			return UnexecutableCommand.INSTANCE;
98
		}
99
		final Classifier element = (Classifier) req.getSource();
100
		if (req.getContainmentFeature() == null) {
101
			req.setContainmentFeature(UMLPackage.eINSTANCE.getClassifier_Generalization());
102
		}
103
		return getMSLWrapper(new CreateIncomingGeneralization4001Command(req) {
104
105
			protected EObject getElementToEdit() {
106
				return element;
107
			}
108
		});
109
	}
110
111
	/**
112
	 * @generated
113
	 */
114
	private static class CreateIncomingGeneralization4001Command extends CreateRelationshipCommand {
115
116
		/**
117
		 * @generated
118
		 */
119
		public CreateIncomingGeneralization4001Command(CreateRelationshipRequest req) {
120
			super(req);
121
		}
122
123
		/**
124
		 * @generated
125
		 */
126
		protected EClass getEClassToEdit() {
127
			return UMLPackage.eINSTANCE.getClassifier();
128
		};
129
130
		/**
131
		 * @generated
132
		 */
133
		protected void setElementToEdit(EObject element) {
134
			throw new UnsupportedOperationException();
135
		}
136
137
		/**
138
		 * @generated
139
		 */
140
		protected EObject doDefaultElementCreation() {
141
			Generalization newElement = (Generalization) super.doDefaultElementCreation();
142
			if (newElement != null) {
143
				newElement.setGeneral((Classifier) getTarget());
144
			}
145
			return newElement;
146
		}
147
	}
148
149
	/**
150
	 * @generated
151
	 */
152
	protected Command getCreateStartOutgoingDependency4002Command(CreateRelationshipRequest req) {
153
		return new Command() {
154
		};
155
	}
156
157
	/**
158
	 * @generated
159
	 */
160
	protected Command getCreateCompleteIncomingDependency4002Command(CreateRelationshipRequest req) {
161
		if (!(req.getSource() instanceof NamedElement)) {
162
			return UnexecutableCommand.INSTANCE;
163
		}
164
		final org.eclipse.uml2.uml.Package element = (org.eclipse.uml2.uml.Package) getRelationshipContainer(req.getSource(), UMLPackage.eINSTANCE.getPackage(), req.getElementType());
165
		if (element == null) {
166
			return UnexecutableCommand.INSTANCE;
167
		}
168
		if (req.getContainmentFeature() == null) {
169
			req.setContainmentFeature(UMLPackage.eINSTANCE.getPackage_PackagedElement());
170
		}
171
		return getMSLWrapper(new CreateIncomingDependency4002Command(req) {
172
173
			protected EObject getElementToEdit() {
174
				return element;
175
			}
176
		});
177
	}
178
179
	/**
180
	 * @generated
181
	 */
182
	private static class CreateIncomingDependency4002Command extends CreateRelationshipCommand {
183
184
		/**
185
		 * @generated
186
		 */
187
		public CreateIncomingDependency4002Command(CreateRelationshipRequest req) {
188
			super(req);
189
		}
190
191
		/**
192
		 * @generated
193
		 */
194
		protected EClass getEClassToEdit() {
195
			return UMLPackage.eINSTANCE.getPackage();
196
		};
197
198
		/**
199
		 * @generated
200
		 */
201
		protected void setElementToEdit(EObject element) {
202
			throw new UnsupportedOperationException();
203
		}
204
205
		/**
206
		 * @generated
207
		 */
208
		protected EObject doDefaultElementCreation() {
209
			Dependency newElement = (Dependency) super.doDefaultElementCreation();
210
			if (newElement != null) {
211
				newElement.getSuppliers().add((NamedElement) getTarget());
212
				newElement.getClients().add((NamedElement) getSource());
213
			}
214
			return newElement;
215
		}
216
	}
217
218
	/**
219
	 * @generated
220
	 */
221
	protected Command getCreateCompleteIncomingProperty4003Command(CreateRelationshipRequest req) {
222
		if (!(req.getSource() instanceof Association)) {
223
			return UnexecutableCommand.INSTANCE;
224
		}
225
		final Association element = (Association) req.getSource();
226
		if (req.getContainmentFeature() == null) {
227
			req.setContainmentFeature(UMLPackage.eINSTANCE.getAssociation_OwnedEnd());
228
		}
229
		return getMSLWrapper(new CreateIncomingProperty4003Command(req) {
230
231
			protected EObject getElementToEdit() {
232
				return element;
233
			}
234
		});
235
	}
236
237
	/**
238
	 * @generated
239
	 */
240
	private static class CreateIncomingProperty4003Command extends CreateRelationshipCommand {
241
242
		/**
243
		 * @generated
244
		 */
245
		public CreateIncomingProperty4003Command(CreateRelationshipRequest req) {
246
			super(req);
247
		}
248
249
		/**
250
		 * @generated
251
		 */
252
		protected EClass getEClassToEdit() {
253
			return UMLPackage.eINSTANCE.getAssociation();
254
		};
255
256
		/**
257
		 * @generated
258
		 */
259
		protected void setElementToEdit(EObject element) {
260
			throw new UnsupportedOperationException();
261
		}
262
263
		/**
264
		 * @generated
265
		 */
266
		protected EObject doDefaultElementCreation() {
267
			Property newElement = (Property) super.doDefaultElementCreation();
268
			if (newElement != null) {
269
				newElement.setType((Type) getTarget());
270
			}
271
			return newElement;
272
		}
273
	}
274
275
	/**
276
	 * @generated
277
	 */
278
	protected Command getCreateCompleteIncomingConstraint_ConstrainedElement4004Command(CreateRelationshipRequest req) {
279
		if (!(req.getSource() instanceof Constraint)) {
280
			return UnexecutableCommand.INSTANCE;
281
		}
282
		Constraint element = (Constraint) req.getSource();
283
		if (element.getConstrainedElements().contains(req.getTarget())) {
284
			return UnexecutableCommand.INSTANCE;
285
		}
286
		SetRequest setReq = new SetRequest(req.getSource(), UMLPackage.eINSTANCE.getConstraint_ConstrainedElement(), req.getTarget());
287
		return getMSLWrapper(new SetValueCommand(setReq));
288
	}
289
290
	/**
291
	 * @generated
292
	 */
293
	protected Command getCreateStartOutgoingAssociation4005Command(CreateRelationshipRequest req) {
294
		return new Command() {
295
		};
296
	}
297
298
	/**
299
	 * @generated
300
	 */
301
	protected Command getCreateCompleteIncomingAssociation4005Command(CreateRelationshipRequest req) {
302
		if (!(req.getSource() instanceof Type)) {
303
			return UnexecutableCommand.INSTANCE;
304
		}
305
		final org.eclipse.uml2.uml.Package element = (org.eclipse.uml2.uml.Package) getRelationshipContainer(req.getSource(), UMLPackage.eINSTANCE.getPackage(), req.getElementType());
306
		if (element == null) {
307
			return UnexecutableCommand.INSTANCE;
308
		}
309
		if (req.getContainmentFeature() == null) {
310
			req.setContainmentFeature(UMLPackage.eINSTANCE.getPackage_PackagedElement());
311
		}
312
		return getMSLWrapper(new CreateIncomingAssociation4005Command(req) {
313
314
			protected EObject getElementToEdit() {
315
				return element;
316
			}
317
		});
318
	}
319
320
	/**
321
	 * @generated NOT
322
	 */
323
	private static class CreateIncomingAssociation4005Command extends CreateAssociationCommand {
324
325
		/**
326
		 * @generated
327
		 */
328
		public CreateIncomingAssociation4005Command(CreateRelationshipRequest req) {
329
			super(req);
330
		}
331
332
		/**
333
		 * @generated
334
		 */
335
		protected EClass getEClassToEdit() {
336
			return UMLPackage.eINSTANCE.getPackage();
337
		};
338
339
		/**
340
		 * @generated
341
		 */
342
		protected void setElementToEdit(EObject element) {
343
			throw new UnsupportedOperationException();
344
		}
345
346
		/**
347
		 * @generated NOT
348
		 */
349
		protected EObject doDefaultElementCreation() {
350
			return super.doDefaultElementCreation();
351
		}
352
	}
353
354
	/**
355
	 * @generated
356
	 */
357
	protected Command getCreateCompleteIncomingDependency_Supplier4006Command(CreateRelationshipRequest req) {
358
		if (!(req.getSource() instanceof Dependency)) {
359
			return UnexecutableCommand.INSTANCE;
360
		}
361
		Dependency element = (Dependency) req.getSource();
362
		if (element.getSuppliers().contains(req.getTarget())) {
363
			return UnexecutableCommand.INSTANCE;
364
		}
365
		SetRequest setReq = new SetRequest(req.getSource(), UMLPackage.eINSTANCE.getDependency_Supplier(), req.getTarget());
366
		return getMSLWrapper(new SetValueCommand(setReq));
367
	}
368
369
	/**
370
	 * @generated
371
	 */
372
	protected Command getCreateCompleteIncomingDependency_Client4007Command(CreateRelationshipRequest req) {
373
		if (!(req.getSource() instanceof Dependency)) {
374
			return UnexecutableCommand.INSTANCE;
375
		}
376
		Dependency element = (Dependency) req.getSource();
377
		if (element.getClients().contains(req.getTarget())) {
378
			return UnexecutableCommand.INSTANCE;
379
		}
380
		SetRequest setReq = new SetRequest(req.getSource(), UMLPackage.eINSTANCE.getDependency_Client(), req.getTarget());
381
		return getMSLWrapper(new SetValueCommand(setReq));
382
	}
383
384
	/**
385
	 * @generated
386
	 */
387
	protected Command getCreateStartOutgoingInterfaceRealization4008Command(CreateRelationshipRequest req) {
388
		return new Command() {
389
		};
390
	}
391
392
	/**
393
	 * @generated
394
	 */
395
	protected Command getCreateStartOutgoingUsage4009Command(CreateRelationshipRequest req) {
396
		if (!UMLBaseItemSemanticEditPolicy.LinkConstraints.Usage_4009.canCreateLink(req, false)) {
397
			return UnexecutableCommand.INSTANCE;
398
		}
399
		return new Command() {
400
		};
401
	}
402
403
	/**
404
	 * @generated
405
	 */
406
	protected Command getCreateCompleteIncomingUsage4009Command(CreateRelationshipRequest req) {
407
		if (!(req.getSource() instanceof NamedElement)) {
408
			return UnexecutableCommand.INSTANCE;
409
		}
410
		final org.eclipse.uml2.uml.Package element = (org.eclipse.uml2.uml.Package) getRelationshipContainer(req.getSource(), UMLPackage.eINSTANCE.getPackage(), req.getElementType());
411
		if (element == null) {
412
			return UnexecutableCommand.INSTANCE;
413
		}
414
		if (!UMLBaseItemSemanticEditPolicy.LinkConstraints.Usage_4009.canCreateLink(req, false)) {
415
			return UnexecutableCommand.INSTANCE;
416
		}
417
		if (req.getContainmentFeature() == null) {
418
			req.setContainmentFeature(UMLPackage.eINSTANCE.getPackage_PackagedElement());
419
		}
420
		return getMSLWrapper(new CreateIncomingUsage4009Command(req) {
421
422
			protected EObject getElementToEdit() {
423
				return element;
424
			}
425
		});
426
	}
427
428
	/**
429
	 * @generated
430
	 */
431
	private static class CreateIncomingUsage4009Command extends CreateRelationshipCommand {
432
433
		/**
434
		 * @generated
435
		 */
436
		public CreateIncomingUsage4009Command(CreateRelationshipRequest req) {
437
			super(req);
438
		}
439
440
		/**
441
		 * @generated
442
		 */
443
		protected EClass getEClassToEdit() {
444
			return UMLPackage.eINSTANCE.getPackage();
445
		};
446
447
		/**
448
		 * @generated
449
		 */
450
		protected void setElementToEdit(EObject element) {
451
			throw new UnsupportedOperationException();
452
		}
453
454
		/**
455
		 * @generated
456
		 */
457
		protected EObject doDefaultElementCreation() {
458
			Usage newElement = (Usage) super.doDefaultElementCreation();
459
			if (newElement != null) {
460
				newElement.getSuppliers().add((NamedElement) getTarget());
461
				newElement.getClients().add((NamedElement) getSource());
462
			}
463
			return newElement;
464
		}
465
	}
466
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/policies/DataTypeItemSemanticEditPolicy.java (+455 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.policies;
2
3
import org.eclipse.emf.ecore.EAnnotation;
4
import org.eclipse.emf.ecore.EClass;
5
import org.eclipse.emf.ecore.EObject;
6
import org.eclipse.gef.commands.Command;
7
import org.eclipse.gef.commands.UnexecutableCommand;
8
import org.eclipse.gmf.runtime.emf.type.core.commands.CreateRelationshipCommand;
9
import org.eclipse.gmf.runtime.emf.type.core.commands.DestroyElementCommand;
10
import org.eclipse.gmf.runtime.emf.type.core.commands.SetValueCommand;
11
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest;
12
import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest;
13
import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest;
14
import org.eclipse.gmf.runtime.notation.View;
15
import org.eclipse.uml2.diagram.clazz.providers.UMLElementTypes;
16
import org.eclipse.uml2.uml.Association;
17
import org.eclipse.uml2.uml.Classifier;
18
import org.eclipse.uml2.uml.Constraint;
19
import org.eclipse.uml2.uml.Dependency;
20
import org.eclipse.uml2.uml.Generalization;
21
import org.eclipse.uml2.uml.NamedElement;
22
import org.eclipse.uml2.uml.Property;
23
import org.eclipse.uml2.uml.Type;
24
import org.eclipse.uml2.uml.UMLPackage;
25
import org.eclipse.uml2.uml.Usage;
26
27
/**
28
 * @generated
29
 */
30
public class DataTypeItemSemanticEditPolicy extends UMLBaseItemSemanticEditPolicy {
31
32
	/**
33
	 * @generated
34
	 */
35
	protected Command getDestroyElementCommand(DestroyElementRequest req) {
36
		return getMSLWrapper(new DestroyElementCommand(req) {
37
38
			protected EObject getElementToDestroy() {
39
				View view = (View) getHost().getModel();
40
				EAnnotation annotation = view.getEAnnotation("Shortcut"); //$NON-NLS-1$
41
				if (annotation != null) {
42
					return view;
43
				}
44
				return super.getElementToDestroy();
45
			}
46
47
		});
48
	}
49
50
	/**
51
	 * @generated
52
	 */
53
	protected Command getCreateRelationshipCommand(CreateRelationshipRequest req) {
54
		if (UMLElementTypes.Generalization_4001 == req.getElementType()) {
55
			return req.getTarget() == null ? getCreateStartOutgoingGeneralization4001Command(req) : getCreateCompleteIncomingGeneralization4001Command(req);
56
		}
57
		if (UMLElementTypes.Dependency_4002 == req.getElementType()) {
58
			return req.getTarget() == null ? getCreateStartOutgoingDependency4002Command(req) : getCreateCompleteIncomingDependency4002Command(req);
59
		}
60
		if (UMLElementTypes.Property_4003 == req.getElementType()) {
61
			return req.getTarget() == null ? null : getCreateCompleteIncomingProperty4003Command(req);
62
		}
63
		if (UMLElementTypes.ConstraintConstrainedElement_4004 == req.getElementType()) {
64
			return req.getTarget() == null ? null : getCreateCompleteIncomingConstraint_ConstrainedElement4004Command(req);
65
		}
66
		if (UMLElementTypes.Association_4005 == req.getElementType()) {
67
			return req.getTarget() == null ? getCreateStartOutgoingAssociation4005Command(req) : getCreateCompleteIncomingAssociation4005Command(req);
68
		}
69
		if (UMLElementTypes.DependencySupplier_4006 == req.getElementType()) {
70
			return req.getTarget() == null ? null : getCreateCompleteIncomingDependency_Supplier4006Command(req);
71
		}
72
		if (UMLElementTypes.DependencyClient_4007 == req.getElementType()) {
73
			return req.getTarget() == null ? null : getCreateCompleteIncomingDependency_Client4007Command(req);
74
		}
75
		if (UMLElementTypes.Usage_4009 == req.getElementType()) {
76
			return req.getTarget() == null ? getCreateStartOutgoingUsage4009Command(req) : getCreateCompleteIncomingUsage4009Command(req);
77
		}
78
		return super.getCreateRelationshipCommand(req);
79
	}
80
81
	/**
82
	 * @generated
83
	 */
84
	protected Command getCreateStartOutgoingGeneralization4001Command(CreateRelationshipRequest req) {
85
		return new Command() {
86
		};
87
	}
88
89
	/**
90
	 * @generated
91
	 */
92
	protected Command getCreateCompleteIncomingGeneralization4001Command(CreateRelationshipRequest req) {
93
		if (!(req.getSource() instanceof Classifier)) {
94
			return UnexecutableCommand.INSTANCE;
95
		}
96
		final Classifier element = (Classifier) req.getSource();
97
		if (req.getContainmentFeature() == null) {
98
			req.setContainmentFeature(UMLPackage.eINSTANCE.getClassifier_Generalization());
99
		}
100
		return getMSLWrapper(new CreateIncomingGeneralization4001Command(req) {
101
102
			protected EObject getElementToEdit() {
103
				return element;
104
			}
105
		});
106
	}
107
108
	/**
109
	 * @generated
110
	 */
111
	private static class CreateIncomingGeneralization4001Command extends CreateRelationshipCommand {
112
113
		/**
114
		 * @generated
115
		 */
116
		public CreateIncomingGeneralization4001Command(CreateRelationshipRequest req) {
117
			super(req);
118
		}
119
120
		/**
121
		 * @generated
122
		 */
123
		protected EClass getEClassToEdit() {
124
			return UMLPackage.eINSTANCE.getClassifier();
125
		};
126
127
		/**
128
		 * @generated
129
		 */
130
		protected void setElementToEdit(EObject element) {
131
			throw new UnsupportedOperationException();
132
		}
133
134
		/**
135
		 * @generated
136
		 */
137
		protected EObject doDefaultElementCreation() {
138
			Generalization newElement = (Generalization) super.doDefaultElementCreation();
139
			if (newElement != null) {
140
				newElement.setGeneral((Classifier) getTarget());
141
			}
142
			return newElement;
143
		}
144
	}
145
146
	/**
147
	 * @generated
148
	 */
149
	protected Command getCreateStartOutgoingDependency4002Command(CreateRelationshipRequest req) {
150
		return new Command() {
151
		};
152
	}
153
154
	/**
155
	 * @generated
156
	 */
157
	protected Command getCreateCompleteIncomingDependency4002Command(CreateRelationshipRequest req) {
158
		if (!(req.getSource() instanceof NamedElement)) {
159
			return UnexecutableCommand.INSTANCE;
160
		}
161
		final org.eclipse.uml2.uml.Package element = (org.eclipse.uml2.uml.Package) getRelationshipContainer(req.getSource(), UMLPackage.eINSTANCE.getPackage(), req.getElementType());
162
		if (element == null) {
163
			return UnexecutableCommand.INSTANCE;
164
		}
165
		if (req.getContainmentFeature() == null) {
166
			req.setContainmentFeature(UMLPackage.eINSTANCE.getPackage_PackagedElement());
167
		}
168
		return getMSLWrapper(new CreateIncomingDependency4002Command(req) {
169
170
			protected EObject getElementToEdit() {
171
				return element;
172
			}
173
		});
174
	}
175
176
	/**
177
	 * @generated
178
	 */
179
	private static class CreateIncomingDependency4002Command extends CreateRelationshipCommand {
180
181
		/**
182
		 * @generated
183
		 */
184
		public CreateIncomingDependency4002Command(CreateRelationshipRequest req) {
185
			super(req);
186
		}
187
188
		/**
189
		 * @generated
190
		 */
191
		protected EClass getEClassToEdit() {
192
			return UMLPackage.eINSTANCE.getPackage();
193
		};
194
195
		/**
196
		 * @generated
197
		 */
198
		protected void setElementToEdit(EObject element) {
199
			throw new UnsupportedOperationException();
200
		}
201
202
		/**
203
		 * @generated
204
		 */
205
		protected EObject doDefaultElementCreation() {
206
			Dependency newElement = (Dependency) super.doDefaultElementCreation();
207
			if (newElement != null) {
208
				newElement.getSuppliers().add((NamedElement) getTarget());
209
				newElement.getClients().add((NamedElement) getSource());
210
			}
211
			return newElement;
212
		}
213
	}
214
215
	/**
216
	 * @generated
217
	 */
218
	protected Command getCreateCompleteIncomingProperty4003Command(CreateRelationshipRequest req) {
219
		if (!(req.getSource() instanceof Association)) {
220
			return UnexecutableCommand.INSTANCE;
221
		}
222
		final Association element = (Association) req.getSource();
223
		if (req.getContainmentFeature() == null) {
224
			req.setContainmentFeature(UMLPackage.eINSTANCE.getAssociation_OwnedEnd());
225
		}
226
		return getMSLWrapper(new CreateIncomingProperty4003Command(req) {
227
228
			protected EObject getElementToEdit() {
229
				return element;
230
			}
231
		});
232
	}
233
234
	/**
235
	 * @generated
236
	 */
237
	private static class CreateIncomingProperty4003Command extends CreateRelationshipCommand {
238
239
		/**
240
		 * @generated
241
		 */
242
		public CreateIncomingProperty4003Command(CreateRelationshipRequest req) {
243
			super(req);
244
		}
245
246
		/**
247
		 * @generated
248
		 */
249
		protected EClass getEClassToEdit() {
250
			return UMLPackage.eINSTANCE.getAssociation();
251
		};
252
253
		/**
254
		 * @generated
255
		 */
256
		protected void setElementToEdit(EObject element) {
257
			throw new UnsupportedOperationException();
258
		}
259
260
		/**
261
		 * @generated
262
		 */
263
		protected EObject doDefaultElementCreation() {
264
			Property newElement = (Property) super.doDefaultElementCreation();
265
			if (newElement != null) {
266
				newElement.setType((Type) getTarget());
267
			}
268
			return newElement;
269
		}
270
	}
271
272
	/**
273
	 * @generated
274
	 */
275
	protected Command getCreateCompleteIncomingConstraint_ConstrainedElement4004Command(CreateRelationshipRequest req) {
276
		if (!(req.getSource() instanceof Constraint)) {
277
			return UnexecutableCommand.INSTANCE;
278
		}
279
		Constraint element = (Constraint) req.getSource();
280
		if (element.getConstrainedElements().contains(req.getTarget())) {
281
			return UnexecutableCommand.INSTANCE;
282
		}
283
		SetRequest setReq = new SetRequest(req.getSource(), UMLPackage.eINSTANCE.getConstraint_ConstrainedElement(), req.getTarget());
284
		return getMSLWrapper(new SetValueCommand(setReq));
285
	}
286
287
	/**
288
	 * @generated
289
	 */
290
	protected Command getCreateStartOutgoingAssociation4005Command(CreateRelationshipRequest req) {
291
		return new Command() {
292
		};
293
	}
294
295
	/**
296
	 * @generated
297
	 */
298
	protected Command getCreateCompleteIncomingAssociation4005Command(CreateRelationshipRequest req) {
299
		if (!(req.getSource() instanceof Type)) {
300
			return UnexecutableCommand.INSTANCE;
301
		}
302
		final org.eclipse.uml2.uml.Package element = (org.eclipse.uml2.uml.Package) getRelationshipContainer(req.getSource(), UMLPackage.eINSTANCE.getPackage(), req.getElementType());
303
		if (element == null) {
304
			return UnexecutableCommand.INSTANCE;
305
		}
306
		if (req.getContainmentFeature() == null) {
307
			req.setContainmentFeature(UMLPackage.eINSTANCE.getPackage_PackagedElement());
308
		}
309
		return getMSLWrapper(new CreateIncomingAssociation4005Command(req) {
310
311
			protected EObject getElementToEdit() {
312
				return element;
313
			}
314
		});
315
	}
316
317
	/**
318
	 * @generated NOT
319
	 */
320
	private static class CreateIncomingAssociation4005Command extends CreateAssociationCommand {
321
322
		/**
323
		 * @generated
324
		 */
325
		public CreateIncomingAssociation4005Command(CreateRelationshipRequest req) {
326
			super(req);
327
		}
328
329
		/**
330
		 * @generated
331
		 */
332
		protected EClass getEClassToEdit() {
333
			return UMLPackage.eINSTANCE.getPackage();
334
		};
335
336
		/**
337
		 * @generated
338
		 */
339
		protected void setElementToEdit(EObject element) {
340
			throw new UnsupportedOperationException();
341
		}
342
343
		/**
344
		 * @generated NOT
345
		 */
346
		protected EObject doDefaultElementCreation() {
347
			return super.doDefaultElementCreation();
348
		}
349
	}
350
351
	/**
352
	 * @generated
353
	 */
354
	protected Command getCreateCompleteIncomingDependency_Supplier4006Command(CreateRelationshipRequest req) {
355
		if (!(req.getSource() instanceof Dependency)) {
356
			return UnexecutableCommand.INSTANCE;
357
		}
358
		Dependency element = (Dependency) req.getSource();
359
		if (element.getSuppliers().contains(req.getTarget())) {
360
			return UnexecutableCommand.INSTANCE;
361
		}
362
		SetRequest setReq = new SetRequest(req.getSource(), UMLPackage.eINSTANCE.getDependency_Supplier(), req.getTarget());
363
		return getMSLWrapper(new SetValueCommand(setReq));
364
	}
365
366
	/**
367
	 * @generated
368
	 */
369
	protected Command getCreateCompleteIncomingDependency_Client4007Command(CreateRelationshipRequest req) {
370
		if (!(req.getSource() instanceof Dependency)) {
371
			return UnexecutableCommand.INSTANCE;
372
		}
373
		Dependency element = (Dependency) req.getSource();
374
		if (element.getClients().contains(req.getTarget())) {
375
			return UnexecutableCommand.INSTANCE;
376
		}
377
		SetRequest setReq = new SetRequest(req.getSource(), UMLPackage.eINSTANCE.getDependency_Client(), req.getTarget());
378
		return getMSLWrapper(new SetValueCommand(setReq));
379
	}
380
381
	/**
382
	 * @generated
383
	 */
384
	protected Command getCreateStartOutgoingUsage4009Command(CreateRelationshipRequest req) {
385
		if (!UMLBaseItemSemanticEditPolicy.LinkConstraints.Usage_4009.canCreateLink(req, false)) {
386
			return UnexecutableCommand.INSTANCE;
387
		}
388
		return new Command() {
389
		};
390
	}
391
392
	/**
393
	 * @generated
394
	 */
395
	protected Command getCreateCompleteIncomingUsage4009Command(CreateRelationshipRequest req) {
396
		if (!(req.getSource() instanceof NamedElement)) {
397
			return UnexecutableCommand.INSTANCE;
398
		}
399
		final org.eclipse.uml2.uml.Package element = (org.eclipse.uml2.uml.Package) getRelationshipContainer(req.getSource(), UMLPackage.eINSTANCE.getPackage(), req.getElementType());
400
		if (element == null) {
401
			return UnexecutableCommand.INSTANCE;
402
		}
403
		if (!UMLBaseItemSemanticEditPolicy.LinkConstraints.Usage_4009.canCreateLink(req, false)) {
404
			return UnexecutableCommand.INSTANCE;
405
		}
406
		if (req.getContainmentFeature() == null) {
407
			req.setContainmentFeature(UMLPackage.eINSTANCE.getPackage_PackagedElement());
408
		}
409
		return getMSLWrapper(new CreateIncomingUsage4009Command(req) {
410
411
			protected EObject getElementToEdit() {
412
				return element;
413
			}
414
		});
415
	}
416
417
	/**
418
	 * @generated
419
	 */
420
	private static class CreateIncomingUsage4009Command extends CreateRelationshipCommand {
421
422
		/**
423
		 * @generated
424
		 */
425
		public CreateIncomingUsage4009Command(CreateRelationshipRequest req) {
426
			super(req);
427
		}
428
429
		/**
430
		 * @generated
431
		 */
432
		protected EClass getEClassToEdit() {
433
			return UMLPackage.eINSTANCE.getPackage();
434
		};
435
436
		/**
437
		 * @generated
438
		 */
439
		protected void setElementToEdit(EObject element) {
440
			throw new UnsupportedOperationException();
441
		}
442
443
		/**
444
		 * @generated
445
		 */
446
		protected EObject doDefaultElementCreation() {
447
			Usage newElement = (Usage) super.doDefaultElementCreation();
448
			if (newElement != null) {
449
				newElement.getSuppliers().add((NamedElement) getTarget());
450
				newElement.getClients().add((NamedElement) getSource());
451
			}
452
			return newElement;
453
		}
454
	}
455
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/policies/PrimitiveTypeAttributesCanonicalEditPolicy.java (+52 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.policies;
2
3
import java.util.Iterator;
4
import java.util.LinkedList;
5
import java.util.List;
6
7
import org.eclipse.emf.ecore.EObject;
8
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.CanonicalEditPolicy;
9
import org.eclipse.gmf.runtime.notation.View;
10
import org.eclipse.uml2.diagram.clazz.edit.parts.Property4EditPart;
11
import org.eclipse.uml2.diagram.clazz.part.UMLVisualIDRegistry;
12
import org.eclipse.uml2.uml.DataType;
13
14
/**
15
 * @generated
16
 */
17
public class PrimitiveTypeAttributesCanonicalEditPolicy extends CanonicalEditPolicy {
18
19
	/**
20
	 * @generated
21
	 */
22
	protected List getSemanticChildrenList() {
23
		List result = new LinkedList();
24
		EObject modelObject = ((View) getHost().getModel()).getElement();
25
		View viewObject = (View) getHost().getModel();
26
		EObject nextValue;
27
		int nodeVID;
28
		for (Iterator values = ((DataType) modelObject).getOwnedAttributes().iterator(); values.hasNext();) {
29
			nextValue = (EObject) values.next();
30
			nodeVID = UMLVisualIDRegistry.getNodeVisualID(viewObject, nextValue);
31
			if (Property4EditPart.VISUAL_ID == nodeVID) {
32
				result.add(nextValue);
33
			}
34
		}
35
		return result;
36
	}
37
38
	/**
39
	 * @generated
40
	 */
41
	protected boolean shouldDeleteView(View view) {
42
		return view.isSetElement() && view.getElement() != null && view.getElement().eIsProxy();
43
	}
44
45
	/**
46
	 * @generated
47
	 */
48
	protected String getDefaultFactoryHint() {
49
		return null;
50
	}
51
52
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/policies/Class2ItemSemanticEditPolicy.java (+524 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.policies;
2
3
import org.eclipse.emf.ecore.EAnnotation;
4
import org.eclipse.emf.ecore.EClass;
5
import org.eclipse.emf.ecore.EObject;
6
import org.eclipse.gef.commands.Command;
7
import org.eclipse.gef.commands.UnexecutableCommand;
8
import org.eclipse.gmf.runtime.emf.type.core.commands.CreateElementCommand;
9
import org.eclipse.gmf.runtime.emf.type.core.commands.CreateRelationshipCommand;
10
import org.eclipse.gmf.runtime.emf.type.core.commands.DestroyElementCommand;
11
import org.eclipse.gmf.runtime.emf.type.core.commands.SetValueCommand;
12
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest;
13
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest;
14
import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest;
15
import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest;
16
import org.eclipse.gmf.runtime.notation.View;
17
import org.eclipse.uml2.diagram.clazz.providers.UMLElementTypes;
18
import org.eclipse.uml2.uml.Association;
19
import org.eclipse.uml2.uml.Classifier;
20
import org.eclipse.uml2.uml.Constraint;
21
import org.eclipse.uml2.uml.Dependency;
22
import org.eclipse.uml2.uml.Generalization;
23
import org.eclipse.uml2.uml.NamedElement;
24
import org.eclipse.uml2.uml.Port;
25
import org.eclipse.uml2.uml.Property;
26
import org.eclipse.uml2.uml.Type;
27
import org.eclipse.uml2.uml.UMLPackage;
28
import org.eclipse.uml2.uml.Usage;
29
30
/**
31
 * @generated
32
 */
33
public class Class2ItemSemanticEditPolicy extends UMLBaseItemSemanticEditPolicy {
34
35
	/**
36
	 * @generated
37
	 */
38
	protected Command getCreateCommand(CreateElementRequest req) {
39
		if (UMLElementTypes.Port_3025 == req.getElementType()) {
40
			if (req.getContainmentFeature() == null) {
41
				req.setContainmentFeature(UMLPackage.eINSTANCE.getStructuredClassifier_OwnedAttribute());
42
			}
43
			return getMSLWrapper(new CreatePort_3025Command(req));
44
		}
45
		return super.getCreateCommand(req);
46
	}
47
48
	/**
49
	 * @generated
50
	 */
51
	private static class CreatePort_3025Command extends CreateElementCommand {
52
53
		/**
54
		 * @generated
55
		 */
56
		public CreatePort_3025Command(CreateElementRequest req) {
57
			super(req);
58
		}
59
60
		/**
61
		 * @generated
62
		 */
63
		protected EClass getEClassToEdit() {
64
			return UMLPackage.eINSTANCE.getClass_();
65
		};
66
67
		/**
68
		 * @generated
69
		 */
70
		protected EObject getElementToEdit() {
71
			EObject container = ((CreateElementRequest) getRequest()).getContainer();
72
			if (container instanceof View) {
73
				container = ((View) container).getElement();
74
			}
75
			return container;
76
		}
77
78
		/**
79
		 * @generated
80
		 */
81
		protected EObject doDefaultElementCreation() {
82
			Port newElement = (Port) super.doDefaultElementCreation();
83
			if (newElement != null) {
84
				UMLElementTypes.Initializers.Port_3025.init(newElement);
85
			}
86
			return newElement;
87
		}
88
	}
89
90
	/**
91
	 * @generated
92
	 */
93
	protected Command getDestroyElementCommand(DestroyElementRequest req) {
94
		return getMSLWrapper(new DestroyElementCommand(req) {
95
96
			protected EObject getElementToDestroy() {
97
				View view = (View) getHost().getModel();
98
				EAnnotation annotation = view.getEAnnotation("Shortcut"); //$NON-NLS-1$
99
				if (annotation != null) {
100
					return view;
101
				}
102
				return super.getElementToDestroy();
103
			}
104
105
		});
106
	}
107
108
	/**
109
	 * @generated
110
	 */
111
	protected Command getCreateRelationshipCommand(CreateRelationshipRequest req) {
112
		if (UMLElementTypes.Generalization_4001 == req.getElementType()) {
113
			return req.getTarget() == null ? getCreateStartOutgoingGeneralization4001Command(req) : getCreateCompleteIncomingGeneralization4001Command(req);
114
		}
115
		if (UMLElementTypes.Dependency_4002 == req.getElementType()) {
116
			return req.getTarget() == null ? getCreateStartOutgoingDependency4002Command(req) : getCreateCompleteIncomingDependency4002Command(req);
117
		}
118
		if (UMLElementTypes.Property_4003 == req.getElementType()) {
119
			return req.getTarget() == null ? null : getCreateCompleteIncomingProperty4003Command(req);
120
		}
121
		if (UMLElementTypes.ConstraintConstrainedElement_4004 == req.getElementType()) {
122
			return req.getTarget() == null ? null : getCreateCompleteIncomingConstraint_ConstrainedElement4004Command(req);
123
		}
124
		if (UMLElementTypes.Association_4005 == req.getElementType()) {
125
			return req.getTarget() == null ? getCreateStartOutgoingAssociation4005Command(req) : getCreateCompleteIncomingAssociation4005Command(req);
126
		}
127
		if (UMLElementTypes.DependencySupplier_4006 == req.getElementType()) {
128
			return req.getTarget() == null ? null : getCreateCompleteIncomingDependency_Supplier4006Command(req);
129
		}
130
		if (UMLElementTypes.DependencyClient_4007 == req.getElementType()) {
131
			return req.getTarget() == null ? null : getCreateCompleteIncomingDependency_Client4007Command(req);
132
		}
133
		if (UMLElementTypes.InterfaceRealization_4008 == req.getElementType()) {
134
			return req.getTarget() == null ? getCreateStartOutgoingInterfaceRealization4008Command(req) : null;
135
		}
136
		if (UMLElementTypes.Usage_4009 == req.getElementType()) {
137
			return req.getTarget() == null ? getCreateStartOutgoingUsage4009Command(req) : getCreateCompleteIncomingUsage4009Command(req);
138
		}
139
		return super.getCreateRelationshipCommand(req);
140
	}
141
142
	/**
143
	 * @generated
144
	 */
145
	protected Command getCreateStartOutgoingGeneralization4001Command(CreateRelationshipRequest req) {
146
		return new Command() {
147
		};
148
	}
149
150
	/**
151
	 * @generated
152
	 */
153
	protected Command getCreateCompleteIncomingGeneralization4001Command(CreateRelationshipRequest req) {
154
		if (!(req.getSource() instanceof Classifier)) {
155
			return UnexecutableCommand.INSTANCE;
156
		}
157
		final Classifier element = (Classifier) req.getSource();
158
		if (req.getContainmentFeature() == null) {
159
			req.setContainmentFeature(UMLPackage.eINSTANCE.getClassifier_Generalization());
160
		}
161
		return getMSLWrapper(new CreateIncomingGeneralization4001Command(req) {
162
163
			protected EObject getElementToEdit() {
164
				return element;
165
			}
166
		});
167
	}
168
169
	/**
170
	 * @generated
171
	 */
172
	private static class CreateIncomingGeneralization4001Command extends CreateRelationshipCommand {
173
174
		/**
175
		 * @generated
176
		 */
177
		public CreateIncomingGeneralization4001Command(CreateRelationshipRequest req) {
178
			super(req);
179
		}
180
181
		/**
182
		 * @generated
183
		 */
184
		protected EClass getEClassToEdit() {
185
			return UMLPackage.eINSTANCE.getClassifier();
186
		};
187
188
		/**
189
		 * @generated
190
		 */
191
		protected void setElementToEdit(EObject element) {
192
			throw new UnsupportedOperationException();
193
		}
194
195
		/**
196
		 * @generated
197
		 */
198
		protected EObject doDefaultElementCreation() {
199
			Generalization newElement = (Generalization) super.doDefaultElementCreation();
200
			if (newElement != null) {
201
				newElement.setGeneral((Classifier) getTarget());
202
			}
203
			return newElement;
204
		}
205
	}
206
207
	/**
208
	 * @generated
209
	 */
210
	protected Command getCreateStartOutgoingDependency4002Command(CreateRelationshipRequest req) {
211
		return new Command() {
212
		};
213
	}
214
215
	/**
216
	 * @generated
217
	 */
218
	protected Command getCreateCompleteIncomingDependency4002Command(CreateRelationshipRequest req) {
219
		if (!(req.getSource() instanceof NamedElement)) {
220
			return UnexecutableCommand.INSTANCE;
221
		}
222
		final org.eclipse.uml2.uml.Package element = (org.eclipse.uml2.uml.Package) getRelationshipContainer(req.getSource(), UMLPackage.eINSTANCE.getPackage(), req.getElementType());
223
		if (element == null) {
224
			return UnexecutableCommand.INSTANCE;
225
		}
226
		if (req.getContainmentFeature() == null) {
227
			req.setContainmentFeature(UMLPackage.eINSTANCE.getPackage_PackagedElement());
228
		}
229
		return getMSLWrapper(new CreateIncomingDependency4002Command(req) {
230
231
			protected EObject getElementToEdit() {
232
				return element;
233
			}
234
		});
235
	}
236
237
	/**
238
	 * @generated
239
	 */
240
	private static class CreateIncomingDependency4002Command extends CreateRelationshipCommand {
241
242
		/**
243
		 * @generated
244
		 */
245
		public CreateIncomingDependency4002Command(CreateRelationshipRequest req) {
246
			super(req);
247
		}
248
249
		/**
250
		 * @generated
251
		 */
252
		protected EClass getEClassToEdit() {
253
			return UMLPackage.eINSTANCE.getPackage();
254
		};
255
256
		/**
257
		 * @generated
258
		 */
259
		protected void setElementToEdit(EObject element) {
260
			throw new UnsupportedOperationException();
261
		}
262
263
		/**
264
		 * @generated
265
		 */
266
		protected EObject doDefaultElementCreation() {
267
			Dependency newElement = (Dependency) super.doDefaultElementCreation();
268
			if (newElement != null) {
269
				newElement.getSuppliers().add((NamedElement) getTarget());
270
				newElement.getClients().add((NamedElement) getSource());
271
			}
272
			return newElement;
273
		}
274
	}
275
276
	/**
277
	 * @generated
278
	 */
279
	protected Command getCreateCompleteIncomingProperty4003Command(CreateRelationshipRequest req) {
280
		if (!(req.getSource() instanceof Association)) {
281
			return UnexecutableCommand.INSTANCE;
282
		}
283
		final Association element = (Association) req.getSource();
284
		if (req.getContainmentFeature() == null) {
285
			req.setContainmentFeature(UMLPackage.eINSTANCE.getAssociation_OwnedEnd());
286
		}
287
		return getMSLWrapper(new CreateIncomingProperty4003Command(req) {
288
289
			protected EObject getElementToEdit() {
290
				return element;
291
			}
292
		});
293
	}
294
295
	/**
296
	 * @generated
297
	 */
298
	private static class CreateIncomingProperty4003Command extends CreateRelationshipCommand {
299
300
		/**
301
		 * @generated
302
		 */
303
		public CreateIncomingProperty4003Command(CreateRelationshipRequest req) {
304
			super(req);
305
		}
306
307
		/**
308
		 * @generated
309
		 */
310
		protected EClass getEClassToEdit() {
311
			return UMLPackage.eINSTANCE.getAssociation();
312
		};
313
314
		/**
315
		 * @generated
316
		 */
317
		protected void setElementToEdit(EObject element) {
318
			throw new UnsupportedOperationException();
319
		}
320
321
		/**
322
		 * @generated
323
		 */
324
		protected EObject doDefaultElementCreation() {
325
			Property newElement = (Property) super.doDefaultElementCreation();
326
			if (newElement != null) {
327
				newElement.setType((Type) getTarget());
328
			}
329
			return newElement;
330
		}
331
	}
332
333
	/**
334
	 * @generated
335
	 */
336
	protected Command getCreateCompleteIncomingConstraint_ConstrainedElement4004Command(CreateRelationshipRequest req) {
337
		if (!(req.getSource() instanceof Constraint)) {
338
			return UnexecutableCommand.INSTANCE;
339
		}
340
		Constraint element = (Constraint) req.getSource();
341
		if (element.getConstrainedElements().contains(req.getTarget())) {
342
			return UnexecutableCommand.INSTANCE;
343
		}
344
		SetRequest setReq = new SetRequest(req.getSource(), UMLPackage.eINSTANCE.getConstraint_ConstrainedElement(), req.getTarget());
345
		return getMSLWrapper(new SetValueCommand(setReq));
346
	}
347
348
	/**
349
	 * @generated
350
	 */
351
	protected Command getCreateStartOutgoingAssociation4005Command(CreateRelationshipRequest req) {
352
		return new Command() {
353
		};
354
	}
355
356
	/**
357
	 * @generated
358
	 */
359
	protected Command getCreateCompleteIncomingAssociation4005Command(CreateRelationshipRequest req) {
360
		if (!(req.getSource() instanceof Type)) {
361
			return UnexecutableCommand.INSTANCE;
362
		}
363
		final org.eclipse.uml2.uml.Package element = (org.eclipse.uml2.uml.Package) getRelationshipContainer(req.getSource(), UMLPackage.eINSTANCE.getPackage(), req.getElementType());
364
		if (element == null) {
365
			return UnexecutableCommand.INSTANCE;
366
		}
367
		if (req.getContainmentFeature() == null) {
368
			req.setContainmentFeature(UMLPackage.eINSTANCE.getPackage_PackagedElement());
369
		}
370
		return getMSLWrapper(new CreateIncomingAssociation4005Command(req) {
371
372
			protected EObject getElementToEdit() {
373
				return element;
374
			}
375
		});
376
	}
377
378
	/**
379
	 * @generated NOT
380
	 */
381
	private static class CreateIncomingAssociation4005Command extends CreateAssociationCommand {
382
383
		/**
384
		 * @generated
385
		 */
386
		public CreateIncomingAssociation4005Command(CreateRelationshipRequest req) {
387
			super(req);
388
		}
389
390
		/**
391
		 * @generated
392
		 */
393
		protected EClass getEClassToEdit() {
394
			return UMLPackage.eINSTANCE.getPackage();
395
		};
396
397
		/**
398
		 * @generated
399
		 */
400
		protected void setElementToEdit(EObject element) {
401
			throw new UnsupportedOperationException();
402
		}
403
404
		/**
405
		 * @generated NOT
406
		 */
407
		protected EObject doDefaultElementCreation() {
408
			return super.doDefaultElementCreation();
409
		}
410
	}
411
412
	/**
413
	 * @generated
414
	 */
415
	protected Command getCreateCompleteIncomingDependency_Supplier4006Command(CreateRelationshipRequest req) {
416
		if (!(req.getSource() instanceof Dependency)) {
417
			return UnexecutableCommand.INSTANCE;
418
		}
419
		Dependency element = (Dependency) req.getSource();
420
		if (element.getSuppliers().contains(req.getTarget())) {
421
			return UnexecutableCommand.INSTANCE;
422
		}
423
		SetRequest setReq = new SetRequest(req.getSource(), UMLPackage.eINSTANCE.getDependency_Supplier(), req.getTarget());
424
		return getMSLWrapper(new SetValueCommand(setReq));
425
	}
426
427
	/**
428
	 * @generated
429
	 */
430
	protected Command getCreateCompleteIncomingDependency_Client4007Command(CreateRelationshipRequest req) {
431
		if (!(req.getSource() instanceof Dependency)) {
432
			return UnexecutableCommand.INSTANCE;
433
		}
434
		Dependency element = (Dependency) req.getSource();
435
		if (element.getClients().contains(req.getTarget())) {
436
			return UnexecutableCommand.INSTANCE;
437
		}
438
		SetRequest setReq = new SetRequest(req.getSource(), UMLPackage.eINSTANCE.getDependency_Client(), req.getTarget());
439
		return getMSLWrapper(new SetValueCommand(setReq));
440
	}
441
442
	/**
443
	 * @generated
444
	 */
445
	protected Command getCreateStartOutgoingInterfaceRealization4008Command(CreateRelationshipRequest req) {
446
		return new Command() {
447
		};
448
	}
449
450
	/**
451
	 * @generated
452
	 */
453
	protected Command getCreateStartOutgoingUsage4009Command(CreateRelationshipRequest req) {
454
		if (!UMLBaseItemSemanticEditPolicy.LinkConstraints.Usage_4009.canCreateLink(req, false)) {
455
			return UnexecutableCommand.INSTANCE;
456
		}
457
		return new Command() {
458
		};
459
	}
460
461
	/**
462
	 * @generated
463
	 */
464
	protected Command getCreateCompleteIncomingUsage4009Command(CreateRelationshipRequest req) {
465
		if (!(req.getSource() instanceof NamedElement)) {
466
			return UnexecutableCommand.INSTANCE;
467
		}
468
		final org.eclipse.uml2.uml.Package element = (org.eclipse.uml2.uml.Package) getRelationshipContainer(req.getSource(), UMLPackage.eINSTANCE.getPackage(), req.getElementType());
469
		if (element == null) {
470
			return UnexecutableCommand.INSTANCE;
471
		}
472
		if (!UMLBaseItemSemanticEditPolicy.LinkConstraints.Usage_4009.canCreateLink(req, false)) {
473
			return UnexecutableCommand.INSTANCE;
474
		}
475
		if (req.getContainmentFeature() == null) {
476
			req.setContainmentFeature(UMLPackage.eINSTANCE.getPackage_PackagedElement());
477
		}
478
		return getMSLWrapper(new CreateIncomingUsage4009Command(req) {
479
480
			protected EObject getElementToEdit() {
481
				return element;
482
			}
483
		});
484
	}
485
486
	/**
487
	 * @generated
488
	 */
489
	private static class CreateIncomingUsage4009Command extends CreateRelationshipCommand {
490
491
		/**
492
		 * @generated
493
		 */
494
		public CreateIncomingUsage4009Command(CreateRelationshipRequest req) {
495
			super(req);
496
		}
497
498
		/**
499
		 * @generated
500
		 */
501
		protected EClass getEClassToEdit() {
502
			return UMLPackage.eINSTANCE.getPackage();
503
		};
504
505
		/**
506
		 * @generated
507
		 */
508
		protected void setElementToEdit(EObject element) {
509
			throw new UnsupportedOperationException();
510
		}
511
512
		/**
513
		 * @generated
514
		 */
515
		protected EObject doDefaultElementCreation() {
516
			Usage newElement = (Usage) super.doDefaultElementCreation();
517
			if (newElement != null) {
518
				newElement.getSuppliers().add((NamedElement) getTarget());
519
				newElement.getClients().add((NamedElement) getSource());
520
			}
521
			return newElement;
522
		}
523
	}
524
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/policies/EnumerationOperationsItemSemanticEditPolicy.java (+73 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.policies;
2
3
import org.eclipse.emf.ecore.EClass;
4
import org.eclipse.emf.ecore.EObject;
5
import org.eclipse.gef.commands.Command;
6
import org.eclipse.gmf.runtime.emf.type.core.commands.CreateElementCommand;
7
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest;
8
import org.eclipse.gmf.runtime.notation.View;
9
import org.eclipse.uml2.diagram.clazz.providers.UMLElementTypes;
10
import org.eclipse.uml2.uml.Operation;
11
import org.eclipse.uml2.uml.UMLPackage;
12
13
/**
14
 * @generated
15
 */
16
public class EnumerationOperationsItemSemanticEditPolicy extends UMLBaseItemSemanticEditPolicy {
17
18
	/**
19
	 * @generated
20
	 */
21
	protected Command getCreateCommand(CreateElementRequest req) {
22
		if (UMLElementTypes.Operation_3024 == req.getElementType()) {
23
			if (req.getContainmentFeature() == null) {
24
				req.setContainmentFeature(UMLPackage.eINSTANCE.getDataType_OwnedOperation());
25
			}
26
			return getMSLWrapper(new CreateOperation_3024Command(req));
27
		}
28
		return super.getCreateCommand(req);
29
	}
30
31
	/**
32
	 * @generated
33
	 */
34
	private static class CreateOperation_3024Command extends CreateElementCommand {
35
36
		/**
37
		 * @generated
38
		 */
39
		public CreateOperation_3024Command(CreateElementRequest req) {
40
			super(req);
41
		}
42
43
		/**
44
		 * @generated
45
		 */
46
		protected EClass getEClassToEdit() {
47
			return UMLPackage.eINSTANCE.getEnumeration();
48
		};
49
50
		/**
51
		 * @generated
52
		 */
53
		protected EObject getElementToEdit() {
54
			EObject container = ((CreateElementRequest) getRequest()).getContainer();
55
			if (container instanceof View) {
56
				container = ((View) container).getElement();
57
			}
58
			return container;
59
		}
60
61
		/**
62
		 * @generated
63
		 */
64
		protected EObject doDefaultElementCreation() {
65
			Operation newElement = (Operation) super.doDefaultElementCreation();
66
			if (newElement != null) {
67
				UMLElementTypes.Initializers.Operation_3024.init(newElement);
68
			}
69
			return newElement;
70
		}
71
	}
72
73
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/parts/InstanceSpecificationSlotsEditPart.java (+64 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.parts;
2
3
import org.eclipse.emf.common.notify.Notification;
4
import org.eclipse.gmf.runtime.diagram.ui.editparts.ListCompartmentEditPart;
5
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.CreationEditPolicy;
6
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.DragDropEditPolicy;
7
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
8
import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout;
9
import org.eclipse.gmf.runtime.notation.View;
10
import org.eclipse.uml2.diagram.clazz.edit.policies.InstanceSpecificationSlotsCanonicalEditPolicy;
11
import org.eclipse.uml2.diagram.clazz.edit.policies.InstanceSpecificationSlotsItemSemanticEditPolicy;
12
13
/**
14
 * @generated
15
 */
16
public class InstanceSpecificationSlotsEditPart extends ListCompartmentEditPart {
17
18
	/**
19
	 * @generated
20
	 */
21
	public static final int VISUAL_ID = 7028;
22
23
	/**
24
	 * @generated
25
	 */
26
	public InstanceSpecificationSlotsEditPart(View view) {
27
		super(view);
28
	}
29
30
	/**
31
	 * @generated
32
	 */
33
	protected boolean hasModelChildrenChanged(Notification evt) {
34
		return false;
35
	}
36
37
	/**
38
	 * @generated
39
	 */
40
	public String getCompartmentName() {
41
		return "Slots";
42
	}
43
44
	/**
45
	 * @generated
46
	 */
47
	protected void createDefaultEditPolicies() {
48
		super.createDefaultEditPolicies();
49
		installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new InstanceSpecificationSlotsItemSemanticEditPolicy());
50
		installEditPolicy(EditPolicyRoles.CREATION_ROLE, new CreationEditPolicy());
51
		installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, new DragDropEditPolicy());
52
		installEditPolicy(EditPolicyRoles.CANONICAL_ROLE, new InstanceSpecificationSlotsCanonicalEditPolicy());
53
54
	}
55
56
	/**
57
	 * @generated
58
	 */
59
	protected void setRatio(Double ratio) {
60
		if (getFigure().getParent().getLayoutManager() instanceof ConstrainedToolbarLayout) {
61
			super.setRatio(ratio);
62
		}
63
	}
64
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/policies/ClassClassesCanonicalEditPolicy.java (+51 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.policies;
2
3
import java.util.Iterator;
4
import java.util.LinkedList;
5
import java.util.List;
6
7
import org.eclipse.emf.ecore.EObject;
8
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.CanonicalEditPolicy;
9
import org.eclipse.gmf.runtime.notation.View;
10
import org.eclipse.uml2.diagram.clazz.edit.parts.Class3EditPart;
11
import org.eclipse.uml2.diagram.clazz.part.UMLVisualIDRegistry;
12
13
/**
14
 * @generated
15
 */
16
public class ClassClassesCanonicalEditPolicy extends CanonicalEditPolicy {
17
18
	/**
19
	 * @generated
20
	 */
21
	protected List getSemanticChildrenList() {
22
		List result = new LinkedList();
23
		EObject modelObject = ((View) getHost().getModel()).getElement();
24
		View viewObject = (View) getHost().getModel();
25
		EObject nextValue;
26
		int nodeVID;
27
		for (Iterator values = ((org.eclipse.uml2.uml.Class) modelObject).getNestedClassifiers().iterator(); values.hasNext();) {
28
			nextValue = (EObject) values.next();
29
			nodeVID = UMLVisualIDRegistry.getNodeVisualID(viewObject, nextValue);
30
			if (Class3EditPart.VISUAL_ID == nodeVID) {
31
				result.add(nextValue);
32
			}
33
		}
34
		return result;
35
	}
36
37
	/**
38
	 * @generated
39
	 */
40
	protected boolean shouldDeleteView(View view) {
41
		return view.isSetElement() && view.getElement() != null && view.getElement().eIsProxy();
42
	}
43
44
	/**
45
	 * @generated
46
	 */
47
	protected String getDefaultFactoryHint() {
48
		return null;
49
	}
50
51
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/parts/PortNameEditPart.java (+524 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.parts;
2
3
import java.util.Collections;
4
import java.util.List;
5
6
import org.eclipse.draw2d.IFigure;
7
import org.eclipse.draw2d.Label;
8
import org.eclipse.draw2d.geometry.Point;
9
import org.eclipse.emf.common.notify.Notification;
10
import org.eclipse.emf.ecore.EObject;
11
import org.eclipse.emf.transaction.RunnableWithResult;
12
import org.eclipse.gef.AccessibleEditPart;
13
import org.eclipse.gef.EditPolicy;
14
import org.eclipse.gef.Request;
15
import org.eclipse.gef.requests.DirectEditRequest;
16
import org.eclipse.gef.tools.DirectEditManager;
17
import org.eclipse.gmf.runtime.common.ui.services.parser.IParser;
18
import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus;
19
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserEditStatus;
20
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions;
21
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserService;
22
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
23
import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart;
24
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy;
25
import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry;
26
import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants;
27
import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager;
28
import org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel;
29
import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
30
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
31
import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser;
32
import org.eclipse.gmf.runtime.emf.ui.services.parser.ParserHintAdapter;
33
import org.eclipse.gmf.runtime.notation.FontStyle;
34
import org.eclipse.gmf.runtime.notation.NotationPackage;
35
import org.eclipse.gmf.runtime.notation.View;
36
import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
37
import org.eclipse.jface.viewers.ICellEditorValidator;
38
import org.eclipse.swt.SWT;
39
import org.eclipse.swt.accessibility.AccessibleEvent;
40
import org.eclipse.swt.graphics.Color;
41
import org.eclipse.swt.graphics.FontData;
42
import org.eclipse.swt.graphics.Image;
43
import org.eclipse.uml2.diagram.clazz.edit.policies.UMLTextSelectionEditPolicy;
44
import org.eclipse.uml2.diagram.clazz.part.UMLVisualIDRegistry;
45
import org.eclipse.uml2.diagram.clazz.providers.UMLElementTypes;
46
47
/**
48
 * @generated
49
 */
50
public class PortNameEditPart extends UMLExtNodeLabelEditPart implements ITextAwareEditPart {
51
52
	/**
53
	 * @generated
54
	 */
55
	public static final int VISUAL_ID = 5013;
56
57
	/**
58
	 * @generated
59
	 */
60
	private DirectEditManager manager;
61
62
	/**
63
	 * @generated
64
	 */
65
	private IParser parser;
66
67
	/**
68
	 * @generated
69
	 */
70
	private List parserElements;
71
72
	/**
73
	 * @generated
74
	 */
75
	private String defaultText;
76
77
	/**
78
	 * @generated
79
	 */
80
	static {
81
		registerSnapBackPosition(UMLVisualIDRegistry.getType(PortNameEditPart.VISUAL_ID), new Point(0, 0));
82
	}
83
84
	/**
85
	 * @generated
86
	 */
87
	public PortNameEditPart(View view) {
88
		super(view);
89
	}
90
91
	/**
92
	 * @generated
93
	 */
94
	protected void createDefaultEditPolicies() {
95
		super.createDefaultEditPolicies();
96
		installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy());
97
98
	}
99
100
	/**
101
	 * @generated
102
	 */
103
	protected String getLabelTextHelper(IFigure figure) {
104
		if (figure instanceof WrapLabel) {
105
			return ((WrapLabel) figure).getText();
106
		} else {
107
			return ((Label) figure).getText();
108
		}
109
	}
110
111
	/**
112
	 * @generated
113
	 */
114
	protected void setLabelTextHelper(IFigure figure, String text) {
115
		if (figure instanceof WrapLabel) {
116
			((WrapLabel) figure).setText(text);
117
		} else {
118
			((Label) figure).setText(text);
119
		}
120
	}
121
122
	/**
123
	 * @generated
124
	 */
125
	protected Image getLabelIconHelper(IFigure figure) {
126
		if (figure instanceof WrapLabel) {
127
			return ((WrapLabel) figure).getIcon();
128
		} else {
129
			return ((Label) figure).getIcon();
130
		}
131
	}
132
133
	/**
134
	 * @generated
135
	 */
136
	protected void setLabelIconHelper(IFigure figure, Image icon) {
137
		if (figure instanceof WrapLabel) {
138
			((WrapLabel) figure).setIcon(icon);
139
		} else {
140
			((Label) figure).setIcon(icon);
141
		}
142
	}
143
144
	/**
145
	 * @generated
146
	 */
147
	public void setLabel(IFigure figure) {
148
		unregisterVisuals();
149
		setFigure(figure);
150
		defaultText = getLabelTextHelper(figure);
151
		registerVisuals();
152
		refreshVisuals();
153
	}
154
155
	/**
156
	 * @generated
157
	 */
158
	protected List getModelChildren() {
159
		return Collections.EMPTY_LIST;
160
	}
161
162
	/**
163
	 * @generated
164
	 */
165
	public IGraphicalEditPart getChildBySemanticHint(String semanticHint) {
166
		return null;
167
	}
168
169
	/**
170
	 * @generated
171
	 */
172
	protected EObject getParserElement() {
173
		EObject element = resolveSemanticElement();
174
		return element != null ? element : (View) getModel();
175
	}
176
177
	/**
178
	 * @generated
179
	 */
180
	protected Image getLabelIcon() {
181
		return null;
182
	}
183
184
	/**
185
	 * @generated
186
	 */
187
	protected String getLabelText() {
188
		String text = null;
189
		if (getParser() != null) {
190
			text = getParser().getPrintString(new EObjectAdapter(getParserElement()), getParserOptions().intValue());
191
		}
192
		if (text == null || text.length() == 0) {
193
			text = defaultText;
194
		}
195
		return text;
196
	}
197
198
	/**
199
	 * @generated
200
	 */
201
	public void setLabelText(String text) {
202
		setLabelTextHelper(getFigure(), text);
203
		Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
204
		if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) {
205
			((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback();
206
		}
207
	}
208
209
	/**
210
	 * @generated
211
	 */
212
	public String getEditText() {
213
		if (getParser() == null) {
214
			return ""; //$NON-NLS-1$
215
		}
216
		return getParser().getEditString(new EObjectAdapter(getParserElement()), getParserOptions().intValue());
217
	}
218
219
	/**
220
	 * @generated
221
	 */
222
	protected boolean isEditable() {
223
		return getEditText() != null;
224
	}
225
226
	/**
227
	 * @generated
228
	 */
229
	public ICellEditorValidator getEditTextValidator() {
230
		return new ICellEditorValidator() {
231
232
			public String isValid(final Object value) {
233
				if (value instanceof String) {
234
					final EObject element = getParserElement();
235
					final IParser parser = getParser();
236
					try {
237
						IParserEditStatus valid = (IParserEditStatus) getEditingDomain().runExclusive(new RunnableWithResult.Impl() {
238
239
							public void run() {
240
								setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value));
241
							}
242
						});
243
						return valid.getCode() == ParserEditStatus.EDITABLE ? null : valid.getMessage();
244
					} catch (InterruptedException ie) {
245
						ie.printStackTrace();
246
					}
247
				}
248
249
				// shouldn't get here
250
				return null;
251
			}
252
		};
253
	}
254
255
	/**
256
	 * @generated
257
	 */
258
	public IContentAssistProcessor getCompletionProcessor() {
259
		if (getParser() == null) {
260
			return null;
261
		}
262
		return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement()));
263
	}
264
265
	/**
266
	 * @generated
267
	 */
268
	public ParserOptions getParserOptions() {
269
		return ParserOptions.NONE;
270
	}
271
272
	/**
273
	 * @generated
274
	 */
275
	public IParser getParser() {
276
		if (parser == null) {
277
			String parserHint = ((View) getModel()).getType();
278
			ParserHintAdapter hintAdapter = new ParserHintAdapter(getParserElement(), parserHint) {
279
280
				public Object getAdapter(Class adapter) {
281
					if (IElementType.class.equals(adapter)) {
282
						return UMLElementTypes.Port_3025;
283
					}
284
					return super.getAdapter(adapter);
285
				}
286
			};
287
			parser = ParserService.getInstance().getParser(hintAdapter);
288
		}
289
		return parser;
290
	}
291
292
	/**
293
	 * @generated
294
	 */
295
	protected DirectEditManager getManager() {
296
		if (manager == null) {
297
			setManager(new TextDirectEditManager(this, TextDirectEditManager.getTextCellEditorClass(this), UMLEditPartFactory.getTextCellEditorLocator(this)));
298
		}
299
		return manager;
300
	}
301
302
	/**
303
	 * @generated
304
	 */
305
	protected void setManager(DirectEditManager manager) {
306
		this.manager = manager;
307
	}
308
309
	/**
310
	 * @generated
311
	 */
312
	protected void performDirectEdit() {
313
		getManager().show();
314
	}
315
316
	/**
317
	 * @generated
318
	 */
319
	protected void performDirectEdit(Point eventLocation) {
320
		if (getManager().getClass() == TextDirectEditManager.class) {
321
			((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint());
322
		}
323
	}
324
325
	/**
326
	 * @generated
327
	 */
328
	private void performDirectEdit(char initialCharacter) {
329
		if (getManager() instanceof TextDirectEditManager) {
330
			((TextDirectEditManager) getManager()).show(initialCharacter);
331
		} else {
332
			performDirectEdit();
333
		}
334
	}
335
336
	/**
337
	 * @generated
338
	 */
339
	protected void performDirectEditRequest(Request request) {
340
		final Request theRequest = request;
341
		try {
342
			getEditingDomain().runExclusive(new Runnable() {
343
344
				public void run() {
345
					if (isActive() && isEditable()) {
346
						if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) {
347
							Character initialChar = (Character) theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR);
348
							performDirectEdit(initialChar.charValue());
349
						} else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) {
350
							DirectEditRequest editRequest = (DirectEditRequest) theRequest;
351
							performDirectEdit(editRequest.getLocation());
352
						} else {
353
							performDirectEdit();
354
						}
355
					}
356
				}
357
			});
358
		} catch (InterruptedException e) {
359
			e.printStackTrace();
360
		}
361
	}
362
363
	/**
364
	 * @generated
365
	 */
366
	protected void refreshVisuals() {
367
		super.refreshVisuals();
368
		refreshLabel();
369
		refreshFont();
370
		refreshFontColor();
371
		refreshUnderline();
372
		refreshStrikeThrough();
373
	}
374
375
	/**
376
	 * @generated
377
	 */
378
	protected void refreshLabel() {
379
		setLabelTextHelper(getFigure(), getLabelText());
380
		setLabelIconHelper(getFigure(), getLabelIcon());
381
		Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
382
		if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) {
383
			((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback();
384
		}
385
	}
386
387
	/**
388
	 * @generated
389
	 */
390
	protected void refreshUnderline() {
391
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
392
		if (style != null && getFigure() instanceof WrapLabel) {
393
			((WrapLabel) getFigure()).setTextUnderline(style.isUnderline());
394
		}
395
	}
396
397
	/**
398
	 * @generated
399
	 */
400
	protected void refreshStrikeThrough() {
401
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
402
		if (style != null && getFigure() instanceof WrapLabel) {
403
			((WrapLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough());
404
		}
405
	}
406
407
	/**
408
	 * @generated
409
	 */
410
	protected void refreshFont() {
411
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
412
		if (style != null) {
413
			FontData fontData = new FontData(style.getFontName(), style.getFontHeight(), (style.isBold() ? SWT.BOLD : SWT.NORMAL) | (style.isItalic() ? SWT.ITALIC : SWT.NORMAL));
414
			setFont(fontData);
415
		}
416
	}
417
418
	/**
419
	 * @generated
420
	 */
421
	protected void setFontColor(Color color) {
422
		getFigure().setForegroundColor(color);
423
	}
424
425
	/**
426
	 * @generated
427
	 */
428
	protected void addSemanticListeners() {
429
		if (getParser() instanceof ISemanticParser) {
430
			EObject element = resolveSemanticElement();
431
			parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element);
432
			for (int i = 0; i < parserElements.size(); i++) {
433
				addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$
434
			}
435
		} else {
436
			super.addSemanticListeners();
437
		}
438
	}
439
440
	/**
441
	 * @generated
442
	 */
443
	protected void removeSemanticListeners() {
444
		if (parserElements != null) {
445
			for (int i = 0; i < parserElements.size(); i++) {
446
				removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$
447
			}
448
		} else {
449
			super.removeSemanticListeners();
450
		}
451
	}
452
453
	/**
454
	 * @generated
455
	 */
456
	protected AccessibleEditPart getAccessibleEditPart() {
457
		if (accessibleEP == null) {
458
			accessibleEP = new AccessibleGraphicalEditPart() {
459
460
				public void getName(AccessibleEvent e) {
461
					e.result = getLabelTextHelper(getFigure());
462
				}
463
			};
464
		}
465
		return accessibleEP;
466
	}
467
468
	/**
469
	 * @generated
470
	 */
471
	private View getFontStyleOwnerView() {
472
		return getPrimaryView();
473
	}
474
475
	/**
476
	 * @generated
477
	 */
478
	protected void handleNotificationEvent(Notification event) {
479
		Object feature = event.getFeature();
480
		if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) {
481
			Integer c = (Integer) event.getNewValue();
482
			setFontColor(DiagramColorRegistry.getInstance().getColor(c));
483
		} else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) {
484
			refreshUnderline();
485
		} else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) {
486
			refreshStrikeThrough();
487
		} else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature)
488
				|| NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) {
489
			refreshFont();
490
		} else {
491
			if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) {
492
				refreshLabel();
493
			}
494
			if (getParser() instanceof ISemanticParser) {
495
				ISemanticParser modelParser = (ISemanticParser) getParser();
496
				if (modelParser.areSemanticElementsAffected(null, event)) {
497
					removeSemanticListeners();
498
					if (resolveSemanticElement() != null) {
499
						addSemanticListeners();
500
					}
501
					refreshLabel();
502
				}
503
			}
504
		}
505
		super.handleNotificationEvent(event);
506
	}
507
508
	/**
509
	 * @generated
510
	 */
511
	protected IFigure createFigure() {
512
		IFigure label = createFigurePrim();
513
		defaultText = getLabelTextHelper(label);
514
		return label;
515
	}
516
517
	/**
518
	 * @generated
519
	 */
520
	protected IFigure createFigurePrim() {
521
		return new WrapLabel();
522
	}
523
524
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/parts/PackageClassifiersEditPart.java (+67 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.parts;
2
3
import org.eclipse.emf.common.notify.Notification;
4
import org.eclipse.gef.EditPolicy;
5
import org.eclipse.gmf.runtime.diagram.ui.editparts.ListCompartmentEditPart;
6
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.CreationEditPolicy;
7
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.DragDropEditPolicy;
8
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
9
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.ResizableCompartmentEditPolicy;
10
import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout;
11
import org.eclipse.gmf.runtime.notation.View;
12
import org.eclipse.uml2.diagram.clazz.edit.policies.PackageClassifiersCanonicalEditPolicy;
13
import org.eclipse.uml2.diagram.clazz.edit.policies.PackageClassifiersItemSemanticEditPolicy;
14
15
/**
16
 * @generated
17
 */
18
public class PackageClassifiersEditPart extends ListCompartmentEditPart {
19
20
	/**
21
	 * @generated
22
	 */
23
	public static final int VISUAL_ID = 7011;
24
25
	/**
26
	 * @generated
27
	 */
28
	public PackageClassifiersEditPart(View view) {
29
		super(view);
30
	}
31
32
	/**
33
	 * @generated
34
	 */
35
	protected boolean hasModelChildrenChanged(Notification evt) {
36
		return false;
37
	}
38
39
	/**
40
	 * @generated
41
	 */
42
	public String getCompartmentName() {
43
		return "classifiers";
44
	}
45
46
	/**
47
	 * @generated
48
	 */
49
	protected void createDefaultEditPolicies() {
50
		super.createDefaultEditPolicies();
51
		installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ResizableCompartmentEditPolicy());
52
		installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new PackageClassifiersItemSemanticEditPolicy());
53
		installEditPolicy(EditPolicyRoles.CREATION_ROLE, new CreationEditPolicy());
54
		installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, new DragDropEditPolicy());
55
		installEditPolicy(EditPolicyRoles.CANONICAL_ROLE, new PackageClassifiersCanonicalEditPolicy());
56
57
	}
58
59
	/**
60
	 * @generated
61
	 */
62
	protected void setRatio(Double ratio) {
63
		if (getFigure().getParent().getLayoutManager() instanceof ConstrainedToolbarLayout) {
64
			super.setRatio(ratio);
65
		}
66
	}
67
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/parts/DependencyClientEditPart.java (+66 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.parts;
2
3
import org.eclipse.draw2d.Connection;
4
import org.eclipse.gef.EditPolicy;
5
import org.eclipse.gmf.runtime.diagram.ui.editparts.ConnectionNodeEditPart;
6
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
7
import org.eclipse.gmf.runtime.notation.View;
8
import org.eclipse.uml2.diagram.clazz.edit.policies.DependencyClientItemSemanticEditPolicy;
9
import org.eclipse.uml2.diagram.clazz.edit.policies.UMLReferenceConnectionEditPolicy;
10
11
/**
12
 * @generated
13
 */
14
public class DependencyClientEditPart extends ConnectionNodeEditPart {
15
16
	/**
17
	 * @generated
18
	 */
19
	public static final int VISUAL_ID = 4007;
20
21
	/**
22
	 * @generated
23
	 */
24
	public DependencyClientEditPart(View view) {
25
		super(view);
26
	}
27
28
	/**
29
	 * @generated
30
	 */
31
	protected void createDefaultEditPolicies() {
32
		super.createDefaultEditPolicies();
33
		installEditPolicy(EditPolicy.CONNECTION_ROLE, new UMLReferenceConnectionEditPolicy());
34
		installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new DependencyClientItemSemanticEditPolicy());
35
36
	}
37
38
	/**
39
	 * Creates figure for this edit part.
40
	 * 
41
	 * Body of this method does not depend on settings in generation model
42
	 * so you may safely remove <i>generated</i> tag and modify it.
43
	 * 
44
	 * @generated
45
	 */
46
	protected Connection createConnectionFigure() {
47
		return new Dependency_NoArrow_Polyline();
48
	}
49
50
	/**
51
	 * @generated
52
	 */
53
	public class Dependency_NoArrow_Polyline extends org.eclipse.gmf.runtime.draw2d.ui.figures.PolylineConnectionEx {
54
55
		/**
56
		 * @generated
57
		 */
58
		public Dependency_NoArrow_Polyline() {
59
60
			this.setLineStyle(org.eclipse.draw2d.Graphics.LINE_DASH);
61
			this.setForegroundColor(org.eclipse.draw2d.ColorConstants.lightGray);
62
		}
63
64
	}
65
66
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/policies/InstanceSpecificationItemSemanticEditPolicy.java (+255 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.policies;
2
3
import org.eclipse.emf.ecore.EAnnotation;
4
import org.eclipse.emf.ecore.EClass;
5
import org.eclipse.emf.ecore.EObject;
6
import org.eclipse.gef.commands.Command;
7
import org.eclipse.gef.commands.UnexecutableCommand;
8
import org.eclipse.gmf.runtime.emf.type.core.commands.CreateRelationshipCommand;
9
import org.eclipse.gmf.runtime.emf.type.core.commands.DestroyElementCommand;
10
import org.eclipse.gmf.runtime.emf.type.core.commands.SetValueCommand;
11
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest;
12
import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest;
13
import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest;
14
import org.eclipse.gmf.runtime.notation.View;
15
import org.eclipse.uml2.diagram.clazz.providers.UMLElementTypes;
16
import org.eclipse.uml2.uml.Constraint;
17
import org.eclipse.uml2.uml.Dependency;
18
import org.eclipse.uml2.uml.NamedElement;
19
import org.eclipse.uml2.uml.UMLPackage;
20
import org.eclipse.uml2.uml.Usage;
21
22
/**
23
 * @generated
24
 */
25
public class InstanceSpecificationItemSemanticEditPolicy extends UMLBaseItemSemanticEditPolicy {
26
27
	/**
28
	 * @generated
29
	 */
30
	protected Command getDestroyElementCommand(DestroyElementRequest req) {
31
		return getMSLWrapper(new DestroyElementCommand(req) {
32
33
			protected EObject getElementToDestroy() {
34
				View view = (View) getHost().getModel();
35
				EAnnotation annotation = view.getEAnnotation("Shortcut"); //$NON-NLS-1$
36
				if (annotation != null) {
37
					return view;
38
				}
39
				return super.getElementToDestroy();
40
			}
41
42
		});
43
	}
44
45
	/**
46
	 * @generated
47
	 */
48
	protected Command getCreateRelationshipCommand(CreateRelationshipRequest req) {
49
		if (UMLElementTypes.Dependency_4002 == req.getElementType()) {
50
			return req.getTarget() == null ? getCreateStartOutgoingDependency4002Command(req) : getCreateCompleteIncomingDependency4002Command(req);
51
		}
52
		if (UMLElementTypes.ConstraintConstrainedElement_4004 == req.getElementType()) {
53
			return req.getTarget() == null ? null : getCreateCompleteIncomingConstraint_ConstrainedElement4004Command(req);
54
		}
55
		if (UMLElementTypes.DependencySupplier_4006 == req.getElementType()) {
56
			return req.getTarget() == null ? null : getCreateCompleteIncomingDependency_Supplier4006Command(req);
57
		}
58
		if (UMLElementTypes.DependencyClient_4007 == req.getElementType()) {
59
			return req.getTarget() == null ? null : getCreateCompleteIncomingDependency_Client4007Command(req);
60
		}
61
		if (UMLElementTypes.Usage_4009 == req.getElementType()) {
62
			return req.getTarget() == null ? getCreateStartOutgoingUsage4009Command(req) : getCreateCompleteIncomingUsage4009Command(req);
63
		}
64
		return super.getCreateRelationshipCommand(req);
65
	}
66
67
	/**
68
	 * @generated
69
	 */
70
	protected Command getCreateStartOutgoingDependency4002Command(CreateRelationshipRequest req) {
71
		return new Command() {
72
		};
73
	}
74
75
	/**
76
	 * @generated
77
	 */
78
	protected Command getCreateCompleteIncomingDependency4002Command(CreateRelationshipRequest req) {
79
		if (!(req.getSource() instanceof NamedElement)) {
80
			return UnexecutableCommand.INSTANCE;
81
		}
82
		final org.eclipse.uml2.uml.Package element = (org.eclipse.uml2.uml.Package) getRelationshipContainer(req.getSource(), UMLPackage.eINSTANCE.getPackage(), req.getElementType());
83
		if (element == null) {
84
			return UnexecutableCommand.INSTANCE;
85
		}
86
		if (req.getContainmentFeature() == null) {
87
			req.setContainmentFeature(UMLPackage.eINSTANCE.getPackage_PackagedElement());
88
		}
89
		return getMSLWrapper(new CreateIncomingDependency4002Command(req) {
90
91
			protected EObject getElementToEdit() {
92
				return element;
93
			}
94
		});
95
	}
96
97
	/**
98
	 * @generated
99
	 */
100
	private static class CreateIncomingDependency4002Command extends CreateRelationshipCommand {
101
102
		/**
103
		 * @generated
104
		 */
105
		public CreateIncomingDependency4002Command(CreateRelationshipRequest req) {
106
			super(req);
107
		}
108
109
		/**
110
		 * @generated
111
		 */
112
		protected EClass getEClassToEdit() {
113
			return UMLPackage.eINSTANCE.getPackage();
114
		};
115
116
		/**
117
		 * @generated
118
		 */
119
		protected void setElementToEdit(EObject element) {
120
			throw new UnsupportedOperationException();
121
		}
122
123
		/**
124
		 * @generated
125
		 */
126
		protected EObject doDefaultElementCreation() {
127
			Dependency newElement = (Dependency) super.doDefaultElementCreation();
128
			if (newElement != null) {
129
				newElement.getSuppliers().add((NamedElement) getTarget());
130
				newElement.getClients().add((NamedElement) getSource());
131
			}
132
			return newElement;
133
		}
134
	}
135
136
	/**
137
	 * @generated
138
	 */
139
	protected Command getCreateCompleteIncomingConstraint_ConstrainedElement4004Command(CreateRelationshipRequest req) {
140
		if (!(req.getSource() instanceof Constraint)) {
141
			return UnexecutableCommand.INSTANCE;
142
		}
143
		Constraint element = (Constraint) req.getSource();
144
		if (element.getConstrainedElements().contains(req.getTarget())) {
145
			return UnexecutableCommand.INSTANCE;
146
		}
147
		SetRequest setReq = new SetRequest(req.getSource(), UMLPackage.eINSTANCE.getConstraint_ConstrainedElement(), req.getTarget());
148
		return getMSLWrapper(new SetValueCommand(setReq));
149
	}
150
151
	/**
152
	 * @generated
153
	 */
154
	protected Command getCreateCompleteIncomingDependency_Supplier4006Command(CreateRelationshipRequest req) {
155
		if (!(req.getSource() instanceof Dependency)) {
156
			return UnexecutableCommand.INSTANCE;
157
		}
158
		Dependency element = (Dependency) req.getSource();
159
		if (element.getSuppliers().contains(req.getTarget())) {
160
			return UnexecutableCommand.INSTANCE;
161
		}
162
		SetRequest setReq = new SetRequest(req.getSource(), UMLPackage.eINSTANCE.getDependency_Supplier(), req.getTarget());
163
		return getMSLWrapper(new SetValueCommand(setReq));
164
	}
165
166
	/**
167
	 * @generated
168
	 */
169
	protected Command getCreateCompleteIncomingDependency_Client4007Command(CreateRelationshipRequest req) {
170
		if (!(req.getSource() instanceof Dependency)) {
171
			return UnexecutableCommand.INSTANCE;
172
		}
173
		Dependency element = (Dependency) req.getSource();
174
		if (element.getClients().contains(req.getTarget())) {
175
			return UnexecutableCommand.INSTANCE;
176
		}
177
		SetRequest setReq = new SetRequest(req.getSource(), UMLPackage.eINSTANCE.getDependency_Client(), req.getTarget());
178
		return getMSLWrapper(new SetValueCommand(setReq));
179
	}
180
181
	/**
182
	 * @generated
183
	 */
184
	protected Command getCreateStartOutgoingUsage4009Command(CreateRelationshipRequest req) {
185
		if (!UMLBaseItemSemanticEditPolicy.LinkConstraints.Usage_4009.canCreateLink(req, false)) {
186
			return UnexecutableCommand.INSTANCE;
187
		}
188
		return new Command() {
189
		};
190
	}
191
192
	/**
193
	 * @generated
194
	 */
195
	protected Command getCreateCompleteIncomingUsage4009Command(CreateRelationshipRequest req) {
196
		if (!(req.getSource() instanceof NamedElement)) {
197
			return UnexecutableCommand.INSTANCE;
198
		}
199
		final org.eclipse.uml2.uml.Package element = (org.eclipse.uml2.uml.Package) getRelationshipContainer(req.getSource(), UMLPackage.eINSTANCE.getPackage(), req.getElementType());
200
		if (element == null) {
201
			return UnexecutableCommand.INSTANCE;
202
		}
203
		if (!UMLBaseItemSemanticEditPolicy.LinkConstraints.Usage_4009.canCreateLink(req, false)) {
204
			return UnexecutableCommand.INSTANCE;
205
		}
206
		if (req.getContainmentFeature() == null) {
207
			req.setContainmentFeature(UMLPackage.eINSTANCE.getPackage_PackagedElement());
208
		}
209
		return getMSLWrapper(new CreateIncomingUsage4009Command(req) {
210
211
			protected EObject getElementToEdit() {
212
				return element;
213
			}
214
		});
215
	}
216
217
	/**
218
	 * @generated
219
	 */
220
	private static class CreateIncomingUsage4009Command extends CreateRelationshipCommand {
221
222
		/**
223
		 * @generated
224
		 */
225
		public CreateIncomingUsage4009Command(CreateRelationshipRequest req) {
226
			super(req);
227
		}
228
229
		/**
230
		 * @generated
231
		 */
232
		protected EClass getEClassToEdit() {
233
			return UMLPackage.eINSTANCE.getPackage();
234
		};
235
236
		/**
237
		 * @generated
238
		 */
239
		protected void setElementToEdit(EObject element) {
240
			throw new UnsupportedOperationException();
241
		}
242
243
		/**
244
		 * @generated
245
		 */
246
		protected EObject doDefaultElementCreation() {
247
			Usage newElement = (Usage) super.doDefaultElementCreation();
248
			if (newElement != null) {
249
				newElement.getSuppliers().add((NamedElement) getTarget());
250
				newElement.getClients().add((NamedElement) getSource());
251
			}
252
			return newElement;
253
		}
254
	}
255
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/policies/AssociationClassClassesItemSemanticEditPolicy.java (+72 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.policies;
2
3
import org.eclipse.emf.ecore.EClass;
4
import org.eclipse.emf.ecore.EObject;
5
import org.eclipse.gef.commands.Command;
6
import org.eclipse.gmf.runtime.emf.type.core.commands.CreateElementCommand;
7
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest;
8
import org.eclipse.gmf.runtime.notation.View;
9
import org.eclipse.uml2.diagram.clazz.providers.UMLElementTypes;
10
import org.eclipse.uml2.uml.UMLPackage;
11
12
/**
13
 * @generated
14
 */
15
public class AssociationClassClassesItemSemanticEditPolicy extends UMLBaseItemSemanticEditPolicy {
16
17
	/**
18
	 * @generated
19
	 */
20
	protected Command getCreateCommand(CreateElementRequest req) {
21
		if (UMLElementTypes.Class_3003 == req.getElementType()) {
22
			if (req.getContainmentFeature() == null) {
23
				req.setContainmentFeature(UMLPackage.eINSTANCE.getClass_NestedClassifier());
24
			}
25
			return getMSLWrapper(new CreateClass_3003Command(req));
26
		}
27
		return super.getCreateCommand(req);
28
	}
29
30
	/**
31
	 * @generated
32
	 */
33
	private static class CreateClass_3003Command extends CreateElementCommand {
34
35
		/**
36
		 * @generated
37
		 */
38
		public CreateClass_3003Command(CreateElementRequest req) {
39
			super(req);
40
		}
41
42
		/**
43
		 * @generated
44
		 */
45
		protected EClass getEClassToEdit() {
46
			return UMLPackage.eINSTANCE.getAssociationClass();
47
		};
48
49
		/**
50
		 * @generated
51
		 */
52
		protected EObject getElementToEdit() {
53
			EObject container = ((CreateElementRequest) getRequest()).getContainer();
54
			if (container instanceof View) {
55
				container = ((View) container).getElement();
56
			}
57
			return container;
58
		}
59
60
		/**
61
		 * @generated
62
		 */
63
		protected EObject doDefaultElementCreation() {
64
			org.eclipse.uml2.uml.Class newElement = (org.eclipse.uml2.uml.Class) super.doDefaultElementCreation();
65
			if (newElement != null) {
66
				UMLElementTypes.Initializers.Class_3003.init(newElement);
67
			}
68
			return newElement;
69
		}
70
	}
71
72
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/parts/EnumerationLiteralsEditPart.java (+67 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.parts;
2
3
import org.eclipse.emf.common.notify.Notification;
4
import org.eclipse.gef.EditPolicy;
5
import org.eclipse.gmf.runtime.diagram.ui.editparts.ListCompartmentEditPart;
6
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.CreationEditPolicy;
7
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.DragDropEditPolicy;
8
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
9
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.ResizableCompartmentEditPolicy;
10
import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout;
11
import org.eclipse.gmf.runtime.notation.View;
12
import org.eclipse.uml2.diagram.clazz.edit.policies.EnumerationLiteralsCanonicalEditPolicy;
13
import org.eclipse.uml2.diagram.clazz.edit.policies.EnumerationLiteralsItemSemanticEditPolicy;
14
15
/**
16
 * @generated
17
 */
18
public class EnumerationLiteralsEditPart extends ListCompartmentEditPart {
19
20
	/**
21
	 * @generated
22
	 */
23
	public static final int VISUAL_ID = 7013;
24
25
	/**
26
	 * @generated
27
	 */
28
	public EnumerationLiteralsEditPart(View view) {
29
		super(view);
30
	}
31
32
	/**
33
	 * @generated
34
	 */
35
	protected boolean hasModelChildrenChanged(Notification evt) {
36
		return false;
37
	}
38
39
	/**
40
	 * @generated
41
	 */
42
	public String getCompartmentName() {
43
		return "literals";
44
	}
45
46
	/**
47
	 * @generated
48
	 */
49
	protected void createDefaultEditPolicies() {
50
		super.createDefaultEditPolicies();
51
		installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ResizableCompartmentEditPolicy());
52
		installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new EnumerationLiteralsItemSemanticEditPolicy());
53
		installEditPolicy(EditPolicyRoles.CREATION_ROLE, new CreationEditPolicy());
54
		installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, new DragDropEditPolicy());
55
		installEditPolicy(EditPolicyRoles.CANONICAL_ROLE, new EnumerationLiteralsCanonicalEditPolicy());
56
57
	}
58
59
	/**
60
	 * @generated
61
	 */
62
	protected void setRatio(Double ratio) {
63
		if (getFigure().getParent().getLayoutManager() instanceof ConstrainedToolbarLayout) {
64
			super.setRatio(ratio);
65
		}
66
	}
67
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/policies/DependencySupplierItemSemanticEditPolicy.java (+18 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.policies;
2
3
import org.eclipse.gef.commands.Command;
4
import org.eclipse.gmf.runtime.emf.type.core.commands.DestroyReferenceCommand;
5
import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyReferenceRequest;
6
7
/**
8
 * @generated
9
 */
10
public class DependencySupplierItemSemanticEditPolicy extends UMLBaseItemSemanticEditPolicy {
11
12
	/**
13
	 * @generated
14
	 */
15
	protected Command getDestroyReferenceCommand(DestroyReferenceRequest req) {
16
		return getMSLWrapper(new DestroyReferenceCommand(req));
17
	}
18
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/policies/DependencyItemSemanticEditPolicy.java (+273 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.policies;
2
3
import org.eclipse.emf.ecore.EAnnotation;
4
import org.eclipse.emf.ecore.EClass;
5
import org.eclipse.emf.ecore.EObject;
6
import org.eclipse.gef.commands.Command;
7
import org.eclipse.gef.commands.UnexecutableCommand;
8
import org.eclipse.gmf.runtime.emf.type.core.commands.CreateRelationshipCommand;
9
import org.eclipse.gmf.runtime.emf.type.core.commands.DestroyElementCommand;
10
import org.eclipse.gmf.runtime.emf.type.core.commands.SetValueCommand;
11
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest;
12
import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest;
13
import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest;
14
import org.eclipse.gmf.runtime.notation.View;
15
import org.eclipse.uml2.diagram.clazz.providers.UMLElementTypes;
16
import org.eclipse.uml2.uml.Constraint;
17
import org.eclipse.uml2.uml.Dependency;
18
import org.eclipse.uml2.uml.NamedElement;
19
import org.eclipse.uml2.uml.UMLPackage;
20
import org.eclipse.uml2.uml.Usage;
21
22
/**
23
 * @generated
24
 */
25
public class DependencyItemSemanticEditPolicy extends UMLBaseItemSemanticEditPolicy {
26
27
	/**
28
	 * @generated
29
	 */
30
	protected Command getDestroyElementCommand(DestroyElementRequest req) {
31
		return getMSLWrapper(new DestroyElementCommand(req) {
32
33
			protected EObject getElementToDestroy() {
34
				View view = (View) getHost().getModel();
35
				EAnnotation annotation = view.getEAnnotation("Shortcut"); //$NON-NLS-1$
36
				if (annotation != null) {
37
					return view;
38
				}
39
				return super.getElementToDestroy();
40
			}
41
42
		});
43
	}
44
45
	/**
46
	 * @generated
47
	 */
48
	protected Command getCreateRelationshipCommand(CreateRelationshipRequest req) {
49
		if (UMLElementTypes.Dependency_4002 == req.getElementType()) {
50
			return req.getTarget() == null ? getCreateStartOutgoingDependency4002Command(req) : getCreateCompleteIncomingDependency4002Command(req);
51
		}
52
		if (UMLElementTypes.ConstraintConstrainedElement_4004 == req.getElementType()) {
53
			return req.getTarget() == null ? null : getCreateCompleteIncomingConstraint_ConstrainedElement4004Command(req);
54
		}
55
		if (UMLElementTypes.DependencySupplier_4006 == req.getElementType()) {
56
			return req.getTarget() == null ? getCreateStartOutgoingDependency_Supplier4006Command(req) : getCreateCompleteIncomingDependency_Supplier4006Command(req);
57
		}
58
		if (UMLElementTypes.DependencyClient_4007 == req.getElementType()) {
59
			return req.getTarget() == null ? getCreateStartOutgoingDependency_Client4007Command(req) : getCreateCompleteIncomingDependency_Client4007Command(req);
60
		}
61
		if (UMLElementTypes.Usage_4009 == req.getElementType()) {
62
			return req.getTarget() == null ? getCreateStartOutgoingUsage4009Command(req) : getCreateCompleteIncomingUsage4009Command(req);
63
		}
64
		return super.getCreateRelationshipCommand(req);
65
	}
66
67
	/**
68
	 * @generated
69
	 */
70
	protected Command getCreateStartOutgoingDependency4002Command(CreateRelationshipRequest req) {
71
		return new Command() {
72
		};
73
	}
74
75
	/**
76
	 * @generated
77
	 */
78
	protected Command getCreateCompleteIncomingDependency4002Command(CreateRelationshipRequest req) {
79
		if (!(req.getSource() instanceof NamedElement)) {
80
			return UnexecutableCommand.INSTANCE;
81
		}
82
		final org.eclipse.uml2.uml.Package element = (org.eclipse.uml2.uml.Package) getRelationshipContainer(req.getSource(), UMLPackage.eINSTANCE.getPackage(), req.getElementType());
83
		if (element == null) {
84
			return UnexecutableCommand.INSTANCE;
85
		}
86
		if (req.getContainmentFeature() == null) {
87
			req.setContainmentFeature(UMLPackage.eINSTANCE.getPackage_PackagedElement());
88
		}
89
		return getMSLWrapper(new CreateIncomingDependency4002Command(req) {
90
91
			protected EObject getElementToEdit() {
92
				return element;
93
			}
94
		});
95
	}
96
97
	/**
98
	 * @generated
99
	 */
100
	private static class CreateIncomingDependency4002Command extends CreateRelationshipCommand {
101
102
		/**
103
		 * @generated
104
		 */
105
		public CreateIncomingDependency4002Command(CreateRelationshipRequest req) {
106
			super(req);
107
		}
108
109
		/**
110
		 * @generated
111
		 */
112
		protected EClass getEClassToEdit() {
113
			return UMLPackage.eINSTANCE.getPackage();
114
		};
115
116
		/**
117
		 * @generated
118
		 */
119
		protected void setElementToEdit(EObject element) {
120
			throw new UnsupportedOperationException();
121
		}
122
123
		/**
124
		 * @generated
125
		 */
126
		protected EObject doDefaultElementCreation() {
127
			Dependency newElement = (Dependency) super.doDefaultElementCreation();
128
			if (newElement != null) {
129
				newElement.getSuppliers().add((NamedElement) getTarget());
130
				newElement.getClients().add((NamedElement) getSource());
131
			}
132
			return newElement;
133
		}
134
	}
135
136
	/**
137
	 * @generated
138
	 */
139
	protected Command getCreateCompleteIncomingConstraint_ConstrainedElement4004Command(CreateRelationshipRequest req) {
140
		if (!(req.getSource() instanceof Constraint)) {
141
			return UnexecutableCommand.INSTANCE;
142
		}
143
		Constraint element = (Constraint) req.getSource();
144
		if (element.getConstrainedElements().contains(req.getTarget())) {
145
			return UnexecutableCommand.INSTANCE;
146
		}
147
		SetRequest setReq = new SetRequest(req.getSource(), UMLPackage.eINSTANCE.getConstraint_ConstrainedElement(), req.getTarget());
148
		return getMSLWrapper(new SetValueCommand(setReq));
149
	}
150
151
	/**
152
	 * @generated
153
	 */
154
	protected Command getCreateStartOutgoingDependency_Supplier4006Command(CreateRelationshipRequest req) {
155
156
		return new Command() {
157
		};
158
	}
159
160
	/**
161
	 * @generated
162
	 */
163
	protected Command getCreateCompleteIncomingDependency_Supplier4006Command(CreateRelationshipRequest req) {
164
		if (!(req.getSource() instanceof Dependency)) {
165
			return UnexecutableCommand.INSTANCE;
166
		}
167
		Dependency element = (Dependency) req.getSource();
168
		if (element.getSuppliers().contains(req.getTarget())) {
169
			return UnexecutableCommand.INSTANCE;
170
		}
171
		SetRequest setReq = new SetRequest(req.getSource(), UMLPackage.eINSTANCE.getDependency_Supplier(), req.getTarget());
172
		return getMSLWrapper(new SetValueCommand(setReq));
173
	}
174
175
	/**
176
	 * @generated
177
	 */
178
	protected Command getCreateStartOutgoingDependency_Client4007Command(CreateRelationshipRequest req) {
179
180
		return new Command() {
181
		};
182
	}
183
184
	/**
185
	 * @generated
186
	 */
187
	protected Command getCreateCompleteIncomingDependency_Client4007Command(CreateRelationshipRequest req) {
188
		if (!(req.getSource() instanceof Dependency)) {
189
			return UnexecutableCommand.INSTANCE;
190
		}
191
		Dependency element = (Dependency) req.getSource();
192
		if (element.getClients().contains(req.getTarget())) {
193
			return UnexecutableCommand.INSTANCE;
194
		}
195
		SetRequest setReq = new SetRequest(req.getSource(), UMLPackage.eINSTANCE.getDependency_Client(), req.getTarget());
196
		return getMSLWrapper(new SetValueCommand(setReq));
197
	}
198
199
	/**
200
	 * @generated
201
	 */
202
	protected Command getCreateStartOutgoingUsage4009Command(CreateRelationshipRequest req) {
203
		if (!UMLBaseItemSemanticEditPolicy.LinkConstraints.Usage_4009.canCreateLink(req, false)) {
204
			return UnexecutableCommand.INSTANCE;
205
		}
206
		return new Command() {
207
		};
208
	}
209
210
	/**
211
	 * @generated
212
	 */
213
	protected Command getCreateCompleteIncomingUsage4009Command(CreateRelationshipRequest req) {
214
		if (!(req.getSource() instanceof NamedElement)) {
215
			return UnexecutableCommand.INSTANCE;
216
		}
217
		final org.eclipse.uml2.uml.Package element = (org.eclipse.uml2.uml.Package) getRelationshipContainer(req.getSource(), UMLPackage.eINSTANCE.getPackage(), req.getElementType());
218
		if (element == null) {
219
			return UnexecutableCommand.INSTANCE;
220
		}
221
		if (!UMLBaseItemSemanticEditPolicy.LinkConstraints.Usage_4009.canCreateLink(req, false)) {
222
			return UnexecutableCommand.INSTANCE;
223
		}
224
		if (req.getContainmentFeature() == null) {
225
			req.setContainmentFeature(UMLPackage.eINSTANCE.getPackage_PackagedElement());
226
		}
227
		return getMSLWrapper(new CreateIncomingUsage4009Command(req) {
228
229
			protected EObject getElementToEdit() {
230
				return element;
231
			}
232
		});
233
	}
234
235
	/**
236
	 * @generated
237
	 */
238
	private static class CreateIncomingUsage4009Command extends CreateRelationshipCommand {
239
240
		/**
241
		 * @generated
242
		 */
243
		public CreateIncomingUsage4009Command(CreateRelationshipRequest req) {
244
			super(req);
245
		}
246
247
		/**
248
		 * @generated
249
		 */
250
		protected EClass getEClassToEdit() {
251
			return UMLPackage.eINSTANCE.getPackage();
252
		};
253
254
		/**
255
		 * @generated
256
		 */
257
		protected void setElementToEdit(EObject element) {
258
			throw new UnsupportedOperationException();
259
		}
260
261
		/**
262
		 * @generated
263
		 */
264
		protected EObject doDefaultElementCreation() {
265
			Usage newElement = (Usage) super.doDefaultElementCreation();
266
			if (newElement != null) {
267
				newElement.getSuppliers().add((NamedElement) getTarget());
268
				newElement.getClients().add((NamedElement) getSource());
269
			}
270
			return newElement;
271
		}
272
	}
273
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/policies/AssociationClass2ItemSemanticEditPolicy.java (+474 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.policies;
2
3
import org.eclipse.emf.ecore.EAnnotation;
4
import org.eclipse.emf.ecore.EClass;
5
import org.eclipse.emf.ecore.EObject;
6
import org.eclipse.gef.commands.Command;
7
import org.eclipse.gef.commands.UnexecutableCommand;
8
import org.eclipse.gmf.runtime.emf.type.core.commands.CreateRelationshipCommand;
9
import org.eclipse.gmf.runtime.emf.type.core.commands.DestroyElementCommand;
10
import org.eclipse.gmf.runtime.emf.type.core.commands.SetValueCommand;
11
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest;
12
import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest;
13
import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest;
14
import org.eclipse.gmf.runtime.notation.View;
15
import org.eclipse.uml2.diagram.clazz.providers.UMLElementTypes;
16
import org.eclipse.uml2.uml.Association;
17
import org.eclipse.uml2.uml.Classifier;
18
import org.eclipse.uml2.uml.Constraint;
19
import org.eclipse.uml2.uml.Dependency;
20
import org.eclipse.uml2.uml.Generalization;
21
import org.eclipse.uml2.uml.NamedElement;
22
import org.eclipse.uml2.uml.Property;
23
import org.eclipse.uml2.uml.Type;
24
import org.eclipse.uml2.uml.UMLPackage;
25
import org.eclipse.uml2.uml.Usage;
26
27
/**
28
 * @generated
29
 */
30
public class AssociationClass2ItemSemanticEditPolicy extends UMLBaseItemSemanticEditPolicy {
31
32
	/**
33
	 * @generated
34
	 */
35
	protected Command getDestroyElementCommand(DestroyElementRequest req) {
36
		return getMSLWrapper(new DestroyElementCommand(req) {
37
38
			protected EObject getElementToDestroy() {
39
				View view = (View) getHost().getModel();
40
				EAnnotation annotation = view.getEAnnotation("Shortcut"); //$NON-NLS-1$
41
				if (annotation != null) {
42
					return view;
43
				}
44
				return super.getElementToDestroy();
45
			}
46
47
		});
48
	}
49
50
	/**
51
	 * @generated
52
	 */
53
	protected Command getCreateRelationshipCommand(CreateRelationshipRequest req) {
54
		if (UMLElementTypes.Generalization_4001 == req.getElementType()) {
55
			return req.getTarget() == null ? getCreateStartOutgoingGeneralization4001Command(req) : getCreateCompleteIncomingGeneralization4001Command(req);
56
		}
57
		if (UMLElementTypes.Dependency_4002 == req.getElementType()) {
58
			return req.getTarget() == null ? getCreateStartOutgoingDependency4002Command(req) : getCreateCompleteIncomingDependency4002Command(req);
59
		}
60
		if (UMLElementTypes.Property_4003 == req.getElementType()) {
61
			return req.getTarget() == null ? getCreateStartOutgoingProperty4003Command(req) : getCreateCompleteIncomingProperty4003Command(req);
62
		}
63
		if (UMLElementTypes.ConstraintConstrainedElement_4004 == req.getElementType()) {
64
			return req.getTarget() == null ? null : getCreateCompleteIncomingConstraint_ConstrainedElement4004Command(req);
65
		}
66
		if (UMLElementTypes.Association_4005 == req.getElementType()) {
67
			return req.getTarget() == null ? getCreateStartOutgoingAssociation4005Command(req) : getCreateCompleteIncomingAssociation4005Command(req);
68
		}
69
		if (UMLElementTypes.DependencySupplier_4006 == req.getElementType()) {
70
			return req.getTarget() == null ? null : getCreateCompleteIncomingDependency_Supplier4006Command(req);
71
		}
72
		if (UMLElementTypes.DependencyClient_4007 == req.getElementType()) {
73
			return req.getTarget() == null ? null : getCreateCompleteIncomingDependency_Client4007Command(req);
74
		}
75
		if (UMLElementTypes.InterfaceRealization_4008 == req.getElementType()) {
76
			return req.getTarget() == null ? getCreateStartOutgoingInterfaceRealization4008Command(req) : null;
77
		}
78
		if (UMLElementTypes.Usage_4009 == req.getElementType()) {
79
			return req.getTarget() == null ? getCreateStartOutgoingUsage4009Command(req) : getCreateCompleteIncomingUsage4009Command(req);
80
		}
81
		return super.getCreateRelationshipCommand(req);
82
	}
83
84
	/**
85
	 * @generated
86
	 */
87
	protected Command getCreateStartOutgoingGeneralization4001Command(CreateRelationshipRequest req) {
88
		return new Command() {
89
		};
90
	}
91
92
	/**
93
	 * @generated
94
	 */
95
	protected Command getCreateCompleteIncomingGeneralization4001Command(CreateRelationshipRequest req) {
96
		if (!(req.getSource() instanceof Classifier)) {
97
			return UnexecutableCommand.INSTANCE;
98
		}
99
		final Classifier element = (Classifier) req.getSource();
100
		if (req.getContainmentFeature() == null) {
101
			req.setContainmentFeature(UMLPackage.eINSTANCE.getClassifier_Generalization());
102
		}
103
		return getMSLWrapper(new CreateIncomingGeneralization4001Command(req) {
104
105
			protected EObject getElementToEdit() {
106
				return element;
107
			}
108
		});
109
	}
110
111
	/**
112
	 * @generated
113
	 */
114
	private static class CreateIncomingGeneralization4001Command extends CreateRelationshipCommand {
115
116
		/**
117
		 * @generated
118
		 */
119
		public CreateIncomingGeneralization4001Command(CreateRelationshipRequest req) {
120
			super(req);
121
		}
122
123
		/**
124
		 * @generated
125
		 */
126
		protected EClass getEClassToEdit() {
127
			return UMLPackage.eINSTANCE.getClassifier();
128
		};
129
130
		/**
131
		 * @generated
132
		 */
133
		protected void setElementToEdit(EObject element) {
134
			throw new UnsupportedOperationException();
135
		}
136
137
		/**
138
		 * @generated
139
		 */
140
		protected EObject doDefaultElementCreation() {
141
			Generalization newElement = (Generalization) super.doDefaultElementCreation();
142
			if (newElement != null) {
143
				newElement.setGeneral((Classifier) getTarget());
144
			}
145
			return newElement;
146
		}
147
	}
148
149
	/**
150
	 * @generated
151
	 */
152
	protected Command getCreateStartOutgoingDependency4002Command(CreateRelationshipRequest req) {
153
		return new Command() {
154
		};
155
	}
156
157
	/**
158
	 * @generated
159
	 */
160
	protected Command getCreateCompleteIncomingDependency4002Command(CreateRelationshipRequest req) {
161
		if (!(req.getSource() instanceof NamedElement)) {
162
			return UnexecutableCommand.INSTANCE;
163
		}
164
		final org.eclipse.uml2.uml.Package element = (org.eclipse.uml2.uml.Package) getRelationshipContainer(req.getSource(), UMLPackage.eINSTANCE.getPackage(), req.getElementType());
165
		if (element == null) {
166
			return UnexecutableCommand.INSTANCE;
167
		}
168
		if (req.getContainmentFeature() == null) {
169
			req.setContainmentFeature(UMLPackage.eINSTANCE.getPackage_PackagedElement());
170
		}
171
		return getMSLWrapper(new CreateIncomingDependency4002Command(req) {
172
173
			protected EObject getElementToEdit() {
174
				return element;
175
			}
176
		});
177
	}
178
179
	/**
180
	 * @generated
181
	 */
182
	private static class CreateIncomingDependency4002Command extends CreateRelationshipCommand {
183
184
		/**
185
		 * @generated
186
		 */
187
		public CreateIncomingDependency4002Command(CreateRelationshipRequest req) {
188
			super(req);
189
		}
190
191
		/**
192
		 * @generated
193
		 */
194
		protected EClass getEClassToEdit() {
195
			return UMLPackage.eINSTANCE.getPackage();
196
		};
197
198
		/**
199
		 * @generated
200
		 */
201
		protected void setElementToEdit(EObject element) {
202
			throw new UnsupportedOperationException();
203
		}
204
205
		/**
206
		 * @generated
207
		 */
208
		protected EObject doDefaultElementCreation() {
209
			Dependency newElement = (Dependency) super.doDefaultElementCreation();
210
			if (newElement != null) {
211
				newElement.getSuppliers().add((NamedElement) getTarget());
212
				newElement.getClients().add((NamedElement) getSource());
213
			}
214
			return newElement;
215
		}
216
	}
217
218
	/**
219
	 * @generated
220
	 */
221
	protected Command getCreateStartOutgoingProperty4003Command(CreateRelationshipRequest req) {
222
		return new Command() {
223
		};
224
	}
225
226
	/**
227
	 * @generated
228
	 */
229
	protected Command getCreateCompleteIncomingProperty4003Command(CreateRelationshipRequest req) {
230
		if (!(req.getSource() instanceof Association)) {
231
			return UnexecutableCommand.INSTANCE;
232
		}
233
		final Association element = (Association) req.getSource();
234
		if (req.getContainmentFeature() == null) {
235
			req.setContainmentFeature(UMLPackage.eINSTANCE.getAssociation_OwnedEnd());
236
		}
237
		return getMSLWrapper(new CreateIncomingProperty4003Command(req) {
238
239
			protected EObject getElementToEdit() {
240
				return element;
241
			}
242
		});
243
	}
244
245
	/**
246
	 * @generated
247
	 */
248
	private static class CreateIncomingProperty4003Command extends CreateRelationshipCommand {
249
250
		/**
251
		 * @generated
252
		 */
253
		public CreateIncomingProperty4003Command(CreateRelationshipRequest req) {
254
			super(req);
255
		}
256
257
		/**
258
		 * @generated
259
		 */
260
		protected EClass getEClassToEdit() {
261
			return UMLPackage.eINSTANCE.getAssociation();
262
		};
263
264
		/**
265
		 * @generated
266
		 */
267
		protected void setElementToEdit(EObject element) {
268
			throw new UnsupportedOperationException();
269
		}
270
271
		/**
272
		 * @generated
273
		 */
274
		protected EObject doDefaultElementCreation() {
275
			Property newElement = (Property) super.doDefaultElementCreation();
276
			if (newElement != null) {
277
				newElement.setType((Type) getTarget());
278
			}
279
			return newElement;
280
		}
281
	}
282
283
	/**
284
	 * @generated
285
	 */
286
	protected Command getCreateCompleteIncomingConstraint_ConstrainedElement4004Command(CreateRelationshipRequest req) {
287
		if (!(req.getSource() instanceof Constraint)) {
288
			return UnexecutableCommand.INSTANCE;
289
		}
290
		Constraint element = (Constraint) req.getSource();
291
		if (element.getConstrainedElements().contains(req.getTarget())) {
292
			return UnexecutableCommand.INSTANCE;
293
		}
294
		SetRequest setReq = new SetRequest(req.getSource(), UMLPackage.eINSTANCE.getConstraint_ConstrainedElement(), req.getTarget());
295
		return getMSLWrapper(new SetValueCommand(setReq));
296
	}
297
298
	/**
299
	 * @generated
300
	 */
301
	protected Command getCreateStartOutgoingAssociation4005Command(CreateRelationshipRequest req) {
302
		return new Command() {
303
		};
304
	}
305
306
	/**
307
	 * @generated
308
	 */
309
	protected Command getCreateCompleteIncomingAssociation4005Command(CreateRelationshipRequest req) {
310
		if (!(req.getSource() instanceof Type)) {
311
			return UnexecutableCommand.INSTANCE;
312
		}
313
		final org.eclipse.uml2.uml.Package element = (org.eclipse.uml2.uml.Package) getRelationshipContainer(req.getSource(), UMLPackage.eINSTANCE.getPackage(), req.getElementType());
314
		if (element == null) {
315
			return UnexecutableCommand.INSTANCE;
316
		}
317
		if (req.getContainmentFeature() == null) {
318
			req.setContainmentFeature(UMLPackage.eINSTANCE.getPackage_PackagedElement());
319
		}
320
		return getMSLWrapper(new CreateIncomingAssociation4005Command(req) {
321
322
			protected EObject getElementToEdit() {
323
				return element;
324
			}
325
		});
326
	}
327
328
	/**
329
	 * @generated NOT
330
	 */
331
	private static class CreateIncomingAssociation4005Command extends CreateAssociationCommand {
332
333
		/**
334
		 * @generated
335
		 */
336
		public CreateIncomingAssociation4005Command(CreateRelationshipRequest req) {
337
			super(req);
338
		}
339
340
		/**
341
		 * @generated
342
		 */
343
		protected EClass getEClassToEdit() {
344
			return UMLPackage.eINSTANCE.getPackage();
345
		};
346
347
		/**
348
		 * @generated
349
		 */
350
		protected void setElementToEdit(EObject element) {
351
			throw new UnsupportedOperationException();
352
		}
353
354
		/**
355
		 * @generated NOT
356
		 */
357
		protected EObject doDefaultElementCreation() {
358
			return super.doDefaultElementCreation();
359
		}
360
	}
361
362
	/**
363
	 * @generated
364
	 */
365
	protected Command getCreateCompleteIncomingDependency_Supplier4006Command(CreateRelationshipRequest req) {
366
		if (!(req.getSource() instanceof Dependency)) {
367
			return UnexecutableCommand.INSTANCE;
368
		}
369
		Dependency element = (Dependency) req.getSource();
370
		if (element.getSuppliers().contains(req.getTarget())) {
371
			return UnexecutableCommand.INSTANCE;
372
		}
373
		SetRequest setReq = new SetRequest(req.getSource(), UMLPackage.eINSTANCE.getDependency_Supplier(), req.getTarget());
374
		return getMSLWrapper(new SetValueCommand(setReq));
375
	}
376
377
	/**
378
	 * @generated
379
	 */
380
	protected Command getCreateCompleteIncomingDependency_Client4007Command(CreateRelationshipRequest req) {
381
		if (!(req.getSource() instanceof Dependency)) {
382
			return UnexecutableCommand.INSTANCE;
383
		}
384
		Dependency element = (Dependency) req.getSource();
385
		if (element.getClients().contains(req.getTarget())) {
386
			return UnexecutableCommand.INSTANCE;
387
		}
388
		SetRequest setReq = new SetRequest(req.getSource(), UMLPackage.eINSTANCE.getDependency_Client(), req.getTarget());
389
		return getMSLWrapper(new SetValueCommand(setReq));
390
	}
391
392
	/**
393
	 * @generated
394
	 */
395
	protected Command getCreateStartOutgoingInterfaceRealization4008Command(CreateRelationshipRequest req) {
396
		return new Command() {
397
		};
398
	}
399
400
	/**
401
	 * @generated
402
	 */
403
	protected Command getCreateStartOutgoingUsage4009Command(CreateRelationshipRequest req) {
404
		if (!UMLBaseItemSemanticEditPolicy.LinkConstraints.Usage_4009.canCreateLink(req, false)) {
405
			return UnexecutableCommand.INSTANCE;
406
		}
407
		return new Command() {
408
		};
409
	}
410
411
	/**
412
	 * @generated
413
	 */
414
	protected Command getCreateCompleteIncomingUsage4009Command(CreateRelationshipRequest req) {
415
		if (!(req.getSource() instanceof NamedElement)) {
416
			return UnexecutableCommand.INSTANCE;
417
		}
418
		final org.eclipse.uml2.uml.Package element = (org.eclipse.uml2.uml.Package) getRelationshipContainer(req.getSource(), UMLPackage.eINSTANCE.getPackage(), req.getElementType());
419
		if (element == null) {
420
			return UnexecutableCommand.INSTANCE;
421
		}
422
		if (!UMLBaseItemSemanticEditPolicy.LinkConstraints.Usage_4009.canCreateLink(req, false)) {
423
			return UnexecutableCommand.INSTANCE;
424
		}
425
		if (req.getContainmentFeature() == null) {
426
			req.setContainmentFeature(UMLPackage.eINSTANCE.getPackage_PackagedElement());
427
		}
428
		return getMSLWrapper(new CreateIncomingUsage4009Command(req) {
429
430
			protected EObject getElementToEdit() {
431
				return element;
432
			}
433
		});
434
	}
435
436
	/**
437
	 * @generated
438
	 */
439
	private static class CreateIncomingUsage4009Command extends CreateRelationshipCommand {
440
441
		/**
442
		 * @generated
443
		 */
444
		public CreateIncomingUsage4009Command(CreateRelationshipRequest req) {
445
			super(req);
446
		}
447
448
		/**
449
		 * @generated
450
		 */
451
		protected EClass getEClassToEdit() {
452
			return UMLPackage.eINSTANCE.getPackage();
453
		};
454
455
		/**
456
		 * @generated
457
		 */
458
		protected void setElementToEdit(EObject element) {
459
			throw new UnsupportedOperationException();
460
		}
461
462
		/**
463
		 * @generated
464
		 */
465
		protected EObject doDefaultElementCreation() {
466
			Usage newElement = (Usage) super.doDefaultElementCreation();
467
			if (newElement != null) {
468
				newElement.getSuppliers().add((NamedElement) getTarget());
469
				newElement.getClients().add((NamedElement) getSource());
470
			}
471
			return newElement;
472
		}
473
	}
474
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/policies/InstanceSpecification2ItemSemanticEditPolicy.java (+255 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.policies;
2
3
import org.eclipse.emf.ecore.EAnnotation;
4
import org.eclipse.emf.ecore.EClass;
5
import org.eclipse.emf.ecore.EObject;
6
import org.eclipse.gef.commands.Command;
7
import org.eclipse.gef.commands.UnexecutableCommand;
8
import org.eclipse.gmf.runtime.emf.type.core.commands.CreateRelationshipCommand;
9
import org.eclipse.gmf.runtime.emf.type.core.commands.DestroyElementCommand;
10
import org.eclipse.gmf.runtime.emf.type.core.commands.SetValueCommand;
11
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest;
12
import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest;
13
import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest;
14
import org.eclipse.gmf.runtime.notation.View;
15
import org.eclipse.uml2.diagram.clazz.providers.UMLElementTypes;
16
import org.eclipse.uml2.uml.Constraint;
17
import org.eclipse.uml2.uml.Dependency;
18
import org.eclipse.uml2.uml.NamedElement;
19
import org.eclipse.uml2.uml.UMLPackage;
20
import org.eclipse.uml2.uml.Usage;
21
22
/**
23
 * @generated
24
 */
25
public class InstanceSpecification2ItemSemanticEditPolicy extends UMLBaseItemSemanticEditPolicy {
26
27
	/**
28
	 * @generated
29
	 */
30
	protected Command getDestroyElementCommand(DestroyElementRequest req) {
31
		return getMSLWrapper(new DestroyElementCommand(req) {
32
33
			protected EObject getElementToDestroy() {
34
				View view = (View) getHost().getModel();
35
				EAnnotation annotation = view.getEAnnotation("Shortcut"); //$NON-NLS-1$
36
				if (annotation != null) {
37
					return view;
38
				}
39
				return super.getElementToDestroy();
40
			}
41
42
		});
43
	}
44
45
	/**
46
	 * @generated
47
	 */
48
	protected Command getCreateRelationshipCommand(CreateRelationshipRequest req) {
49
		if (UMLElementTypes.Dependency_4002 == req.getElementType()) {
50
			return req.getTarget() == null ? getCreateStartOutgoingDependency4002Command(req) : getCreateCompleteIncomingDependency4002Command(req);
51
		}
52
		if (UMLElementTypes.ConstraintConstrainedElement_4004 == req.getElementType()) {
53
			return req.getTarget() == null ? null : getCreateCompleteIncomingConstraint_ConstrainedElement4004Command(req);
54
		}
55
		if (UMLElementTypes.DependencySupplier_4006 == req.getElementType()) {
56
			return req.getTarget() == null ? null : getCreateCompleteIncomingDependency_Supplier4006Command(req);
57
		}
58
		if (UMLElementTypes.DependencyClient_4007 == req.getElementType()) {
59
			return req.getTarget() == null ? null : getCreateCompleteIncomingDependency_Client4007Command(req);
60
		}
61
		if (UMLElementTypes.Usage_4009 == req.getElementType()) {
62
			return req.getTarget() == null ? getCreateStartOutgoingUsage4009Command(req) : getCreateCompleteIncomingUsage4009Command(req);
63
		}
64
		return super.getCreateRelationshipCommand(req);
65
	}
66
67
	/**
68
	 * @generated
69
	 */
70
	protected Command getCreateStartOutgoingDependency4002Command(CreateRelationshipRequest req) {
71
		return new Command() {
72
		};
73
	}
74
75
	/**
76
	 * @generated
77
	 */
78
	protected Command getCreateCompleteIncomingDependency4002Command(CreateRelationshipRequest req) {
79
		if (!(req.getSource() instanceof NamedElement)) {
80
			return UnexecutableCommand.INSTANCE;
81
		}
82
		final org.eclipse.uml2.uml.Package element = (org.eclipse.uml2.uml.Package) getRelationshipContainer(req.getSource(), UMLPackage.eINSTANCE.getPackage(), req.getElementType());
83
		if (element == null) {
84
			return UnexecutableCommand.INSTANCE;
85
		}
86
		if (req.getContainmentFeature() == null) {
87
			req.setContainmentFeature(UMLPackage.eINSTANCE.getPackage_PackagedElement());
88
		}
89
		return getMSLWrapper(new CreateIncomingDependency4002Command(req) {
90
91
			protected EObject getElementToEdit() {
92
				return element;
93
			}
94
		});
95
	}
96
97
	/**
98
	 * @generated
99
	 */
100
	private static class CreateIncomingDependency4002Command extends CreateRelationshipCommand {
101
102
		/**
103
		 * @generated
104
		 */
105
		public CreateIncomingDependency4002Command(CreateRelationshipRequest req) {
106
			super(req);
107
		}
108
109
		/**
110
		 * @generated
111
		 */
112
		protected EClass getEClassToEdit() {
113
			return UMLPackage.eINSTANCE.getPackage();
114
		};
115
116
		/**
117
		 * @generated
118
		 */
119
		protected void setElementToEdit(EObject element) {
120
			throw new UnsupportedOperationException();
121
		}
122
123
		/**
124
		 * @generated
125
		 */
126
		protected EObject doDefaultElementCreation() {
127
			Dependency newElement = (Dependency) super.doDefaultElementCreation();
128
			if (newElement != null) {
129
				newElement.getSuppliers().add((NamedElement) getTarget());
130
				newElement.getClients().add((NamedElement) getSource());
131
			}
132
			return newElement;
133
		}
134
	}
135
136
	/**
137
	 * @generated
138
	 */
139
	protected Command getCreateCompleteIncomingConstraint_ConstrainedElement4004Command(CreateRelationshipRequest req) {
140
		if (!(req.getSource() instanceof Constraint)) {
141
			return UnexecutableCommand.INSTANCE;
142
		}
143
		Constraint element = (Constraint) req.getSource();
144
		if (element.getConstrainedElements().contains(req.getTarget())) {
145
			return UnexecutableCommand.INSTANCE;
146
		}
147
		SetRequest setReq = new SetRequest(req.getSource(), UMLPackage.eINSTANCE.getConstraint_ConstrainedElement(), req.getTarget());
148
		return getMSLWrapper(new SetValueCommand(setReq));
149
	}
150
151
	/**
152
	 * @generated
153
	 */
154
	protected Command getCreateCompleteIncomingDependency_Supplier4006Command(CreateRelationshipRequest req) {
155
		if (!(req.getSource() instanceof Dependency)) {
156
			return UnexecutableCommand.INSTANCE;
157
		}
158
		Dependency element = (Dependency) req.getSource();
159
		if (element.getSuppliers().contains(req.getTarget())) {
160
			return UnexecutableCommand.INSTANCE;
161
		}
162
		SetRequest setReq = new SetRequest(req.getSource(), UMLPackage.eINSTANCE.getDependency_Supplier(), req.getTarget());
163
		return getMSLWrapper(new SetValueCommand(setReq));
164
	}
165
166
	/**
167
	 * @generated
168
	 */
169
	protected Command getCreateCompleteIncomingDependency_Client4007Command(CreateRelationshipRequest req) {
170
		if (!(req.getSource() instanceof Dependency)) {
171
			return UnexecutableCommand.INSTANCE;
172
		}
173
		Dependency element = (Dependency) req.getSource();
174
		if (element.getClients().contains(req.getTarget())) {
175
			return UnexecutableCommand.INSTANCE;
176
		}
177
		SetRequest setReq = new SetRequest(req.getSource(), UMLPackage.eINSTANCE.getDependency_Client(), req.getTarget());
178
		return getMSLWrapper(new SetValueCommand(setReq));
179
	}
180
181
	/**
182
	 * @generated
183
	 */
184
	protected Command getCreateStartOutgoingUsage4009Command(CreateRelationshipRequest req) {
185
		if (!UMLBaseItemSemanticEditPolicy.LinkConstraints.Usage_4009.canCreateLink(req, false)) {
186
			return UnexecutableCommand.INSTANCE;
187
		}
188
		return new Command() {
189
		};
190
	}
191
192
	/**
193
	 * @generated
194
	 */
195
	protected Command getCreateCompleteIncomingUsage4009Command(CreateRelationshipRequest req) {
196
		if (!(req.getSource() instanceof NamedElement)) {
197
			return UnexecutableCommand.INSTANCE;
198
		}
199
		final org.eclipse.uml2.uml.Package element = (org.eclipse.uml2.uml.Package) getRelationshipContainer(req.getSource(), UMLPackage.eINSTANCE.getPackage(), req.getElementType());
200
		if (element == null) {
201
			return UnexecutableCommand.INSTANCE;
202
		}
203
		if (!UMLBaseItemSemanticEditPolicy.LinkConstraints.Usage_4009.canCreateLink(req, false)) {
204
			return UnexecutableCommand.INSTANCE;
205
		}
206
		if (req.getContainmentFeature() == null) {
207
			req.setContainmentFeature(UMLPackage.eINSTANCE.getPackage_PackagedElement());
208
		}
209
		return getMSLWrapper(new CreateIncomingUsage4009Command(req) {
210
211
			protected EObject getElementToEdit() {
212
				return element;
213
			}
214
		});
215
	}
216
217
	/**
218
	 * @generated
219
	 */
220
	private static class CreateIncomingUsage4009Command extends CreateRelationshipCommand {
221
222
		/**
223
		 * @generated
224
		 */
225
		public CreateIncomingUsage4009Command(CreateRelationshipRequest req) {
226
			super(req);
227
		}
228
229
		/**
230
		 * @generated
231
		 */
232
		protected EClass getEClassToEdit() {
233
			return UMLPackage.eINSTANCE.getPackage();
234
		};
235
236
		/**
237
		 * @generated
238
		 */
239
		protected void setElementToEdit(EObject element) {
240
			throw new UnsupportedOperationException();
241
		}
242
243
		/**
244
		 * @generated
245
		 */
246
		protected EObject doDefaultElementCreation() {
247
			Usage newElement = (Usage) super.doDefaultElementCreation();
248
			if (newElement != null) {
249
				newElement.getSuppliers().add((NamedElement) getTarget());
250
				newElement.getClients().add((NamedElement) getSource());
251
			}
252
			return newElement;
253
		}
254
	}
255
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/parts/AssociationName5EditPart.java (+533 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.parts;
2
3
import java.util.Collections;
4
import java.util.List;
5
6
import org.eclipse.draw2d.ConnectionLocator;
7
import org.eclipse.draw2d.IFigure;
8
import org.eclipse.draw2d.Label;
9
import org.eclipse.draw2d.geometry.Point;
10
import org.eclipse.emf.common.notify.Notification;
11
import org.eclipse.emf.ecore.EObject;
12
import org.eclipse.emf.transaction.RunnableWithResult;
13
import org.eclipse.gef.AccessibleEditPart;
14
import org.eclipse.gef.EditPolicy;
15
import org.eclipse.gef.Request;
16
import org.eclipse.gef.requests.DirectEditRequest;
17
import org.eclipse.gef.tools.DirectEditManager;
18
import org.eclipse.gmf.runtime.common.ui.services.parser.IParser;
19
import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus;
20
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserEditStatus;
21
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions;
22
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserService;
23
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
24
import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart;
25
import org.eclipse.gmf.runtime.diagram.ui.editparts.LabelEditPart;
26
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy;
27
import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry;
28
import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants;
29
import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager;
30
import org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel;
31
import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
32
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
33
import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser;
34
import org.eclipse.gmf.runtime.emf.ui.services.parser.ParserHintAdapter;
35
import org.eclipse.gmf.runtime.notation.FontStyle;
36
import org.eclipse.gmf.runtime.notation.NotationPackage;
37
import org.eclipse.gmf.runtime.notation.View;
38
import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
39
import org.eclipse.jface.viewers.ICellEditorValidator;
40
import org.eclipse.swt.SWT;
41
import org.eclipse.swt.accessibility.AccessibleEvent;
42
import org.eclipse.swt.graphics.Color;
43
import org.eclipse.swt.graphics.FontData;
44
import org.eclipse.swt.graphics.Image;
45
import org.eclipse.uml2.diagram.clazz.edit.policies.UMLTextSelectionEditPolicy;
46
import org.eclipse.uml2.diagram.clazz.part.UMLVisualIDRegistry;
47
import org.eclipse.uml2.diagram.clazz.providers.UMLElementTypes;
48
49
/**
50
 * @generated
51
 */
52
public class AssociationName5EditPart extends LabelEditPart implements ITextAwareEditPart {
53
54
	/**
55
	 * @generated
56
	 */
57
	public static final int VISUAL_ID = 6007;
58
59
	/**
60
	 * @generated
61
	 */
62
	private DirectEditManager manager;
63
64
	/**
65
	 * @generated
66
	 */
67
	private IParser parser;
68
69
	/**
70
	 * @generated
71
	 */
72
	private List parserElements;
73
74
	/**
75
	 * @generated
76
	 */
77
	private String defaultText;
78
79
	/**
80
	 * @generated
81
	 */
82
	static {
83
		registerSnapBackPosition(UMLVisualIDRegistry.getType(AssociationName5EditPart.VISUAL_ID), new Point(0, -30));
84
	}
85
86
	/**
87
	 * @generated
88
	 */
89
	public AssociationName5EditPart(View view) {
90
		super(view);
91
	}
92
93
	/**
94
	 * @generated
95
	 */
96
	protected void createDefaultEditPolicies() {
97
		super.createDefaultEditPolicies();
98
		installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy());
99
100
	}
101
102
	/**
103
	 * @generated
104
	 */
105
	public int getKeyPoint() {
106
		return ConnectionLocator.SOURCE;
107
	}
108
109
	/**
110
	 * @generated
111
	 */
112
	protected String getLabelTextHelper(IFigure figure) {
113
		if (figure instanceof WrapLabel) {
114
			return ((WrapLabel) figure).getText();
115
		} else {
116
			return ((Label) figure).getText();
117
		}
118
	}
119
120
	/**
121
	 * @generated
122
	 */
123
	protected void setLabelTextHelper(IFigure figure, String text) {
124
		if (figure instanceof WrapLabel) {
125
			((WrapLabel) figure).setText(text);
126
		} else {
127
			((Label) figure).setText(text);
128
		}
129
	}
130
131
	/**
132
	 * @generated
133
	 */
134
	protected Image getLabelIconHelper(IFigure figure) {
135
		if (figure instanceof WrapLabel) {
136
			return ((WrapLabel) figure).getIcon();
137
		} else {
138
			return ((Label) figure).getIcon();
139
		}
140
	}
141
142
	/**
143
	 * @generated
144
	 */
145
	protected void setLabelIconHelper(IFigure figure, Image icon) {
146
		if (figure instanceof WrapLabel) {
147
			((WrapLabel) figure).setIcon(icon);
148
		} else {
149
			((Label) figure).setIcon(icon);
150
		}
151
	}
152
153
	/**
154
	 * @generated
155
	 */
156
	public void setLabel(IFigure figure) {
157
		unregisterVisuals();
158
		setFigure(figure);
159
		defaultText = getLabelTextHelper(figure);
160
		registerVisuals();
161
		refreshVisuals();
162
	}
163
164
	/**
165
	 * @generated
166
	 */
167
	protected List getModelChildren() {
168
		return Collections.EMPTY_LIST;
169
	}
170
171
	/**
172
	 * @generated
173
	 */
174
	public IGraphicalEditPart getChildBySemanticHint(String semanticHint) {
175
		return null;
176
	}
177
178
	/**
179
	 * @generated
180
	 */
181
	protected EObject getParserElement() {
182
		EObject element = resolveSemanticElement();
183
		return element != null ? element : (View) getModel();
184
	}
185
186
	/**
187
	 * @generated
188
	 */
189
	protected Image getLabelIcon() {
190
		return null;
191
	}
192
193
	/**
194
	 * @generated
195
	 */
196
	protected String getLabelText() {
197
		String text = null;
198
		if (getParser() != null) {
199
			text = getParser().getPrintString(new EObjectAdapter(getParserElement()), getParserOptions().intValue());
200
		}
201
		if (text == null || text.length() == 0) {
202
			text = defaultText;
203
		}
204
		return text;
205
	}
206
207
	/**
208
	 * @generated
209
	 */
210
	public void setLabelText(String text) {
211
		setLabelTextHelper(getFigure(), text);
212
		Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
213
		if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) {
214
			((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback();
215
		}
216
	}
217
218
	/**
219
	 * @generated
220
	 */
221
	public String getEditText() {
222
		if (getParser() == null) {
223
			return ""; //$NON-NLS-1$
224
		}
225
		return getParser().getEditString(new EObjectAdapter(getParserElement()), getParserOptions().intValue());
226
	}
227
228
	/**
229
	 * @generated
230
	 */
231
	protected boolean isEditable() {
232
		return getEditText() != null;
233
	}
234
235
	/**
236
	 * @generated
237
	 */
238
	public ICellEditorValidator getEditTextValidator() {
239
		return new ICellEditorValidator() {
240
241
			public String isValid(final Object value) {
242
				if (value instanceof String) {
243
					final EObject element = getParserElement();
244
					final IParser parser = getParser();
245
					try {
246
						IParserEditStatus valid = (IParserEditStatus) getEditingDomain().runExclusive(new RunnableWithResult.Impl() {
247
248
							public void run() {
249
								setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value));
250
							}
251
						});
252
						return valid.getCode() == ParserEditStatus.EDITABLE ? null : valid.getMessage();
253
					} catch (InterruptedException ie) {
254
						ie.printStackTrace();
255
					}
256
				}
257
258
				// shouldn't get here
259
				return null;
260
			}
261
		};
262
	}
263
264
	/**
265
	 * @generated
266
	 */
267
	public IContentAssistProcessor getCompletionProcessor() {
268
		if (getParser() == null) {
269
			return null;
270
		}
271
		return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement()));
272
	}
273
274
	/**
275
	 * @generated
276
	 */
277
	public ParserOptions getParserOptions() {
278
		return ParserOptions.NONE;
279
	}
280
281
	/**
282
	 * @generated
283
	 */
284
	public IParser getParser() {
285
		if (parser == null) {
286
			String parserHint = ((View) getModel()).getType();
287
			ParserHintAdapter hintAdapter = new ParserHintAdapter(getParserElement(), parserHint) {
288
289
				public Object getAdapter(Class adapter) {
290
					if (IElementType.class.equals(adapter)) {
291
						return UMLElementTypes.Association_4005;
292
					}
293
					return super.getAdapter(adapter);
294
				}
295
			};
296
			parser = ParserService.getInstance().getParser(hintAdapter);
297
		}
298
		return parser;
299
	}
300
301
	/**
302
	 * @generated
303
	 */
304
	protected DirectEditManager getManager() {
305
		if (manager == null) {
306
			setManager(new TextDirectEditManager(this, TextDirectEditManager.getTextCellEditorClass(this), UMLEditPartFactory.getTextCellEditorLocator(this)));
307
		}
308
		return manager;
309
	}
310
311
	/**
312
	 * @generated
313
	 */
314
	protected void setManager(DirectEditManager manager) {
315
		this.manager = manager;
316
	}
317
318
	/**
319
	 * @generated
320
	 */
321
	protected void performDirectEdit() {
322
		getManager().show();
323
	}
324
325
	/**
326
	 * @generated
327
	 */
328
	protected void performDirectEdit(Point eventLocation) {
329
		if (getManager().getClass() == TextDirectEditManager.class) {
330
			((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint());
331
		}
332
	}
333
334
	/**
335
	 * @generated
336
	 */
337
	private void performDirectEdit(char initialCharacter) {
338
		if (getManager() instanceof TextDirectEditManager) {
339
			((TextDirectEditManager) getManager()).show(initialCharacter);
340
		} else {
341
			performDirectEdit();
342
		}
343
	}
344
345
	/**
346
	 * @generated
347
	 */
348
	protected void performDirectEditRequest(Request request) {
349
		final Request theRequest = request;
350
		try {
351
			getEditingDomain().runExclusive(new Runnable() {
352
353
				public void run() {
354
					if (isActive() && isEditable()) {
355
						if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) {
356
							Character initialChar = (Character) theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR);
357
							performDirectEdit(initialChar.charValue());
358
						} else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) {
359
							DirectEditRequest editRequest = (DirectEditRequest) theRequest;
360
							performDirectEdit(editRequest.getLocation());
361
						} else {
362
							performDirectEdit();
363
						}
364
					}
365
				}
366
			});
367
		} catch (InterruptedException e) {
368
			e.printStackTrace();
369
		}
370
	}
371
372
	/**
373
	 * @generated
374
	 */
375
	protected void refreshVisuals() {
376
		super.refreshVisuals();
377
		refreshLabel();
378
		refreshFont();
379
		refreshFontColor();
380
		refreshUnderline();
381
		refreshStrikeThrough();
382
	}
383
384
	/**
385
	 * @generated
386
	 */
387
	protected void refreshLabel() {
388
		setLabelTextHelper(getFigure(), getLabelText());
389
		setLabelIconHelper(getFigure(), getLabelIcon());
390
		Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
391
		if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) {
392
			((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback();
393
		}
394
	}
395
396
	/**
397
	 * @generated
398
	 */
399
	protected void refreshUnderline() {
400
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
401
		if (style != null && getFigure() instanceof WrapLabel) {
402
			((WrapLabel) getFigure()).setTextUnderline(style.isUnderline());
403
		}
404
	}
405
406
	/**
407
	 * @generated
408
	 */
409
	protected void refreshStrikeThrough() {
410
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
411
		if (style != null && getFigure() instanceof WrapLabel) {
412
			((WrapLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough());
413
		}
414
	}
415
416
	/**
417
	 * @generated
418
	 */
419
	protected void refreshFont() {
420
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
421
		if (style != null) {
422
			FontData fontData = new FontData(style.getFontName(), style.getFontHeight(), (style.isBold() ? SWT.BOLD : SWT.NORMAL) | (style.isItalic() ? SWT.ITALIC : SWT.NORMAL));
423
			setFont(fontData);
424
		}
425
	}
426
427
	/**
428
	 * @generated
429
	 */
430
	protected void setFontColor(Color color) {
431
		getFigure().setForegroundColor(color);
432
	}
433
434
	/**
435
	 * @generated
436
	 */
437
	protected void addSemanticListeners() {
438
		if (getParser() instanceof ISemanticParser) {
439
			EObject element = resolveSemanticElement();
440
			parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element);
441
			for (int i = 0; i < parserElements.size(); i++) {
442
				addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$
443
			}
444
		} else {
445
			super.addSemanticListeners();
446
		}
447
	}
448
449
	/**
450
	 * @generated
451
	 */
452
	protected void removeSemanticListeners() {
453
		if (parserElements != null) {
454
			for (int i = 0; i < parserElements.size(); i++) {
455
				removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$
456
			}
457
		} else {
458
			super.removeSemanticListeners();
459
		}
460
	}
461
462
	/**
463
	 * @generated
464
	 */
465
	protected AccessibleEditPart getAccessibleEditPart() {
466
		if (accessibleEP == null) {
467
			accessibleEP = new AccessibleGraphicalEditPart() {
468
469
				public void getName(AccessibleEvent e) {
470
					e.result = getLabelTextHelper(getFigure());
471
				}
472
			};
473
		}
474
		return accessibleEP;
475
	}
476
477
	/**
478
	 * @generated
479
	 */
480
	private View getFontStyleOwnerView() {
481
		return getPrimaryView();
482
	}
483
484
	/**
485
	 * @generated
486
	 */
487
	protected void handleNotificationEvent(Notification event) {
488
		Object feature = event.getFeature();
489
		if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) {
490
			Integer c = (Integer) event.getNewValue();
491
			setFontColor(DiagramColorRegistry.getInstance().getColor(c));
492
		} else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) {
493
			refreshUnderline();
494
		} else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) {
495
			refreshStrikeThrough();
496
		} else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature)
497
				|| NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) {
498
			refreshFont();
499
		} else {
500
			if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) {
501
				refreshLabel();
502
			}
503
			if (getParser() instanceof ISemanticParser) {
504
				ISemanticParser modelParser = (ISemanticParser) getParser();
505
				if (modelParser.areSemanticElementsAffected(null, event)) {
506
					removeSemanticListeners();
507
					if (resolveSemanticElement() != null) {
508
						addSemanticListeners();
509
					}
510
					refreshLabel();
511
				}
512
			}
513
		}
514
		super.handleNotificationEvent(event);
515
	}
516
517
	/**
518
	 * @generated
519
	 */
520
	protected IFigure createFigure() {
521
		IFigure label = createFigurePrim();
522
		defaultText = getLabelTextHelper(label);
523
		return label;
524
	}
525
526
	/**
527
	 * @generated
528
	 */
529
	protected IFigure createFigurePrim() {
530
		return new WrapLabel();
531
	}
532
533
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/parts/Enumeration2EditPart.java (+560 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.parts;
2
3
import org.eclipse.draw2d.IFigure;
4
import org.eclipse.draw2d.StackLayout;
5
import org.eclipse.gef.EditPart;
6
import org.eclipse.gef.EditPolicy;
7
import org.eclipse.gef.Request;
8
import org.eclipse.gef.commands.Command;
9
import org.eclipse.gef.editpolicies.LayoutEditPolicy;
10
import org.eclipse.gef.editpolicies.NonResizableEditPolicy;
11
import org.eclipse.gef.requests.CreateRequest;
12
import org.eclipse.gmf.runtime.diagram.core.edithelpers.CreateElementRequestAdapter;
13
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
14
import org.eclipse.gmf.runtime.diagram.ui.editparts.ShapeNodeEditPart;
15
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.CreationEditPolicy;
16
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
17
import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewAndElementRequest;
18
import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout;
19
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
20
import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure;
21
import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure;
22
import org.eclipse.gmf.runtime.notation.View;
23
import org.eclipse.uml2.diagram.clazz.edit.policies.Enumeration2ItemSemanticEditPolicy;
24
import org.eclipse.uml2.diagram.clazz.part.UMLVisualIDRegistry;
25
import org.eclipse.uml2.diagram.clazz.providers.UMLElementTypes;
26
27
/**
28
 * @generated
29
 */
30
public class Enumeration2EditPart extends ShapeNodeEditPart {
31
32
	/**
33
	 * @generated
34
	 */
35
	public static final int VISUAL_ID = 2003;
36
37
	/**
38
	 * @generated
39
	 */
40
	protected IFigure contentPane;
41
42
	/**
43
	 * @generated
44
	 */
45
	protected IFigure primaryShape;
46
47
	/**
48
	 * @generated
49
	 */
50
	public Enumeration2EditPart(View view) {
51
		super(view);
52
	}
53
54
	/**
55
	 * @generated
56
	 */
57
	protected void createDefaultEditPolicies() {
58
		installEditPolicy(EditPolicyRoles.CREATION_ROLE, new CreationEditPolicy() {
59
60
			public Command getCommand(Request request) {
61
				if (understandsRequest(request)) {
62
					if (request instanceof CreateViewAndElementRequest) {
63
						CreateElementRequestAdapter adapter = ((CreateViewAndElementRequest) request).getViewAndElementDescriptor().getCreateElementRequestAdapter();
64
						IElementType type = (IElementType) adapter.getAdapter(IElementType.class);
65
						if (type == UMLElementTypes.EnumerationLiteral_3016) {
66
							EditPart compartmentEditPart = getChildBySemanticHint(UMLVisualIDRegistry.getType(EnumerationLiteralsEditPart.VISUAL_ID));
67
							return compartmentEditPart == null ? null : compartmentEditPart.getCommand(request);
68
						}
69
						if (type == UMLElementTypes.Property_3023) {
70
							EditPart compartmentEditPart = getChildBySemanticHint(UMLVisualIDRegistry.getType(EnumerationAttributesEditPart.VISUAL_ID));
71
							return compartmentEditPart == null ? null : compartmentEditPart.getCommand(request);
72
						}
73
						if (type == UMLElementTypes.Operation_3024) {
74
							EditPart compartmentEditPart = getChildBySemanticHint(UMLVisualIDRegistry.getType(EnumerationOperationsEditPart.VISUAL_ID));
75
							return compartmentEditPart == null ? null : compartmentEditPart.getCommand(request);
76
						}
77
					}
78
					return super.getCommand(request);
79
				}
80
				return null;
81
			}
82
		});
83
		super.createDefaultEditPolicies();
84
		installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new Enumeration2ItemSemanticEditPolicy());
85
		installEditPolicy(EditPolicy.LAYOUT_ROLE, createLayoutEditPolicy());
86
87
	}
88
89
	/**
90
	 * @generated
91
	 */
92
	protected LayoutEditPolicy createLayoutEditPolicy() {
93
		LayoutEditPolicy lep = new LayoutEditPolicy() {
94
95
			protected EditPolicy createChildEditPolicy(EditPart child) {
96
				EditPolicy result = child.getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
97
				if (result == null) {
98
					result = new NonResizableEditPolicy();
99
				}
100
				return result;
101
			}
102
103
			protected Command getMoveChildrenCommand(Request request) {
104
				return null;
105
			}
106
107
			protected Command getCreateCommand(CreateRequest request) {
108
				return null;
109
			}
110
		};
111
		return lep;
112
	}
113
114
	/**
115
	 * @generated
116
	 */
117
	protected IFigure createNodeShape() {
118
		ClassFigure figure = new ClassFigure();
119
		return primaryShape = figure;
120
	}
121
122
	/**
123
	 * @generated
124
	 */
125
	public ClassFigure getPrimaryShape() {
126
		return (ClassFigure) primaryShape;
127
	}
128
129
	/**
130
	 * @generated 
131
	 */
132
	protected IFigure getContentPaneFor(IGraphicalEditPart editPart) {
133
		if (editPart instanceof EnumerationLiteralsEditPart) {
134
			return getPrimaryShape().getFigureClassFigure_LiteralsCompartment();
135
		}
136
		if (editPart instanceof EnumerationAttributesEditPart) {
137
			return getPrimaryShape().getFigureClassFigure_PropertiesCompartment();
138
		}
139
		if (editPart instanceof EnumerationOperationsEditPart) {
140
			return getPrimaryShape().getFigureClassFigure_OperationsCompartment();
141
		}
142
143
		return super.getContentPaneFor(editPart);
144
	}
145
146
	/**
147
	 * @generated
148
	 */
149
	protected boolean addFixedChild(EditPart childEditPart) {
150
		if (childEditPart instanceof EnumerationNameEditPart) {
151
			((EnumerationNameEditPart) childEditPart).setLabel(getPrimaryShape().getFigureClassFigure_name());
152
			return true;
153
		}
154
		if (childEditPart instanceof EnumerationLiteralsEditPart) {
155
			IFigure pane = getPrimaryShape().getFigureClassFigure_LiteralsCompartment();
156
			setupContentPane(pane); // FIXME each comparment should handle his content pane in his own way 
157
			pane.add(((EnumerationLiteralsEditPart) childEditPart).getFigure());
158
			return true;
159
		}
160
		if (childEditPart instanceof EnumerationAttributesEditPart) {
161
			IFigure pane = getPrimaryShape().getFigureClassFigure_PropertiesCompartment();
162
			setupContentPane(pane); // FIXME each comparment should handle his content pane in his own way 
163
			pane.add(((EnumerationAttributesEditPart) childEditPart).getFigure());
164
			return true;
165
		}
166
		if (childEditPart instanceof EnumerationOperationsEditPart) {
167
			IFigure pane = getPrimaryShape().getFigureClassFigure_OperationsCompartment();
168
			setupContentPane(pane); // FIXME each comparment should handle his content pane in his own way 
169
			pane.add(((EnumerationOperationsEditPart) childEditPart).getFigure());
170
			return true;
171
		}
172
		return false;
173
	}
174
175
	/**
176
	 * @generated
177
	 */
178
	protected boolean removeFixedChild(EditPart childEditPart) {
179
		if (childEditPart instanceof EnumerationLiteralsEditPart) {
180
			IFigure pane = getPrimaryShape().getFigureClassFigure_LiteralsCompartment();
181
			pane.remove(((EnumerationLiteralsEditPart) childEditPart).getFigure());
182
			return true;
183
		}
184
		if (childEditPart instanceof EnumerationAttributesEditPart) {
185
			IFigure pane = getPrimaryShape().getFigureClassFigure_PropertiesCompartment();
186
			pane.remove(((EnumerationAttributesEditPart) childEditPart).getFigure());
187
			return true;
188
		}
189
		if (childEditPart instanceof EnumerationOperationsEditPart) {
190
			IFigure pane = getPrimaryShape().getFigureClassFigure_OperationsCompartment();
191
			pane.remove(((EnumerationOperationsEditPart) childEditPart).getFigure());
192
			return true;
193
		}
194
		return false;
195
	}
196
197
	/**
198
	 * @generated
199
	 */
200
	protected NodeFigure createNodePlate() {
201
		DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(getMapMode().DPtoLP(100), getMapMode().DPtoLP(60));
202
		return result;
203
	}
204
205
	/**
206
	 * Creates figure for this edit part.
207
	 * 
208
	 * Body of this method does not depend on settings in generation model
209
	 * so you may safely remove <i>generated</i> tag and modify it.
210
	 * 
211
	 * @generated
212
	 */
213
	protected NodeFigure createNodeFigure() {
214
		NodeFigure figure = createNodePlate();
215
		figure.setLayoutManager(new StackLayout());
216
		IFigure shape = createNodeShape();
217
		figure.add(shape);
218
		contentPane = setupContentPane(shape);
219
		return figure;
220
	}
221
222
	/**
223
	 * Default implementation treats passed figure as content pane.
224
	 * Respects layout one may have set for generated figure.
225
	 * @param nodeShape instance of generated figure class
226
	 * @generated
227
	 */
228
	protected IFigure setupContentPane(IFigure nodeShape) {
229
		if (nodeShape.getLayoutManager() == null) {
230
			ConstrainedToolbarLayout layout = new ConstrainedToolbarLayout();
231
			layout.setSpacing(getMapMode().DPtoLP(5));
232
			nodeShape.setLayoutManager(layout);
233
		}
234
		return nodeShape; // use nodeShape itself as contentPane
235
	}
236
237
	/**
238
	 * @generated
239
	 */
240
	public IFigure getContentPane() {
241
		if (contentPane != null) {
242
			return contentPane;
243
		}
244
		return super.getContentPane();
245
	}
246
247
	/**
248
	 * @generated
249
	 */
250
	public EditPart getPrimaryChildEditPart() {
251
		return getChildBySemanticHint(UMLVisualIDRegistry.getType(EnumerationNameEditPart.VISUAL_ID));
252
	}
253
254
	/**
255
	 * @generated
256
	 */
257
	protected void addChildVisual(EditPart childEditPart, int index) {
258
		if (addFixedChild(childEditPart)) {
259
			return;
260
		}
261
		super.addChildVisual(childEditPart, -1);
262
	}
263
264
	/**
265
	 * @generated
266
	 */
267
	protected void removeChildVisual(EditPart childEditPart) {
268
		if (removeFixedChild(childEditPart)) {
269
			return;
270
		}
271
		super.removeChildVisual(childEditPart);
272
	}
273
274
	/**
275
	 * @generated
276
	 */
277
	public class ClassFigure extends org.eclipse.draw2d.RectangleFigure {
278
279
		/**
280
		 * @generated
281
		 */
282
		public ClassFigure() {
283
284
			org.eclipse.gmf.internal.codegen.draw2d.GridLayout myGenLayoutManager = new org.eclipse.gmf.internal.codegen.draw2d.GridLayout();
285
			myGenLayoutManager.numColumns = 1;
286
			myGenLayoutManager.makeColumnsEqualWidth = true;
287
			myGenLayoutManager.marginWidth = 0;
288
			myGenLayoutManager.marginHeight = 0;
289
			myGenLayoutManager.horizontalSpacing = 0;
290
			myGenLayoutManager.verticalSpacing = 0;
291
292
			this.setLayoutManager(myGenLayoutManager);
293
294
			this.setFill(false);
295
			this.setOutline(false);
296
			createContents();
297
		}
298
299
		/**
300
		 * @generated
301
		 */
302
		private void createContents() {
303
			org.eclipse.draw2d.RectangleFigure fig_0 = new org.eclipse.draw2d.RectangleFigure();
304
305
			fig_0.setMinimumSize(new org.eclipse.draw2d.geometry.Dimension(getMapMode().DPtoLP(0), getMapMode().DPtoLP(25)));
306
307
			org.eclipse.uml2.diagram.common.draw2d.CenterLayout layouter0 = new org.eclipse.uml2.diagram.common.draw2d.CenterLayout();
308
309
			fig_0.setLayoutManager(layouter0);
310
311
			setFigureClassFigure_NameContainer(fig_0);
312
			org.eclipse.gmf.internal.codegen.draw2d.GridLayoutData layData0 = new org.eclipse.gmf.internal.codegen.draw2d.GridLayoutData();
313
			layData0.verticalAlignment = org.eclipse.gmf.internal.codegen.draw2d.GridLayoutData.FILL;
314
			layData0.horizontalAlignment = org.eclipse.gmf.internal.codegen.draw2d.GridLayoutData.FILL;
315
			layData0.horizontalIndent = 0;
316
			layData0.horizontalSpan = 2;
317
			layData0.verticalSpan = 1;
318
			layData0.grabExcessHorizontalSpace = true;
319
			layData0.grabExcessVerticalSpace = false;
320
321
			this.add(fig_0, layData0);
322
			org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel fig_1 = new org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel();
323
324
			setFigureClassFigure_name(fig_1);
325
326
			Object layData1 = null;
327
328
			fig_0.add(fig_1, layData1);
329
			org.eclipse.draw2d.RectangleFigure fig_2 = new org.eclipse.draw2d.RectangleFigure();
330
331
			org.eclipse.draw2d.ToolbarLayout layouter2 = new org.eclipse.draw2d.ToolbarLayout();
332
			layouter2.setStretchMinorAxis(true);
333
			layouter2.setMinorAlignment(org.eclipse.draw2d.ToolbarLayout.ALIGN_CENTER);
334
			layouter2.setSpacing(0);
335
			layouter2.setVertical(true);
336
337
			fig_2.setLayoutManager(layouter2);
338
339
			setFigureClassFigure_Body(fig_2);
340
			org.eclipse.gmf.internal.codegen.draw2d.GridLayoutData layData2 = new org.eclipse.gmf.internal.codegen.draw2d.GridLayoutData();
341
			layData2.verticalAlignment = org.eclipse.gmf.internal.codegen.draw2d.GridLayoutData.FILL;
342
			layData2.horizontalAlignment = org.eclipse.gmf.internal.codegen.draw2d.GridLayoutData.FILL;
343
			layData2.horizontalIndent = 0;
344
			layData2.horizontalSpan = 2;
345
			layData2.verticalSpan = 1;
346
			layData2.grabExcessHorizontalSpace = true;
347
			layData2.grabExcessVerticalSpace = true;
348
349
			this.add(fig_2, layData2);
350
			org.eclipse.draw2d.RectangleFigure fig_3 = new org.eclipse.draw2d.RectangleFigure();
351
352
			setFigureClassFigure_PropertiesCompartment(fig_3);
353
354
			Object layData3 = null;
355
356
			fig_2.add(fig_3, layData3);
357
			org.eclipse.draw2d.RectangleFigure fig_4 = new org.eclipse.draw2d.RectangleFigure();
358
359
			setFigureClassFigure_OperationsCompartment(fig_4);
360
361
			Object layData4 = null;
362
363
			fig_2.add(fig_4, layData4);
364
			org.eclipse.draw2d.RectangleFigure fig_5 = new org.eclipse.draw2d.RectangleFigure();
365
366
			setFigureClassFigure_ClassesCompartment(fig_5);
367
368
			Object layData5 = null;
369
370
			fig_2.add(fig_5, layData5);
371
			org.eclipse.draw2d.RectangleFigure fig_6 = new org.eclipse.draw2d.RectangleFigure();
372
373
			setFigureClassFigure_LiteralsCompartment(fig_6);
374
375
			Object layData6 = null;
376
377
			fig_2.add(fig_6, layData6);
378
			org.eclipse.draw2d.RectangleFigure fig_7 = new org.eclipse.draw2d.RectangleFigure();
379
380
			setFigureClassFigure_OthersCompartment(fig_7);
381
382
			Object layData7 = null;
383
384
			fig_2.add(fig_7, layData7);
385
		}
386
387
		/**
388
		 * @generated
389
		 */
390
		private org.eclipse.draw2d.RectangleFigure fClassFigure_NameContainer;
391
392
		/**
393
		 * @generated
394
		 */
395
		public org.eclipse.draw2d.RectangleFigure getFigureClassFigure_NameContainer() {
396
			return fClassFigure_NameContainer;
397
		}
398
399
		/**
400
		 * @generated
401
		 */
402
		private void setFigureClassFigure_NameContainer(org.eclipse.draw2d.RectangleFigure fig) {
403
			fClassFigure_NameContainer = fig;
404
		}
405
406
		/**
407
		 * @generated
408
		 */
409
		private org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel fClassFigure_name;
410
411
		/**
412
		 * @generated
413
		 */
414
		public org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel getFigureClassFigure_name() {
415
			return fClassFigure_name;
416
		}
417
418
		/**
419
		 * @generated
420
		 */
421
		private void setFigureClassFigure_name(org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel fig) {
422
			fClassFigure_name = fig;
423
		}
424
425
		/**
426
		 * @generated
427
		 */
428
		private org.eclipse.draw2d.RectangleFigure fClassFigure_Body;
429
430
		/**
431
		 * @generated
432
		 */
433
		public org.eclipse.draw2d.RectangleFigure getFigureClassFigure_Body() {
434
			return fClassFigure_Body;
435
		}
436
437
		/**
438
		 * @generated
439
		 */
440
		private void setFigureClassFigure_Body(org.eclipse.draw2d.RectangleFigure fig) {
441
			fClassFigure_Body = fig;
442
		}
443
444
		/**
445
		 * @generated
446
		 */
447
		private org.eclipse.draw2d.RectangleFigure fClassFigure_PropertiesCompartment;
448
449
		/**
450
		 * @generated
451
		 */
452
		public org.eclipse.draw2d.RectangleFigure getFigureClassFigure_PropertiesCompartment() {
453
			return fClassFigure_PropertiesCompartment;
454
		}
455
456
		/**
457
		 * @generated
458
		 */
459
		private void setFigureClassFigure_PropertiesCompartment(org.eclipse.draw2d.RectangleFigure fig) {
460
			fClassFigure_PropertiesCompartment = fig;
461
		}
462
463
		/**
464
		 * @generated
465
		 */
466
		private org.eclipse.draw2d.RectangleFigure fClassFigure_OperationsCompartment;
467
468
		/**
469
		 * @generated
470
		 */
471
		public org.eclipse.draw2d.RectangleFigure getFigureClassFigure_OperationsCompartment() {
472
			return fClassFigure_OperationsCompartment;
473
		}
474
475
		/**
476
		 * @generated
477
		 */
478
		private void setFigureClassFigure_OperationsCompartment(org.eclipse.draw2d.RectangleFigure fig) {
479
			fClassFigure_OperationsCompartment = fig;
480
		}
481
482
		/**
483
		 * @generated
484
		 */
485
		private org.eclipse.draw2d.RectangleFigure fClassFigure_ClassesCompartment;
486
487
		/**
488
		 * @generated
489
		 */
490
		public org.eclipse.draw2d.RectangleFigure getFigureClassFigure_ClassesCompartment() {
491
			return fClassFigure_ClassesCompartment;
492
		}
493
494
		/**
495
		 * @generated
496
		 */
497
		private void setFigureClassFigure_ClassesCompartment(org.eclipse.draw2d.RectangleFigure fig) {
498
			fClassFigure_ClassesCompartment = fig;
499
		}
500
501
		/**
502
		 * @generated
503
		 */
504
		private org.eclipse.draw2d.RectangleFigure fClassFigure_LiteralsCompartment;
505
506
		/**
507
		 * @generated
508
		 */
509
		public org.eclipse.draw2d.RectangleFigure getFigureClassFigure_LiteralsCompartment() {
510
			return fClassFigure_LiteralsCompartment;
511
		}
512
513
		/**
514
		 * @generated
515
		 */
516
		private void setFigureClassFigure_LiteralsCompartment(org.eclipse.draw2d.RectangleFigure fig) {
517
			fClassFigure_LiteralsCompartment = fig;
518
		}
519
520
		/**
521
		 * @generated
522
		 */
523
		private org.eclipse.draw2d.RectangleFigure fClassFigure_OthersCompartment;
524
525
		/**
526
		 * @generated
527
		 */
528
		public org.eclipse.draw2d.RectangleFigure getFigureClassFigure_OthersCompartment() {
529
			return fClassFigure_OthersCompartment;
530
		}
531
532
		/**
533
		 * @generated
534
		 */
535
		private void setFigureClassFigure_OthersCompartment(org.eclipse.draw2d.RectangleFigure fig) {
536
			fClassFigure_OthersCompartment = fig;
537
		}
538
539
		/**
540
		 * @generated
541
		 */
542
		private boolean myUseLocalCoordinates = false;
543
544
		/**
545
		 * @generated
546
		 */
547
		protected boolean useLocalCoordinates() {
548
			return myUseLocalCoordinates;
549
		}
550
551
		/**
552
		 * @generated
553
		 */
554
		protected void setUseLocalCoordinates(boolean useLocalCoordinates) {
555
			myUseLocalCoordinates = useLocalCoordinates;
556
		}
557
558
	}
559
560
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/parts/UMLEditPartFactory.java (+307 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.parts;
2
3
import org.eclipse.draw2d.FigureUtilities;
4
import org.eclipse.draw2d.IFigure;
5
import org.eclipse.draw2d.Label;
6
import org.eclipse.draw2d.geometry.Dimension;
7
import org.eclipse.draw2d.geometry.Rectangle;
8
import org.eclipse.gef.EditPart;
9
import org.eclipse.gef.EditPartFactory;
10
import org.eclipse.gef.tools.CellEditorLocator;
11
import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart;
12
import org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel;
13
import org.eclipse.gmf.runtime.notation.View;
14
import org.eclipse.jface.viewers.CellEditor;
15
import org.eclipse.swt.SWT;
16
import org.eclipse.swt.widgets.Text;
17
import org.eclipse.uml2.diagram.clazz.part.UMLVisualIDRegistry;
18
19
/**
20
 * @generated
21
 */
22
public class UMLEditPartFactory implements EditPartFactory {
23
24
	/**
25
	 * @generated
26
	 */
27
	public static final String EXTERNAL_NODE_LABELS_LAYER = "External Node Labels"; //$NON-NLS-1$
28
29
	/**
30
	 * @generated
31
	 */
32
	public EditPart createEditPart(EditPart context, Object model) {
33
		if (model instanceof View) {
34
			View view = (View) model;
35
			int viewVisualID = UMLVisualIDRegistry.getVisualID(view);
36
			switch (viewVisualID) {
37
			case Package2EditPart.VISUAL_ID:
38
				return new Package2EditPart(view);
39
			case PackageNameEditPart.VISUAL_ID:
40
				return new PackageNameEditPart(view);
41
			case Class2EditPart.VISUAL_ID:
42
				return new Class2EditPart(view);
43
			case ClassNameEditPart.VISUAL_ID:
44
				return new ClassNameEditPart(view);
45
			case AssociationClass2EditPart.VISUAL_ID:
46
				return new AssociationClass2EditPart(view);
47
			case AssociationClassNameEditPart.VISUAL_ID:
48
				return new AssociationClassNameEditPart(view);
49
			case DataType2EditPart.VISUAL_ID:
50
				return new DataType2EditPart(view);
51
			case DataTypeNameEditPart.VISUAL_ID:
52
				return new DataTypeNameEditPart(view);
53
			case PrimitiveType2EditPart.VISUAL_ID:
54
				return new PrimitiveType2EditPart(view);
55
			case PrimitiveTypeNameEditPart.VISUAL_ID:
56
				return new PrimitiveTypeNameEditPart(view);
57
			case Enumeration2EditPart.VISUAL_ID:
58
				return new Enumeration2EditPart(view);
59
			case EnumerationNameEditPart.VISUAL_ID:
60
				return new EnumerationNameEditPart(view);
61
			case InterfaceEditPart.VISUAL_ID:
62
				return new InterfaceEditPart(view);
63
			case InterfaceNameEditPart.VISUAL_ID:
64
				return new InterfaceNameEditPart(view);
65
			case ConstraintEditPart.VISUAL_ID:
66
				return new ConstraintEditPart(view);
67
			case ConstraintNameEditPart.VISUAL_ID:
68
				return new ConstraintNameEditPart(view);
69
			case InstanceSpecification2EditPart.VISUAL_ID:
70
				return new InstanceSpecification2EditPart(view);
71
			case InstanceSpecificationNameEditPart.VISUAL_ID:
72
				return new InstanceSpecificationNameEditPart(view);
73
			case DependencyEditPart.VISUAL_ID:
74
				return new DependencyEditPart(view);
75
			case DependencyNameEditPart.VISUAL_ID:
76
				return new DependencyNameEditPart(view);
77
			case Package3EditPart.VISUAL_ID:
78
				return new Package3EditPart(view);
79
			case ClassEditPart.VISUAL_ID:
80
				return new ClassEditPart(view);
81
			case DataTypeEditPart.VISUAL_ID:
82
				return new DataTypeEditPart(view);
83
			case PrimitiveTypeEditPart.VISUAL_ID:
84
				return new PrimitiveTypeEditPart(view);
85
			case EnumerationEditPart.VISUAL_ID:
86
				return new EnumerationEditPart(view);
87
			case AssociationClassEditPart.VISUAL_ID:
88
				return new AssociationClassEditPart(view);
89
			case InstanceSpecificationEditPart.VISUAL_ID:
90
				return new InstanceSpecificationEditPart(view);
91
			case PropertyEditPart.VISUAL_ID:
92
				return new PropertyEditPart(view);
93
			case OperationEditPart.VISUAL_ID:
94
				return new OperationEditPart(view);
95
			case Class3EditPart.VISUAL_ID:
96
				return new Class3EditPart(view);
97
			case PortEditPart.VISUAL_ID:
98
				return new PortEditPart(view);
99
			case PortNameEditPart.VISUAL_ID:
100
				return new PortNameEditPart(view);
101
			case Property2EditPart.VISUAL_ID:
102
				return new Property2EditPart(view);
103
			case Operation2EditPart.VISUAL_ID:
104
				return new Operation2EditPart(view);
105
			case Property3EditPart.VISUAL_ID:
106
				return new Property3EditPart(view);
107
			case Operation3EditPart.VISUAL_ID:
108
				return new Operation3EditPart(view);
109
			case Property4EditPart.VISUAL_ID:
110
				return new Property4EditPart(view);
111
			case Operation4EditPart.VISUAL_ID:
112
				return new Operation4EditPart(view);
113
			case EnumerationLiteralEditPart.VISUAL_ID:
114
				return new EnumerationLiteralEditPart(view);
115
			case Property5EditPart.VISUAL_ID:
116
				return new Property5EditPart(view);
117
			case Operation5EditPart.VISUAL_ID:
118
				return new Operation5EditPart(view);
119
			case LiteralStringEditPart.VISUAL_ID:
120
				return new LiteralStringEditPart(view);
121
			case SlotEditPart.VISUAL_ID:
122
				return new SlotEditPart(view);
123
			case PackagePackagesEditPart.VISUAL_ID:
124
				return new PackagePackagesEditPart(view);
125
			case PackageClassifiersEditPart.VISUAL_ID:
126
				return new PackageClassifiersEditPart(view);
127
			case PackageOtherEditPart.VISUAL_ID:
128
				return new PackageOtherEditPart(view);
129
			case ClassAttributesEditPart.VISUAL_ID:
130
				return new ClassAttributesEditPart(view);
131
			case ClassOperationsEditPart.VISUAL_ID:
132
				return new ClassOperationsEditPart(view);
133
			case ClassClassesEditPart.VISUAL_ID:
134
				return new ClassClassesEditPart(view);
135
			case AssociationClassAttributesEditPart.VISUAL_ID:
136
				return new AssociationClassAttributesEditPart(view);
137
			case AssociationClassOperationsEditPart.VISUAL_ID:
138
				return new AssociationClassOperationsEditPart(view);
139
			case AssociationClassClassesEditPart.VISUAL_ID:
140
				return new AssociationClassClassesEditPart(view);
141
			case DataTypeAttributesEditPart.VISUAL_ID:
142
				return new DataTypeAttributesEditPart(view);
143
			case DataTypeOperationsEditPart.VISUAL_ID:
144
				return new DataTypeOperationsEditPart(view);
145
			case PrimitiveTypeAttributesEditPart.VISUAL_ID:
146
				return new PrimitiveTypeAttributesEditPart(view);
147
			case PrimitiveTypeOperationsEditPart.VISUAL_ID:
148
				return new PrimitiveTypeOperationsEditPart(view);
149
			case EnumerationLiteralsEditPart.VISUAL_ID:
150
				return new EnumerationLiteralsEditPart(view);
151
			case EnumerationAttributesEditPart.VISUAL_ID:
152
				return new EnumerationAttributesEditPart(view);
153
			case EnumerationOperationsEditPart.VISUAL_ID:
154
				return new EnumerationOperationsEditPart(view);
155
			case ConstraintCompartmentEditPart.VISUAL_ID:
156
				return new ConstraintCompartmentEditPart(view);
157
			case InstanceSpecificationSlotsEditPart.VISUAL_ID:
158
				return new InstanceSpecificationSlotsEditPart(view);
159
			case PackageEditPart.VISUAL_ID:
160
				return new PackageEditPart(view);
161
			case GeneralizationEditPart.VISUAL_ID:
162
				return new GeneralizationEditPart(view);
163
			case Dependency2EditPart.VISUAL_ID:
164
				return new Dependency2EditPart(view);
165
			case DependencyName2EditPart.VISUAL_ID:
166
				return new DependencyName2EditPart(view);
167
			case Property6EditPart.VISUAL_ID:
168
				return new Property6EditPart(view);
169
			case PropertyNameEditPart.VISUAL_ID:
170
				return new PropertyNameEditPart(view);
171
			case ConstraintConstrainedElementEditPart.VISUAL_ID:
172
				return new ConstraintConstrainedElementEditPart(view);
173
			case AssociationEditPart.VISUAL_ID:
174
				return new AssociationEditPart(view);
175
			case AssociationNameEditPart.VISUAL_ID:
176
				return new AssociationNameEditPart(view);
177
			case AssociationName2EditPart.VISUAL_ID:
178
				return new AssociationName2EditPart(view);
179
			case AssociationName3EditPart.VISUAL_ID:
180
				return new AssociationName3EditPart(view);
181
			case AssociationName4EditPart.VISUAL_ID:
182
				return new AssociationName4EditPart(view);
183
			case AssociationName5EditPart.VISUAL_ID:
184
				return new AssociationName5EditPart(view);
185
			case AssociationName6EditPart.VISUAL_ID:
186
				return new AssociationName6EditPart(view);
187
			case AssociationName7EditPart.VISUAL_ID:
188
				return new AssociationName7EditPart(view);
189
			case DependencySupplierEditPart.VISUAL_ID:
190
				return new DependencySupplierEditPart(view);
191
			case DependencyClientEditPart.VISUAL_ID:
192
				return new DependencyClientEditPart(view);
193
			case InterfaceRealizationEditPart.VISUAL_ID:
194
				return new InterfaceRealizationEditPart(view);
195
			case UsageEditPart.VISUAL_ID:
196
				return new UsageEditPart(view);
197
			}
198
		}
199
		return createUnrecognizedEditPart(context, model);
200
	}
201
202
	/**
203
	 * @generated
204
	 */
205
	private EditPart createUnrecognizedEditPart(EditPart context, Object model) {
206
		// Handle creation of unrecognized child node EditParts here
207
		return null;
208
	}
209
210
	/**
211
	 * @generated
212
	 */
213
	public static CellEditorLocator getTextCellEditorLocator(ITextAwareEditPart source) {
214
		if (source.getFigure() instanceof WrapLabel)
215
			return new TextCellEditorLocator((WrapLabel) source.getFigure());
216
		else {
217
			IFigure figure = source.getFigure();
218
			return new LabelCellEditorLocator((Label) figure);
219
		}
220
	}
221
222
	/**
223
	 * @generated
224
	 */
225
	static private class TextCellEditorLocator implements CellEditorLocator {
226
227
		/**
228
		 * @generated
229
		 */
230
		private WrapLabel wrapLabel;
231
232
		/**
233
		 * @generated
234
		 */
235
		public TextCellEditorLocator(WrapLabel wrapLabel) {
236
			super();
237
			this.wrapLabel = wrapLabel;
238
		}
239
240
		/**
241
		 * @generated
242
		 */
243
		public WrapLabel getWrapLabel() {
244
			return wrapLabel;
245
		}
246
247
		/**
248
		 * @generated
249
		 */
250
		public void relocate(CellEditor celleditor) {
251
			Text text = (Text) celleditor.getControl();
252
			Rectangle rect = getWrapLabel().getTextBounds().getCopy();
253
			getWrapLabel().translateToAbsolute(rect);
254
255
			if (getWrapLabel().isTextWrapped() && getWrapLabel().getText().length() > 0)
256
				rect.setSize(new Dimension(text.computeSize(rect.width, SWT.DEFAULT)));
257
			else {
258
				int avr = FigureUtilities.getFontMetrics(text.getFont()).getAverageCharWidth();
259
				rect.setSize(new Dimension(text.computeSize(SWT.DEFAULT, SWT.DEFAULT)).expand(avr * 2, 0));
260
			}
261
262
			if (!rect.equals(new Rectangle(text.getBounds())))
263
				text.setBounds(rect.x, rect.y, rect.width, rect.height);
264
		}
265
266
	}
267
268
	/**
269
	 * @generated
270
	 */
271
	private static class LabelCellEditorLocator implements CellEditorLocator {
272
273
		/**
274
		 * @generated
275
		 */
276
		private Label label;
277
278
		/**
279
		 * @generated
280
		 */
281
		public LabelCellEditorLocator(Label label) {
282
			this.label = label;
283
		}
284
285
		/**
286
		 * @generated
287
		 */
288
		public Label getLabel() {
289
			return label;
290
		}
291
292
		/**
293
		 * @generated
294
		 */
295
		public void relocate(CellEditor celleditor) {
296
			Text text = (Text) celleditor.getControl();
297
			Rectangle rect = getLabel().getTextBounds().getCopy();
298
			getLabel().translateToAbsolute(rect);
299
300
			int avr = FigureUtilities.getFontMetrics(text.getFont()).getAverageCharWidth();
301
			rect.setSize(new Dimension(text.computeSize(SWT.DEFAULT, SWT.DEFAULT)).expand(avr * 2, 0));
302
303
			if (!rect.equals(new Rectangle(text.getBounds())))
304
				text.setBounds(rect.x, rect.y, rect.width, rect.height);
305
		}
306
	}
307
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/policies/ConstraintCompartmentItemSemanticEditPolicy.java (+78 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.policies;
2
3
import org.eclipse.emf.ecore.EClass;
4
import org.eclipse.emf.ecore.EObject;
5
import org.eclipse.gef.commands.Command;
6
import org.eclipse.gmf.runtime.emf.type.core.commands.CreateElementCommand;
7
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest;
8
import org.eclipse.gmf.runtime.notation.View;
9
import org.eclipse.uml2.diagram.clazz.providers.UMLElementTypes;
10
import org.eclipse.uml2.uml.Constraint;
11
import org.eclipse.uml2.uml.LiteralString;
12
import org.eclipse.uml2.uml.UMLPackage;
13
14
/**
15
 * @generated
16
 */
17
public class ConstraintCompartmentItemSemanticEditPolicy extends UMLBaseItemSemanticEditPolicy {
18
19
	/**
20
	 * @generated
21
	 */
22
	protected Command getCreateCommand(CreateElementRequest req) {
23
		if (UMLElementTypes.LiteralString_3005 == req.getElementType()) {
24
			Constraint container = (Constraint) (req.getContainer() instanceof View ? ((View) req.getContainer()).getElement() : req.getContainer());
25
			if (container.getSpecification() != null) {
26
				return super.getCreateCommand(req);
27
			}
28
			if (req.getContainmentFeature() == null) {
29
				req.setContainmentFeature(UMLPackage.eINSTANCE.getConstraint_Specification());
30
			}
31
			return getMSLWrapper(new CreateLiteralString_3005Command(req));
32
		}
33
		return super.getCreateCommand(req);
34
	}
35
36
	/**
37
	 * @generated
38
	 */
39
	private static class CreateLiteralString_3005Command extends CreateElementCommand {
40
41
		/**
42
		 * @generated
43
		 */
44
		public CreateLiteralString_3005Command(CreateElementRequest req) {
45
			super(req);
46
		}
47
48
		/**
49
		 * @generated
50
		 */
51
		protected EClass getEClassToEdit() {
52
			return UMLPackage.eINSTANCE.getConstraint();
53
		};
54
55
		/**
56
		 * @generated
57
		 */
58
		protected EObject getElementToEdit() {
59
			EObject container = ((CreateElementRequest) getRequest()).getContainer();
60
			if (container instanceof View) {
61
				container = ((View) container).getElement();
62
			}
63
			return container;
64
		}
65
66
		/**
67
		 * @generated
68
		 */
69
		protected EObject doDefaultElementCreation() {
70
			LiteralString newElement = (LiteralString) super.doDefaultElementCreation();
71
			if (newElement != null) {
72
				UMLElementTypes.Initializers.LiteralString_3005.init(newElement);
73
			}
74
			return newElement;
75
		}
76
	}
77
78
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/parts/DependencySupplierEditPart.java (+84 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.parts;
2
3
import org.eclipse.draw2d.Connection;
4
import org.eclipse.gef.EditPolicy;
5
import org.eclipse.gmf.runtime.diagram.ui.editparts.ConnectionNodeEditPart;
6
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
7
import org.eclipse.gmf.runtime.notation.View;
8
import org.eclipse.uml2.diagram.clazz.edit.policies.DependencySupplierItemSemanticEditPolicy;
9
import org.eclipse.uml2.diagram.clazz.edit.policies.UMLReferenceConnectionEditPolicy;
10
11
/**
12
 * @generated
13
 */
14
public class DependencySupplierEditPart extends ConnectionNodeEditPart {
15
16
	/**
17
	 * @generated
18
	 */
19
	public static final int VISUAL_ID = 4006;
20
21
	/**
22
	 * @generated
23
	 */
24
	public DependencySupplierEditPart(View view) {
25
		super(view);
26
	}
27
28
	/**
29
	 * @generated
30
	 */
31
	protected void createDefaultEditPolicies() {
32
		super.createDefaultEditPolicies();
33
		installEditPolicy(EditPolicy.CONNECTION_ROLE, new UMLReferenceConnectionEditPolicy());
34
		installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new DependencySupplierItemSemanticEditPolicy());
35
36
	}
37
38
	/**
39
	 * Creates figure for this edit part.
40
	 * 
41
	 * Body of this method does not depend on settings in generation model
42
	 * so you may safely remove <i>generated</i> tag and modify it.
43
	 * 
44
	 * @generated
45
	 */
46
	protected Connection createConnectionFigure() {
47
		return new Dependency_WithArrow_Polyline();
48
	}
49
50
	/**
51
	 * @generated
52
	 */
53
	public class Dependency_WithArrow_Polyline extends org.eclipse.gmf.runtime.draw2d.ui.figures.PolylineConnectionEx {
54
55
		/**
56
		 * @generated
57
		 */
58
		public Dependency_WithArrow_Polyline() {
59
60
			this.setLineStyle(org.eclipse.draw2d.Graphics.LINE_DASH);
61
			this.setForegroundColor(org.eclipse.draw2d.ColorConstants.lightGray);
62
			setTargetDecoration(createTargetDecoration());
63
		}
64
65
		/**
66
		 * @generated
67
		 */
68
		private org.eclipse.draw2d.PolylineDecoration createTargetDecoration() {
69
			org.eclipse.draw2d.PolylineDecoration df = new org.eclipse.draw2d.PolylineDecoration();
70
			// dispatchNext?
71
72
			org.eclipse.draw2d.geometry.PointList pl = new org.eclipse.draw2d.geometry.PointList();
73
			pl.addPoint(-1, 1);
74
			pl.addPoint(0, 0);
75
			pl.addPoint(-1, -1);
76
			df.setTemplate(pl);
77
			df.setScale(getMapMode().DPtoLP(7), getMapMode().DPtoLP(3));
78
79
			return df;
80
		}
81
82
	}
83
84
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/policies/InterfaceRealizationItemSemanticEditPolicy.java (+18 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.policies;
2
3
import org.eclipse.gef.commands.Command;
4
import org.eclipse.gmf.runtime.emf.type.core.commands.DestroyElementCommand;
5
import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest;
6
7
/**
8
 * @generated
9
 */
10
public class InterfaceRealizationItemSemanticEditPolicy extends UMLBaseItemSemanticEditPolicy {
11
12
	/**
13
	 * @generated
14
	 */
15
	protected Command getDestroyElementCommand(DestroyElementRequest req) {
16
		return getMSLWrapper(new DestroyElementCommand(req));
17
	}
18
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/parts/AssociationClass2EditPart.java (+560 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.parts;
2
3
import org.eclipse.draw2d.IFigure;
4
import org.eclipse.draw2d.StackLayout;
5
import org.eclipse.gef.EditPart;
6
import org.eclipse.gef.EditPolicy;
7
import org.eclipse.gef.Request;
8
import org.eclipse.gef.commands.Command;
9
import org.eclipse.gef.editpolicies.LayoutEditPolicy;
10
import org.eclipse.gef.editpolicies.NonResizableEditPolicy;
11
import org.eclipse.gef.requests.CreateRequest;
12
import org.eclipse.gmf.runtime.diagram.core.edithelpers.CreateElementRequestAdapter;
13
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
14
import org.eclipse.gmf.runtime.diagram.ui.editparts.ShapeNodeEditPart;
15
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.CreationEditPolicy;
16
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
17
import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewAndElementRequest;
18
import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout;
19
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
20
import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure;
21
import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure;
22
import org.eclipse.gmf.runtime.notation.View;
23
import org.eclipse.uml2.diagram.clazz.edit.policies.AssociationClass2ItemSemanticEditPolicy;
24
import org.eclipse.uml2.diagram.clazz.part.UMLVisualIDRegistry;
25
import org.eclipse.uml2.diagram.clazz.providers.UMLElementTypes;
26
27
/**
28
 * @generated
29
 */
30
public class AssociationClass2EditPart extends ShapeNodeEditPart {
31
32
	/**
33
	 * @generated
34
	 */
35
	public static final int VISUAL_ID = 2007;
36
37
	/**
38
	 * @generated
39
	 */
40
	protected IFigure contentPane;
41
42
	/**
43
	 * @generated
44
	 */
45
	protected IFigure primaryShape;
46
47
	/**
48
	 * @generated
49
	 */
50
	public AssociationClass2EditPart(View view) {
51
		super(view);
52
	}
53
54
	/**
55
	 * @generated
56
	 */
57
	protected void createDefaultEditPolicies() {
58
		installEditPolicy(EditPolicyRoles.CREATION_ROLE, new CreationEditPolicy() {
59
60
			public Command getCommand(Request request) {
61
				if (understandsRequest(request)) {
62
					if (request instanceof CreateViewAndElementRequest) {
63
						CreateElementRequestAdapter adapter = ((CreateViewAndElementRequest) request).getViewAndElementDescriptor().getCreateElementRequestAdapter();
64
						IElementType type = (IElementType) adapter.getAdapter(IElementType.class);
65
						if (type == UMLElementTypes.Property_3019) {
66
							EditPart compartmentEditPart = getChildBySemanticHint(UMLVisualIDRegistry.getType(AssociationClassAttributesEditPart.VISUAL_ID));
67
							return compartmentEditPart == null ? null : compartmentEditPart.getCommand(request);
68
						}
69
						if (type == UMLElementTypes.Operation_3020) {
70
							EditPart compartmentEditPart = getChildBySemanticHint(UMLVisualIDRegistry.getType(AssociationClassOperationsEditPart.VISUAL_ID));
71
							return compartmentEditPart == null ? null : compartmentEditPart.getCommand(request);
72
						}
73
						if (type == UMLElementTypes.Class_3003) {
74
							EditPart compartmentEditPart = getChildBySemanticHint(UMLVisualIDRegistry.getType(AssociationClassClassesEditPart.VISUAL_ID));
75
							return compartmentEditPart == null ? null : compartmentEditPart.getCommand(request);
76
						}
77
					}
78
					return super.getCommand(request);
79
				}
80
				return null;
81
			}
82
		});
83
		super.createDefaultEditPolicies();
84
		installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new AssociationClass2ItemSemanticEditPolicy());
85
		installEditPolicy(EditPolicy.LAYOUT_ROLE, createLayoutEditPolicy());
86
87
	}
88
89
	/**
90
	 * @generated
91
	 */
92
	protected LayoutEditPolicy createLayoutEditPolicy() {
93
		LayoutEditPolicy lep = new LayoutEditPolicy() {
94
95
			protected EditPolicy createChildEditPolicy(EditPart child) {
96
				EditPolicy result = child.getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
97
				if (result == null) {
98
					result = new NonResizableEditPolicy();
99
				}
100
				return result;
101
			}
102
103
			protected Command getMoveChildrenCommand(Request request) {
104
				return null;
105
			}
106
107
			protected Command getCreateCommand(CreateRequest request) {
108
				return null;
109
			}
110
		};
111
		return lep;
112
	}
113
114
	/**
115
	 * @generated
116
	 */
117
	protected IFigure createNodeShape() {
118
		ClassFigure figure = new ClassFigure();
119
		return primaryShape = figure;
120
	}
121
122
	/**
123
	 * @generated
124
	 */
125
	public ClassFigure getPrimaryShape() {
126
		return (ClassFigure) primaryShape;
127
	}
128
129
	/**
130
	 * @generated 
131
	 */
132
	protected IFigure getContentPaneFor(IGraphicalEditPart editPart) {
133
		if (editPart instanceof AssociationClassAttributesEditPart) {
134
			return getPrimaryShape().getFigureClassFigure_PropertiesCompartment();
135
		}
136
		if (editPart instanceof AssociationClassOperationsEditPart) {
137
			return getPrimaryShape().getFigureClassFigure_OperationsCompartment();
138
		}
139
		if (editPart instanceof AssociationClassClassesEditPart) {
140
			return getPrimaryShape().getFigureClassFigure_ClassesCompartment();
141
		}
142
143
		return super.getContentPaneFor(editPart);
144
	}
145
146
	/**
147
	 * @generated
148
	 */
149
	protected boolean addFixedChild(EditPart childEditPart) {
150
		if (childEditPart instanceof AssociationClassNameEditPart) {
151
			((AssociationClassNameEditPart) childEditPart).setLabel(getPrimaryShape().getFigureClassFigure_name());
152
			return true;
153
		}
154
		if (childEditPart instanceof AssociationClassAttributesEditPart) {
155
			IFigure pane = getPrimaryShape().getFigureClassFigure_PropertiesCompartment();
156
			setupContentPane(pane); // FIXME each comparment should handle his content pane in his own way 
157
			pane.add(((AssociationClassAttributesEditPart) childEditPart).getFigure());
158
			return true;
159
		}
160
		if (childEditPart instanceof AssociationClassOperationsEditPart) {
161
			IFigure pane = getPrimaryShape().getFigureClassFigure_OperationsCompartment();
162
			setupContentPane(pane); // FIXME each comparment should handle his content pane in his own way 
163
			pane.add(((AssociationClassOperationsEditPart) childEditPart).getFigure());
164
			return true;
165
		}
166
		if (childEditPart instanceof AssociationClassClassesEditPart) {
167
			IFigure pane = getPrimaryShape().getFigureClassFigure_ClassesCompartment();
168
			setupContentPane(pane); // FIXME each comparment should handle his content pane in his own way 
169
			pane.add(((AssociationClassClassesEditPart) childEditPart).getFigure());
170
			return true;
171
		}
172
		return false;
173
	}
174
175
	/**
176
	 * @generated
177
	 */
178
	protected boolean removeFixedChild(EditPart childEditPart) {
179
		if (childEditPart instanceof AssociationClassAttributesEditPart) {
180
			IFigure pane = getPrimaryShape().getFigureClassFigure_PropertiesCompartment();
181
			pane.remove(((AssociationClassAttributesEditPart) childEditPart).getFigure());
182
			return true;
183
		}
184
		if (childEditPart instanceof AssociationClassOperationsEditPart) {
185
			IFigure pane = getPrimaryShape().getFigureClassFigure_OperationsCompartment();
186
			pane.remove(((AssociationClassOperationsEditPart) childEditPart).getFigure());
187
			return true;
188
		}
189
		if (childEditPart instanceof AssociationClassClassesEditPart) {
190
			IFigure pane = getPrimaryShape().getFigureClassFigure_ClassesCompartment();
191
			pane.remove(((AssociationClassClassesEditPart) childEditPart).getFigure());
192
			return true;
193
		}
194
		return false;
195
	}
196
197
	/**
198
	 * @generated
199
	 */
200
	protected NodeFigure createNodePlate() {
201
		DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(getMapMode().DPtoLP(100), getMapMode().DPtoLP(60));
202
		return result;
203
	}
204
205
	/**
206
	 * Creates figure for this edit part.
207
	 * 
208
	 * Body of this method does not depend on settings in generation model
209
	 * so you may safely remove <i>generated</i> tag and modify it.
210
	 * 
211
	 * @generated
212
	 */
213
	protected NodeFigure createNodeFigure() {
214
		NodeFigure figure = createNodePlate();
215
		figure.setLayoutManager(new StackLayout());
216
		IFigure shape = createNodeShape();
217
		figure.add(shape);
218
		contentPane = setupContentPane(shape);
219
		return figure;
220
	}
221
222
	/**
223
	 * Default implementation treats passed figure as content pane.
224
	 * Respects layout one may have set for generated figure.
225
	 * @param nodeShape instance of generated figure class
226
	 * @generated
227
	 */
228
	protected IFigure setupContentPane(IFigure nodeShape) {
229
		if (nodeShape.getLayoutManager() == null) {
230
			ConstrainedToolbarLayout layout = new ConstrainedToolbarLayout();
231
			layout.setSpacing(getMapMode().DPtoLP(5));
232
			nodeShape.setLayoutManager(layout);
233
		}
234
		return nodeShape; // use nodeShape itself as contentPane
235
	}
236
237
	/**
238
	 * @generated
239
	 */
240
	public IFigure getContentPane() {
241
		if (contentPane != null) {
242
			return contentPane;
243
		}
244
		return super.getContentPane();
245
	}
246
247
	/**
248
	 * @generated
249
	 */
250
	public EditPart getPrimaryChildEditPart() {
251
		return getChildBySemanticHint(UMLVisualIDRegistry.getType(AssociationClassNameEditPart.VISUAL_ID));
252
	}
253
254
	/**
255
	 * @generated
256
	 */
257
	protected void addChildVisual(EditPart childEditPart, int index) {
258
		if (addFixedChild(childEditPart)) {
259
			return;
260
		}
261
		super.addChildVisual(childEditPart, -1);
262
	}
263
264
	/**
265
	 * @generated
266
	 */
267
	protected void removeChildVisual(EditPart childEditPart) {
268
		if (removeFixedChild(childEditPart)) {
269
			return;
270
		}
271
		super.removeChildVisual(childEditPart);
272
	}
273
274
	/**
275
	 * @generated
276
	 */
277
	public class ClassFigure extends org.eclipse.draw2d.RectangleFigure {
278
279
		/**
280
		 * @generated
281
		 */
282
		public ClassFigure() {
283
284
			org.eclipse.gmf.internal.codegen.draw2d.GridLayout myGenLayoutManager = new org.eclipse.gmf.internal.codegen.draw2d.GridLayout();
285
			myGenLayoutManager.numColumns = 1;
286
			myGenLayoutManager.makeColumnsEqualWidth = true;
287
			myGenLayoutManager.marginWidth = 0;
288
			myGenLayoutManager.marginHeight = 0;
289
			myGenLayoutManager.horizontalSpacing = 0;
290
			myGenLayoutManager.verticalSpacing = 0;
291
292
			this.setLayoutManager(myGenLayoutManager);
293
294
			this.setFill(false);
295
			this.setOutline(false);
296
			createContents();
297
		}
298
299
		/**
300
		 * @generated
301
		 */
302
		private void createContents() {
303
			org.eclipse.draw2d.RectangleFigure fig_0 = new org.eclipse.draw2d.RectangleFigure();
304
305
			fig_0.setMinimumSize(new org.eclipse.draw2d.geometry.Dimension(getMapMode().DPtoLP(0), getMapMode().DPtoLP(25)));
306
307
			org.eclipse.uml2.diagram.common.draw2d.CenterLayout layouter0 = new org.eclipse.uml2.diagram.common.draw2d.CenterLayout();
308
309
			fig_0.setLayoutManager(layouter0);
310
311
			setFigureClassFigure_NameContainer(fig_0);
312
			org.eclipse.gmf.internal.codegen.draw2d.GridLayoutData layData0 = new org.eclipse.gmf.internal.codegen.draw2d.GridLayoutData();
313
			layData0.verticalAlignment = org.eclipse.gmf.internal.codegen.draw2d.GridLayoutData.FILL;
314
			layData0.horizontalAlignment = org.eclipse.gmf.internal.codegen.draw2d.GridLayoutData.FILL;
315
			layData0.horizontalIndent = 0;
316
			layData0.horizontalSpan = 2;
317
			layData0.verticalSpan = 1;
318
			layData0.grabExcessHorizontalSpace = true;
319
			layData0.grabExcessVerticalSpace = false;
320
321
			this.add(fig_0, layData0);
322
			org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel fig_1 = new org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel();
323
324
			setFigureClassFigure_name(fig_1);
325
326
			Object layData1 = null;
327
328
			fig_0.add(fig_1, layData1);
329
			org.eclipse.draw2d.RectangleFigure fig_2 = new org.eclipse.draw2d.RectangleFigure();
330
331
			org.eclipse.draw2d.ToolbarLayout layouter2 = new org.eclipse.draw2d.ToolbarLayout();
332
			layouter2.setStretchMinorAxis(true);
333
			layouter2.setMinorAlignment(org.eclipse.draw2d.ToolbarLayout.ALIGN_CENTER);
334
			layouter2.setSpacing(0);
335
			layouter2.setVertical(true);
336
337
			fig_2.setLayoutManager(layouter2);
338
339
			setFigureClassFigure_Body(fig_2);
340
			org.eclipse.gmf.internal.codegen.draw2d.GridLayoutData layData2 = new org.eclipse.gmf.internal.codegen.draw2d.GridLayoutData();
341
			layData2.verticalAlignment = org.eclipse.gmf.internal.codegen.draw2d.GridLayoutData.FILL;
342
			layData2.horizontalAlignment = org.eclipse.gmf.internal.codegen.draw2d.GridLayoutData.FILL;
343
			layData2.horizontalIndent = 0;
344
			layData2.horizontalSpan = 2;
345
			layData2.verticalSpan = 1;
346
			layData2.grabExcessHorizontalSpace = true;
347
			layData2.grabExcessVerticalSpace = true;
348
349
			this.add(fig_2, layData2);
350
			org.eclipse.draw2d.RectangleFigure fig_3 = new org.eclipse.draw2d.RectangleFigure();
351
352
			setFigureClassFigure_PropertiesCompartment(fig_3);
353
354
			Object layData3 = null;
355
356
			fig_2.add(fig_3, layData3);
357
			org.eclipse.draw2d.RectangleFigure fig_4 = new org.eclipse.draw2d.RectangleFigure();
358
359
			setFigureClassFigure_OperationsCompartment(fig_4);
360
361
			Object layData4 = null;
362
363
			fig_2.add(fig_4, layData4);
364
			org.eclipse.draw2d.RectangleFigure fig_5 = new org.eclipse.draw2d.RectangleFigure();
365
366
			setFigureClassFigure_ClassesCompartment(fig_5);
367
368
			Object layData5 = null;
369
370
			fig_2.add(fig_5, layData5);
371
			org.eclipse.draw2d.RectangleFigure fig_6 = new org.eclipse.draw2d.RectangleFigure();
372
373
			setFigureClassFigure_LiteralsCompartment(fig_6);
374
375
			Object layData6 = null;
376
377
			fig_2.add(fig_6, layData6);
378
			org.eclipse.draw2d.RectangleFigure fig_7 = new org.eclipse.draw2d.RectangleFigure();
379
380
			setFigureClassFigure_OthersCompartment(fig_7);
381
382
			Object layData7 = null;
383
384
			fig_2.add(fig_7, layData7);
385
		}
386
387
		/**
388
		 * @generated
389
		 */
390
		private org.eclipse.draw2d.RectangleFigure fClassFigure_NameContainer;
391
392
		/**
393
		 * @generated
394
		 */
395
		public org.eclipse.draw2d.RectangleFigure getFigureClassFigure_NameContainer() {
396
			return fClassFigure_NameContainer;
397
		}
398
399
		/**
400
		 * @generated
401
		 */
402
		private void setFigureClassFigure_NameContainer(org.eclipse.draw2d.RectangleFigure fig) {
403
			fClassFigure_NameContainer = fig;
404
		}
405
406
		/**
407
		 * @generated
408
		 */
409
		private org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel fClassFigure_name;
410
411
		/**
412
		 * @generated
413
		 */
414
		public org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel getFigureClassFigure_name() {
415
			return fClassFigure_name;
416
		}
417
418
		/**
419
		 * @generated
420
		 */
421
		private void setFigureClassFigure_name(org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel fig) {
422
			fClassFigure_name = fig;
423
		}
424
425
		/**
426
		 * @generated
427
		 */
428
		private org.eclipse.draw2d.RectangleFigure fClassFigure_Body;
429
430
		/**
431
		 * @generated
432
		 */
433
		public org.eclipse.draw2d.RectangleFigure getFigureClassFigure_Body() {
434
			return fClassFigure_Body;
435
		}
436
437
		/**
438
		 * @generated
439
		 */
440
		private void setFigureClassFigure_Body(org.eclipse.draw2d.RectangleFigure fig) {
441
			fClassFigure_Body = fig;
442
		}
443
444
		/**
445
		 * @generated
446
		 */
447
		private org.eclipse.draw2d.RectangleFigure fClassFigure_PropertiesCompartment;
448
449
		/**
450
		 * @generated
451
		 */
452
		public org.eclipse.draw2d.RectangleFigure getFigureClassFigure_PropertiesCompartment() {
453
			return fClassFigure_PropertiesCompartment;
454
		}
455
456
		/**
457
		 * @generated
458
		 */
459
		private void setFigureClassFigure_PropertiesCompartment(org.eclipse.draw2d.RectangleFigure fig) {
460
			fClassFigure_PropertiesCompartment = fig;
461
		}
462
463
		/**
464
		 * @generated
465
		 */
466
		private org.eclipse.draw2d.RectangleFigure fClassFigure_OperationsCompartment;
467
468
		/**
469
		 * @generated
470
		 */
471
		public org.eclipse.draw2d.RectangleFigure getFigureClassFigure_OperationsCompartment() {
472
			return fClassFigure_OperationsCompartment;
473
		}
474
475
		/**
476
		 * @generated
477
		 */
478
		private void setFigureClassFigure_OperationsCompartment(org.eclipse.draw2d.RectangleFigure fig) {
479
			fClassFigure_OperationsCompartment = fig;
480
		}
481
482
		/**
483
		 * @generated
484
		 */
485
		private org.eclipse.draw2d.RectangleFigure fClassFigure_ClassesCompartment;
486
487
		/**
488
		 * @generated
489
		 */
490
		public org.eclipse.draw2d.RectangleFigure getFigureClassFigure_ClassesCompartment() {
491
			return fClassFigure_ClassesCompartment;
492
		}
493
494
		/**
495
		 * @generated
496
		 */
497
		private void setFigureClassFigure_ClassesCompartment(org.eclipse.draw2d.RectangleFigure fig) {
498
			fClassFigure_ClassesCompartment = fig;
499
		}
500
501
		/**
502
		 * @generated
503
		 */
504
		private org.eclipse.draw2d.RectangleFigure fClassFigure_LiteralsCompartment;
505
506
		/**
507
		 * @generated
508
		 */
509
		public org.eclipse.draw2d.RectangleFigure getFigureClassFigure_LiteralsCompartment() {
510
			return fClassFigure_LiteralsCompartment;
511
		}
512
513
		/**
514
		 * @generated
515
		 */
516
		private void setFigureClassFigure_LiteralsCompartment(org.eclipse.draw2d.RectangleFigure fig) {
517
			fClassFigure_LiteralsCompartment = fig;
518
		}
519
520
		/**
521
		 * @generated
522
		 */
523
		private org.eclipse.draw2d.RectangleFigure fClassFigure_OthersCompartment;
524
525
		/**
526
		 * @generated
527
		 */
528
		public org.eclipse.draw2d.RectangleFigure getFigureClassFigure_OthersCompartment() {
529
			return fClassFigure_OthersCompartment;
530
		}
531
532
		/**
533
		 * @generated
534
		 */
535
		private void setFigureClassFigure_OthersCompartment(org.eclipse.draw2d.RectangleFigure fig) {
536
			fClassFigure_OthersCompartment = fig;
537
		}
538
539
		/**
540
		 * @generated
541
		 */
542
		private boolean myUseLocalCoordinates = false;
543
544
		/**
545
		 * @generated
546
		 */
547
		protected boolean useLocalCoordinates() {
548
			return myUseLocalCoordinates;
549
		}
550
551
		/**
552
		 * @generated
553
		 */
554
		protected void setUseLocalCoordinates(boolean useLocalCoordinates) {
555
			myUseLocalCoordinates = useLocalCoordinates;
556
		}
557
558
	}
559
560
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/parts/AssociationName4EditPart.java (+533 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.parts;
2
3
import java.util.Collections;
4
import java.util.List;
5
6
import org.eclipse.draw2d.ConnectionLocator;
7
import org.eclipse.draw2d.IFigure;
8
import org.eclipse.draw2d.Label;
9
import org.eclipse.draw2d.geometry.Point;
10
import org.eclipse.emf.common.notify.Notification;
11
import org.eclipse.emf.ecore.EObject;
12
import org.eclipse.emf.transaction.RunnableWithResult;
13
import org.eclipse.gef.AccessibleEditPart;
14
import org.eclipse.gef.EditPolicy;
15
import org.eclipse.gef.Request;
16
import org.eclipse.gef.requests.DirectEditRequest;
17
import org.eclipse.gef.tools.DirectEditManager;
18
import org.eclipse.gmf.runtime.common.ui.services.parser.IParser;
19
import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus;
20
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserEditStatus;
21
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions;
22
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserService;
23
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
24
import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart;
25
import org.eclipse.gmf.runtime.diagram.ui.editparts.LabelEditPart;
26
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy;
27
import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry;
28
import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants;
29
import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager;
30
import org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel;
31
import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
32
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
33
import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser;
34
import org.eclipse.gmf.runtime.emf.ui.services.parser.ParserHintAdapter;
35
import org.eclipse.gmf.runtime.notation.FontStyle;
36
import org.eclipse.gmf.runtime.notation.NotationPackage;
37
import org.eclipse.gmf.runtime.notation.View;
38
import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
39
import org.eclipse.jface.viewers.ICellEditorValidator;
40
import org.eclipse.swt.SWT;
41
import org.eclipse.swt.accessibility.AccessibleEvent;
42
import org.eclipse.swt.graphics.Color;
43
import org.eclipse.swt.graphics.FontData;
44
import org.eclipse.swt.graphics.Image;
45
import org.eclipse.uml2.diagram.clazz.edit.policies.UMLTextSelectionEditPolicy;
46
import org.eclipse.uml2.diagram.clazz.part.UMLVisualIDRegistry;
47
import org.eclipse.uml2.diagram.clazz.providers.UMLElementTypes;
48
49
/**
50
 * @generated
51
 */
52
public class AssociationName4EditPart extends LabelEditPart implements ITextAwareEditPart {
53
54
	/**
55
	 * @generated
56
	 */
57
	public static final int VISUAL_ID = 6006;
58
59
	/**
60
	 * @generated
61
	 */
62
	private DirectEditManager manager;
63
64
	/**
65
	 * @generated
66
	 */
67
	private IParser parser;
68
69
	/**
70
	 * @generated
71
	 */
72
	private List parserElements;
73
74
	/**
75
	 * @generated
76
	 */
77
	private String defaultText;
78
79
	/**
80
	 * @generated
81
	 */
82
	static {
83
		registerSnapBackPosition(UMLVisualIDRegistry.getType(AssociationName4EditPart.VISUAL_ID), new Point(0, -30));
84
	}
85
86
	/**
87
	 * @generated
88
	 */
89
	public AssociationName4EditPart(View view) {
90
		super(view);
91
	}
92
93
	/**
94
	 * @generated
95
	 */
96
	protected void createDefaultEditPolicies() {
97
		super.createDefaultEditPolicies();
98
		installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy());
99
100
	}
101
102
	/**
103
	 * @generated
104
	 */
105
	public int getKeyPoint() {
106
		return ConnectionLocator.TARGET;
107
	}
108
109
	/**
110
	 * @generated
111
	 */
112
	protected String getLabelTextHelper(IFigure figure) {
113
		if (figure instanceof WrapLabel) {
114
			return ((WrapLabel) figure).getText();
115
		} else {
116
			return ((Label) figure).getText();
117
		}
118
	}
119
120
	/**
121
	 * @generated
122
	 */
123
	protected void setLabelTextHelper(IFigure figure, String text) {
124
		if (figure instanceof WrapLabel) {
125
			((WrapLabel) figure).setText(text);
126
		} else {
127
			((Label) figure).setText(text);
128
		}
129
	}
130
131
	/**
132
	 * @generated
133
	 */
134
	protected Image getLabelIconHelper(IFigure figure) {
135
		if (figure instanceof WrapLabel) {
136
			return ((WrapLabel) figure).getIcon();
137
		} else {
138
			return ((Label) figure).getIcon();
139
		}
140
	}
141
142
	/**
143
	 * @generated
144
	 */
145
	protected void setLabelIconHelper(IFigure figure, Image icon) {
146
		if (figure instanceof WrapLabel) {
147
			((WrapLabel) figure).setIcon(icon);
148
		} else {
149
			((Label) figure).setIcon(icon);
150
		}
151
	}
152
153
	/**
154
	 * @generated
155
	 */
156
	public void setLabel(IFigure figure) {
157
		unregisterVisuals();
158
		setFigure(figure);
159
		defaultText = getLabelTextHelper(figure);
160
		registerVisuals();
161
		refreshVisuals();
162
	}
163
164
	/**
165
	 * @generated
166
	 */
167
	protected List getModelChildren() {
168
		return Collections.EMPTY_LIST;
169
	}
170
171
	/**
172
	 * @generated
173
	 */
174
	public IGraphicalEditPart getChildBySemanticHint(String semanticHint) {
175
		return null;
176
	}
177
178
	/**
179
	 * @generated
180
	 */
181
	protected EObject getParserElement() {
182
		EObject element = resolveSemanticElement();
183
		return element != null ? element : (View) getModel();
184
	}
185
186
	/**
187
	 * @generated
188
	 */
189
	protected Image getLabelIcon() {
190
		return null;
191
	}
192
193
	/**
194
	 * @generated
195
	 */
196
	protected String getLabelText() {
197
		String text = null;
198
		if (getParser() != null) {
199
			text = getParser().getPrintString(new EObjectAdapter(getParserElement()), getParserOptions().intValue());
200
		}
201
		if (text == null || text.length() == 0) {
202
			text = defaultText;
203
		}
204
		return text;
205
	}
206
207
	/**
208
	 * @generated
209
	 */
210
	public void setLabelText(String text) {
211
		setLabelTextHelper(getFigure(), text);
212
		Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
213
		if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) {
214
			((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback();
215
		}
216
	}
217
218
	/**
219
	 * @generated
220
	 */
221
	public String getEditText() {
222
		if (getParser() == null) {
223
			return ""; //$NON-NLS-1$
224
		}
225
		return getParser().getEditString(new EObjectAdapter(getParserElement()), getParserOptions().intValue());
226
	}
227
228
	/**
229
	 * @generated
230
	 */
231
	protected boolean isEditable() {
232
		return getEditText() != null;
233
	}
234
235
	/**
236
	 * @generated
237
	 */
238
	public ICellEditorValidator getEditTextValidator() {
239
		return new ICellEditorValidator() {
240
241
			public String isValid(final Object value) {
242
				if (value instanceof String) {
243
					final EObject element = getParserElement();
244
					final IParser parser = getParser();
245
					try {
246
						IParserEditStatus valid = (IParserEditStatus) getEditingDomain().runExclusive(new RunnableWithResult.Impl() {
247
248
							public void run() {
249
								setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value));
250
							}
251
						});
252
						return valid.getCode() == ParserEditStatus.EDITABLE ? null : valid.getMessage();
253
					} catch (InterruptedException ie) {
254
						ie.printStackTrace();
255
					}
256
				}
257
258
				// shouldn't get here
259
				return null;
260
			}
261
		};
262
	}
263
264
	/**
265
	 * @generated
266
	 */
267
	public IContentAssistProcessor getCompletionProcessor() {
268
		if (getParser() == null) {
269
			return null;
270
		}
271
		return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement()));
272
	}
273
274
	/**
275
	 * @generated
276
	 */
277
	public ParserOptions getParserOptions() {
278
		return ParserOptions.NONE;
279
	}
280
281
	/**
282
	 * @generated
283
	 */
284
	public IParser getParser() {
285
		if (parser == null) {
286
			String parserHint = ((View) getModel()).getType();
287
			ParserHintAdapter hintAdapter = new ParserHintAdapter(getParserElement(), parserHint) {
288
289
				public Object getAdapter(Class adapter) {
290
					if (IElementType.class.equals(adapter)) {
291
						return UMLElementTypes.Association_4005;
292
					}
293
					return super.getAdapter(adapter);
294
				}
295
			};
296
			parser = ParserService.getInstance().getParser(hintAdapter);
297
		}
298
		return parser;
299
	}
300
301
	/**
302
	 * @generated
303
	 */
304
	protected DirectEditManager getManager() {
305
		if (manager == null) {
306
			setManager(new TextDirectEditManager(this, TextDirectEditManager.getTextCellEditorClass(this), UMLEditPartFactory.getTextCellEditorLocator(this)));
307
		}
308
		return manager;
309
	}
310
311
	/**
312
	 * @generated
313
	 */
314
	protected void setManager(DirectEditManager manager) {
315
		this.manager = manager;
316
	}
317
318
	/**
319
	 * @generated
320
	 */
321
	protected void performDirectEdit() {
322
		getManager().show();
323
	}
324
325
	/**
326
	 * @generated
327
	 */
328
	protected void performDirectEdit(Point eventLocation) {
329
		if (getManager().getClass() == TextDirectEditManager.class) {
330
			((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint());
331
		}
332
	}
333
334
	/**
335
	 * @generated
336
	 */
337
	private void performDirectEdit(char initialCharacter) {
338
		if (getManager() instanceof TextDirectEditManager) {
339
			((TextDirectEditManager) getManager()).show(initialCharacter);
340
		} else {
341
			performDirectEdit();
342
		}
343
	}
344
345
	/**
346
	 * @generated
347
	 */
348
	protected void performDirectEditRequest(Request request) {
349
		final Request theRequest = request;
350
		try {
351
			getEditingDomain().runExclusive(new Runnable() {
352
353
				public void run() {
354
					if (isActive() && isEditable()) {
355
						if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) {
356
							Character initialChar = (Character) theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR);
357
							performDirectEdit(initialChar.charValue());
358
						} else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) {
359
							DirectEditRequest editRequest = (DirectEditRequest) theRequest;
360
							performDirectEdit(editRequest.getLocation());
361
						} else {
362
							performDirectEdit();
363
						}
364
					}
365
				}
366
			});
367
		} catch (InterruptedException e) {
368
			e.printStackTrace();
369
		}
370
	}
371
372
	/**
373
	 * @generated
374
	 */
375
	protected void refreshVisuals() {
376
		super.refreshVisuals();
377
		refreshLabel();
378
		refreshFont();
379
		refreshFontColor();
380
		refreshUnderline();
381
		refreshStrikeThrough();
382
	}
383
384
	/**
385
	 * @generated
386
	 */
387
	protected void refreshLabel() {
388
		setLabelTextHelper(getFigure(), getLabelText());
389
		setLabelIconHelper(getFigure(), getLabelIcon());
390
		Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
391
		if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) {
392
			((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback();
393
		}
394
	}
395
396
	/**
397
	 * @generated
398
	 */
399
	protected void refreshUnderline() {
400
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
401
		if (style != null && getFigure() instanceof WrapLabel) {
402
			((WrapLabel) getFigure()).setTextUnderline(style.isUnderline());
403
		}
404
	}
405
406
	/**
407
	 * @generated
408
	 */
409
	protected void refreshStrikeThrough() {
410
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
411
		if (style != null && getFigure() instanceof WrapLabel) {
412
			((WrapLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough());
413
		}
414
	}
415
416
	/**
417
	 * @generated
418
	 */
419
	protected void refreshFont() {
420
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
421
		if (style != null) {
422
			FontData fontData = new FontData(style.getFontName(), style.getFontHeight(), (style.isBold() ? SWT.BOLD : SWT.NORMAL) | (style.isItalic() ? SWT.ITALIC : SWT.NORMAL));
423
			setFont(fontData);
424
		}
425
	}
426
427
	/**
428
	 * @generated
429
	 */
430
	protected void setFontColor(Color color) {
431
		getFigure().setForegroundColor(color);
432
	}
433
434
	/**
435
	 * @generated
436
	 */
437
	protected void addSemanticListeners() {
438
		if (getParser() instanceof ISemanticParser) {
439
			EObject element = resolveSemanticElement();
440
			parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element);
441
			for (int i = 0; i < parserElements.size(); i++) {
442
				addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$
443
			}
444
		} else {
445
			super.addSemanticListeners();
446
		}
447
	}
448
449
	/**
450
	 * @generated
451
	 */
452
	protected void removeSemanticListeners() {
453
		if (parserElements != null) {
454
			for (int i = 0; i < parserElements.size(); i++) {
455
				removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$
456
			}
457
		} else {
458
			super.removeSemanticListeners();
459
		}
460
	}
461
462
	/**
463
	 * @generated
464
	 */
465
	protected AccessibleEditPart getAccessibleEditPart() {
466
		if (accessibleEP == null) {
467
			accessibleEP = new AccessibleGraphicalEditPart() {
468
469
				public void getName(AccessibleEvent e) {
470
					e.result = getLabelTextHelper(getFigure());
471
				}
472
			};
473
		}
474
		return accessibleEP;
475
	}
476
477
	/**
478
	 * @generated
479
	 */
480
	private View getFontStyleOwnerView() {
481
		return getPrimaryView();
482
	}
483
484
	/**
485
	 * @generated
486
	 */
487
	protected void handleNotificationEvent(Notification event) {
488
		Object feature = event.getFeature();
489
		if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) {
490
			Integer c = (Integer) event.getNewValue();
491
			setFontColor(DiagramColorRegistry.getInstance().getColor(c));
492
		} else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) {
493
			refreshUnderline();
494
		} else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) {
495
			refreshStrikeThrough();
496
		} else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature)
497
				|| NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) {
498
			refreshFont();
499
		} else {
500
			if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) {
501
				refreshLabel();
502
			}
503
			if (getParser() instanceof ISemanticParser) {
504
				ISemanticParser modelParser = (ISemanticParser) getParser();
505
				if (modelParser.areSemanticElementsAffected(null, event)) {
506
					removeSemanticListeners();
507
					if (resolveSemanticElement() != null) {
508
						addSemanticListeners();
509
					}
510
					refreshLabel();
511
				}
512
			}
513
		}
514
		super.handleNotificationEvent(event);
515
	}
516
517
	/**
518
	 * @generated
519
	 */
520
	protected IFigure createFigure() {
521
		IFigure label = createFigurePrim();
522
		defaultText = getLabelTextHelper(label);
523
		return label;
524
	}
525
526
	/**
527
	 * @generated
528
	 */
529
	protected IFigure createFigurePrim() {
530
		return new WrapLabel();
531
	}
532
533
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/parts/AssociationClassEditPart.java (+553 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.parts;
2
3
import java.util.Collections;
4
import java.util.List;
5
6
import org.eclipse.draw2d.IFigure;
7
import org.eclipse.draw2d.Label;
8
import org.eclipse.draw2d.geometry.Point;
9
import org.eclipse.emf.common.notify.Notification;
10
import org.eclipse.emf.ecore.EObject;
11
import org.eclipse.emf.transaction.RunnableWithResult;
12
import org.eclipse.gef.AccessibleEditPart;
13
import org.eclipse.gef.DragTracker;
14
import org.eclipse.gef.EditPolicy;
15
import org.eclipse.gef.Request;
16
import org.eclipse.gef.requests.DirectEditRequest;
17
import org.eclipse.gef.requests.SelectionRequest;
18
import org.eclipse.gef.tools.DirectEditManager;
19
import org.eclipse.gmf.runtime.common.ui.services.parser.IParser;
20
import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus;
21
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserEditStatus;
22
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions;
23
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserService;
24
import org.eclipse.gmf.runtime.diagram.ui.editparts.CompartmentEditPart;
25
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
26
import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart;
27
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
28
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy;
29
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.ListItemComponentEditPolicy;
30
import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry;
31
import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants;
32
import org.eclipse.gmf.runtime.diagram.ui.tools.DragEditPartsTrackerEx;
33
import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager;
34
import org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel;
35
import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
36
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
37
import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser;
38
import org.eclipse.gmf.runtime.emf.ui.services.parser.ParserHintAdapter;
39
import org.eclipse.gmf.runtime.notation.FontStyle;
40
import org.eclipse.gmf.runtime.notation.NotationPackage;
41
import org.eclipse.gmf.runtime.notation.View;
42
import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
43
import org.eclipse.jface.viewers.ICellEditorValidator;
44
import org.eclipse.swt.SWT;
45
import org.eclipse.swt.accessibility.AccessibleEvent;
46
import org.eclipse.swt.graphics.Color;
47
import org.eclipse.swt.graphics.FontData;
48
import org.eclipse.swt.graphics.Image;
49
import org.eclipse.uml2.diagram.clazz.edit.policies.AssociationClassItemSemanticEditPolicy;
50
import org.eclipse.uml2.diagram.clazz.edit.policies.UMLTextNonResizableEditPolicy;
51
import org.eclipse.uml2.diagram.clazz.edit.policies.UMLTextSelectionEditPolicy;
52
import org.eclipse.uml2.diagram.clazz.providers.UMLElementTypes;
53
54
/**
55
 * @generated
56
 */
57
public class AssociationClassEditPart extends CompartmentEditPart implements ITextAwareEditPart {
58
59
	/**
60
	 * @generated
61
	 */
62
	public static final int VISUAL_ID = 3012;
63
64
	/**
65
	 * @generated
66
	 */
67
	private DirectEditManager manager;
68
69
	/**
70
	 * @generated
71
	 */
72
	private IParser parser;
73
74
	/**
75
	 * @generated
76
	 */
77
	private List parserElements;
78
79
	/**
80
	 * @generated
81
	 */
82
	private String defaultText;
83
84
	/**
85
	 * @generated
86
	 */
87
	public AssociationClassEditPart(View view) {
88
		super(view);
89
	}
90
91
	/**
92
	 * @generated
93
	 */
94
	public DragTracker getDragTracker(Request request) {
95
		if (request instanceof SelectionRequest && ((SelectionRequest) request).getLastButtonPressed() == 3) {
96
			return null;
97
		}
98
		return new DragEditPartsTrackerEx(this);
99
	}
100
101
	/**
102
	 * @generated
103
	 */
104
	protected void createDefaultEditPolicies() {
105
		super.createDefaultEditPolicies();
106
		installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new AssociationClassItemSemanticEditPolicy());
107
		installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new UMLTextNonResizableEditPolicy());
108
		installEditPolicy(EditPolicy.COMPONENT_ROLE, new ListItemComponentEditPolicy());
109
		installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy());
110
111
	}
112
113
	/**
114
	 * @generated
115
	 */
116
	protected String getLabelTextHelper(IFigure figure) {
117
		if (figure instanceof WrapLabel) {
118
			return ((WrapLabel) figure).getText();
119
		} else {
120
			return ((Label) figure).getText();
121
		}
122
	}
123
124
	/**
125
	 * @generated
126
	 */
127
	protected void setLabelTextHelper(IFigure figure, String text) {
128
		if (figure instanceof WrapLabel) {
129
			((WrapLabel) figure).setText(text);
130
		} else {
131
			((Label) figure).setText(text);
132
		}
133
	}
134
135
	/**
136
	 * @generated
137
	 */
138
	protected Image getLabelIconHelper(IFigure figure) {
139
		if (figure instanceof WrapLabel) {
140
			return ((WrapLabel) figure).getIcon();
141
		} else {
142
			return ((Label) figure).getIcon();
143
		}
144
	}
145
146
	/**
147
	 * @generated
148
	 */
149
	protected void setLabelIconHelper(IFigure figure, Image icon) {
150
		if (figure instanceof WrapLabel) {
151
			((WrapLabel) figure).setIcon(icon);
152
		} else {
153
			((Label) figure).setIcon(icon);
154
		}
155
	}
156
157
	/**
158
	 * @generated
159
	 */
160
	public void setLabel(IFigure figure) {
161
		unregisterVisuals();
162
		setFigure(figure);
163
		defaultText = getLabelTextHelper(figure);
164
		registerVisuals();
165
		refreshVisuals();
166
	}
167
168
	/**
169
	 * @generated
170
	 */
171
	protected List getModelChildren() {
172
		return Collections.EMPTY_LIST;
173
	}
174
175
	/**
176
	 * @generated
177
	 */
178
	public IGraphicalEditPart getChildBySemanticHint(String semanticHint) {
179
		return null;
180
	}
181
182
	/**
183
	 * @generated
184
	 */
185
	protected EObject getParserElement() {
186
		EObject element = resolveSemanticElement();
187
		return element != null ? element : (View) getModel();
188
	}
189
190
	/**
191
	 * @generated
192
	 */
193
	protected Image getLabelIcon() {
194
		return null;
195
	}
196
197
	/**
198
	 * @generated
199
	 */
200
	protected String getLabelText() {
201
		String text = null;
202
		if (getParser() != null) {
203
			text = getParser().getPrintString(new EObjectAdapter(getParserElement()), getParserOptions().intValue());
204
		}
205
		if (text == null || text.length() == 0) {
206
			text = defaultText;
207
		}
208
		return text;
209
	}
210
211
	/**
212
	 * @generated
213
	 */
214
	public void setLabelText(String text) {
215
		setLabelTextHelper(getFigure(), text);
216
		Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
217
		if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) {
218
			((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback();
219
		}
220
	}
221
222
	/**
223
	 * @generated
224
	 */
225
	public String getEditText() {
226
		if (getParser() == null) {
227
			return ""; //$NON-NLS-1$
228
		}
229
		return getParser().getEditString(new EObjectAdapter(getParserElement()), getParserOptions().intValue());
230
	}
231
232
	/**
233
	 * @generated
234
	 */
235
	protected boolean isEditable() {
236
		return getEditText() != null;
237
	}
238
239
	/**
240
	 * @generated
241
	 */
242
	public ICellEditorValidator getEditTextValidator() {
243
		return new ICellEditorValidator() {
244
245
			public String isValid(final Object value) {
246
				if (value instanceof String) {
247
					final EObject element = getParserElement();
248
					final IParser parser = getParser();
249
					try {
250
						IParserEditStatus valid = (IParserEditStatus) getEditingDomain().runExclusive(new RunnableWithResult.Impl() {
251
252
							public void run() {
253
								setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value));
254
							}
255
						});
256
						return valid.getCode() == ParserEditStatus.EDITABLE ? null : valid.getMessage();
257
					} catch (InterruptedException ie) {
258
						ie.printStackTrace();
259
					}
260
				}
261
262
				// shouldn't get here
263
				return null;
264
			}
265
		};
266
	}
267
268
	/**
269
	 * @generated
270
	 */
271
	public IContentAssistProcessor getCompletionProcessor() {
272
		if (getParser() == null) {
273
			return null;
274
		}
275
		return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement()));
276
	}
277
278
	/**
279
	 * @generated
280
	 */
281
	public ParserOptions getParserOptions() {
282
		return ParserOptions.NONE;
283
	}
284
285
	/**
286
	 * @generated
287
	 */
288
	public IParser getParser() {
289
		if (parser == null) {
290
			String parserHint = ((View) getModel()).getType();
291
			ParserHintAdapter hintAdapter = new ParserHintAdapter(getParserElement(), parserHint) {
292
293
				public Object getAdapter(Class adapter) {
294
					if (IElementType.class.equals(adapter)) {
295
						return UMLElementTypes.AssociationClass_3012;
296
					}
297
					return super.getAdapter(adapter);
298
				}
299
			};
300
			parser = ParserService.getInstance().getParser(hintAdapter);
301
		}
302
		return parser;
303
	}
304
305
	/**
306
	 * @generated
307
	 */
308
	protected DirectEditManager getManager() {
309
		if (manager == null) {
310
			setManager(new TextDirectEditManager(this, TextDirectEditManager.getTextCellEditorClass(this), UMLEditPartFactory.getTextCellEditorLocator(this)));
311
		}
312
		return manager;
313
	}
314
315
	/**
316
	 * @generated
317
	 */
318
	protected void setManager(DirectEditManager manager) {
319
		this.manager = manager;
320
	}
321
322
	/**
323
	 * @generated
324
	 */
325
	protected void performDirectEdit() {
326
		getManager().show();
327
	}
328
329
	/**
330
	 * @generated
331
	 */
332
	protected void performDirectEdit(Point eventLocation) {
333
		if (getManager().getClass() == TextDirectEditManager.class) {
334
			((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint());
335
		}
336
	}
337
338
	/**
339
	 * @generated
340
	 */
341
	private void performDirectEdit(char initialCharacter) {
342
		if (getManager() instanceof TextDirectEditManager) {
343
			((TextDirectEditManager) getManager()).show(initialCharacter);
344
		} else {
345
			performDirectEdit();
346
		}
347
	}
348
349
	/**
350
	 * @generated
351
	 */
352
	protected void performDirectEditRequest(Request request) {
353
		final Request theRequest = request;
354
		try {
355
			getEditingDomain().runExclusive(new Runnable() {
356
357
				public void run() {
358
					if (isActive() && isEditable()) {
359
						if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) {
360
							Character initialChar = (Character) theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR);
361
							performDirectEdit(initialChar.charValue());
362
						} else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) {
363
							DirectEditRequest editRequest = (DirectEditRequest) theRequest;
364
							performDirectEdit(editRequest.getLocation());
365
						} else {
366
							performDirectEdit();
367
						}
368
					}
369
				}
370
			});
371
		} catch (InterruptedException e) {
372
			e.printStackTrace();
373
		}
374
	}
375
376
	/**
377
	 * @generated
378
	 */
379
	protected void refreshVisuals() {
380
		super.refreshVisuals();
381
		refreshLabel();
382
		refreshFont();
383
		refreshFontColor();
384
		refreshUnderline();
385
		refreshStrikeThrough();
386
	}
387
388
	/**
389
	 * @generated
390
	 */
391
	protected void refreshLabel() {
392
		setLabelTextHelper(getFigure(), getLabelText());
393
		setLabelIconHelper(getFigure(), getLabelIcon());
394
		Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
395
		if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) {
396
			((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback();
397
		}
398
	}
399
400
	/**
401
	 * @generated
402
	 */
403
	protected void refreshUnderline() {
404
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
405
		if (style != null && getFigure() instanceof WrapLabel) {
406
			((WrapLabel) getFigure()).setTextUnderline(style.isUnderline());
407
		}
408
	}
409
410
	/**
411
	 * @generated
412
	 */
413
	protected void refreshStrikeThrough() {
414
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
415
		if (style != null && getFigure() instanceof WrapLabel) {
416
			((WrapLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough());
417
		}
418
	}
419
420
	/**
421
	 * @generated
422
	 */
423
	protected void refreshFont() {
424
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
425
		if (style != null) {
426
			FontData fontData = new FontData(style.getFontName(), style.getFontHeight(), (style.isBold() ? SWT.BOLD : SWT.NORMAL) | (style.isItalic() ? SWT.ITALIC : SWT.NORMAL));
427
			setFont(fontData);
428
		}
429
	}
430
431
	/**
432
	 * @generated
433
	 */
434
	protected void setFontColor(Color color) {
435
		getFigure().setForegroundColor(color);
436
	}
437
438
	/**
439
	 * @generated
440
	 */
441
	protected void addSemanticListeners() {
442
		if (getParser() instanceof ISemanticParser) {
443
			EObject element = resolveSemanticElement();
444
			parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element);
445
			for (int i = 0; i < parserElements.size(); i++) {
446
				addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$
447
			}
448
		} else {
449
			super.addSemanticListeners();
450
		}
451
	}
452
453
	/**
454
	 * @generated
455
	 */
456
	protected void removeSemanticListeners() {
457
		if (parserElements != null) {
458
			for (int i = 0; i < parserElements.size(); i++) {
459
				removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$
460
			}
461
		} else {
462
			super.removeSemanticListeners();
463
		}
464
	}
465
466
	/**
467
	 * @generated
468
	 */
469
	protected AccessibleEditPart getAccessibleEditPart() {
470
		if (accessibleEP == null) {
471
			accessibleEP = new AccessibleGraphicalEditPart() {
472
473
				public void getName(AccessibleEvent e) {
474
					e.result = getLabelTextHelper(getFigure());
475
				}
476
			};
477
		}
478
		return accessibleEP;
479
	}
480
481
	/**
482
	 * @generated
483
	 */
484
	private View getFontStyleOwnerView() {
485
		return getPrimaryView();
486
	}
487
488
	/**
489
	 * @generated
490
	 */
491
	protected void addNotationalListeners() {
492
		super.addNotationalListeners();
493
		addListenerFilter("PrimaryView", this, getPrimaryView()); //$NON-NLS-1$
494
	}
495
496
	/**
497
	 * @generated
498
	 */
499
	protected void removeNotationalListeners() {
500
		super.removeNotationalListeners();
501
		removeListenerFilter("PrimaryView"); //$NON-NLS-1$
502
	}
503
504
	/**
505
	 * @generated
506
	 */
507
	protected void handleNotificationEvent(Notification event) {
508
		Object feature = event.getFeature();
509
		if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) {
510
			Integer c = (Integer) event.getNewValue();
511
			setFontColor(DiagramColorRegistry.getInstance().getColor(c));
512
		} else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) {
513
			refreshUnderline();
514
		} else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) {
515
			refreshStrikeThrough();
516
		} else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature)
517
				|| NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) {
518
			refreshFont();
519
		} else {
520
			if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) {
521
				refreshLabel();
522
			}
523
			if (getParser() instanceof ISemanticParser) {
524
				ISemanticParser modelParser = (ISemanticParser) getParser();
525
				if (modelParser.areSemanticElementsAffected(null, event)) {
526
					removeSemanticListeners();
527
					if (resolveSemanticElement() != null) {
528
						addSemanticListeners();
529
					}
530
					refreshLabel();
531
				}
532
			}
533
		}
534
		super.handleNotificationEvent(event);
535
	}
536
537
	/**
538
	 * @generated
539
	 */
540
	protected IFigure createFigure() {
541
		IFigure label = createFigurePrim();
542
		defaultText = getLabelTextHelper(label);
543
		return label;
544
	}
545
546
	/**
547
	 * @generated
548
	 */
549
	protected IFigure createFigurePrim() {
550
		return new WrapLabel();
551
	}
552
553
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/policies/Class2CanonicalEditPolicy.java (+52 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.policies;
2
3
import java.util.Iterator;
4
import java.util.LinkedList;
5
import java.util.List;
6
7
import org.eclipse.emf.ecore.EObject;
8
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.CanonicalEditPolicy;
9
import org.eclipse.gmf.runtime.notation.View;
10
import org.eclipse.uml2.diagram.clazz.edit.parts.PortEditPart;
11
import org.eclipse.uml2.diagram.clazz.part.UMLVisualIDRegistry;
12
import org.eclipse.uml2.uml.StructuredClassifier;
13
14
/**
15
 * @generated
16
 */
17
public class Class2CanonicalEditPolicy extends CanonicalEditPolicy {
18
19
	/**
20
	 * @generated
21
	 */
22
	protected List getSemanticChildrenList() {
23
		List result = new LinkedList();
24
		EObject modelObject = ((View) getHost().getModel()).getElement();
25
		View viewObject = (View) getHost().getModel();
26
		EObject nextValue;
27
		int nodeVID;
28
		for (Iterator values = ((StructuredClassifier) modelObject).getOwnedAttributes().iterator(); values.hasNext();) {
29
			nextValue = (EObject) values.next();
30
			nodeVID = UMLVisualIDRegistry.getNodeVisualID(viewObject, nextValue);
31
			if (PortEditPart.VISUAL_ID == nodeVID) {
32
				result.add(nextValue);
33
			}
34
		}
35
		return result;
36
	}
37
38
	/**
39
	 * @generated
40
	 */
41
	protected boolean shouldDeleteView(View view) {
42
		return view.isSetElement() && view.getElement() != null && view.getElement().eIsProxy();
43
	}
44
45
	/**
46
	 * @generated
47
	 */
48
	protected String getDefaultFactoryHint() {
49
		return null;
50
	}
51
52
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/policies/EnumerationOperationsCanonicalEditPolicy.java (+52 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.policies;
2
3
import java.util.Iterator;
4
import java.util.LinkedList;
5
import java.util.List;
6
7
import org.eclipse.emf.ecore.EObject;
8
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.CanonicalEditPolicy;
9
import org.eclipse.gmf.runtime.notation.View;
10
import org.eclipse.uml2.diagram.clazz.edit.parts.Operation5EditPart;
11
import org.eclipse.uml2.diagram.clazz.part.UMLVisualIDRegistry;
12
import org.eclipse.uml2.uml.DataType;
13
14
/**
15
 * @generated
16
 */
17
public class EnumerationOperationsCanonicalEditPolicy extends CanonicalEditPolicy {
18
19
	/**
20
	 * @generated
21
	 */
22
	protected List getSemanticChildrenList() {
23
		List result = new LinkedList();
24
		EObject modelObject = ((View) getHost().getModel()).getElement();
25
		View viewObject = (View) getHost().getModel();
26
		EObject nextValue;
27
		int nodeVID;
28
		for (Iterator values = ((DataType) modelObject).getOwnedOperations().iterator(); values.hasNext();) {
29
			nextValue = (EObject) values.next();
30
			nodeVID = UMLVisualIDRegistry.getNodeVisualID(viewObject, nextValue);
31
			if (Operation5EditPart.VISUAL_ID == nodeVID) {
32
				result.add(nextValue);
33
			}
34
		}
35
		return result;
36
	}
37
38
	/**
39
	 * @generated
40
	 */
41
	protected boolean shouldDeleteView(View view) {
42
		return view.isSetElement() && view.getElement() != null && view.getElement().eIsProxy();
43
	}
44
45
	/**
46
	 * @generated
47
	 */
48
	protected String getDefaultFactoryHint() {
49
		return null;
50
	}
51
52
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/policies/AssociationClassClassesCanonicalEditPolicy.java (+51 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.policies;
2
3
import java.util.Iterator;
4
import java.util.LinkedList;
5
import java.util.List;
6
7
import org.eclipse.emf.ecore.EObject;
8
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.CanonicalEditPolicy;
9
import org.eclipse.gmf.runtime.notation.View;
10
import org.eclipse.uml2.diagram.clazz.edit.parts.Class3EditPart;
11
import org.eclipse.uml2.diagram.clazz.part.UMLVisualIDRegistry;
12
13
/**
14
 * @generated
15
 */
16
public class AssociationClassClassesCanonicalEditPolicy extends CanonicalEditPolicy {
17
18
	/**
19
	 * @generated
20
	 */
21
	protected List getSemanticChildrenList() {
22
		List result = new LinkedList();
23
		EObject modelObject = ((View) getHost().getModel()).getElement();
24
		View viewObject = (View) getHost().getModel();
25
		EObject nextValue;
26
		int nodeVID;
27
		for (Iterator values = ((org.eclipse.uml2.uml.Class) modelObject).getNestedClassifiers().iterator(); values.hasNext();) {
28
			nextValue = (EObject) values.next();
29
			nodeVID = UMLVisualIDRegistry.getNodeVisualID(viewObject, nextValue);
30
			if (Class3EditPart.VISUAL_ID == nodeVID) {
31
				result.add(nextValue);
32
			}
33
		}
34
		return result;
35
	}
36
37
	/**
38
	 * @generated
39
	 */
40
	protected boolean shouldDeleteView(View view) {
41
		return view.isSetElement() && view.getElement() != null && view.getElement().eIsProxy();
42
	}
43
44
	/**
45
	 * @generated
46
	 */
47
	protected String getDefaultFactoryHint() {
48
		return null;
49
	}
50
51
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/parts/Dependency2EditPart.java (+81 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.parts;
2
3
import org.eclipse.draw2d.Connection;
4
import org.eclipse.gmf.runtime.diagram.ui.editparts.ConnectionNodeEditPart;
5
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
6
import org.eclipse.gmf.runtime.notation.View;
7
import org.eclipse.uml2.diagram.clazz.edit.policies.Dependency2ItemSemanticEditPolicy;
8
9
/**
10
 * @generated
11
 */
12
public class Dependency2EditPart extends ConnectionNodeEditPart {
13
14
	/**
15
	 * @generated
16
	 */
17
	public static final int VISUAL_ID = 4002;
18
19
	/**
20
	 * @generated
21
	 */
22
	public Dependency2EditPart(View view) {
23
		super(view);
24
	}
25
26
	/**
27
	 * @generated
28
	 */
29
	protected void createDefaultEditPolicies() {
30
		super.createDefaultEditPolicies();
31
		installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new Dependency2ItemSemanticEditPolicy());
32
33
	}
34
35
	/**
36
	 * Creates figure for this edit part.
37
	 * 
38
	 * Body of this method does not depend on settings in generation model
39
	 * so you may safely remove <i>generated</i> tag and modify it.
40
	 * 
41
	 * @generated
42
	 */
43
	protected Connection createConnectionFigure() {
44
		return new Dependency_WithArrow_Polyline();
45
	}
46
47
	/**
48
	 * @generated
49
	 */
50
	public class Dependency_WithArrow_Polyline extends org.eclipse.gmf.runtime.draw2d.ui.figures.PolylineConnectionEx {
51
52
		/**
53
		 * @generated
54
		 */
55
		public Dependency_WithArrow_Polyline() {
56
57
			this.setLineStyle(org.eclipse.draw2d.Graphics.LINE_DASH);
58
			this.setForegroundColor(org.eclipse.draw2d.ColorConstants.lightGray);
59
			setTargetDecoration(createTargetDecoration());
60
		}
61
62
		/**
63
		 * @generated
64
		 */
65
		private org.eclipse.draw2d.PolylineDecoration createTargetDecoration() {
66
			org.eclipse.draw2d.PolylineDecoration df = new org.eclipse.draw2d.PolylineDecoration();
67
			// dispatchNext?
68
69
			org.eclipse.draw2d.geometry.PointList pl = new org.eclipse.draw2d.geometry.PointList();
70
			pl.addPoint(-1, 1);
71
			pl.addPoint(0, 0);
72
			pl.addPoint(-1, -1);
73
			df.setTemplate(pl);
74
			df.setScale(getMapMode().DPtoLP(7), getMapMode().DPtoLP(3));
75
76
			return df;
77
		}
78
79
	}
80
81
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/parts/InstanceSpecificationNameEditPart.java (+551 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.parts;
2
3
import java.util.ArrayList;
4
import java.util.Collections;
5
import java.util.List;
6
7
import org.eclipse.draw2d.IFigure;
8
import org.eclipse.draw2d.Label;
9
import org.eclipse.draw2d.geometry.Point;
10
import org.eclipse.emf.common.notify.Notification;
11
import org.eclipse.emf.ecore.EObject;
12
import org.eclipse.emf.transaction.RunnableWithResult;
13
import org.eclipse.gef.AccessibleEditPart;
14
import org.eclipse.gef.EditPolicy;
15
import org.eclipse.gef.GraphicalEditPart;
16
import org.eclipse.gef.Request;
17
import org.eclipse.gef.commands.Command;
18
import org.eclipse.gef.editpolicies.NonResizableEditPolicy;
19
import org.eclipse.gef.handles.NonResizableHandleKit;
20
import org.eclipse.gef.requests.DirectEditRequest;
21
import org.eclipse.gef.tools.DirectEditManager;
22
import org.eclipse.gmf.runtime.common.ui.services.parser.IParser;
23
import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus;
24
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserEditStatus;
25
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions;
26
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserService;
27
import org.eclipse.gmf.runtime.diagram.ui.editparts.CompartmentEditPart;
28
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
29
import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart;
30
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy;
31
import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry;
32
import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants;
33
import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager;
34
import org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel;
35
import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
36
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
37
import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser;
38
import org.eclipse.gmf.runtime.emf.ui.services.parser.ParserHintAdapter;
39
import org.eclipse.gmf.runtime.notation.FontStyle;
40
import org.eclipse.gmf.runtime.notation.NotationPackage;
41
import org.eclipse.gmf.runtime.notation.View;
42
import org.eclipse.jface.resource.ImageDescriptor;
43
import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
44
import org.eclipse.jface.viewers.ICellEditorValidator;
45
import org.eclipse.swt.SWT;
46
import org.eclipse.swt.accessibility.AccessibleEvent;
47
import org.eclipse.swt.graphics.Color;
48
import org.eclipse.swt.graphics.FontData;
49
import org.eclipse.swt.graphics.Image;
50
import org.eclipse.uml2.diagram.clazz.edit.policies.UMLTextSelectionEditPolicy;
51
import org.eclipse.uml2.diagram.clazz.part.UMLDiagramEditorPlugin;
52
import org.eclipse.uml2.diagram.clazz.providers.UMLElementTypes;
53
54
/**
55
 * @generated
56
 */
57
public class InstanceSpecificationNameEditPart extends CompartmentEditPart implements ITextAwareEditPart {
58
59
	/**
60
	 * @generated
61
	 */
62
	public static final int VISUAL_ID = 5010;
63
64
	/**
65
	 * @generated
66
	 */
67
	private DirectEditManager manager;
68
69
	/**
70
	 * @generated
71
	 */
72
	private IParser parser;
73
74
	/**
75
	 * @generated
76
	 */
77
	private List parserElements;
78
79
	/**
80
	 * @generated
81
	 */
82
	private String defaultText;
83
84
	/**
85
	 * @generated
86
	 */
87
	public InstanceSpecificationNameEditPart(View view) {
88
		super(view);
89
	}
90
91
	/**
92
	 * @generated
93
	 */
94
	protected void createDefaultEditPolicies() {
95
		super.createDefaultEditPolicies();
96
		installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy());
97
		installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new NonResizableEditPolicy() {
98
99
			protected List createSelectionHandles() {
100
				List handles = new ArrayList();
101
				NonResizableHandleKit.addMoveHandle((GraphicalEditPart) getHost(), handles);
102
				return handles;
103
			}
104
105
			public Command getCommand(Request request) {
106
				return null;
107
			}
108
109
			public boolean understandsRequest(Request request) {
110
				return false;
111
			}
112
		});
113
114
	}
115
116
	/**
117
	 * @generated
118
	 */
119
	protected String getLabelTextHelper(IFigure figure) {
120
		if (figure instanceof WrapLabel) {
121
			return ((WrapLabel) figure).getText();
122
		} else {
123
			return ((Label) figure).getText();
124
		}
125
	}
126
127
	/**
128
	 * @generated
129
	 */
130
	protected void setLabelTextHelper(IFigure figure, String text) {
131
		if (figure instanceof WrapLabel) {
132
			((WrapLabel) figure).setText(text);
133
		} else {
134
			((Label) figure).setText(text);
135
		}
136
	}
137
138
	/**
139
	 * @generated
140
	 */
141
	protected Image getLabelIconHelper(IFigure figure) {
142
		if (figure instanceof WrapLabel) {
143
			return ((WrapLabel) figure).getIcon();
144
		} else {
145
			return ((Label) figure).getIcon();
146
		}
147
	}
148
149
	/**
150
	 * @generated
151
	 */
152
	protected void setLabelIconHelper(IFigure figure, Image icon) {
153
		if (figure instanceof WrapLabel) {
154
			((WrapLabel) figure).setIcon(icon);
155
		} else {
156
			((Label) figure).setIcon(icon);
157
		}
158
	}
159
160
	/**
161
	 * @generated
162
	 */
163
	public void setLabel(WrapLabel figure) {
164
		unregisterVisuals();
165
		setFigure(figure);
166
		defaultText = getLabelTextHelper(figure);
167
		registerVisuals();
168
		refreshVisuals();
169
	}
170
171
	/**
172
	 * @generated
173
	 */
174
	protected List getModelChildren() {
175
		return Collections.EMPTY_LIST;
176
	}
177
178
	/**
179
	 * @generated
180
	 */
181
	public IGraphicalEditPart getChildBySemanticHint(String semanticHint) {
182
		return null;
183
	}
184
185
	/**
186
	 * @generated
187
	 */
188
	protected EObject getParserElement() {
189
		EObject element = resolveSemanticElement();
190
		return element != null ? element : (View) getModel();
191
	}
192
193
	/**
194
	 * @generated
195
	 */
196
	protected Image getLabelIcon() {
197
		EObject parserElement = getParserElement();
198
		if (parserElement == null) {
199
			return null;
200
		}
201
		return UMLElementTypes.getImage(parserElement.eClass());
202
	}
203
204
	/**
205
	 * @generated
206
	 */
207
	protected String getLabelText() {
208
		String text = null;
209
		if (getParser() != null) {
210
			text = getParser().getPrintString(new EObjectAdapter(getParserElement()), getParserOptions().intValue());
211
		}
212
		if (text == null || text.length() == 0) {
213
			text = defaultText;
214
		}
215
		return text;
216
	}
217
218
	/**
219
	 * @generated
220
	 */
221
	public void setLabelText(String text) {
222
		setLabelTextHelper(getFigure(), text);
223
		Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
224
		if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) {
225
			((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback();
226
		}
227
	}
228
229
	/**
230
	 * @generated
231
	 */
232
	public String getEditText() {
233
		if (getParser() == null) {
234
			return ""; //$NON-NLS-1$
235
		}
236
		return getParser().getEditString(new EObjectAdapter(getParserElement()), getParserOptions().intValue());
237
	}
238
239
	/**
240
	 * @generated
241
	 */
242
	protected boolean isEditable() {
243
		return getEditText() != null;
244
	}
245
246
	/**
247
	 * @generated
248
	 */
249
	public ICellEditorValidator getEditTextValidator() {
250
		return new ICellEditorValidator() {
251
252
			public String isValid(final Object value) {
253
				if (value instanceof String) {
254
					final EObject element = getParserElement();
255
					final IParser parser = getParser();
256
					try {
257
						IParserEditStatus valid = (IParserEditStatus) getEditingDomain().runExclusive(new RunnableWithResult.Impl() {
258
259
							public void run() {
260
								setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value));
261
							}
262
						});
263
						return valid.getCode() == ParserEditStatus.EDITABLE ? null : valid.getMessage();
264
					} catch (InterruptedException ie) {
265
						ie.printStackTrace();
266
					}
267
				}
268
269
				// shouldn't get here
270
				return null;
271
			}
272
		};
273
	}
274
275
	/**
276
	 * @generated
277
	 */
278
	public IContentAssistProcessor getCompletionProcessor() {
279
		if (getParser() == null) {
280
			return null;
281
		}
282
		return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement()));
283
	}
284
285
	/**
286
	 * @generated
287
	 */
288
	public ParserOptions getParserOptions() {
289
		return ParserOptions.NONE;
290
	}
291
292
	/**
293
	 * @generated
294
	 */
295
	public IParser getParser() {
296
		if (parser == null) {
297
			String parserHint = ((View) getModel()).getType();
298
			ParserHintAdapter hintAdapter = new ParserHintAdapter(getParserElement(), parserHint) {
299
300
				public Object getAdapter(Class adapter) {
301
					if (IElementType.class.equals(adapter)) {
302
						return UMLElementTypes.InstanceSpecification_2008;
303
					}
304
					return super.getAdapter(adapter);
305
				}
306
			};
307
			parser = ParserService.getInstance().getParser(hintAdapter);
308
		}
309
		return parser;
310
	}
311
312
	/**
313
	 * @generated
314
	 */
315
	protected DirectEditManager getManager() {
316
		if (manager == null) {
317
			setManager(new TextDirectEditManager(this, TextDirectEditManager.getTextCellEditorClass(this), UMLEditPartFactory.getTextCellEditorLocator(this)));
318
		}
319
		return manager;
320
	}
321
322
	/**
323
	 * @generated
324
	 */
325
	protected void setManager(DirectEditManager manager) {
326
		this.manager = manager;
327
	}
328
329
	/**
330
	 * @generated
331
	 */
332
	protected void performDirectEdit() {
333
		getManager().show();
334
	}
335
336
	/**
337
	 * @generated
338
	 */
339
	protected void performDirectEdit(Point eventLocation) {
340
		if (getManager().getClass() == TextDirectEditManager.class) {
341
			((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint());
342
		}
343
	}
344
345
	/**
346
	 * @generated
347
	 */
348
	private void performDirectEdit(char initialCharacter) {
349
		if (getManager() instanceof TextDirectEditManager) {
350
			((TextDirectEditManager) getManager()).show(initialCharacter);
351
		} else {
352
			performDirectEdit();
353
		}
354
	}
355
356
	/**
357
	 * @generated
358
	 */
359
	protected void performDirectEditRequest(Request request) {
360
		final Request theRequest = request;
361
		try {
362
			getEditingDomain().runExclusive(new Runnable() {
363
364
				public void run() {
365
					if (isActive() && isEditable()) {
366
						if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) {
367
							Character initialChar = (Character) theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR);
368
							performDirectEdit(initialChar.charValue());
369
						} else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) {
370
							DirectEditRequest editRequest = (DirectEditRequest) theRequest;
371
							performDirectEdit(editRequest.getLocation());
372
						} else {
373
							performDirectEdit();
374
						}
375
					}
376
				}
377
			});
378
		} catch (InterruptedException e) {
379
			e.printStackTrace();
380
		}
381
	}
382
383
	/**
384
	 * @generated
385
	 */
386
	protected void refreshVisuals() {
387
		super.refreshVisuals();
388
		refreshLabel();
389
		refreshFont();
390
		refreshFontColor();
391
		refreshUnderline();
392
		refreshStrikeThrough();
393
	}
394
395
	/**
396
	 * @generated
397
	 */
398
	protected void refreshLabel() {
399
		setLabelTextHelper(getFigure(), getLabelText());
400
		setLabelIconHelper(getFigure(), getLabelIcon());
401
		Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
402
		if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) {
403
			((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback();
404
		}
405
	}
406
407
	/**
408
	 * @generated
409
	 */
410
	protected void refreshUnderline() {
411
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
412
		if (style != null && getFigure() instanceof WrapLabel) {
413
			((WrapLabel) getFigure()).setTextUnderline(style.isUnderline());
414
		}
415
	}
416
417
	/**
418
	 * @generated
419
	 */
420
	protected void refreshStrikeThrough() {
421
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
422
		if (style != null && getFigure() instanceof WrapLabel) {
423
			((WrapLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough());
424
		}
425
	}
426
427
	/**
428
	 * @generated
429
	 */
430
	protected void refreshFont() {
431
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
432
		if (style != null) {
433
			FontData fontData = new FontData(style.getFontName(), style.getFontHeight(), (style.isBold() ? SWT.BOLD : SWT.NORMAL) | (style.isItalic() ? SWT.ITALIC : SWT.NORMAL));
434
			setFont(fontData);
435
		}
436
	}
437
438
	/**
439
	 * @generated
440
	 */
441
	protected void setFontColor(Color color) {
442
		getFigure().setForegroundColor(color);
443
	}
444
445
	/**
446
	 * @generated
447
	 */
448
	protected void addSemanticListeners() {
449
		if (getParser() instanceof ISemanticParser) {
450
			EObject element = resolveSemanticElement();
451
			parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element);
452
			for (int i = 0; i < parserElements.size(); i++) {
453
				addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$
454
			}
455
		} else {
456
			super.addSemanticListeners();
457
		}
458
	}
459
460
	/**
461
	 * @generated
462
	 */
463
	protected void removeSemanticListeners() {
464
		if (parserElements != null) {
465
			for (int i = 0; i < parserElements.size(); i++) {
466
				removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$
467
			}
468
		} else {
469
			super.removeSemanticListeners();
470
		}
471
	}
472
473
	/**
474
	 * @generated
475
	 */
476
	protected AccessibleEditPart getAccessibleEditPart() {
477
		if (accessibleEP == null) {
478
			accessibleEP = new AccessibleGraphicalEditPart() {
479
480
				public void getName(AccessibleEvent e) {
481
					e.result = getLabelTextHelper(getFigure());
482
				}
483
			};
484
		}
485
		return accessibleEP;
486
	}
487
488
	/**
489
	 * @generated
490
	 */
491
	private View getFontStyleOwnerView() {
492
		return getPrimaryView();
493
	}
494
495
	/**
496
	 * @generated
497
	 */
498
	protected void addNotationalListeners() {
499
		super.addNotationalListeners();
500
		addListenerFilter("PrimaryView", this, getPrimaryView()); //$NON-NLS-1$
501
	}
502
503
	/**
504
	 * @generated
505
	 */
506
	protected void removeNotationalListeners() {
507
		super.removeNotationalListeners();
508
		removeListenerFilter("PrimaryView"); //$NON-NLS-1$
509
	}
510
511
	/**
512
	 * @generated
513
	 */
514
	protected void handleNotificationEvent(Notification event) {
515
		Object feature = event.getFeature();
516
		if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) {
517
			Integer c = (Integer) event.getNewValue();
518
			setFontColor(DiagramColorRegistry.getInstance().getColor(c));
519
		} else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) {
520
			refreshUnderline();
521
		} else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) {
522
			refreshStrikeThrough();
523
		} else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature)
524
				|| NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) {
525
			refreshFont();
526
		} else {
527
			if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) {
528
				refreshLabel();
529
			}
530
			if (getParser() instanceof ISemanticParser) {
531
				ISemanticParser modelParser = (ISemanticParser) getParser();
532
				if (modelParser.areSemanticElementsAffected(null, event)) {
533
					removeSemanticListeners();
534
					if (resolveSemanticElement() != null) {
535
						addSemanticListeners();
536
					}
537
					refreshLabel();
538
				}
539
			}
540
		}
541
		super.handleNotificationEvent(event);
542
	}
543
544
	/**
545
	 * @generated
546
	 */
547
	protected IFigure createFigure() {
548
		// Parent should assign one using setLabel method
549
		return null;
550
	}
551
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/parts/DataType2EditPart.java (+542 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.parts;
2
3
import org.eclipse.draw2d.IFigure;
4
import org.eclipse.draw2d.StackLayout;
5
import org.eclipse.gef.EditPart;
6
import org.eclipse.gef.EditPolicy;
7
import org.eclipse.gef.Request;
8
import org.eclipse.gef.commands.Command;
9
import org.eclipse.gef.editpolicies.LayoutEditPolicy;
10
import org.eclipse.gef.editpolicies.NonResizableEditPolicy;
11
import org.eclipse.gef.requests.CreateRequest;
12
import org.eclipse.gmf.runtime.diagram.core.edithelpers.CreateElementRequestAdapter;
13
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
14
import org.eclipse.gmf.runtime.diagram.ui.editparts.ShapeNodeEditPart;
15
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.CreationEditPolicy;
16
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
17
import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewAndElementRequest;
18
import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout;
19
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
20
import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure;
21
import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure;
22
import org.eclipse.gmf.runtime.notation.View;
23
import org.eclipse.uml2.diagram.clazz.edit.policies.DataType2ItemSemanticEditPolicy;
24
import org.eclipse.uml2.diagram.clazz.part.UMLVisualIDRegistry;
25
import org.eclipse.uml2.diagram.clazz.providers.UMLElementTypes;
26
27
/**
28
 * @generated
29
 */
30
public class DataType2EditPart extends ShapeNodeEditPart {
31
32
	/**
33
	 * @generated
34
	 */
35
	public static final int VISUAL_ID = 2004;
36
37
	/**
38
	 * @generated
39
	 */
40
	protected IFigure contentPane;
41
42
	/**
43
	 * @generated
44
	 */
45
	protected IFigure primaryShape;
46
47
	/**
48
	 * @generated
49
	 */
50
	public DataType2EditPart(View view) {
51
		super(view);
52
	}
53
54
	/**
55
	 * @generated
56
	 */
57
	protected void createDefaultEditPolicies() {
58
		installEditPolicy(EditPolicyRoles.CREATION_ROLE, new CreationEditPolicy() {
59
60
			public Command getCommand(Request request) {
61
				if (understandsRequest(request)) {
62
					if (request instanceof CreateViewAndElementRequest) {
63
						CreateElementRequestAdapter adapter = ((CreateViewAndElementRequest) request).getViewAndElementDescriptor().getCreateElementRequestAdapter();
64
						IElementType type = (IElementType) adapter.getAdapter(IElementType.class);
65
						if (type == UMLElementTypes.Property_3014) {
66
							EditPart compartmentEditPart = getChildBySemanticHint(UMLVisualIDRegistry.getType(DataTypeAttributesEditPart.VISUAL_ID));
67
							return compartmentEditPart == null ? null : compartmentEditPart.getCommand(request);
68
						}
69
						if (type == UMLElementTypes.Operation_3015) {
70
							EditPart compartmentEditPart = getChildBySemanticHint(UMLVisualIDRegistry.getType(DataTypeOperationsEditPart.VISUAL_ID));
71
							return compartmentEditPart == null ? null : compartmentEditPart.getCommand(request);
72
						}
73
					}
74
					return super.getCommand(request);
75
				}
76
				return null;
77
			}
78
		});
79
		super.createDefaultEditPolicies();
80
		installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new DataType2ItemSemanticEditPolicy());
81
		installEditPolicy(EditPolicy.LAYOUT_ROLE, createLayoutEditPolicy());
82
83
	}
84
85
	/**
86
	 * @generated
87
	 */
88
	protected LayoutEditPolicy createLayoutEditPolicy() {
89
		LayoutEditPolicy lep = new LayoutEditPolicy() {
90
91
			protected EditPolicy createChildEditPolicy(EditPart child) {
92
				EditPolicy result = child.getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
93
				if (result == null) {
94
					result = new NonResizableEditPolicy();
95
				}
96
				return result;
97
			}
98
99
			protected Command getMoveChildrenCommand(Request request) {
100
				return null;
101
			}
102
103
			protected Command getCreateCommand(CreateRequest request) {
104
				return null;
105
			}
106
		};
107
		return lep;
108
	}
109
110
	/**
111
	 * @generated
112
	 */
113
	protected IFigure createNodeShape() {
114
		ClassFigure figure = new ClassFigure();
115
		return primaryShape = figure;
116
	}
117
118
	/**
119
	 * @generated
120
	 */
121
	public ClassFigure getPrimaryShape() {
122
		return (ClassFigure) primaryShape;
123
	}
124
125
	/**
126
	 * @generated 
127
	 */
128
	protected IFigure getContentPaneFor(IGraphicalEditPart editPart) {
129
		if (editPart instanceof DataTypeAttributesEditPart) {
130
			return getPrimaryShape().getFigureClassFigure_PropertiesCompartment();
131
		}
132
		if (editPart instanceof DataTypeOperationsEditPart) {
133
			return getPrimaryShape().getFigureClassFigure_OperationsCompartment();
134
		}
135
136
		return super.getContentPaneFor(editPart);
137
	}
138
139
	/**
140
	 * @generated
141
	 */
142
	protected boolean addFixedChild(EditPart childEditPart) {
143
		if (childEditPart instanceof DataTypeNameEditPart) {
144
			((DataTypeNameEditPart) childEditPart).setLabel(getPrimaryShape().getFigureClassFigure_name());
145
			return true;
146
		}
147
		if (childEditPart instanceof DataTypeAttributesEditPart) {
148
			IFigure pane = getPrimaryShape().getFigureClassFigure_PropertiesCompartment();
149
			setupContentPane(pane); // FIXME each comparment should handle his content pane in his own way 
150
			pane.add(((DataTypeAttributesEditPart) childEditPart).getFigure());
151
			return true;
152
		}
153
		if (childEditPart instanceof DataTypeOperationsEditPart) {
154
			IFigure pane = getPrimaryShape().getFigureClassFigure_OperationsCompartment();
155
			setupContentPane(pane); // FIXME each comparment should handle his content pane in his own way 
156
			pane.add(((DataTypeOperationsEditPart) childEditPart).getFigure());
157
			return true;
158
		}
159
		return false;
160
	}
161
162
	/**
163
	 * @generated
164
	 */
165
	protected boolean removeFixedChild(EditPart childEditPart) {
166
		if (childEditPart instanceof DataTypeAttributesEditPart) {
167
			IFigure pane = getPrimaryShape().getFigureClassFigure_PropertiesCompartment();
168
			pane.remove(((DataTypeAttributesEditPart) childEditPart).getFigure());
169
			return true;
170
		}
171
		if (childEditPart instanceof DataTypeOperationsEditPart) {
172
			IFigure pane = getPrimaryShape().getFigureClassFigure_OperationsCompartment();
173
			pane.remove(((DataTypeOperationsEditPart) childEditPart).getFigure());
174
			return true;
175
		}
176
		return false;
177
	}
178
179
	/**
180
	 * @generated
181
	 */
182
	protected NodeFigure createNodePlate() {
183
		DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(getMapMode().DPtoLP(100), getMapMode().DPtoLP(60));
184
		return result;
185
	}
186
187
	/**
188
	 * Creates figure for this edit part.
189
	 * 
190
	 * Body of this method does not depend on settings in generation model
191
	 * so you may safely remove <i>generated</i> tag and modify it.
192
	 * 
193
	 * @generated
194
	 */
195
	protected NodeFigure createNodeFigure() {
196
		NodeFigure figure = createNodePlate();
197
		figure.setLayoutManager(new StackLayout());
198
		IFigure shape = createNodeShape();
199
		figure.add(shape);
200
		contentPane = setupContentPane(shape);
201
		return figure;
202
	}
203
204
	/**
205
	 * Default implementation treats passed figure as content pane.
206
	 * Respects layout one may have set for generated figure.
207
	 * @param nodeShape instance of generated figure class
208
	 * @generated
209
	 */
210
	protected IFigure setupContentPane(IFigure nodeShape) {
211
		if (nodeShape.getLayoutManager() == null) {
212
			ConstrainedToolbarLayout layout = new ConstrainedToolbarLayout();
213
			layout.setSpacing(getMapMode().DPtoLP(5));
214
			nodeShape.setLayoutManager(layout);
215
		}
216
		return nodeShape; // use nodeShape itself as contentPane
217
	}
218
219
	/**
220
	 * @generated
221
	 */
222
	public IFigure getContentPane() {
223
		if (contentPane != null) {
224
			return contentPane;
225
		}
226
		return super.getContentPane();
227
	}
228
229
	/**
230
	 * @generated
231
	 */
232
	public EditPart getPrimaryChildEditPart() {
233
		return getChildBySemanticHint(UMLVisualIDRegistry.getType(DataTypeNameEditPart.VISUAL_ID));
234
	}
235
236
	/**
237
	 * @generated
238
	 */
239
	protected void addChildVisual(EditPart childEditPart, int index) {
240
		if (addFixedChild(childEditPart)) {
241
			return;
242
		}
243
		super.addChildVisual(childEditPart, -1);
244
	}
245
246
	/**
247
	 * @generated
248
	 */
249
	protected void removeChildVisual(EditPart childEditPart) {
250
		if (removeFixedChild(childEditPart)) {
251
			return;
252
		}
253
		super.removeChildVisual(childEditPart);
254
	}
255
256
	/**
257
	 * @generated
258
	 */
259
	public class ClassFigure extends org.eclipse.draw2d.RectangleFigure {
260
261
		/**
262
		 * @generated
263
		 */
264
		public ClassFigure() {
265
266
			org.eclipse.gmf.internal.codegen.draw2d.GridLayout myGenLayoutManager = new org.eclipse.gmf.internal.codegen.draw2d.GridLayout();
267
			myGenLayoutManager.numColumns = 1;
268
			myGenLayoutManager.makeColumnsEqualWidth = true;
269
			myGenLayoutManager.marginWidth = 0;
270
			myGenLayoutManager.marginHeight = 0;
271
			myGenLayoutManager.horizontalSpacing = 0;
272
			myGenLayoutManager.verticalSpacing = 0;
273
274
			this.setLayoutManager(myGenLayoutManager);
275
276
			this.setFill(false);
277
			this.setOutline(false);
278
			createContents();
279
		}
280
281
		/**
282
		 * @generated
283
		 */
284
		private void createContents() {
285
			org.eclipse.draw2d.RectangleFigure fig_0 = new org.eclipse.draw2d.RectangleFigure();
286
287
			fig_0.setMinimumSize(new org.eclipse.draw2d.geometry.Dimension(getMapMode().DPtoLP(0), getMapMode().DPtoLP(25)));
288
289
			org.eclipse.uml2.diagram.common.draw2d.CenterLayout layouter0 = new org.eclipse.uml2.diagram.common.draw2d.CenterLayout();
290
291
			fig_0.setLayoutManager(layouter0);
292
293
			setFigureClassFigure_NameContainer(fig_0);
294
			org.eclipse.gmf.internal.codegen.draw2d.GridLayoutData layData0 = new org.eclipse.gmf.internal.codegen.draw2d.GridLayoutData();
295
			layData0.verticalAlignment = org.eclipse.gmf.internal.codegen.draw2d.GridLayoutData.FILL;
296
			layData0.horizontalAlignment = org.eclipse.gmf.internal.codegen.draw2d.GridLayoutData.FILL;
297
			layData0.horizontalIndent = 0;
298
			layData0.horizontalSpan = 2;
299
			layData0.verticalSpan = 1;
300
			layData0.grabExcessHorizontalSpace = true;
301
			layData0.grabExcessVerticalSpace = false;
302
303
			this.add(fig_0, layData0);
304
			org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel fig_1 = new org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel();
305
306
			setFigureClassFigure_name(fig_1);
307
308
			Object layData1 = null;
309
310
			fig_0.add(fig_1, layData1);
311
			org.eclipse.draw2d.RectangleFigure fig_2 = new org.eclipse.draw2d.RectangleFigure();
312
313
			org.eclipse.draw2d.ToolbarLayout layouter2 = new org.eclipse.draw2d.ToolbarLayout();
314
			layouter2.setStretchMinorAxis(true);
315
			layouter2.setMinorAlignment(org.eclipse.draw2d.ToolbarLayout.ALIGN_CENTER);
316
			layouter2.setSpacing(0);
317
			layouter2.setVertical(true);
318
319
			fig_2.setLayoutManager(layouter2);
320
321
			setFigureClassFigure_Body(fig_2);
322
			org.eclipse.gmf.internal.codegen.draw2d.GridLayoutData layData2 = new org.eclipse.gmf.internal.codegen.draw2d.GridLayoutData();
323
			layData2.verticalAlignment = org.eclipse.gmf.internal.codegen.draw2d.GridLayoutData.FILL;
324
			layData2.horizontalAlignment = org.eclipse.gmf.internal.codegen.draw2d.GridLayoutData.FILL;
325
			layData2.horizontalIndent = 0;
326
			layData2.horizontalSpan = 2;
327
			layData2.verticalSpan = 1;
328
			layData2.grabExcessHorizontalSpace = true;
329
			layData2.grabExcessVerticalSpace = true;
330
331
			this.add(fig_2, layData2);
332
			org.eclipse.draw2d.RectangleFigure fig_3 = new org.eclipse.draw2d.RectangleFigure();
333
334
			setFigureClassFigure_PropertiesCompartment(fig_3);
335
336
			Object layData3 = null;
337
338
			fig_2.add(fig_3, layData3);
339
			org.eclipse.draw2d.RectangleFigure fig_4 = new org.eclipse.draw2d.RectangleFigure();
340
341
			setFigureClassFigure_OperationsCompartment(fig_4);
342
343
			Object layData4 = null;
344
345
			fig_2.add(fig_4, layData4);
346
			org.eclipse.draw2d.RectangleFigure fig_5 = new org.eclipse.draw2d.RectangleFigure();
347
348
			setFigureClassFigure_ClassesCompartment(fig_5);
349
350
			Object layData5 = null;
351
352
			fig_2.add(fig_5, layData5);
353
			org.eclipse.draw2d.RectangleFigure fig_6 = new org.eclipse.draw2d.RectangleFigure();
354
355
			setFigureClassFigure_LiteralsCompartment(fig_6);
356
357
			Object layData6 = null;
358
359
			fig_2.add(fig_6, layData6);
360
			org.eclipse.draw2d.RectangleFigure fig_7 = new org.eclipse.draw2d.RectangleFigure();
361
362
			setFigureClassFigure_OthersCompartment(fig_7);
363
364
			Object layData7 = null;
365
366
			fig_2.add(fig_7, layData7);
367
		}
368
369
		/**
370
		 * @generated
371
		 */
372
		private org.eclipse.draw2d.RectangleFigure fClassFigure_NameContainer;
373
374
		/**
375
		 * @generated
376
		 */
377
		public org.eclipse.draw2d.RectangleFigure getFigureClassFigure_NameContainer() {
378
			return fClassFigure_NameContainer;
379
		}
380
381
		/**
382
		 * @generated
383
		 */
384
		private void setFigureClassFigure_NameContainer(org.eclipse.draw2d.RectangleFigure fig) {
385
			fClassFigure_NameContainer = fig;
386
		}
387
388
		/**
389
		 * @generated
390
		 */
391
		private org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel fClassFigure_name;
392
393
		/**
394
		 * @generated
395
		 */
396
		public org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel getFigureClassFigure_name() {
397
			return fClassFigure_name;
398
		}
399
400
		/**
401
		 * @generated
402
		 */
403
		private void setFigureClassFigure_name(org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel fig) {
404
			fClassFigure_name = fig;
405
		}
406
407
		/**
408
		 * @generated
409
		 */
410
		private org.eclipse.draw2d.RectangleFigure fClassFigure_Body;
411
412
		/**
413
		 * @generated
414
		 */
415
		public org.eclipse.draw2d.RectangleFigure getFigureClassFigure_Body() {
416
			return fClassFigure_Body;
417
		}
418
419
		/**
420
		 * @generated
421
		 */
422
		private void setFigureClassFigure_Body(org.eclipse.draw2d.RectangleFigure fig) {
423
			fClassFigure_Body = fig;
424
		}
425
426
		/**
427
		 * @generated
428
		 */
429
		private org.eclipse.draw2d.RectangleFigure fClassFigure_PropertiesCompartment;
430
431
		/**
432
		 * @generated
433
		 */
434
		public org.eclipse.draw2d.RectangleFigure getFigureClassFigure_PropertiesCompartment() {
435
			return fClassFigure_PropertiesCompartment;
436
		}
437
438
		/**
439
		 * @generated
440
		 */
441
		private void setFigureClassFigure_PropertiesCompartment(org.eclipse.draw2d.RectangleFigure fig) {
442
			fClassFigure_PropertiesCompartment = fig;
443
		}
444
445
		/**
446
		 * @generated
447
		 */
448
		private org.eclipse.draw2d.RectangleFigure fClassFigure_OperationsCompartment;
449
450
		/**
451
		 * @generated
452
		 */
453
		public org.eclipse.draw2d.RectangleFigure getFigureClassFigure_OperationsCompartment() {
454
			return fClassFigure_OperationsCompartment;
455
		}
456
457
		/**
458
		 * @generated
459
		 */
460
		private void setFigureClassFigure_OperationsCompartment(org.eclipse.draw2d.RectangleFigure fig) {
461
			fClassFigure_OperationsCompartment = fig;
462
		}
463
464
		/**
465
		 * @generated
466
		 */
467
		private org.eclipse.draw2d.RectangleFigure fClassFigure_ClassesCompartment;
468
469
		/**
470
		 * @generated
471
		 */
472
		public org.eclipse.draw2d.RectangleFigure getFigureClassFigure_ClassesCompartment() {
473
			return fClassFigure_ClassesCompartment;
474
		}
475
476
		/**
477
		 * @generated
478
		 */
479
		private void setFigureClassFigure_ClassesCompartment(org.eclipse.draw2d.RectangleFigure fig) {
480
			fClassFigure_ClassesCompartment = fig;
481
		}
482
483
		/**
484
		 * @generated
485
		 */
486
		private org.eclipse.draw2d.RectangleFigure fClassFigure_LiteralsCompartment;
487
488
		/**
489
		 * @generated
490
		 */
491
		public org.eclipse.draw2d.RectangleFigure getFigureClassFigure_LiteralsCompartment() {
492
			return fClassFigure_LiteralsCompartment;
493
		}
494
495
		/**
496
		 * @generated
497
		 */
498
		private void setFigureClassFigure_LiteralsCompartment(org.eclipse.draw2d.RectangleFigure fig) {
499
			fClassFigure_LiteralsCompartment = fig;
500
		}
501
502
		/**
503
		 * @generated
504
		 */
505
		private org.eclipse.draw2d.RectangleFigure fClassFigure_OthersCompartment;
506
507
		/**
508
		 * @generated
509
		 */
510
		public org.eclipse.draw2d.RectangleFigure getFigureClassFigure_OthersCompartment() {
511
			return fClassFigure_OthersCompartment;
512
		}
513
514
		/**
515
		 * @generated
516
		 */
517
		private void setFigureClassFigure_OthersCompartment(org.eclipse.draw2d.RectangleFigure fig) {
518
			fClassFigure_OthersCompartment = fig;
519
		}
520
521
		/**
522
		 * @generated
523
		 */
524
		private boolean myUseLocalCoordinates = false;
525
526
		/**
527
		 * @generated
528
		 */
529
		protected boolean useLocalCoordinates() {
530
			return myUseLocalCoordinates;
531
		}
532
533
		/**
534
		 * @generated
535
		 */
536
		protected void setUseLocalCoordinates(boolean useLocalCoordinates) {
537
			myUseLocalCoordinates = useLocalCoordinates;
538
		}
539
540
	}
541
542
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/parts/ConstraintConstrainedElementEditPart.java (+65 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.parts;
2
3
import org.eclipse.draw2d.Connection;
4
import org.eclipse.gef.EditPolicy;
5
import org.eclipse.gmf.runtime.diagram.ui.editparts.ConnectionNodeEditPart;
6
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
7
import org.eclipse.gmf.runtime.notation.View;
8
import org.eclipse.uml2.diagram.clazz.edit.policies.ConstraintConstrainedElementItemSemanticEditPolicy;
9
import org.eclipse.uml2.diagram.clazz.edit.policies.UMLReferenceConnectionEditPolicy;
10
11
/**
12
 * @generated
13
 */
14
public class ConstraintConstrainedElementEditPart extends ConnectionNodeEditPart {
15
16
	/**
17
	 * @generated
18
	 */
19
	public static final int VISUAL_ID = 4004;
20
21
	/**
22
	 * @generated
23
	 */
24
	public ConstraintConstrainedElementEditPart(View view) {
25
		super(view);
26
	}
27
28
	/**
29
	 * @generated
30
	 */
31
	protected void createDefaultEditPolicies() {
32
		super.createDefaultEditPolicies();
33
		installEditPolicy(EditPolicy.CONNECTION_ROLE, new UMLReferenceConnectionEditPolicy());
34
		installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new ConstraintConstrainedElementItemSemanticEditPolicy());
35
36
	}
37
38
	/**
39
	 * Creates figure for this edit part.
40
	 * 
41
	 * Body of this method does not depend on settings in generation model
42
	 * so you may safely remove <i>generated</i> tag and modify it.
43
	 * 
44
	 * @generated
45
	 */
46
	protected Connection createConnectionFigure() {
47
		return new DashedLineConnection();
48
	}
49
50
	/**
51
	 * @generated
52
	 */
53
	public class DashedLineConnection extends org.eclipse.gmf.runtime.draw2d.ui.figures.PolylineConnectionEx {
54
55
		/**
56
		 * @generated
57
		 */
58
		public DashedLineConnection() {
59
60
			this.setLineStyle(org.eclipse.draw2d.Graphics.LINE_DASH);
61
		}
62
63
	}
64
65
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/parts/DependencyEditPart.java (+301 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.parts;
2
3
import java.util.Iterator;
4
5
import org.eclipse.draw2d.IFigure;
6
import org.eclipse.draw2d.PositionConstants;
7
import org.eclipse.draw2d.StackLayout;
8
import org.eclipse.gef.EditPart;
9
import org.eclipse.gef.EditPolicy;
10
import org.eclipse.gef.GraphicalEditPart;
11
import org.eclipse.gef.Request;
12
import org.eclipse.gef.commands.Command;
13
import org.eclipse.gef.editparts.LayerManager;
14
import org.eclipse.gef.editpolicies.LayoutEditPolicy;
15
import org.eclipse.gef.editpolicies.NonResizableEditPolicy;
16
import org.eclipse.gef.editpolicies.ResizableEditPolicy;
17
import org.eclipse.gef.requests.CreateRequest;
18
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
19
import org.eclipse.gmf.runtime.diagram.ui.editparts.ShapeNodeEditPart;
20
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
21
import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout;
22
import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure;
23
import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure;
24
import org.eclipse.gmf.runtime.notation.View;
25
import org.eclipse.uml2.diagram.clazz.edit.policies.DependencyItemSemanticEditPolicy;
26
import org.eclipse.uml2.diagram.clazz.edit.policies.UMLExtNodeLabelHostLayoutEditPolicy;
27
import org.eclipse.uml2.diagram.clazz.part.UMLVisualIDRegistry;
28
29
/**
30
 * @generated
31
 */
32
public class DependencyEditPart extends ShapeNodeEditPart {
33
34
	/**
35
	 * @generated
36
	 */
37
	public static final int VISUAL_ID = 2009;
38
39
	/**
40
	 * @generated
41
	 */
42
	protected IFigure contentPane;
43
44
	/**
45
	 * @generated
46
	 */
47
	protected IFigure primaryShape;
48
49
	/**
50
	 * @generated
51
	 */
52
	public DependencyEditPart(View view) {
53
		super(view);
54
	}
55
56
	/**
57
	 * @generated
58
	 */
59
	protected void createDefaultEditPolicies() {
60
		super.createDefaultEditPolicies();
61
		installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new DependencyItemSemanticEditPolicy());
62
		installEditPolicy(EditPolicy.LAYOUT_ROLE, createLayoutEditPolicy());
63
64
	}
65
66
	/**
67
	 * @generated
68
	 */
69
	protected LayoutEditPolicy createLayoutEditPolicy() {
70
		LayoutEditPolicy lep = new LayoutEditPolicy() {
71
72
			protected void decorateChild(EditPart child) {
73
				if (isExternalLabel(child)) {
74
					return;
75
				}
76
				super.decorateChild(child);
77
			}
78
79
			protected EditPolicy createChildEditPolicy(EditPart child) {
80
				EditPolicy result = child.getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
81
				if (result == null) {
82
					result = new NonResizableEditPolicy();
83
				}
84
				return result;
85
			}
86
87
			protected Command getMoveChildrenCommand(Request request) {
88
				return null;
89
			}
90
91
			protected Command getCreateCommand(CreateRequest request) {
92
				return null;
93
			}
94
		};
95
		UMLExtNodeLabelHostLayoutEditPolicy xlep = new UMLExtNodeLabelHostLayoutEditPolicy() {
96
97
			protected boolean isExternalLabel(EditPart editPart) {
98
				return DependencyEditPart.this.isExternalLabel(editPart);
99
			}
100
		};
101
		xlep.setRealLayoutEditPolicy(lep);
102
		return xlep;
103
	}
104
105
	/**
106
	 * @generated
107
	 */
108
	protected IFigure createNodeShape() {
109
		DependencyNode figure = new DependencyNode();
110
		return primaryShape = figure;
111
	}
112
113
	/**
114
	 * @generated
115
	 */
116
	public DependencyNode getPrimaryShape() {
117
		return (DependencyNode) primaryShape;
118
	}
119
120
	/**
121
	 * @generated 
122
	 */
123
	protected IFigure getContentPaneFor(IGraphicalEditPart editPart) {
124
		if (isExternalLabel(editPart)) {
125
			return getExternalLabelsContainer();
126
		}
127
128
		return super.getContentPaneFor(editPart);
129
	}
130
131
	/**
132
	 * @generated
133
	 */
134
	protected NodeFigure createNodePlate() {
135
		DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(getMapMode().DPtoLP(10), getMapMode().DPtoLP(10));
136
		return result;
137
	}
138
139
	/**
140
	 * @generated
141
	 */
142
	public EditPolicy getPrimaryDragEditPolicy() {
143
		EditPolicy result = super.getPrimaryDragEditPolicy();
144
		if (result instanceof ResizableEditPolicy) {
145
			ResizableEditPolicy ep = (ResizableEditPolicy) result;
146
147
			ep.setResizeDirections(PositionConstants.NONE);
148
149
		}
150
		return result;
151
	}
152
153
	/**
154
	 * Creates figure for this edit part.
155
	 * 
156
	 * Body of this method does not depend on settings in generation model
157
	 * so you may safely remove <i>generated</i> tag and modify it.
158
	 * 
159
	 * @generated
160
	 */
161
	protected NodeFigure createNodeFigure() {
162
		NodeFigure figure = createNodePlate();
163
		figure.setLayoutManager(new StackLayout());
164
		IFigure shape = createNodeShape();
165
		figure.add(shape);
166
		contentPane = setupContentPane(shape);
167
		return figure;
168
	}
169
170
	/**
171
	 * Default implementation treats passed figure as content pane.
172
	 * Respects layout one may have set for generated figure.
173
	 * @param nodeShape instance of generated figure class
174
	 * @generated
175
	 */
176
	protected IFigure setupContentPane(IFigure nodeShape) {
177
		if (nodeShape.getLayoutManager() == null) {
178
			ConstrainedToolbarLayout layout = new ConstrainedToolbarLayout();
179
			layout.setSpacing(getMapMode().DPtoLP(5));
180
			nodeShape.setLayoutManager(layout);
181
		}
182
		return nodeShape; // use nodeShape itself as contentPane
183
	}
184
185
	/**
186
	 * @generated
187
	 */
188
	public IFigure getContentPane() {
189
		if (contentPane != null) {
190
			return contentPane;
191
		}
192
		return super.getContentPane();
193
	}
194
195
	/**
196
	 * @generated
197
	 */
198
	public EditPart getPrimaryChildEditPart() {
199
		return getChildBySemanticHint(UMLVisualIDRegistry.getType(DependencyNameEditPart.VISUAL_ID));
200
	}
201
202
	/**
203
	 * @generated
204
	 */
205
	protected boolean isExternalLabel(EditPart childEditPart) {
206
		if (childEditPart instanceof DependencyNameEditPart) {
207
			return true;
208
		}
209
		return false;
210
	}
211
212
	/**
213
	 * @generated
214
	 */
215
	protected IFigure getExternalLabelsContainer() {
216
		LayerManager root = (LayerManager) getRoot();
217
		return root.getLayer(UMLEditPartFactory.EXTERNAL_NODE_LABELS_LAYER);
218
	}
219
220
	/**
221
	 * @generated
222
	 */
223
	protected void addChildVisual(EditPart childEditPart, int index) {
224
		if (isExternalLabel(childEditPart)) {
225
			IFigure labelFigure = ((GraphicalEditPart) childEditPart).getFigure();
226
			getExternalLabelsContainer().add(labelFigure);
227
			return;
228
		}
229
		super.addChildVisual(childEditPart, -1);
230
	}
231
232
	/**
233
	 * @generated
234
	 */
235
	protected void removeChildVisual(EditPart childEditPart) {
236
		if (isExternalLabel(childEditPart)) {
237
			IFigure labelFigure = ((GraphicalEditPart) childEditPart).getFigure();
238
			getExternalLabelsContainer().remove(labelFigure);
239
			return;
240
		}
241
		super.removeChildVisual(childEditPart);
242
	}
243
244
	/**
245
	 * @generated
246
	 */
247
	public void removeNotify() {
248
		for (Iterator it = getChildren().iterator(); it.hasNext();) {
249
			EditPart childEditPart = (EditPart) it.next();
250
			if (isExternalLabel(childEditPart)) {
251
				IFigure labelFigure = ((GraphicalEditPart) childEditPart).getFigure();
252
				getExternalLabelsContainer().remove(labelFigure);
253
			}
254
		}
255
		super.removeNotify();
256
	}
257
258
	/**
259
	 * @generated
260
	 */
261
	public class DependencyNode extends org.eclipse.draw2d.RectangleFigure {
262
263
		/**
264
		 * @generated
265
		 */
266
		public DependencyNode() {
267
268
			this.setBackgroundColor(org.eclipse.draw2d.ColorConstants.darkGray);
269
			this.setPreferredSize(getMapMode().DPtoLP(10), getMapMode().DPtoLP(10));
270
			this.setMaximumSize(new org.eclipse.draw2d.geometry.Dimension(getMapMode().DPtoLP(10), getMapMode().DPtoLP(10)));
271
			createContents();
272
		}
273
274
		/**
275
		 * @generated
276
		 */
277
		private void createContents() {
278
		}
279
280
		/**
281
		 * @generated
282
		 */
283
		private boolean myUseLocalCoordinates = false;
284
285
		/**
286
		 * @generated
287
		 */
288
		protected boolean useLocalCoordinates() {
289
			return myUseLocalCoordinates;
290
		}
291
292
		/**
293
		 * @generated
294
		 */
295
		protected void setUseLocalCoordinates(boolean useLocalCoordinates) {
296
			myUseLocalCoordinates = useLocalCoordinates;
297
		}
298
299
	}
300
301
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/parts/AssociationNameEditPart.java (+533 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.parts;
2
3
import java.util.Collections;
4
import java.util.List;
5
6
import org.eclipse.draw2d.ConnectionLocator;
7
import org.eclipse.draw2d.IFigure;
8
import org.eclipse.draw2d.Label;
9
import org.eclipse.draw2d.geometry.Point;
10
import org.eclipse.emf.common.notify.Notification;
11
import org.eclipse.emf.ecore.EObject;
12
import org.eclipse.emf.transaction.RunnableWithResult;
13
import org.eclipse.gef.AccessibleEditPart;
14
import org.eclipse.gef.EditPolicy;
15
import org.eclipse.gef.Request;
16
import org.eclipse.gef.requests.DirectEditRequest;
17
import org.eclipse.gef.tools.DirectEditManager;
18
import org.eclipse.gmf.runtime.common.ui.services.parser.IParser;
19
import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus;
20
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserEditStatus;
21
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions;
22
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserService;
23
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
24
import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart;
25
import org.eclipse.gmf.runtime.diagram.ui.editparts.LabelEditPart;
26
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy;
27
import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry;
28
import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants;
29
import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager;
30
import org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel;
31
import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
32
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
33
import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser;
34
import org.eclipse.gmf.runtime.emf.ui.services.parser.ParserHintAdapter;
35
import org.eclipse.gmf.runtime.notation.FontStyle;
36
import org.eclipse.gmf.runtime.notation.NotationPackage;
37
import org.eclipse.gmf.runtime.notation.View;
38
import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
39
import org.eclipse.jface.viewers.ICellEditorValidator;
40
import org.eclipse.swt.SWT;
41
import org.eclipse.swt.accessibility.AccessibleEvent;
42
import org.eclipse.swt.graphics.Color;
43
import org.eclipse.swt.graphics.FontData;
44
import org.eclipse.swt.graphics.Image;
45
import org.eclipse.uml2.diagram.clazz.edit.policies.UMLTextSelectionEditPolicy;
46
import org.eclipse.uml2.diagram.clazz.part.UMLVisualIDRegistry;
47
import org.eclipse.uml2.diagram.clazz.providers.UMLElementTypes;
48
49
/**
50
 * @generated
51
 */
52
public class AssociationNameEditPart extends LabelEditPart implements ITextAwareEditPart {
53
54
	/**
55
	 * @generated
56
	 */
57
	public static final int VISUAL_ID = 6003;
58
59
	/**
60
	 * @generated
61
	 */
62
	private DirectEditManager manager;
63
64
	/**
65
	 * @generated
66
	 */
67
	private IParser parser;
68
69
	/**
70
	 * @generated
71
	 */
72
	private List parserElements;
73
74
	/**
75
	 * @generated
76
	 */
77
	private String defaultText;
78
79
	/**
80
	 * @generated
81
	 */
82
	static {
83
		registerSnapBackPosition(UMLVisualIDRegistry.getType(AssociationNameEditPart.VISUAL_ID), new Point(0, 40));
84
	}
85
86
	/**
87
	 * @generated
88
	 */
89
	public AssociationNameEditPart(View view) {
90
		super(view);
91
	}
92
93
	/**
94
	 * @generated
95
	 */
96
	protected void createDefaultEditPolicies() {
97
		super.createDefaultEditPolicies();
98
		installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy());
99
100
	}
101
102
	/**
103
	 * @generated
104
	 */
105
	public int getKeyPoint() {
106
		return ConnectionLocator.MIDDLE;
107
	}
108
109
	/**
110
	 * @generated
111
	 */
112
	protected String getLabelTextHelper(IFigure figure) {
113
		if (figure instanceof WrapLabel) {
114
			return ((WrapLabel) figure).getText();
115
		} else {
116
			return ((Label) figure).getText();
117
		}
118
	}
119
120
	/**
121
	 * @generated
122
	 */
123
	protected void setLabelTextHelper(IFigure figure, String text) {
124
		if (figure instanceof WrapLabel) {
125
			((WrapLabel) figure).setText(text);
126
		} else {
127
			((Label) figure).setText(text);
128
		}
129
	}
130
131
	/**
132
	 * @generated
133
	 */
134
	protected Image getLabelIconHelper(IFigure figure) {
135
		if (figure instanceof WrapLabel) {
136
			return ((WrapLabel) figure).getIcon();
137
		} else {
138
			return ((Label) figure).getIcon();
139
		}
140
	}
141
142
	/**
143
	 * @generated
144
	 */
145
	protected void setLabelIconHelper(IFigure figure, Image icon) {
146
		if (figure instanceof WrapLabel) {
147
			((WrapLabel) figure).setIcon(icon);
148
		} else {
149
			((Label) figure).setIcon(icon);
150
		}
151
	}
152
153
	/**
154
	 * @generated
155
	 */
156
	public void setLabel(IFigure figure) {
157
		unregisterVisuals();
158
		setFigure(figure);
159
		defaultText = getLabelTextHelper(figure);
160
		registerVisuals();
161
		refreshVisuals();
162
	}
163
164
	/**
165
	 * @generated
166
	 */
167
	protected List getModelChildren() {
168
		return Collections.EMPTY_LIST;
169
	}
170
171
	/**
172
	 * @generated
173
	 */
174
	public IGraphicalEditPart getChildBySemanticHint(String semanticHint) {
175
		return null;
176
	}
177
178
	/**
179
	 * @generated
180
	 */
181
	protected EObject getParserElement() {
182
		EObject element = resolveSemanticElement();
183
		return element != null ? element : (View) getModel();
184
	}
185
186
	/**
187
	 * @generated
188
	 */
189
	protected Image getLabelIcon() {
190
		return null;
191
	}
192
193
	/**
194
	 * @generated
195
	 */
196
	protected String getLabelText() {
197
		String text = null;
198
		if (getParser() != null) {
199
			text = getParser().getPrintString(new EObjectAdapter(getParserElement()), getParserOptions().intValue());
200
		}
201
		if (text == null || text.length() == 0) {
202
			text = defaultText;
203
		}
204
		return text;
205
	}
206
207
	/**
208
	 * @generated
209
	 */
210
	public void setLabelText(String text) {
211
		setLabelTextHelper(getFigure(), text);
212
		Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
213
		if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) {
214
			((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback();
215
		}
216
	}
217
218
	/**
219
	 * @generated
220
	 */
221
	public String getEditText() {
222
		if (getParser() == null) {
223
			return ""; //$NON-NLS-1$
224
		}
225
		return getParser().getEditString(new EObjectAdapter(getParserElement()), getParserOptions().intValue());
226
	}
227
228
	/**
229
	 * @generated
230
	 */
231
	protected boolean isEditable() {
232
		return getEditText() != null;
233
	}
234
235
	/**
236
	 * @generated
237
	 */
238
	public ICellEditorValidator getEditTextValidator() {
239
		return new ICellEditorValidator() {
240
241
			public String isValid(final Object value) {
242
				if (value instanceof String) {
243
					final EObject element = getParserElement();
244
					final IParser parser = getParser();
245
					try {
246
						IParserEditStatus valid = (IParserEditStatus) getEditingDomain().runExclusive(new RunnableWithResult.Impl() {
247
248
							public void run() {
249
								setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value));
250
							}
251
						});
252
						return valid.getCode() == ParserEditStatus.EDITABLE ? null : valid.getMessage();
253
					} catch (InterruptedException ie) {
254
						ie.printStackTrace();
255
					}
256
				}
257
258
				// shouldn't get here
259
				return null;
260
			}
261
		};
262
	}
263
264
	/**
265
	 * @generated
266
	 */
267
	public IContentAssistProcessor getCompletionProcessor() {
268
		if (getParser() == null) {
269
			return null;
270
		}
271
		return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement()));
272
	}
273
274
	/**
275
	 * @generated
276
	 */
277
	public ParserOptions getParserOptions() {
278
		return ParserOptions.NONE;
279
	}
280
281
	/**
282
	 * @generated
283
	 */
284
	public IParser getParser() {
285
		if (parser == null) {
286
			String parserHint = ((View) getModel()).getType();
287
			ParserHintAdapter hintAdapter = new ParserHintAdapter(getParserElement(), parserHint) {
288
289
				public Object getAdapter(Class adapter) {
290
					if (IElementType.class.equals(adapter)) {
291
						return UMLElementTypes.Association_4005;
292
					}
293
					return super.getAdapter(adapter);
294
				}
295
			};
296
			parser = ParserService.getInstance().getParser(hintAdapter);
297
		}
298
		return parser;
299
	}
300
301
	/**
302
	 * @generated
303
	 */
304
	protected DirectEditManager getManager() {
305
		if (manager == null) {
306
			setManager(new TextDirectEditManager(this, TextDirectEditManager.getTextCellEditorClass(this), UMLEditPartFactory.getTextCellEditorLocator(this)));
307
		}
308
		return manager;
309
	}
310
311
	/**
312
	 * @generated
313
	 */
314
	protected void setManager(DirectEditManager manager) {
315
		this.manager = manager;
316
	}
317
318
	/**
319
	 * @generated
320
	 */
321
	protected void performDirectEdit() {
322
		getManager().show();
323
	}
324
325
	/**
326
	 * @generated
327
	 */
328
	protected void performDirectEdit(Point eventLocation) {
329
		if (getManager().getClass() == TextDirectEditManager.class) {
330
			((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint());
331
		}
332
	}
333
334
	/**
335
	 * @generated
336
	 */
337
	private void performDirectEdit(char initialCharacter) {
338
		if (getManager() instanceof TextDirectEditManager) {
339
			((TextDirectEditManager) getManager()).show(initialCharacter);
340
		} else {
341
			performDirectEdit();
342
		}
343
	}
344
345
	/**
346
	 * @generated
347
	 */
348
	protected void performDirectEditRequest(Request request) {
349
		final Request theRequest = request;
350
		try {
351
			getEditingDomain().runExclusive(new Runnable() {
352
353
				public void run() {
354
					if (isActive() && isEditable()) {
355
						if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) {
356
							Character initialChar = (Character) theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR);
357
							performDirectEdit(initialChar.charValue());
358
						} else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) {
359
							DirectEditRequest editRequest = (DirectEditRequest) theRequest;
360
							performDirectEdit(editRequest.getLocation());
361
						} else {
362
							performDirectEdit();
363
						}
364
					}
365
				}
366
			});
367
		} catch (InterruptedException e) {
368
			e.printStackTrace();
369
		}
370
	}
371
372
	/**
373
	 * @generated
374
	 */
375
	protected void refreshVisuals() {
376
		super.refreshVisuals();
377
		refreshLabel();
378
		refreshFont();
379
		refreshFontColor();
380
		refreshUnderline();
381
		refreshStrikeThrough();
382
	}
383
384
	/**
385
	 * @generated
386
	 */
387
	protected void refreshLabel() {
388
		setLabelTextHelper(getFigure(), getLabelText());
389
		setLabelIconHelper(getFigure(), getLabelIcon());
390
		Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
391
		if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) {
392
			((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback();
393
		}
394
	}
395
396
	/**
397
	 * @generated
398
	 */
399
	protected void refreshUnderline() {
400
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
401
		if (style != null && getFigure() instanceof WrapLabel) {
402
			((WrapLabel) getFigure()).setTextUnderline(style.isUnderline());
403
		}
404
	}
405
406
	/**
407
	 * @generated
408
	 */
409
	protected void refreshStrikeThrough() {
410
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
411
		if (style != null && getFigure() instanceof WrapLabel) {
412
			((WrapLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough());
413
		}
414
	}
415
416
	/**
417
	 * @generated
418
	 */
419
	protected void refreshFont() {
420
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
421
		if (style != null) {
422
			FontData fontData = new FontData(style.getFontName(), style.getFontHeight(), (style.isBold() ? SWT.BOLD : SWT.NORMAL) | (style.isItalic() ? SWT.ITALIC : SWT.NORMAL));
423
			setFont(fontData);
424
		}
425
	}
426
427
	/**
428
	 * @generated
429
	 */
430
	protected void setFontColor(Color color) {
431
		getFigure().setForegroundColor(color);
432
	}
433
434
	/**
435
	 * @generated
436
	 */
437
	protected void addSemanticListeners() {
438
		if (getParser() instanceof ISemanticParser) {
439
			EObject element = resolveSemanticElement();
440
			parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element);
441
			for (int i = 0; i < parserElements.size(); i++) {
442
				addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$
443
			}
444
		} else {
445
			super.addSemanticListeners();
446
		}
447
	}
448
449
	/**
450
	 * @generated
451
	 */
452
	protected void removeSemanticListeners() {
453
		if (parserElements != null) {
454
			for (int i = 0; i < parserElements.size(); i++) {
455
				removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$
456
			}
457
		} else {
458
			super.removeSemanticListeners();
459
		}
460
	}
461
462
	/**
463
	 * @generated
464
	 */
465
	protected AccessibleEditPart getAccessibleEditPart() {
466
		if (accessibleEP == null) {
467
			accessibleEP = new AccessibleGraphicalEditPart() {
468
469
				public void getName(AccessibleEvent e) {
470
					e.result = getLabelTextHelper(getFigure());
471
				}
472
			};
473
		}
474
		return accessibleEP;
475
	}
476
477
	/**
478
	 * @generated
479
	 */
480
	private View getFontStyleOwnerView() {
481
		return getPrimaryView();
482
	}
483
484
	/**
485
	 * @generated
486
	 */
487
	protected void handleNotificationEvent(Notification event) {
488
		Object feature = event.getFeature();
489
		if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) {
490
			Integer c = (Integer) event.getNewValue();
491
			setFontColor(DiagramColorRegistry.getInstance().getColor(c));
492
		} else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) {
493
			refreshUnderline();
494
		} else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) {
495
			refreshStrikeThrough();
496
		} else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature)
497
				|| NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) {
498
			refreshFont();
499
		} else {
500
			if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) {
501
				refreshLabel();
502
			}
503
			if (getParser() instanceof ISemanticParser) {
504
				ISemanticParser modelParser = (ISemanticParser) getParser();
505
				if (modelParser.areSemanticElementsAffected(null, event)) {
506
					removeSemanticListeners();
507
					if (resolveSemanticElement() != null) {
508
						addSemanticListeners();
509
					}
510
					refreshLabel();
511
				}
512
			}
513
		}
514
		super.handleNotificationEvent(event);
515
	}
516
517
	/**
518
	 * @generated
519
	 */
520
	protected IFigure createFigure() {
521
		IFigure label = createFigurePrim();
522
		defaultText = getLabelTextHelper(label);
523
		return label;
524
	}
525
526
	/**
527
	 * @generated
528
	 */
529
	protected IFigure createFigurePrim() {
530
		return new WrapLabel();
531
	}
532
533
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/policies/UsageItemSemanticEditPolicy.java (+18 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.policies;
2
3
import org.eclipse.gef.commands.Command;
4
import org.eclipse.gmf.runtime.emf.type.core.commands.DestroyElementCommand;
5
import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest;
6
7
/**
8
 * @generated
9
 */
10
public class UsageItemSemanticEditPolicy extends UMLBaseItemSemanticEditPolicy {
11
12
	/**
13
	 * @generated
14
	 */
15
	protected Command getDestroyElementCommand(DestroyElementRequest req) {
16
		return getMSLWrapper(new DestroyElementCommand(req));
17
	}
18
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/parts/AssociationName3EditPart.java (+533 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.parts;
2
3
import java.util.Collections;
4
import java.util.List;
5
6
import org.eclipse.draw2d.ConnectionLocator;
7
import org.eclipse.draw2d.IFigure;
8
import org.eclipse.draw2d.Label;
9
import org.eclipse.draw2d.geometry.Point;
10
import org.eclipse.emf.common.notify.Notification;
11
import org.eclipse.emf.ecore.EObject;
12
import org.eclipse.emf.transaction.RunnableWithResult;
13
import org.eclipse.gef.AccessibleEditPart;
14
import org.eclipse.gef.EditPolicy;
15
import org.eclipse.gef.Request;
16
import org.eclipse.gef.requests.DirectEditRequest;
17
import org.eclipse.gef.tools.DirectEditManager;
18
import org.eclipse.gmf.runtime.common.ui.services.parser.IParser;
19
import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus;
20
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserEditStatus;
21
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions;
22
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserService;
23
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
24
import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart;
25
import org.eclipse.gmf.runtime.diagram.ui.editparts.LabelEditPart;
26
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy;
27
import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry;
28
import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants;
29
import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager;
30
import org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel;
31
import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
32
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
33
import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser;
34
import org.eclipse.gmf.runtime.emf.ui.services.parser.ParserHintAdapter;
35
import org.eclipse.gmf.runtime.notation.FontStyle;
36
import org.eclipse.gmf.runtime.notation.NotationPackage;
37
import org.eclipse.gmf.runtime.notation.View;
38
import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
39
import org.eclipse.jface.viewers.ICellEditorValidator;
40
import org.eclipse.swt.SWT;
41
import org.eclipse.swt.accessibility.AccessibleEvent;
42
import org.eclipse.swt.graphics.Color;
43
import org.eclipse.swt.graphics.FontData;
44
import org.eclipse.swt.graphics.Image;
45
import org.eclipse.uml2.diagram.clazz.edit.policies.UMLTextSelectionEditPolicy;
46
import org.eclipse.uml2.diagram.clazz.part.UMLVisualIDRegistry;
47
import org.eclipse.uml2.diagram.clazz.providers.UMLElementTypes;
48
49
/**
50
 * @generated
51
 */
52
public class AssociationName3EditPart extends LabelEditPart implements ITextAwareEditPart {
53
54
	/**
55
	 * @generated
56
	 */
57
	public static final int VISUAL_ID = 6005;
58
59
	/**
60
	 * @generated
61
	 */
62
	private DirectEditManager manager;
63
64
	/**
65
	 * @generated
66
	 */
67
	private IParser parser;
68
69
	/**
70
	 * @generated
71
	 */
72
	private List parserElements;
73
74
	/**
75
	 * @generated
76
	 */
77
	private String defaultText;
78
79
	/**
80
	 * @generated
81
	 */
82
	static {
83
		registerSnapBackPosition(UMLVisualIDRegistry.getType(AssociationName3EditPart.VISUAL_ID), new Point(0, -15));
84
	}
85
86
	/**
87
	 * @generated
88
	 */
89
	public AssociationName3EditPart(View view) {
90
		super(view);
91
	}
92
93
	/**
94
	 * @generated
95
	 */
96
	protected void createDefaultEditPolicies() {
97
		super.createDefaultEditPolicies();
98
		installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy());
99
100
	}
101
102
	/**
103
	 * @generated
104
	 */
105
	public int getKeyPoint() {
106
		return ConnectionLocator.SOURCE;
107
	}
108
109
	/**
110
	 * @generated
111
	 */
112
	protected String getLabelTextHelper(IFigure figure) {
113
		if (figure instanceof WrapLabel) {
114
			return ((WrapLabel) figure).getText();
115
		} else {
116
			return ((Label) figure).getText();
117
		}
118
	}
119
120
	/**
121
	 * @generated
122
	 */
123
	protected void setLabelTextHelper(IFigure figure, String text) {
124
		if (figure instanceof WrapLabel) {
125
			((WrapLabel) figure).setText(text);
126
		} else {
127
			((Label) figure).setText(text);
128
		}
129
	}
130
131
	/**
132
	 * @generated
133
	 */
134
	protected Image getLabelIconHelper(IFigure figure) {
135
		if (figure instanceof WrapLabel) {
136
			return ((WrapLabel) figure).getIcon();
137
		} else {
138
			return ((Label) figure).getIcon();
139
		}
140
	}
141
142
	/**
143
	 * @generated
144
	 */
145
	protected void setLabelIconHelper(IFigure figure, Image icon) {
146
		if (figure instanceof WrapLabel) {
147
			((WrapLabel) figure).setIcon(icon);
148
		} else {
149
			((Label) figure).setIcon(icon);
150
		}
151
	}
152
153
	/**
154
	 * @generated
155
	 */
156
	public void setLabel(IFigure figure) {
157
		unregisterVisuals();
158
		setFigure(figure);
159
		defaultText = getLabelTextHelper(figure);
160
		registerVisuals();
161
		refreshVisuals();
162
	}
163
164
	/**
165
	 * @generated
166
	 */
167
	protected List getModelChildren() {
168
		return Collections.EMPTY_LIST;
169
	}
170
171
	/**
172
	 * @generated
173
	 */
174
	public IGraphicalEditPart getChildBySemanticHint(String semanticHint) {
175
		return null;
176
	}
177
178
	/**
179
	 * @generated
180
	 */
181
	protected EObject getParserElement() {
182
		EObject element = resolveSemanticElement();
183
		return element != null ? element : (View) getModel();
184
	}
185
186
	/**
187
	 * @generated
188
	 */
189
	protected Image getLabelIcon() {
190
		return null;
191
	}
192
193
	/**
194
	 * @generated
195
	 */
196
	protected String getLabelText() {
197
		String text = null;
198
		if (getParser() != null) {
199
			text = getParser().getPrintString(new EObjectAdapter(getParserElement()), getParserOptions().intValue());
200
		}
201
		if (text == null || text.length() == 0) {
202
			text = defaultText;
203
		}
204
		return text;
205
	}
206
207
	/**
208
	 * @generated
209
	 */
210
	public void setLabelText(String text) {
211
		setLabelTextHelper(getFigure(), text);
212
		Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
213
		if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) {
214
			((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback();
215
		}
216
	}
217
218
	/**
219
	 * @generated
220
	 */
221
	public String getEditText() {
222
		if (getParser() == null) {
223
			return ""; //$NON-NLS-1$
224
		}
225
		return getParser().getEditString(new EObjectAdapter(getParserElement()), getParserOptions().intValue());
226
	}
227
228
	/**
229
	 * @generated
230
	 */
231
	protected boolean isEditable() {
232
		return getEditText() != null;
233
	}
234
235
	/**
236
	 * @generated
237
	 */
238
	public ICellEditorValidator getEditTextValidator() {
239
		return new ICellEditorValidator() {
240
241
			public String isValid(final Object value) {
242
				if (value instanceof String) {
243
					final EObject element = getParserElement();
244
					final IParser parser = getParser();
245
					try {
246
						IParserEditStatus valid = (IParserEditStatus) getEditingDomain().runExclusive(new RunnableWithResult.Impl() {
247
248
							public void run() {
249
								setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value));
250
							}
251
						});
252
						return valid.getCode() == ParserEditStatus.EDITABLE ? null : valid.getMessage();
253
					} catch (InterruptedException ie) {
254
						ie.printStackTrace();
255
					}
256
				}
257
258
				// shouldn't get here
259
				return null;
260
			}
261
		};
262
	}
263
264
	/**
265
	 * @generated
266
	 */
267
	public IContentAssistProcessor getCompletionProcessor() {
268
		if (getParser() == null) {
269
			return null;
270
		}
271
		return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement()));
272
	}
273
274
	/**
275
	 * @generated
276
	 */
277
	public ParserOptions getParserOptions() {
278
		return ParserOptions.NONE;
279
	}
280
281
	/**
282
	 * @generated
283
	 */
284
	public IParser getParser() {
285
		if (parser == null) {
286
			String parserHint = ((View) getModel()).getType();
287
			ParserHintAdapter hintAdapter = new ParserHintAdapter(getParserElement(), parserHint) {
288
289
				public Object getAdapter(Class adapter) {
290
					if (IElementType.class.equals(adapter)) {
291
						return UMLElementTypes.Association_4005;
292
					}
293
					return super.getAdapter(adapter);
294
				}
295
			};
296
			parser = ParserService.getInstance().getParser(hintAdapter);
297
		}
298
		return parser;
299
	}
300
301
	/**
302
	 * @generated
303
	 */
304
	protected DirectEditManager getManager() {
305
		if (manager == null) {
306
			setManager(new TextDirectEditManager(this, TextDirectEditManager.getTextCellEditorClass(this), UMLEditPartFactory.getTextCellEditorLocator(this)));
307
		}
308
		return manager;
309
	}
310
311
	/**
312
	 * @generated
313
	 */
314
	protected void setManager(DirectEditManager manager) {
315
		this.manager = manager;
316
	}
317
318
	/**
319
	 * @generated
320
	 */
321
	protected void performDirectEdit() {
322
		getManager().show();
323
	}
324
325
	/**
326
	 * @generated
327
	 */
328
	protected void performDirectEdit(Point eventLocation) {
329
		if (getManager().getClass() == TextDirectEditManager.class) {
330
			((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint());
331
		}
332
	}
333
334
	/**
335
	 * @generated
336
	 */
337
	private void performDirectEdit(char initialCharacter) {
338
		if (getManager() instanceof TextDirectEditManager) {
339
			((TextDirectEditManager) getManager()).show(initialCharacter);
340
		} else {
341
			performDirectEdit();
342
		}
343
	}
344
345
	/**
346
	 * @generated
347
	 */
348
	protected void performDirectEditRequest(Request request) {
349
		final Request theRequest = request;
350
		try {
351
			getEditingDomain().runExclusive(new Runnable() {
352
353
				public void run() {
354
					if (isActive() && isEditable()) {
355
						if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) {
356
							Character initialChar = (Character) theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR);
357
							performDirectEdit(initialChar.charValue());
358
						} else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) {
359
							DirectEditRequest editRequest = (DirectEditRequest) theRequest;
360
							performDirectEdit(editRequest.getLocation());
361
						} else {
362
							performDirectEdit();
363
						}
364
					}
365
				}
366
			});
367
		} catch (InterruptedException e) {
368
			e.printStackTrace();
369
		}
370
	}
371
372
	/**
373
	 * @generated
374
	 */
375
	protected void refreshVisuals() {
376
		super.refreshVisuals();
377
		refreshLabel();
378
		refreshFont();
379
		refreshFontColor();
380
		refreshUnderline();
381
		refreshStrikeThrough();
382
	}
383
384
	/**
385
	 * @generated
386
	 */
387
	protected void refreshLabel() {
388
		setLabelTextHelper(getFigure(), getLabelText());
389
		setLabelIconHelper(getFigure(), getLabelIcon());
390
		Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
391
		if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) {
392
			((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback();
393
		}
394
	}
395
396
	/**
397
	 * @generated
398
	 */
399
	protected void refreshUnderline() {
400
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
401
		if (style != null && getFigure() instanceof WrapLabel) {
402
			((WrapLabel) getFigure()).setTextUnderline(style.isUnderline());
403
		}
404
	}
405
406
	/**
407
	 * @generated
408
	 */
409
	protected void refreshStrikeThrough() {
410
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
411
		if (style != null && getFigure() instanceof WrapLabel) {
412
			((WrapLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough());
413
		}
414
	}
415
416
	/**
417
	 * @generated
418
	 */
419
	protected void refreshFont() {
420
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
421
		if (style != null) {
422
			FontData fontData = new FontData(style.getFontName(), style.getFontHeight(), (style.isBold() ? SWT.BOLD : SWT.NORMAL) | (style.isItalic() ? SWT.ITALIC : SWT.NORMAL));
423
			setFont(fontData);
424
		}
425
	}
426
427
	/**
428
	 * @generated
429
	 */
430
	protected void setFontColor(Color color) {
431
		getFigure().setForegroundColor(color);
432
	}
433
434
	/**
435
	 * @generated
436
	 */
437
	protected void addSemanticListeners() {
438
		if (getParser() instanceof ISemanticParser) {
439
			EObject element = resolveSemanticElement();
440
			parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element);
441
			for (int i = 0; i < parserElements.size(); i++) {
442
				addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$
443
			}
444
		} else {
445
			super.addSemanticListeners();
446
		}
447
	}
448
449
	/**
450
	 * @generated
451
	 */
452
	protected void removeSemanticListeners() {
453
		if (parserElements != null) {
454
			for (int i = 0; i < parserElements.size(); i++) {
455
				removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$
456
			}
457
		} else {
458
			super.removeSemanticListeners();
459
		}
460
	}
461
462
	/**
463
	 * @generated
464
	 */
465
	protected AccessibleEditPart getAccessibleEditPart() {
466
		if (accessibleEP == null) {
467
			accessibleEP = new AccessibleGraphicalEditPart() {
468
469
				public void getName(AccessibleEvent e) {
470
					e.result = getLabelTextHelper(getFigure());
471
				}
472
			};
473
		}
474
		return accessibleEP;
475
	}
476
477
	/**
478
	 * @generated
479
	 */
480
	private View getFontStyleOwnerView() {
481
		return getPrimaryView();
482
	}
483
484
	/**
485
	 * @generated
486
	 */
487
	protected void handleNotificationEvent(Notification event) {
488
		Object feature = event.getFeature();
489
		if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) {
490
			Integer c = (Integer) event.getNewValue();
491
			setFontColor(DiagramColorRegistry.getInstance().getColor(c));
492
		} else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) {
493
			refreshUnderline();
494
		} else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) {
495
			refreshStrikeThrough();
496
		} else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature)
497
				|| NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) {
498
			refreshFont();
499
		} else {
500
			if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) {
501
				refreshLabel();
502
			}
503
			if (getParser() instanceof ISemanticParser) {
504
				ISemanticParser modelParser = (ISemanticParser) getParser();
505
				if (modelParser.areSemanticElementsAffected(null, event)) {
506
					removeSemanticListeners();
507
					if (resolveSemanticElement() != null) {
508
						addSemanticListeners();
509
					}
510
					refreshLabel();
511
				}
512
			}
513
		}
514
		super.handleNotificationEvent(event);
515
	}
516
517
	/**
518
	 * @generated
519
	 */
520
	protected IFigure createFigure() {
521
		IFigure label = createFigurePrim();
522
		defaultText = getLabelTextHelper(label);
523
		return label;
524
	}
525
526
	/**
527
	 * @generated
528
	 */
529
	protected IFigure createFigurePrim() {
530
		return new WrapLabel();
531
	}
532
533
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/policies/Operation4ItemSemanticEditPolicy.java (+255 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.policies;
2
3
import org.eclipse.emf.ecore.EAnnotation;
4
import org.eclipse.emf.ecore.EClass;
5
import org.eclipse.emf.ecore.EObject;
6
import org.eclipse.gef.commands.Command;
7
import org.eclipse.gef.commands.UnexecutableCommand;
8
import org.eclipse.gmf.runtime.emf.type.core.commands.CreateRelationshipCommand;
9
import org.eclipse.gmf.runtime.emf.type.core.commands.DestroyElementCommand;
10
import org.eclipse.gmf.runtime.emf.type.core.commands.SetValueCommand;
11
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest;
12
import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest;
13
import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest;
14
import org.eclipse.gmf.runtime.notation.View;
15
import org.eclipse.uml2.diagram.clazz.providers.UMLElementTypes;
16
import org.eclipse.uml2.uml.Constraint;
17
import org.eclipse.uml2.uml.Dependency;
18
import org.eclipse.uml2.uml.NamedElement;
19
import org.eclipse.uml2.uml.UMLPackage;
20
import org.eclipse.uml2.uml.Usage;
21
22
/**
23
 * @generated
24
 */
25
public class Operation4ItemSemanticEditPolicy extends UMLBaseItemSemanticEditPolicy {
26
27
	/**
28
	 * @generated
29
	 */
30
	protected Command getDestroyElementCommand(DestroyElementRequest req) {
31
		return getMSLWrapper(new DestroyElementCommand(req) {
32
33
			protected EObject getElementToDestroy() {
34
				View view = (View) getHost().getModel();
35
				EAnnotation annotation = view.getEAnnotation("Shortcut"); //$NON-NLS-1$
36
				if (annotation != null) {
37
					return view;
38
				}
39
				return super.getElementToDestroy();
40
			}
41
42
		});
43
	}
44
45
	/**
46
	 * @generated
47
	 */
48
	protected Command getCreateRelationshipCommand(CreateRelationshipRequest req) {
49
		if (UMLElementTypes.Dependency_4002 == req.getElementType()) {
50
			return req.getTarget() == null ? getCreateStartOutgoingDependency4002Command(req) : getCreateCompleteIncomingDependency4002Command(req);
51
		}
52
		if (UMLElementTypes.ConstraintConstrainedElement_4004 == req.getElementType()) {
53
			return req.getTarget() == null ? null : getCreateCompleteIncomingConstraint_ConstrainedElement4004Command(req);
54
		}
55
		if (UMLElementTypes.DependencySupplier_4006 == req.getElementType()) {
56
			return req.getTarget() == null ? null : getCreateCompleteIncomingDependency_Supplier4006Command(req);
57
		}
58
		if (UMLElementTypes.DependencyClient_4007 == req.getElementType()) {
59
			return req.getTarget() == null ? null : getCreateCompleteIncomingDependency_Client4007Command(req);
60
		}
61
		if (UMLElementTypes.Usage_4009 == req.getElementType()) {
62
			return req.getTarget() == null ? getCreateStartOutgoingUsage4009Command(req) : getCreateCompleteIncomingUsage4009Command(req);
63
		}
64
		return super.getCreateRelationshipCommand(req);
65
	}
66
67
	/**
68
	 * @generated
69
	 */
70
	protected Command getCreateStartOutgoingDependency4002Command(CreateRelationshipRequest req) {
71
		return new Command() {
72
		};
73
	}
74
75
	/**
76
	 * @generated
77
	 */
78
	protected Command getCreateCompleteIncomingDependency4002Command(CreateRelationshipRequest req) {
79
		if (!(req.getSource() instanceof NamedElement)) {
80
			return UnexecutableCommand.INSTANCE;
81
		}
82
		final org.eclipse.uml2.uml.Package element = (org.eclipse.uml2.uml.Package) getRelationshipContainer(req.getSource(), UMLPackage.eINSTANCE.getPackage(), req.getElementType());
83
		if (element == null) {
84
			return UnexecutableCommand.INSTANCE;
85
		}
86
		if (req.getContainmentFeature() == null) {
87
			req.setContainmentFeature(UMLPackage.eINSTANCE.getPackage_PackagedElement());
88
		}
89
		return getMSLWrapper(new CreateIncomingDependency4002Command(req) {
90
91
			protected EObject getElementToEdit() {
92
				return element;
93
			}
94
		});
95
	}
96
97
	/**
98
	 * @generated
99
	 */
100
	private static class CreateIncomingDependency4002Command extends CreateRelationshipCommand {
101
102
		/**
103
		 * @generated
104
		 */
105
		public CreateIncomingDependency4002Command(CreateRelationshipRequest req) {
106
			super(req);
107
		}
108
109
		/**
110
		 * @generated
111
		 */
112
		protected EClass getEClassToEdit() {
113
			return UMLPackage.eINSTANCE.getPackage();
114
		};
115
116
		/**
117
		 * @generated
118
		 */
119
		protected void setElementToEdit(EObject element) {
120
			throw new UnsupportedOperationException();
121
		}
122
123
		/**
124
		 * @generated
125
		 */
126
		protected EObject doDefaultElementCreation() {
127
			Dependency newElement = (Dependency) super.doDefaultElementCreation();
128
			if (newElement != null) {
129
				newElement.getSuppliers().add((NamedElement) getTarget());
130
				newElement.getClients().add((NamedElement) getSource());
131
			}
132
			return newElement;
133
		}
134
	}
135
136
	/**
137
	 * @generated
138
	 */
139
	protected Command getCreateCompleteIncomingConstraint_ConstrainedElement4004Command(CreateRelationshipRequest req) {
140
		if (!(req.getSource() instanceof Constraint)) {
141
			return UnexecutableCommand.INSTANCE;
142
		}
143
		Constraint element = (Constraint) req.getSource();
144
		if (element.getConstrainedElements().contains(req.getTarget())) {
145
			return UnexecutableCommand.INSTANCE;
146
		}
147
		SetRequest setReq = new SetRequest(req.getSource(), UMLPackage.eINSTANCE.getConstraint_ConstrainedElement(), req.getTarget());
148
		return getMSLWrapper(new SetValueCommand(setReq));
149
	}
150
151
	/**
152
	 * @generated
153
	 */
154
	protected Command getCreateCompleteIncomingDependency_Supplier4006Command(CreateRelationshipRequest req) {
155
		if (!(req.getSource() instanceof Dependency)) {
156
			return UnexecutableCommand.INSTANCE;
157
		}
158
		Dependency element = (Dependency) req.getSource();
159
		if (element.getSuppliers().contains(req.getTarget())) {
160
			return UnexecutableCommand.INSTANCE;
161
		}
162
		SetRequest setReq = new SetRequest(req.getSource(), UMLPackage.eINSTANCE.getDependency_Supplier(), req.getTarget());
163
		return getMSLWrapper(new SetValueCommand(setReq));
164
	}
165
166
	/**
167
	 * @generated
168
	 */
169
	protected Command getCreateCompleteIncomingDependency_Client4007Command(CreateRelationshipRequest req) {
170
		if (!(req.getSource() instanceof Dependency)) {
171
			return UnexecutableCommand.INSTANCE;
172
		}
173
		Dependency element = (Dependency) req.getSource();
174
		if (element.getClients().contains(req.getTarget())) {
175
			return UnexecutableCommand.INSTANCE;
176
		}
177
		SetRequest setReq = new SetRequest(req.getSource(), UMLPackage.eINSTANCE.getDependency_Client(), req.getTarget());
178
		return getMSLWrapper(new SetValueCommand(setReq));
179
	}
180
181
	/**
182
	 * @generated
183
	 */
184
	protected Command getCreateStartOutgoingUsage4009Command(CreateRelationshipRequest req) {
185
		if (!UMLBaseItemSemanticEditPolicy.LinkConstraints.Usage_4009.canCreateLink(req, false)) {
186
			return UnexecutableCommand.INSTANCE;
187
		}
188
		return new Command() {
189
		};
190
	}
191
192
	/**
193
	 * @generated
194
	 */
195
	protected Command getCreateCompleteIncomingUsage4009Command(CreateRelationshipRequest req) {
196
		if (!(req.getSource() instanceof NamedElement)) {
197
			return UnexecutableCommand.INSTANCE;
198
		}
199
		final org.eclipse.uml2.uml.Package element = (org.eclipse.uml2.uml.Package) getRelationshipContainer(req.getSource(), UMLPackage.eINSTANCE.getPackage(), req.getElementType());
200
		if (element == null) {
201
			return UnexecutableCommand.INSTANCE;
202
		}
203
		if (!UMLBaseItemSemanticEditPolicy.LinkConstraints.Usage_4009.canCreateLink(req, false)) {
204
			return UnexecutableCommand.INSTANCE;
205
		}
206
		if (req.getContainmentFeature() == null) {
207
			req.setContainmentFeature(UMLPackage.eINSTANCE.getPackage_PackagedElement());
208
		}
209
		return getMSLWrapper(new CreateIncomingUsage4009Command(req) {
210
211
			protected EObject getElementToEdit() {
212
				return element;
213
			}
214
		});
215
	}
216
217
	/**
218
	 * @generated
219
	 */
220
	private static class CreateIncomingUsage4009Command extends CreateRelationshipCommand {
221
222
		/**
223
		 * @generated
224
		 */
225
		public CreateIncomingUsage4009Command(CreateRelationshipRequest req) {
226
			super(req);
227
		}
228
229
		/**
230
		 * @generated
231
		 */
232
		protected EClass getEClassToEdit() {
233
			return UMLPackage.eINSTANCE.getPackage();
234
		};
235
236
		/**
237
		 * @generated
238
		 */
239
		protected void setElementToEdit(EObject element) {
240
			throw new UnsupportedOperationException();
241
		}
242
243
		/**
244
		 * @generated
245
		 */
246
		protected EObject doDefaultElementCreation() {
247
			Usage newElement = (Usage) super.doDefaultElementCreation();
248
			if (newElement != null) {
249
				newElement.getSuppliers().add((NamedElement) getTarget());
250
				newElement.getClients().add((NamedElement) getSource());
251
			}
252
			return newElement;
253
		}
254
	}
255
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/policies/GeneralizationItemSemanticEditPolicy.java (+18 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.policies;
2
3
import org.eclipse.gef.commands.Command;
4
import org.eclipse.gmf.runtime.emf.type.core.commands.DestroyElementCommand;
5
import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest;
6
7
/**
8
 * @generated
9
 */
10
public class GeneralizationItemSemanticEditPolicy extends UMLBaseItemSemanticEditPolicy {
11
12
	/**
13
	 * @generated
14
	 */
15
	protected Command getDestroyElementCommand(DestroyElementRequest req) {
16
		return getMSLWrapper(new DestroyElementCommand(req));
17
	}
18
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/policies/PackagePackagesItemSemanticEditPolicy.java (+72 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.policies;
2
3
import org.eclipse.emf.ecore.EClass;
4
import org.eclipse.emf.ecore.EObject;
5
import org.eclipse.gef.commands.Command;
6
import org.eclipse.gmf.runtime.emf.type.core.commands.CreateElementCommand;
7
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest;
8
import org.eclipse.gmf.runtime.notation.View;
9
import org.eclipse.uml2.diagram.clazz.providers.UMLElementTypes;
10
import org.eclipse.uml2.uml.UMLPackage;
11
12
/**
13
 * @generated
14
 */
15
public class PackagePackagesItemSemanticEditPolicy extends UMLBaseItemSemanticEditPolicy {
16
17
	/**
18
	 * @generated
19
	 */
20
	protected Command getCreateCommand(CreateElementRequest req) {
21
		if (UMLElementTypes.Package_3006 == req.getElementType()) {
22
			if (req.getContainmentFeature() == null) {
23
				req.setContainmentFeature(UMLPackage.eINSTANCE.getPackage_PackagedElement());
24
			}
25
			return getMSLWrapper(new CreatePackage_3006Command(req));
26
		}
27
		return super.getCreateCommand(req);
28
	}
29
30
	/**
31
	 * @generated
32
	 */
33
	private static class CreatePackage_3006Command extends CreateElementCommand {
34
35
		/**
36
		 * @generated
37
		 */
38
		public CreatePackage_3006Command(CreateElementRequest req) {
39
			super(req);
40
		}
41
42
		/**
43
		 * @generated
44
		 */
45
		protected EClass getEClassToEdit() {
46
			return UMLPackage.eINSTANCE.getPackage();
47
		};
48
49
		/**
50
		 * @generated
51
		 */
52
		protected EObject getElementToEdit() {
53
			EObject container = ((CreateElementRequest) getRequest()).getContainer();
54
			if (container instanceof View) {
55
				container = ((View) container).getElement();
56
			}
57
			return container;
58
		}
59
60
		/**
61
		 * @generated
62
		 */
63
		protected EObject doDefaultElementCreation() {
64
			org.eclipse.uml2.uml.Package newElement = (org.eclipse.uml2.uml.Package) super.doDefaultElementCreation();
65
			if (newElement != null) {
66
				UMLElementTypes.Initializers.Package_3006.init(newElement);
67
			}
68
			return newElement;
69
		}
70
	}
71
72
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/parts/InterfaceRealizationEditPart.java (+48 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.parts;
2
3
import org.eclipse.draw2d.Connection;
4
import org.eclipse.gmf.runtime.diagram.ui.editparts.ConnectionNodeEditPart;
5
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
6
import org.eclipse.gmf.runtime.draw2d.ui.figures.PolylineConnectionEx;
7
import org.eclipse.gmf.runtime.notation.View;
8
import org.eclipse.uml2.diagram.clazz.edit.policies.InterfaceRealizationItemSemanticEditPolicy;
9
10
/**
11
 * @generated
12
 */
13
public class InterfaceRealizationEditPart extends ConnectionNodeEditPart {
14
15
	/**
16
	 * @generated
17
	 */
18
	public static final int VISUAL_ID = 4008;
19
20
	/**
21
	 * @generated
22
	 */
23
	public InterfaceRealizationEditPart(View view) {
24
		super(view);
25
	}
26
27
	/**
28
	 * @generated
29
	 */
30
	protected void createDefaultEditPolicies() {
31
		super.createDefaultEditPolicies();
32
		installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new InterfaceRealizationItemSemanticEditPolicy());
33
34
	}
35
36
	/**
37
	 * Creates figure for this edit part.
38
	 * 
39
	 * Body of this method does not depend on settings in generation model
40
	 * so you may safely remove <i>generated</i> tag and modify it.
41
	 * 
42
	 * @generated
43
	 */
44
	protected Connection createConnectionFigure() {
45
		return new PolylineConnectionEx();
46
	}
47
48
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/parts/DataTypeAttributesEditPart.java (+67 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.parts;
2
3
import org.eclipse.emf.common.notify.Notification;
4
import org.eclipse.gef.EditPolicy;
5
import org.eclipse.gmf.runtime.diagram.ui.editparts.ListCompartmentEditPart;
6
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.CreationEditPolicy;
7
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.DragDropEditPolicy;
8
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
9
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.ResizableCompartmentEditPolicy;
10
import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout;
11
import org.eclipse.gmf.runtime.notation.View;
12
import org.eclipse.uml2.diagram.clazz.edit.policies.DataTypeAttributesCanonicalEditPolicy;
13
import org.eclipse.uml2.diagram.clazz.edit.policies.DataTypeAttributesItemSemanticEditPolicy;
14
15
/**
16
 * @generated
17
 */
18
public class DataTypeAttributesEditPart extends ListCompartmentEditPart {
19
20
	/**
21
	 * @generated
22
	 */
23
	public static final int VISUAL_ID = 7017;
24
25
	/**
26
	 * @generated
27
	 */
28
	public DataTypeAttributesEditPart(View view) {
29
		super(view);
30
	}
31
32
	/**
33
	 * @generated
34
	 */
35
	protected boolean hasModelChildrenChanged(Notification evt) {
36
		return false;
37
	}
38
39
	/**
40
	 * @generated
41
	 */
42
	public String getCompartmentName() {
43
		return "attributes";
44
	}
45
46
	/**
47
	 * @generated
48
	 */
49
	protected void createDefaultEditPolicies() {
50
		super.createDefaultEditPolicies();
51
		installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ResizableCompartmentEditPolicy());
52
		installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new DataTypeAttributesItemSemanticEditPolicy());
53
		installEditPolicy(EditPolicyRoles.CREATION_ROLE, new CreationEditPolicy());
54
		installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, new DragDropEditPolicy());
55
		installEditPolicy(EditPolicyRoles.CANONICAL_ROLE, new DataTypeAttributesCanonicalEditPolicy());
56
57
	}
58
59
	/**
60
	 * @generated
61
	 */
62
	protected void setRatio(Double ratio) {
63
		if (getFigure().getParent().getLayoutManager() instanceof ConstrainedToolbarLayout) {
64
			super.setRatio(ratio);
65
		}
66
	}
67
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/parts/Package3EditPart.java (+553 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.parts;
2
3
import java.util.Collections;
4
import java.util.List;
5
6
import org.eclipse.draw2d.IFigure;
7
import org.eclipse.draw2d.Label;
8
import org.eclipse.draw2d.geometry.Point;
9
import org.eclipse.emf.common.notify.Notification;
10
import org.eclipse.emf.ecore.EObject;
11
import org.eclipse.emf.transaction.RunnableWithResult;
12
import org.eclipse.gef.AccessibleEditPart;
13
import org.eclipse.gef.DragTracker;
14
import org.eclipse.gef.EditPolicy;
15
import org.eclipse.gef.Request;
16
import org.eclipse.gef.requests.DirectEditRequest;
17
import org.eclipse.gef.requests.SelectionRequest;
18
import org.eclipse.gef.tools.DirectEditManager;
19
import org.eclipse.gmf.runtime.common.ui.services.parser.IParser;
20
import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus;
21
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserEditStatus;
22
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions;
23
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserService;
24
import org.eclipse.gmf.runtime.diagram.ui.editparts.CompartmentEditPart;
25
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
26
import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart;
27
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
28
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy;
29
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.ListItemComponentEditPolicy;
30
import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry;
31
import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants;
32
import org.eclipse.gmf.runtime.diagram.ui.tools.DragEditPartsTrackerEx;
33
import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager;
34
import org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel;
35
import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
36
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
37
import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser;
38
import org.eclipse.gmf.runtime.emf.ui.services.parser.ParserHintAdapter;
39
import org.eclipse.gmf.runtime.notation.FontStyle;
40
import org.eclipse.gmf.runtime.notation.NotationPackage;
41
import org.eclipse.gmf.runtime.notation.View;
42
import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
43
import org.eclipse.jface.viewers.ICellEditorValidator;
44
import org.eclipse.swt.SWT;
45
import org.eclipse.swt.accessibility.AccessibleEvent;
46
import org.eclipse.swt.graphics.Color;
47
import org.eclipse.swt.graphics.FontData;
48
import org.eclipse.swt.graphics.Image;
49
import org.eclipse.uml2.diagram.clazz.edit.policies.Package3ItemSemanticEditPolicy;
50
import org.eclipse.uml2.diagram.clazz.edit.policies.UMLTextNonResizableEditPolicy;
51
import org.eclipse.uml2.diagram.clazz.edit.policies.UMLTextSelectionEditPolicy;
52
import org.eclipse.uml2.diagram.clazz.providers.UMLElementTypes;
53
54
/**
55
 * @generated
56
 */
57
public class Package3EditPart extends CompartmentEditPart implements ITextAwareEditPart {
58
59
	/**
60
	 * @generated
61
	 */
62
	public static final int VISUAL_ID = 3006;
63
64
	/**
65
	 * @generated
66
	 */
67
	private DirectEditManager manager;
68
69
	/**
70
	 * @generated
71
	 */
72
	private IParser parser;
73
74
	/**
75
	 * @generated
76
	 */
77
	private List parserElements;
78
79
	/**
80
	 * @generated
81
	 */
82
	private String defaultText;
83
84
	/**
85
	 * @generated
86
	 */
87
	public Package3EditPart(View view) {
88
		super(view);
89
	}
90
91
	/**
92
	 * @generated
93
	 */
94
	public DragTracker getDragTracker(Request request) {
95
		if (request instanceof SelectionRequest && ((SelectionRequest) request).getLastButtonPressed() == 3) {
96
			return null;
97
		}
98
		return new DragEditPartsTrackerEx(this);
99
	}
100
101
	/**
102
	 * @generated
103
	 */
104
	protected void createDefaultEditPolicies() {
105
		super.createDefaultEditPolicies();
106
		installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new Package3ItemSemanticEditPolicy());
107
		installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new UMLTextNonResizableEditPolicy());
108
		installEditPolicy(EditPolicy.COMPONENT_ROLE, new ListItemComponentEditPolicy());
109
		installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy());
110
111
	}
112
113
	/**
114
	 * @generated
115
	 */
116
	protected String getLabelTextHelper(IFigure figure) {
117
		if (figure instanceof WrapLabel) {
118
			return ((WrapLabel) figure).getText();
119
		} else {
120
			return ((Label) figure).getText();
121
		}
122
	}
123
124
	/**
125
	 * @generated
126
	 */
127
	protected void setLabelTextHelper(IFigure figure, String text) {
128
		if (figure instanceof WrapLabel) {
129
			((WrapLabel) figure).setText(text);
130
		} else {
131
			((Label) figure).setText(text);
132
		}
133
	}
134
135
	/**
136
	 * @generated
137
	 */
138
	protected Image getLabelIconHelper(IFigure figure) {
139
		if (figure instanceof WrapLabel) {
140
			return ((WrapLabel) figure).getIcon();
141
		} else {
142
			return ((Label) figure).getIcon();
143
		}
144
	}
145
146
	/**
147
	 * @generated
148
	 */
149
	protected void setLabelIconHelper(IFigure figure, Image icon) {
150
		if (figure instanceof WrapLabel) {
151
			((WrapLabel) figure).setIcon(icon);
152
		} else {
153
			((Label) figure).setIcon(icon);
154
		}
155
	}
156
157
	/**
158
	 * @generated
159
	 */
160
	public void setLabel(IFigure figure) {
161
		unregisterVisuals();
162
		setFigure(figure);
163
		defaultText = getLabelTextHelper(figure);
164
		registerVisuals();
165
		refreshVisuals();
166
	}
167
168
	/**
169
	 * @generated
170
	 */
171
	protected List getModelChildren() {
172
		return Collections.EMPTY_LIST;
173
	}
174
175
	/**
176
	 * @generated
177
	 */
178
	public IGraphicalEditPart getChildBySemanticHint(String semanticHint) {
179
		return null;
180
	}
181
182
	/**
183
	 * @generated
184
	 */
185
	protected EObject getParserElement() {
186
		EObject element = resolveSemanticElement();
187
		return element != null ? element : (View) getModel();
188
	}
189
190
	/**
191
	 * @generated
192
	 */
193
	protected Image getLabelIcon() {
194
		return null;
195
	}
196
197
	/**
198
	 * @generated
199
	 */
200
	protected String getLabelText() {
201
		String text = null;
202
		if (getParser() != null) {
203
			text = getParser().getPrintString(new EObjectAdapter(getParserElement()), getParserOptions().intValue());
204
		}
205
		if (text == null || text.length() == 0) {
206
			text = defaultText;
207
		}
208
		return text;
209
	}
210
211
	/**
212
	 * @generated
213
	 */
214
	public void setLabelText(String text) {
215
		setLabelTextHelper(getFigure(), text);
216
		Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
217
		if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) {
218
			((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback();
219
		}
220
	}
221
222
	/**
223
	 * @generated
224
	 */
225
	public String getEditText() {
226
		if (getParser() == null) {
227
			return ""; //$NON-NLS-1$
228
		}
229
		return getParser().getEditString(new EObjectAdapter(getParserElement()), getParserOptions().intValue());
230
	}
231
232
	/**
233
	 * @generated
234
	 */
235
	protected boolean isEditable() {
236
		return getEditText() != null;
237
	}
238
239
	/**
240
	 * @generated
241
	 */
242
	public ICellEditorValidator getEditTextValidator() {
243
		return new ICellEditorValidator() {
244
245
			public String isValid(final Object value) {
246
				if (value instanceof String) {
247
					final EObject element = getParserElement();
248
					final IParser parser = getParser();
249
					try {
250
						IParserEditStatus valid = (IParserEditStatus) getEditingDomain().runExclusive(new RunnableWithResult.Impl() {
251
252
							public void run() {
253
								setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value));
254
							}
255
						});
256
						return valid.getCode() == ParserEditStatus.EDITABLE ? null : valid.getMessage();
257
					} catch (InterruptedException ie) {
258
						ie.printStackTrace();
259
					}
260
				}
261
262
				// shouldn't get here
263
				return null;
264
			}
265
		};
266
	}
267
268
	/**
269
	 * @generated
270
	 */
271
	public IContentAssistProcessor getCompletionProcessor() {
272
		if (getParser() == null) {
273
			return null;
274
		}
275
		return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement()));
276
	}
277
278
	/**
279
	 * @generated
280
	 */
281
	public ParserOptions getParserOptions() {
282
		return ParserOptions.NONE;
283
	}
284
285
	/**
286
	 * @generated
287
	 */
288
	public IParser getParser() {
289
		if (parser == null) {
290
			String parserHint = ((View) getModel()).getType();
291
			ParserHintAdapter hintAdapter = new ParserHintAdapter(getParserElement(), parserHint) {
292
293
				public Object getAdapter(Class adapter) {
294
					if (IElementType.class.equals(adapter)) {
295
						return UMLElementTypes.Package_3006;
296
					}
297
					return super.getAdapter(adapter);
298
				}
299
			};
300
			parser = ParserService.getInstance().getParser(hintAdapter);
301
		}
302
		return parser;
303
	}
304
305
	/**
306
	 * @generated
307
	 */
308
	protected DirectEditManager getManager() {
309
		if (manager == null) {
310
			setManager(new TextDirectEditManager(this, TextDirectEditManager.getTextCellEditorClass(this), UMLEditPartFactory.getTextCellEditorLocator(this)));
311
		}
312
		return manager;
313
	}
314
315
	/**
316
	 * @generated
317
	 */
318
	protected void setManager(DirectEditManager manager) {
319
		this.manager = manager;
320
	}
321
322
	/**
323
	 * @generated
324
	 */
325
	protected void performDirectEdit() {
326
		getManager().show();
327
	}
328
329
	/**
330
	 * @generated
331
	 */
332
	protected void performDirectEdit(Point eventLocation) {
333
		if (getManager().getClass() == TextDirectEditManager.class) {
334
			((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint());
335
		}
336
	}
337
338
	/**
339
	 * @generated
340
	 */
341
	private void performDirectEdit(char initialCharacter) {
342
		if (getManager() instanceof TextDirectEditManager) {
343
			((TextDirectEditManager) getManager()).show(initialCharacter);
344
		} else {
345
			performDirectEdit();
346
		}
347
	}
348
349
	/**
350
	 * @generated
351
	 */
352
	protected void performDirectEditRequest(Request request) {
353
		final Request theRequest = request;
354
		try {
355
			getEditingDomain().runExclusive(new Runnable() {
356
357
				public void run() {
358
					if (isActive() && isEditable()) {
359
						if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) {
360
							Character initialChar = (Character) theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR);
361
							performDirectEdit(initialChar.charValue());
362
						} else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) {
363
							DirectEditRequest editRequest = (DirectEditRequest) theRequest;
364
							performDirectEdit(editRequest.getLocation());
365
						} else {
366
							performDirectEdit();
367
						}
368
					}
369
				}
370
			});
371
		} catch (InterruptedException e) {
372
			e.printStackTrace();
373
		}
374
	}
375
376
	/**
377
	 * @generated
378
	 */
379
	protected void refreshVisuals() {
380
		super.refreshVisuals();
381
		refreshLabel();
382
		refreshFont();
383
		refreshFontColor();
384
		refreshUnderline();
385
		refreshStrikeThrough();
386
	}
387
388
	/**
389
	 * @generated
390
	 */
391
	protected void refreshLabel() {
392
		setLabelTextHelper(getFigure(), getLabelText());
393
		setLabelIconHelper(getFigure(), getLabelIcon());
394
		Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
395
		if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) {
396
			((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback();
397
		}
398
	}
399
400
	/**
401
	 * @generated
402
	 */
403
	protected void refreshUnderline() {
404
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
405
		if (style != null && getFigure() instanceof WrapLabel) {
406
			((WrapLabel) getFigure()).setTextUnderline(style.isUnderline());
407
		}
408
	}
409
410
	/**
411
	 * @generated
412
	 */
413
	protected void refreshStrikeThrough() {
414
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
415
		if (style != null && getFigure() instanceof WrapLabel) {
416
			((WrapLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough());
417
		}
418
	}
419
420
	/**
421
	 * @generated
422
	 */
423
	protected void refreshFont() {
424
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
425
		if (style != null) {
426
			FontData fontData = new FontData(style.getFontName(), style.getFontHeight(), (style.isBold() ? SWT.BOLD : SWT.NORMAL) | (style.isItalic() ? SWT.ITALIC : SWT.NORMAL));
427
			setFont(fontData);
428
		}
429
	}
430
431
	/**
432
	 * @generated
433
	 */
434
	protected void setFontColor(Color color) {
435
		getFigure().setForegroundColor(color);
436
	}
437
438
	/**
439
	 * @generated
440
	 */
441
	protected void addSemanticListeners() {
442
		if (getParser() instanceof ISemanticParser) {
443
			EObject element = resolveSemanticElement();
444
			parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element);
445
			for (int i = 0; i < parserElements.size(); i++) {
446
				addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$
447
			}
448
		} else {
449
			super.addSemanticListeners();
450
		}
451
	}
452
453
	/**
454
	 * @generated
455
	 */
456
	protected void removeSemanticListeners() {
457
		if (parserElements != null) {
458
			for (int i = 0; i < parserElements.size(); i++) {
459
				removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$
460
			}
461
		} else {
462
			super.removeSemanticListeners();
463
		}
464
	}
465
466
	/**
467
	 * @generated
468
	 */
469
	protected AccessibleEditPart getAccessibleEditPart() {
470
		if (accessibleEP == null) {
471
			accessibleEP = new AccessibleGraphicalEditPart() {
472
473
				public void getName(AccessibleEvent e) {
474
					e.result = getLabelTextHelper(getFigure());
475
				}
476
			};
477
		}
478
		return accessibleEP;
479
	}
480
481
	/**
482
	 * @generated
483
	 */
484
	private View getFontStyleOwnerView() {
485
		return getPrimaryView();
486
	}
487
488
	/**
489
	 * @generated
490
	 */
491
	protected void addNotationalListeners() {
492
		super.addNotationalListeners();
493
		addListenerFilter("PrimaryView", this, getPrimaryView()); //$NON-NLS-1$
494
	}
495
496
	/**
497
	 * @generated
498
	 */
499
	protected void removeNotationalListeners() {
500
		super.removeNotationalListeners();
501
		removeListenerFilter("PrimaryView"); //$NON-NLS-1$
502
	}
503
504
	/**
505
	 * @generated
506
	 */
507
	protected void handleNotificationEvent(Notification event) {
508
		Object feature = event.getFeature();
509
		if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) {
510
			Integer c = (Integer) event.getNewValue();
511
			setFontColor(DiagramColorRegistry.getInstance().getColor(c));
512
		} else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) {
513
			refreshUnderline();
514
		} else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) {
515
			refreshStrikeThrough();
516
		} else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature)
517
				|| NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) {
518
			refreshFont();
519
		} else {
520
			if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) {
521
				refreshLabel();
522
			}
523
			if (getParser() instanceof ISemanticParser) {
524
				ISemanticParser modelParser = (ISemanticParser) getParser();
525
				if (modelParser.areSemanticElementsAffected(null, event)) {
526
					removeSemanticListeners();
527
					if (resolveSemanticElement() != null) {
528
						addSemanticListeners();
529
					}
530
					refreshLabel();
531
				}
532
			}
533
		}
534
		super.handleNotificationEvent(event);
535
	}
536
537
	/**
538
	 * @generated
539
	 */
540
	protected IFigure createFigure() {
541
		IFigure label = createFigurePrim();
542
		defaultText = getLabelTextHelper(label);
543
		return label;
544
	}
545
546
	/**
547
	 * @generated
548
	 */
549
	protected IFigure createFigurePrim() {
550
		return new WrapLabel();
551
	}
552
553
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/policies/AssociationClassAttributesItemSemanticEditPolicy.java (+73 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.policies;
2
3
import org.eclipse.emf.ecore.EClass;
4
import org.eclipse.emf.ecore.EObject;
5
import org.eclipse.gef.commands.Command;
6
import org.eclipse.gmf.runtime.emf.type.core.commands.CreateElementCommand;
7
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest;
8
import org.eclipse.gmf.runtime.notation.View;
9
import org.eclipse.uml2.diagram.clazz.providers.UMLElementTypes;
10
import org.eclipse.uml2.uml.Property;
11
import org.eclipse.uml2.uml.UMLPackage;
12
13
/**
14
 * @generated
15
 */
16
public class AssociationClassAttributesItemSemanticEditPolicy extends UMLBaseItemSemanticEditPolicy {
17
18
	/**
19
	 * @generated
20
	 */
21
	protected Command getCreateCommand(CreateElementRequest req) {
22
		if (UMLElementTypes.Property_3019 == req.getElementType()) {
23
			if (req.getContainmentFeature() == null) {
24
				req.setContainmentFeature(UMLPackage.eINSTANCE.getStructuredClassifier_OwnedAttribute());
25
			}
26
			return getMSLWrapper(new CreateProperty_3019Command(req));
27
		}
28
		return super.getCreateCommand(req);
29
	}
30
31
	/**
32
	 * @generated
33
	 */
34
	private static class CreateProperty_3019Command extends CreateElementCommand {
35
36
		/**
37
		 * @generated
38
		 */
39
		public CreateProperty_3019Command(CreateElementRequest req) {
40
			super(req);
41
		}
42
43
		/**
44
		 * @generated
45
		 */
46
		protected EClass getEClassToEdit() {
47
			return UMLPackage.eINSTANCE.getAssociationClass();
48
		};
49
50
		/**
51
		 * @generated
52
		 */
53
		protected EObject getElementToEdit() {
54
			EObject container = ((CreateElementRequest) getRequest()).getContainer();
55
			if (container instanceof View) {
56
				container = ((View) container).getElement();
57
			}
58
			return container;
59
		}
60
61
		/**
62
		 * @generated
63
		 */
64
		protected EObject doDefaultElementCreation() {
65
			Property newElement = (Property) super.doDefaultElementCreation();
66
			if (newElement != null) {
67
				UMLElementTypes.Initializers.Property_3019.init(newElement);
68
			}
69
			return newElement;
70
		}
71
	}
72
73
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/parts/AssociationName6EditPart.java (+533 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.parts;
2
3
import java.util.Collections;
4
import java.util.List;
5
6
import org.eclipse.draw2d.ConnectionLocator;
7
import org.eclipse.draw2d.IFigure;
8
import org.eclipse.draw2d.Label;
9
import org.eclipse.draw2d.geometry.Point;
10
import org.eclipse.emf.common.notify.Notification;
11
import org.eclipse.emf.ecore.EObject;
12
import org.eclipse.emf.transaction.RunnableWithResult;
13
import org.eclipse.gef.AccessibleEditPart;
14
import org.eclipse.gef.EditPolicy;
15
import org.eclipse.gef.Request;
16
import org.eclipse.gef.requests.DirectEditRequest;
17
import org.eclipse.gef.tools.DirectEditManager;
18
import org.eclipse.gmf.runtime.common.ui.services.parser.IParser;
19
import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus;
20
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserEditStatus;
21
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions;
22
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserService;
23
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
24
import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart;
25
import org.eclipse.gmf.runtime.diagram.ui.editparts.LabelEditPart;
26
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy;
27
import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry;
28
import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants;
29
import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager;
30
import org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel;
31
import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
32
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
33
import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser;
34
import org.eclipse.gmf.runtime.emf.ui.services.parser.ParserHintAdapter;
35
import org.eclipse.gmf.runtime.notation.FontStyle;
36
import org.eclipse.gmf.runtime.notation.NotationPackage;
37
import org.eclipse.gmf.runtime.notation.View;
38
import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
39
import org.eclipse.jface.viewers.ICellEditorValidator;
40
import org.eclipse.swt.SWT;
41
import org.eclipse.swt.accessibility.AccessibleEvent;
42
import org.eclipse.swt.graphics.Color;
43
import org.eclipse.swt.graphics.FontData;
44
import org.eclipse.swt.graphics.Image;
45
import org.eclipse.uml2.diagram.clazz.edit.policies.UMLTextSelectionEditPolicy;
46
import org.eclipse.uml2.diagram.clazz.part.UMLVisualIDRegistry;
47
import org.eclipse.uml2.diagram.clazz.providers.UMLElementTypes;
48
49
/**
50
 * @generated
51
 */
52
public class AssociationName6EditPart extends LabelEditPart implements ITextAwareEditPart {
53
54
	/**
55
	 * @generated
56
	 */
57
	public static final int VISUAL_ID = 6008;
58
59
	/**
60
	 * @generated
61
	 */
62
	private DirectEditManager manager;
63
64
	/**
65
	 * @generated
66
	 */
67
	private IParser parser;
68
69
	/**
70
	 * @generated
71
	 */
72
	private List parserElements;
73
74
	/**
75
	 * @generated
76
	 */
77
	private String defaultText;
78
79
	/**
80
	 * @generated
81
	 */
82
	static {
83
		registerSnapBackPosition(UMLVisualIDRegistry.getType(AssociationName6EditPart.VISUAL_ID), new Point(0, 15));
84
	}
85
86
	/**
87
	 * @generated
88
	 */
89
	public AssociationName6EditPart(View view) {
90
		super(view);
91
	}
92
93
	/**
94
	 * @generated
95
	 */
96
	protected void createDefaultEditPolicies() {
97
		super.createDefaultEditPolicies();
98
		installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy());
99
100
	}
101
102
	/**
103
	 * @generated
104
	 */
105
	public int getKeyPoint() {
106
		return ConnectionLocator.TARGET;
107
	}
108
109
	/**
110
	 * @generated
111
	 */
112
	protected String getLabelTextHelper(IFigure figure) {
113
		if (figure instanceof WrapLabel) {
114
			return ((WrapLabel) figure).getText();
115
		} else {
116
			return ((Label) figure).getText();
117
		}
118
	}
119
120
	/**
121
	 * @generated
122
	 */
123
	protected void setLabelTextHelper(IFigure figure, String text) {
124
		if (figure instanceof WrapLabel) {
125
			((WrapLabel) figure).setText(text);
126
		} else {
127
			((Label) figure).setText(text);
128
		}
129
	}
130
131
	/**
132
	 * @generated
133
	 */
134
	protected Image getLabelIconHelper(IFigure figure) {
135
		if (figure instanceof WrapLabel) {
136
			return ((WrapLabel) figure).getIcon();
137
		} else {
138
			return ((Label) figure).getIcon();
139
		}
140
	}
141
142
	/**
143
	 * @generated
144
	 */
145
	protected void setLabelIconHelper(IFigure figure, Image icon) {
146
		if (figure instanceof WrapLabel) {
147
			((WrapLabel) figure).setIcon(icon);
148
		} else {
149
			((Label) figure).setIcon(icon);
150
		}
151
	}
152
153
	/**
154
	 * @generated
155
	 */
156
	public void setLabel(IFigure figure) {
157
		unregisterVisuals();
158
		setFigure(figure);
159
		defaultText = getLabelTextHelper(figure);
160
		registerVisuals();
161
		refreshVisuals();
162
	}
163
164
	/**
165
	 * @generated
166
	 */
167
	protected List getModelChildren() {
168
		return Collections.EMPTY_LIST;
169
	}
170
171
	/**
172
	 * @generated
173
	 */
174
	public IGraphicalEditPart getChildBySemanticHint(String semanticHint) {
175
		return null;
176
	}
177
178
	/**
179
	 * @generated
180
	 */
181
	protected EObject getParserElement() {
182
		EObject element = resolveSemanticElement();
183
		return element != null ? element : (View) getModel();
184
	}
185
186
	/**
187
	 * @generated
188
	 */
189
	protected Image getLabelIcon() {
190
		return null;
191
	}
192
193
	/**
194
	 * @generated
195
	 */
196
	protected String getLabelText() {
197
		String text = null;
198
		if (getParser() != null) {
199
			text = getParser().getPrintString(new EObjectAdapter(getParserElement()), getParserOptions().intValue());
200
		}
201
		if (text == null || text.length() == 0) {
202
			text = defaultText;
203
		}
204
		return text;
205
	}
206
207
	/**
208
	 * @generated
209
	 */
210
	public void setLabelText(String text) {
211
		setLabelTextHelper(getFigure(), text);
212
		Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
213
		if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) {
214
			((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback();
215
		}
216
	}
217
218
	/**
219
	 * @generated
220
	 */
221
	public String getEditText() {
222
		if (getParser() == null) {
223
			return ""; //$NON-NLS-1$
224
		}
225
		return getParser().getEditString(new EObjectAdapter(getParserElement()), getParserOptions().intValue());
226
	}
227
228
	/**
229
	 * @generated
230
	 */
231
	protected boolean isEditable() {
232
		return getEditText() != null;
233
	}
234
235
	/**
236
	 * @generated
237
	 */
238
	public ICellEditorValidator getEditTextValidator() {
239
		return new ICellEditorValidator() {
240
241
			public String isValid(final Object value) {
242
				if (value instanceof String) {
243
					final EObject element = getParserElement();
244
					final IParser parser = getParser();
245
					try {
246
						IParserEditStatus valid = (IParserEditStatus) getEditingDomain().runExclusive(new RunnableWithResult.Impl() {
247
248
							public void run() {
249
								setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value));
250
							}
251
						});
252
						return valid.getCode() == ParserEditStatus.EDITABLE ? null : valid.getMessage();
253
					} catch (InterruptedException ie) {
254
						ie.printStackTrace();
255
					}
256
				}
257
258
				// shouldn't get here
259
				return null;
260
			}
261
		};
262
	}
263
264
	/**
265
	 * @generated
266
	 */
267
	public IContentAssistProcessor getCompletionProcessor() {
268
		if (getParser() == null) {
269
			return null;
270
		}
271
		return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement()));
272
	}
273
274
	/**
275
	 * @generated
276
	 */
277
	public ParserOptions getParserOptions() {
278
		return ParserOptions.NONE;
279
	}
280
281
	/**
282
	 * @generated
283
	 */
284
	public IParser getParser() {
285
		if (parser == null) {
286
			String parserHint = ((View) getModel()).getType();
287
			ParserHintAdapter hintAdapter = new ParserHintAdapter(getParserElement(), parserHint) {
288
289
				public Object getAdapter(Class adapter) {
290
					if (IElementType.class.equals(adapter)) {
291
						return UMLElementTypes.Association_4005;
292
					}
293
					return super.getAdapter(adapter);
294
				}
295
			};
296
			parser = ParserService.getInstance().getParser(hintAdapter);
297
		}
298
		return parser;
299
	}
300
301
	/**
302
	 * @generated
303
	 */
304
	protected DirectEditManager getManager() {
305
		if (manager == null) {
306
			setManager(new TextDirectEditManager(this, TextDirectEditManager.getTextCellEditorClass(this), UMLEditPartFactory.getTextCellEditorLocator(this)));
307
		}
308
		return manager;
309
	}
310
311
	/**
312
	 * @generated
313
	 */
314
	protected void setManager(DirectEditManager manager) {
315
		this.manager = manager;
316
	}
317
318
	/**
319
	 * @generated
320
	 */
321
	protected void performDirectEdit() {
322
		getManager().show();
323
	}
324
325
	/**
326
	 * @generated
327
	 */
328
	protected void performDirectEdit(Point eventLocation) {
329
		if (getManager().getClass() == TextDirectEditManager.class) {
330
			((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint());
331
		}
332
	}
333
334
	/**
335
	 * @generated
336
	 */
337
	private void performDirectEdit(char initialCharacter) {
338
		if (getManager() instanceof TextDirectEditManager) {
339
			((TextDirectEditManager) getManager()).show(initialCharacter);
340
		} else {
341
			performDirectEdit();
342
		}
343
	}
344
345
	/**
346
	 * @generated
347
	 */
348
	protected void performDirectEditRequest(Request request) {
349
		final Request theRequest = request;
350
		try {
351
			getEditingDomain().runExclusive(new Runnable() {
352
353
				public void run() {
354
					if (isActive() && isEditable()) {
355
						if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) {
356
							Character initialChar = (Character) theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR);
357
							performDirectEdit(initialChar.charValue());
358
						} else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) {
359
							DirectEditRequest editRequest = (DirectEditRequest) theRequest;
360
							performDirectEdit(editRequest.getLocation());
361
						} else {
362
							performDirectEdit();
363
						}
364
					}
365
				}
366
			});
367
		} catch (InterruptedException e) {
368
			e.printStackTrace();
369
		}
370
	}
371
372
	/**
373
	 * @generated
374
	 */
375
	protected void refreshVisuals() {
376
		super.refreshVisuals();
377
		refreshLabel();
378
		refreshFont();
379
		refreshFontColor();
380
		refreshUnderline();
381
		refreshStrikeThrough();
382
	}
383
384
	/**
385
	 * @generated
386
	 */
387
	protected void refreshLabel() {
388
		setLabelTextHelper(getFigure(), getLabelText());
389
		setLabelIconHelper(getFigure(), getLabelIcon());
390
		Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
391
		if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) {
392
			((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback();
393
		}
394
	}
395
396
	/**
397
	 * @generated
398
	 */
399
	protected void refreshUnderline() {
400
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
401
		if (style != null && getFigure() instanceof WrapLabel) {
402
			((WrapLabel) getFigure()).setTextUnderline(style.isUnderline());
403
		}
404
	}
405
406
	/**
407
	 * @generated
408
	 */
409
	protected void refreshStrikeThrough() {
410
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
411
		if (style != null && getFigure() instanceof WrapLabel) {
412
			((WrapLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough());
413
		}
414
	}
415
416
	/**
417
	 * @generated
418
	 */
419
	protected void refreshFont() {
420
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
421
		if (style != null) {
422
			FontData fontData = new FontData(style.getFontName(), style.getFontHeight(), (style.isBold() ? SWT.BOLD : SWT.NORMAL) | (style.isItalic() ? SWT.ITALIC : SWT.NORMAL));
423
			setFont(fontData);
424
		}
425
	}
426
427
	/**
428
	 * @generated
429
	 */
430
	protected void setFontColor(Color color) {
431
		getFigure().setForegroundColor(color);
432
	}
433
434
	/**
435
	 * @generated
436
	 */
437
	protected void addSemanticListeners() {
438
		if (getParser() instanceof ISemanticParser) {
439
			EObject element = resolveSemanticElement();
440
			parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element);
441
			for (int i = 0; i < parserElements.size(); i++) {
442
				addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$
443
			}
444
		} else {
445
			super.addSemanticListeners();
446
		}
447
	}
448
449
	/**
450
	 * @generated
451
	 */
452
	protected void removeSemanticListeners() {
453
		if (parserElements != null) {
454
			for (int i = 0; i < parserElements.size(); i++) {
455
				removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$
456
			}
457
		} else {
458
			super.removeSemanticListeners();
459
		}
460
	}
461
462
	/**
463
	 * @generated
464
	 */
465
	protected AccessibleEditPart getAccessibleEditPart() {
466
		if (accessibleEP == null) {
467
			accessibleEP = new AccessibleGraphicalEditPart() {
468
469
				public void getName(AccessibleEvent e) {
470
					e.result = getLabelTextHelper(getFigure());
471
				}
472
			};
473
		}
474
		return accessibleEP;
475
	}
476
477
	/**
478
	 * @generated
479
	 */
480
	private View getFontStyleOwnerView() {
481
		return getPrimaryView();
482
	}
483
484
	/**
485
	 * @generated
486
	 */
487
	protected void handleNotificationEvent(Notification event) {
488
		Object feature = event.getFeature();
489
		if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) {
490
			Integer c = (Integer) event.getNewValue();
491
			setFontColor(DiagramColorRegistry.getInstance().getColor(c));
492
		} else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) {
493
			refreshUnderline();
494
		} else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) {
495
			refreshStrikeThrough();
496
		} else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature)
497
				|| NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) {
498
			refreshFont();
499
		} else {
500
			if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) {
501
				refreshLabel();
502
			}
503
			if (getParser() instanceof ISemanticParser) {
504
				ISemanticParser modelParser = (ISemanticParser) getParser();
505
				if (modelParser.areSemanticElementsAffected(null, event)) {
506
					removeSemanticListeners();
507
					if (resolveSemanticElement() != null) {
508
						addSemanticListeners();
509
					}
510
					refreshLabel();
511
				}
512
			}
513
		}
514
		super.handleNotificationEvent(event);
515
	}
516
517
	/**
518
	 * @generated
519
	 */
520
	protected IFigure createFigure() {
521
		IFigure label = createFigurePrim();
522
		defaultText = getLabelTextHelper(label);
523
		return label;
524
	}
525
526
	/**
527
	 * @generated
528
	 */
529
	protected IFigure createFigurePrim() {
530
		return new WrapLabel();
531
	}
532
533
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/policies/PropertyItemSemanticEditPolicy.java (+255 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.policies;
2
3
import org.eclipse.emf.ecore.EAnnotation;
4
import org.eclipse.emf.ecore.EClass;
5
import org.eclipse.emf.ecore.EObject;
6
import org.eclipse.gef.commands.Command;
7
import org.eclipse.gef.commands.UnexecutableCommand;
8
import org.eclipse.gmf.runtime.emf.type.core.commands.CreateRelationshipCommand;
9
import org.eclipse.gmf.runtime.emf.type.core.commands.DestroyElementCommand;
10
import org.eclipse.gmf.runtime.emf.type.core.commands.SetValueCommand;
11
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest;
12
import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest;
13
import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest;
14
import org.eclipse.gmf.runtime.notation.View;
15
import org.eclipse.uml2.diagram.clazz.providers.UMLElementTypes;
16
import org.eclipse.uml2.uml.Constraint;
17
import org.eclipse.uml2.uml.Dependency;
18
import org.eclipse.uml2.uml.NamedElement;
19
import org.eclipse.uml2.uml.UMLPackage;
20
import org.eclipse.uml2.uml.Usage;
21
22
/**
23
 * @generated
24
 */
25
public class PropertyItemSemanticEditPolicy extends UMLBaseItemSemanticEditPolicy {
26
27
	/**
28
	 * @generated
29
	 */
30
	protected Command getDestroyElementCommand(DestroyElementRequest req) {
31
		return getMSLWrapper(new DestroyElementCommand(req) {
32
33
			protected EObject getElementToDestroy() {
34
				View view = (View) getHost().getModel();
35
				EAnnotation annotation = view.getEAnnotation("Shortcut"); //$NON-NLS-1$
36
				if (annotation != null) {
37
					return view;
38
				}
39
				return super.getElementToDestroy();
40
			}
41
42
		});
43
	}
44
45
	/**
46
	 * @generated
47
	 */
48
	protected Command getCreateRelationshipCommand(CreateRelationshipRequest req) {
49
		if (UMLElementTypes.Dependency_4002 == req.getElementType()) {
50
			return req.getTarget() == null ? getCreateStartOutgoingDependency4002Command(req) : getCreateCompleteIncomingDependency4002Command(req);
51
		}
52
		if (UMLElementTypes.ConstraintConstrainedElement_4004 == req.getElementType()) {
53
			return req.getTarget() == null ? null : getCreateCompleteIncomingConstraint_ConstrainedElement4004Command(req);
54
		}
55
		if (UMLElementTypes.DependencySupplier_4006 == req.getElementType()) {
56
			return req.getTarget() == null ? null : getCreateCompleteIncomingDependency_Supplier4006Command(req);
57
		}
58
		if (UMLElementTypes.DependencyClient_4007 == req.getElementType()) {
59
			return req.getTarget() == null ? null : getCreateCompleteIncomingDependency_Client4007Command(req);
60
		}
61
		if (UMLElementTypes.Usage_4009 == req.getElementType()) {
62
			return req.getTarget() == null ? getCreateStartOutgoingUsage4009Command(req) : getCreateCompleteIncomingUsage4009Command(req);
63
		}
64
		return super.getCreateRelationshipCommand(req);
65
	}
66
67
	/**
68
	 * @generated
69
	 */
70
	protected Command getCreateStartOutgoingDependency4002Command(CreateRelationshipRequest req) {
71
		return new Command() {
72
		};
73
	}
74
75
	/**
76
	 * @generated
77
	 */
78
	protected Command getCreateCompleteIncomingDependency4002Command(CreateRelationshipRequest req) {
79
		if (!(req.getSource() instanceof NamedElement)) {
80
			return UnexecutableCommand.INSTANCE;
81
		}
82
		final org.eclipse.uml2.uml.Package element = (org.eclipse.uml2.uml.Package) getRelationshipContainer(req.getSource(), UMLPackage.eINSTANCE.getPackage(), req.getElementType());
83
		if (element == null) {
84
			return UnexecutableCommand.INSTANCE;
85
		}
86
		if (req.getContainmentFeature() == null) {
87
			req.setContainmentFeature(UMLPackage.eINSTANCE.getPackage_PackagedElement());
88
		}
89
		return getMSLWrapper(new CreateIncomingDependency4002Command(req) {
90
91
			protected EObject getElementToEdit() {
92
				return element;
93
			}
94
		});
95
	}
96
97
	/**
98
	 * @generated
99
	 */
100
	private static class CreateIncomingDependency4002Command extends CreateRelationshipCommand {
101
102
		/**
103
		 * @generated
104
		 */
105
		public CreateIncomingDependency4002Command(CreateRelationshipRequest req) {
106
			super(req);
107
		}
108
109
		/**
110
		 * @generated
111
		 */
112
		protected EClass getEClassToEdit() {
113
			return UMLPackage.eINSTANCE.getPackage();
114
		};
115
116
		/**
117
		 * @generated
118
		 */
119
		protected void setElementToEdit(EObject element) {
120
			throw new UnsupportedOperationException();
121
		}
122
123
		/**
124
		 * @generated
125
		 */
126
		protected EObject doDefaultElementCreation() {
127
			Dependency newElement = (Dependency) super.doDefaultElementCreation();
128
			if (newElement != null) {
129
				newElement.getSuppliers().add((NamedElement) getTarget());
130
				newElement.getClients().add((NamedElement) getSource());
131
			}
132
			return newElement;
133
		}
134
	}
135
136
	/**
137
	 * @generated
138
	 */
139
	protected Command getCreateCompleteIncomingConstraint_ConstrainedElement4004Command(CreateRelationshipRequest req) {
140
		if (!(req.getSource() instanceof Constraint)) {
141
			return UnexecutableCommand.INSTANCE;
142
		}
143
		Constraint element = (Constraint) req.getSource();
144
		if (element.getConstrainedElements().contains(req.getTarget())) {
145
			return UnexecutableCommand.INSTANCE;
146
		}
147
		SetRequest setReq = new SetRequest(req.getSource(), UMLPackage.eINSTANCE.getConstraint_ConstrainedElement(), req.getTarget());
148
		return getMSLWrapper(new SetValueCommand(setReq));
149
	}
150
151
	/**
152
	 * @generated
153
	 */
154
	protected Command getCreateCompleteIncomingDependency_Supplier4006Command(CreateRelationshipRequest req) {
155
		if (!(req.getSource() instanceof Dependency)) {
156
			return UnexecutableCommand.INSTANCE;
157
		}
158
		Dependency element = (Dependency) req.getSource();
159
		if (element.getSuppliers().contains(req.getTarget())) {
160
			return UnexecutableCommand.INSTANCE;
161
		}
162
		SetRequest setReq = new SetRequest(req.getSource(), UMLPackage.eINSTANCE.getDependency_Supplier(), req.getTarget());
163
		return getMSLWrapper(new SetValueCommand(setReq));
164
	}
165
166
	/**
167
	 * @generated
168
	 */
169
	protected Command getCreateCompleteIncomingDependency_Client4007Command(CreateRelationshipRequest req) {
170
		if (!(req.getSource() instanceof Dependency)) {
171
			return UnexecutableCommand.INSTANCE;
172
		}
173
		Dependency element = (Dependency) req.getSource();
174
		if (element.getClients().contains(req.getTarget())) {
175
			return UnexecutableCommand.INSTANCE;
176
		}
177
		SetRequest setReq = new SetRequest(req.getSource(), UMLPackage.eINSTANCE.getDependency_Client(), req.getTarget());
178
		return getMSLWrapper(new SetValueCommand(setReq));
179
	}
180
181
	/**
182
	 * @generated
183
	 */
184
	protected Command getCreateStartOutgoingUsage4009Command(CreateRelationshipRequest req) {
185
		if (!UMLBaseItemSemanticEditPolicy.LinkConstraints.Usage_4009.canCreateLink(req, false)) {
186
			return UnexecutableCommand.INSTANCE;
187
		}
188
		return new Command() {
189
		};
190
	}
191
192
	/**
193
	 * @generated
194
	 */
195
	protected Command getCreateCompleteIncomingUsage4009Command(CreateRelationshipRequest req) {
196
		if (!(req.getSource() instanceof NamedElement)) {
197
			return UnexecutableCommand.INSTANCE;
198
		}
199
		final org.eclipse.uml2.uml.Package element = (org.eclipse.uml2.uml.Package) getRelationshipContainer(req.getSource(), UMLPackage.eINSTANCE.getPackage(), req.getElementType());
200
		if (element == null) {
201
			return UnexecutableCommand.INSTANCE;
202
		}
203
		if (!UMLBaseItemSemanticEditPolicy.LinkConstraints.Usage_4009.canCreateLink(req, false)) {
204
			return UnexecutableCommand.INSTANCE;
205
		}
206
		if (req.getContainmentFeature() == null) {
207
			req.setContainmentFeature(UMLPackage.eINSTANCE.getPackage_PackagedElement());
208
		}
209
		return getMSLWrapper(new CreateIncomingUsage4009Command(req) {
210
211
			protected EObject getElementToEdit() {
212
				return element;
213
			}
214
		});
215
	}
216
217
	/**
218
	 * @generated
219
	 */
220
	private static class CreateIncomingUsage4009Command extends CreateRelationshipCommand {
221
222
		/**
223
		 * @generated
224
		 */
225
		public CreateIncomingUsage4009Command(CreateRelationshipRequest req) {
226
			super(req);
227
		}
228
229
		/**
230
		 * @generated
231
		 */
232
		protected EClass getEClassToEdit() {
233
			return UMLPackage.eINSTANCE.getPackage();
234
		};
235
236
		/**
237
		 * @generated
238
		 */
239
		protected void setElementToEdit(EObject element) {
240
			throw new UnsupportedOperationException();
241
		}
242
243
		/**
244
		 * @generated
245
		 */
246
		protected EObject doDefaultElementCreation() {
247
			Usage newElement = (Usage) super.doDefaultElementCreation();
248
			if (newElement != null) {
249
				newElement.getSuppliers().add((NamedElement) getTarget());
250
				newElement.getClients().add((NamedElement) getSource());
251
			}
252
			return newElement;
253
		}
254
	}
255
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/policies/DataTypeAttributesCanonicalEditPolicy.java (+52 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.policies;
2
3
import java.util.Iterator;
4
import java.util.LinkedList;
5
import java.util.List;
6
7
import org.eclipse.emf.ecore.EObject;
8
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.CanonicalEditPolicy;
9
import org.eclipse.gmf.runtime.notation.View;
10
import org.eclipse.uml2.diagram.clazz.edit.parts.Property3EditPart;
11
import org.eclipse.uml2.diagram.clazz.part.UMLVisualIDRegistry;
12
import org.eclipse.uml2.uml.DataType;
13
14
/**
15
 * @generated
16
 */
17
public class DataTypeAttributesCanonicalEditPolicy extends CanonicalEditPolicy {
18
19
	/**
20
	 * @generated
21
	 */
22
	protected List getSemanticChildrenList() {
23
		List result = new LinkedList();
24
		EObject modelObject = ((View) getHost().getModel()).getElement();
25
		View viewObject = (View) getHost().getModel();
26
		EObject nextValue;
27
		int nodeVID;
28
		for (Iterator values = ((DataType) modelObject).getOwnedAttributes().iterator(); values.hasNext();) {
29
			nextValue = (EObject) values.next();
30
			nodeVID = UMLVisualIDRegistry.getNodeVisualID(viewObject, nextValue);
31
			if (Property3EditPart.VISUAL_ID == nodeVID) {
32
				result.add(nextValue);
33
			}
34
		}
35
		return result;
36
	}
37
38
	/**
39
	 * @generated
40
	 */
41
	protected boolean shouldDeleteView(View view) {
42
		return view.isSetElement() && view.getElement() != null && view.getElement().eIsProxy();
43
	}
44
45
	/**
46
	 * @generated
47
	 */
48
	protected String getDefaultFactoryHint() {
49
		return null;
50
	}
51
52
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/parts/PackageEditPart.java (+40 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.parts;
2
3
import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart;
4
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
5
import org.eclipse.gmf.runtime.notation.View;
6
import org.eclipse.uml2.diagram.clazz.edit.policies.PackageCanonicalEditPolicy;
7
import org.eclipse.uml2.diagram.clazz.edit.policies.PackageItemSemanticEditPolicy;
8
9
/**
10
 * @generated
11
 */
12
public class PackageEditPart extends DiagramEditPart {
13
14
	/**
15
	 * @generated
16
	 */
17
	public final static String MODEL_ID = "UMLClass"; //$NON-NLS-1$
18
19
	/**
20
	 * @generated
21
	 */
22
	public static final int VISUAL_ID = 1000;
23
24
	/**
25
	 * @generated
26
	 */
27
	public PackageEditPart(View view) {
28
		super(view);
29
	}
30
31
	/**
32
	 * @generated
33
	 */
34
	protected void createDefaultEditPolicies() {
35
		super.createDefaultEditPolicies();
36
		installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new PackageItemSemanticEditPolicy());
37
		installEditPolicy(EditPolicyRoles.CANONICAL_ROLE, new PackageCanonicalEditPolicy());
38
39
	}
40
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/parts/AssociationName7EditPart.java (+533 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.parts;
2
3
import java.util.Collections;
4
import java.util.List;
5
6
import org.eclipse.draw2d.ConnectionLocator;
7
import org.eclipse.draw2d.IFigure;
8
import org.eclipse.draw2d.Label;
9
import org.eclipse.draw2d.geometry.Point;
10
import org.eclipse.emf.common.notify.Notification;
11
import org.eclipse.emf.ecore.EObject;
12
import org.eclipse.emf.transaction.RunnableWithResult;
13
import org.eclipse.gef.AccessibleEditPart;
14
import org.eclipse.gef.EditPolicy;
15
import org.eclipse.gef.Request;
16
import org.eclipse.gef.requests.DirectEditRequest;
17
import org.eclipse.gef.tools.DirectEditManager;
18
import org.eclipse.gmf.runtime.common.ui.services.parser.IParser;
19
import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus;
20
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserEditStatus;
21
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions;
22
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserService;
23
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
24
import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart;
25
import org.eclipse.gmf.runtime.diagram.ui.editparts.LabelEditPart;
26
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy;
27
import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry;
28
import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants;
29
import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager;
30
import org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel;
31
import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
32
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
33
import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser;
34
import org.eclipse.gmf.runtime.emf.ui.services.parser.ParserHintAdapter;
35
import org.eclipse.gmf.runtime.notation.FontStyle;
36
import org.eclipse.gmf.runtime.notation.NotationPackage;
37
import org.eclipse.gmf.runtime.notation.View;
38
import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
39
import org.eclipse.jface.viewers.ICellEditorValidator;
40
import org.eclipse.swt.SWT;
41
import org.eclipse.swt.accessibility.AccessibleEvent;
42
import org.eclipse.swt.graphics.Color;
43
import org.eclipse.swt.graphics.FontData;
44
import org.eclipse.swt.graphics.Image;
45
import org.eclipse.uml2.diagram.clazz.edit.policies.UMLTextSelectionEditPolicy;
46
import org.eclipse.uml2.diagram.clazz.part.UMLVisualIDRegistry;
47
import org.eclipse.uml2.diagram.clazz.providers.UMLElementTypes;
48
49
/**
50
 * @generated
51
 */
52
public class AssociationName7EditPart extends LabelEditPart implements ITextAwareEditPart {
53
54
	/**
55
	 * @generated
56
	 */
57
	public static final int VISUAL_ID = 6009;
58
59
	/**
60
	 * @generated
61
	 */
62
	private DirectEditManager manager;
63
64
	/**
65
	 * @generated
66
	 */
67
	private IParser parser;
68
69
	/**
70
	 * @generated
71
	 */
72
	private List parserElements;
73
74
	/**
75
	 * @generated
76
	 */
77
	private String defaultText;
78
79
	/**
80
	 * @generated
81
	 */
82
	static {
83
		registerSnapBackPosition(UMLVisualIDRegistry.getType(AssociationName7EditPart.VISUAL_ID), new Point(0, 15));
84
	}
85
86
	/**
87
	 * @generated
88
	 */
89
	public AssociationName7EditPart(View view) {
90
		super(view);
91
	}
92
93
	/**
94
	 * @generated
95
	 */
96
	protected void createDefaultEditPolicies() {
97
		super.createDefaultEditPolicies();
98
		installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy());
99
100
	}
101
102
	/**
103
	 * @generated
104
	 */
105
	public int getKeyPoint() {
106
		return ConnectionLocator.SOURCE;
107
	}
108
109
	/**
110
	 * @generated
111
	 */
112
	protected String getLabelTextHelper(IFigure figure) {
113
		if (figure instanceof WrapLabel) {
114
			return ((WrapLabel) figure).getText();
115
		} else {
116
			return ((Label) figure).getText();
117
		}
118
	}
119
120
	/**
121
	 * @generated
122
	 */
123
	protected void setLabelTextHelper(IFigure figure, String text) {
124
		if (figure instanceof WrapLabel) {
125
			((WrapLabel) figure).setText(text);
126
		} else {
127
			((Label) figure).setText(text);
128
		}
129
	}
130
131
	/**
132
	 * @generated
133
	 */
134
	protected Image getLabelIconHelper(IFigure figure) {
135
		if (figure instanceof WrapLabel) {
136
			return ((WrapLabel) figure).getIcon();
137
		} else {
138
			return ((Label) figure).getIcon();
139
		}
140
	}
141
142
	/**
143
	 * @generated
144
	 */
145
	protected void setLabelIconHelper(IFigure figure, Image icon) {
146
		if (figure instanceof WrapLabel) {
147
			((WrapLabel) figure).setIcon(icon);
148
		} else {
149
			((Label) figure).setIcon(icon);
150
		}
151
	}
152
153
	/**
154
	 * @generated
155
	 */
156
	public void setLabel(IFigure figure) {
157
		unregisterVisuals();
158
		setFigure(figure);
159
		defaultText = getLabelTextHelper(figure);
160
		registerVisuals();
161
		refreshVisuals();
162
	}
163
164
	/**
165
	 * @generated
166
	 */
167
	protected List getModelChildren() {
168
		return Collections.EMPTY_LIST;
169
	}
170
171
	/**
172
	 * @generated
173
	 */
174
	public IGraphicalEditPart getChildBySemanticHint(String semanticHint) {
175
		return null;
176
	}
177
178
	/**
179
	 * @generated
180
	 */
181
	protected EObject getParserElement() {
182
		EObject element = resolveSemanticElement();
183
		return element != null ? element : (View) getModel();
184
	}
185
186
	/**
187
	 * @generated
188
	 */
189
	protected Image getLabelIcon() {
190
		return null;
191
	}
192
193
	/**
194
	 * @generated
195
	 */
196
	protected String getLabelText() {
197
		String text = null;
198
		if (getParser() != null) {
199
			text = getParser().getPrintString(new EObjectAdapter(getParserElement()), getParserOptions().intValue());
200
		}
201
		if (text == null || text.length() == 0) {
202
			text = defaultText;
203
		}
204
		return text;
205
	}
206
207
	/**
208
	 * @generated
209
	 */
210
	public void setLabelText(String text) {
211
		setLabelTextHelper(getFigure(), text);
212
		Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
213
		if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) {
214
			((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback();
215
		}
216
	}
217
218
	/**
219
	 * @generated
220
	 */
221
	public String getEditText() {
222
		if (getParser() == null) {
223
			return ""; //$NON-NLS-1$
224
		}
225
		return getParser().getEditString(new EObjectAdapter(getParserElement()), getParserOptions().intValue());
226
	}
227
228
	/**
229
	 * @generated
230
	 */
231
	protected boolean isEditable() {
232
		return getEditText() != null;
233
	}
234
235
	/**
236
	 * @generated
237
	 */
238
	public ICellEditorValidator getEditTextValidator() {
239
		return new ICellEditorValidator() {
240
241
			public String isValid(final Object value) {
242
				if (value instanceof String) {
243
					final EObject element = getParserElement();
244
					final IParser parser = getParser();
245
					try {
246
						IParserEditStatus valid = (IParserEditStatus) getEditingDomain().runExclusive(new RunnableWithResult.Impl() {
247
248
							public void run() {
249
								setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value));
250
							}
251
						});
252
						return valid.getCode() == ParserEditStatus.EDITABLE ? null : valid.getMessage();
253
					} catch (InterruptedException ie) {
254
						ie.printStackTrace();
255
					}
256
				}
257
258
				// shouldn't get here
259
				return null;
260
			}
261
		};
262
	}
263
264
	/**
265
	 * @generated
266
	 */
267
	public IContentAssistProcessor getCompletionProcessor() {
268
		if (getParser() == null) {
269
			return null;
270
		}
271
		return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement()));
272
	}
273
274
	/**
275
	 * @generated
276
	 */
277
	public ParserOptions getParserOptions() {
278
		return ParserOptions.NONE;
279
	}
280
281
	/**
282
	 * @generated
283
	 */
284
	public IParser getParser() {
285
		if (parser == null) {
286
			String parserHint = ((View) getModel()).getType();
287
			ParserHintAdapter hintAdapter = new ParserHintAdapter(getParserElement(), parserHint) {
288
289
				public Object getAdapter(Class adapter) {
290
					if (IElementType.class.equals(adapter)) {
291
						return UMLElementTypes.Association_4005;
292
					}
293
					return super.getAdapter(adapter);
294
				}
295
			};
296
			parser = ParserService.getInstance().getParser(hintAdapter);
297
		}
298
		return parser;
299
	}
300
301
	/**
302
	 * @generated
303
	 */
304
	protected DirectEditManager getManager() {
305
		if (manager == null) {
306
			setManager(new TextDirectEditManager(this, TextDirectEditManager.getTextCellEditorClass(this), UMLEditPartFactory.getTextCellEditorLocator(this)));
307
		}
308
		return manager;
309
	}
310
311
	/**
312
	 * @generated
313
	 */
314
	protected void setManager(DirectEditManager manager) {
315
		this.manager = manager;
316
	}
317
318
	/**
319
	 * @generated
320
	 */
321
	protected void performDirectEdit() {
322
		getManager().show();
323
	}
324
325
	/**
326
	 * @generated
327
	 */
328
	protected void performDirectEdit(Point eventLocation) {
329
		if (getManager().getClass() == TextDirectEditManager.class) {
330
			((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint());
331
		}
332
	}
333
334
	/**
335
	 * @generated
336
	 */
337
	private void performDirectEdit(char initialCharacter) {
338
		if (getManager() instanceof TextDirectEditManager) {
339
			((TextDirectEditManager) getManager()).show(initialCharacter);
340
		} else {
341
			performDirectEdit();
342
		}
343
	}
344
345
	/**
346
	 * @generated
347
	 */
348
	protected void performDirectEditRequest(Request request) {
349
		final Request theRequest = request;
350
		try {
351
			getEditingDomain().runExclusive(new Runnable() {
352
353
				public void run() {
354
					if (isActive() && isEditable()) {
355
						if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) {
356
							Character initialChar = (Character) theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR);
357
							performDirectEdit(initialChar.charValue());
358
						} else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) {
359
							DirectEditRequest editRequest = (DirectEditRequest) theRequest;
360
							performDirectEdit(editRequest.getLocation());
361
						} else {
362
							performDirectEdit();
363
						}
364
					}
365
				}
366
			});
367
		} catch (InterruptedException e) {
368
			e.printStackTrace();
369
		}
370
	}
371
372
	/**
373
	 * @generated
374
	 */
375
	protected void refreshVisuals() {
376
		super.refreshVisuals();
377
		refreshLabel();
378
		refreshFont();
379
		refreshFontColor();
380
		refreshUnderline();
381
		refreshStrikeThrough();
382
	}
383
384
	/**
385
	 * @generated
386
	 */
387
	protected void refreshLabel() {
388
		setLabelTextHelper(getFigure(), getLabelText());
389
		setLabelIconHelper(getFigure(), getLabelIcon());
390
		Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
391
		if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) {
392
			((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback();
393
		}
394
	}
395
396
	/**
397
	 * @generated
398
	 */
399
	protected void refreshUnderline() {
400
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
401
		if (style != null && getFigure() instanceof WrapLabel) {
402
			((WrapLabel) getFigure()).setTextUnderline(style.isUnderline());
403
		}
404
	}
405
406
	/**
407
	 * @generated
408
	 */
409
	protected void refreshStrikeThrough() {
410
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
411
		if (style != null && getFigure() instanceof WrapLabel) {
412
			((WrapLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough());
413
		}
414
	}
415
416
	/**
417
	 * @generated
418
	 */
419
	protected void refreshFont() {
420
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
421
		if (style != null) {
422
			FontData fontData = new FontData(style.getFontName(), style.getFontHeight(), (style.isBold() ? SWT.BOLD : SWT.NORMAL) | (style.isItalic() ? SWT.ITALIC : SWT.NORMAL));
423
			setFont(fontData);
424
		}
425
	}
426
427
	/**
428
	 * @generated
429
	 */
430
	protected void setFontColor(Color color) {
431
		getFigure().setForegroundColor(color);
432
	}
433
434
	/**
435
	 * @generated
436
	 */
437
	protected void addSemanticListeners() {
438
		if (getParser() instanceof ISemanticParser) {
439
			EObject element = resolveSemanticElement();
440
			parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element);
441
			for (int i = 0; i < parserElements.size(); i++) {
442
				addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$
443
			}
444
		} else {
445
			super.addSemanticListeners();
446
		}
447
	}
448
449
	/**
450
	 * @generated
451
	 */
452
	protected void removeSemanticListeners() {
453
		if (parserElements != null) {
454
			for (int i = 0; i < parserElements.size(); i++) {
455
				removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$
456
			}
457
		} else {
458
			super.removeSemanticListeners();
459
		}
460
	}
461
462
	/**
463
	 * @generated
464
	 */
465
	protected AccessibleEditPart getAccessibleEditPart() {
466
		if (accessibleEP == null) {
467
			accessibleEP = new AccessibleGraphicalEditPart() {
468
469
				public void getName(AccessibleEvent e) {
470
					e.result = getLabelTextHelper(getFigure());
471
				}
472
			};
473
		}
474
		return accessibleEP;
475
	}
476
477
	/**
478
	 * @generated
479
	 */
480
	private View getFontStyleOwnerView() {
481
		return getPrimaryView();
482
	}
483
484
	/**
485
	 * @generated
486
	 */
487
	protected void handleNotificationEvent(Notification event) {
488
		Object feature = event.getFeature();
489
		if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) {
490
			Integer c = (Integer) event.getNewValue();
491
			setFontColor(DiagramColorRegistry.getInstance().getColor(c));
492
		} else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) {
493
			refreshUnderline();
494
		} else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) {
495
			refreshStrikeThrough();
496
		} else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature)
497
				|| NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) {
498
			refreshFont();
499
		} else {
500
			if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) {
501
				refreshLabel();
502
			}
503
			if (getParser() instanceof ISemanticParser) {
504
				ISemanticParser modelParser = (ISemanticParser) getParser();
505
				if (modelParser.areSemanticElementsAffected(null, event)) {
506
					removeSemanticListeners();
507
					if (resolveSemanticElement() != null) {
508
						addSemanticListeners();
509
					}
510
					refreshLabel();
511
				}
512
			}
513
		}
514
		super.handleNotificationEvent(event);
515
	}
516
517
	/**
518
	 * @generated
519
	 */
520
	protected IFigure createFigure() {
521
		IFigure label = createFigurePrim();
522
		defaultText = getLabelTextHelper(label);
523
		return label;
524
	}
525
526
	/**
527
	 * @generated
528
	 */
529
	protected IFigure createFigurePrim() {
530
		return new WrapLabel();
531
	}
532
533
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/parts/ClassEditPart.java (+553 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.parts;
2
3
import java.util.Collections;
4
import java.util.List;
5
6
import org.eclipse.draw2d.IFigure;
7
import org.eclipse.draw2d.Label;
8
import org.eclipse.draw2d.geometry.Point;
9
import org.eclipse.emf.common.notify.Notification;
10
import org.eclipse.emf.ecore.EObject;
11
import org.eclipse.emf.transaction.RunnableWithResult;
12
import org.eclipse.gef.AccessibleEditPart;
13
import org.eclipse.gef.DragTracker;
14
import org.eclipse.gef.EditPolicy;
15
import org.eclipse.gef.Request;
16
import org.eclipse.gef.requests.DirectEditRequest;
17
import org.eclipse.gef.requests.SelectionRequest;
18
import org.eclipse.gef.tools.DirectEditManager;
19
import org.eclipse.gmf.runtime.common.ui.services.parser.IParser;
20
import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus;
21
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserEditStatus;
22
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions;
23
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserService;
24
import org.eclipse.gmf.runtime.diagram.ui.editparts.CompartmentEditPart;
25
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
26
import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart;
27
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
28
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy;
29
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.ListItemComponentEditPolicy;
30
import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry;
31
import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants;
32
import org.eclipse.gmf.runtime.diagram.ui.tools.DragEditPartsTrackerEx;
33
import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager;
34
import org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel;
35
import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
36
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
37
import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser;
38
import org.eclipse.gmf.runtime.emf.ui.services.parser.ParserHintAdapter;
39
import org.eclipse.gmf.runtime.notation.FontStyle;
40
import org.eclipse.gmf.runtime.notation.NotationPackage;
41
import org.eclipse.gmf.runtime.notation.View;
42
import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
43
import org.eclipse.jface.viewers.ICellEditorValidator;
44
import org.eclipse.swt.SWT;
45
import org.eclipse.swt.accessibility.AccessibleEvent;
46
import org.eclipse.swt.graphics.Color;
47
import org.eclipse.swt.graphics.FontData;
48
import org.eclipse.swt.graphics.Image;
49
import org.eclipse.uml2.diagram.clazz.edit.policies.ClassItemSemanticEditPolicy;
50
import org.eclipse.uml2.diagram.clazz.edit.policies.UMLTextNonResizableEditPolicy;
51
import org.eclipse.uml2.diagram.clazz.edit.policies.UMLTextSelectionEditPolicy;
52
import org.eclipse.uml2.diagram.clazz.providers.UMLElementTypes;
53
54
/**
55
 * @generated
56
 */
57
public class ClassEditPart extends CompartmentEditPart implements ITextAwareEditPart {
58
59
	/**
60
	 * @generated
61
	 */
62
	public static final int VISUAL_ID = 3007;
63
64
	/**
65
	 * @generated
66
	 */
67
	private DirectEditManager manager;
68
69
	/**
70
	 * @generated
71
	 */
72
	private IParser parser;
73
74
	/**
75
	 * @generated
76
	 */
77
	private List parserElements;
78
79
	/**
80
	 * @generated
81
	 */
82
	private String defaultText;
83
84
	/**
85
	 * @generated
86
	 */
87
	public ClassEditPart(View view) {
88
		super(view);
89
	}
90
91
	/**
92
	 * @generated
93
	 */
94
	public DragTracker getDragTracker(Request request) {
95
		if (request instanceof SelectionRequest && ((SelectionRequest) request).getLastButtonPressed() == 3) {
96
			return null;
97
		}
98
		return new DragEditPartsTrackerEx(this);
99
	}
100
101
	/**
102
	 * @generated
103
	 */
104
	protected void createDefaultEditPolicies() {
105
		super.createDefaultEditPolicies();
106
		installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new ClassItemSemanticEditPolicy());
107
		installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new UMLTextNonResizableEditPolicy());
108
		installEditPolicy(EditPolicy.COMPONENT_ROLE, new ListItemComponentEditPolicy());
109
		installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy());
110
111
	}
112
113
	/**
114
	 * @generated
115
	 */
116
	protected String getLabelTextHelper(IFigure figure) {
117
		if (figure instanceof WrapLabel) {
118
			return ((WrapLabel) figure).getText();
119
		} else {
120
			return ((Label) figure).getText();
121
		}
122
	}
123
124
	/**
125
	 * @generated
126
	 */
127
	protected void setLabelTextHelper(IFigure figure, String text) {
128
		if (figure instanceof WrapLabel) {
129
			((WrapLabel) figure).setText(text);
130
		} else {
131
			((Label) figure).setText(text);
132
		}
133
	}
134
135
	/**
136
	 * @generated
137
	 */
138
	protected Image getLabelIconHelper(IFigure figure) {
139
		if (figure instanceof WrapLabel) {
140
			return ((WrapLabel) figure).getIcon();
141
		} else {
142
			return ((Label) figure).getIcon();
143
		}
144
	}
145
146
	/**
147
	 * @generated
148
	 */
149
	protected void setLabelIconHelper(IFigure figure, Image icon) {
150
		if (figure instanceof WrapLabel) {
151
			((WrapLabel) figure).setIcon(icon);
152
		} else {
153
			((Label) figure).setIcon(icon);
154
		}
155
	}
156
157
	/**
158
	 * @generated
159
	 */
160
	public void setLabel(IFigure figure) {
161
		unregisterVisuals();
162
		setFigure(figure);
163
		defaultText = getLabelTextHelper(figure);
164
		registerVisuals();
165
		refreshVisuals();
166
	}
167
168
	/**
169
	 * @generated
170
	 */
171
	protected List getModelChildren() {
172
		return Collections.EMPTY_LIST;
173
	}
174
175
	/**
176
	 * @generated
177
	 */
178
	public IGraphicalEditPart getChildBySemanticHint(String semanticHint) {
179
		return null;
180
	}
181
182
	/**
183
	 * @generated
184
	 */
185
	protected EObject getParserElement() {
186
		EObject element = resolveSemanticElement();
187
		return element != null ? element : (View) getModel();
188
	}
189
190
	/**
191
	 * @generated
192
	 */
193
	protected Image getLabelIcon() {
194
		return null;
195
	}
196
197
	/**
198
	 * @generated
199
	 */
200
	protected String getLabelText() {
201
		String text = null;
202
		if (getParser() != null) {
203
			text = getParser().getPrintString(new EObjectAdapter(getParserElement()), getParserOptions().intValue());
204
		}
205
		if (text == null || text.length() == 0) {
206
			text = defaultText;
207
		}
208
		return text;
209
	}
210
211
	/**
212
	 * @generated
213
	 */
214
	public void setLabelText(String text) {
215
		setLabelTextHelper(getFigure(), text);
216
		Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
217
		if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) {
218
			((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback();
219
		}
220
	}
221
222
	/**
223
	 * @generated
224
	 */
225
	public String getEditText() {
226
		if (getParser() == null) {
227
			return ""; //$NON-NLS-1$
228
		}
229
		return getParser().getEditString(new EObjectAdapter(getParserElement()), getParserOptions().intValue());
230
	}
231
232
	/**
233
	 * @generated
234
	 */
235
	protected boolean isEditable() {
236
		return getEditText() != null;
237
	}
238
239
	/**
240
	 * @generated
241
	 */
242
	public ICellEditorValidator getEditTextValidator() {
243
		return new ICellEditorValidator() {
244
245
			public String isValid(final Object value) {
246
				if (value instanceof String) {
247
					final EObject element = getParserElement();
248
					final IParser parser = getParser();
249
					try {
250
						IParserEditStatus valid = (IParserEditStatus) getEditingDomain().runExclusive(new RunnableWithResult.Impl() {
251
252
							public void run() {
253
								setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value));
254
							}
255
						});
256
						return valid.getCode() == ParserEditStatus.EDITABLE ? null : valid.getMessage();
257
					} catch (InterruptedException ie) {
258
						ie.printStackTrace();
259
					}
260
				}
261
262
				// shouldn't get here
263
				return null;
264
			}
265
		};
266
	}
267
268
	/**
269
	 * @generated
270
	 */
271
	public IContentAssistProcessor getCompletionProcessor() {
272
		if (getParser() == null) {
273
			return null;
274
		}
275
		return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement()));
276
	}
277
278
	/**
279
	 * @generated
280
	 */
281
	public ParserOptions getParserOptions() {
282
		return ParserOptions.NONE;
283
	}
284
285
	/**
286
	 * @generated
287
	 */
288
	public IParser getParser() {
289
		if (parser == null) {
290
			String parserHint = ((View) getModel()).getType();
291
			ParserHintAdapter hintAdapter = new ParserHintAdapter(getParserElement(), parserHint) {
292
293
				public Object getAdapter(Class adapter) {
294
					if (IElementType.class.equals(adapter)) {
295
						return UMLElementTypes.Class_3007;
296
					}
297
					return super.getAdapter(adapter);
298
				}
299
			};
300
			parser = ParserService.getInstance().getParser(hintAdapter);
301
		}
302
		return parser;
303
	}
304
305
	/**
306
	 * @generated
307
	 */
308
	protected DirectEditManager getManager() {
309
		if (manager == null) {
310
			setManager(new TextDirectEditManager(this, TextDirectEditManager.getTextCellEditorClass(this), UMLEditPartFactory.getTextCellEditorLocator(this)));
311
		}
312
		return manager;
313
	}
314
315
	/**
316
	 * @generated
317
	 */
318
	protected void setManager(DirectEditManager manager) {
319
		this.manager = manager;
320
	}
321
322
	/**
323
	 * @generated
324
	 */
325
	protected void performDirectEdit() {
326
		getManager().show();
327
	}
328
329
	/**
330
	 * @generated
331
	 */
332
	protected void performDirectEdit(Point eventLocation) {
333
		if (getManager().getClass() == TextDirectEditManager.class) {
334
			((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint());
335
		}
336
	}
337
338
	/**
339
	 * @generated
340
	 */
341
	private void performDirectEdit(char initialCharacter) {
342
		if (getManager() instanceof TextDirectEditManager) {
343
			((TextDirectEditManager) getManager()).show(initialCharacter);
344
		} else {
345
			performDirectEdit();
346
		}
347
	}
348
349
	/**
350
	 * @generated
351
	 */
352
	protected void performDirectEditRequest(Request request) {
353
		final Request theRequest = request;
354
		try {
355
			getEditingDomain().runExclusive(new Runnable() {
356
357
				public void run() {
358
					if (isActive() && isEditable()) {
359
						if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) {
360
							Character initialChar = (Character) theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR);
361
							performDirectEdit(initialChar.charValue());
362
						} else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) {
363
							DirectEditRequest editRequest = (DirectEditRequest) theRequest;
364
							performDirectEdit(editRequest.getLocation());
365
						} else {
366
							performDirectEdit();
367
						}
368
					}
369
				}
370
			});
371
		} catch (InterruptedException e) {
372
			e.printStackTrace();
373
		}
374
	}
375
376
	/**
377
	 * @generated
378
	 */
379
	protected void refreshVisuals() {
380
		super.refreshVisuals();
381
		refreshLabel();
382
		refreshFont();
383
		refreshFontColor();
384
		refreshUnderline();
385
		refreshStrikeThrough();
386
	}
387
388
	/**
389
	 * @generated
390
	 */
391
	protected void refreshLabel() {
392
		setLabelTextHelper(getFigure(), getLabelText());
393
		setLabelIconHelper(getFigure(), getLabelIcon());
394
		Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
395
		if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) {
396
			((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback();
397
		}
398
	}
399
400
	/**
401
	 * @generated
402
	 */
403
	protected void refreshUnderline() {
404
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
405
		if (style != null && getFigure() instanceof WrapLabel) {
406
			((WrapLabel) getFigure()).setTextUnderline(style.isUnderline());
407
		}
408
	}
409
410
	/**
411
	 * @generated
412
	 */
413
	protected void refreshStrikeThrough() {
414
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
415
		if (style != null && getFigure() instanceof WrapLabel) {
416
			((WrapLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough());
417
		}
418
	}
419
420
	/**
421
	 * @generated
422
	 */
423
	protected void refreshFont() {
424
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
425
		if (style != null) {
426
			FontData fontData = new FontData(style.getFontName(), style.getFontHeight(), (style.isBold() ? SWT.BOLD : SWT.NORMAL) | (style.isItalic() ? SWT.ITALIC : SWT.NORMAL));
427
			setFont(fontData);
428
		}
429
	}
430
431
	/**
432
	 * @generated
433
	 */
434
	protected void setFontColor(Color color) {
435
		getFigure().setForegroundColor(color);
436
	}
437
438
	/**
439
	 * @generated
440
	 */
441
	protected void addSemanticListeners() {
442
		if (getParser() instanceof ISemanticParser) {
443
			EObject element = resolveSemanticElement();
444
			parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element);
445
			for (int i = 0; i < parserElements.size(); i++) {
446
				addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$
447
			}
448
		} else {
449
			super.addSemanticListeners();
450
		}
451
	}
452
453
	/**
454
	 * @generated
455
	 */
456
	protected void removeSemanticListeners() {
457
		if (parserElements != null) {
458
			for (int i = 0; i < parserElements.size(); i++) {
459
				removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$
460
			}
461
		} else {
462
			super.removeSemanticListeners();
463
		}
464
	}
465
466
	/**
467
	 * @generated
468
	 */
469
	protected AccessibleEditPart getAccessibleEditPart() {
470
		if (accessibleEP == null) {
471
			accessibleEP = new AccessibleGraphicalEditPart() {
472
473
				public void getName(AccessibleEvent e) {
474
					e.result = getLabelTextHelper(getFigure());
475
				}
476
			};
477
		}
478
		return accessibleEP;
479
	}
480
481
	/**
482
	 * @generated
483
	 */
484
	private View getFontStyleOwnerView() {
485
		return getPrimaryView();
486
	}
487
488
	/**
489
	 * @generated
490
	 */
491
	protected void addNotationalListeners() {
492
		super.addNotationalListeners();
493
		addListenerFilter("PrimaryView", this, getPrimaryView()); //$NON-NLS-1$
494
	}
495
496
	/**
497
	 * @generated
498
	 */
499
	protected void removeNotationalListeners() {
500
		super.removeNotationalListeners();
501
		removeListenerFilter("PrimaryView"); //$NON-NLS-1$
502
	}
503
504
	/**
505
	 * @generated
506
	 */
507
	protected void handleNotificationEvent(Notification event) {
508
		Object feature = event.getFeature();
509
		if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) {
510
			Integer c = (Integer) event.getNewValue();
511
			setFontColor(DiagramColorRegistry.getInstance().getColor(c));
512
		} else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) {
513
			refreshUnderline();
514
		} else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) {
515
			refreshStrikeThrough();
516
		} else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature)
517
				|| NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) {
518
			refreshFont();
519
		} else {
520
			if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) {
521
				refreshLabel();
522
			}
523
			if (getParser() instanceof ISemanticParser) {
524
				ISemanticParser modelParser = (ISemanticParser) getParser();
525
				if (modelParser.areSemanticElementsAffected(null, event)) {
526
					removeSemanticListeners();
527
					if (resolveSemanticElement() != null) {
528
						addSemanticListeners();
529
					}
530
					refreshLabel();
531
				}
532
			}
533
		}
534
		super.handleNotificationEvent(event);
535
	}
536
537
	/**
538
	 * @generated
539
	 */
540
	protected IFigure createFigure() {
541
		IFigure label = createFigurePrim();
542
		defaultText = getLabelTextHelper(label);
543
		return label;
544
	}
545
546
	/**
547
	 * @generated
548
	 */
549
	protected IFigure createFigurePrim() {
550
		return new WrapLabel();
551
	}
552
553
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/parts/Package2EditPart.java (+595 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.parts;
2
3
import org.eclipse.draw2d.IFigure;
4
import org.eclipse.draw2d.StackLayout;
5
import org.eclipse.gef.EditPart;
6
import org.eclipse.gef.EditPolicy;
7
import org.eclipse.gef.Request;
8
import org.eclipse.gef.commands.Command;
9
import org.eclipse.gef.editpolicies.LayoutEditPolicy;
10
import org.eclipse.gef.editpolicies.NonResizableEditPolicy;
11
import org.eclipse.gef.requests.CreateRequest;
12
import org.eclipse.gmf.runtime.diagram.core.edithelpers.CreateElementRequestAdapter;
13
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
14
import org.eclipse.gmf.runtime.diagram.ui.editparts.ShapeNodeEditPart;
15
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.CreationEditPolicy;
16
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
17
import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewAndElementRequest;
18
import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout;
19
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
20
import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure;
21
import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure;
22
import org.eclipse.gmf.runtime.notation.View;
23
import org.eclipse.uml2.diagram.clazz.edit.policies.Package2ItemSemanticEditPolicy;
24
import org.eclipse.uml2.diagram.clazz.part.UMLVisualIDRegistry;
25
import org.eclipse.uml2.diagram.clazz.providers.UMLElementTypes;
26
27
/**
28
 * @generated
29
 */
30
public class Package2EditPart extends ShapeNodeEditPart {
31
32
	/**
33
	 * @generated
34
	 */
35
	public static final int VISUAL_ID = 2002;
36
37
	/**
38
	 * @generated
39
	 */
40
	protected IFigure contentPane;
41
42
	/**
43
	 * @generated
44
	 */
45
	protected IFigure primaryShape;
46
47
	/**
48
	 * @generated
49
	 */
50
	public Package2EditPart(View view) {
51
		super(view);
52
	}
53
54
	/**
55
	 * @generated
56
	 */
57
	protected void createDefaultEditPolicies() {
58
		installEditPolicy(EditPolicyRoles.CREATION_ROLE, new CreationEditPolicy() {
59
60
			public Command getCommand(Request request) {
61
				if (understandsRequest(request)) {
62
					if (request instanceof CreateViewAndElementRequest) {
63
						CreateElementRequestAdapter adapter = ((CreateViewAndElementRequest) request).getViewAndElementDescriptor().getCreateElementRequestAdapter();
64
						IElementType type = (IElementType) adapter.getAdapter(IElementType.class);
65
						if (type == UMLElementTypes.Package_3006) {
66
							EditPart compartmentEditPart = getChildBySemanticHint(UMLVisualIDRegistry.getType(PackagePackagesEditPart.VISUAL_ID));
67
							return compartmentEditPart == null ? null : compartmentEditPart.getCommand(request);
68
						}
69
						if (type == UMLElementTypes.Class_3007) {
70
							EditPart compartmentEditPart = getChildBySemanticHint(UMLVisualIDRegistry.getType(PackageClassifiersEditPart.VISUAL_ID));
71
							return compartmentEditPart == null ? null : compartmentEditPart.getCommand(request);
72
						}
73
						if (type == UMLElementTypes.DataType_3008) {
74
							EditPart compartmentEditPart = getChildBySemanticHint(UMLVisualIDRegistry.getType(PackageClassifiersEditPart.VISUAL_ID));
75
							return compartmentEditPart == null ? null : compartmentEditPart.getCommand(request);
76
						}
77
						if (type == UMLElementTypes.PrimitiveType_3009) {
78
							EditPart compartmentEditPart = getChildBySemanticHint(UMLVisualIDRegistry.getType(PackageClassifiersEditPart.VISUAL_ID));
79
							return compartmentEditPart == null ? null : compartmentEditPart.getCommand(request);
80
						}
81
						if (type == UMLElementTypes.Enumeration_3011) {
82
							EditPart compartmentEditPart = getChildBySemanticHint(UMLVisualIDRegistry.getType(PackageClassifiersEditPart.VISUAL_ID));
83
							return compartmentEditPart == null ? null : compartmentEditPart.getCommand(request);
84
						}
85
						if (type == UMLElementTypes.AssociationClass_3012) {
86
							EditPart compartmentEditPart = getChildBySemanticHint(UMLVisualIDRegistry.getType(PackageClassifiersEditPart.VISUAL_ID));
87
							return compartmentEditPart == null ? null : compartmentEditPart.getCommand(request);
88
						}
89
						if (type == UMLElementTypes.InstanceSpecification_3013) {
90
							EditPart compartmentEditPart = getChildBySemanticHint(UMLVisualIDRegistry.getType(PackageOtherEditPart.VISUAL_ID));
91
							return compartmentEditPart == null ? null : compartmentEditPart.getCommand(request);
92
						}
93
					}
94
					return super.getCommand(request);
95
				}
96
				return null;
97
			}
98
		});
99
		super.createDefaultEditPolicies();
100
		installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new Package2ItemSemanticEditPolicy());
101
		installEditPolicy(EditPolicy.LAYOUT_ROLE, createLayoutEditPolicy());
102
103
	}
104
105
	/**
106
	 * @generated
107
	 */
108
	protected LayoutEditPolicy createLayoutEditPolicy() {
109
		LayoutEditPolicy lep = new LayoutEditPolicy() {
110
111
			protected EditPolicy createChildEditPolicy(EditPart child) {
112
				EditPolicy result = child.getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
113
				if (result == null) {
114
					result = new NonResizableEditPolicy();
115
				}
116
				return result;
117
			}
118
119
			protected Command getMoveChildrenCommand(Request request) {
120
				return null;
121
			}
122
123
			protected Command getCreateCommand(CreateRequest request) {
124
				return null;
125
			}
126
		};
127
		return lep;
128
	}
129
130
	/**
131
	 * @generated
132
	 */
133
	protected IFigure createNodeShape() {
134
		PackageFigure figure = new PackageFigure();
135
		return primaryShape = figure;
136
	}
137
138
	/**
139
	 * @generated
140
	 */
141
	public PackageFigure getPrimaryShape() {
142
		return (PackageFigure) primaryShape;
143
	}
144
145
	/**
146
	 * @generated 
147
	 */
148
	protected IFigure getContentPaneFor(IGraphicalEditPart editPart) {
149
		if (editPart instanceof PackagePackagesEditPart) {
150
			return getPrimaryShape().getFigurePackageFigure_PackagesCompartment();
151
		}
152
		if (editPart instanceof PackageClassifiersEditPart) {
153
			return getPrimaryShape().getFigurePackageFigure_ClassesCompartment();
154
		}
155
		if (editPart instanceof PackageOtherEditPart) {
156
			return getPrimaryShape().getFigurePackageFigure_OthersCompartment();
157
		}
158
159
		return super.getContentPaneFor(editPart);
160
	}
161
162
	/**
163
	 * @generated
164
	 */
165
	protected boolean addFixedChild(EditPart childEditPart) {
166
		if (childEditPart instanceof PackageNameEditPart) {
167
			((PackageNameEditPart) childEditPart).setLabel(getPrimaryShape().getFigurePackageFigure_name());
168
			return true;
169
		}
170
		if (childEditPart instanceof PackagePackagesEditPart) {
171
			IFigure pane = getPrimaryShape().getFigurePackageFigure_PackagesCompartment();
172
			setupContentPane(pane); // FIXME each comparment should handle his content pane in his own way 
173
			pane.add(((PackagePackagesEditPart) childEditPart).getFigure());
174
			return true;
175
		}
176
		if (childEditPart instanceof PackageClassifiersEditPart) {
177
			IFigure pane = getPrimaryShape().getFigurePackageFigure_ClassesCompartment();
178
			setupContentPane(pane); // FIXME each comparment should handle his content pane in his own way 
179
			pane.add(((PackageClassifiersEditPart) childEditPart).getFigure());
180
			return true;
181
		}
182
		if (childEditPart instanceof PackageOtherEditPart) {
183
			IFigure pane = getPrimaryShape().getFigurePackageFigure_OthersCompartment();
184
			setupContentPane(pane); // FIXME each comparment should handle his content pane in his own way 
185
			pane.add(((PackageOtherEditPart) childEditPart).getFigure());
186
			return true;
187
		}
188
		return false;
189
	}
190
191
	/**
192
	 * @generated
193
	 */
194
	protected boolean removeFixedChild(EditPart childEditPart) {
195
		if (childEditPart instanceof PackagePackagesEditPart) {
196
			IFigure pane = getPrimaryShape().getFigurePackageFigure_PackagesCompartment();
197
			pane.remove(((PackagePackagesEditPart) childEditPart).getFigure());
198
			return true;
199
		}
200
		if (childEditPart instanceof PackageClassifiersEditPart) {
201
			IFigure pane = getPrimaryShape().getFigurePackageFigure_ClassesCompartment();
202
			pane.remove(((PackageClassifiersEditPart) childEditPart).getFigure());
203
			return true;
204
		}
205
		if (childEditPart instanceof PackageOtherEditPart) {
206
			IFigure pane = getPrimaryShape().getFigurePackageFigure_OthersCompartment();
207
			pane.remove(((PackageOtherEditPart) childEditPart).getFigure());
208
			return true;
209
		}
210
		return false;
211
	}
212
213
	/**
214
	 * @generated
215
	 */
216
	protected NodeFigure createNodePlate() {
217
		DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(getMapMode().DPtoLP(100), getMapMode().DPtoLP(80));
218
		return result;
219
	}
220
221
	/**
222
	 * Creates figure for this edit part.
223
	 * 
224
	 * Body of this method does not depend on settings in generation model
225
	 * so you may safely remove <i>generated</i> tag and modify it.
226
	 * 
227
	 * @generated
228
	 */
229
	protected NodeFigure createNodeFigure() {
230
		NodeFigure figure = createNodePlate();
231
		figure.setLayoutManager(new StackLayout());
232
		IFigure shape = createNodeShape();
233
		figure.add(shape);
234
		contentPane = setupContentPane(shape);
235
		return figure;
236
	}
237
238
	/**
239
	 * Default implementation treats passed figure as content pane.
240
	 * Respects layout one may have set for generated figure.
241
	 * @param nodeShape instance of generated figure class
242
	 * @generated
243
	 */
244
	protected IFigure setupContentPane(IFigure nodeShape) {
245
		if (nodeShape.getLayoutManager() == null) {
246
			ConstrainedToolbarLayout layout = new ConstrainedToolbarLayout();
247
			layout.setSpacing(getMapMode().DPtoLP(5));
248
			nodeShape.setLayoutManager(layout);
249
		}
250
		return nodeShape; // use nodeShape itself as contentPane
251
	}
252
253
	/**
254
	 * @generated
255
	 */
256
	public IFigure getContentPane() {
257
		if (contentPane != null) {
258
			return contentPane;
259
		}
260
		return super.getContentPane();
261
	}
262
263
	/**
264
	 * @generated
265
	 */
266
	public EditPart getPrimaryChildEditPart() {
267
		return getChildBySemanticHint(UMLVisualIDRegistry.getType(PackageNameEditPart.VISUAL_ID));
268
	}
269
270
	/**
271
	 * @generated
272
	 */
273
	protected void addChildVisual(EditPart childEditPart, int index) {
274
		if (addFixedChild(childEditPart)) {
275
			return;
276
		}
277
		super.addChildVisual(childEditPart, -1);
278
	}
279
280
	/**
281
	 * @generated
282
	 */
283
	protected void removeChildVisual(EditPart childEditPart) {
284
		if (removeFixedChild(childEditPart)) {
285
			return;
286
		}
287
		super.removeChildVisual(childEditPart);
288
	}
289
290
	/**
291
	 * @generated
292
	 */
293
	public class PackageFigure extends org.eclipse.draw2d.RectangleFigure {
294
295
		/**
296
		 * @generated
297
		 */
298
		public PackageFigure() {
299
300
			org.eclipse.gmf.internal.codegen.draw2d.GridLayout myGenLayoutManager = new org.eclipse.gmf.internal.codegen.draw2d.GridLayout();
301
			myGenLayoutManager.numColumns = 2;
302
			myGenLayoutManager.makeColumnsEqualWidth = true;
303
			myGenLayoutManager.marginWidth = 0;
304
			myGenLayoutManager.marginHeight = 0;
305
			myGenLayoutManager.horizontalSpacing = 0;
306
			myGenLayoutManager.verticalSpacing = 0;
307
308
			this.setLayoutManager(myGenLayoutManager);
309
310
			this.setFill(false);
311
			this.setOutline(false);
312
			createContents();
313
		}
314
315
		/**
316
		 * @generated
317
		 */
318
		private void createContents() {
319
			org.eclipse.draw2d.RectangleFigure fig_0 = new org.eclipse.draw2d.RectangleFigure();
320
321
			fig_0.setPreferredSize(getMapMode().DPtoLP(0), getMapMode().DPtoLP(25));
322
			fig_0.setMinimumSize(new org.eclipse.draw2d.geometry.Dimension(getMapMode().DPtoLP(0), getMapMode().DPtoLP(25)));
323
324
			setFigurePackageFigure_AuxLeftTab(fig_0);
325
			org.eclipse.gmf.internal.codegen.draw2d.GridLayoutData layData0 = new org.eclipse.gmf.internal.codegen.draw2d.GridLayoutData();
326
			layData0.verticalAlignment = org.eclipse.gmf.internal.codegen.draw2d.GridLayoutData.FILL;
327
			layData0.horizontalAlignment = org.eclipse.gmf.internal.codegen.draw2d.GridLayoutData.FILL;
328
			layData0.horizontalIndent = 0;
329
			layData0.horizontalSpan = 1;
330
			layData0.verticalSpan = 1;
331
			layData0.grabExcessHorizontalSpace = true;
332
			layData0.grabExcessVerticalSpace = false;
333
334
			this.add(fig_0, layData0);
335
			org.eclipse.draw2d.RectangleFigure fig_1 = new org.eclipse.draw2d.RectangleFigure();
336
			fig_1.setFill(false);
337
			fig_1.setOutline(false);
338
			fig_1.setPreferredSize(getMapMode().DPtoLP(0), getMapMode().DPtoLP(25));
339
			fig_1.setMinimumSize(new org.eclipse.draw2d.geometry.Dimension(getMapMode().DPtoLP(0), getMapMode().DPtoLP(25)));
340
341
			setFigurePackageFigure_AuxRightPadding(fig_1);
342
			org.eclipse.gmf.internal.codegen.draw2d.GridLayoutData layData1 = new org.eclipse.gmf.internal.codegen.draw2d.GridLayoutData();
343
			layData1.verticalAlignment = org.eclipse.gmf.internal.codegen.draw2d.GridLayoutData.FILL;
344
			layData1.horizontalAlignment = org.eclipse.gmf.internal.codegen.draw2d.GridLayoutData.FILL;
345
			layData1.horizontalIndent = 0;
346
			layData1.horizontalSpan = 1;
347
			layData1.verticalSpan = 1;
348
			layData1.grabExcessHorizontalSpace = true;
349
			layData1.grabExcessVerticalSpace = false;
350
351
			this.add(fig_1, layData1);
352
			org.eclipse.draw2d.RectangleFigure fig_2 = new org.eclipse.draw2d.RectangleFigure();
353
354
			fig_2.setMinimumSize(new org.eclipse.draw2d.geometry.Dimension(getMapMode().DPtoLP(0), getMapMode().DPtoLP(25)));
355
356
			org.eclipse.uml2.diagram.common.draw2d.CenterLayout layouter2 = new org.eclipse.uml2.diagram.common.draw2d.CenterLayout();
357
358
			fig_2.setLayoutManager(layouter2);
359
360
			setFigurePackageFigure_NameContainer(fig_2);
361
			org.eclipse.gmf.internal.codegen.draw2d.GridLayoutData layData2 = new org.eclipse.gmf.internal.codegen.draw2d.GridLayoutData();
362
			layData2.verticalAlignment = org.eclipse.gmf.internal.codegen.draw2d.GridLayoutData.FILL;
363
			layData2.horizontalAlignment = org.eclipse.gmf.internal.codegen.draw2d.GridLayoutData.FILL;
364
			layData2.horizontalIndent = 0;
365
			layData2.horizontalSpan = 2;
366
			layData2.verticalSpan = 1;
367
			layData2.grabExcessHorizontalSpace = true;
368
			layData2.grabExcessVerticalSpace = false;
369
370
			this.add(fig_2, layData2);
371
			org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel fig_3 = new org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel();
372
373
			setFigurePackageFigure_name(fig_3);
374
375
			Object layData3 = null;
376
377
			fig_2.add(fig_3, layData3);
378
			org.eclipse.draw2d.RectangleFigure fig_4 = new org.eclipse.draw2d.RectangleFigure();
379
380
			org.eclipse.draw2d.ToolbarLayout layouter4 = new org.eclipse.draw2d.ToolbarLayout();
381
			layouter4.setStretchMinorAxis(true);
382
			layouter4.setMinorAlignment(org.eclipse.draw2d.ToolbarLayout.ALIGN_CENTER);
383
			layouter4.setSpacing(0);
384
			layouter4.setVertical(true);
385
386
			fig_4.setLayoutManager(layouter4);
387
388
			setFigurePackageFigure_Body(fig_4);
389
			org.eclipse.gmf.internal.codegen.draw2d.GridLayoutData layData4 = new org.eclipse.gmf.internal.codegen.draw2d.GridLayoutData();
390
			layData4.verticalAlignment = org.eclipse.gmf.internal.codegen.draw2d.GridLayoutData.FILL;
391
			layData4.horizontalAlignment = org.eclipse.gmf.internal.codegen.draw2d.GridLayoutData.FILL;
392
			layData4.horizontalIndent = 0;
393
			layData4.horizontalSpan = 2;
394
			layData4.verticalSpan = 1;
395
			layData4.grabExcessHorizontalSpace = true;
396
			layData4.grabExcessVerticalSpace = true;
397
398
			this.add(fig_4, layData4);
399
			org.eclipse.draw2d.RectangleFigure fig_5 = new org.eclipse.draw2d.RectangleFigure();
400
401
			setFigurePackageFigure_PackagesCompartment(fig_5);
402
403
			Object layData5 = null;
404
405
			fig_4.add(fig_5, layData5);
406
			org.eclipse.draw2d.RectangleFigure fig_6 = new org.eclipse.draw2d.RectangleFigure();
407
408
			setFigurePackageFigure_ClassesCompartment(fig_6);
409
410
			Object layData6 = null;
411
412
			fig_4.add(fig_6, layData6);
413
			org.eclipse.draw2d.RectangleFigure fig_7 = new org.eclipse.draw2d.RectangleFigure();
414
415
			setFigurePackageFigure_OthersCompartment(fig_7);
416
417
			Object layData7 = null;
418
419
			fig_4.add(fig_7, layData7);
420
		}
421
422
		/**
423
		 * @generated
424
		 */
425
		private org.eclipse.draw2d.RectangleFigure fPackageFigure_AuxLeftTab;
426
427
		/**
428
		 * @generated
429
		 */
430
		public org.eclipse.draw2d.RectangleFigure getFigurePackageFigure_AuxLeftTab() {
431
			return fPackageFigure_AuxLeftTab;
432
		}
433
434
		/**
435
		 * @generated
436
		 */
437
		private void setFigurePackageFigure_AuxLeftTab(org.eclipse.draw2d.RectangleFigure fig) {
438
			fPackageFigure_AuxLeftTab = fig;
439
		}
440
441
		/**
442
		 * @generated
443
		 */
444
		private org.eclipse.draw2d.RectangleFigure fPackageFigure_AuxRightPadding;
445
446
		/**
447
		 * @generated
448
		 */
449
		public org.eclipse.draw2d.RectangleFigure getFigurePackageFigure_AuxRightPadding() {
450
			return fPackageFigure_AuxRightPadding;
451
		}
452
453
		/**
454
		 * @generated
455
		 */
456
		private void setFigurePackageFigure_AuxRightPadding(org.eclipse.draw2d.RectangleFigure fig) {
457
			fPackageFigure_AuxRightPadding = fig;
458
		}
459
460
		/**
461
		 * @generated
462
		 */
463
		private org.eclipse.draw2d.RectangleFigure fPackageFigure_NameContainer;
464
465
		/**
466
		 * @generated
467
		 */
468
		public org.eclipse.draw2d.RectangleFigure getFigurePackageFigure_NameContainer() {
469
			return fPackageFigure_NameContainer;
470
		}
471
472
		/**
473
		 * @generated
474
		 */
475
		private void setFigurePackageFigure_NameContainer(org.eclipse.draw2d.RectangleFigure fig) {
476
			fPackageFigure_NameContainer = fig;
477
		}
478
479
		/**
480
		 * @generated
481
		 */
482
		private org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel fPackageFigure_name;
483
484
		/**
485
		 * @generated
486
		 */
487
		public org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel getFigurePackageFigure_name() {
488
			return fPackageFigure_name;
489
		}
490
491
		/**
492
		 * @generated
493
		 */
494
		private void setFigurePackageFigure_name(org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel fig) {
495
			fPackageFigure_name = fig;
496
		}
497
498
		/**
499
		 * @generated
500
		 */
501
		private org.eclipse.draw2d.RectangleFigure fPackageFigure_Body;
502
503
		/**
504
		 * @generated
505
		 */
506
		public org.eclipse.draw2d.RectangleFigure getFigurePackageFigure_Body() {
507
			return fPackageFigure_Body;
508
		}
509
510
		/**
511
		 * @generated
512
		 */
513
		private void setFigurePackageFigure_Body(org.eclipse.draw2d.RectangleFigure fig) {
514
			fPackageFigure_Body = fig;
515
		}
516
517
		/**
518
		 * @generated
519
		 */
520
		private org.eclipse.draw2d.RectangleFigure fPackageFigure_PackagesCompartment;
521
522
		/**
523
		 * @generated
524
		 */
525
		public org.eclipse.draw2d.RectangleFigure getFigurePackageFigure_PackagesCompartment() {
526
			return fPackageFigure_PackagesCompartment;
527
		}
528
529
		/**
530
		 * @generated
531
		 */
532
		private void setFigurePackageFigure_PackagesCompartment(org.eclipse.draw2d.RectangleFigure fig) {
533
			fPackageFigure_PackagesCompartment = fig;
534
		}
535
536
		/**
537
		 * @generated
538
		 */
539
		private org.eclipse.draw2d.RectangleFigure fPackageFigure_ClassesCompartment;
540
541
		/**
542
		 * @generated
543
		 */
544
		public org.eclipse.draw2d.RectangleFigure getFigurePackageFigure_ClassesCompartment() {
545
			return fPackageFigure_ClassesCompartment;
546
		}
547
548
		/**
549
		 * @generated
550
		 */
551
		private void setFigurePackageFigure_ClassesCompartment(org.eclipse.draw2d.RectangleFigure fig) {
552
			fPackageFigure_ClassesCompartment = fig;
553
		}
554
555
		/**
556
		 * @generated
557
		 */
558
		private org.eclipse.draw2d.RectangleFigure fPackageFigure_OthersCompartment;
559
560
		/**
561
		 * @generated
562
		 */
563
		public org.eclipse.draw2d.RectangleFigure getFigurePackageFigure_OthersCompartment() {
564
			return fPackageFigure_OthersCompartment;
565
		}
566
567
		/**
568
		 * @generated
569
		 */
570
		private void setFigurePackageFigure_OthersCompartment(org.eclipse.draw2d.RectangleFigure fig) {
571
			fPackageFigure_OthersCompartment = fig;
572
		}
573
574
		/**
575
		 * @generated
576
		 */
577
		private boolean myUseLocalCoordinates = false;
578
579
		/**
580
		 * @generated
581
		 */
582
		protected boolean useLocalCoordinates() {
583
			return myUseLocalCoordinates;
584
		}
585
586
		/**
587
		 * @generated
588
		 */
589
		protected void setUseLocalCoordinates(boolean useLocalCoordinates) {
590
			myUseLocalCoordinates = useLocalCoordinates;
591
		}
592
593
	}
594
595
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/policies/DataTypeOperationsCanonicalEditPolicy.java (+52 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.policies;
2
3
import java.util.Iterator;
4
import java.util.LinkedList;
5
import java.util.List;
6
7
import org.eclipse.emf.ecore.EObject;
8
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.CanonicalEditPolicy;
9
import org.eclipse.gmf.runtime.notation.View;
10
import org.eclipse.uml2.diagram.clazz.edit.parts.Operation3EditPart;
11
import org.eclipse.uml2.diagram.clazz.part.UMLVisualIDRegistry;
12
import org.eclipse.uml2.uml.DataType;
13
14
/**
15
 * @generated
16
 */
17
public class DataTypeOperationsCanonicalEditPolicy extends CanonicalEditPolicy {
18
19
	/**
20
	 * @generated
21
	 */
22
	protected List getSemanticChildrenList() {
23
		List result = new LinkedList();
24
		EObject modelObject = ((View) getHost().getModel()).getElement();
25
		View viewObject = (View) getHost().getModel();
26
		EObject nextValue;
27
		int nodeVID;
28
		for (Iterator values = ((DataType) modelObject).getOwnedOperations().iterator(); values.hasNext();) {
29
			nextValue = (EObject) values.next();
30
			nodeVID = UMLVisualIDRegistry.getNodeVisualID(viewObject, nextValue);
31
			if (Operation3EditPart.VISUAL_ID == nodeVID) {
32
				result.add(nextValue);
33
			}
34
		}
35
		return result;
36
	}
37
38
	/**
39
	 * @generated
40
	 */
41
	protected boolean shouldDeleteView(View view) {
42
		return view.isSetElement() && view.getElement() != null && view.getElement().eIsProxy();
43
	}
44
45
	/**
46
	 * @generated
47
	 */
48
	protected String getDefaultFactoryHint() {
49
		return null;
50
	}
51
52
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/parts/ClassAttributesEditPart.java (+67 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.parts;
2
3
import org.eclipse.emf.common.notify.Notification;
4
import org.eclipse.gef.EditPolicy;
5
import org.eclipse.gmf.runtime.diagram.ui.editparts.ListCompartmentEditPart;
6
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.CreationEditPolicy;
7
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.DragDropEditPolicy;
8
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
9
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.ResizableCompartmentEditPolicy;
10
import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout;
11
import org.eclipse.gmf.runtime.notation.View;
12
import org.eclipse.uml2.diagram.clazz.edit.policies.ClassAttributesCanonicalEditPolicy;
13
import org.eclipse.uml2.diagram.clazz.edit.policies.ClassAttributesItemSemanticEditPolicy;
14
15
/**
16
 * @generated
17
 */
18
public class ClassAttributesEditPart extends ListCompartmentEditPart {
19
20
	/**
21
	 * @generated
22
	 */
23
	public static final int VISUAL_ID = 7001;
24
25
	/**
26
	 * @generated
27
	 */
28
	public ClassAttributesEditPart(View view) {
29
		super(view);
30
	}
31
32
	/**
33
	 * @generated
34
	 */
35
	protected boolean hasModelChildrenChanged(Notification evt) {
36
		return false;
37
	}
38
39
	/**
40
	 * @generated
41
	 */
42
	public String getCompartmentName() {
43
		return "attributes";
44
	}
45
46
	/**
47
	 * @generated
48
	 */
49
	protected void createDefaultEditPolicies() {
50
		super.createDefaultEditPolicies();
51
		installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ResizableCompartmentEditPolicy());
52
		installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new ClassAttributesItemSemanticEditPolicy());
53
		installEditPolicy(EditPolicyRoles.CREATION_ROLE, new CreationEditPolicy());
54
		installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, new DragDropEditPolicy());
55
		installEditPolicy(EditPolicyRoles.CANONICAL_ROLE, new ClassAttributesCanonicalEditPolicy());
56
57
	}
58
59
	/**
60
	 * @generated
61
	 */
62
	protected void setRatio(Double ratio) {
63
		if (getFigure().getParent().getLayoutManager() instanceof ConstrainedToolbarLayout) {
64
			super.setRatio(ratio);
65
		}
66
	}
67
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/policies/DataTypeOperationsItemSemanticEditPolicy.java (+73 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.policies;
2
3
import org.eclipse.emf.ecore.EClass;
4
import org.eclipse.emf.ecore.EObject;
5
import org.eclipse.gef.commands.Command;
6
import org.eclipse.gmf.runtime.emf.type.core.commands.CreateElementCommand;
7
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest;
8
import org.eclipse.gmf.runtime.notation.View;
9
import org.eclipse.uml2.diagram.clazz.providers.UMLElementTypes;
10
import org.eclipse.uml2.uml.Operation;
11
import org.eclipse.uml2.uml.UMLPackage;
12
13
/**
14
 * @generated
15
 */
16
public class DataTypeOperationsItemSemanticEditPolicy extends UMLBaseItemSemanticEditPolicy {
17
18
	/**
19
	 * @generated
20
	 */
21
	protected Command getCreateCommand(CreateElementRequest req) {
22
		if (UMLElementTypes.Operation_3015 == req.getElementType()) {
23
			if (req.getContainmentFeature() == null) {
24
				req.setContainmentFeature(UMLPackage.eINSTANCE.getDataType_OwnedOperation());
25
			}
26
			return getMSLWrapper(new CreateOperation_3015Command(req));
27
		}
28
		return super.getCreateCommand(req);
29
	}
30
31
	/**
32
	 * @generated
33
	 */
34
	private static class CreateOperation_3015Command extends CreateElementCommand {
35
36
		/**
37
		 * @generated
38
		 */
39
		public CreateOperation_3015Command(CreateElementRequest req) {
40
			super(req);
41
		}
42
43
		/**
44
		 * @generated
45
		 */
46
		protected EClass getEClassToEdit() {
47
			return UMLPackage.eINSTANCE.getDataType();
48
		};
49
50
		/**
51
		 * @generated
52
		 */
53
		protected EObject getElementToEdit() {
54
			EObject container = ((CreateElementRequest) getRequest()).getContainer();
55
			if (container instanceof View) {
56
				container = ((View) container).getElement();
57
			}
58
			return container;
59
		}
60
61
		/**
62
		 * @generated
63
		 */
64
		protected EObject doDefaultElementCreation() {
65
			Operation newElement = (Operation) super.doDefaultElementCreation();
66
			if (newElement != null) {
67
				UMLElementTypes.Initializers.Operation_3015.init(newElement);
68
			}
69
			return newElement;
70
		}
71
	}
72
73
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/parts/AssociationClassNameEditPart.java (+551 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.parts;
2
3
import java.util.ArrayList;
4
import java.util.Collections;
5
import java.util.List;
6
7
import org.eclipse.draw2d.IFigure;
8
import org.eclipse.draw2d.Label;
9
import org.eclipse.draw2d.geometry.Point;
10
import org.eclipse.emf.common.notify.Notification;
11
import org.eclipse.emf.ecore.EObject;
12
import org.eclipse.emf.transaction.RunnableWithResult;
13
import org.eclipse.gef.AccessibleEditPart;
14
import org.eclipse.gef.EditPolicy;
15
import org.eclipse.gef.GraphicalEditPart;
16
import org.eclipse.gef.Request;
17
import org.eclipse.gef.commands.Command;
18
import org.eclipse.gef.editpolicies.NonResizableEditPolicy;
19
import org.eclipse.gef.handles.NonResizableHandleKit;
20
import org.eclipse.gef.requests.DirectEditRequest;
21
import org.eclipse.gef.tools.DirectEditManager;
22
import org.eclipse.gmf.runtime.common.ui.services.parser.IParser;
23
import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus;
24
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserEditStatus;
25
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions;
26
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserService;
27
import org.eclipse.gmf.runtime.diagram.ui.editparts.CompartmentEditPart;
28
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
29
import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart;
30
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy;
31
import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry;
32
import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants;
33
import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager;
34
import org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel;
35
import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
36
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
37
import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser;
38
import org.eclipse.gmf.runtime.emf.ui.services.parser.ParserHintAdapter;
39
import org.eclipse.gmf.runtime.notation.FontStyle;
40
import org.eclipse.gmf.runtime.notation.NotationPackage;
41
import org.eclipse.gmf.runtime.notation.View;
42
import org.eclipse.jface.resource.ImageDescriptor;
43
import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
44
import org.eclipse.jface.viewers.ICellEditorValidator;
45
import org.eclipse.swt.SWT;
46
import org.eclipse.swt.accessibility.AccessibleEvent;
47
import org.eclipse.swt.graphics.Color;
48
import org.eclipse.swt.graphics.FontData;
49
import org.eclipse.swt.graphics.Image;
50
import org.eclipse.uml2.diagram.clazz.edit.policies.UMLTextSelectionEditPolicy;
51
import org.eclipse.uml2.diagram.clazz.part.UMLDiagramEditorPlugin;
52
import org.eclipse.uml2.diagram.clazz.providers.UMLElementTypes;
53
54
/**
55
 * @generated
56
 */
57
public class AssociationClassNameEditPart extends CompartmentEditPart implements ITextAwareEditPart {
58
59
	/**
60
	 * @generated
61
	 */
62
	public static final int VISUAL_ID = 5009;
63
64
	/**
65
	 * @generated
66
	 */
67
	private DirectEditManager manager;
68
69
	/**
70
	 * @generated
71
	 */
72
	private IParser parser;
73
74
	/**
75
	 * @generated
76
	 */
77
	private List parserElements;
78
79
	/**
80
	 * @generated
81
	 */
82
	private String defaultText;
83
84
	/**
85
	 * @generated
86
	 */
87
	public AssociationClassNameEditPart(View view) {
88
		super(view);
89
	}
90
91
	/**
92
	 * @generated
93
	 */
94
	protected void createDefaultEditPolicies() {
95
		super.createDefaultEditPolicies();
96
		installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy());
97
		installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new NonResizableEditPolicy() {
98
99
			protected List createSelectionHandles() {
100
				List handles = new ArrayList();
101
				NonResizableHandleKit.addMoveHandle((GraphicalEditPart) getHost(), handles);
102
				return handles;
103
			}
104
105
			public Command getCommand(Request request) {
106
				return null;
107
			}
108
109
			public boolean understandsRequest(Request request) {
110
				return false;
111
			}
112
		});
113
114
	}
115
116
	/**
117
	 * @generated
118
	 */
119
	protected String getLabelTextHelper(IFigure figure) {
120
		if (figure instanceof WrapLabel) {
121
			return ((WrapLabel) figure).getText();
122
		} else {
123
			return ((Label) figure).getText();
124
		}
125
	}
126
127
	/**
128
	 * @generated
129
	 */
130
	protected void setLabelTextHelper(IFigure figure, String text) {
131
		if (figure instanceof WrapLabel) {
132
			((WrapLabel) figure).setText(text);
133
		} else {
134
			((Label) figure).setText(text);
135
		}
136
	}
137
138
	/**
139
	 * @generated
140
	 */
141
	protected Image getLabelIconHelper(IFigure figure) {
142
		if (figure instanceof WrapLabel) {
143
			return ((WrapLabel) figure).getIcon();
144
		} else {
145
			return ((Label) figure).getIcon();
146
		}
147
	}
148
149
	/**
150
	 * @generated
151
	 */
152
	protected void setLabelIconHelper(IFigure figure, Image icon) {
153
		if (figure instanceof WrapLabel) {
154
			((WrapLabel) figure).setIcon(icon);
155
		} else {
156
			((Label) figure).setIcon(icon);
157
		}
158
	}
159
160
	/**
161
	 * @generated
162
	 */
163
	public void setLabel(WrapLabel figure) {
164
		unregisterVisuals();
165
		setFigure(figure);
166
		defaultText = getLabelTextHelper(figure);
167
		registerVisuals();
168
		refreshVisuals();
169
	}
170
171
	/**
172
	 * @generated
173
	 */
174
	protected List getModelChildren() {
175
		return Collections.EMPTY_LIST;
176
	}
177
178
	/**
179
	 * @generated
180
	 */
181
	public IGraphicalEditPart getChildBySemanticHint(String semanticHint) {
182
		return null;
183
	}
184
185
	/**
186
	 * @generated
187
	 */
188
	protected EObject getParserElement() {
189
		EObject element = resolveSemanticElement();
190
		return element != null ? element : (View) getModel();
191
	}
192
193
	/**
194
	 * @generated
195
	 */
196
	protected Image getLabelIcon() {
197
		EObject parserElement = getParserElement();
198
		if (parserElement == null) {
199
			return null;
200
		}
201
		return UMLElementTypes.getImage(parserElement.eClass());
202
	}
203
204
	/**
205
	 * @generated
206
	 */
207
	protected String getLabelText() {
208
		String text = null;
209
		if (getParser() != null) {
210
			text = getParser().getPrintString(new EObjectAdapter(getParserElement()), getParserOptions().intValue());
211
		}
212
		if (text == null || text.length() == 0) {
213
			text = defaultText;
214
		}
215
		return text;
216
	}
217
218
	/**
219
	 * @generated
220
	 */
221
	public void setLabelText(String text) {
222
		setLabelTextHelper(getFigure(), text);
223
		Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
224
		if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) {
225
			((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback();
226
		}
227
	}
228
229
	/**
230
	 * @generated
231
	 */
232
	public String getEditText() {
233
		if (getParser() == null) {
234
			return ""; //$NON-NLS-1$
235
		}
236
		return getParser().getEditString(new EObjectAdapter(getParserElement()), getParserOptions().intValue());
237
	}
238
239
	/**
240
	 * @generated
241
	 */
242
	protected boolean isEditable() {
243
		return getEditText() != null;
244
	}
245
246
	/**
247
	 * @generated
248
	 */
249
	public ICellEditorValidator getEditTextValidator() {
250
		return new ICellEditorValidator() {
251
252
			public String isValid(final Object value) {
253
				if (value instanceof String) {
254
					final EObject element = getParserElement();
255
					final IParser parser = getParser();
256
					try {
257
						IParserEditStatus valid = (IParserEditStatus) getEditingDomain().runExclusive(new RunnableWithResult.Impl() {
258
259
							public void run() {
260
								setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value));
261
							}
262
						});
263
						return valid.getCode() == ParserEditStatus.EDITABLE ? null : valid.getMessage();
264
					} catch (InterruptedException ie) {
265
						ie.printStackTrace();
266
					}
267
				}
268
269
				// shouldn't get here
270
				return null;
271
			}
272
		};
273
	}
274
275
	/**
276
	 * @generated
277
	 */
278
	public IContentAssistProcessor getCompletionProcessor() {
279
		if (getParser() == null) {
280
			return null;
281
		}
282
		return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement()));
283
	}
284
285
	/**
286
	 * @generated
287
	 */
288
	public ParserOptions getParserOptions() {
289
		return ParserOptions.NONE;
290
	}
291
292
	/**
293
	 * @generated
294
	 */
295
	public IParser getParser() {
296
		if (parser == null) {
297
			String parserHint = ((View) getModel()).getType();
298
			ParserHintAdapter hintAdapter = new ParserHintAdapter(getParserElement(), parserHint) {
299
300
				public Object getAdapter(Class adapter) {
301
					if (IElementType.class.equals(adapter)) {
302
						return UMLElementTypes.AssociationClass_2007;
303
					}
304
					return super.getAdapter(adapter);
305
				}
306
			};
307
			parser = ParserService.getInstance().getParser(hintAdapter);
308
		}
309
		return parser;
310
	}
311
312
	/**
313
	 * @generated
314
	 */
315
	protected DirectEditManager getManager() {
316
		if (manager == null) {
317
			setManager(new TextDirectEditManager(this, TextDirectEditManager.getTextCellEditorClass(this), UMLEditPartFactory.getTextCellEditorLocator(this)));
318
		}
319
		return manager;
320
	}
321
322
	/**
323
	 * @generated
324
	 */
325
	protected void setManager(DirectEditManager manager) {
326
		this.manager = manager;
327
	}
328
329
	/**
330
	 * @generated
331
	 */
332
	protected void performDirectEdit() {
333
		getManager().show();
334
	}
335
336
	/**
337
	 * @generated
338
	 */
339
	protected void performDirectEdit(Point eventLocation) {
340
		if (getManager().getClass() == TextDirectEditManager.class) {
341
			((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint());
342
		}
343
	}
344
345
	/**
346
	 * @generated
347
	 */
348
	private void performDirectEdit(char initialCharacter) {
349
		if (getManager() instanceof TextDirectEditManager) {
350
			((TextDirectEditManager) getManager()).show(initialCharacter);
351
		} else {
352
			performDirectEdit();
353
		}
354
	}
355
356
	/**
357
	 * @generated
358
	 */
359
	protected void performDirectEditRequest(Request request) {
360
		final Request theRequest = request;
361
		try {
362
			getEditingDomain().runExclusive(new Runnable() {
363
364
				public void run() {
365
					if (isActive() && isEditable()) {
366
						if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) {
367
							Character initialChar = (Character) theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR);
368
							performDirectEdit(initialChar.charValue());
369
						} else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) {
370
							DirectEditRequest editRequest = (DirectEditRequest) theRequest;
371
							performDirectEdit(editRequest.getLocation());
372
						} else {
373
							performDirectEdit();
374
						}
375
					}
376
				}
377
			});
378
		} catch (InterruptedException e) {
379
			e.printStackTrace();
380
		}
381
	}
382
383
	/**
384
	 * @generated
385
	 */
386
	protected void refreshVisuals() {
387
		super.refreshVisuals();
388
		refreshLabel();
389
		refreshFont();
390
		refreshFontColor();
391
		refreshUnderline();
392
		refreshStrikeThrough();
393
	}
394
395
	/**
396
	 * @generated
397
	 */
398
	protected void refreshLabel() {
399
		setLabelTextHelper(getFigure(), getLabelText());
400
		setLabelIconHelper(getFigure(), getLabelIcon());
401
		Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
402
		if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) {
403
			((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback();
404
		}
405
	}
406
407
	/**
408
	 * @generated
409
	 */
410
	protected void refreshUnderline() {
411
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
412
		if (style != null && getFigure() instanceof WrapLabel) {
413
			((WrapLabel) getFigure()).setTextUnderline(style.isUnderline());
414
		}
415
	}
416
417
	/**
418
	 * @generated
419
	 */
420
	protected void refreshStrikeThrough() {
421
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
422
		if (style != null && getFigure() instanceof WrapLabel) {
423
			((WrapLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough());
424
		}
425
	}
426
427
	/**
428
	 * @generated
429
	 */
430
	protected void refreshFont() {
431
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
432
		if (style != null) {
433
			FontData fontData = new FontData(style.getFontName(), style.getFontHeight(), (style.isBold() ? SWT.BOLD : SWT.NORMAL) | (style.isItalic() ? SWT.ITALIC : SWT.NORMAL));
434
			setFont(fontData);
435
		}
436
	}
437
438
	/**
439
	 * @generated
440
	 */
441
	protected void setFontColor(Color color) {
442
		getFigure().setForegroundColor(color);
443
	}
444
445
	/**
446
	 * @generated
447
	 */
448
	protected void addSemanticListeners() {
449
		if (getParser() instanceof ISemanticParser) {
450
			EObject element = resolveSemanticElement();
451
			parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element);
452
			for (int i = 0; i < parserElements.size(); i++) {
453
				addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$
454
			}
455
		} else {
456
			super.addSemanticListeners();
457
		}
458
	}
459
460
	/**
461
	 * @generated
462
	 */
463
	protected void removeSemanticListeners() {
464
		if (parserElements != null) {
465
			for (int i = 0; i < parserElements.size(); i++) {
466
				removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$
467
			}
468
		} else {
469
			super.removeSemanticListeners();
470
		}
471
	}
472
473
	/**
474
	 * @generated
475
	 */
476
	protected AccessibleEditPart getAccessibleEditPart() {
477
		if (accessibleEP == null) {
478
			accessibleEP = new AccessibleGraphicalEditPart() {
479
480
				public void getName(AccessibleEvent e) {
481
					e.result = getLabelTextHelper(getFigure());
482
				}
483
			};
484
		}
485
		return accessibleEP;
486
	}
487
488
	/**
489
	 * @generated
490
	 */
491
	private View getFontStyleOwnerView() {
492
		return getPrimaryView();
493
	}
494
495
	/**
496
	 * @generated
497
	 */
498
	protected void addNotationalListeners() {
499
		super.addNotationalListeners();
500
		addListenerFilter("PrimaryView", this, getPrimaryView()); //$NON-NLS-1$
501
	}
502
503
	/**
504
	 * @generated
505
	 */
506
	protected void removeNotationalListeners() {
507
		super.removeNotationalListeners();
508
		removeListenerFilter("PrimaryView"); //$NON-NLS-1$
509
	}
510
511
	/**
512
	 * @generated
513
	 */
514
	protected void handleNotificationEvent(Notification event) {
515
		Object feature = event.getFeature();
516
		if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) {
517
			Integer c = (Integer) event.getNewValue();
518
			setFontColor(DiagramColorRegistry.getInstance().getColor(c));
519
		} else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) {
520
			refreshUnderline();
521
		} else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) {
522
			refreshStrikeThrough();
523
		} else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature)
524
				|| NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) {
525
			refreshFont();
526
		} else {
527
			if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) {
528
				refreshLabel();
529
			}
530
			if (getParser() instanceof ISemanticParser) {
531
				ISemanticParser modelParser = (ISemanticParser) getParser();
532
				if (modelParser.areSemanticElementsAffected(null, event)) {
533
					removeSemanticListeners();
534
					if (resolveSemanticElement() != null) {
535
						addSemanticListeners();
536
					}
537
					refreshLabel();
538
				}
539
			}
540
		}
541
		super.handleNotificationEvent(event);
542
	}
543
544
	/**
545
	 * @generated
546
	 */
547
	protected IFigure createFigure() {
548
		// Parent should assign one using setLabel method
549
		return null;
550
	}
551
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/parts/InterfaceEditPart.java (+301 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.parts;
2
3
import java.util.Iterator;
4
5
import org.eclipse.draw2d.IFigure;
6
import org.eclipse.draw2d.PositionConstants;
7
import org.eclipse.draw2d.StackLayout;
8
import org.eclipse.gef.EditPart;
9
import org.eclipse.gef.EditPolicy;
10
import org.eclipse.gef.GraphicalEditPart;
11
import org.eclipse.gef.Request;
12
import org.eclipse.gef.commands.Command;
13
import org.eclipse.gef.editparts.LayerManager;
14
import org.eclipse.gef.editpolicies.LayoutEditPolicy;
15
import org.eclipse.gef.editpolicies.NonResizableEditPolicy;
16
import org.eclipse.gef.editpolicies.ResizableEditPolicy;
17
import org.eclipse.gef.requests.CreateRequest;
18
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
19
import org.eclipse.gmf.runtime.diagram.ui.editparts.ShapeNodeEditPart;
20
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
21
import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout;
22
import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure;
23
import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure;
24
import org.eclipse.gmf.runtime.notation.View;
25
import org.eclipse.uml2.diagram.clazz.edit.policies.InterfaceItemSemanticEditPolicy;
26
import org.eclipse.uml2.diagram.clazz.edit.policies.UMLExtNodeLabelHostLayoutEditPolicy;
27
import org.eclipse.uml2.diagram.clazz.part.UMLVisualIDRegistry;
28
29
/**
30
 * @generated
31
 */
32
public class InterfaceEditPart extends ShapeNodeEditPart {
33
34
	/**
35
	 * @generated
36
	 */
37
	public static final int VISUAL_ID = 2010;
38
39
	/**
40
	 * @generated
41
	 */
42
	protected IFigure contentPane;
43
44
	/**
45
	 * @generated
46
	 */
47
	protected IFigure primaryShape;
48
49
	/**
50
	 * @generated
51
	 */
52
	public InterfaceEditPart(View view) {
53
		super(view);
54
	}
55
56
	/**
57
	 * @generated
58
	 */
59
	protected void createDefaultEditPolicies() {
60
		super.createDefaultEditPolicies();
61
		installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new InterfaceItemSemanticEditPolicy());
62
		installEditPolicy(EditPolicy.LAYOUT_ROLE, createLayoutEditPolicy());
63
64
	}
65
66
	/**
67
	 * @generated
68
	 */
69
	protected LayoutEditPolicy createLayoutEditPolicy() {
70
		LayoutEditPolicy lep = new LayoutEditPolicy() {
71
72
			protected void decorateChild(EditPart child) {
73
				if (isExternalLabel(child)) {
74
					return;
75
				}
76
				super.decorateChild(child);
77
			}
78
79
			protected EditPolicy createChildEditPolicy(EditPart child) {
80
				EditPolicy result = child.getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
81
				if (result == null) {
82
					result = new NonResizableEditPolicy();
83
				}
84
				return result;
85
			}
86
87
			protected Command getMoveChildrenCommand(Request request) {
88
				return null;
89
			}
90
91
			protected Command getCreateCommand(CreateRequest request) {
92
				return null;
93
			}
94
		};
95
		UMLExtNodeLabelHostLayoutEditPolicy xlep = new UMLExtNodeLabelHostLayoutEditPolicy() {
96
97
			protected boolean isExternalLabel(EditPart editPart) {
98
				return InterfaceEditPart.this.isExternalLabel(editPart);
99
			}
100
		};
101
		xlep.setRealLayoutEditPolicy(lep);
102
		return xlep;
103
	}
104
105
	/**
106
	 * @generated
107
	 */
108
	protected IFigure createNodeShape() {
109
		ProvidedInterfaceCircleFigure figure = new ProvidedInterfaceCircleFigure();
110
		return primaryShape = figure;
111
	}
112
113
	/**
114
	 * @generated
115
	 */
116
	public ProvidedInterfaceCircleFigure getPrimaryShape() {
117
		return (ProvidedInterfaceCircleFigure) primaryShape;
118
	}
119
120
	/**
121
	 * @generated 
122
	 */
123
	protected IFigure getContentPaneFor(IGraphicalEditPart editPart) {
124
		if (isExternalLabel(editPart)) {
125
			return getExternalLabelsContainer();
126
		}
127
128
		return super.getContentPaneFor(editPart);
129
	}
130
131
	/**
132
	 * @generated
133
	 */
134
	protected NodeFigure createNodePlate() {
135
		DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(getMapMode().DPtoLP(15), getMapMode().DPtoLP(15));
136
		return result;
137
	}
138
139
	/**
140
	 * @generated
141
	 */
142
	public EditPolicy getPrimaryDragEditPolicy() {
143
		EditPolicy result = super.getPrimaryDragEditPolicy();
144
		if (result instanceof ResizableEditPolicy) {
145
			ResizableEditPolicy ep = (ResizableEditPolicy) result;
146
147
			ep.setResizeDirections(PositionConstants.NONE);
148
149
		}
150
		return result;
151
	}
152
153
	/**
154
	 * Creates figure for this edit part.
155
	 * 
156
	 * Body of this method does not depend on settings in generation model
157
	 * so you may safely remove <i>generated</i> tag and modify it.
158
	 * 
159
	 * @generated
160
	 */
161
	protected NodeFigure createNodeFigure() {
162
		NodeFigure figure = createNodePlate();
163
		figure.setLayoutManager(new StackLayout());
164
		IFigure shape = createNodeShape();
165
		figure.add(shape);
166
		contentPane = setupContentPane(shape);
167
		return figure;
168
	}
169
170
	/**
171
	 * Default implementation treats passed figure as content pane.
172
	 * Respects layout one may have set for generated figure.
173
	 * @param nodeShape instance of generated figure class
174
	 * @generated
175
	 */
176
	protected IFigure setupContentPane(IFigure nodeShape) {
177
		if (nodeShape.getLayoutManager() == null) {
178
			ConstrainedToolbarLayout layout = new ConstrainedToolbarLayout();
179
			layout.setSpacing(getMapMode().DPtoLP(5));
180
			nodeShape.setLayoutManager(layout);
181
		}
182
		return nodeShape; // use nodeShape itself as contentPane
183
	}
184
185
	/**
186
	 * @generated
187
	 */
188
	public IFigure getContentPane() {
189
		if (contentPane != null) {
190
			return contentPane;
191
		}
192
		return super.getContentPane();
193
	}
194
195
	/**
196
	 * @generated
197
	 */
198
	public EditPart getPrimaryChildEditPart() {
199
		return getChildBySemanticHint(UMLVisualIDRegistry.getType(InterfaceNameEditPart.VISUAL_ID));
200
	}
201
202
	/**
203
	 * @generated
204
	 */
205
	protected boolean isExternalLabel(EditPart childEditPart) {
206
		if (childEditPart instanceof InterfaceNameEditPart) {
207
			return true;
208
		}
209
		return false;
210
	}
211
212
	/**
213
	 * @generated
214
	 */
215
	protected IFigure getExternalLabelsContainer() {
216
		LayerManager root = (LayerManager) getRoot();
217
		return root.getLayer(UMLEditPartFactory.EXTERNAL_NODE_LABELS_LAYER);
218
	}
219
220
	/**
221
	 * @generated
222
	 */
223
	protected void addChildVisual(EditPart childEditPart, int index) {
224
		if (isExternalLabel(childEditPart)) {
225
			IFigure labelFigure = ((GraphicalEditPart) childEditPart).getFigure();
226
			getExternalLabelsContainer().add(labelFigure);
227
			return;
228
		}
229
		super.addChildVisual(childEditPart, -1);
230
	}
231
232
	/**
233
	 * @generated
234
	 */
235
	protected void removeChildVisual(EditPart childEditPart) {
236
		if (isExternalLabel(childEditPart)) {
237
			IFigure labelFigure = ((GraphicalEditPart) childEditPart).getFigure();
238
			getExternalLabelsContainer().remove(labelFigure);
239
			return;
240
		}
241
		super.removeChildVisual(childEditPart);
242
	}
243
244
	/**
245
	 * @generated
246
	 */
247
	public void removeNotify() {
248
		for (Iterator it = getChildren().iterator(); it.hasNext();) {
249
			EditPart childEditPart = (EditPart) it.next();
250
			if (isExternalLabel(childEditPart)) {
251
				IFigure labelFigure = ((GraphicalEditPart) childEditPart).getFigure();
252
				getExternalLabelsContainer().remove(labelFigure);
253
			}
254
		}
255
		super.removeNotify();
256
	}
257
258
	/**
259
	 * @generated
260
	 */
261
	public class ProvidedInterfaceCircleFigure extends org.eclipse.draw2d.Ellipse {
262
263
		/**
264
		 * @generated
265
		 */
266
		public ProvidedInterfaceCircleFigure() {
267
268
			this.setPreferredSize(getMapMode().DPtoLP(15), getMapMode().DPtoLP(15));
269
			this.setMaximumSize(new org.eclipse.draw2d.geometry.Dimension(getMapMode().DPtoLP(15), getMapMode().DPtoLP(15)));
270
			this.setMinimumSize(new org.eclipse.draw2d.geometry.Dimension(getMapMode().DPtoLP(15), getMapMode().DPtoLP(15)));
271
			createContents();
272
		}
273
274
		/**
275
		 * @generated
276
		 */
277
		private void createContents() {
278
		}
279
280
		/**
281
		 * @generated
282
		 */
283
		private boolean myUseLocalCoordinates = false;
284
285
		/**
286
		 * @generated
287
		 */
288
		protected boolean useLocalCoordinates() {
289
			return myUseLocalCoordinates;
290
		}
291
292
		/**
293
		 * @generated
294
		 */
295
		protected void setUseLocalCoordinates(boolean useLocalCoordinates) {
296
			myUseLocalCoordinates = useLocalCoordinates;
297
		}
298
299
	}
300
301
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/parts/EnumerationOperationsEditPart.java (+67 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.parts;
2
3
import org.eclipse.emf.common.notify.Notification;
4
import org.eclipse.gef.EditPolicy;
5
import org.eclipse.gmf.runtime.diagram.ui.editparts.ListCompartmentEditPart;
6
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.CreationEditPolicy;
7
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.DragDropEditPolicy;
8
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
9
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.ResizableCompartmentEditPolicy;
10
import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout;
11
import org.eclipse.gmf.runtime.notation.View;
12
import org.eclipse.uml2.diagram.clazz.edit.policies.EnumerationOperationsCanonicalEditPolicy;
13
import org.eclipse.uml2.diagram.clazz.edit.policies.EnumerationOperationsItemSemanticEditPolicy;
14
15
/**
16
 * @generated
17
 */
18
public class EnumerationOperationsEditPart extends ListCompartmentEditPart {
19
20
	/**
21
	 * @generated
22
	 */
23
	public static final int VISUAL_ID = 7015;
24
25
	/**
26
	 * @generated
27
	 */
28
	public EnumerationOperationsEditPart(View view) {
29
		super(view);
30
	}
31
32
	/**
33
	 * @generated
34
	 */
35
	protected boolean hasModelChildrenChanged(Notification evt) {
36
		return false;
37
	}
38
39
	/**
40
	 * @generated
41
	 */
42
	public String getCompartmentName() {
43
		return "operations";
44
	}
45
46
	/**
47
	 * @generated
48
	 */
49
	protected void createDefaultEditPolicies() {
50
		super.createDefaultEditPolicies();
51
		installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ResizableCompartmentEditPolicy());
52
		installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new EnumerationOperationsItemSemanticEditPolicy());
53
		installEditPolicy(EditPolicyRoles.CREATION_ROLE, new CreationEditPolicy());
54
		installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, new DragDropEditPolicy());
55
		installEditPolicy(EditPolicyRoles.CANONICAL_ROLE, new EnumerationOperationsCanonicalEditPolicy());
56
57
	}
58
59
	/**
60
	 * @generated
61
	 */
62
	protected void setRatio(Double ratio) {
63
		if (getFigure().getParent().getLayoutManager() instanceof ConstrainedToolbarLayout) {
64
			super.setRatio(ratio);
65
		}
66
	}
67
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/policies/EnumerationLiteralsCanonicalEditPolicy.java (+52 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.policies;
2
3
import java.util.Iterator;
4
import java.util.LinkedList;
5
import java.util.List;
6
7
import org.eclipse.emf.ecore.EObject;
8
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.CanonicalEditPolicy;
9
import org.eclipse.gmf.runtime.notation.View;
10
import org.eclipse.uml2.diagram.clazz.edit.parts.EnumerationLiteralEditPart;
11
import org.eclipse.uml2.diagram.clazz.part.UMLVisualIDRegistry;
12
import org.eclipse.uml2.uml.Enumeration;
13
14
/**
15
 * @generated
16
 */
17
public class EnumerationLiteralsCanonicalEditPolicy extends CanonicalEditPolicy {
18
19
	/**
20
	 * @generated
21
	 */
22
	protected List getSemanticChildrenList() {
23
		List result = new LinkedList();
24
		EObject modelObject = ((View) getHost().getModel()).getElement();
25
		View viewObject = (View) getHost().getModel();
26
		EObject nextValue;
27
		int nodeVID;
28
		for (Iterator values = ((Enumeration) modelObject).getOwnedLiterals().iterator(); values.hasNext();) {
29
			nextValue = (EObject) values.next();
30
			nodeVID = UMLVisualIDRegistry.getNodeVisualID(viewObject, nextValue);
31
			if (EnumerationLiteralEditPart.VISUAL_ID == nodeVID) {
32
				result.add(nextValue);
33
			}
34
		}
35
		return result;
36
	}
37
38
	/**
39
	 * @generated
40
	 */
41
	protected boolean shouldDeleteView(View view) {
42
		return view.isSetElement() && view.getElement() != null && view.getElement().eIsProxy();
43
	}
44
45
	/**
46
	 * @generated
47
	 */
48
	protected String getDefaultFactoryHint() {
49
		return null;
50
	}
51
52
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/policies/Package2ItemSemanticEditPolicy.java (+255 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.policies;
2
3
import org.eclipse.emf.ecore.EAnnotation;
4
import org.eclipse.emf.ecore.EClass;
5
import org.eclipse.emf.ecore.EObject;
6
import org.eclipse.gef.commands.Command;
7
import org.eclipse.gef.commands.UnexecutableCommand;
8
import org.eclipse.gmf.runtime.emf.type.core.commands.CreateRelationshipCommand;
9
import org.eclipse.gmf.runtime.emf.type.core.commands.DestroyElementCommand;
10
import org.eclipse.gmf.runtime.emf.type.core.commands.SetValueCommand;
11
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest;
12
import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest;
13
import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest;
14
import org.eclipse.gmf.runtime.notation.View;
15
import org.eclipse.uml2.diagram.clazz.providers.UMLElementTypes;
16
import org.eclipse.uml2.uml.Constraint;
17
import org.eclipse.uml2.uml.Dependency;
18
import org.eclipse.uml2.uml.NamedElement;
19
import org.eclipse.uml2.uml.UMLPackage;
20
import org.eclipse.uml2.uml.Usage;
21
22
/**
23
 * @generated
24
 */
25
public class Package2ItemSemanticEditPolicy extends UMLBaseItemSemanticEditPolicy {
26
27
	/**
28
	 * @generated
29
	 */
30
	protected Command getDestroyElementCommand(DestroyElementRequest req) {
31
		return getMSLWrapper(new DestroyElementCommand(req) {
32
33
			protected EObject getElementToDestroy() {
34
				View view = (View) getHost().getModel();
35
				EAnnotation annotation = view.getEAnnotation("Shortcut"); //$NON-NLS-1$
36
				if (annotation != null) {
37
					return view;
38
				}
39
				return super.getElementToDestroy();
40
			}
41
42
		});
43
	}
44
45
	/**
46
	 * @generated
47
	 */
48
	protected Command getCreateRelationshipCommand(CreateRelationshipRequest req) {
49
		if (UMLElementTypes.Dependency_4002 == req.getElementType()) {
50
			return req.getTarget() == null ? getCreateStartOutgoingDependency4002Command(req) : getCreateCompleteIncomingDependency4002Command(req);
51
		}
52
		if (UMLElementTypes.ConstraintConstrainedElement_4004 == req.getElementType()) {
53
			return req.getTarget() == null ? null : getCreateCompleteIncomingConstraint_ConstrainedElement4004Command(req);
54
		}
55
		if (UMLElementTypes.DependencySupplier_4006 == req.getElementType()) {
56
			return req.getTarget() == null ? null : getCreateCompleteIncomingDependency_Supplier4006Command(req);
57
		}
58
		if (UMLElementTypes.DependencyClient_4007 == req.getElementType()) {
59
			return req.getTarget() == null ? null : getCreateCompleteIncomingDependency_Client4007Command(req);
60
		}
61
		if (UMLElementTypes.Usage_4009 == req.getElementType()) {
62
			return req.getTarget() == null ? getCreateStartOutgoingUsage4009Command(req) : getCreateCompleteIncomingUsage4009Command(req);
63
		}
64
		return super.getCreateRelationshipCommand(req);
65
	}
66
67
	/**
68
	 * @generated
69
	 */
70
	protected Command getCreateStartOutgoingDependency4002Command(CreateRelationshipRequest req) {
71
		return new Command() {
72
		};
73
	}
74
75
	/**
76
	 * @generated
77
	 */
78
	protected Command getCreateCompleteIncomingDependency4002Command(CreateRelationshipRequest req) {
79
		if (!(req.getSource() instanceof NamedElement)) {
80
			return UnexecutableCommand.INSTANCE;
81
		}
82
		final org.eclipse.uml2.uml.Package element = (org.eclipse.uml2.uml.Package) getRelationshipContainer(req.getSource(), UMLPackage.eINSTANCE.getPackage(), req.getElementType());
83
		if (element == null) {
84
			return UnexecutableCommand.INSTANCE;
85
		}
86
		if (req.getContainmentFeature() == null) {
87
			req.setContainmentFeature(UMLPackage.eINSTANCE.getPackage_PackagedElement());
88
		}
89
		return getMSLWrapper(new CreateIncomingDependency4002Command(req) {
90
91
			protected EObject getElementToEdit() {
92
				return element;
93
			}
94
		});
95
	}
96
97
	/**
98
	 * @generated
99
	 */
100
	private static class CreateIncomingDependency4002Command extends CreateRelationshipCommand {
101
102
		/**
103
		 * @generated
104
		 */
105
		public CreateIncomingDependency4002Command(CreateRelationshipRequest req) {
106
			super(req);
107
		}
108
109
		/**
110
		 * @generated
111
		 */
112
		protected EClass getEClassToEdit() {
113
			return UMLPackage.eINSTANCE.getPackage();
114
		};
115
116
		/**
117
		 * @generated
118
		 */
119
		protected void setElementToEdit(EObject element) {
120
			throw new UnsupportedOperationException();
121
		}
122
123
		/**
124
		 * @generated
125
		 */
126
		protected EObject doDefaultElementCreation() {
127
			Dependency newElement = (Dependency) super.doDefaultElementCreation();
128
			if (newElement != null) {
129
				newElement.getSuppliers().add((NamedElement) getTarget());
130
				newElement.getClients().add((NamedElement) getSource());
131
			}
132
			return newElement;
133
		}
134
	}
135
136
	/**
137
	 * @generated
138
	 */
139
	protected Command getCreateCompleteIncomingConstraint_ConstrainedElement4004Command(CreateRelationshipRequest req) {
140
		if (!(req.getSource() instanceof Constraint)) {
141
			return UnexecutableCommand.INSTANCE;
142
		}
143
		Constraint element = (Constraint) req.getSource();
144
		if (element.getConstrainedElements().contains(req.getTarget())) {
145
			return UnexecutableCommand.INSTANCE;
146
		}
147
		SetRequest setReq = new SetRequest(req.getSource(), UMLPackage.eINSTANCE.getConstraint_ConstrainedElement(), req.getTarget());
148
		return getMSLWrapper(new SetValueCommand(setReq));
149
	}
150
151
	/**
152
	 * @generated
153
	 */
154
	protected Command getCreateCompleteIncomingDependency_Supplier4006Command(CreateRelationshipRequest req) {
155
		if (!(req.getSource() instanceof Dependency)) {
156
			return UnexecutableCommand.INSTANCE;
157
		}
158
		Dependency element = (Dependency) req.getSource();
159
		if (element.getSuppliers().contains(req.getTarget())) {
160
			return UnexecutableCommand.INSTANCE;
161
		}
162
		SetRequest setReq = new SetRequest(req.getSource(), UMLPackage.eINSTANCE.getDependency_Supplier(), req.getTarget());
163
		return getMSLWrapper(new SetValueCommand(setReq));
164
	}
165
166
	/**
167
	 * @generated
168
	 */
169
	protected Command getCreateCompleteIncomingDependency_Client4007Command(CreateRelationshipRequest req) {
170
		if (!(req.getSource() instanceof Dependency)) {
171
			return UnexecutableCommand.INSTANCE;
172
		}
173
		Dependency element = (Dependency) req.getSource();
174
		if (element.getClients().contains(req.getTarget())) {
175
			return UnexecutableCommand.INSTANCE;
176
		}
177
		SetRequest setReq = new SetRequest(req.getSource(), UMLPackage.eINSTANCE.getDependency_Client(), req.getTarget());
178
		return getMSLWrapper(new SetValueCommand(setReq));
179
	}
180
181
	/**
182
	 * @generated
183
	 */
184
	protected Command getCreateStartOutgoingUsage4009Command(CreateRelationshipRequest req) {
185
		if (!UMLBaseItemSemanticEditPolicy.LinkConstraints.Usage_4009.canCreateLink(req, false)) {
186
			return UnexecutableCommand.INSTANCE;
187
		}
188
		return new Command() {
189
		};
190
	}
191
192
	/**
193
	 * @generated
194
	 */
195
	protected Command getCreateCompleteIncomingUsage4009Command(CreateRelationshipRequest req) {
196
		if (!(req.getSource() instanceof NamedElement)) {
197
			return UnexecutableCommand.INSTANCE;
198
		}
199
		final org.eclipse.uml2.uml.Package element = (org.eclipse.uml2.uml.Package) getRelationshipContainer(req.getSource(), UMLPackage.eINSTANCE.getPackage(), req.getElementType());
200
		if (element == null) {
201
			return UnexecutableCommand.INSTANCE;
202
		}
203
		if (!UMLBaseItemSemanticEditPolicy.LinkConstraints.Usage_4009.canCreateLink(req, false)) {
204
			return UnexecutableCommand.INSTANCE;
205
		}
206
		if (req.getContainmentFeature() == null) {
207
			req.setContainmentFeature(UMLPackage.eINSTANCE.getPackage_PackagedElement());
208
		}
209
		return getMSLWrapper(new CreateIncomingUsage4009Command(req) {
210
211
			protected EObject getElementToEdit() {
212
				return element;
213
			}
214
		});
215
	}
216
217
	/**
218
	 * @generated
219
	 */
220
	private static class CreateIncomingUsage4009Command extends CreateRelationshipCommand {
221
222
		/**
223
		 * @generated
224
		 */
225
		public CreateIncomingUsage4009Command(CreateRelationshipRequest req) {
226
			super(req);
227
		}
228
229
		/**
230
		 * @generated
231
		 */
232
		protected EClass getEClassToEdit() {
233
			return UMLPackage.eINSTANCE.getPackage();
234
		};
235
236
		/**
237
		 * @generated
238
		 */
239
		protected void setElementToEdit(EObject element) {
240
			throw new UnsupportedOperationException();
241
		}
242
243
		/**
244
		 * @generated
245
		 */
246
		protected EObject doDefaultElementCreation() {
247
			Usage newElement = (Usage) super.doDefaultElementCreation();
248
			if (newElement != null) {
249
				newElement.getSuppliers().add((NamedElement) getTarget());
250
				newElement.getClients().add((NamedElement) getSource());
251
			}
252
			return newElement;
253
		}
254
	}
255
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/parts/Property3EditPart.java (+553 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.parts;
2
3
import java.util.Collections;
4
import java.util.List;
5
6
import org.eclipse.draw2d.IFigure;
7
import org.eclipse.draw2d.Label;
8
import org.eclipse.draw2d.geometry.Point;
9
import org.eclipse.emf.common.notify.Notification;
10
import org.eclipse.emf.ecore.EObject;
11
import org.eclipse.emf.transaction.RunnableWithResult;
12
import org.eclipse.gef.AccessibleEditPart;
13
import org.eclipse.gef.DragTracker;
14
import org.eclipse.gef.EditPolicy;
15
import org.eclipse.gef.Request;
16
import org.eclipse.gef.requests.DirectEditRequest;
17
import org.eclipse.gef.requests.SelectionRequest;
18
import org.eclipse.gef.tools.DirectEditManager;
19
import org.eclipse.gmf.runtime.common.ui.services.parser.IParser;
20
import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus;
21
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserEditStatus;
22
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions;
23
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserService;
24
import org.eclipse.gmf.runtime.diagram.ui.editparts.CompartmentEditPart;
25
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
26
import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart;
27
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
28
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy;
29
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.ListItemComponentEditPolicy;
30
import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry;
31
import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants;
32
import org.eclipse.gmf.runtime.diagram.ui.tools.DragEditPartsTrackerEx;
33
import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager;
34
import org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel;
35
import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
36
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
37
import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser;
38
import org.eclipse.gmf.runtime.emf.ui.services.parser.ParserHintAdapter;
39
import org.eclipse.gmf.runtime.notation.FontStyle;
40
import org.eclipse.gmf.runtime.notation.NotationPackage;
41
import org.eclipse.gmf.runtime.notation.View;
42
import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
43
import org.eclipse.jface.viewers.ICellEditorValidator;
44
import org.eclipse.swt.SWT;
45
import org.eclipse.swt.accessibility.AccessibleEvent;
46
import org.eclipse.swt.graphics.Color;
47
import org.eclipse.swt.graphics.FontData;
48
import org.eclipse.swt.graphics.Image;
49
import org.eclipse.uml2.diagram.clazz.edit.policies.Property3ItemSemanticEditPolicy;
50
import org.eclipse.uml2.diagram.clazz.edit.policies.UMLTextNonResizableEditPolicy;
51
import org.eclipse.uml2.diagram.clazz.edit.policies.UMLTextSelectionEditPolicy;
52
import org.eclipse.uml2.diagram.clazz.providers.UMLElementTypes;
53
54
/**
55
 * @generated
56
 */
57
public class Property3EditPart extends CompartmentEditPart implements ITextAwareEditPart {
58
59
	/**
60
	 * @generated
61
	 */
62
	public static final int VISUAL_ID = 3014;
63
64
	/**
65
	 * @generated
66
	 */
67
	private DirectEditManager manager;
68
69
	/**
70
	 * @generated
71
	 */
72
	private IParser parser;
73
74
	/**
75
	 * @generated
76
	 */
77
	private List parserElements;
78
79
	/**
80
	 * @generated
81
	 */
82
	private String defaultText;
83
84
	/**
85
	 * @generated
86
	 */
87
	public Property3EditPart(View view) {
88
		super(view);
89
	}
90
91
	/**
92
	 * @generated
93
	 */
94
	public DragTracker getDragTracker(Request request) {
95
		if (request instanceof SelectionRequest && ((SelectionRequest) request).getLastButtonPressed() == 3) {
96
			return null;
97
		}
98
		return new DragEditPartsTrackerEx(this);
99
	}
100
101
	/**
102
	 * @generated
103
	 */
104
	protected void createDefaultEditPolicies() {
105
		super.createDefaultEditPolicies();
106
		installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new Property3ItemSemanticEditPolicy());
107
		installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new UMLTextNonResizableEditPolicy());
108
		installEditPolicy(EditPolicy.COMPONENT_ROLE, new ListItemComponentEditPolicy());
109
		installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy());
110
111
	}
112
113
	/**
114
	 * @generated
115
	 */
116
	protected String getLabelTextHelper(IFigure figure) {
117
		if (figure instanceof WrapLabel) {
118
			return ((WrapLabel) figure).getText();
119
		} else {
120
			return ((Label) figure).getText();
121
		}
122
	}
123
124
	/**
125
	 * @generated
126
	 */
127
	protected void setLabelTextHelper(IFigure figure, String text) {
128
		if (figure instanceof WrapLabel) {
129
			((WrapLabel) figure).setText(text);
130
		} else {
131
			((Label) figure).setText(text);
132
		}
133
	}
134
135
	/**
136
	 * @generated
137
	 */
138
	protected Image getLabelIconHelper(IFigure figure) {
139
		if (figure instanceof WrapLabel) {
140
			return ((WrapLabel) figure).getIcon();
141
		} else {
142
			return ((Label) figure).getIcon();
143
		}
144
	}
145
146
	/**
147
	 * @generated
148
	 */
149
	protected void setLabelIconHelper(IFigure figure, Image icon) {
150
		if (figure instanceof WrapLabel) {
151
			((WrapLabel) figure).setIcon(icon);
152
		} else {
153
			((Label) figure).setIcon(icon);
154
		}
155
	}
156
157
	/**
158
	 * @generated
159
	 */
160
	public void setLabel(IFigure figure) {
161
		unregisterVisuals();
162
		setFigure(figure);
163
		defaultText = getLabelTextHelper(figure);
164
		registerVisuals();
165
		refreshVisuals();
166
	}
167
168
	/**
169
	 * @generated
170
	 */
171
	protected List getModelChildren() {
172
		return Collections.EMPTY_LIST;
173
	}
174
175
	/**
176
	 * @generated
177
	 */
178
	public IGraphicalEditPart getChildBySemanticHint(String semanticHint) {
179
		return null;
180
	}
181
182
	/**
183
	 * @generated
184
	 */
185
	protected EObject getParserElement() {
186
		EObject element = resolveSemanticElement();
187
		return element != null ? element : (View) getModel();
188
	}
189
190
	/**
191
	 * @generated
192
	 */
193
	protected Image getLabelIcon() {
194
		return null;
195
	}
196
197
	/**
198
	 * @generated
199
	 */
200
	protected String getLabelText() {
201
		String text = null;
202
		if (getParser() != null) {
203
			text = getParser().getPrintString(new EObjectAdapter(getParserElement()), getParserOptions().intValue());
204
		}
205
		if (text == null || text.length() == 0) {
206
			text = defaultText;
207
		}
208
		return text;
209
	}
210
211
	/**
212
	 * @generated
213
	 */
214
	public void setLabelText(String text) {
215
		setLabelTextHelper(getFigure(), text);
216
		Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
217
		if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) {
218
			((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback();
219
		}
220
	}
221
222
	/**
223
	 * @generated
224
	 */
225
	public String getEditText() {
226
		if (getParser() == null) {
227
			return ""; //$NON-NLS-1$
228
		}
229
		return getParser().getEditString(new EObjectAdapter(getParserElement()), getParserOptions().intValue());
230
	}
231
232
	/**
233
	 * @generated
234
	 */
235
	protected boolean isEditable() {
236
		return getEditText() != null;
237
	}
238
239
	/**
240
	 * @generated
241
	 */
242
	public ICellEditorValidator getEditTextValidator() {
243
		return new ICellEditorValidator() {
244
245
			public String isValid(final Object value) {
246
				if (value instanceof String) {
247
					final EObject element = getParserElement();
248
					final IParser parser = getParser();
249
					try {
250
						IParserEditStatus valid = (IParserEditStatus) getEditingDomain().runExclusive(new RunnableWithResult.Impl() {
251
252
							public void run() {
253
								setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value));
254
							}
255
						});
256
						return valid.getCode() == ParserEditStatus.EDITABLE ? null : valid.getMessage();
257
					} catch (InterruptedException ie) {
258
						ie.printStackTrace();
259
					}
260
				}
261
262
				// shouldn't get here
263
				return null;
264
			}
265
		};
266
	}
267
268
	/**
269
	 * @generated
270
	 */
271
	public IContentAssistProcessor getCompletionProcessor() {
272
		if (getParser() == null) {
273
			return null;
274
		}
275
		return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement()));
276
	}
277
278
	/**
279
	 * @generated
280
	 */
281
	public ParserOptions getParserOptions() {
282
		return ParserOptions.NONE;
283
	}
284
285
	/**
286
	 * @generated
287
	 */
288
	public IParser getParser() {
289
		if (parser == null) {
290
			String parserHint = ((View) getModel()).getType();
291
			ParserHintAdapter hintAdapter = new ParserHintAdapter(getParserElement(), parserHint) {
292
293
				public Object getAdapter(Class adapter) {
294
					if (IElementType.class.equals(adapter)) {
295
						return UMLElementTypes.Property_3014;
296
					}
297
					return super.getAdapter(adapter);
298
				}
299
			};
300
			parser = ParserService.getInstance().getParser(hintAdapter);
301
		}
302
		return parser;
303
	}
304
305
	/**
306
	 * @generated
307
	 */
308
	protected DirectEditManager getManager() {
309
		if (manager == null) {
310
			setManager(new TextDirectEditManager(this, TextDirectEditManager.getTextCellEditorClass(this), UMLEditPartFactory.getTextCellEditorLocator(this)));
311
		}
312
		return manager;
313
	}
314
315
	/**
316
	 * @generated
317
	 */
318
	protected void setManager(DirectEditManager manager) {
319
		this.manager = manager;
320
	}
321
322
	/**
323
	 * @generated
324
	 */
325
	protected void performDirectEdit() {
326
		getManager().show();
327
	}
328
329
	/**
330
	 * @generated
331
	 */
332
	protected void performDirectEdit(Point eventLocation) {
333
		if (getManager().getClass() == TextDirectEditManager.class) {
334
			((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint());
335
		}
336
	}
337
338
	/**
339
	 * @generated
340
	 */
341
	private void performDirectEdit(char initialCharacter) {
342
		if (getManager() instanceof TextDirectEditManager) {
343
			((TextDirectEditManager) getManager()).show(initialCharacter);
344
		} else {
345
			performDirectEdit();
346
		}
347
	}
348
349
	/**
350
	 * @generated
351
	 */
352
	protected void performDirectEditRequest(Request request) {
353
		final Request theRequest = request;
354
		try {
355
			getEditingDomain().runExclusive(new Runnable() {
356
357
				public void run() {
358
					if (isActive() && isEditable()) {
359
						if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) {
360
							Character initialChar = (Character) theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR);
361
							performDirectEdit(initialChar.charValue());
362
						} else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) {
363
							DirectEditRequest editRequest = (DirectEditRequest) theRequest;
364
							performDirectEdit(editRequest.getLocation());
365
						} else {
366
							performDirectEdit();
367
						}
368
					}
369
				}
370
			});
371
		} catch (InterruptedException e) {
372
			e.printStackTrace();
373
		}
374
	}
375
376
	/**
377
	 * @generated
378
	 */
379
	protected void refreshVisuals() {
380
		super.refreshVisuals();
381
		refreshLabel();
382
		refreshFont();
383
		refreshFontColor();
384
		refreshUnderline();
385
		refreshStrikeThrough();
386
	}
387
388
	/**
389
	 * @generated
390
	 */
391
	protected void refreshLabel() {
392
		setLabelTextHelper(getFigure(), getLabelText());
393
		setLabelIconHelper(getFigure(), getLabelIcon());
394
		Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
395
		if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) {
396
			((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback();
397
		}
398
	}
399
400
	/**
401
	 * @generated
402
	 */
403
	protected void refreshUnderline() {
404
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
405
		if (style != null && getFigure() instanceof WrapLabel) {
406
			((WrapLabel) getFigure()).setTextUnderline(style.isUnderline());
407
		}
408
	}
409
410
	/**
411
	 * @generated
412
	 */
413
	protected void refreshStrikeThrough() {
414
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
415
		if (style != null && getFigure() instanceof WrapLabel) {
416
			((WrapLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough());
417
		}
418
	}
419
420
	/**
421
	 * @generated
422
	 */
423
	protected void refreshFont() {
424
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
425
		if (style != null) {
426
			FontData fontData = new FontData(style.getFontName(), style.getFontHeight(), (style.isBold() ? SWT.BOLD : SWT.NORMAL) | (style.isItalic() ? SWT.ITALIC : SWT.NORMAL));
427
			setFont(fontData);
428
		}
429
	}
430
431
	/**
432
	 * @generated
433
	 */
434
	protected void setFontColor(Color color) {
435
		getFigure().setForegroundColor(color);
436
	}
437
438
	/**
439
	 * @generated
440
	 */
441
	protected void addSemanticListeners() {
442
		if (getParser() instanceof ISemanticParser) {
443
			EObject element = resolveSemanticElement();
444
			parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element);
445
			for (int i = 0; i < parserElements.size(); i++) {
446
				addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$
447
			}
448
		} else {
449
			super.addSemanticListeners();
450
		}
451
	}
452
453
	/**
454
	 * @generated
455
	 */
456
	protected void removeSemanticListeners() {
457
		if (parserElements != null) {
458
			for (int i = 0; i < parserElements.size(); i++) {
459
				removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$
460
			}
461
		} else {
462
			super.removeSemanticListeners();
463
		}
464
	}
465
466
	/**
467
	 * @generated
468
	 */
469
	protected AccessibleEditPart getAccessibleEditPart() {
470
		if (accessibleEP == null) {
471
			accessibleEP = new AccessibleGraphicalEditPart() {
472
473
				public void getName(AccessibleEvent e) {
474
					e.result = getLabelTextHelper(getFigure());
475
				}
476
			};
477
		}
478
		return accessibleEP;
479
	}
480
481
	/**
482
	 * @generated
483
	 */
484
	private View getFontStyleOwnerView() {
485
		return getPrimaryView();
486
	}
487
488
	/**
489
	 * @generated
490
	 */
491
	protected void addNotationalListeners() {
492
		super.addNotationalListeners();
493
		addListenerFilter("PrimaryView", this, getPrimaryView()); //$NON-NLS-1$
494
	}
495
496
	/**
497
	 * @generated
498
	 */
499
	protected void removeNotationalListeners() {
500
		super.removeNotationalListeners();
501
		removeListenerFilter("PrimaryView"); //$NON-NLS-1$
502
	}
503
504
	/**
505
	 * @generated
506
	 */
507
	protected void handleNotificationEvent(Notification event) {
508
		Object feature = event.getFeature();
509
		if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) {
510
			Integer c = (Integer) event.getNewValue();
511
			setFontColor(DiagramColorRegistry.getInstance().getColor(c));
512
		} else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) {
513
			refreshUnderline();
514
		} else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) {
515
			refreshStrikeThrough();
516
		} else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature)
517
				|| NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) {
518
			refreshFont();
519
		} else {
520
			if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) {
521
				refreshLabel();
522
			}
523
			if (getParser() instanceof ISemanticParser) {
524
				ISemanticParser modelParser = (ISemanticParser) getParser();
525
				if (modelParser.areSemanticElementsAffected(null, event)) {
526
					removeSemanticListeners();
527
					if (resolveSemanticElement() != null) {
528
						addSemanticListeners();
529
					}
530
					refreshLabel();
531
				}
532
			}
533
		}
534
		super.handleNotificationEvent(event);
535
	}
536
537
	/**
538
	 * @generated
539
	 */
540
	protected IFigure createFigure() {
541
		IFigure label = createFigurePrim();
542
		defaultText = getLabelTextHelper(label);
543
		return label;
544
	}
545
546
	/**
547
	 * @generated
548
	 */
549
	protected IFigure createFigurePrim() {
550
		return new WrapLabel();
551
	}
552
553
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/policies/OperationItemSemanticEditPolicy.java (+255 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.policies;
2
3
import org.eclipse.emf.ecore.EAnnotation;
4
import org.eclipse.emf.ecore.EClass;
5
import org.eclipse.emf.ecore.EObject;
6
import org.eclipse.gef.commands.Command;
7
import org.eclipse.gef.commands.UnexecutableCommand;
8
import org.eclipse.gmf.runtime.emf.type.core.commands.CreateRelationshipCommand;
9
import org.eclipse.gmf.runtime.emf.type.core.commands.DestroyElementCommand;
10
import org.eclipse.gmf.runtime.emf.type.core.commands.SetValueCommand;
11
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest;
12
import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest;
13
import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest;
14
import org.eclipse.gmf.runtime.notation.View;
15
import org.eclipse.uml2.diagram.clazz.providers.UMLElementTypes;
16
import org.eclipse.uml2.uml.Constraint;
17
import org.eclipse.uml2.uml.Dependency;
18
import org.eclipse.uml2.uml.NamedElement;
19
import org.eclipse.uml2.uml.UMLPackage;
20
import org.eclipse.uml2.uml.Usage;
21
22
/**
23
 * @generated
24
 */
25
public class OperationItemSemanticEditPolicy extends UMLBaseItemSemanticEditPolicy {
26
27
	/**
28
	 * @generated
29
	 */
30
	protected Command getDestroyElementCommand(DestroyElementRequest req) {
31
		return getMSLWrapper(new DestroyElementCommand(req) {
32
33
			protected EObject getElementToDestroy() {
34
				View view = (View) getHost().getModel();
35
				EAnnotation annotation = view.getEAnnotation("Shortcut"); //$NON-NLS-1$
36
				if (annotation != null) {
37
					return view;
38
				}
39
				return super.getElementToDestroy();
40
			}
41
42
		});
43
	}
44
45
	/**
46
	 * @generated
47
	 */
48
	protected Command getCreateRelationshipCommand(CreateRelationshipRequest req) {
49
		if (UMLElementTypes.Dependency_4002 == req.getElementType()) {
50
			return req.getTarget() == null ? getCreateStartOutgoingDependency4002Command(req) : getCreateCompleteIncomingDependency4002Command(req);
51
		}
52
		if (UMLElementTypes.ConstraintConstrainedElement_4004 == req.getElementType()) {
53
			return req.getTarget() == null ? null : getCreateCompleteIncomingConstraint_ConstrainedElement4004Command(req);
54
		}
55
		if (UMLElementTypes.DependencySupplier_4006 == req.getElementType()) {
56
			return req.getTarget() == null ? null : getCreateCompleteIncomingDependency_Supplier4006Command(req);
57
		}
58
		if (UMLElementTypes.DependencyClient_4007 == req.getElementType()) {
59
			return req.getTarget() == null ? null : getCreateCompleteIncomingDependency_Client4007Command(req);
60
		}
61
		if (UMLElementTypes.Usage_4009 == req.getElementType()) {
62
			return req.getTarget() == null ? getCreateStartOutgoingUsage4009Command(req) : getCreateCompleteIncomingUsage4009Command(req);
63
		}
64
		return super.getCreateRelationshipCommand(req);
65
	}
66
67
	/**
68
	 * @generated
69
	 */
70
	protected Command getCreateStartOutgoingDependency4002Command(CreateRelationshipRequest req) {
71
		return new Command() {
72
		};
73
	}
74
75
	/**
76
	 * @generated
77
	 */
78
	protected Command getCreateCompleteIncomingDependency4002Command(CreateRelationshipRequest req) {
79
		if (!(req.getSource() instanceof NamedElement)) {
80
			return UnexecutableCommand.INSTANCE;
81
		}
82
		final org.eclipse.uml2.uml.Package element = (org.eclipse.uml2.uml.Package) getRelationshipContainer(req.getSource(), UMLPackage.eINSTANCE.getPackage(), req.getElementType());
83
		if (element == null) {
84
			return UnexecutableCommand.INSTANCE;
85
		}
86
		if (req.getContainmentFeature() == null) {
87
			req.setContainmentFeature(UMLPackage.eINSTANCE.getPackage_PackagedElement());
88
		}
89
		return getMSLWrapper(new CreateIncomingDependency4002Command(req) {
90
91
			protected EObject getElementToEdit() {
92
				return element;
93
			}
94
		});
95
	}
96
97
	/**
98
	 * @generated
99
	 */
100
	private static class CreateIncomingDependency4002Command extends CreateRelationshipCommand {
101
102
		/**
103
		 * @generated
104
		 */
105
		public CreateIncomingDependency4002Command(CreateRelationshipRequest req) {
106
			super(req);
107
		}
108
109
		/**
110
		 * @generated
111
		 */
112
		protected EClass getEClassToEdit() {
113
			return UMLPackage.eINSTANCE.getPackage();
114
		};
115
116
		/**
117
		 * @generated
118
		 */
119
		protected void setElementToEdit(EObject element) {
120
			throw new UnsupportedOperationException();
121
		}
122
123
		/**
124
		 * @generated
125
		 */
126
		protected EObject doDefaultElementCreation() {
127
			Dependency newElement = (Dependency) super.doDefaultElementCreation();
128
			if (newElement != null) {
129
				newElement.getSuppliers().add((NamedElement) getTarget());
130
				newElement.getClients().add((NamedElement) getSource());
131
			}
132
			return newElement;
133
		}
134
	}
135
136
	/**
137
	 * @generated
138
	 */
139
	protected Command getCreateCompleteIncomingConstraint_ConstrainedElement4004Command(CreateRelationshipRequest req) {
140
		if (!(req.getSource() instanceof Constraint)) {
141
			return UnexecutableCommand.INSTANCE;
142
		}
143
		Constraint element = (Constraint) req.getSource();
144
		if (element.getConstrainedElements().contains(req.getTarget())) {
145
			return UnexecutableCommand.INSTANCE;
146
		}
147
		SetRequest setReq = new SetRequest(req.getSource(), UMLPackage.eINSTANCE.getConstraint_ConstrainedElement(), req.getTarget());
148
		return getMSLWrapper(new SetValueCommand(setReq));
149
	}
150
151
	/**
152
	 * @generated
153
	 */
154
	protected Command getCreateCompleteIncomingDependency_Supplier4006Command(CreateRelationshipRequest req) {
155
		if (!(req.getSource() instanceof Dependency)) {
156
			return UnexecutableCommand.INSTANCE;
157
		}
158
		Dependency element = (Dependency) req.getSource();
159
		if (element.getSuppliers().contains(req.getTarget())) {
160
			return UnexecutableCommand.INSTANCE;
161
		}
162
		SetRequest setReq = new SetRequest(req.getSource(), UMLPackage.eINSTANCE.getDependency_Supplier(), req.getTarget());
163
		return getMSLWrapper(new SetValueCommand(setReq));
164
	}
165
166
	/**
167
	 * @generated
168
	 */
169
	protected Command getCreateCompleteIncomingDependency_Client4007Command(CreateRelationshipRequest req) {
170
		if (!(req.getSource() instanceof Dependency)) {
171
			return UnexecutableCommand.INSTANCE;
172
		}
173
		Dependency element = (Dependency) req.getSource();
174
		if (element.getClients().contains(req.getTarget())) {
175
			return UnexecutableCommand.INSTANCE;
176
		}
177
		SetRequest setReq = new SetRequest(req.getSource(), UMLPackage.eINSTANCE.getDependency_Client(), req.getTarget());
178
		return getMSLWrapper(new SetValueCommand(setReq));
179
	}
180
181
	/**
182
	 * @generated
183
	 */
184
	protected Command getCreateStartOutgoingUsage4009Command(CreateRelationshipRequest req) {
185
		if (!UMLBaseItemSemanticEditPolicy.LinkConstraints.Usage_4009.canCreateLink(req, false)) {
186
			return UnexecutableCommand.INSTANCE;
187
		}
188
		return new Command() {
189
		};
190
	}
191
192
	/**
193
	 * @generated
194
	 */
195
	protected Command getCreateCompleteIncomingUsage4009Command(CreateRelationshipRequest req) {
196
		if (!(req.getSource() instanceof NamedElement)) {
197
			return UnexecutableCommand.INSTANCE;
198
		}
199
		final org.eclipse.uml2.uml.Package element = (org.eclipse.uml2.uml.Package) getRelationshipContainer(req.getSource(), UMLPackage.eINSTANCE.getPackage(), req.getElementType());
200
		if (element == null) {
201
			return UnexecutableCommand.INSTANCE;
202
		}
203
		if (!UMLBaseItemSemanticEditPolicy.LinkConstraints.Usage_4009.canCreateLink(req, false)) {
204
			return UnexecutableCommand.INSTANCE;
205
		}
206
		if (req.getContainmentFeature() == null) {
207
			req.setContainmentFeature(UMLPackage.eINSTANCE.getPackage_PackagedElement());
208
		}
209
		return getMSLWrapper(new CreateIncomingUsage4009Command(req) {
210
211
			protected EObject getElementToEdit() {
212
				return element;
213
			}
214
		});
215
	}
216
217
	/**
218
	 * @generated
219
	 */
220
	private static class CreateIncomingUsage4009Command extends CreateRelationshipCommand {
221
222
		/**
223
		 * @generated
224
		 */
225
		public CreateIncomingUsage4009Command(CreateRelationshipRequest req) {
226
			super(req);
227
		}
228
229
		/**
230
		 * @generated
231
		 */
232
		protected EClass getEClassToEdit() {
233
			return UMLPackage.eINSTANCE.getPackage();
234
		};
235
236
		/**
237
		 * @generated
238
		 */
239
		protected void setElementToEdit(EObject element) {
240
			throw new UnsupportedOperationException();
241
		}
242
243
		/**
244
		 * @generated
245
		 */
246
		protected EObject doDefaultElementCreation() {
247
			Usage newElement = (Usage) super.doDefaultElementCreation();
248
			if (newElement != null) {
249
				newElement.getSuppliers().add((NamedElement) getTarget());
250
				newElement.getClients().add((NamedElement) getSource());
251
			}
252
			return newElement;
253
		}
254
	}
255
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/policies/ConstraintConstrainedElementItemSemanticEditPolicy.java (+18 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.policies;
2
3
import org.eclipse.gef.commands.Command;
4
import org.eclipse.gmf.runtime.emf.type.core.commands.DestroyReferenceCommand;
5
import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyReferenceRequest;
6
7
/**
8
 * @generated
9
 */
10
public class ConstraintConstrainedElementItemSemanticEditPolicy extends UMLBaseItemSemanticEditPolicy {
11
12
	/**
13
	 * @generated
14
	 */
15
	protected Command getDestroyReferenceCommand(DestroyReferenceRequest req) {
16
		return getMSLWrapper(new DestroyReferenceCommand(req));
17
	}
18
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/parts/ClassNameEditPart.java (+551 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.parts;
2
3
import java.util.ArrayList;
4
import java.util.Collections;
5
import java.util.List;
6
7
import org.eclipse.draw2d.IFigure;
8
import org.eclipse.draw2d.Label;
9
import org.eclipse.draw2d.geometry.Point;
10
import org.eclipse.emf.common.notify.Notification;
11
import org.eclipse.emf.ecore.EObject;
12
import org.eclipse.emf.transaction.RunnableWithResult;
13
import org.eclipse.gef.AccessibleEditPart;
14
import org.eclipse.gef.EditPolicy;
15
import org.eclipse.gef.GraphicalEditPart;
16
import org.eclipse.gef.Request;
17
import org.eclipse.gef.commands.Command;
18
import org.eclipse.gef.editpolicies.NonResizableEditPolicy;
19
import org.eclipse.gef.handles.NonResizableHandleKit;
20
import org.eclipse.gef.requests.DirectEditRequest;
21
import org.eclipse.gef.tools.DirectEditManager;
22
import org.eclipse.gmf.runtime.common.ui.services.parser.IParser;
23
import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus;
24
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserEditStatus;
25
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions;
26
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserService;
27
import org.eclipse.gmf.runtime.diagram.ui.editparts.CompartmentEditPart;
28
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
29
import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart;
30
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy;
31
import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry;
32
import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants;
33
import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager;
34
import org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel;
35
import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
36
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
37
import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser;
38
import org.eclipse.gmf.runtime.emf.ui.services.parser.ParserHintAdapter;
39
import org.eclipse.gmf.runtime.notation.FontStyle;
40
import org.eclipse.gmf.runtime.notation.NotationPackage;
41
import org.eclipse.gmf.runtime.notation.View;
42
import org.eclipse.jface.resource.ImageDescriptor;
43
import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
44
import org.eclipse.jface.viewers.ICellEditorValidator;
45
import org.eclipse.swt.SWT;
46
import org.eclipse.swt.accessibility.AccessibleEvent;
47
import org.eclipse.swt.graphics.Color;
48
import org.eclipse.swt.graphics.FontData;
49
import org.eclipse.swt.graphics.Image;
50
import org.eclipse.uml2.diagram.clazz.edit.policies.UMLTextSelectionEditPolicy;
51
import org.eclipse.uml2.diagram.clazz.part.UMLDiagramEditorPlugin;
52
import org.eclipse.uml2.diagram.clazz.providers.UMLElementTypes;
53
54
/**
55
 * @generated
56
 */
57
public class ClassNameEditPart extends CompartmentEditPart implements ITextAwareEditPart {
58
59
	/**
60
	 * @generated
61
	 */
62
	public static final int VISUAL_ID = 5003;
63
64
	/**
65
	 * @generated
66
	 */
67
	private DirectEditManager manager;
68
69
	/**
70
	 * @generated
71
	 */
72
	private IParser parser;
73
74
	/**
75
	 * @generated
76
	 */
77
	private List parserElements;
78
79
	/**
80
	 * @generated
81
	 */
82
	private String defaultText;
83
84
	/**
85
	 * @generated
86
	 */
87
	public ClassNameEditPart(View view) {
88
		super(view);
89
	}
90
91
	/**
92
	 * @generated
93
	 */
94
	protected void createDefaultEditPolicies() {
95
		super.createDefaultEditPolicies();
96
		installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy());
97
		installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new NonResizableEditPolicy() {
98
99
			protected List createSelectionHandles() {
100
				List handles = new ArrayList();
101
				NonResizableHandleKit.addMoveHandle((GraphicalEditPart) getHost(), handles);
102
				return handles;
103
			}
104
105
			public Command getCommand(Request request) {
106
				return null;
107
			}
108
109
			public boolean understandsRequest(Request request) {
110
				return false;
111
			}
112
		});
113
114
	}
115
116
	/**
117
	 * @generated
118
	 */
119
	protected String getLabelTextHelper(IFigure figure) {
120
		if (figure instanceof WrapLabel) {
121
			return ((WrapLabel) figure).getText();
122
		} else {
123
			return ((Label) figure).getText();
124
		}
125
	}
126
127
	/**
128
	 * @generated
129
	 */
130
	protected void setLabelTextHelper(IFigure figure, String text) {
131
		if (figure instanceof WrapLabel) {
132
			((WrapLabel) figure).setText(text);
133
		} else {
134
			((Label) figure).setText(text);
135
		}
136
	}
137
138
	/**
139
	 * @generated
140
	 */
141
	protected Image getLabelIconHelper(IFigure figure) {
142
		if (figure instanceof WrapLabel) {
143
			return ((WrapLabel) figure).getIcon();
144
		} else {
145
			return ((Label) figure).getIcon();
146
		}
147
	}
148
149
	/**
150
	 * @generated
151
	 */
152
	protected void setLabelIconHelper(IFigure figure, Image icon) {
153
		if (figure instanceof WrapLabel) {
154
			((WrapLabel) figure).setIcon(icon);
155
		} else {
156
			((Label) figure).setIcon(icon);
157
		}
158
	}
159
160
	/**
161
	 * @generated
162
	 */
163
	public void setLabel(WrapLabel figure) {
164
		unregisterVisuals();
165
		setFigure(figure);
166
		defaultText = getLabelTextHelper(figure);
167
		registerVisuals();
168
		refreshVisuals();
169
	}
170
171
	/**
172
	 * @generated
173
	 */
174
	protected List getModelChildren() {
175
		return Collections.EMPTY_LIST;
176
	}
177
178
	/**
179
	 * @generated
180
	 */
181
	public IGraphicalEditPart getChildBySemanticHint(String semanticHint) {
182
		return null;
183
	}
184
185
	/**
186
	 * @generated
187
	 */
188
	protected EObject getParserElement() {
189
		EObject element = resolveSemanticElement();
190
		return element != null ? element : (View) getModel();
191
	}
192
193
	/**
194
	 * @generated
195
	 */
196
	protected Image getLabelIcon() {
197
		EObject parserElement = getParserElement();
198
		if (parserElement == null) {
199
			return null;
200
		}
201
		return UMLElementTypes.getImage(parserElement.eClass());
202
	}
203
204
	/**
205
	 * @generated
206
	 */
207
	protected String getLabelText() {
208
		String text = null;
209
		if (getParser() != null) {
210
			text = getParser().getPrintString(new EObjectAdapter(getParserElement()), getParserOptions().intValue());
211
		}
212
		if (text == null || text.length() == 0) {
213
			text = defaultText;
214
		}
215
		return text;
216
	}
217
218
	/**
219
	 * @generated
220
	 */
221
	public void setLabelText(String text) {
222
		setLabelTextHelper(getFigure(), text);
223
		Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
224
		if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) {
225
			((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback();
226
		}
227
	}
228
229
	/**
230
	 * @generated
231
	 */
232
	public String getEditText() {
233
		if (getParser() == null) {
234
			return ""; //$NON-NLS-1$
235
		}
236
		return getParser().getEditString(new EObjectAdapter(getParserElement()), getParserOptions().intValue());
237
	}
238
239
	/**
240
	 * @generated
241
	 */
242
	protected boolean isEditable() {
243
		return getEditText() != null;
244
	}
245
246
	/**
247
	 * @generated
248
	 */
249
	public ICellEditorValidator getEditTextValidator() {
250
		return new ICellEditorValidator() {
251
252
			public String isValid(final Object value) {
253
				if (value instanceof String) {
254
					final EObject element = getParserElement();
255
					final IParser parser = getParser();
256
					try {
257
						IParserEditStatus valid = (IParserEditStatus) getEditingDomain().runExclusive(new RunnableWithResult.Impl() {
258
259
							public void run() {
260
								setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value));
261
							}
262
						});
263
						return valid.getCode() == ParserEditStatus.EDITABLE ? null : valid.getMessage();
264
					} catch (InterruptedException ie) {
265
						ie.printStackTrace();
266
					}
267
				}
268
269
				// shouldn't get here
270
				return null;
271
			}
272
		};
273
	}
274
275
	/**
276
	 * @generated
277
	 */
278
	public IContentAssistProcessor getCompletionProcessor() {
279
		if (getParser() == null) {
280
			return null;
281
		}
282
		return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement()));
283
	}
284
285
	/**
286
	 * @generated
287
	 */
288
	public ParserOptions getParserOptions() {
289
		return ParserOptions.NONE;
290
	}
291
292
	/**
293
	 * @generated
294
	 */
295
	public IParser getParser() {
296
		if (parser == null) {
297
			String parserHint = ((View) getModel()).getType();
298
			ParserHintAdapter hintAdapter = new ParserHintAdapter(getParserElement(), parserHint) {
299
300
				public Object getAdapter(Class adapter) {
301
					if (IElementType.class.equals(adapter)) {
302
						return UMLElementTypes.Class_2001;
303
					}
304
					return super.getAdapter(adapter);
305
				}
306
			};
307
			parser = ParserService.getInstance().getParser(hintAdapter);
308
		}
309
		return parser;
310
	}
311
312
	/**
313
	 * @generated
314
	 */
315
	protected DirectEditManager getManager() {
316
		if (manager == null) {
317
			setManager(new TextDirectEditManager(this, TextDirectEditManager.getTextCellEditorClass(this), UMLEditPartFactory.getTextCellEditorLocator(this)));
318
		}
319
		return manager;
320
	}
321
322
	/**
323
	 * @generated
324
	 */
325
	protected void setManager(DirectEditManager manager) {
326
		this.manager = manager;
327
	}
328
329
	/**
330
	 * @generated
331
	 */
332
	protected void performDirectEdit() {
333
		getManager().show();
334
	}
335
336
	/**
337
	 * @generated
338
	 */
339
	protected void performDirectEdit(Point eventLocation) {
340
		if (getManager().getClass() == TextDirectEditManager.class) {
341
			((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint());
342
		}
343
	}
344
345
	/**
346
	 * @generated
347
	 */
348
	private void performDirectEdit(char initialCharacter) {
349
		if (getManager() instanceof TextDirectEditManager) {
350
			((TextDirectEditManager) getManager()).show(initialCharacter);
351
		} else {
352
			performDirectEdit();
353
		}
354
	}
355
356
	/**
357
	 * @generated
358
	 */
359
	protected void performDirectEditRequest(Request request) {
360
		final Request theRequest = request;
361
		try {
362
			getEditingDomain().runExclusive(new Runnable() {
363
364
				public void run() {
365
					if (isActive() && isEditable()) {
366
						if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) {
367
							Character initialChar = (Character) theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR);
368
							performDirectEdit(initialChar.charValue());
369
						} else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) {
370
							DirectEditRequest editRequest = (DirectEditRequest) theRequest;
371
							performDirectEdit(editRequest.getLocation());
372
						} else {
373
							performDirectEdit();
374
						}
375
					}
376
				}
377
			});
378
		} catch (InterruptedException e) {
379
			e.printStackTrace();
380
		}
381
	}
382
383
	/**
384
	 * @generated
385
	 */
386
	protected void refreshVisuals() {
387
		super.refreshVisuals();
388
		refreshLabel();
389
		refreshFont();
390
		refreshFontColor();
391
		refreshUnderline();
392
		refreshStrikeThrough();
393
	}
394
395
	/**
396
	 * @generated
397
	 */
398
	protected void refreshLabel() {
399
		setLabelTextHelper(getFigure(), getLabelText());
400
		setLabelIconHelper(getFigure(), getLabelIcon());
401
		Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
402
		if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) {
403
			((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback();
404
		}
405
	}
406
407
	/**
408
	 * @generated
409
	 */
410
	protected void refreshUnderline() {
411
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
412
		if (style != null && getFigure() instanceof WrapLabel) {
413
			((WrapLabel) getFigure()).setTextUnderline(style.isUnderline());
414
		}
415
	}
416
417
	/**
418
	 * @generated
419
	 */
420
	protected void refreshStrikeThrough() {
421
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
422
		if (style != null && getFigure() instanceof WrapLabel) {
423
			((WrapLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough());
424
		}
425
	}
426
427
	/**
428
	 * @generated
429
	 */
430
	protected void refreshFont() {
431
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
432
		if (style != null) {
433
			FontData fontData = new FontData(style.getFontName(), style.getFontHeight(), (style.isBold() ? SWT.BOLD : SWT.NORMAL) | (style.isItalic() ? SWT.ITALIC : SWT.NORMAL));
434
			setFont(fontData);
435
		}
436
	}
437
438
	/**
439
	 * @generated
440
	 */
441
	protected void setFontColor(Color color) {
442
		getFigure().setForegroundColor(color);
443
	}
444
445
	/**
446
	 * @generated
447
	 */
448
	protected void addSemanticListeners() {
449
		if (getParser() instanceof ISemanticParser) {
450
			EObject element = resolveSemanticElement();
451
			parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element);
452
			for (int i = 0; i < parserElements.size(); i++) {
453
				addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$
454
			}
455
		} else {
456
			super.addSemanticListeners();
457
		}
458
	}
459
460
	/**
461
	 * @generated
462
	 */
463
	protected void removeSemanticListeners() {
464
		if (parserElements != null) {
465
			for (int i = 0; i < parserElements.size(); i++) {
466
				removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$
467
			}
468
		} else {
469
			super.removeSemanticListeners();
470
		}
471
	}
472
473
	/**
474
	 * @generated
475
	 */
476
	protected AccessibleEditPart getAccessibleEditPart() {
477
		if (accessibleEP == null) {
478
			accessibleEP = new AccessibleGraphicalEditPart() {
479
480
				public void getName(AccessibleEvent e) {
481
					e.result = getLabelTextHelper(getFigure());
482
				}
483
			};
484
		}
485
		return accessibleEP;
486
	}
487
488
	/**
489
	 * @generated
490
	 */
491
	private View getFontStyleOwnerView() {
492
		return getPrimaryView();
493
	}
494
495
	/**
496
	 * @generated
497
	 */
498
	protected void addNotationalListeners() {
499
		super.addNotationalListeners();
500
		addListenerFilter("PrimaryView", this, getPrimaryView()); //$NON-NLS-1$
501
	}
502
503
	/**
504
	 * @generated
505
	 */
506
	protected void removeNotationalListeners() {
507
		super.removeNotationalListeners();
508
		removeListenerFilter("PrimaryView"); //$NON-NLS-1$
509
	}
510
511
	/**
512
	 * @generated
513
	 */
514
	protected void handleNotificationEvent(Notification event) {
515
		Object feature = event.getFeature();
516
		if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) {
517
			Integer c = (Integer) event.getNewValue();
518
			setFontColor(DiagramColorRegistry.getInstance().getColor(c));
519
		} else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) {
520
			refreshUnderline();
521
		} else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) {
522
			refreshStrikeThrough();
523
		} else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature)
524
				|| NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) {
525
			refreshFont();
526
		} else {
527
			if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) {
528
				refreshLabel();
529
			}
530
			if (getParser() instanceof ISemanticParser) {
531
				ISemanticParser modelParser = (ISemanticParser) getParser();
532
				if (modelParser.areSemanticElementsAffected(null, event)) {
533
					removeSemanticListeners();
534
					if (resolveSemanticElement() != null) {
535
						addSemanticListeners();
536
					}
537
					refreshLabel();
538
				}
539
			}
540
		}
541
		super.handleNotificationEvent(event);
542
	}
543
544
	/**
545
	 * @generated
546
	 */
547
	protected IFigure createFigure() {
548
		// Parent should assign one using setLabel method
549
		return null;
550
	}
551
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/policies/DataType2ItemSemanticEditPolicy.java (+455 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.policies;
2
3
import org.eclipse.emf.ecore.EAnnotation;
4
import org.eclipse.emf.ecore.EClass;
5
import org.eclipse.emf.ecore.EObject;
6
import org.eclipse.gef.commands.Command;
7
import org.eclipse.gef.commands.UnexecutableCommand;
8
import org.eclipse.gmf.runtime.emf.type.core.commands.CreateRelationshipCommand;
9
import org.eclipse.gmf.runtime.emf.type.core.commands.DestroyElementCommand;
10
import org.eclipse.gmf.runtime.emf.type.core.commands.SetValueCommand;
11
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest;
12
import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest;
13
import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest;
14
import org.eclipse.gmf.runtime.notation.View;
15
import org.eclipse.uml2.diagram.clazz.providers.UMLElementTypes;
16
import org.eclipse.uml2.uml.Association;
17
import org.eclipse.uml2.uml.Classifier;
18
import org.eclipse.uml2.uml.Constraint;
19
import org.eclipse.uml2.uml.Dependency;
20
import org.eclipse.uml2.uml.Generalization;
21
import org.eclipse.uml2.uml.NamedElement;
22
import org.eclipse.uml2.uml.Property;
23
import org.eclipse.uml2.uml.Type;
24
import org.eclipse.uml2.uml.UMLPackage;
25
import org.eclipse.uml2.uml.Usage;
26
27
/**
28
 * @generated
29
 */
30
public class DataType2ItemSemanticEditPolicy extends UMLBaseItemSemanticEditPolicy {
31
32
	/**
33
	 * @generated
34
	 */
35
	protected Command getDestroyElementCommand(DestroyElementRequest req) {
36
		return getMSLWrapper(new DestroyElementCommand(req) {
37
38
			protected EObject getElementToDestroy() {
39
				View view = (View) getHost().getModel();
40
				EAnnotation annotation = view.getEAnnotation("Shortcut"); //$NON-NLS-1$
41
				if (annotation != null) {
42
					return view;
43
				}
44
				return super.getElementToDestroy();
45
			}
46
47
		});
48
	}
49
50
	/**
51
	 * @generated
52
	 */
53
	protected Command getCreateRelationshipCommand(CreateRelationshipRequest req) {
54
		if (UMLElementTypes.Generalization_4001 == req.getElementType()) {
55
			return req.getTarget() == null ? getCreateStartOutgoingGeneralization4001Command(req) : getCreateCompleteIncomingGeneralization4001Command(req);
56
		}
57
		if (UMLElementTypes.Dependency_4002 == req.getElementType()) {
58
			return req.getTarget() == null ? getCreateStartOutgoingDependency4002Command(req) : getCreateCompleteIncomingDependency4002Command(req);
59
		}
60
		if (UMLElementTypes.Property_4003 == req.getElementType()) {
61
			return req.getTarget() == null ? null : getCreateCompleteIncomingProperty4003Command(req);
62
		}
63
		if (UMLElementTypes.ConstraintConstrainedElement_4004 == req.getElementType()) {
64
			return req.getTarget() == null ? null : getCreateCompleteIncomingConstraint_ConstrainedElement4004Command(req);
65
		}
66
		if (UMLElementTypes.Association_4005 == req.getElementType()) {
67
			return req.getTarget() == null ? getCreateStartOutgoingAssociation4005Command(req) : getCreateCompleteIncomingAssociation4005Command(req);
68
		}
69
		if (UMLElementTypes.DependencySupplier_4006 == req.getElementType()) {
70
			return req.getTarget() == null ? null : getCreateCompleteIncomingDependency_Supplier4006Command(req);
71
		}
72
		if (UMLElementTypes.DependencyClient_4007 == req.getElementType()) {
73
			return req.getTarget() == null ? null : getCreateCompleteIncomingDependency_Client4007Command(req);
74
		}
75
		if (UMLElementTypes.Usage_4009 == req.getElementType()) {
76
			return req.getTarget() == null ? getCreateStartOutgoingUsage4009Command(req) : getCreateCompleteIncomingUsage4009Command(req);
77
		}
78
		return super.getCreateRelationshipCommand(req);
79
	}
80
81
	/**
82
	 * @generated
83
	 */
84
	protected Command getCreateStartOutgoingGeneralization4001Command(CreateRelationshipRequest req) {
85
		return new Command() {
86
		};
87
	}
88
89
	/**
90
	 * @generated
91
	 */
92
	protected Command getCreateCompleteIncomingGeneralization4001Command(CreateRelationshipRequest req) {
93
		if (!(req.getSource() instanceof Classifier)) {
94
			return UnexecutableCommand.INSTANCE;
95
		}
96
		final Classifier element = (Classifier) req.getSource();
97
		if (req.getContainmentFeature() == null) {
98
			req.setContainmentFeature(UMLPackage.eINSTANCE.getClassifier_Generalization());
99
		}
100
		return getMSLWrapper(new CreateIncomingGeneralization4001Command(req) {
101
102
			protected EObject getElementToEdit() {
103
				return element;
104
			}
105
		});
106
	}
107
108
	/**
109
	 * @generated
110
	 */
111
	private static class CreateIncomingGeneralization4001Command extends CreateRelationshipCommand {
112
113
		/**
114
		 * @generated
115
		 */
116
		public CreateIncomingGeneralization4001Command(CreateRelationshipRequest req) {
117
			super(req);
118
		}
119
120
		/**
121
		 * @generated
122
		 */
123
		protected EClass getEClassToEdit() {
124
			return UMLPackage.eINSTANCE.getClassifier();
125
		};
126
127
		/**
128
		 * @generated
129
		 */
130
		protected void setElementToEdit(EObject element) {
131
			throw new UnsupportedOperationException();
132
		}
133
134
		/**
135
		 * @generated
136
		 */
137
		protected EObject doDefaultElementCreation() {
138
			Generalization newElement = (Generalization) super.doDefaultElementCreation();
139
			if (newElement != null) {
140
				newElement.setGeneral((Classifier) getTarget());
141
			}
142
			return newElement;
143
		}
144
	}
145
146
	/**
147
	 * @generated
148
	 */
149
	protected Command getCreateStartOutgoingDependency4002Command(CreateRelationshipRequest req) {
150
		return new Command() {
151
		};
152
	}
153
154
	/**
155
	 * @generated
156
	 */
157
	protected Command getCreateCompleteIncomingDependency4002Command(CreateRelationshipRequest req) {
158
		if (!(req.getSource() instanceof NamedElement)) {
159
			return UnexecutableCommand.INSTANCE;
160
		}
161
		final org.eclipse.uml2.uml.Package element = (org.eclipse.uml2.uml.Package) getRelationshipContainer(req.getSource(), UMLPackage.eINSTANCE.getPackage(), req.getElementType());
162
		if (element == null) {
163
			return UnexecutableCommand.INSTANCE;
164
		}
165
		if (req.getContainmentFeature() == null) {
166
			req.setContainmentFeature(UMLPackage.eINSTANCE.getPackage_PackagedElement());
167
		}
168
		return getMSLWrapper(new CreateIncomingDependency4002Command(req) {
169
170
			protected EObject getElementToEdit() {
171
				return element;
172
			}
173
		});
174
	}
175
176
	/**
177
	 * @generated
178
	 */
179
	private static class CreateIncomingDependency4002Command extends CreateRelationshipCommand {
180
181
		/**
182
		 * @generated
183
		 */
184
		public CreateIncomingDependency4002Command(CreateRelationshipRequest req) {
185
			super(req);
186
		}
187
188
		/**
189
		 * @generated
190
		 */
191
		protected EClass getEClassToEdit() {
192
			return UMLPackage.eINSTANCE.getPackage();
193
		};
194
195
		/**
196
		 * @generated
197
		 */
198
		protected void setElementToEdit(EObject element) {
199
			throw new UnsupportedOperationException();
200
		}
201
202
		/**
203
		 * @generated
204
		 */
205
		protected EObject doDefaultElementCreation() {
206
			Dependency newElement = (Dependency) super.doDefaultElementCreation();
207
			if (newElement != null) {
208
				newElement.getSuppliers().add((NamedElement) getTarget());
209
				newElement.getClients().add((NamedElement) getSource());
210
			}
211
			return newElement;
212
		}
213
	}
214
215
	/**
216
	 * @generated
217
	 */
218
	protected Command getCreateCompleteIncomingProperty4003Command(CreateRelationshipRequest req) {
219
		if (!(req.getSource() instanceof Association)) {
220
			return UnexecutableCommand.INSTANCE;
221
		}
222
		final Association element = (Association) req.getSource();
223
		if (req.getContainmentFeature() == null) {
224
			req.setContainmentFeature(UMLPackage.eINSTANCE.getAssociation_OwnedEnd());
225
		}
226
		return getMSLWrapper(new CreateIncomingProperty4003Command(req) {
227
228
			protected EObject getElementToEdit() {
229
				return element;
230
			}
231
		});
232
	}
233
234
	/**
235
	 * @generated
236
	 */
237
	private static class CreateIncomingProperty4003Command extends CreateRelationshipCommand {
238
239
		/**
240
		 * @generated
241
		 */
242
		public CreateIncomingProperty4003Command(CreateRelationshipRequest req) {
243
			super(req);
244
		}
245
246
		/**
247
		 * @generated
248
		 */
249
		protected EClass getEClassToEdit() {
250
			return UMLPackage.eINSTANCE.getAssociation();
251
		};
252
253
		/**
254
		 * @generated
255
		 */
256
		protected void setElementToEdit(EObject element) {
257
			throw new UnsupportedOperationException();
258
		}
259
260
		/**
261
		 * @generated
262
		 */
263
		protected EObject doDefaultElementCreation() {
264
			Property newElement = (Property) super.doDefaultElementCreation();
265
			if (newElement != null) {
266
				newElement.setType((Type) getTarget());
267
			}
268
			return newElement;
269
		}
270
	}
271
272
	/**
273
	 * @generated
274
	 */
275
	protected Command getCreateCompleteIncomingConstraint_ConstrainedElement4004Command(CreateRelationshipRequest req) {
276
		if (!(req.getSource() instanceof Constraint)) {
277
			return UnexecutableCommand.INSTANCE;
278
		}
279
		Constraint element = (Constraint) req.getSource();
280
		if (element.getConstrainedElements().contains(req.getTarget())) {
281
			return UnexecutableCommand.INSTANCE;
282
		}
283
		SetRequest setReq = new SetRequest(req.getSource(), UMLPackage.eINSTANCE.getConstraint_ConstrainedElement(), req.getTarget());
284
		return getMSLWrapper(new SetValueCommand(setReq));
285
	}
286
287
	/**
288
	 * @generated
289
	 */
290
	protected Command getCreateStartOutgoingAssociation4005Command(CreateRelationshipRequest req) {
291
		return new Command() {
292
		};
293
	}
294
295
	/**
296
	 * @generated
297
	 */
298
	protected Command getCreateCompleteIncomingAssociation4005Command(CreateRelationshipRequest req) {
299
		if (!(req.getSource() instanceof Type)) {
300
			return UnexecutableCommand.INSTANCE;
301
		}
302
		final org.eclipse.uml2.uml.Package element = (org.eclipse.uml2.uml.Package) getRelationshipContainer(req.getSource(), UMLPackage.eINSTANCE.getPackage(), req.getElementType());
303
		if (element == null) {
304
			return UnexecutableCommand.INSTANCE;
305
		}
306
		if (req.getContainmentFeature() == null) {
307
			req.setContainmentFeature(UMLPackage.eINSTANCE.getPackage_PackagedElement());
308
		}
309
		return getMSLWrapper(new CreateIncomingAssociation4005Command(req) {
310
311
			protected EObject getElementToEdit() {
312
				return element;
313
			}
314
		});
315
	}
316
317
	/**
318
	 * @generated NOT
319
	 */
320
	private static class CreateIncomingAssociation4005Command extends CreateAssociationCommand {
321
322
		/**
323
		 * @generated
324
		 */
325
		public CreateIncomingAssociation4005Command(CreateRelationshipRequest req) {
326
			super(req);
327
		}
328
329
		/**
330
		 * @generated
331
		 */
332
		protected EClass getEClassToEdit() {
333
			return UMLPackage.eINSTANCE.getPackage();
334
		};
335
336
		/**
337
		 * @generated
338
		 */
339
		protected void setElementToEdit(EObject element) {
340
			throw new UnsupportedOperationException();
341
		}
342
343
		/**
344
		 * @generated NOT
345
		 */
346
		protected EObject doDefaultElementCreation() {
347
			return super.doDefaultElementCreation();
348
		}
349
	}
350
351
	/**
352
	 * @generated
353
	 */
354
	protected Command getCreateCompleteIncomingDependency_Supplier4006Command(CreateRelationshipRequest req) {
355
		if (!(req.getSource() instanceof Dependency)) {
356
			return UnexecutableCommand.INSTANCE;
357
		}
358
		Dependency element = (Dependency) req.getSource();
359
		if (element.getSuppliers().contains(req.getTarget())) {
360
			return UnexecutableCommand.INSTANCE;
361
		}
362
		SetRequest setReq = new SetRequest(req.getSource(), UMLPackage.eINSTANCE.getDependency_Supplier(), req.getTarget());
363
		return getMSLWrapper(new SetValueCommand(setReq));
364
	}
365
366
	/**
367
	 * @generated
368
	 */
369
	protected Command getCreateCompleteIncomingDependency_Client4007Command(CreateRelationshipRequest req) {
370
		if (!(req.getSource() instanceof Dependency)) {
371
			return UnexecutableCommand.INSTANCE;
372
		}
373
		Dependency element = (Dependency) req.getSource();
374
		if (element.getClients().contains(req.getTarget())) {
375
			return UnexecutableCommand.INSTANCE;
376
		}
377
		SetRequest setReq = new SetRequest(req.getSource(), UMLPackage.eINSTANCE.getDependency_Client(), req.getTarget());
378
		return getMSLWrapper(new SetValueCommand(setReq));
379
	}
380
381
	/**
382
	 * @generated
383
	 */
384
	protected Command getCreateStartOutgoingUsage4009Command(CreateRelationshipRequest req) {
385
		if (!UMLBaseItemSemanticEditPolicy.LinkConstraints.Usage_4009.canCreateLink(req, false)) {
386
			return UnexecutableCommand.INSTANCE;
387
		}
388
		return new Command() {
389
		};
390
	}
391
392
	/**
393
	 * @generated
394
	 */
395
	protected Command getCreateCompleteIncomingUsage4009Command(CreateRelationshipRequest req) {
396
		if (!(req.getSource() instanceof NamedElement)) {
397
			return UnexecutableCommand.INSTANCE;
398
		}
399
		final org.eclipse.uml2.uml.Package element = (org.eclipse.uml2.uml.Package) getRelationshipContainer(req.getSource(), UMLPackage.eINSTANCE.getPackage(), req.getElementType());
400
		if (element == null) {
401
			return UnexecutableCommand.INSTANCE;
402
		}
403
		if (!UMLBaseItemSemanticEditPolicy.LinkConstraints.Usage_4009.canCreateLink(req, false)) {
404
			return UnexecutableCommand.INSTANCE;
405
		}
406
		if (req.getContainmentFeature() == null) {
407
			req.setContainmentFeature(UMLPackage.eINSTANCE.getPackage_PackagedElement());
408
		}
409
		return getMSLWrapper(new CreateIncomingUsage4009Command(req) {
410
411
			protected EObject getElementToEdit() {
412
				return element;
413
			}
414
		});
415
	}
416
417
	/**
418
	 * @generated
419
	 */
420
	private static class CreateIncomingUsage4009Command extends CreateRelationshipCommand {
421
422
		/**
423
		 * @generated
424
		 */
425
		public CreateIncomingUsage4009Command(CreateRelationshipRequest req) {
426
			super(req);
427
		}
428
429
		/**
430
		 * @generated
431
		 */
432
		protected EClass getEClassToEdit() {
433
			return UMLPackage.eINSTANCE.getPackage();
434
		};
435
436
		/**
437
		 * @generated
438
		 */
439
		protected void setElementToEdit(EObject element) {
440
			throw new UnsupportedOperationException();
441
		}
442
443
		/**
444
		 * @generated
445
		 */
446
		protected EObject doDefaultElementCreation() {
447
			Usage newElement = (Usage) super.doDefaultElementCreation();
448
			if (newElement != null) {
449
				newElement.getSuppliers().add((NamedElement) getTarget());
450
				newElement.getClients().add((NamedElement) getSource());
451
			}
452
			return newElement;
453
		}
454
	}
455
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/parts/PrimitiveTypeNameEditPart.java (+551 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.parts;
2
3
import java.util.ArrayList;
4
import java.util.Collections;
5
import java.util.List;
6
7
import org.eclipse.draw2d.IFigure;
8
import org.eclipse.draw2d.Label;
9
import org.eclipse.draw2d.geometry.Point;
10
import org.eclipse.emf.common.notify.Notification;
11
import org.eclipse.emf.ecore.EObject;
12
import org.eclipse.emf.transaction.RunnableWithResult;
13
import org.eclipse.gef.AccessibleEditPart;
14
import org.eclipse.gef.EditPolicy;
15
import org.eclipse.gef.GraphicalEditPart;
16
import org.eclipse.gef.Request;
17
import org.eclipse.gef.commands.Command;
18
import org.eclipse.gef.editpolicies.NonResizableEditPolicy;
19
import org.eclipse.gef.handles.NonResizableHandleKit;
20
import org.eclipse.gef.requests.DirectEditRequest;
21
import org.eclipse.gef.tools.DirectEditManager;
22
import org.eclipse.gmf.runtime.common.ui.services.parser.IParser;
23
import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus;
24
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserEditStatus;
25
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions;
26
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserService;
27
import org.eclipse.gmf.runtime.diagram.ui.editparts.CompartmentEditPart;
28
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
29
import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart;
30
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy;
31
import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry;
32
import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants;
33
import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager;
34
import org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel;
35
import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
36
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
37
import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser;
38
import org.eclipse.gmf.runtime.emf.ui.services.parser.ParserHintAdapter;
39
import org.eclipse.gmf.runtime.notation.FontStyle;
40
import org.eclipse.gmf.runtime.notation.NotationPackage;
41
import org.eclipse.gmf.runtime.notation.View;
42
import org.eclipse.jface.resource.ImageDescriptor;
43
import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
44
import org.eclipse.jface.viewers.ICellEditorValidator;
45
import org.eclipse.swt.SWT;
46
import org.eclipse.swt.accessibility.AccessibleEvent;
47
import org.eclipse.swt.graphics.Color;
48
import org.eclipse.swt.graphics.FontData;
49
import org.eclipse.swt.graphics.Image;
50
import org.eclipse.uml2.diagram.clazz.edit.policies.UMLTextSelectionEditPolicy;
51
import org.eclipse.uml2.diagram.clazz.part.UMLDiagramEditorPlugin;
52
import org.eclipse.uml2.diagram.clazz.providers.UMLElementTypes;
53
54
/**
55
 * @generated
56
 */
57
public class PrimitiveTypeNameEditPart extends CompartmentEditPart implements ITextAwareEditPart {
58
59
	/**
60
	 * @generated
61
	 */
62
	public static final int VISUAL_ID = 5007;
63
64
	/**
65
	 * @generated
66
	 */
67
	private DirectEditManager manager;
68
69
	/**
70
	 * @generated
71
	 */
72
	private IParser parser;
73
74
	/**
75
	 * @generated
76
	 */
77
	private List parserElements;
78
79
	/**
80
	 * @generated
81
	 */
82
	private String defaultText;
83
84
	/**
85
	 * @generated
86
	 */
87
	public PrimitiveTypeNameEditPart(View view) {
88
		super(view);
89
	}
90
91
	/**
92
	 * @generated
93
	 */
94
	protected void createDefaultEditPolicies() {
95
		super.createDefaultEditPolicies();
96
		installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy());
97
		installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new NonResizableEditPolicy() {
98
99
			protected List createSelectionHandles() {
100
				List handles = new ArrayList();
101
				NonResizableHandleKit.addMoveHandle((GraphicalEditPart) getHost(), handles);
102
				return handles;
103
			}
104
105
			public Command getCommand(Request request) {
106
				return null;
107
			}
108
109
			public boolean understandsRequest(Request request) {
110
				return false;
111
			}
112
		});
113
114
	}
115
116
	/**
117
	 * @generated
118
	 */
119
	protected String getLabelTextHelper(IFigure figure) {
120
		if (figure instanceof WrapLabel) {
121
			return ((WrapLabel) figure).getText();
122
		} else {
123
			return ((Label) figure).getText();
124
		}
125
	}
126
127
	/**
128
	 * @generated
129
	 */
130
	protected void setLabelTextHelper(IFigure figure, String text) {
131
		if (figure instanceof WrapLabel) {
132
			((WrapLabel) figure).setText(text);
133
		} else {
134
			((Label) figure).setText(text);
135
		}
136
	}
137
138
	/**
139
	 * @generated
140
	 */
141
	protected Image getLabelIconHelper(IFigure figure) {
142
		if (figure instanceof WrapLabel) {
143
			return ((WrapLabel) figure).getIcon();
144
		} else {
145
			return ((Label) figure).getIcon();
146
		}
147
	}
148
149
	/**
150
	 * @generated
151
	 */
152
	protected void setLabelIconHelper(IFigure figure, Image icon) {
153
		if (figure instanceof WrapLabel) {
154
			((WrapLabel) figure).setIcon(icon);
155
		} else {
156
			((Label) figure).setIcon(icon);
157
		}
158
	}
159
160
	/**
161
	 * @generated
162
	 */
163
	public void setLabel(WrapLabel figure) {
164
		unregisterVisuals();
165
		setFigure(figure);
166
		defaultText = getLabelTextHelper(figure);
167
		registerVisuals();
168
		refreshVisuals();
169
	}
170
171
	/**
172
	 * @generated
173
	 */
174
	protected List getModelChildren() {
175
		return Collections.EMPTY_LIST;
176
	}
177
178
	/**
179
	 * @generated
180
	 */
181
	public IGraphicalEditPart getChildBySemanticHint(String semanticHint) {
182
		return null;
183
	}
184
185
	/**
186
	 * @generated
187
	 */
188
	protected EObject getParserElement() {
189
		EObject element = resolveSemanticElement();
190
		return element != null ? element : (View) getModel();
191
	}
192
193
	/**
194
	 * @generated
195
	 */
196
	protected Image getLabelIcon() {
197
		EObject parserElement = getParserElement();
198
		if (parserElement == null) {
199
			return null;
200
		}
201
		return UMLElementTypes.getImage(parserElement.eClass());
202
	}
203
204
	/**
205
	 * @generated
206
	 */
207
	protected String getLabelText() {
208
		String text = null;
209
		if (getParser() != null) {
210
			text = getParser().getPrintString(new EObjectAdapter(getParserElement()), getParserOptions().intValue());
211
		}
212
		if (text == null || text.length() == 0) {
213
			text = defaultText;
214
		}
215
		return text;
216
	}
217
218
	/**
219
	 * @generated
220
	 */
221
	public void setLabelText(String text) {
222
		setLabelTextHelper(getFigure(), text);
223
		Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
224
		if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) {
225
			((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback();
226
		}
227
	}
228
229
	/**
230
	 * @generated
231
	 */
232
	public String getEditText() {
233
		if (getParser() == null) {
234
			return ""; //$NON-NLS-1$
235
		}
236
		return getParser().getEditString(new EObjectAdapter(getParserElement()), getParserOptions().intValue());
237
	}
238
239
	/**
240
	 * @generated
241
	 */
242
	protected boolean isEditable() {
243
		return getEditText() != null;
244
	}
245
246
	/**
247
	 * @generated
248
	 */
249
	public ICellEditorValidator getEditTextValidator() {
250
		return new ICellEditorValidator() {
251
252
			public String isValid(final Object value) {
253
				if (value instanceof String) {
254
					final EObject element = getParserElement();
255
					final IParser parser = getParser();
256
					try {
257
						IParserEditStatus valid = (IParserEditStatus) getEditingDomain().runExclusive(new RunnableWithResult.Impl() {
258
259
							public void run() {
260
								setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value));
261
							}
262
						});
263
						return valid.getCode() == ParserEditStatus.EDITABLE ? null : valid.getMessage();
264
					} catch (InterruptedException ie) {
265
						ie.printStackTrace();
266
					}
267
				}
268
269
				// shouldn't get here
270
				return null;
271
			}
272
		};
273
	}
274
275
	/**
276
	 * @generated
277
	 */
278
	public IContentAssistProcessor getCompletionProcessor() {
279
		if (getParser() == null) {
280
			return null;
281
		}
282
		return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement()));
283
	}
284
285
	/**
286
	 * @generated
287
	 */
288
	public ParserOptions getParserOptions() {
289
		return ParserOptions.NONE;
290
	}
291
292
	/**
293
	 * @generated
294
	 */
295
	public IParser getParser() {
296
		if (parser == null) {
297
			String parserHint = ((View) getModel()).getType();
298
			ParserHintAdapter hintAdapter = new ParserHintAdapter(getParserElement(), parserHint) {
299
300
				public Object getAdapter(Class adapter) {
301
					if (IElementType.class.equals(adapter)) {
302
						return UMLElementTypes.PrimitiveType_2005;
303
					}
304
					return super.getAdapter(adapter);
305
				}
306
			};
307
			parser = ParserService.getInstance().getParser(hintAdapter);
308
		}
309
		return parser;
310
	}
311
312
	/**
313
	 * @generated
314
	 */
315
	protected DirectEditManager getManager() {
316
		if (manager == null) {
317
			setManager(new TextDirectEditManager(this, TextDirectEditManager.getTextCellEditorClass(this), UMLEditPartFactory.getTextCellEditorLocator(this)));
318
		}
319
		return manager;
320
	}
321
322
	/**
323
	 * @generated
324
	 */
325
	protected void setManager(DirectEditManager manager) {
326
		this.manager = manager;
327
	}
328
329
	/**
330
	 * @generated
331
	 */
332
	protected void performDirectEdit() {
333
		getManager().show();
334
	}
335
336
	/**
337
	 * @generated
338
	 */
339
	protected void performDirectEdit(Point eventLocation) {
340
		if (getManager().getClass() == TextDirectEditManager.class) {
341
			((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint());
342
		}
343
	}
344
345
	/**
346
	 * @generated
347
	 */
348
	private void performDirectEdit(char initialCharacter) {
349
		if (getManager() instanceof TextDirectEditManager) {
350
			((TextDirectEditManager) getManager()).show(initialCharacter);
351
		} else {
352
			performDirectEdit();
353
		}
354
	}
355
356
	/**
357
	 * @generated
358
	 */
359
	protected void performDirectEditRequest(Request request) {
360
		final Request theRequest = request;
361
		try {
362
			getEditingDomain().runExclusive(new Runnable() {
363
364
				public void run() {
365
					if (isActive() && isEditable()) {
366
						if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) {
367
							Character initialChar = (Character) theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR);
368
							performDirectEdit(initialChar.charValue());
369
						} else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) {
370
							DirectEditRequest editRequest = (DirectEditRequest) theRequest;
371
							performDirectEdit(editRequest.getLocation());
372
						} else {
373
							performDirectEdit();
374
						}
375
					}
376
				}
377
			});
378
		} catch (InterruptedException e) {
379
			e.printStackTrace();
380
		}
381
	}
382
383
	/**
384
	 * @generated
385
	 */
386
	protected void refreshVisuals() {
387
		super.refreshVisuals();
388
		refreshLabel();
389
		refreshFont();
390
		refreshFontColor();
391
		refreshUnderline();
392
		refreshStrikeThrough();
393
	}
394
395
	/**
396
	 * @generated
397
	 */
398
	protected void refreshLabel() {
399
		setLabelTextHelper(getFigure(), getLabelText());
400
		setLabelIconHelper(getFigure(), getLabelIcon());
401
		Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
402
		if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) {
403
			((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback();
404
		}
405
	}
406
407
	/**
408
	 * @generated
409
	 */
410
	protected void refreshUnderline() {
411
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
412
		if (style != null && getFigure() instanceof WrapLabel) {
413
			((WrapLabel) getFigure()).setTextUnderline(style.isUnderline());
414
		}
415
	}
416
417
	/**
418
	 * @generated
419
	 */
420
	protected void refreshStrikeThrough() {
421
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
422
		if (style != null && getFigure() instanceof WrapLabel) {
423
			((WrapLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough());
424
		}
425
	}
426
427
	/**
428
	 * @generated
429
	 */
430
	protected void refreshFont() {
431
		FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
432
		if (style != null) {
433
			FontData fontData = new FontData(style.getFontName(), style.getFontHeight(), (style.isBold() ? SWT.BOLD : SWT.NORMAL) | (style.isItalic() ? SWT.ITALIC : SWT.NORMAL));
434
			setFont(fontData);
435
		}
436
	}
437
438
	/**
439
	 * @generated
440
	 */
441
	protected void setFontColor(Color color) {
442
		getFigure().setForegroundColor(color);
443
	}
444
445
	/**
446
	 * @generated
447
	 */
448
	protected void addSemanticListeners() {
449
		if (getParser() instanceof ISemanticParser) {
450
			EObject element = resolveSemanticElement();
451
			parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element);
452
			for (int i = 0; i < parserElements.size(); i++) {
453
				addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$
454
			}
455
		} else {
456
			super.addSemanticListeners();
457
		}
458
	}
459
460
	/**
461
	 * @generated
462
	 */
463
	protected void removeSemanticListeners() {
464
		if (parserElements != null) {
465
			for (int i = 0; i < parserElements.size(); i++) {
466
				removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$
467
			}
468
		} else {
469
			super.removeSemanticListeners();
470
		}
471
	}
472
473
	/**
474
	 * @generated
475
	 */
476
	protected AccessibleEditPart getAccessibleEditPart() {
477
		if (accessibleEP == null) {
478
			accessibleEP = new AccessibleGraphicalEditPart() {
479
480
				public void getName(AccessibleEvent e) {
481
					e.result = getLabelTextHelper(getFigure());
482
				}
483
			};
484
		}
485
		return accessibleEP;
486
	}
487
488
	/**
489
	 * @generated
490
	 */
491
	private View getFontStyleOwnerView() {
492
		return getPrimaryView();
493
	}
494
495
	/**
496
	 * @generated
497
	 */
498
	protected void addNotationalListeners() {
499
		super.addNotationalListeners();
500
		addListenerFilter("PrimaryView", this, getPrimaryView()); //$NON-NLS-1$
501
	}
502
503
	/**
504
	 * @generated
505
	 */
506
	protected void removeNotationalListeners() {
507
		super.removeNotationalListeners();
508
		removeListenerFilter("PrimaryView"); //$NON-NLS-1$
509
	}
510
511
	/**
512
	 * @generated
513
	 */
514
	protected void handleNotificationEvent(Notification event) {
515
		Object feature = event.getFeature();
516
		if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) {
517
			Integer c = (Integer) event.getNewValue();
518
			setFontColor(DiagramColorRegistry.getInstance().getColor(c));
519
		} else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) {
520
			refreshUnderline();
521
		} else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) {
522
			refreshStrikeThrough();
523
		} else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature)
524
				|| NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) {
525
			refreshFont();
526
		} else {
527
			if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) {
528
				refreshLabel();
529
			}
530
			if (getParser() instanceof ISemanticParser) {
531
				ISemanticParser modelParser = (ISemanticParser) getParser();
532
				if (modelParser.areSemanticElementsAffected(null, event)) {
533
					removeSemanticListeners();
534
					if (resolveSemanticElement() != null) {
535
						addSemanticListeners();
536
					}
537
					refreshLabel();
538
				}
539
			}
540
		}
541
		super.handleNotificationEvent(event);
542
	}
543
544
	/**
545
	 * @generated
546
	 */
547
	protected IFigure createFigure() {
548
		// Parent should assign one using setLabel method
549
		return null;
550
	}
551
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/parts/InstanceSpecification2EditPart.java (+458 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.parts;
2
3
import org.eclipse.draw2d.IFigure;
4
import org.eclipse.draw2d.StackLayout;
5
import org.eclipse.gef.EditPart;
6
import org.eclipse.gef.EditPolicy;
7
import org.eclipse.gef.Request;
8
import org.eclipse.gef.commands.Command;
9
import org.eclipse.gef.editpolicies.LayoutEditPolicy;
10
import org.eclipse.gef.editpolicies.NonResizableEditPolicy;
11
import org.eclipse.gef.requests.CreateRequest;
12
import org.eclipse.gmf.runtime.diagram.core.edithelpers.CreateElementRequestAdapter;
13
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
14
import org.eclipse.gmf.runtime.diagram.ui.editparts.ShapeNodeEditPart;
15
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.CreationEditPolicy;
16
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
17
import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewAndElementRequest;
18
import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout;
19
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
20
import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure;
21
import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure;
22
import org.eclipse.gmf.runtime.notation.View;
23
import org.eclipse.uml2.diagram.clazz.edit.policies.InstanceSpecification2ItemSemanticEditPolicy;
24
import org.eclipse.uml2.diagram.clazz.part.UMLVisualIDRegistry;
25
import org.eclipse.uml2.diagram.clazz.providers.UMLElementTypes;
26
27
/**
28
 * @generated
29
 */
30
public class InstanceSpecification2EditPart extends ShapeNodeEditPart {
31
32
	/**
33
	 * @generated
34
	 */
35
	public static final int VISUAL_ID = 2008;
36
37
	/**
38
	 * @generated
39
	 */
40
	protected IFigure contentPane;
41
42
	/**
43
	 * @generated
44
	 */
45
	protected IFigure primaryShape;
46
47
	/**
48
	 * @generated
49
	 */
50
	public InstanceSpecification2EditPart(View view) {
51
		super(view);
52
	}
53
54
	/**
55
	 * @generated
56
	 */
57
	protected void createDefaultEditPolicies() {
58
		installEditPolicy(EditPolicyRoles.CREATION_ROLE, new CreationEditPolicy() {
59
60
			public Command getCommand(Request request) {
61
				if (understandsRequest(request)) {
62
					if (request instanceof CreateViewAndElementRequest) {
63
						CreateElementRequestAdapter adapter = ((CreateViewAndElementRequest) request).getViewAndElementDescriptor().getCreateElementRequestAdapter();
64
						IElementType type = (IElementType) adapter.getAdapter(IElementType.class);
65
						if (type == UMLElementTypes.Slot_3017) {
66
							EditPart compartmentEditPart = getChildBySemanticHint(UMLVisualIDRegistry.getType(InstanceSpecificationSlotsEditPart.VISUAL_ID));
67
							return compartmentEditPart == null ? null : compartmentEditPart.getCommand(request);
68
						}
69
					}
70
					return super.getCommand(request);
71
				}
72
				return null;
73
			}
74
		});
75
		super.createDefaultEditPolicies();
76
		installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new InstanceSpecification2ItemSemanticEditPolicy());
77
		installEditPolicy(EditPolicy.LAYOUT_ROLE, createLayoutEditPolicy());
78
79
	}
80
81
	/**
82
	 * @generated
83
	 */
84
	protected LayoutEditPolicy createLayoutEditPolicy() {
85
		LayoutEditPolicy lep = new LayoutEditPolicy() {
86
87
			protected EditPolicy createChildEditPolicy(EditPart child) {
88
				EditPolicy result = child.getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
89
				if (result == null) {
90
					result = new NonResizableEditPolicy();
91
				}
92
				return result;
93
			}
94
95
			protected Command getMoveChildrenCommand(Request request) {
96
				return null;
97
			}
98
99
			protected Command getCreateCommand(CreateRequest request) {
100
				return null;
101
			}
102
		};
103
		return lep;
104
	}
105
106
	/**
107
	 * @generated
108
	 */
109
	protected IFigure createNodeShape() {
110
		InstanceNodeFigure figure = new InstanceNodeFigure();
111
		return primaryShape = figure;
112
	}
113
114
	/**
115
	 * @generated
116
	 */
117
	public InstanceNodeFigure getPrimaryShape() {
118
		return (InstanceNodeFigure) primaryShape;
119
	}
120
121
	/**
122
	 * @generated 
123
	 */
124
	protected IFigure getContentPaneFor(IGraphicalEditPart editPart) {
125
		if (editPart instanceof InstanceSpecificationSlotsEditPart) {
126
			return getPrimaryShape().getFigureInstanceNode_SlotsCompartmentFigure();
127
		}
128
129
		return super.getContentPaneFor(editPart);
130
	}
131
132
	/**
133
	 * @generated
134
	 */
135
	protected boolean addFixedChild(EditPart childEditPart) {
136
		if (childEditPart instanceof InstanceSpecificationNameEditPart) {
137
			((InstanceSpecificationNameEditPart) childEditPart).setLabel(getPrimaryShape().getFigureInstanceNode_NameLabel());
138
			return true;
139
		}
140
		if (childEditPart instanceof InstanceSpecificationSlotsEditPart) {
141
			IFigure pane = getPrimaryShape().getFigureInstanceNode_SlotsCompartmentFigure();
142
			setupContentPane(pane); // FIXME each comparment should handle his content pane in his own way 
143
			pane.add(((InstanceSpecificationSlotsEditPart) childEditPart).getFigure());
144
			return true;
145
		}
146
		return false;
147
	}
148
149
	/**
150
	 * @generated
151
	 */
152
	protected boolean removeFixedChild(EditPart childEditPart) {
153
		if (childEditPart instanceof InstanceSpecificationSlotsEditPart) {
154
			IFigure pane = getPrimaryShape().getFigureInstanceNode_SlotsCompartmentFigure();
155
			pane.remove(((InstanceSpecificationSlotsEditPart) childEditPart).getFigure());
156
			return true;
157
		}
158
		return false;
159
	}
160
161
	/**
162
	 * @generated
163
	 */
164
	protected NodeFigure createNodePlate() {
165
		DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(getMapMode().DPtoLP(40), getMapMode().DPtoLP(40));
166
		return result;
167
	}
168
169
	/**
170
	 * Creates figure for this edit part.
171
	 * 
172
	 * Body of this method does not depend on settings in generation model
173
	 * so you may safely remove <i>generated</i> tag and modify it.
174
	 * 
175
	 * @generated
176
	 */
177
	protected NodeFigure createNodeFigure() {
178
		NodeFigure figure = createNodePlate();
179
		figure.setLayoutManager(new StackLayout());
180
		IFigure shape = createNodeShape();
181
		figure.add(shape);
182
		contentPane = setupContentPane(shape);
183
		return figure;
184
	}
185
186
	/**
187
	 * Default implementation treats passed figure as content pane.
188
	 * Respects layout one may have set for generated figure.
189
	 * @param nodeShape instance of generated figure class
190
	 * @generated
191
	 */
192
	protected IFigure setupContentPane(IFigure nodeShape) {
193
		if (nodeShape.getLayoutManager() == null) {
194
			ConstrainedToolbarLayout layout = new ConstrainedToolbarLayout();
195
			layout.setSpacing(getMapMode().DPtoLP(5));
196
			nodeShape.setLayoutManager(layout);
197
		}
198
		return nodeShape; // use nodeShape itself as contentPane
199
	}
200
201
	/**
202
	 * @generated
203
	 */
204
	public IFigure getContentPane() {
205
		if (contentPane != null) {
206
			return contentPane;
207
		}
208
		return super.getContentPane();
209
	}
210
211
	/**
212
	 * @generated
213
	 */
214
	public EditPart getPrimaryChildEditPart() {
215
		return getChildBySemanticHint(UMLVisualIDRegistry.getType(InstanceSpecificationNameEditPart.VISUAL_ID));
216
	}
217
218
	/**
219
	 * @generated
220
	 */
221
	protected void addChildVisual(EditPart childEditPart, int index) {
222
		if (addFixedChild(childEditPart)) {
223
			return;
224
		}
225
		super.addChildVisual(childEditPart, -1);
226
	}
227
228
	/**
229
	 * @generated
230
	 */
231
	protected void removeChildVisual(EditPart childEditPart) {
232
		if (removeFixedChild(childEditPart)) {
233
			return;
234
		}
235
		super.removeChildVisual(childEditPart);
236
	}
237
238
	/**
239
	 * @generated
240
	 */
241
	public class InstanceNodeFigure extends org.eclipse.draw2d.RectangleFigure {
242
243
		/**
244
		 * @generated
245
		 */
246
		private org.eclipse.draw2d.Border createBorder_InstanceNode_NameLabel_1() {
247
			org.eclipse.gmf.runtime.draw2d.ui.figures.OneLineBorder result = new org.eclipse.gmf.runtime.draw2d.ui.figures.OneLineBorder();
248
249
			result.setPosition(org.eclipse.draw2d.PositionConstants.BOTTOM);
250
251
			return result;
252
		}
253
254
		/**
255
		 * @generated
256
		 */
257
		public InstanceNodeFigure() {
258
259
			org.eclipse.gmf.internal.codegen.draw2d.GridLayout myGenLayoutManager = new org.eclipse.gmf.internal.codegen.draw2d.GridLayout();
260
			myGenLayoutManager.numColumns = 1;
261
			myGenLayoutManager.makeColumnsEqualWidth = true;
262
263
			this.setLayoutManager(myGenLayoutManager);
264
265
			createContents();
266
		}
267
268
		/**
269
		 * @generated
270
		 */
271
		private void createContents() {
272
			org.eclipse.draw2d.RectangleFigure fig_0 = new org.eclipse.draw2d.RectangleFigure();
273
274
			fig_0.setOutline(false);
275
			fig_0.setBorder(createBorder_InstanceNode_NameLabel_1());
276
277
			org.eclipse.draw2d.StackLayout layouter0 = new org.eclipse.draw2d.StackLayout();
278
279
			fig_0.setLayoutManager(layouter0);
280
281
			setFigureInstanceNode_NameContainerFigure(fig_0);
282
			org.eclipse.gmf.internal.codegen.draw2d.GridLayoutData layData0 = new org.eclipse.gmf.internal.codegen.draw2d.GridLayoutData();
283
			layData0.verticalAlignment = org.eclipse.gmf.internal.codegen.draw2d.GridLayoutData.FILL;
284
			layData0.horizontalAlignment = org.eclipse.gmf.internal.codegen.draw2d.GridLayoutData.CENTER;
285
			layData0.horizontalIndent = 0;
286
			layData0.horizontalSpan = 1;
287
			layData0.verticalSpan = 1;
288
			layData0.grabExcessHorizontalSpace = true;
289
			layData0.grabExcessVerticalSpace = false;
290
291
			this.add(fig_0, layData0);
292
			org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel fig_1 = new org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel();
293
294
			setFigureInstanceNode_NameLabel(fig_1);
295
296
			Object layData1 = null;
297
298
			fig_0.add(fig_1, layData1);
299
			org.eclipse.draw2d.RectangleFigure fig_2 = new org.eclipse.draw2d.RectangleFigure();
300
301
			fig_2.setOutline(false);
302
303
			org.eclipse.draw2d.StackLayout layouter2 = new org.eclipse.draw2d.StackLayout();
304
305
			fig_2.setLayoutManager(layouter2);
306
307
			setFigureInstanceSpecification_SpecificationContainerFigure(fig_2);
308
			org.eclipse.gmf.internal.codegen.draw2d.GridLayoutData layData2 = new org.eclipse.gmf.internal.codegen.draw2d.GridLayoutData();
309
			layData2.verticalAlignment = org.eclipse.gmf.internal.codegen.draw2d.GridLayoutData.FILL;
310
			layData2.horizontalAlignment = org.eclipse.gmf.internal.codegen.draw2d.GridLayoutData.CENTER;
311
			layData2.horizontalIndent = 0;
312
			layData2.horizontalSpan = 1;
313
			layData2.verticalSpan = 1;
314
			layData2.grabExcessHorizontalSpace = true;
315
			layData2.grabExcessVerticalSpace = false;
316
317
			this.add(fig_2, layData2);
318
			org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel fig_3 = new org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel();
319
320
			setFigureInstanceNode_SpecificationLabel(fig_3);
321
322
			Object layData3 = null;
323
324
			fig_2.add(fig_3, layData3);
325
			org.eclipse.draw2d.RectangleFigure fig_4 = new org.eclipse.draw2d.RectangleFigure();
326
327
			fig_4.setOutline(false);
328
329
			setFigureInstanceNode_SlotsCompartmentFigure(fig_4);
330
			org.eclipse.gmf.internal.codegen.draw2d.GridLayoutData layData4 = new org.eclipse.gmf.internal.codegen.draw2d.GridLayoutData();
331
			layData4.verticalAlignment = org.eclipse.gmf.internal.codegen.draw2d.GridLayoutData.FILL;
332
			layData4.horizontalAlignment = org.eclipse.gmf.internal.codegen.draw2d.GridLayoutData.FILL;
333
			layData4.horizontalIndent = 0;
334
			layData4.horizontalSpan = 1;
335
			layData4.verticalSpan = 1;
336
			layData4.grabExcessHorizontalSpace = true;
337
			layData4.grabExcessVerticalSpace = true;
338
339
			this.add(fig_4, layData4);
340
		}
341
342
		/**
343
		 * @generated
344
		 */
345
		private org.eclipse.draw2d.RectangleFigure fInstanceNode_NameContainerFigure;
346
347
		/**
348
		 * @generated
349
		 */
350
		public org.eclipse.draw2d.RectangleFigure getFigureInstanceNode_NameContainerFigure() {
351
			return fInstanceNode_NameContainerFigure;
352
		}
353
354
		/**
355
		 * @generated
356
		 */
357
		private void setFigureInstanceNode_NameContainerFigure(org.eclipse.draw2d.RectangleFigure fig) {
358
			fInstanceNode_NameContainerFigure = fig;
359
		}
360
361
		/**
362
		 * @generated
363
		 */
364
		private org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel fInstanceNode_NameLabel;
365
366
		/**
367
		 * @generated
368
		 */
369
		public org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel getFigureInstanceNode_NameLabel() {
370
			return fInstanceNode_NameLabel;
371
		}
372
373
		/**
374
		 * @generated
375
		 */
376
		private void setFigureInstanceNode_NameLabel(org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel fig) {
377
			fInstanceNode_NameLabel = fig;
378
		}
379
380
		/**
381
		 * @generated
382
		 */
383
		private org.eclipse.draw2d.RectangleFigure fInstanceSpecification_SpecificationContainerFigure;
384
385
		/**
386
		 * @generated
387
		 */
388
		public org.eclipse.draw2d.RectangleFigure getFigureInstanceSpecification_SpecificationContainerFigure() {
389
			return fInstanceSpecification_SpecificationContainerFigure;
390
		}
391
392
		/**
393
		 * @generated
394
		 */
395
		private void setFigureInstanceSpecification_SpecificationContainerFigure(org.eclipse.draw2d.RectangleFigure fig) {
396
			fInstanceSpecification_SpecificationContainerFigure = fig;
397
		}
398
399
		/**
400
		 * @generated
401
		 */
402
		private org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel fInstanceNode_SpecificationLabel;
403
404
		/**
405
		 * @generated
406
		 */
407
		public org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel getFigureInstanceNode_SpecificationLabel() {
408
			return fInstanceNode_SpecificationLabel;
409
		}
410
411
		/**
412
		 * @generated
413
		 */
414
		private void setFigureInstanceNode_SpecificationLabel(org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel fig) {
415
			fInstanceNode_SpecificationLabel = fig;
416
		}
417
418
		/**
419
		 * @generated
420
		 */
421
		private org.eclipse.draw2d.RectangleFigure fInstanceNode_SlotsCompartmentFigure;
422
423
		/**
424
		 * @generated
425
		 */
426
		public org.eclipse.draw2d.RectangleFigure getFigureInstanceNode_SlotsCompartmentFigure() {
427
			return fInstanceNode_SlotsCompartmentFigure;
428
		}
429
430
		/**
431
		 * @generated
432
		 */
433
		private void setFigureInstanceNode_SlotsCompartmentFigure(org.eclipse.draw2d.RectangleFigure fig) {
434
			fInstanceNode_SlotsCompartmentFigure = fig;
435
		}
436
437
		/**
438
		 * @generated
439
		 */
440
		private boolean myUseLocalCoordinates = false;
441
442
		/**
443
		 * @generated
444
		 */
445
		protected boolean useLocalCoordinates() {
446
			return myUseLocalCoordinates;
447
		}
448
449
		/**
450
		 * @generated
451
		 */
452
		protected void setUseLocalCoordinates(boolean useLocalCoordinates) {
453
			myUseLocalCoordinates = useLocalCoordinates;
454
		}
455
456
	}
457
458
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/policies/UMLTextSelectionEditPolicy.java (+192 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.policies;
2
3
import org.eclipse.draw2d.ColorConstants;
4
import org.eclipse.draw2d.Figure;
5
import org.eclipse.draw2d.Graphics;
6
import org.eclipse.draw2d.IFigure;
7
import org.eclipse.draw2d.Label;
8
import org.eclipse.draw2d.RectangleFigure;
9
import org.eclipse.draw2d.geometry.Rectangle;
10
import org.eclipse.gef.LayerConstants;
11
import org.eclipse.gef.editpolicies.SelectionEditPolicy;
12
import org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel;
13
14
/**
15
 * @generated
16
 */
17
public class UMLTextSelectionEditPolicy extends SelectionEditPolicy {
18
19
	/**
20
	 * @generated
21
	 */
22
	private IFigure selectionFeedbackFigure;
23
24
	/**
25
	 * @generated
26
	 */
27
	private IFigure focusFeedbackFigure;
28
29
	/**
30
	 * @generated
31
	 */
32
	protected void showPrimarySelection() {
33
		if (getHostFigure() instanceof WrapLabel) {
34
			((WrapLabel) getHostFigure()).setSelected(true);
35
			((WrapLabel) getHostFigure()).setFocus(true);
36
		} else {
37
			showSelection();
38
			showFocus();
39
		}
40
	}
41
42
	/**
43
	 * @generated
44
	 */
45
	protected void showSelection() {
46
		if (getHostFigure() instanceof WrapLabel) {
47
			((WrapLabel) getHostFigure()).setSelected(true);
48
			((WrapLabel) getHostFigure()).setFocus(false);
49
		} else {
50
			hideSelection();
51
			addFeedback(selectionFeedbackFigure = createSelectionFeedbackFigure());
52
			refreshSelectionFeedback();
53
			hideFocus();
54
		}
55
	}
56
57
	/**
58
	 * @generated
59
	 */
60
	protected void hideSelection() {
61
		if (getHostFigure() instanceof WrapLabel) {
62
			((WrapLabel) getHostFigure()).setSelected(false);
63
			((WrapLabel) getHostFigure()).setFocus(false);
64
		} else {
65
			if (selectionFeedbackFigure != null) {
66
				removeFeedback(selectionFeedbackFigure);
67
				selectionFeedbackFigure = null;
68
			}
69
			hideFocus();
70
		}
71
	}
72
73
	/**
74
	 * @generated
75
	 */
76
	protected void showFocus() {
77
		if (getHostFigure() instanceof WrapLabel) {
78
			((WrapLabel) getHostFigure()).setFocus(true);
79
		} else {
80
			hideFocus();
81
			addFeedback(focusFeedbackFigure = createFocusFeedbackFigure());
82
			refreshFocusFeedback();
83
		}
84
	}
85
86
	/**
87
	 * @generated
88
	 */
89
	protected void hideFocus() {
90
		if (getHostFigure() instanceof WrapLabel) {
91
			((WrapLabel) getHostFigure()).setFocus(false);
92
		} else {
93
			if (focusFeedbackFigure != null) {
94
				removeFeedback(focusFeedbackFigure);
95
				focusFeedbackFigure = null;
96
			}
97
		}
98
	}
99
100
	/**
101
	 * @generated
102
	 */
103
	protected IFigure getFeedbackLayer() {
104
		return getLayer(LayerConstants.SCALED_FEEDBACK_LAYER);
105
	}
106
107
	/**
108
	 * @generated
109
	 */
110
	protected Rectangle getFeedbackBounds() {
111
		Rectangle bounds;
112
		if (getHostFigure() instanceof Label) {
113
			bounds = ((Label) getHostFigure()).getTextBounds();
114
			bounds.intersect(getHostFigure().getBounds());
115
		} else {
116
			bounds = getHostFigure().getBounds().getCopy();
117
		}
118
		getHostFigure().getParent().translateToAbsolute(bounds);
119
		getFeedbackLayer().translateToRelative(bounds);
120
		return bounds;
121
	}
122
123
	/**
124
	 * @generated
125
	 */
126
	protected IFigure createSelectionFeedbackFigure() {
127
		if (getHostFigure() instanceof Label) {
128
			Label feedbackFigure = new Label();
129
			feedbackFigure.setOpaque(true);
130
			feedbackFigure.setBackgroundColor(ColorConstants.menuBackgroundSelected);
131
			feedbackFigure.setForegroundColor(ColorConstants.menuForegroundSelected);
132
			return feedbackFigure;
133
		} else {
134
			RectangleFigure feedbackFigure = new RectangleFigure();
135
			feedbackFigure.setFill(false);
136
			return feedbackFigure;
137
		}
138
	}
139
140
	/**
141
	 * @generated
142
	 */
143
	protected IFigure createFocusFeedbackFigure() {
144
		return new Figure() {
145
146
			protected void paintFigure(Graphics graphics) {
147
				graphics.drawFocus(getBounds().getResized(-1, -1));
148
			}
149
		};
150
	}
151
152
	/**
153
	 * @generated
154
	 */
155
	protected void updateLabel(Label target) {
156
		Label source = (Label) getHostFigure();
157
		target.setText(source.getText());
158
		target.setTextAlignment(source.getTextAlignment());
159
		target.setFont(source.getFont());
160
	}
161
162
	/**
163
	 * @generated
164
	 */
165
	protected void refreshSelectionFeedback() {
166
		if (selectionFeedbackFigure != null) {
167
			if (selectionFeedbackFigure instanceof Label) {
168
				updateLabel((Label) selectionFeedbackFigure);
169
				selectionFeedbackFigure.setBounds(getFeedbackBounds());
170
			} else {
171
				selectionFeedbackFigure.setBounds(getFeedbackBounds().expand(5, 5));
172
			}
173
		}
174
	}
175
176
	/**
177
	 * @generated
178
	 */
179
	protected void refreshFocusFeedback() {
180
		if (focusFeedbackFigure != null) {
181
			focusFeedbackFigure.setBounds(getFeedbackBounds());
182
		}
183
	}
184
185
	/**
186
	 * @generated
187
	 */
188
	public void refreshFeedback() {
189
		refreshSelectionFeedback();
190
		refreshFocusFeedback();
191
	}
192
}
(-)src/org/eclipse/uml2/diagram/clazz/edit/policies/ClassAttributesItemSemanticEditPolicy.java (+73 lines)
Added Link Here
1
package org.eclipse.uml2.diagram.clazz.edit.policies;
2
3
import org.eclipse.emf.ecore.EClass;
4
import org.eclipse.emf.ecore.EObject;
5
import org.eclipse.gef.commands.Command;
6
import org.eclipse.gmf.runtime.emf.type.core.commands.CreateElementCommand;
7
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest;
8
import org.eclipse.gmf.runtime.notation.View;
9
import org.eclipse.uml2.diagram.clazz.providers.UMLElementTypes;
10
import org.eclipse.uml2.uml.Property;
11
import org.eclipse.uml2.uml.UMLPackage;
12
13
/**
14
 * @generated
15
 */
16
public class ClassAttributesItemSemanticEditPolicy extends UMLBaseItemSemanticEditPolicy {
17
18
	/**
19
	 * @generated
20
	 */
21
	protected Command getCreateCommand(CreateElementRequest req) {
22
		if (UMLElementTypes.Property_3001 == req.getElementType()) {
23
			if (req.getContainmentFeature() == null) {
24
				req.setContainmentFeature(UMLPackage.eINSTANCE.getStructuredClassifier_OwnedAttribute());
25
			}
26
			return getMSLWrapper(new CreateProperty_3001Command(req));
27
		}
28
		return super.getCreateCommand(req);
29
	}
30
31
	/**
32
	 * @generated
33
	 */
34
	private static class CreateProperty_3001Command extends CreateElementCommand {
35
36
		/**
37
		 * @generated
38
		 */
39
		public CreateProperty_3001Command(CreateElementRequest req) {
40
			super(req);
41
		}
42
43
		/**
44
		 * @generated
45
		 */
46
		protected EClass getEClassToEdit() {
47
			return UMLPackage.eINSTANCE.getClass_();
48
		};
49
50
		/**
51
		 * @generated
52
		 */
53
		protected EObject getElementToEdit() {
54
			EObject container = ((CreateElementRequest) getRequest()).getContainer();
55
			if (container instanceof View) {
56
				container = ((View) container).getElement();
57
			}
58
			return container;
59
		}
60
61
		/**
62
		 * @generated
63
		 */
64
		protected EObject doDefaultElementCreation() {
65
			Property newElement = (Property) super.doDefaultElementCreation();
66
			if (newElement != null) {
67
				UMLElementTypes.Initializers.Property_3001.init(newElement);
68
			}
69
			return newElement;
70
		}
71
	}
72
73
}

Return to bug 80318