blob: 47a14904c9a89e18cb112f384c6eb5d2de397e8a (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
/*
* Copyright (c) 2004 - 2011 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.graphiti.features.IFeatureProvider;
import org.eclipse.graphiti.features.IReason;
import org.eclipse.graphiti.features.context.IUpdateContext;
import org.eclipse.graphiti.features.impl.AbstractUpdateFeature;
import org.eclipse.graphiti.features.impl.Reason;
import org.eclipse.graphiti.mm.algorithms.Text;
import org.eclipse.graphiti.mm.pictograms.ContainerShape;
import org.eclipse.graphiti.mm.pictograms.PictogramElement;
import org.eclipse.graphiti.mm.pictograms.Shape;
/**
* @author Martin Fluegge
*/
public class AcoreUpdateAClassFeature extends AbstractUpdateFeature
{
public AcoreUpdateAClassFeature(IFeatureProvider fp)
{
super(fp);
}
public boolean canUpdate(IUpdateContext context)
{
// return true, if linked business object is a AClass
Object bo = getBusinessObjectForPictogramElement(context.getPictogramElement());
return bo instanceof AClass;
}
public IReason updateNeeded(IUpdateContext context)
{
// retrieve name from pictogram model
String pictogramName = null;
PictogramElement pictogramElement = context.getPictogramElement();
if (pictogramElement instanceof ContainerShape)
{
ContainerShape cs = (ContainerShape)pictogramElement;
for (Shape shape : cs.getChildren())
{
if (shape.getGraphicsAlgorithm() instanceof Text)
{
Text text = (Text)shape.getGraphicsAlgorithm();
pictogramName = text.getValue();
}
}
}
// retrieve name from business model
String businessName = null;
Object bo = getBusinessObjectForPictogramElement(pictogramElement);
if (bo instanceof AClass)
{
AClass AClass = (AClass)bo;
businessName = AClass.getName();
}
// update needed, if names are different
boolean updateNameNeeded = pictogramName == null && businessName != null || pictogramName != null
&& !pictogramName.equals(businessName);
if (updateNameNeeded)
{
return Reason.createTrueReason("Name is out of date");
}
else
{
return Reason.createFalseReason();
}
}
public boolean update(IUpdateContext context)
{
// retrieve name from business model
String businessName = null;
PictogramElement pictogramElement = context.getPictogramElement();
Object bo = getBusinessObjectForPictogramElement(pictogramElement);
if (bo instanceof AClass)
{
AClass AClass = (AClass)bo;
businessName = AClass.getName();
}
// Set name in pictogram model
if (pictogramElement instanceof ContainerShape)
{
ContainerShape cs = (ContainerShape)pictogramElement;
for (Shape shape : cs.getChildren())
{
if (shape.getGraphicsAlgorithm() instanceof Text)
{
Text text = (Text)shape.getGraphicsAlgorithm();
text.setValue(businessName);
return true;
}
}
}
return false;
}
}
|