blob: e87b86217481258a5ecb765b822e3a3946b2b171 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
/*
* Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Martin Fluegge - initial API and implementation
*
*/
package org.eclipse.emf.cdo.dawn.examples.acore.graphiti.features;
import org.eclipse.emf.cdo.dawn.examples.acore.AClass;
import org.eclipse.emf.cdo.dawn.examples.acore.graphiti.util.AcoreGraphitiContextUtil.ConnectionType;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.graphiti.features.IFeatureProvider;
import org.eclipse.graphiti.features.context.ICreateConnectionContext;
import org.eclipse.graphiti.mm.pictograms.Anchor;
/**
* @author Martin Fluegge
*/
public class AcoreCreateCompositionsFeature extends AcoreBasicCreateConnectionFeature
{
public AcoreCreateCompositionsFeature(IFeatureProvider fp)
{
// provide name and description for the UI, e.g. the palette
super(fp, "composition", "composition");
}
@Override
public boolean canCreate(ICreateConnectionContext context)
{
// return true if both anchors belong to an AClass
// and those AClasses are not identical
AClass source = getAClass(context.getSourceAnchor());
AClass target = getAClass(context.getTargetAnchor());
if (source != null && target != null && source != target)
{
return true;
}
return false;
}
@Override
public boolean canStartConnection(ICreateConnectionContext context)
{
if (getAClass(context.getSourceAnchor()) != null)
{
return true;
}
return false;
}
/**
* Creates a EReference between two AClasses.
*/
@Override
protected void createConnection(EObject source, EObject target)
{
((AClass)source).getCompositions().add((AClass)target);
}
@Override
protected EObject getTarget(Anchor targetAnchor)
{
return getAClass(targetAnchor);
}
@Override
protected EObject getSource(Anchor anchor)
{
return getAClass(anchor);
}
@Override
protected ConnectionType getConnectionType()
{
return ConnectionType.COMPOSITIONS;
}
/**
* Returns the AClass belonging to the anchor, or null if not available.
*/
private AClass getAClass(Anchor anchor)
{
if (anchor != null)
{
Object object = getBusinessObjectForPictogramElement(anchor.getParent());
if (object instanceof AClass)
{
return (AClass)object;
}
}
return null;
}
}
|