Lines 1-1711
Link Here
|
1 |
/******************************************************************************* |
1 |
/******************************************************************************* |
2 |
* Copyright (c) 2007, 2014 THALES GLOBAL SERVICES and others. |
2 |
* Copyright (c) 2007, 2014 THALES GLOBAL SERVICES and others. |
3 |
* All rights reserved. This program and the accompanying materials |
3 |
* All rights reserved. This program and the accompanying materials |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
5 |
* which accompanies this distribution, and is available at |
5 |
* which accompanies this distribution, and is available at |
6 |
* http://www.eclipse.org/legal/epl-v10.html |
6 |
* http://www.eclipse.org/legal/epl-v10.html |
7 |
* |
7 |
* |
8 |
* Contributors: |
8 |
* Contributors: |
9 |
* Obeo - initial API and implementation |
9 |
* Obeo - initial API and implementation |
10 |
*******************************************************************************/ |
10 |
*******************************************************************************/ |
11 |
package org.eclipse.sirius.diagram.business.internal.metamodel.helper; |
11 |
package org.eclipse.sirius.diagram.business.internal.metamodel.helper; |
12 |
|
12 |
|
13 |
import java.util.List; |
13 |
import java.util.List; |
14 |
|
14 |
|
15 |
import org.eclipse.core.runtime.Platform; |
15 |
import org.eclipse.core.runtime.Platform; |
16 |
import org.eclipse.core.runtime.preferences.IPreferencesService; |
16 |
import org.eclipse.core.runtime.preferences.IPreferencesService; |
17 |
import org.eclipse.emf.common.util.BasicEList; |
17 |
import org.eclipse.emf.common.util.BasicEList; |
18 |
import org.eclipse.emf.common.util.EList; |
18 |
import org.eclipse.emf.common.util.EList; |
19 |
import org.eclipse.emf.ecore.EObject; |
19 |
import org.eclipse.emf.ecore.EObject; |
20 |
import org.eclipse.emf.ecore.EStructuralFeature; |
20 |
import org.eclipse.emf.ecore.EStructuralFeature; |
21 |
import org.eclipse.emf.ecore.util.EcoreUtil; |
21 |
import org.eclipse.emf.ecore.util.EcoreUtil; |
22 |
import org.eclipse.sirius.business.api.logger.RuntimeLoggerManager; |
22 |
import org.eclipse.sirius.business.api.logger.RuntimeLoggerManager; |
23 |
import org.eclipse.sirius.business.api.metamodel.helper.FontFormatHelper; |
23 |
import org.eclipse.sirius.business.api.metamodel.helper.FontFormatHelper; |
24 |
import org.eclipse.sirius.common.tools.api.interpreter.EvaluationException; |
24 |
import org.eclipse.sirius.common.tools.api.interpreter.EvaluationException; |
25 |
import org.eclipse.sirius.common.tools.api.interpreter.IInterpreter; |
25 |
import org.eclipse.sirius.common.tools.api.interpreter.IInterpreter; |
26 |
import org.eclipse.sirius.common.tools.api.util.EqualityHelper; |
26 |
import org.eclipse.sirius.common.tools.api.util.EqualityHelper; |
27 |
import org.eclipse.sirius.common.tools.api.util.StringUtil; |
27 |
import org.eclipse.sirius.common.tools.api.util.StringUtil; |
28 |
import org.eclipse.sirius.diagram.AbstractDNode; |
28 |
import org.eclipse.sirius.diagram.AbstractDNode; |
29 |
import org.eclipse.sirius.diagram.BeginLabelStyle; |
29 |
import org.eclipse.sirius.diagram.BeginLabelStyle; |
30 |
import org.eclipse.sirius.diagram.BorderedStyle; |
30 |
import org.eclipse.sirius.diagram.BorderedStyle; |
31 |
import org.eclipse.sirius.diagram.BundledImage; |
31 |
import org.eclipse.sirius.diagram.BundledImage; |
32 |
import org.eclipse.sirius.diagram.CenterLabelStyle; |
32 |
import org.eclipse.sirius.diagram.CenterLabelStyle; |
33 |
import org.eclipse.sirius.diagram.ContainerStyle; |
33 |
import org.eclipse.sirius.diagram.ContainerStyle; |
34 |
import org.eclipse.sirius.diagram.CustomStyle; |
34 |
import org.eclipse.sirius.diagram.CustomStyle; |
35 |
import org.eclipse.sirius.diagram.DDiagramElement; |
35 |
import org.eclipse.sirius.diagram.DDiagramElement; |
36 |
import org.eclipse.sirius.diagram.DDiagramElementContainer; |
36 |
import org.eclipse.sirius.diagram.DDiagramElementContainer; |
37 |
import org.eclipse.sirius.diagram.DEdge; |
37 |
import org.eclipse.sirius.diagram.DEdge; |
38 |
import org.eclipse.sirius.diagram.DNode; |
38 |
import org.eclipse.sirius.diagram.DNode; |
39 |
import org.eclipse.sirius.diagram.DNodeContainer; |
39 |
import org.eclipse.sirius.diagram.DNodeContainer; |
40 |
import org.eclipse.sirius.diagram.DNodeList; |
40 |
import org.eclipse.sirius.diagram.DNodeList; |
41 |
import org.eclipse.sirius.diagram.DNodeListElement; |
41 |
import org.eclipse.sirius.diagram.DNodeListElement; |
42 |
import org.eclipse.sirius.diagram.DiagramFactory; |
42 |
import org.eclipse.sirius.diagram.DiagramFactory; |
43 |
import org.eclipse.sirius.diagram.DiagramPackage; |
43 |
import org.eclipse.sirius.diagram.DiagramPackage; |
44 |
import org.eclipse.sirius.diagram.DiagramPlugin; |
44 |
import org.eclipse.sirius.diagram.DiagramPlugin; |
45 |
import org.eclipse.sirius.diagram.Dot; |
45 |
import org.eclipse.sirius.diagram.Dot; |
46 |
import org.eclipse.sirius.diagram.EdgeRouting; |
46 |
import org.eclipse.sirius.diagram.EdgeRouting; |
47 |
import org.eclipse.sirius.diagram.EdgeStyle; |
47 |
import org.eclipse.sirius.diagram.EdgeStyle; |
48 |
import org.eclipse.sirius.diagram.EdgeTarget; |
48 |
import org.eclipse.sirius.diagram.EdgeTarget; |
49 |
import org.eclipse.sirius.diagram.Ellipse; |
49 |
import org.eclipse.sirius.diagram.Ellipse; |
50 |
import org.eclipse.sirius.diagram.EndLabelStyle; |
50 |
import org.eclipse.sirius.diagram.EndLabelStyle; |
51 |
import org.eclipse.sirius.diagram.FlatContainerStyle; |
51 |
import org.eclipse.sirius.diagram.FlatContainerStyle; |
52 |
import org.eclipse.sirius.diagram.GaugeCompositeStyle; |
52 |
import org.eclipse.sirius.diagram.GaugeCompositeStyle; |
53 |
import org.eclipse.sirius.diagram.GaugeSection; |
53 |
import org.eclipse.sirius.diagram.GaugeSection; |
54 |
import org.eclipse.sirius.diagram.HideLabelCapabilityStyle; |
54 |
import org.eclipse.sirius.diagram.HideLabelCapabilityStyle; |
55 |
import org.eclipse.sirius.diagram.Lozenge; |
55 |
import org.eclipse.sirius.diagram.Lozenge; |
56 |
import org.eclipse.sirius.diagram.NodeStyle; |
56 |
import org.eclipse.sirius.diagram.NodeStyle; |
57 |
import org.eclipse.sirius.diagram.Note; |
57 |
import org.eclipse.sirius.diagram.Note; |
58 |
import org.eclipse.sirius.diagram.ShapeContainerStyle; |
58 |
import org.eclipse.sirius.diagram.ShapeContainerStyle; |
59 |
import org.eclipse.sirius.diagram.Square; |
59 |
import org.eclipse.sirius.diagram.Square; |
60 |
import org.eclipse.sirius.diagram.WorkspaceImage; |
60 |
import org.eclipse.sirius.diagram.WorkspaceImage; |
61 |
import org.eclipse.sirius.diagram.business.api.query.DiagramElementMappingQuery; |
61 |
import org.eclipse.sirius.diagram.business.api.query.DiagramElementMappingQuery; |
62 |
import org.eclipse.sirius.diagram.business.internal.color.DiagramStyleColorUpdater; |
62 |
import org.eclipse.sirius.diagram.business.internal.color.DiagramStyleColorUpdater; |
63 |
import org.eclipse.sirius.diagram.description.CenteringStyle; |
63 |
import org.eclipse.sirius.diagram.description.CenteringStyle; |
64 |
import org.eclipse.sirius.diagram.description.DiagramElementMapping; |
64 |
import org.eclipse.sirius.diagram.description.DiagramElementMapping; |
65 |
import org.eclipse.sirius.diagram.description.style.BeginLabelStyleDescription; |
65 |
import org.eclipse.sirius.diagram.description.style.BeginLabelStyleDescription; |
66 |
import org.eclipse.sirius.diagram.description.style.BorderedStyleDescription; |
66 |
import org.eclipse.sirius.diagram.description.style.BorderedStyleDescription; |
67 |
import org.eclipse.sirius.diagram.description.style.BracketEdgeStyleDescription; |
67 |
import org.eclipse.sirius.diagram.description.style.BracketEdgeStyleDescription; |
68 |
import org.eclipse.sirius.diagram.description.style.BundledImageDescription; |
68 |
import org.eclipse.sirius.diagram.description.style.BundledImageDescription; |
69 |
import org.eclipse.sirius.diagram.description.style.CenterLabelStyleDescription; |
69 |
import org.eclipse.sirius.diagram.description.style.CenterLabelStyleDescription; |
70 |
import org.eclipse.sirius.diagram.description.style.ContainerStyleDescription; |
70 |
import org.eclipse.sirius.diagram.description.style.ContainerStyleDescription; |
71 |
import org.eclipse.sirius.diagram.description.style.CustomStyleDescription; |
71 |
import org.eclipse.sirius.diagram.description.style.CustomStyleDescription; |
72 |
import org.eclipse.sirius.diagram.description.style.DotDescription; |
72 |
import org.eclipse.sirius.diagram.description.style.DotDescription; |
73 |
import org.eclipse.sirius.diagram.description.style.EdgeStyleDescription; |
73 |
import org.eclipse.sirius.diagram.description.style.EdgeStyleDescription; |
74 |
import org.eclipse.sirius.diagram.description.style.EllipseNodeDescription; |
74 |
import org.eclipse.sirius.diagram.description.style.EllipseNodeDescription; |
75 |
import org.eclipse.sirius.diagram.description.style.EndLabelStyleDescription; |
75 |
import org.eclipse.sirius.diagram.description.style.EndLabelStyleDescription; |
76 |
import org.eclipse.sirius.diagram.description.style.FlatContainerStyleDescription; |
76 |
import org.eclipse.sirius.diagram.description.style.FlatContainerStyleDescription; |
77 |
import org.eclipse.sirius.diagram.description.style.GaugeCompositeStyleDescription; |
77 |
import org.eclipse.sirius.diagram.description.style.GaugeCompositeStyleDescription; |
78 |
import org.eclipse.sirius.diagram.description.style.GaugeSectionDescription; |
78 |
import org.eclipse.sirius.diagram.description.style.GaugeSectionDescription; |
79 |
import org.eclipse.sirius.diagram.description.style.HideLabelCapabilityStyleDescription; |
79 |
import org.eclipse.sirius.diagram.description.style.HideLabelCapabilityStyleDescription; |
80 |
import org.eclipse.sirius.diagram.description.style.LozengeNodeDescription; |
80 |
import org.eclipse.sirius.diagram.description.style.LozengeNodeDescription; |
81 |
import org.eclipse.sirius.diagram.description.style.NodeStyleDescription; |
81 |
import org.eclipse.sirius.diagram.description.style.NodeStyleDescription; |
82 |
import org.eclipse.sirius.diagram.description.style.NoteDescription; |
82 |
import org.eclipse.sirius.diagram.description.style.NoteDescription; |
83 |
import org.eclipse.sirius.diagram.description.style.ShapeContainerStyleDescription; |
83 |
import org.eclipse.sirius.diagram.description.style.ShapeContainerStyleDescription; |
84 |
import org.eclipse.sirius.diagram.description.style.SizeComputationContainerStyleDescription; |
84 |
import org.eclipse.sirius.diagram.description.style.SizeComputationContainerStyleDescription; |
85 |
import org.eclipse.sirius.diagram.description.style.SquareDescription; |
85 |
import org.eclipse.sirius.diagram.description.style.SquareDescription; |
86 |
import org.eclipse.sirius.diagram.description.style.StylePackage; |
86 |
import org.eclipse.sirius.diagram.description.style.StylePackage; |
87 |
import org.eclipse.sirius.diagram.description.style.WorkspaceImageDescription; |
87 |
import org.eclipse.sirius.diagram.description.style.WorkspaceImageDescription; |
88 |
import org.eclipse.sirius.diagram.tools.api.preferences.SiriusDiagramCorePreferences; |
88 |
import org.eclipse.sirius.diagram.tools.api.preferences.SiriusDiagramCorePreferences; |
89 |
import org.eclipse.sirius.diagram.util.DiagramSwitch; |
89 |
import org.eclipse.sirius.diagram.util.DiagramSwitch; |
90 |
import org.eclipse.sirius.ext.base.Option; |
90 |
import org.eclipse.sirius.ext.base.Option; |
91 |
import org.eclipse.sirius.ext.base.Options; |
91 |
import org.eclipse.sirius.ext.base.Options; |
92 |
import org.eclipse.sirius.viewpoint.BasicLabelStyle; |
92 |
import org.eclipse.sirius.viewpoint.BasicLabelStyle; |
93 |
import org.eclipse.sirius.viewpoint.Customizable; |
93 |
import org.eclipse.sirius.viewpoint.Customizable; |
94 |
import org.eclipse.sirius.viewpoint.DSemanticDecorator; |
94 |
import org.eclipse.sirius.viewpoint.DSemanticDecorator; |
95 |
import org.eclipse.sirius.viewpoint.FontFormat; |
95 |
import org.eclipse.sirius.viewpoint.FontFormat; |
96 |
import org.eclipse.sirius.viewpoint.LabelAlignment; |
96 |
import org.eclipse.sirius.viewpoint.LabelAlignment; |
97 |
import org.eclipse.sirius.viewpoint.LabelStyle; |
97 |
import org.eclipse.sirius.viewpoint.LabelStyle; |
98 |
import org.eclipse.sirius.viewpoint.Style; |
98 |
import org.eclipse.sirius.viewpoint.Style; |
99 |
import org.eclipse.sirius.viewpoint.ViewpointPackage; |
99 |
import org.eclipse.sirius.viewpoint.ViewpointPackage; |
100 |
import org.eclipse.sirius.viewpoint.description.style.BasicLabelStyleDescription; |
100 |
import org.eclipse.sirius.viewpoint.description.style.BasicLabelStyleDescription; |
101 |
import org.eclipse.sirius.viewpoint.description.style.LabelStyleDescription; |
101 |
import org.eclipse.sirius.viewpoint.description.style.LabelStyleDescription; |
102 |
import org.eclipse.sirius.viewpoint.description.style.StyleDescription; |
102 |
import org.eclipse.sirius.viewpoint.description.style.StyleDescription; |
103 |
|
103 |
|
104 |
/** |
104 |
/** |
105 |
* This helper class contains utility methods to create and update (refresh) |
105 |
* This helper class contains utility methods to create and update (refresh) |
106 |
* concrete style instances from a style description. This helper modify |
106 |
* concrete style instances from a style description. This helper modify |
107 |
* sometimes the diagram element to which apply the style (width, height, ...). |
107 |
* sometimes the diagram element to which apply the style (width, height, ...). |
108 |
* |
108 |
* |
109 |
* @author mchauvin |
109 |
* @author mchauvin |
110 |
*/ |
110 |
*/ |
111 |
public final class StyleHelper { |
111 |
public final class StyleHelper { |
112 |
|
112 |
|
113 |
// This is default size used for node height, node width or edge size when |
113 |
// This is default size used for node height, node width or edge size when |
114 |
// everything for computing these values failed. |
114 |
// everything for computing these values failed. |
115 |
// "3" is an arbitrary value extracted from this code and it doesn't seem to |
115 |
// "3" is an arbitrary value extracted from this code and it doesn't seem to |
116 |
// be linked with any existing requirement. |
116 |
// be linked with any existing requirement. |
117 |
private static final Integer DEFAULT_SIZE = Integer.valueOf(3); |
117 |
private static final Integer DEFAULT_SIZE = Integer.valueOf(3); |
118 |
|
118 |
|
119 |
private static final Integer AUTO_SIZE_CONTAINER = Integer.valueOf(-1); |
119 |
private static final Integer AUTO_SIZE_CONTAINER = Integer.valueOf(-1); |
120 |
|
120 |
|
121 |
private IInterpreter interpreter; |
121 |
private IInterpreter interpreter; |
122 |
|
122 |
|
123 |
private DiagramStyleColorUpdater colorUpdater; |
123 |
private DiagramStyleColorUpdater colorUpdater; |
124 |
|
124 |
|
125 |
/** |
125 |
/** |
126 |
* Create the helper. |
126 |
* Create the helper. |
127 |
* |
127 |
* |
128 |
* @param interpreter |
128 |
* @param interpreter |
129 |
* interpreter used to evaluate expressions. |
129 |
* interpreter used to evaluate expressions. |
130 |
*/ |
130 |
*/ |
131 |
public StyleHelper(IInterpreter interpreter) { |
131 |
public StyleHelper(IInterpreter interpreter) { |
132 |
this.interpreter = interpreter; |
132 |
this.interpreter = interpreter; |
133 |
this.colorUpdater = new DiagramStyleColorUpdater(); |
133 |
this.colorUpdater = new DiagramStyleColorUpdater(); |
134 |
} |
134 |
} |
135 |
|
135 |
|
136 |
/** |
136 |
/** |
137 |
* Refresh a style based on its description. This style is considered as the |
137 |
* Refresh a style based on its description. This style is considered as the |
138 |
* previous style to used to look its the customizations. |
138 |
* previous style to used to look its the customizations. |
139 |
* |
139 |
* |
140 |
* @param style |
140 |
* @param style |
141 |
* the style to refresh. |
141 |
* the style to refresh. |
142 |
*/ |
142 |
*/ |
143 |
public void refreshStyle(final Style style) { |
143 |
public void refreshStyle(final Style style) { |
144 |
refreshStyle(style, Options.newSome(style)); |
144 |
refreshStyle(style, Options.newSome(style)); |
145 |
} |
145 |
} |
146 |
|
146 |
|
147 |
/** |
147 |
/** |
148 |
* Refresh a style based on its description. |
148 |
* Refresh a style based on its description. |
149 |
* |
149 |
* |
150 |
* @param style |
150 |
* @param style |
151 |
* the style to refresh. |
151 |
* the style to refresh. |
152 |
* @param previousStyle |
152 |
* @param previousStyle |
153 |
* the previous style (if existing) to keep compatible |
153 |
* the previous style (if existing) to keep compatible |
154 |
* customization. |
154 |
* customization. |
155 |
*/ |
155 |
*/ |
156 |
public void refreshStyle(final Style style, final Option<? extends Style> previousStyle) { |
156 |
public void refreshStyle(final Style style, final Option<? extends Style> previousStyle) { |
157 |
if (style != null && !isWorkspaceImageStyleWithNotWorkspaceImageDescription(style)) { |
157 |
if (style != null && !isWorkspaceImageStyleWithNotWorkspaceImageDescription(style)) { |
158 |
final StyleDescription description = style.getDescription(); |
158 |
final StyleDescription description = style.getDescription(); |
159 |
// Some styles are ContainerStyleDescription AND |
159 |
// Some styles are ContainerStyleDescription AND |
160 |
// NodeStyleDescription (WorkspaceImageDescription for example). |
160 |
// NodeStyleDescription (WorkspaceImageDescription for example). |
161 |
// Verify if style is instanceof Container Style. this case is |
161 |
// Verify if style is instanceof Container Style. this case is |
162 |
// only necessary for WorkspaceImageDescription who was be |
162 |
// only necessary for WorkspaceImageDescription who was be |
163 |
// Container Style or Node Style. |
163 |
// Container Style or Node Style. |
164 |
if (description instanceof ContainerStyleDescription && style instanceof ContainerStyle) { |
164 |
if (description instanceof ContainerStyleDescription && style instanceof ContainerStyle) { |
165 |
updateContainerStyle((ContainerStyleDescription) description, (ContainerStyle) style, (Option<Style>) previousStyle); |
165 |
updateContainerStyle((ContainerStyleDescription) description, (ContainerStyle) style, (Option<Style>) previousStyle); |
166 |
} |
166 |
} |
167 |
if (description instanceof NodeStyleDescription && style instanceof NodeStyle) { |
167 |
if (description instanceof NodeStyleDescription && style instanceof NodeStyle) { |
168 |
updateNodeStyle((NodeStyleDescription) description, (NodeStyle) style, (Option<Style>) previousStyle); |
168 |
updateNodeStyle((NodeStyleDescription) description, (NodeStyle) style, (Option<Style>) previousStyle); |
169 |
} |
169 |
} |
170 |
if (description instanceof EdgeStyleDescription) { |
170 |
if (description instanceof EdgeStyleDescription) { |
171 |
updateEdgeStyle((EdgeStyleDescription) description, (EdgeStyle) style, (Option<EdgeStyle>) previousStyle); |
171 |
updateEdgeStyle((EdgeStyleDescription) description, (EdgeStyle) style, (Option<EdgeStyle>) previousStyle); |
172 |
} |
172 |
} |
173 |
refreshColors(style, previousStyle); |
173 |
refreshColors(style, previousStyle); |
174 |
} |
174 |
} |
175 |
} |
175 |
} |
176 |
|
176 |
|
177 |
private boolean isWorkspaceImageStyleWithNotWorkspaceImageDescription(Style style) { |
177 |
private boolean isWorkspaceImageStyleWithNotWorkspaceImageDescription(Style style) { |
178 |
boolean isWorkspaceImageStyleWithNotWorkspaceImageDescription = style instanceof WorkspaceImage && !(style.getDescription() instanceof WorkspaceImageDescription) |
178 |
boolean isWorkspaceImageStyleWithNotWorkspaceImageDescription = style instanceof WorkspaceImage && !(style.getDescription() instanceof WorkspaceImageDescription) |
179 |
&& !style.getCustomFeatures().isEmpty(); |
179 |
&& !style.getCustomFeatures().isEmpty(); |
180 |
return isWorkspaceImageStyleWithNotWorkspaceImageDescription; |
180 |
return isWorkspaceImageStyleWithNotWorkspaceImageDescription; |
181 |
} |
181 |
} |
182 |
|
182 |
|
183 |
/** |
183 |
/** |
184 |
* Create a new style from its description. All the variable fields are not |
184 |
* Create a new style from its description. All the variable fields are not |
185 |
* computed during the creation. Indeed, they need a context that is not |
185 |
* computed during the creation. Indeed, they need a context that is not |
186 |
* known at present. |
186 |
* known at present. |
187 |
* |
187 |
* |
188 |
* @param description |
188 |
* @param description |
189 |
* the style description. |
189 |
* the style description. |
190 |
* @return the created style. |
190 |
* @return the created style. |
191 |
*/ |
191 |
*/ |
192 |
public Style createStyle(final StyleDescription description) { |
192 |
public Style createStyle(final StyleDescription description) { |
193 |
Style style = null; |
193 |
Style style = null; |
194 |
if (description instanceof ContainerStyleDescription) { |
194 |
if (description instanceof ContainerStyleDescription) { |
195 |
style = createContainerStyle((ContainerStyleDescription) description); |
195 |
style = createContainerStyle((ContainerStyleDescription) description); |
196 |
} else if (description instanceof NodeStyleDescription) { |
196 |
} else if (description instanceof NodeStyleDescription) { |
197 |
style = createNodeStyle((NodeStyleDescription) description); |
197 |
style = createNodeStyle((NodeStyleDescription) description); |
198 |
} else if (description instanceof EdgeStyleDescription) { |
198 |
} else if (description instanceof EdgeStyleDescription) { |
199 |
style = createEdgeStyle((EdgeStyleDescription) description); |
199 |
style = createEdgeStyle((EdgeStyleDescription) description); |
200 |
} |
200 |
} |
201 |
return style; |
201 |
return style; |
202 |
} |
202 |
} |
203 |
|
203 |
|
204 |
/** |
204 |
/** |
205 |
* |
205 |
* |
206 |
* Create a new edge style from its description. All the variable fields are |
206 |
* Create a new edge style from its description. All the variable fields are |
207 |
* not computed during the creation. Indeed, they need a context that is not |
207 |
* not computed during the creation. Indeed, they need a context that is not |
208 |
* known at present. |
208 |
* known at present. |
209 |
* |
209 |
* |
210 |
* @param description |
210 |
* @param description |
211 |
* the edge style description |
211 |
* the edge style description |
212 |
* @return the created style |
212 |
* @return the created style |
213 |
*/ |
213 |
*/ |
214 |
public EdgeStyle createEdgeStyle(final EdgeStyleDescription description) { |
214 |
public EdgeStyle createEdgeStyle(final EdgeStyleDescription description) { |
215 |
EdgeStyle style = null; |
215 |
EdgeStyle style = null; |
216 |
if (description instanceof BracketEdgeStyleDescription) { |
216 |
if (description instanceof BracketEdgeStyleDescription) { |
217 |
style = DiagramFactory.eINSTANCE.createBracketEdgeStyle(); |
217 |
style = DiagramFactory.eINSTANCE.createBracketEdgeStyle(); |
218 |
} else { |
218 |
} else { |
219 |
style = DiagramFactory.eINSTANCE.createEdgeStyle(); |
219 |
style = DiagramFactory.eINSTANCE.createEdgeStyle(); |
220 |
} |
220 |
} |
221 |
if (description.getBeginLabelStyleDescription() != null) { |
221 |
if (description.getBeginLabelStyleDescription() != null) { |
222 |
style.setBeginLabelStyle(DiagramFactory.eINSTANCE.createBeginLabelStyle()); |
222 |
style.setBeginLabelStyle(DiagramFactory.eINSTANCE.createBeginLabelStyle()); |
223 |
} |
223 |
} |
224 |
if (description.getEndLabelStyleDescription() != null) { |
224 |
if (description.getEndLabelStyleDescription() != null) { |
225 |
style.setEndLabelStyle(DiagramFactory.eINSTANCE.createEndLabelStyle()); |
225 |
style.setEndLabelStyle(DiagramFactory.eINSTANCE.createEndLabelStyle()); |
226 |
} |
226 |
} |
227 |
if (description.getCenterLabelStyleDescription() != null) { |
227 |
if (description.getCenterLabelStyleDescription() != null) { |
228 |
style.setCenterLabelStyle(DiagramFactory.eINSTANCE.createCenterLabelStyle()); |
228 |
style.setCenterLabelStyle(DiagramFactory.eINSTANCE.createCenterLabelStyle()); |
229 |
} |
229 |
} |
230 |
Option<EdgeStyle> noPreviousStyle = Options.newNone(); |
230 |
Option<EdgeStyle> noPreviousStyle = Options.newNone(); |
231 |
updateEdgeStyle(description, style, noPreviousStyle); |
231 |
updateEdgeStyle(description, style, noPreviousStyle); |
232 |
refreshColors(style, noPreviousStyle); |
232 |
refreshColors(style, noPreviousStyle); |
233 |
return style; |
233 |
return style; |
234 |
} |
234 |
} |
235 |
|
235 |
|
236 |
private void updateEdgeStyle(final EdgeStyleDescription edgeDescription, final EdgeStyle edgeStyle, Option<EdgeStyle> previousStyle) { |
236 |
private void updateEdgeStyle(final EdgeStyleDescription edgeDescription, final EdgeStyle edgeStyle, Option<EdgeStyle> previousStyle) { |
237 |
Integer size = Integer.valueOf(1); |
237 |
Integer size = Integer.valueOf(1); |
238 |
|
238 |
|
239 |
if (edgeStyle.getDescription() != edgeDescription) { |
239 |
if (edgeStyle.getDescription() != edgeDescription) { |
240 |
edgeStyle.setDescription(edgeDescription); |
240 |
edgeStyle.setDescription(edgeDescription); |
241 |
} |
241 |
} |
242 |
if (edgeDescription != null) { |
242 |
if (edgeDescription != null) { |
243 |
if (previousStyle.some() && previousStyle.get().getCustomFeatures().contains(DiagramPackage.Literals.EDGE_STYLE__SOURCE_ARROW.getName())) { |
243 |
if (previousStyle.some() && previousStyle.get().getCustomFeatures().contains(DiagramPackage.Literals.EDGE_STYLE__SOURCE_ARROW.getName())) { |
244 |
edgeStyle.setSourceArrow(previousStyle.get().getSourceArrow()); |
244 |
edgeStyle.setSourceArrow(previousStyle.get().getSourceArrow()); |
245 |
edgeStyle.getCustomFeatures().add(DiagramPackage.Literals.EDGE_STYLE__SOURCE_ARROW.getName()); |
245 |
edgeStyle.getCustomFeatures().add(DiagramPackage.Literals.EDGE_STYLE__SOURCE_ARROW.getName()); |
246 |
} else { |
246 |
} else { |
247 |
if (edgeStyle.getSourceArrow().getValue() != edgeDescription.getSourceArrow().getValue() |
247 |
if (edgeStyle.getSourceArrow().getValue() != edgeDescription.getSourceArrow().getValue() |
248 |
&& !edgeStyle.getCustomFeatures().contains(DiagramPackage.Literals.EDGE_STYLE__SOURCE_ARROW.getName())) { |
248 |
&& !edgeStyle.getCustomFeatures().contains(DiagramPackage.Literals.EDGE_STYLE__SOURCE_ARROW.getName())) { |
249 |
edgeStyle.setSourceArrow(edgeDescription.getSourceArrow()); |
249 |
edgeStyle.setSourceArrow(edgeDescription.getSourceArrow()); |
250 |
} |
250 |
} |
251 |
} |
251 |
} |
252 |
if (previousStyle.some() && previousStyle.get().getCustomFeatures().contains(DiagramPackage.Literals.EDGE_STYLE__TARGET_ARROW.getName())) { |
252 |
if (previousStyle.some() && previousStyle.get().getCustomFeatures().contains(DiagramPackage.Literals.EDGE_STYLE__TARGET_ARROW.getName())) { |
253 |
edgeStyle.setTargetArrow(previousStyle.get().getTargetArrow()); |
253 |
edgeStyle.setTargetArrow(previousStyle.get().getTargetArrow()); |
254 |
edgeStyle.getCustomFeatures().add(DiagramPackage.Literals.EDGE_STYLE__TARGET_ARROW.getName()); |
254 |
edgeStyle.getCustomFeatures().add(DiagramPackage.Literals.EDGE_STYLE__TARGET_ARROW.getName()); |
255 |
} else { |
255 |
} else { |
256 |
if (edgeStyle.getTargetArrow().getValue() != edgeDescription.getTargetArrow().getValue() |
256 |
if (edgeStyle.getTargetArrow().getValue() != edgeDescription.getTargetArrow().getValue() |
257 |
&& !edgeStyle.getCustomFeatures().contains(DiagramPackage.Literals.EDGE_STYLE__TARGET_ARROW.getName())) { |
257 |
&& !edgeStyle.getCustomFeatures().contains(DiagramPackage.Literals.EDGE_STYLE__TARGET_ARROW.getName())) { |
258 |
edgeStyle.setTargetArrow(edgeDescription.getTargetArrow()); |
258 |
edgeStyle.setTargetArrow(edgeDescription.getTargetArrow()); |
259 |
} |
259 |
} |
260 |
} |
260 |
} |
261 |
|
261 |
|
262 |
if (previousStyle.some() && previousStyle.get().getCustomFeatures().contains(DiagramPackage.Literals.EDGE_STYLE__LINE_STYLE.getName())) { |
262 |
if (previousStyle.some() && previousStyle.get().getCustomFeatures().contains(DiagramPackage.Literals.EDGE_STYLE__LINE_STYLE.getName())) { |
263 |
edgeStyle.setLineStyle(previousStyle.get().getLineStyle()); |
263 |
edgeStyle.setLineStyle(previousStyle.get().getLineStyle()); |
264 |
edgeStyle.getCustomFeatures().add(DiagramPackage.Literals.EDGE_STYLE__LINE_STYLE.getName()); |
264 |
edgeStyle.getCustomFeatures().add(DiagramPackage.Literals.EDGE_STYLE__LINE_STYLE.getName()); |
265 |
} else { |
265 |
} else { |
266 |
if (edgeStyle.getLineStyle().getValue() != edgeDescription.getLineStyle().getValue() |
266 |
if (edgeStyle.getLineStyle().getValue() != edgeDescription.getLineStyle().getValue() |
267 |
&& !edgeStyle.getCustomFeatures().contains(DiagramPackage.Literals.EDGE_STYLE__LINE_STYLE.getName())) { |
267 |
&& !edgeStyle.getCustomFeatures().contains(DiagramPackage.Literals.EDGE_STYLE__LINE_STYLE.getName())) { |
268 |
edgeStyle.setLineStyle(edgeDescription.getLineStyle()); |
268 |
edgeStyle.setLineStyle(edgeDescription.getLineStyle()); |
269 |
} |
269 |
} |
270 |
} |
270 |
} |
271 |
if (previousStyle.some() && previousStyle.get().getCustomFeatures().contains(DiagramPackage.Literals.EDGE_STYLE__FOLDING_STYLE.getName())) { |
271 |
if (previousStyle.some() && previousStyle.get().getCustomFeatures().contains(DiagramPackage.Literals.EDGE_STYLE__FOLDING_STYLE.getName())) { |
272 |
edgeStyle.setFoldingStyle(previousStyle.get().getFoldingStyle()); |
272 |
edgeStyle.setFoldingStyle(previousStyle.get().getFoldingStyle()); |
273 |
edgeStyle.getCustomFeatures().add(DiagramPackage.Literals.EDGE_STYLE__FOLDING_STYLE.getName()); |
273 |
edgeStyle.getCustomFeatures().add(DiagramPackage.Literals.EDGE_STYLE__FOLDING_STYLE.getName()); |
274 |
} else { |
274 |
} else { |
275 |
if (edgeStyle.getFoldingStyle().getValue() != edgeDescription.getFoldingStyle().getValue() |
275 |
if (edgeStyle.getFoldingStyle().getValue() != edgeDescription.getFoldingStyle().getValue() |
276 |
&& !edgeStyle.getCustomFeatures().contains(DiagramPackage.Literals.EDGE_STYLE__FOLDING_STYLE.getName())) { |
276 |
&& !edgeStyle.getCustomFeatures().contains(DiagramPackage.Literals.EDGE_STYLE__FOLDING_STYLE.getName())) { |
277 |
edgeStyle.setFoldingStyle(edgeDescription.getFoldingStyle()); |
277 |
edgeStyle.setFoldingStyle(edgeDescription.getFoldingStyle()); |
278 |
} |
278 |
} |
279 |
} |
279 |
} |
280 |
if (previousStyle.some() && previousStyle.get().getCustomFeatures().contains(DiagramPackage.Literals.EDGE_STYLE__SIZE.getName())) { |
280 |
if (previousStyle.some() && previousStyle.get().getCustomFeatures().contains(DiagramPackage.Literals.EDGE_STYLE__SIZE.getName())) { |
281 |
edgeStyle.setSize(previousStyle.get().getSize()); |
281 |
edgeStyle.setSize(previousStyle.get().getSize()); |
282 |
edgeStyle.getCustomFeatures().add(DiagramPackage.Literals.EDGE_STYLE__SIZE.getName()); |
282 |
edgeStyle.getCustomFeatures().add(DiagramPackage.Literals.EDGE_STYLE__SIZE.getName()); |
283 |
} else { |
283 |
} else { |
284 |
if (edgeDescription.getSizeComputationExpression() != null && edgeStyle.eContainer() != null |
284 |
if (edgeDescription.getSizeComputationExpression() != null && edgeStyle.eContainer() != null |
285 |
&& !edgeStyle.getCustomFeatures().contains(DiagramPackage.Literals.EDGE_STYLE__SIZE.getName())) { |
285 |
&& !edgeStyle.getCustomFeatures().contains(DiagramPackage.Literals.EDGE_STYLE__SIZE.getName())) { |
286 |
try { |
286 |
try { |
287 |
size = interpreter.evaluateInteger(((DSemanticDecorator) edgeStyle.eContainer()).getTarget(), edgeDescription.getSizeComputationExpression()); |
287 |
size = interpreter.evaluateInteger(((DSemanticDecorator) edgeStyle.eContainer()).getTarget(), edgeDescription.getSizeComputationExpression()); |
288 |
} catch (final EvaluationException e) { |
288 |
} catch (final EvaluationException e) { |
289 |
// silent. |
289 |
// silent. |
290 |
} |
290 |
} |
291 |
edgeStyle.setSize(size); |
291 |
edgeStyle.setSize(size); |
292 |
} |
292 |
} |
293 |
} |
293 |
} |
294 |
// Get the override edge routing from the diagram preferences. If |
294 |
// Get the override edge routing from the diagram preferences. If |
295 |
// the edge routing override is enable, it is more priority than the |
295 |
// the edge routing override is enable, it is more priority than the |
296 |
// VSM style but less that the manual customization. |
296 |
// VSM style but less that the manual customization. |
297 |
final IPreferencesService service = Platform.getPreferencesService(); |
297 |
final IPreferencesService service = Platform.getPreferencesService(); |
298 |
Option<EdgeRouting> overrideEdgeRouting = Options.newNone(); |
298 |
Option<EdgeRouting> overrideEdgeRouting = Options.newNone(); |
299 |
boolean isOverideEnabled = service.getBoolean(DiagramPlugin.ID, SiriusDiagramCorePreferences.PREF_ENABLE_OVERRIDE, SiriusDiagramCorePreferences.PREF_ENABLE_OVERRIDE_DEFAULT_VALUE, null); |
299 |
boolean isOverideEnabled = service.getBoolean(DiagramPlugin.ID, SiriusDiagramCorePreferences.PREF_ENABLE_OVERRIDE, SiriusDiagramCorePreferences.PREF_ENABLE_OVERRIDE_DEFAULT_VALUE, null); |
300 |
if (isOverideEnabled) { |
300 |
if (isOverideEnabled) { |
301 |
int routingStyle = service.getInt(DiagramPlugin.ID, SiriusDiagramCorePreferences.PREF_LINE_STYLE, SiriusDiagramCorePreferences.PREF_LINE_STYLE_DEFAULT_VALUE, null); |
301 |
int routingStyle = service.getInt(DiagramPlugin.ID, SiriusDiagramCorePreferences.PREF_LINE_STYLE, SiriusDiagramCorePreferences.PREF_LINE_STYLE_DEFAULT_VALUE, null); |
302 |
overrideEdgeRouting = Options.newSome(EdgeRouting.get(routingStyle)); |
302 |
overrideEdgeRouting = Options.newSome(EdgeRouting.get(routingStyle)); |
303 |
} |
303 |
} |
304 |
// If a previous style exists, we are not on a creation of an edge |
304 |
// If a previous style exists, we are not on a creation of an edge |
305 |
// so the potential override is ignored. |
305 |
// so the potential override is ignored. |
306 |
if (previousStyle.some()) { |
306 |
if (previousStyle.some()) { |
307 |
// If the previous style has been manually customized we use the |
307 |
// If the previous style has been manually customized we use the |
308 |
// same customization. |
308 |
// same customization. |
309 |
if (previousStyle.get().getCustomFeatures().contains(DiagramPackage.Literals.EDGE_STYLE__ROUTING_STYLE.getName())) { |
309 |
if (previousStyle.get().getCustomFeatures().contains(DiagramPackage.Literals.EDGE_STYLE__ROUTING_STYLE.getName())) { |
310 |
edgeStyle.setRoutingStyle(previousStyle.get().getRoutingStyle()); |
310 |
edgeStyle.setRoutingStyle(previousStyle.get().getRoutingStyle()); |
311 |
edgeStyle.getCustomFeatures().add(DiagramPackage.Literals.EDGE_STYLE__ROUTING_STYLE.getName()); |
311 |
edgeStyle.getCustomFeatures().add(DiagramPackage.Literals.EDGE_STYLE__ROUTING_STYLE.getName()); |
312 |
} |
312 |
} |
313 |
} else if (overrideEdgeRouting.some()) { |
313 |
} else if (overrideEdgeRouting.some()) { |
314 |
// Add the feature routingStyle as customization |
314 |
// Add the feature routingStyle as customization |
315 |
edgeStyle.getCustomFeatures().add(DiagramPackage.Literals.EDGE_STYLE__ROUTING_STYLE.getName()); |
315 |
edgeStyle.getCustomFeatures().add(DiagramPackage.Literals.EDGE_STYLE__ROUTING_STYLE.getName()); |
316 |
// Set the new value if different. |
316 |
// Set the new value if different. |
317 |
if (edgeStyle.getRoutingStyle().getValue() != overrideEdgeRouting.get().getValue()) { |
317 |
if (edgeStyle.getRoutingStyle().getValue() != overrideEdgeRouting.get().getValue()) { |
318 |
edgeStyle.setRoutingStyle(overrideEdgeRouting.get()); |
318 |
edgeStyle.setRoutingStyle(overrideEdgeRouting.get()); |
319 |
} |
319 |
} |
320 |
} |
320 |
} |
321 |
// Use the VSM value if there is no customization (from manual |
321 |
// Use the VSM value if there is no customization (from manual |
322 |
// customization of existing style or from preference) |
322 |
// customization of existing style or from preference) |
323 |
|
323 |
|
324 |
if (edgeDescription.getRoutingStyle().getValue() != edgeStyle.getRoutingStyle().getValue() |
324 |
if (edgeDescription.getRoutingStyle().getValue() != edgeStyle.getRoutingStyle().getValue() |
325 |
&& !edgeStyle.getCustomFeatures().contains(DiagramPackage.Literals.EDGE_STYLE__ROUTING_STYLE.getName())) { |
325 |
&& !edgeStyle.getCustomFeatures().contains(DiagramPackage.Literals.EDGE_STYLE__ROUTING_STYLE.getName())) { |
326 |
edgeStyle.setRoutingStyle(edgeDescription.getRoutingStyle()); |
326 |
edgeStyle.setRoutingStyle(edgeDescription.getRoutingStyle()); |
327 |
} |
327 |
} |
328 |
updateLabels(edgeDescription, edgeStyle, previousStyle); |
328 |
updateLabels(edgeDescription, edgeStyle, previousStyle); |
329 |
updateEdgeCenteringInformations(edgeDescription, edgeStyle, previousStyle); |
329 |
updateEdgeCenteringInformations(edgeDescription, edgeStyle, previousStyle); |
330 |
} |
330 |
} |
331 |
} |
331 |
} |
332 |
|
332 |
|
333 |
private void updateLabels(EdgeStyleDescription edgeDescription, EdgeStyle edgeStyle, Option<EdgeStyle> previousStyle) { |
333 |
private void updateLabels(EdgeStyleDescription edgeDescription, EdgeStyle edgeStyle, Option<EdgeStyle> previousStyle) { |
334 |
if (previousStyle.some()) { |
334 |
if (previousStyle.some()) { |
335 |
if (previousStyle.get().getCustomFeatures().contains(DiagramPackage.Literals.EDGE_STYLE__CENTER_LABEL_STYLE.getName())) { |
335 |
if (previousStyle.get().getCustomFeatures().contains(DiagramPackage.Literals.EDGE_STYLE__CENTER_LABEL_STYLE.getName())) { |
336 |
edgeStyle.getCustomFeatures().add(DiagramPackage.Literals.EDGE_STYLE__CENTER_LABEL_STYLE.getName()); |
336 |
edgeStyle.getCustomFeatures().add(DiagramPackage.Literals.EDGE_STYLE__CENTER_LABEL_STYLE.getName()); |
337 |
edgeStyle.setCenterLabelStyle(previousStyle.get().getCenterLabelStyle()); |
337 |
edgeStyle.setCenterLabelStyle(previousStyle.get().getCenterLabelStyle()); |
338 |
} |
338 |
} |
339 |
} |
339 |
} |
340 |
if (edgeDescription.getCenterLabelStyleDescription() != null && edgeStyle.getCenterLabelStyle() == null |
340 |
if (edgeDescription.getCenterLabelStyleDescription() != null && edgeStyle.getCenterLabelStyle() == null |
341 |
&& !edgeStyle.getCustomFeatures().contains(DiagramPackage.Literals.EDGE_STYLE__CENTER_LABEL_STYLE.getName())) { |
341 |
&& !edgeStyle.getCustomFeatures().contains(DiagramPackage.Literals.EDGE_STYLE__CENTER_LABEL_STYLE.getName())) { |
342 |
CenterLabelStyle centerLabelStyle = DiagramFactory.eINSTANCE.createCenterLabelStyle(); |
342 |
CenterLabelStyle centerLabelStyle = DiagramFactory.eINSTANCE.createCenterLabelStyle(); |
343 |
edgeStyle.setCenterLabelStyle(centerLabelStyle); |
343 |
edgeStyle.setCenterLabelStyle(centerLabelStyle); |
344 |
} |
344 |
} |
345 |
updateEdgeLabel(edgeDescription.getCenterLabelStyleDescription(), edgeStyle.getCenterLabelStyle()); |
345 |
updateEdgeLabel(edgeDescription.getCenterLabelStyleDescription(), edgeStyle.getCenterLabelStyle()); |
346 |
|
346 |
|
347 |
if (previousStyle.some()) { |
347 |
if (previousStyle.some()) { |
348 |
if (previousStyle.get().getCustomFeatures().contains(DiagramPackage.Literals.EDGE_STYLE__BEGIN_LABEL_STYLE.getName())) { |
348 |
if (previousStyle.get().getCustomFeatures().contains(DiagramPackage.Literals.EDGE_STYLE__BEGIN_LABEL_STYLE.getName())) { |
349 |
edgeStyle.getCustomFeatures().add(DiagramPackage.Literals.EDGE_STYLE__BEGIN_LABEL_STYLE.getName()); |
349 |
edgeStyle.getCustomFeatures().add(DiagramPackage.Literals.EDGE_STYLE__BEGIN_LABEL_STYLE.getName()); |
350 |
edgeStyle.setBeginLabelStyle(previousStyle.get().getBeginLabelStyle()); |
350 |
edgeStyle.setBeginLabelStyle(previousStyle.get().getBeginLabelStyle()); |
351 |
} |
351 |
} |
352 |
} |
352 |
} |
353 |
if (edgeDescription.getBeginLabelStyleDescription() != null && edgeStyle.getBeginLabelStyle() == null |
353 |
if (edgeDescription.getBeginLabelStyleDescription() != null && edgeStyle.getBeginLabelStyle() == null |
354 |
&& !edgeStyle.getCustomFeatures().contains(DiagramPackage.Literals.EDGE_STYLE__BEGIN_LABEL_STYLE.getName())) { |
354 |
&& !edgeStyle.getCustomFeatures().contains(DiagramPackage.Literals.EDGE_STYLE__BEGIN_LABEL_STYLE.getName())) { |
355 |
BeginLabelStyle beginLabelStyle = DiagramFactory.eINSTANCE.createBeginLabelStyle(); |
355 |
BeginLabelStyle beginLabelStyle = DiagramFactory.eINSTANCE.createBeginLabelStyle(); |
356 |
edgeStyle.setBeginLabelStyle(beginLabelStyle); |
356 |
edgeStyle.setBeginLabelStyle(beginLabelStyle); |
357 |
} |
357 |
} |
358 |
updateEdgeLabel(edgeDescription.getBeginLabelStyleDescription(), edgeStyle.getBeginLabelStyle()); |
358 |
updateEdgeLabel(edgeDescription.getBeginLabelStyleDescription(), edgeStyle.getBeginLabelStyle()); |
359 |
|
359 |
|
360 |
if (previousStyle.some()) { |
360 |
if (previousStyle.some()) { |
361 |
if (previousStyle.get().getCustomFeatures().contains(DiagramPackage.Literals.EDGE_STYLE__END_LABEL_STYLE.getName())) { |
361 |
if (previousStyle.get().getCustomFeatures().contains(DiagramPackage.Literals.EDGE_STYLE__END_LABEL_STYLE.getName())) { |
362 |
edgeStyle.getCustomFeatures().add(DiagramPackage.Literals.EDGE_STYLE__END_LABEL_STYLE.getName()); |
362 |
edgeStyle.getCustomFeatures().add(DiagramPackage.Literals.EDGE_STYLE__END_LABEL_STYLE.getName()); |
363 |
edgeStyle.setBeginLabelStyle(previousStyle.get().getBeginLabelStyle()); |
363 |
edgeStyle.setBeginLabelStyle(previousStyle.get().getBeginLabelStyle()); |
364 |
} |
364 |
} |
365 |
} |
365 |
} |
366 |
if (edgeDescription.getEndLabelStyleDescription() != null && edgeStyle.getEndLabelStyle() == null |
366 |
if (edgeDescription.getEndLabelStyleDescription() != null && edgeStyle.getEndLabelStyle() == null |
367 |
&& !edgeStyle.getCustomFeatures().contains(DiagramPackage.Literals.EDGE_STYLE__END_LABEL_STYLE.getName())) { |
367 |
&& !edgeStyle.getCustomFeatures().contains(DiagramPackage.Literals.EDGE_STYLE__END_LABEL_STYLE.getName())) { |
368 |
EndLabelStyle endLabelStyle = DiagramFactory.eINSTANCE.createEndLabelStyle(); |
368 |
EndLabelStyle endLabelStyle = DiagramFactory.eINSTANCE.createEndLabelStyle(); |
369 |
edgeStyle.setEndLabelStyle(endLabelStyle); |
369 |
edgeStyle.setEndLabelStyle(endLabelStyle); |
370 |
} |
370 |
} |
371 |
updateEdgeLabel(edgeDescription.getEndLabelStyleDescription(), edgeStyle.getEndLabelStyle()); |
371 |
updateEdgeLabel(edgeDescription.getEndLabelStyleDescription(), edgeStyle.getEndLabelStyle()); |
372 |
} |
372 |
} |
373 |
|
373 |
|
374 |
private void updateEdgeCenteringInformations(EdgeStyleDescription edgeDescription, EdgeStyle edgeStyle, Option<EdgeStyle> previousStyle) { |
374 |
private void updateEdgeCenteringInformations(EdgeStyleDescription edgeDescription, EdgeStyle edgeStyle, Option<EdgeStyle> previousStyle) { |
375 |
|
375 |
|
376 |
if (previousStyle.some() && previousStyle.get().getCustomFeatures().contains(DiagramPackage.Literals.EDGE_STYLE__CENTERED.getName())) { |
376 |
if (previousStyle.some() && previousStyle.get().getCustomFeatures().contains(DiagramPackage.Literals.EDGE_STYLE__CENTERED.getName())) { |
377 |
edgeStyle.setCentered(previousStyle.get().getCentered()); |
377 |
edgeStyle.setCentered(previousStyle.get().getCentered()); |
378 |
edgeStyle.getCustomFeatures().add(DiagramPackage.Literals.EDGE_STYLE__CENTERED.getName()); |
378 |
edgeStyle.getCustomFeatures().add(DiagramPackage.Literals.EDGE_STYLE__CENTERED.getName()); |
379 |
} else { |
379 |
} else { |
380 |
if (!edgeStyle.getCustomFeatures().contains(DiagramPackage.Literals.EDGE_STYLE__CENTERED.getName())) { |
380 |
if (!edgeStyle.getCustomFeatures().contains(DiagramPackage.Literals.EDGE_STYLE__CENTERED.getName())) { |
381 |
|
381 |
|
382 |
computeCentered(edgeDescription, edgeStyle); |
382 |
computeCentered(edgeDescription, edgeStyle); |
383 |
} |
383 |
} |
384 |
} |
384 |
} |
385 |
} |
385 |
} |
386 |
|
386 |
|
387 |
private void computeCentered(EdgeStyleDescription edgeDescription, EdgeStyle edgeStyle) { |
387 |
private void computeCentered(EdgeStyleDescription edgeDescription, EdgeStyle edgeStyle) { |
388 |
switch (edgeDescription.getEndsCentering().getValue()) { |
388 |
switch (edgeDescription.getEndsCentering().getValue()) { |
389 |
case CenteringStyle.BOTH_VALUE: |
389 |
case CenteringStyle.BOTH_VALUE: |
390 |
edgeStyle.setCentered(CenteringStyle.BOTH); |
390 |
edgeStyle.setCentered(CenteringStyle.BOTH); |
391 |
break; |
391 |
break; |
392 |
case CenteringStyle.SOURCE_VALUE: |
392 |
case CenteringStyle.SOURCE_VALUE: |
393 |
if (isTargetCentered(edgeDescription, edgeStyle)) { |
393 |
if (isTargetCentered(edgeDescription, edgeStyle)) { |
394 |
edgeStyle.setCentered(CenteringStyle.BOTH); |
394 |
edgeStyle.setCentered(CenteringStyle.BOTH); |
395 |
} else { |
395 |
} else { |
396 |
edgeStyle.setCentered(CenteringStyle.SOURCE); |
396 |
edgeStyle.setCentered(CenteringStyle.SOURCE); |
397 |
} |
397 |
} |
398 |
break; |
398 |
break; |
399 |
case CenteringStyle.TARGET_VALUE: |
399 |
case CenteringStyle.TARGET_VALUE: |
400 |
if (isSourceCentered(edgeDescription, edgeStyle)) { |
400 |
if (isSourceCentered(edgeDescription, edgeStyle)) { |
401 |
edgeStyle.setCentered(CenteringStyle.BOTH); |
401 |
edgeStyle.setCentered(CenteringStyle.BOTH); |
402 |
} else { |
402 |
} else { |
403 |
edgeStyle.setCentered(CenteringStyle.TARGET); |
403 |
edgeStyle.setCentered(CenteringStyle.TARGET); |
404 |
} |
404 |
} |
405 |
|
405 |
|
406 |
break; |
406 |
break; |
407 |
case CenteringStyle.NONE_VALUE: |
407 |
case CenteringStyle.NONE_VALUE: |
408 |
boolean isSourceCentered = isSourceCentered(edgeDescription, edgeStyle); |
408 |
boolean isSourceCentered = isSourceCentered(edgeDescription, edgeStyle); |
409 |
boolean isTargetCentered = isTargetCentered(edgeDescription, edgeStyle); |
409 |
boolean isTargetCentered = isTargetCentered(edgeDescription, edgeStyle); |
410 |
if (isSourceCentered && isTargetCentered) { |
410 |
if (isSourceCentered && isTargetCentered) { |
411 |
edgeStyle.setCentered(CenteringStyle.BOTH); |
411 |
edgeStyle.setCentered(CenteringStyle.BOTH); |
412 |
} else if (isSourceCentered) { |
412 |
} else if (isSourceCentered) { |
413 |
edgeStyle.setCentered(CenteringStyle.SOURCE); |
413 |
edgeStyle.setCentered(CenteringStyle.SOURCE); |
414 |
} else if (isTargetCentered) { |
414 |
} else if (isTargetCentered) { |
415 |
edgeStyle.setCentered(CenteringStyle.TARGET); |
415 |
edgeStyle.setCentered(CenteringStyle.TARGET); |
416 |
} else { |
416 |
} else { |
417 |
edgeStyle.setCentered(CenteringStyle.NONE); |
417 |
edgeStyle.setCentered(CenteringStyle.NONE); |
418 |
} |
418 |
} |
419 |
break; |
419 |
break; |
420 |
default: |
420 |
default: |
421 |
// This case should not append |
421 |
// This case should not append |
422 |
break; |
422 |
break; |
423 |
} |
423 |
} |
424 |
} |
424 |
} |
425 |
|
425 |
|
426 |
private boolean isTargetCentered(EdgeStyleDescription edgeDescription, EdgeStyle edgeStyle) { |
426 |
private boolean isTargetCentered(EdgeStyleDescription edgeDescription, EdgeStyle edgeStyle) { |
427 |
EObject dEdgeEObject = edgeStyle.eContainer(); |
427 |
EObject dEdgeEObject = edgeStyle.eContainer(); |
428 |
|
428 |
|
429 |
// if the edge style is affected to a DEdge |
429 |
// if the edge style is affected to a DEdge |
430 |
if (dEdgeEObject instanceof DEdge) { |
430 |
if (dEdgeEObject instanceof DEdge) { |
431 |
EdgeTarget edgeTarget = ((DEdge) dEdgeEObject).getTargetNode(); |
431 |
EdgeTarget edgeTarget = ((DEdge) dEdgeEObject).getTargetNode(); |
432 |
if (edgeTarget instanceof DDiagramElement) { |
432 |
if (edgeTarget instanceof DDiagramElement) { |
433 |
|
433 |
|
434 |
List<DiagramElementMapping> centeredTargetMappings = edgeDescription.getCenteredTargetMappings(); |
434 |
List<DiagramElementMapping> centeredTargetMappings = edgeDescription.getCenteredTargetMappings(); |
435 |
return isHierarchyPartOfMappingsList(edgeTarget, centeredTargetMappings); |
435 |
return isHierarchyPartOfMappingsList(edgeTarget, centeredTargetMappings); |
436 |
|
436 |
|
437 |
} |
437 |
} |
438 |
} |
438 |
} |
439 |
return false; |
439 |
return false; |
440 |
} |
440 |
} |
441 |
|
441 |
|
442 |
private boolean isSourceCentered(EdgeStyleDescription edgeDescription, EdgeStyle edgeStyle) { |
442 |
private boolean isSourceCentered(EdgeStyleDescription edgeDescription, EdgeStyle edgeStyle) { |
443 |
EObject dEdgeEObject = edgeStyle.eContainer(); |
443 |
EObject dEdgeEObject = edgeStyle.eContainer(); |
444 |
|
444 |
|
445 |
// if the edge style is affected to a DEdge |
445 |
// if the edge style is affected to a DEdge |
446 |
if (dEdgeEObject instanceof DEdge) { |
446 |
if (dEdgeEObject instanceof DEdge) { |
447 |
EdgeTarget edgeSource = ((DEdge) dEdgeEObject).getSourceNode(); |
447 |
EdgeTarget edgeSource = ((DEdge) dEdgeEObject).getSourceNode(); |
448 |
if (edgeSource instanceof DDiagramElement) { |
448 |
if (edgeSource instanceof DDiagramElement) { |
449 |
|
449 |
|
450 |
List<DiagramElementMapping> centeredSourceMappings = edgeDescription.getCenteredSourceMappings(); |
450 |
List<DiagramElementMapping> centeredSourceMappings = edgeDescription.getCenteredSourceMappings(); |
451 |
return isHierarchyPartOfMappingsList(edgeSource, centeredSourceMappings); |
451 |
return isHierarchyPartOfMappingsList(edgeSource, centeredSourceMappings); |
452 |
} |
452 |
} |
453 |
} |
453 |
} |
454 |
return false; |
454 |
return false; |
455 |
} |
455 |
} |
456 |
|
456 |
|
457 |
private boolean isHierarchyPartOfMappingsList(EdgeTarget edgeTarget, List<DiagramElementMapping> mappingsList) { |
457 |
private boolean isHierarchyPartOfMappingsList(EdgeTarget edgeTarget, List<DiagramElementMapping> mappingsList) { |
458 |
|
458 |
|
459 |
DiagramElementMapping diagramElementMapping = ((DDiagramElement) edgeTarget).getDiagramElementMapping(); |
459 |
DiagramElementMapping diagramElementMapping = ((DDiagramElement) edgeTarget).getDiagramElementMapping(); |
460 |
DiagramElementMappingQuery mappingQuery = new DiagramElementMappingQuery(diagramElementMapping); |
460 |
DiagramElementMappingQuery mappingQuery = new DiagramElementMappingQuery(diagramElementMapping); |
461 |
for (DiagramElementMapping currentMapping : mappingsList) { |
461 |
for (DiagramElementMapping currentMapping : mappingsList) { |
462 |
if (EqualityHelper.areEquals(diagramElementMapping, currentMapping) || mappingQuery.isSubTypeOf(currentMapping)) { |
462 |
if (EqualityHelper.areEquals(diagramElementMapping, currentMapping) || mappingQuery.isSubTypeOf(currentMapping)) { |
463 |
return true; |
463 |
return true; |
464 |
} |
464 |
} |
465 |
} |
465 |
} |
466 |
return false; |
466 |
return false; |
467 |
} |
467 |
} |
468 |
|
468 |
|
469 |
private void updateEdgeLabel(BasicLabelStyleDescription description, BasicLabelStyle style) { |
469 |
private void updateEdgeLabel(BasicLabelStyleDescription description, BasicLabelStyle style) { |
470 |
if (description instanceof BeginLabelStyleDescription && style instanceof BeginLabelStyle && ((BeginLabelStyle) style).getDescription() != description) { |
470 |
if (description instanceof BeginLabelStyleDescription && style instanceof BeginLabelStyle && ((BeginLabelStyle) style).getDescription() != description) { |
471 |
((BeginLabelStyle) style).setDescription(description); |
471 |
((BeginLabelStyle) style).setDescription(description); |
472 |
} |
472 |
} |
473 |
|
473 |
|
474 |
if (description instanceof EndLabelStyleDescription && style instanceof EndLabelStyle && ((EndLabelStyle) style).getDescription() != description) { |
474 |
if (description instanceof EndLabelStyleDescription && style instanceof EndLabelStyle && ((EndLabelStyle) style).getDescription() != description) { |
475 |
((EndLabelStyle) style).setDescription(description); |
475 |
((EndLabelStyle) style).setDescription(description); |
476 |
} |
476 |
} |
477 |
|
477 |
|
478 |
if (description instanceof CenterLabelStyleDescription && style instanceof CenterLabelStyle && ((CenterLabelStyle) style).getDescription() != description) { |
478 |
if (description instanceof CenterLabelStyleDescription && style instanceof CenterLabelStyle && ((CenterLabelStyle) style).getDescription() != description) { |
479 |
((CenterLabelStyle) style).setDescription(description); |
479 |
((CenterLabelStyle) style).setDescription(description); |
480 |
} |
480 |
} |
481 |
|
481 |
|
482 |
if (description != null && style != null) { |
482 |
if (description != null && style != null) { |
483 |
if (style.isShowIcon() != description.isShowIcon() && !style.getCustomFeatures().contains(ViewpointPackage.Literals.BASIC_LABEL_STYLE__SHOW_ICON.getName())) { |
483 |
if (style.isShowIcon() != description.isShowIcon() && !style.getCustomFeatures().contains(ViewpointPackage.Literals.BASIC_LABEL_STYLE__SHOW_ICON.getName())) { |
484 |
style.setShowIcon(description.isShowIcon()); |
484 |
style.setShowIcon(description.isShowIcon()); |
485 |
} |
485 |
} |
486 |
if (style.getIconPath() != null && !style.getIconPath().equals(description.getIconPath()) |
486 |
if (style.getIconPath() != null && !style.getIconPath().equals(description.getIconPath()) |
487 |
&& !style.getCustomFeatures().contains(ViewpointPackage.Literals.BASIC_LABEL_STYLE__ICON_PATH.getName())) { |
487 |
&& !style.getCustomFeatures().contains(ViewpointPackage.Literals.BASIC_LABEL_STYLE__ICON_PATH.getName())) { |
488 |
style.setIconPath(description.getIconPath()); |
488 |
style.setIconPath(description.getIconPath()); |
489 |
} |
489 |
} |
490 |
|
490 |
|
491 |
Option<NodeStyle> noPreviousStyle = Options.newNone(); |
491 |
Option<NodeStyle> noPreviousStyle = Options.newNone(); |
492 |
updateBasicLabelStyleFeatures(description, style, noPreviousStyle); |
492 |
updateBasicLabelStyleFeatures(description, style, noPreviousStyle); |
493 |
} |
493 |
} |
494 |
} |
494 |
} |
495 |
|
495 |
|
496 |
private void updateLabelStyleFeatures(final LabelStyleDescription description, final LabelStyle style, Option<? extends LabelStyle> previousStyle) { |
496 |
private void updateLabelStyleFeatures(final LabelStyleDescription description, final LabelStyle style, Option<? extends LabelStyle> previousStyle) { |
497 |
final LabelAlignment alignment = description.getLabelAlignment(); |
497 |
final LabelAlignment alignment = description.getLabelAlignment(); |
498 |
|
498 |
|
499 |
if (previousStyle.some() && previousStyle.get().getCustomFeatures().contains(ViewpointPackage.Literals.LABEL_STYLE__LABEL_ALIGNMENT.getName())) { |
499 |
if (previousStyle.some() && previousStyle.get().getCustomFeatures().contains(ViewpointPackage.Literals.LABEL_STYLE__LABEL_ALIGNMENT.getName())) { |
500 |
style.setLabelAlignment(previousStyle.get().getLabelAlignment()); |
500 |
style.setLabelAlignment(previousStyle.get().getLabelAlignment()); |
501 |
style.getCustomFeatures().add(ViewpointPackage.Literals.LABEL_STYLE__LABEL_ALIGNMENT.getName()); |
501 |
style.getCustomFeatures().add(ViewpointPackage.Literals.LABEL_STYLE__LABEL_ALIGNMENT.getName()); |
502 |
} else { |
502 |
} else { |
503 |
if (style.getLabelAlignment() != alignment && !style.getCustomFeatures().contains(ViewpointPackage.Literals.LABEL_STYLE__LABEL_ALIGNMENT.getName())) { |
503 |
if (style.getLabelAlignment() != alignment && !style.getCustomFeatures().contains(ViewpointPackage.Literals.LABEL_STYLE__LABEL_ALIGNMENT.getName())) { |
504 |
style.setLabelAlignment(alignment); |
504 |
style.setLabelAlignment(alignment); |
505 |
} |
505 |
} |
506 |
} |
506 |
} |
507 |
updateBasicLabelStyleFeatures(description, style, previousStyle); |
507 |
updateBasicLabelStyleFeatures(description, style, previousStyle); |
508 |
} |
508 |
} |
509 |
|
509 |
|
510 |
private void updateBasicLabelStyleFeatures(final BasicLabelStyleDescription description, final BasicLabelStyle style, Option<? extends BasicLabelStyle> previousStyle) { |
510 |
private void updateBasicLabelStyleFeatures(final BasicLabelStyleDescription description, final BasicLabelStyle style, Option<? extends BasicLabelStyle> previousStyle) { |
511 |
final List<FontFormat> format = description.getLabelFormat(); |
511 |
final List<FontFormat> format = description.getLabelFormat(); |
512 |
final int size = description.getLabelSize(); |
512 |
final int size = description.getLabelSize(); |
513 |
|
513 |
|
514 |
if (previousStyle.some() && previousStyle.get().getCustomFeatures().contains(ViewpointPackage.Literals.BASIC_LABEL_STYLE__SHOW_ICON.getName())) { |
514 |
if (previousStyle.some() && previousStyle.get().getCustomFeatures().contains(ViewpointPackage.Literals.BASIC_LABEL_STYLE__SHOW_ICON.getName())) { |
515 |
style.setShowIcon(previousStyle.get().isShowIcon()); |
515 |
style.setShowIcon(previousStyle.get().isShowIcon()); |
516 |
style.getCustomFeatures().add(ViewpointPackage.Literals.BASIC_LABEL_STYLE__SHOW_ICON.getName()); |
516 |
style.getCustomFeatures().add(ViewpointPackage.Literals.BASIC_LABEL_STYLE__SHOW_ICON.getName()); |
517 |
} else { |
517 |
} else { |
518 |
if (style.isShowIcon() != description.isShowIcon() && !style.getCustomFeatures().contains(ViewpointPackage.Literals.BASIC_LABEL_STYLE__SHOW_ICON.getName())) { |
518 |
if (style.isShowIcon() != description.isShowIcon() && !style.getCustomFeatures().contains(ViewpointPackage.Literals.BASIC_LABEL_STYLE__SHOW_ICON.getName())) { |
519 |
style.setShowIcon(description.isShowIcon()); |
519 |
style.setShowIcon(description.isShowIcon()); |
520 |
} |
520 |
} |
521 |
} |
521 |
} |
522 |
|
522 |
|
523 |
if (previousStyle.some() && previousStyle.get().getCustomFeatures().contains(ViewpointPackage.Literals.BASIC_LABEL_STYLE__ICON_PATH.getName())) { |
523 |
if (previousStyle.some() && previousStyle.get().getCustomFeatures().contains(ViewpointPackage.Literals.BASIC_LABEL_STYLE__ICON_PATH.getName())) { |
524 |
style.setIconPath(previousStyle.get().getIconPath()); |
524 |
style.setIconPath(previousStyle.get().getIconPath()); |
525 |
style.getCustomFeatures().add(ViewpointPackage.Literals.BASIC_LABEL_STYLE__ICON_PATH.getName()); |
525 |
style.getCustomFeatures().add(ViewpointPackage.Literals.BASIC_LABEL_STYLE__ICON_PATH.getName()); |
526 |
} else { |
526 |
} else { |
527 |
if (style.getIconPath() != null && !style.getIconPath().equals(description.getIconPath()) |
527 |
if (style.getIconPath() != null && !style.getIconPath().equals(description.getIconPath()) |
528 |
&& !style.getCustomFeatures().contains(ViewpointPackage.Literals.BASIC_LABEL_STYLE__ICON_PATH.getName())) { |
528 |
&& !style.getCustomFeatures().contains(ViewpointPackage.Literals.BASIC_LABEL_STYLE__ICON_PATH.getName())) { |
529 |
style.setIconPath(description.getIconPath()); |
529 |
style.setIconPath(description.getIconPath()); |
530 |
} |
530 |
} |
531 |
} |
531 |
} |
532 |
|
532 |
|
533 |
if (previousStyle.some() && previousStyle.get().getCustomFeatures().contains(ViewpointPackage.Literals.BASIC_LABEL_STYLE__LABEL_FORMAT.getName())) { |
533 |
if (previousStyle.some() && previousStyle.get().getCustomFeatures().contains(ViewpointPackage.Literals.BASIC_LABEL_STYLE__LABEL_FORMAT.getName())) { |
534 |
FontFormatHelper.setFontFormat(style.getLabelFormat(), previousStyle.get().getLabelFormat()); |
534 |
FontFormatHelper.setFontFormat(style.getLabelFormat(), previousStyle.get().getLabelFormat()); |
535 |
style.getCustomFeatures().add(ViewpointPackage.Literals.BASIC_LABEL_STYLE__LABEL_FORMAT.getName()); |
535 |
style.getCustomFeatures().add(ViewpointPackage.Literals.BASIC_LABEL_STYLE__LABEL_FORMAT.getName()); |
536 |
} else { |
536 |
} else { |
537 |
if (!style.getLabelFormat().equals(format) && !style.getCustomFeatures().contains(ViewpointPackage.Literals.BASIC_LABEL_STYLE__LABEL_FORMAT.getName())) { |
537 |
if (!style.getLabelFormat().equals(format) && !style.getCustomFeatures().contains(ViewpointPackage.Literals.BASIC_LABEL_STYLE__LABEL_FORMAT.getName())) { |
538 |
FontFormatHelper.setFontFormat(style.getLabelFormat(), format); |
538 |
FontFormatHelper.setFontFormat(style.getLabelFormat(), format); |
539 |
} |
539 |
} |
540 |
} |
540 |
} |
541 |
|
541 |
|
542 |
if (previousStyle.some() && previousStyle.get().getCustomFeatures().contains(ViewpointPackage.Literals.BASIC_LABEL_STYLE__LABEL_SIZE.getName())) { |
542 |
if (previousStyle.some() && previousStyle.get().getCustomFeatures().contains(ViewpointPackage.Literals.BASIC_LABEL_STYLE__LABEL_SIZE.getName())) { |
543 |
style.setLabelSize(Math.max(previousStyle.get().getLabelSize(), 1)); |
543 |
style.setLabelSize(Math.max(previousStyle.get().getLabelSize(), 1)); |
544 |
style.getCustomFeatures().add(ViewpointPackage.Literals.BASIC_LABEL_STYLE__LABEL_SIZE.getName()); |
544 |
style.getCustomFeatures().add(ViewpointPackage.Literals.BASIC_LABEL_STYLE__LABEL_SIZE.getName()); |
545 |
} else { |
545 |
} else { |
546 |
if (style.getLabelSize() != size && !style.getCustomFeatures().contains(ViewpointPackage.Literals.BASIC_LABEL_STYLE__LABEL_SIZE.getName())) { |
546 |
if (style.getLabelSize() != size && !style.getCustomFeatures().contains(ViewpointPackage.Literals.BASIC_LABEL_STYLE__LABEL_SIZE.getName())) { |
547 |
style.setLabelSize(Math.max(size, 1)); |
547 |
style.setLabelSize(Math.max(size, 1)); |
548 |
} |
548 |
} |
549 |
} |
549 |
} |
550 |
} |
550 |
} |
551 |
|
551 |
|
552 |
/** |
552 |
/** |
553 |
* Create a new container style from its description. All the variable |
553 |
* Create a new container style from its description. All the variable |
554 |
* fields are not computed during the creation. Indeed, they need a context |
554 |
* fields are not computed during the creation. Indeed, they need a context |
555 |
* that is not known at present. |
555 |
* that is not known at present. |
556 |
* |
556 |
* |
557 |
* @param description |
557 |
* @param description |
558 |
* the container style description |
558 |
* the container style description |
559 |
* @return the created style |
559 |
* @return the created style |
560 |
*/ |
560 |
*/ |
561 |
public ContainerStyle createContainerStyle(final ContainerStyleDescription description) { |
561 |
public ContainerStyle createContainerStyle(final ContainerStyleDescription description) { |
562 |
ContainerStyle style = null; |
562 |
ContainerStyle style = null; |
563 |
if (description instanceof FlatContainerStyleDescription) { |
563 |
if (description instanceof FlatContainerStyleDescription) { |
564 |
style = createFlatContainerStyle((FlatContainerStyleDescription) description); |
564 |
style = createFlatContainerStyle((FlatContainerStyleDescription) description); |
565 |
} else if (description instanceof ShapeContainerStyleDescription) { |
565 |
} else if (description instanceof ShapeContainerStyleDescription) { |
566 |
style = createShapeContainerStyle((ShapeContainerStyleDescription) description); |
566 |
style = createShapeContainerStyle((ShapeContainerStyleDescription) description); |
567 |
} else if (description instanceof WorkspaceImageDescription) { |
567 |
} else if (description instanceof WorkspaceImageDescription) { |
568 |
style = createWorkspaceImage((WorkspaceImageDescription) description); |
568 |
style = createWorkspaceImage((WorkspaceImageDescription) description); |
569 |
} |
569 |
} |
570 |
if (style != null) { |
570 |
if (style != null) { |
571 |
style.setHideLabelByDefault(description.isHideLabelByDefault()); |
571 |
style.setHideLabelByDefault(description.isHideLabelByDefault()); |
572 |
Option<Style> noPreviousStyle = Options.newNone(); |
572 |
Option<Style> noPreviousStyle = Options.newNone(); |
573 |
refreshColors(style, noPreviousStyle); |
573 |
refreshColors(style, noPreviousStyle); |
574 |
} |
574 |
} |
575 |
|
575 |
|
576 |
return style; |
576 |
return style; |
577 |
} |
577 |
} |
578 |
|
578 |
|
579 |
/** |
579 |
/** |
580 |
* @param description |
580 |
* @param description |
581 |
* @param style |
581 |
* @param style |
582 |
* @param previousStyle |
582 |
* @param previousStyle |
583 |
* Could be a NodeStyle if the style is a |
583 |
* Could be a NodeStyle if the style is a |
584 |
* WorkspaceImageDescription. This style is both a ContainerStyle |
584 |
* WorkspaceImageDescription. This style is both a ContainerStyle |
585 |
* and a NodeStyle (example we passed from a NodeStyle to a |
585 |
* and a NodeStyle (example we passed from a NodeStyle to a |
586 |
* WorkspaceImageDescription). If the style is not a |
586 |
* WorkspaceImageDescription). If the style is not a |
587 |
* WorkspaceImageDescription, the previousStyle is inevitably a |
587 |
* WorkspaceImageDescription, the previousStyle is inevitably a |
588 |
* ContainerStyle. |
588 |
* ContainerStyle. |
589 |
*/ |
589 |
*/ |
590 |
private void updateContainerStyle(final ContainerStyleDescription description, final ContainerStyle style, Option<? extends Style> previousStyle) { |
590 |
private void updateContainerStyle(final ContainerStyleDescription description, final ContainerStyle style, Option<? extends Style> previousStyle) { |
591 |
if (previousStyle.some() && previousStyle.get().getCustomFeatures().contains(ViewpointPackage.Literals.BASIC_LABEL_STYLE__SHOW_ICON.getName())) { |
591 |
if (previousStyle.some() && previousStyle.get().getCustomFeatures().contains(ViewpointPackage.Literals.BASIC_LABEL_STYLE__SHOW_ICON.getName())) { |
592 |
if (previousStyle.get() instanceof BasicLabelStyle) { |
592 |
if (previousStyle.get() instanceof BasicLabelStyle) { |
593 |
style.setShowIcon(((BasicLabelStyle) previousStyle.get()).isShowIcon()); |
593 |
style.setShowIcon(((BasicLabelStyle) previousStyle.get()).isShowIcon()); |
594 |
} |
594 |
} |
595 |
style.getCustomFeatures().add(ViewpointPackage.Literals.BASIC_LABEL_STYLE__SHOW_ICON.getName()); |
595 |
style.getCustomFeatures().add(ViewpointPackage.Literals.BASIC_LABEL_STYLE__SHOW_ICON.getName()); |
596 |
} else { |
596 |
} else { |
597 |
if (style.isShowIcon() != description.isShowIcon() && !style.getCustomFeatures().contains(ViewpointPackage.Literals.BASIC_LABEL_STYLE__SHOW_ICON.getName())) { |
597 |
if (style.isShowIcon() != description.isShowIcon() && !style.getCustomFeatures().contains(ViewpointPackage.Literals.BASIC_LABEL_STYLE__SHOW_ICON.getName())) { |
598 |
style.setShowIcon(description.isShowIcon()); |
598 |
style.setShowIcon(description.isShowIcon()); |
599 |
} |
599 |
} |
600 |
} |
600 |
} |
601 |
|
601 |
|
602 |
if (previousStyle.some() && previousStyle.get().getCustomFeatures().contains(ViewpointPackage.Literals.BASIC_LABEL_STYLE__ICON_PATH.getName())) { |
602 |
if (previousStyle.some() && previousStyle.get().getCustomFeatures().contains(ViewpointPackage.Literals.BASIC_LABEL_STYLE__ICON_PATH.getName())) { |
603 |
if (previousStyle.get() instanceof BasicLabelStyle) { |
603 |
if (previousStyle.get() instanceof BasicLabelStyle) { |
604 |
style.setIconPath(((BasicLabelStyle) previousStyle.get()).getIconPath()); |
604 |
style.setIconPath(((BasicLabelStyle) previousStyle.get()).getIconPath()); |
605 |
} |
605 |
} |
606 |
style.getCustomFeatures().add(ViewpointPackage.Literals.BASIC_LABEL_STYLE__ICON_PATH.getName()); |
606 |
style.getCustomFeatures().add(ViewpointPackage.Literals.BASIC_LABEL_STYLE__ICON_PATH.getName()); |
607 |
} else { |
607 |
} else { |
608 |
if (style.getIconPath() != null && !style.getIconPath().equals(description.getIconPath()) |
608 |
if (style.getIconPath() != null && !style.getIconPath().equals(description.getIconPath()) |
609 |
&& !style.getCustomFeatures().contains(ViewpointPackage.Literals.BASIC_LABEL_STYLE__ICON_PATH.getName())) { |
609 |
&& !style.getCustomFeatures().contains(ViewpointPackage.Literals.BASIC_LABEL_STYLE__ICON_PATH.getName())) { |
610 |
style.setIconPath(description.getIconPath()); |
610 |
style.setIconPath(description.getIconPath()); |
611 |
} |
611 |
} |
612 |
} |
612 |
} |
613 |
|
613 |
|
614 |
if (description instanceof FlatContainerStyleDescription && style instanceof FlatContainerStyle) { |
614 |
if (description instanceof FlatContainerStyleDescription && style instanceof FlatContainerStyle) { |
615 |
updateFlatContainerStyle((FlatContainerStyle) style, (FlatContainerStyleDescription) description, (Option<ContainerStyle>) previousStyle); |
615 |
updateFlatContainerStyle((FlatContainerStyle) style, (FlatContainerStyleDescription) description, (Option<ContainerStyle>) previousStyle); |
616 |
} else if (description instanceof ShapeContainerStyleDescription && style instanceof ShapeContainerStyle) { |
616 |
} else if (description instanceof ShapeContainerStyleDescription && style instanceof ShapeContainerStyle) { |
617 |
updateShapeContainerStyle((ShapeContainerStyle) style, (ShapeContainerStyleDescription) description, (Option<ContainerStyle>) previousStyle); |
617 |
updateShapeContainerStyle((ShapeContainerStyle) style, (ShapeContainerStyleDescription) description, (Option<ContainerStyle>) previousStyle); |
618 |
} else if (description instanceof WorkspaceImageDescription && style instanceof WorkspaceImage) { |
618 |
} else if (description instanceof WorkspaceImageDescription && style instanceof WorkspaceImage) { |
619 |
updateWorkspaceImage((WorkspaceImage) style, (WorkspaceImageDescription) description, previousStyle); |
619 |
updateWorkspaceImage((WorkspaceImage) style, (WorkspaceImageDescription) description, previousStyle); |
620 |
} |
620 |
} |
621 |
|
621 |
|
622 |
if (previousStyle.get() instanceof BorderedStyle) { |
622 |
if (previousStyle.get() instanceof BorderedStyle) { |
623 |
updateBorderedStyleFeatures(description, style, (Option<BorderedStyle>) previousStyle); |
623 |
updateBorderedStyleFeatures(description, style, (Option<BorderedStyle>) previousStyle); |
624 |
} else { |
624 |
} else { |
625 |
Option<BorderedStyle> noPreviousBorderedStyle = Options.newNone(); |
625 |
Option<BorderedStyle> noPreviousBorderedStyle = Options.newNone(); |
626 |
updateBorderedStyleFeatures(description, style, noPreviousBorderedStyle); |
626 |
updateBorderedStyleFeatures(description, style, noPreviousBorderedStyle); |
627 |
} |
627 |
} |
628 |
|
628 |
|
629 |
updateHideLabelCapabilityFeature(description, style, previousStyle); |
629 |
updateHideLabelCapabilityFeature(description, style, previousStyle); |
630 |
} |
630 |
} |
631 |
|
631 |
|
632 |
/** |
632 |
/** |
633 |
* Update the "Hide Label Capability" feature of the style. |
633 |
* Update the "Hide Label Capability" feature of the style. |
634 |
* |
634 |
* |
635 |
* @param description |
635 |
* @param description |
636 |
* the style description |
636 |
* the style description |
637 |
* @param style |
637 |
* @param style |
638 |
* the current style to update |
638 |
* the current style to update |
639 |
* @param previousStyle |
639 |
* @param previousStyle |
640 |
* the previous style |
640 |
* the previous style |
641 |
*/ |
641 |
*/ |
642 |
private void updateHideLabelCapabilityFeature(final HideLabelCapabilityStyleDescription description, final HideLabelCapabilityStyle style, Option<? extends Style> previousStyle) { |
642 |
private void updateHideLabelCapabilityFeature(final HideLabelCapabilityStyleDescription description, final HideLabelCapabilityStyle style, Option<? extends Style> previousStyle) { |
643 |
if (previousStyle.some() && previousStyle.get().getCustomFeatures().contains(DiagramPackage.Literals.HIDE_LABEL_CAPABILITY_STYLE__HIDE_LABEL_BY_DEFAULT.getName())) { |
643 |
if (previousStyle.some() && previousStyle.get().getCustomFeatures().contains(DiagramPackage.Literals.HIDE_LABEL_CAPABILITY_STYLE__HIDE_LABEL_BY_DEFAULT.getName())) { |
644 |
if (previousStyle.get() instanceof HideLabelCapabilityStyle) { |
644 |
if (previousStyle.get() instanceof HideLabelCapabilityStyle) { |
645 |
style.setHideLabelByDefault(((HideLabelCapabilityStyle) previousStyle.get()).isHideLabelByDefault()); |
645 |
style.setHideLabelByDefault(((HideLabelCapabilityStyle) previousStyle.get()).isHideLabelByDefault()); |
646 |
} |
646 |
} |
647 |
|
647 |
|
648 |
if (style instanceof Customizable) { |
648 |
if (style instanceof Customizable) { |
649 |
((Customizable) style).getCustomFeatures().add(DiagramPackage.Literals.HIDE_LABEL_CAPABILITY_STYLE__HIDE_LABEL_BY_DEFAULT.getName()); |
649 |
((Customizable) style).getCustomFeatures().add(DiagramPackage.Literals.HIDE_LABEL_CAPABILITY_STYLE__HIDE_LABEL_BY_DEFAULT.getName()); |
650 |
} |
650 |
} |
651 |
} else if (style instanceof Customizable && !((Customizable) style).getCustomFeatures().contains(DiagramPackage.Literals.HIDE_LABEL_CAPABILITY_STYLE__HIDE_LABEL_BY_DEFAULT.getName())) { |
651 |
} else if (style instanceof Customizable && !((Customizable) style).getCustomFeatures().contains(DiagramPackage.Literals.HIDE_LABEL_CAPABILITY_STYLE__HIDE_LABEL_BY_DEFAULT.getName())) { |
652 |
style.setHideLabelByDefault(description.isHideLabelByDefault()); |
652 |
style.setHideLabelByDefault(description.isHideLabelByDefault()); |
653 |
} |
653 |
} |
654 |
} |
654 |
} |
655 |
|
655 |
|
656 |
/** |
656 |
/** |
657 |
* Create a new node style from its description. All the variable fields are |
657 |
* Create a new node style from its description. All the variable fields are |
658 |
* not computed during the creation. Indeed, they need a context that is not |
658 |
* not computed during the creation. Indeed, they need a context that is not |
659 |
* known at present. |
659 |
* known at present. |
660 |
* |
660 |
* |
661 |
* @param description |
661 |
* @param description |
662 |
* the container style description |
662 |
* the container style description |
663 |
* @return the created style |
663 |
* @return the created style |
664 |
*/ |
664 |
*/ |
665 |
public NodeStyle createNodeStyle(final NodeStyleDescription description) { |
665 |
public NodeStyle createNodeStyle(final NodeStyleDescription description) { |
666 |
|
666 |
|
667 |
NodeStyle style = null; |
667 |
NodeStyle style = null; |
668 |
|
668 |
|
669 |
if (description instanceof CustomStyleDescription) { |
669 |
if (description instanceof CustomStyleDescription) { |
670 |
style = createCustomStyle((CustomStyleDescription) description); |
670 |
style = createCustomStyle((CustomStyleDescription) description); |
671 |
} else if (description instanceof SquareDescription) { |
671 |
} else if (description instanceof SquareDescription) { |
672 |
style = createSquare((SquareDescription) description); |
672 |
style = createSquare((SquareDescription) description); |
673 |
} else if (description instanceof DotDescription) { |
673 |
} else if (description instanceof DotDescription) { |
674 |
style = createDot((DotDescription) description); |
674 |
style = createDot((DotDescription) description); |
675 |
} else if (description instanceof GaugeCompositeStyleDescription) { |
675 |
} else if (description instanceof GaugeCompositeStyleDescription) { |
676 |
style = createGaugeCompositeStyle((GaugeCompositeStyleDescription) description); |
676 |
style = createGaugeCompositeStyle((GaugeCompositeStyleDescription) description); |
677 |
} else if (description instanceof NoteDescription) { |
677 |
} else if (description instanceof NoteDescription) { |
678 |
style = createNote((NoteDescription) description); |
678 |
style = createNote((NoteDescription) description); |
679 |
} else if (description instanceof BundledImageDescription) { |
679 |
} else if (description instanceof BundledImageDescription) { |
680 |
style = createBundledImage((BundledImageDescription) description); |
680 |
style = createBundledImage((BundledImageDescription) description); |
681 |
} else if (description instanceof WorkspaceImageDescription) { |
681 |
} else if (description instanceof WorkspaceImageDescription) { |
682 |
style = createWorkspaceImage((WorkspaceImageDescription) description); |
682 |
style = createWorkspaceImage((WorkspaceImageDescription) description); |
683 |
} else if (description instanceof EllipseNodeDescription) { |
683 |
} else if (description instanceof EllipseNodeDescription) { |
684 |
style = createEllipse((EllipseNodeDescription) description); |
684 |
style = createEllipse((EllipseNodeDescription) description); |
685 |
} else if (description instanceof LozengeNodeDescription) { |
685 |
} else if (description instanceof LozengeNodeDescription) { |
686 |
style = createLozenge((LozengeNodeDescription) description); |
686 |
style = createLozenge((LozengeNodeDescription) description); |
687 |
} |
687 |
} |
688 |
if (style != null) { |
688 |
if (style != null) { |
689 |
style.setLabelPosition(description.getLabelPosition()); |
689 |
style.setLabelPosition(description.getLabelPosition()); |
690 |
style.setHideLabelByDefault(description.isHideLabelByDefault()); |
690 |
style.setHideLabelByDefault(description.isHideLabelByDefault()); |
691 |
Option<Style> noPreviousStyle = Options.newNone(); |
691 |
Option<Style> noPreviousStyle = Options.newNone(); |
692 |
refreshColors(style, noPreviousStyle); |
692 |
refreshColors(style, noPreviousStyle); |
693 |
} |
693 |
} |
694 |
return style; |
694 |
return style; |
695 |
} |
695 |
} |
696 |
|
696 |
|
697 |
/** |
697 |
/** |
698 |
* @param description |
698 |
* @param description |
699 |
* @param style |
699 |
* @param style |
700 |
* @param previousStyle |
700 |
* @param previousStyle |
701 |
* Could be a ContainerStyle if the style is a |
701 |
* Could be a ContainerStyle if the style is a |
702 |
* WorkspaceImageDescription. This style is both a ContainerStyle |
702 |
* WorkspaceImageDescription. This style is both a ContainerStyle |
703 |
* and a NodeStyle (example we passed from a ContainerStyle to a |
703 |
* and a NodeStyle (example we passed from a ContainerStyle to a |
704 |
* WorkspaceImageDescription). If the style is not a |
704 |
* WorkspaceImageDescription). If the style is not a |
705 |
* WorkspaceImageDescription, the previousStyle is inevitably a |
705 |
* WorkspaceImageDescription, the previousStyle is inevitably a |
706 |
* NodeStyle. |
706 |
* NodeStyle. |
707 |
*/ |
707 |
*/ |
708 |
private void updateNodeStyle(final NodeStyleDescription description, final NodeStyle style, Option<? extends Style> previousStyle) { |
708 |
private void updateNodeStyle(final NodeStyleDescription description, final NodeStyle style, Option<? extends Style> previousStyle) { |
709 |
boolean brokenStyle = false; |
709 |
boolean brokenStyle = false; |
710 |
|
710 |
|
711 |
if (previousStyle.get() instanceof BasicLabelStyle) { |
711 |
if (previousStyle.get() instanceof BasicLabelStyle) { |
712 |
updateBasicLabelStyleFeatures(description, style, (Option<BasicLabelStyle>) previousStyle); |
712 |
updateBasicLabelStyleFeatures(description, style, (Option<BasicLabelStyle>) previousStyle); |
713 |
} else { |
713 |
} else { |
714 |
Option<BasicLabelStyle> noPreviousBasicLabelStyle = Options.newNone(); |
714 |
Option<BasicLabelStyle> noPreviousBasicLabelStyle = Options.newNone(); |
715 |
updateBasicLabelStyleFeatures(description, style, noPreviousBasicLabelStyle); |
715 |
updateBasicLabelStyleFeatures(description, style, noPreviousBasicLabelStyle); |
716 |
} |
716 |
} |
717 |
|
717 |
|
718 |
if (description instanceof CustomStyleDescription) { |
718 |
if (description instanceof CustomStyleDescription) { |
719 |
if (style instanceof CustomStyle) { |
719 |
if (style instanceof CustomStyle) { |
720 |
updateCustomStyle((CustomStyle) style, (CustomStyleDescription) description, (Option<NodeStyle>) previousStyle); |
720 |
updateCustomStyle((CustomStyle) style, (CustomStyleDescription) description, (Option<NodeStyle>) previousStyle); |
721 |
} else { |
721 |
} else { |
722 |
brokenStyle = true; |
722 |
brokenStyle = true; |
723 |
} |
723 |
} |
724 |
} else if (description instanceof SquareDescription) { |
724 |
} else if (description instanceof SquareDescription) { |
725 |
if (style instanceof Square) { |
725 |
if (style instanceof Square) { |
726 |
updateSquare((Square) style, (SquareDescription) description, (Option<NodeStyle>) previousStyle); |
726 |
updateSquare((Square) style, (SquareDescription) description, (Option<NodeStyle>) previousStyle); |
727 |
} else { |
727 |
} else { |
728 |
brokenStyle = true; |
728 |
brokenStyle = true; |
729 |
} |
729 |
} |
730 |
} else if (description instanceof DotDescription) { |
730 |
} else if (description instanceof DotDescription) { |
731 |
if (style instanceof Dot) { |
731 |
if (style instanceof Dot) { |
732 |
updateDot((Dot) style, (DotDescription) description, (Option<NodeStyle>) previousStyle); |
732 |
updateDot((Dot) style, (DotDescription) description, (Option<NodeStyle>) previousStyle); |
733 |
} else { |
733 |
} else { |
734 |
brokenStyle = true; |
734 |
brokenStyle = true; |
735 |
} |
735 |
} |
736 |
} else if (description instanceof GaugeCompositeStyleDescription) { |
736 |
} else if (description instanceof GaugeCompositeStyleDescription) { |
737 |
if (style instanceof GaugeCompositeStyle) { |
737 |
if (style instanceof GaugeCompositeStyle) { |
738 |
updateGaugeCompositeStyle((GaugeCompositeStyle) style, (GaugeCompositeStyleDescription) description, (Option<NodeStyle>) previousStyle); |
738 |
updateGaugeCompositeStyle((GaugeCompositeStyle) style, (GaugeCompositeStyleDescription) description, (Option<NodeStyle>) previousStyle); |
739 |
} else { |
739 |
} else { |
740 |
brokenStyle = true; |
740 |
brokenStyle = true; |
741 |
} |
741 |
} |
742 |
} else if (description instanceof NoteDescription) { |
742 |
} else if (description instanceof NoteDescription) { |
743 |
if (style instanceof Note) { |
743 |
if (style instanceof Note) { |
744 |
updateNote((Note) style, (NoteDescription) description, (Option<NodeStyle>) previousStyle); |
744 |
updateNote((Note) style, (NoteDescription) description, (Option<NodeStyle>) previousStyle); |
745 |
} else { |
745 |
} else { |
746 |
brokenStyle = true; |
746 |
brokenStyle = true; |
747 |
} |
747 |
} |
748 |
} else if (description instanceof BundledImageDescription) { |
748 |
} else if (description instanceof BundledImageDescription) { |
749 |
if (style instanceof BundledImage) { |
749 |
if (style instanceof BundledImage) { |
750 |
updateBundledImage((BundledImage) style, (BundledImageDescription) description, (Option<NodeStyle>) previousStyle); |
750 |
updateBundledImage((BundledImage) style, (BundledImageDescription) description, (Option<NodeStyle>) previousStyle); |
751 |
} else { |
751 |
} else { |
752 |
brokenStyle = true; |
752 |
brokenStyle = true; |
753 |
} |
753 |
} |
754 |
} else if (description instanceof WorkspaceImageDescription) { |
754 |
} else if (description instanceof WorkspaceImageDescription) { |
755 |
if (style instanceof WorkspaceImage) { |
755 |
if (style instanceof WorkspaceImage) { |
756 |
updateWorkspaceImage((WorkspaceImage) style, (WorkspaceImageDescription) description, previousStyle); |
756 |
updateWorkspaceImage((WorkspaceImage) style, (WorkspaceImageDescription) description, previousStyle); |
757 |
} else { |
757 |
} else { |
758 |
brokenStyle = true; |
758 |
brokenStyle = true; |
759 |
} |
759 |
} |
760 |
} else if (description instanceof EllipseNodeDescription) { |
760 |
} else if (description instanceof EllipseNodeDescription) { |
761 |
if (style instanceof Ellipse) { |
761 |
if (style instanceof Ellipse) { |
762 |
updateEllipse((Ellipse) style, (EllipseNodeDescription) description, (Option<NodeStyle>) previousStyle); |
762 |
updateEllipse((Ellipse) style, (EllipseNodeDescription) description, (Option<NodeStyle>) previousStyle); |
763 |
} else { |
763 |
} else { |
764 |
brokenStyle = true; |
764 |
brokenStyle = true; |
765 |
} |
765 |
} |
766 |
} else if (description instanceof LozengeNodeDescription) { |
766 |
} else if (description instanceof LozengeNodeDescription) { |
767 |
if (style instanceof Lozenge) { |
767 |
if (style instanceof Lozenge) { |
768 |
updateLozenge((Lozenge) style, (LozengeNodeDescription) description, (Option<NodeStyle>) previousStyle); |
768 |
updateLozenge((Lozenge) style, (LozengeNodeDescription) description, (Option<NodeStyle>) previousStyle); |
769 |
} else { |
769 |
} else { |
770 |
brokenStyle = true; |
770 |
brokenStyle = true; |
771 |
} |
771 |
} |
772 |
} |
772 |
} |
773 |
if (brokenStyle && style.eContainer() instanceof AbstractDNode) { |
773 |
if (brokenStyle && style.eContainer() instanceof AbstractDNode) { |
774 |
EObject copy = EcoreUtil.copy(createNodeStyle(description)); |
774 |
EObject copy = EcoreUtil.copy(createNodeStyle(description)); |
775 |
final NodeStyle newStyle = (NodeStyle) copy; |
775 |
final NodeStyle newStyle = (NodeStyle) copy; |
776 |
affectStyle((AbstractDNode) style.eContainer(), newStyle); |
776 |
affectStyle((AbstractDNode) style.eContainer(), newStyle); |
777 |
} |
777 |
} |
778 |
|
778 |
|
779 |
if (previousStyle.get() instanceof BorderedStyle) { |
779 |
if (previousStyle.get() instanceof BorderedStyle) { |
780 |
updateBorderedStyleFeatures(description, style, (Option<BorderedStyle>) previousStyle); |
780 |
updateBorderedStyleFeatures(description, style, (Option<BorderedStyle>) previousStyle); |
781 |
} else { |
781 |
} else { |
782 |
Option<BorderedStyle> noPreviousBorderedStyle = Options.newNone(); |
782 |
Option<BorderedStyle> noPreviousBorderedStyle = Options.newNone(); |
783 |
updateBorderedStyleFeatures(description, style, noPreviousBorderedStyle); |
783 |
updateBorderedStyleFeatures(description, style, noPreviousBorderedStyle); |
784 |
} |
784 |
} |
785 |
|
785 |
|
786 |
if (previousStyle.some() && previousStyle.get().getCustomFeatures().contains(DiagramPackage.Literals.NODE_STYLE__LABEL_POSITION.getName())) { |
786 |
if (previousStyle.some() && previousStyle.get().getCustomFeatures().contains(DiagramPackage.Literals.NODE_STYLE__LABEL_POSITION.getName())) { |
787 |
if (previousStyle.get() instanceof NodeStyle) { |
787 |
if (previousStyle.get() instanceof NodeStyle) { |
788 |
style.setLabelPosition(((NodeStyle) previousStyle.get()).getLabelPosition()); |
788 |
style.setLabelPosition(((NodeStyle) previousStyle.get()).getLabelPosition()); |
789 |
} |
789 |
} |
790 |
style.getCustomFeatures().add(DiagramPackage.Literals.NODE_STYLE__LABEL_POSITION.getName()); |
790 |
style.getCustomFeatures().add(DiagramPackage.Literals.NODE_STYLE__LABEL_POSITION.getName()); |
791 |
} else { |
791 |
} else { |
792 |
if (!style.getCustomFeatures().contains(DiagramPackage.Literals.NODE_STYLE__LABEL_POSITION.getName())) { |
792 |
if (!style.getCustomFeatures().contains(DiagramPackage.Literals.NODE_STYLE__LABEL_POSITION.getName())) { |
793 |
style.setLabelPosition(description.getLabelPosition()); |
793 |
style.setLabelPosition(description.getLabelPosition()); |
794 |
} |
794 |
} |
795 |
} |
795 |
} |
796 |
|
796 |
|
797 |
updateHideLabelCapabilityFeature(description, style, previousStyle); |
797 |
updateHideLabelCapabilityFeature(description, style, previousStyle); |
798 |
} |
798 |
} |
799 |
|
799 |
|
800 |
/** |
800 |
/** |
801 |
* @param description |
801 |
* @param description |
802 |
* @param style |
802 |
* @param style |
803 |
* @param previousStyle |
803 |
* @param previousStyle |
804 |
*/ |
804 |
*/ |
805 |
private void updateBorderedStyleFeatures(BorderedStyleDescription description, BorderedStyle style, Option<BorderedStyle> previousStyle) { |
805 |
private void updateBorderedStyleFeatures(BorderedStyleDescription description, BorderedStyle style, Option<BorderedStyle> previousStyle) { |
806 |
if (previousStyle.some() && previousStyle.get().getCustomFeatures().contains(DiagramPackage.Literals.BORDERED_STYLE__BORDER_SIZE.getName())) { |
806 |
if (previousStyle.some() && previousStyle.get().getCustomFeatures().contains(DiagramPackage.Literals.BORDERED_STYLE__BORDER_SIZE.getName())) { |
807 |
style.setBorderSize(previousStyle.get().getBorderSize()); |
807 |
style.setBorderSize(previousStyle.get().getBorderSize()); |
808 |
style.getCustomFeatures().add(DiagramPackage.Literals.BORDERED_STYLE__BORDER_SIZE.getName()); |
808 |
style.getCustomFeatures().add(DiagramPackage.Literals.BORDERED_STYLE__BORDER_SIZE.getName()); |
809 |
} else { |
809 |
} else { |
810 |
if (style.eContainer() instanceof AbstractDNode && style.getBorderSizeComputationExpression() != null |
810 |
if (style.eContainer() instanceof AbstractDNode && style.getBorderSizeComputationExpression() != null |
811 |
&& !style.getCustomFeatures().contains(DiagramPackage.Literals.BORDERED_STYLE__BORDER_SIZE.getName())) { |
811 |
&& !style.getCustomFeatures().contains(DiagramPackage.Literals.BORDERED_STYLE__BORDER_SIZE.getName())) { |
812 |
try { |
812 |
try { |
813 |
style.setBorderSize(interpreter.evaluateInteger(((AbstractDNode) style.eContainer()).getTarget(), description.getBorderSizeComputationExpression())); |
813 |
style.setBorderSize(interpreter.evaluateInteger(((AbstractDNode) style.eContainer()).getTarget(), description.getBorderSizeComputationExpression())); |
814 |
} catch (final EvaluationException e) { |
814 |
} catch (final EvaluationException e) { |
815 |
RuntimeLoggerManager.INSTANCE.error(description, StylePackage.eINSTANCE.getBorderedStyleDescription_BorderSizeComputationExpression(), e); |
815 |
RuntimeLoggerManager.INSTANCE.error(description, StylePackage.eINSTANCE.getBorderedStyleDescription_BorderSizeComputationExpression(), e); |
816 |
} |
816 |
} |
817 |
} |
817 |
} |
818 |
} |
818 |
} |
819 |
|
819 |
|
820 |
if (previousStyle.some() && previousStyle.get().getCustomFeatures().contains(DiagramPackage.Literals.BORDERED_STYLE__BORDER_SIZE_COMPUTATION_EXPRESSION.getName())) { |
820 |
if (previousStyle.some() && previousStyle.get().getCustomFeatures().contains(DiagramPackage.Literals.BORDERED_STYLE__BORDER_SIZE_COMPUTATION_EXPRESSION.getName())) { |
821 |
style.setBorderSizeComputationExpression(previousStyle.get().getBorderSizeComputationExpression()); |
821 |
style.setBorderSizeComputationExpression(previousStyle.get().getBorderSizeComputationExpression()); |
822 |
style.getCustomFeatures().add(DiagramPackage.Literals.BORDERED_STYLE__BORDER_SIZE_COMPUTATION_EXPRESSION.getName()); |
822 |
style.getCustomFeatures().add(DiagramPackage.Literals.BORDERED_STYLE__BORDER_SIZE_COMPUTATION_EXPRESSION.getName()); |
823 |
} else { |
823 |
} else { |
824 |
if (!style.getBorderSizeComputationExpression().equals(description.getBorderSizeComputationExpression()) |
824 |
if (!style.getBorderSizeComputationExpression().equals(description.getBorderSizeComputationExpression()) |
825 |
&& !style.getCustomFeatures().contains(DiagramPackage.Literals.BORDERED_STYLE__BORDER_SIZE_COMPUTATION_EXPRESSION.getName())) { |
825 |
&& !style.getCustomFeatures().contains(DiagramPackage.Literals.BORDERED_STYLE__BORDER_SIZE_COMPUTATION_EXPRESSION.getName())) { |
826 |
style.setBorderSizeComputationExpression(description.getBorderSizeComputationExpression()); |
826 |
style.setBorderSizeComputationExpression(description.getBorderSizeComputationExpression()); |
827 |
} |
827 |
} |
828 |
} |
828 |
} |
829 |
|
829 |
|
830 |
if (previousStyle.some() && previousStyle.get().getCustomFeatures().contains(DiagramPackage.Literals.BORDERED_STYLE__BORDER_LINE_STYLE.getName())) { |
830 |
if (previousStyle.some() && previousStyle.get().getCustomFeatures().contains(DiagramPackage.Literals.BORDERED_STYLE__BORDER_LINE_STYLE.getName())) { |
831 |
style.setBorderLineStyle(previousStyle.get().getBorderLineStyle()); |
831 |
style.setBorderLineStyle(previousStyle.get().getBorderLineStyle()); |
832 |
style.getCustomFeatures().add(DiagramPackage.Literals.BORDERED_STYLE__BORDER_LINE_STYLE.getName()); |
832 |
style.getCustomFeatures().add(DiagramPackage.Literals.BORDERED_STYLE__BORDER_LINE_STYLE.getName()); |
833 |
} else { |
833 |
} else { |
834 |
if (!style.getBorderLineStyle().equals(description.getBorderLineStyle()) && !style.getCustomFeatures().contains(DiagramPackage.Literals.BORDERED_STYLE__BORDER_LINE_STYLE.getName())) { |
834 |
if (!style.getBorderLineStyle().equals(description.getBorderLineStyle()) && !style.getCustomFeatures().contains(DiagramPackage.Literals.BORDERED_STYLE__BORDER_LINE_STYLE.getName())) { |
835 |
style.setBorderLineStyle(description.getBorderLineStyle()); |
835 |
style.setBorderLineStyle(description.getBorderLineStyle()); |
836 |
} |
836 |
} |
837 |
} |
837 |
} |
838 |
} |
838 |
} |
839 |
|
839 |
|
840 |
private void affectStyle(final AbstractDNode container, final NodeStyle newStyle) { |
840 |
private void affectStyle(final AbstractDNode container, final NodeStyle newStyle) { |
841 |
final DiagramSwitch<?> sw = new DiagramSwitch<Object>() { |
841 |
final DiagramSwitch<?> sw = new DiagramSwitch<Object>() { |
842 |
|
842 |
|
843 |
@Override |
843 |
@Override |
844 |
public Object caseDNode(final DNode object) { |
844 |
public Object caseDNode(final DNode object) { |
845 |
object.setOwnedStyle(newStyle); |
845 |
object.setOwnedStyle(newStyle); |
846 |
return super.caseDNode(object); |
846 |
return super.caseDNode(object); |
847 |
} |
847 |
} |
848 |
|
848 |
|
849 |
@Override |
849 |
@Override |
850 |
public Object caseDNodeListElement(final DNodeListElement object) { |
850 |
public Object caseDNodeListElement(final DNodeListElement object) { |
851 |
object.setOwnedStyle(newStyle); |
851 |
object.setOwnedStyle(newStyle); |
852 |
return super.caseDNodeListElement(object); |
852 |
return super.caseDNodeListElement(object); |
853 |
} |
853 |
} |
854 |
|
854 |
|
855 |
}; |
855 |
}; |
856 |
sw.doSwitch(container); |
856 |
sw.doSwitch(container); |
857 |
} |
857 |
} |
858 |
|
858 |
|
859 |
private FlatContainerStyle createFlatContainerStyle(final FlatContainerStyleDescription description) { |
859 |
private FlatContainerStyle createFlatContainerStyle(final FlatContainerStyleDescription description) { |
860 |
final FlatContainerStyle style = DiagramFactory.eINSTANCE.createFlatContainerStyle(); |
860 |
final FlatContainerStyle style = DiagramFactory.eINSTANCE.createFlatContainerStyle(); |
861 |
Option<ContainerStyle> noPreviousStyle = Options.newNone(); |
861 |
Option<ContainerStyle> noPreviousStyle = Options.newNone(); |
862 |
updateFlatContainerStyle(style, description, noPreviousStyle); |
862 |
updateFlatContainerStyle(style, description, noPreviousStyle); |
863 |
return style; |
863 |
return style; |
864 |
} |
864 |
} |
865 |
|
865 |
|
866 |
private void updateFlatContainerStyle(final FlatContainerStyle style, final FlatContainerStyleDescription description, Option<ContainerStyle> previousStyle) { |
866 |
private void updateFlatContainerStyle(final FlatContainerStyle style, final FlatContainerStyleDescription description, Option<ContainerStyle> previousStyle) { |
867 |
if (style.getDescription() != description) { |
867 |
if (style.getDescription() != description) { |
868 |
style.setDescription(description); |
868 |
style.setDescription(description); |
869 |
} |
869 |
} |
870 |
|
870 |
|
871 |
if (previousStyle.some() && previousStyle.get().getCustomFeatures().contains(DiagramPackage.Literals.FLAT_CONTAINER_STYLE__BACKGROUND_STYLE.getName()) |
871 |
if (previousStyle.some() && previousStyle.get().getCustomFeatures().contains(DiagramPackage.Literals.FLAT_CONTAINER_STYLE__BACKGROUND_STYLE.getName()) |
872 |
&& previousStyle.get() instanceof FlatContainerStyle) { |
872 |
&& previousStyle.get() instanceof FlatContainerStyle) { |
873 |
style.setBackgroundStyle(((FlatContainerStyle) previousStyle.get()).getBackgroundStyle()); |
873 |
style.setBackgroundStyle(((FlatContainerStyle) previousStyle.get()).getBackgroundStyle()); |
874 |
style.getCustomFeatures().add(DiagramPackage.Literals.FLAT_CONTAINER_STYLE__BACKGROUND_STYLE.getName()); |
874 |
style.getCustomFeatures().add(DiagramPackage.Literals.FLAT_CONTAINER_STYLE__BACKGROUND_STYLE.getName()); |
875 |
} else { |
875 |
} else { |
876 |
if (style.getBackgroundStyle().getValue() != description.getBackgroundStyle().getValue() |
876 |
if (style.getBackgroundStyle().getValue() != description.getBackgroundStyle().getValue() |
877 |
&& !style.getCustomFeatures().contains(DiagramPackage.Literals.FLAT_CONTAINER_STYLE__BACKGROUND_STYLE.getName())) { |
877 |
&& !style.getCustomFeatures().contains(DiagramPackage.Literals.FLAT_CONTAINER_STYLE__BACKGROUND_STYLE.getName())) { |
878 |
style.setBackgroundStyle(description.getBackgroundStyle()); |
878 |
style.setBackgroundStyle(description.getBackgroundStyle()); |
879 |
} |
879 |
} |
880 |
} |
880 |
} |
881 |
|
881 |
|
882 |
updateLabelStyleFeatures(description, style, previousStyle); |
882 |
updateLabelStyleFeatures(description, style, previousStyle); |
883 |
if (style.eContainer() instanceof DDiagramElementContainer) { |
883 |
if (style.eContainer() instanceof DDiagramElementContainer) { |
884 |
setComputedSize((DDiagramElementContainer) style.eContainer(), description); |
884 |
setComputedSize((DDiagramElementContainer) style.eContainer(), description); |
885 |
} |
885 |
} |
886 |
} |
886 |
} |
887 |
|
887 |
|
888 |
private ShapeContainerStyle createShapeContainerStyle(final ShapeContainerStyleDescription description) { |
888 |
private ShapeContainerStyle createShapeContainerStyle(final ShapeContainerStyleDescription description) { |
889 |
final ShapeContainerStyle style = DiagramFactory.eINSTANCE.createShapeContainerStyle(); |
889 |
final ShapeContainerStyle style = DiagramFactory.eINSTANCE.createShapeContainerStyle(); |
890 |
Option<ContainerStyle> noPreviousStyle = Options.newNone(); |
890 |
Option<ContainerStyle> noPreviousStyle = Options.newNone(); |
891 |
updateShapeContainerStyle(style, description, noPreviousStyle); |
891 |
updateShapeContainerStyle(style, description, noPreviousStyle); |
892 |
return style; |
892 |
return style; |
893 |
} |
893 |
} |
894 |
|
894 |
|
895 |
private void updateShapeContainerStyle(final ShapeContainerStyle style, final ShapeContainerStyleDescription description, Option<ContainerStyle> previousStyle) { |
895 |
private void updateShapeContainerStyle(final ShapeContainerStyle style, final ShapeContainerStyleDescription description, Option<ContainerStyle> previousStyle) { |
896 |
if (style.getDescription() != description) { |
896 |
if (style.getDescription() != description) { |
897 |
style.setDescription(description); |
897 |
style.setDescription(description); |
898 |
} |
898 |
} |
899 |
|
899 |
|
900 |
updateLabelStyleFeatures(description, style, previousStyle); |
900 |
updateLabelStyleFeatures(description, style, previousStyle); |
901 |
|
901 |
|
902 |
if (previousStyle.some() && previousStyle.get().getCustomFeatures().contains(DiagramPackage.Literals.SHAPE_CONTAINER_STYLE__SHAPE.getName()) |
902 |
if (previousStyle.some() && previousStyle.get().getCustomFeatures().contains(DiagramPackage.Literals.SHAPE_CONTAINER_STYLE__SHAPE.getName()) |
903 |
&& previousStyle.get() instanceof ShapeContainerStyle) { |
903 |
&& previousStyle.get() instanceof ShapeContainerStyle) { |
904 |
style.setShape(((ShapeContainerStyle) previousStyle.get()).getShape()); |
904 |
style.setShape(((ShapeContainerStyle) previousStyle.get()).getShape()); |
905 |
style.getCustomFeatures().add(DiagramPackage.Literals.SHAPE_CONTAINER_STYLE__SHAPE.getName()); |
905 |
style.getCustomFeatures().add(DiagramPackage.Literals.SHAPE_CONTAINER_STYLE__SHAPE.getName()); |
906 |
} else { |
906 |
} else { |
907 |
if (style.getShape().getValue() != description.getShape().getValue() && !style.getCustomFeatures().contains(DiagramPackage.Literals.SHAPE_CONTAINER_STYLE__SHAPE.getName())) { |
907 |
if (style.getShape().getValue() != description.getShape().getValue() && !style.getCustomFeatures().contains(DiagramPackage.Literals.SHAPE_CONTAINER_STYLE__SHAPE.getName())) { |
908 |
style.setShape(description.getShape()); |
908 |
style.setShape(description.getShape()); |
909 |
} |
909 |
} |
910 |
} |
910 |
} |
911 |
|
911 |
|
912 |
if (style.eContainer() instanceof DDiagramElementContainer) { |
912 |
if (style.eContainer() instanceof DDiagramElementContainer) { |
913 |
setComputedSize((DDiagramElementContainer) style.eContainer(), description); |
913 |
setComputedSize((DDiagramElementContainer) style.eContainer(), description); |
914 |
} |
914 |
} |
915 |
|
915 |
|
916 |
} |
916 |
} |
917 |
|
917 |
|
918 |
private void setComputedSize(DDiagramElementContainer container, SizeComputationContainerStyleDescription style) { |
918 |
private void setComputedSize(DDiagramElementContainer container, SizeComputationContainerStyleDescription style) { |
919 |
if (style != null) { |
919 |
if (style != null) { |
920 |
Integer computedWidth = computeExpressions(container.getTarget(), style, StylePackage.eINSTANCE.getSizeComputationContainerStyleDescription_WidthComputationExpression()); |
920 |
Integer computedWidth = computeExpressions(container.getTarget(), style, StylePackage.eINSTANCE.getSizeComputationContainerStyleDescription_WidthComputationExpression()); |
921 |
Integer computedHeight = computeExpressions(container.getTarget(), style, StylePackage.eINSTANCE.getSizeComputationContainerStyleDescription_HeightComputationExpression()); |
921 |
Integer computedHeight = computeExpressions(container.getTarget(), style, StylePackage.eINSTANCE.getSizeComputationContainerStyleDescription_HeightComputationExpression()); |
922 |
safeSetComputedSize(container, computedWidth, computedHeight); |
922 |
safeSetComputedSize(container, computedWidth, computedHeight); |
923 |
} |
923 |
} |
924 |
} |
924 |
} |
925 |
|
925 |
|
926 |
private void safeSetComputedSize(DDiagramElementContainer container, Integer computedWidth, Integer computedHeight) { |
926 |
private void safeSetComputedSize(DDiagramElementContainer container, Integer computedWidth, Integer computedHeight) { |
927 |
if (featureCanBeSet(computedWidth, container, DiagramPackage.eINSTANCE.getDDiagramElementContainer_Width()) && !computedWidth.equals(container.getWidth())) { |
927 |
if (featureCanBeSet(computedWidth, container, DiagramPackage.eINSTANCE.getDDiagramElementContainer_Width()) && !computedWidth.equals(container.getWidth())) { |
928 |
container.setWidth(computedWidth); |
928 |
container.setWidth(computedWidth); |
929 |
} |
929 |
} |
930 |
if (featureCanBeSet(computedHeight, container, DiagramPackage.eINSTANCE.getDDiagramElementContainer_Height()) && !computedHeight.equals(container.getHeight())) { |
930 |
if (featureCanBeSet(computedHeight, container, DiagramPackage.eINSTANCE.getDDiagramElementContainer_Height()) && !computedHeight.equals(container.getHeight())) { |
931 |
container.setHeight(computedHeight); |
931 |
container.setHeight(computedHeight); |
932 |
} |
932 |
} |
933 |
|
933 |
|
934 |
} |
934 |
} |
935 |
|
935 |
|
936 |
/** |
936 |
/** |
937 |
* To avoid abusive dirty because of the new "width" and "height" attributes |
937 |
* To avoid abusive dirty because of the new "width" and "height" attributes |
938 |
* on {@link DDiagramElementContainer}, we have to check whether the VSM |
938 |
* on {@link DDiagramElementContainer}, we have to check whether the VSM |
939 |
* width and height computation expression are different of the default |
939 |
* width and height computation expression are different of the default |
940 |
* value (-1) before to set them. By default, if the width or height |
940 |
* value (-1) before to set them. By default, if the width or height |
941 |
* features are unset, we keep the same auto-size behavior than before. |
941 |
* features are unset, we keep the same auto-size behavior than before. |
942 |
* |
942 |
* |
943 |
* @param value |
943 |
* @param value |
944 |
* the value, already evaluated. |
944 |
* the value, already evaluated. |
945 |
* @param container |
945 |
* @param container |
946 |
* the {@link DDiagramElementContainer} to set width and height. |
946 |
* the {@link DDiagramElementContainer} to set width and height. |
947 |
* @param feature |
947 |
* @param feature |
948 |
* the concerned feature (width or height). |
948 |
* the concerned feature (width or height). |
949 |
* @return true if the feature can be set otherwise false. |
949 |
* @return true if the feature can be set otherwise false. |
950 |
*/ |
950 |
*/ |
951 |
private boolean featureCanBeSet(Integer value, DDiagramElementContainer container, EStructuralFeature feature) { |
951 |
private boolean featureCanBeSet(Integer value, DDiagramElementContainer container, EStructuralFeature feature) { |
952 |
boolean returnValue = false; |
952 |
boolean returnValue = false; |
953 |
|
953 |
|
954 |
// if the feature has already been set we can set it without verify if |
954 |
// if the feature has already been set we can set it without verify if |
955 |
// we have the VSM default value. |
955 |
// we have the VSM default value. |
956 |
if (container.eIsSet(feature)) { |
956 |
if (container.eIsSet(feature)) { |
957 |
returnValue = true; |
957 |
returnValue = true; |
958 |
} else if (value.intValue() > 0) { |
958 |
} else if (value.intValue() > 0) { |
959 |
returnValue = true; |
959 |
returnValue = true; |
960 |
|
960 |
|
961 |
} |
961 |
} |
962 |
return returnValue; |
962 |
return returnValue; |
963 |
} |
963 |
} |
964 |
|
964 |
|
965 |
private Integer computeExpressions(EObject target, SizeComputationContainerStyleDescription description, EStructuralFeature feature) { |
965 |
private Integer computeExpressions(EObject target, SizeComputationContainerStyleDescription description, EStructuralFeature feature) { |
966 |
Integer size = null; |
966 |
Integer size = null; |
967 |
Object expression = description.eGet(feature); |
967 |
Object expression = description.eGet(feature); |
968 |
if (expression instanceof String && !StringUtil.isEmpty((String) expression) && !((String) expression).equals("-1")) { //$NON-NLS-1$ |
968 |
if (expression instanceof String && !StringUtil.isEmpty((String) expression) && !((String) expression).equals("-1")) { //$NON-NLS-1$ |
969 |
try { |
969 |
try { |
970 |
size = interpreter.evaluateInteger(target, (String) expression); |
970 |
size = interpreter.evaluateInteger(target, (String) expression); |
971 |
if (size == null) { |
971 |
if (size == null) { |
972 |
size = AUTO_SIZE_CONTAINER; |
972 |
size = AUTO_SIZE_CONTAINER; |
973 |
} |
973 |
} |
974 |
|
974 |
|
975 |
} catch (EvaluationException e) { |
975 |
} catch (EvaluationException e) { |
976 |
// do nothing |
976 |
// do nothing |
977 |
} |
977 |
} |
978 |
} else { |
978 |
} else { |
979 |
size = AUTO_SIZE_CONTAINER; |
979 |
size = AUTO_SIZE_CONTAINER; |
980 |
} |
980 |
} |
981 |
return size; |
981 |
return size; |
982 |
|
982 |
|
983 |
} |
983 |
} |
984 |
|
984 |
|
985 |
private WorkspaceImage createWorkspaceImage(final WorkspaceImageDescription description) { |
985 |
private WorkspaceImage createWorkspaceImage(final WorkspaceImageDescription description) { |
986 |
final WorkspaceImage image = DiagramFactory.eINSTANCE.createWorkspaceImage(); |
986 |
final WorkspaceImage image = DiagramFactory.eINSTANCE.createWorkspaceImage(); |
987 |
Option<ContainerStyle> noPreviousStyle = Options.newNone(); |
987 |
Option<ContainerStyle> noPreviousStyle = Options.newNone(); |
988 |
updateWorkspaceImage(image, description, noPreviousStyle); |
988 |
updateWorkspaceImage(image, description, noPreviousStyle); |
989 |
return image; |
989 |
return image; |
990 |
} |
990 |
} |
991 |
|
991 |
|
992 |
private void updateWorkspaceImage(final WorkspaceImage image, final WorkspaceImageDescription description, Option<? extends Style> previousStyle) { |
992 |
private void updateWorkspaceImage(final WorkspaceImage image, final WorkspaceImageDescription description, Option<? extends Style> previousStyle) { |
993 |
if (image.getDescription() != description) { |
993 |
if (image.getDescription() != description) { |
994 |
image.setDescription(description); |
994 |
image.setDescription(description); |
995 |
} |
995 |
} |
996 |
|
996 |
|
997 |
if (!previousStyle.some() || (previousStyle.some() && previousStyle.get() instanceof LabelStyle)) { |
997 |
if (!previousStyle.some() || (previousStyle.some() && previousStyle.get() instanceof LabelStyle)) { |
998 |
updateLabelStyleFeatures(description, image, (Option<LabelStyle>) previousStyle); |
998 |
updateLabelStyleFeatures(description, image, (Option<LabelStyle>) previousStyle); |
999 |
} |
999 |
} |
1000 |
|
1000 |
|
1001 |
if (previousStyle.some() && previousStyle.get().getCustomFeatures().contains(DiagramPackage.Literals.WORKSPACE_IMAGE__WORKSPACE_PATH.getName()) |
1001 |
if (previousStyle.some() && previousStyle.get().getCustomFeatures().contains(DiagramPackage.Literals.WORKSPACE_IMAGE__WORKSPACE_PATH.getName()) |
1002 |
&& previousStyle.get() instanceof WorkspaceImage) { |
1002 |
&& previousStyle.get() instanceof WorkspaceImage) { |
1003 |
image.setWorkspacePath(((WorkspaceImage) previousStyle.get()).getWorkspacePath()); |
1003 |
image.setWorkspacePath(((WorkspaceImage) previousStyle.get()).getWorkspacePath()); |
1004 |
image.getCustomFeatures().add(DiagramPackage.Literals.WORKSPACE_IMAGE__WORKSPACE_PATH.getName()); |
1004 |
image.getCustomFeatures().add(DiagramPackage.Literals.WORKSPACE_IMAGE__WORKSPACE_PATH.getName()); |
1005 |
} else { |
1005 |
} else { |
1006 |
if (image.getWorkspacePath() == null || !image.getWorkspacePath().equals(description.getWorkspacePath()) |
1006 |
if (image.getWorkspacePath() == null || !image.getWorkspacePath().equals(description.getWorkspacePath()) |
1007 |
&& !image.getCustomFeatures().contains(DiagramPackage.Literals.WORKSPACE_IMAGE__WORKSPACE_PATH.getName())) { |
1007 |
&& !image.getCustomFeatures().contains(DiagramPackage.Literals.WORKSPACE_IMAGE__WORKSPACE_PATH.getName())) { |
1008 |
image.setWorkspacePath(description.getWorkspacePath()); |
1008 |
image.setWorkspacePath(description.getWorkspacePath()); |
1009 |
} |
1009 |
} |
1010 |
} |
1010 |
} |
1011 |
|
1011 |
|
1012 |
// handle image size |
1012 |
// handle image size |
1013 |
if (image.eContainer() instanceof DNode && description.getSizeComputationExpression() != null) { |
1013 |
if ((image.eContainer() instanceof DNode || image.eContainer() instanceof DDiagramElementContainer) && description.getSizeComputationExpression() != null) { |
1014 |
final DNode node = (DNode) image.eContainer(); |
1014 |
if(image.eContainer() instanceof DNode){ |
1015 |
Integer size = computeStyleSize(node.getTarget(), description); |
1015 |
final DNode node = (DNode) image.eContainer(); |
1016 |
if (size.intValue() == -1) { |
1016 |
Integer size = computeStyleSize(node.getTarget(), description); |
1017 |
// real image size |
1017 |
if (size.intValue() == -1) { |
1018 |
node.setHeight(size); |
1018 |
// real image size |
1019 |
node.setWidth(size); |
1019 |
node.setHeight(size); |
1020 |
} else { |
1020 |
node.setWidth(size); |
1021 |
safeSetComputedSize(node, size); |
1021 |
} else { |
1022 |
} |
1022 |
safeSetComputedSize(node, size); |
1023 |
} |
1023 |
} |
1024 |
} |
1024 |
} else if(image.eContainer() instanceof DDiagramElementContainer){ |
1025 |
|
1025 |
final DDiagramElementContainer container = (DDiagramElementContainer) image.eContainer(); |
1026 |
private BundledImage createBundledImage(final BundledImageDescription description) { |
1026 |
Integer size = computeStyleSize(container.getTarget(), description); |
1027 |
final BundledImage image = DiagramFactory.eINSTANCE.createBundledImage(); |
1027 |
if (size.intValue() == -1) { |
1028 |
Option<NodeStyle> noPreviousStyle = Options.newNone(); |
1028 |
// real image size |
1029 |
updateBundledImage(image, description, noPreviousStyle); |
1029 |
container.setHeight(size); |
1030 |
return image; |
1030 |
container.setWidth(size); |
1031 |
} |
1031 |
} else { |
1032 |
|
1032 |
safeSetComputedSizeForContainer(container, size); |
1033 |
private void updateBundledImage(final BundledImage image, final BundledImageDescription description, Option<NodeStyle> previousStyle) { |
1033 |
} |
1034 |
if (image.getDescription() != description) { |
1034 |
} |
1035 |
image.setDescription(description); |
1035 |
} |
1036 |
} |
1036 |
} |
1037 |
|
1037 |
|
1038 |
updateLabelStyleFeatures(description, image, previousStyle); |
1038 |
private BundledImage createBundledImage(final BundledImageDescription description) { |
1039 |
|
1039 |
final BundledImage image = DiagramFactory.eINSTANCE.createBundledImage(); |
1040 |
if (previousStyle.some() && previousStyle.get().getCustomFeatures().contains(DiagramPackage.Literals.BUNDLED_IMAGE__SHAPE.getName()) && previousStyle.get() instanceof BundledImage) { |
1040 |
Option<NodeStyle> noPreviousStyle = Options.newNone(); |
1041 |
image.setShape(((BundledImage) previousStyle.get()).getShape()); |
1041 |
updateBundledImage(image, description, noPreviousStyle); |
1042 |
image.getCustomFeatures().add(DiagramPackage.Literals.BUNDLED_IMAGE__SHAPE.getName()); |
1042 |
return image; |
1043 |
} else { |
1043 |
} |
1044 |
if (image.getShape().getValue() != description.getShape().getValue() && !image.getCustomFeatures().contains(DiagramPackage.Literals.BUNDLED_IMAGE__SHAPE.getName())) { |
1044 |
|
1045 |
image.setShape(description.getShape()); |
1045 |
private void updateBundledImage(final BundledImage image, final BundledImageDescription description, Option<NodeStyle> previousStyle) { |
1046 |
} |
1046 |
if (image.getDescription() != description) { |
1047 |
} |
1047 |
image.setDescription(description); |
1048 |
} |
1048 |
} |
1049 |
|
1049 |
|
1050 |
private Note createNote(final NoteDescription description) { |
1050 |
updateLabelStyleFeatures(description, image, previousStyle); |
1051 |
final Note style = DiagramFactory.eINSTANCE.createNote(); |
1051 |
|
1052 |
Option<NodeStyle> noPreviousStyle = Options.newNone(); |
1052 |
if (previousStyle.some() && previousStyle.get().getCustomFeatures().contains(DiagramPackage.Literals.BUNDLED_IMAGE__SHAPE.getName()) && previousStyle.get() instanceof BundledImage) { |
1053 |
updateNote(style, description, noPreviousStyle); |
1053 |
image.setShape(((BundledImage) previousStyle.get()).getShape()); |
1054 |
return style; |
1054 |
image.getCustomFeatures().add(DiagramPackage.Literals.BUNDLED_IMAGE__SHAPE.getName()); |
1055 |
} |
1055 |
} else { |
1056 |
|
1056 |
if (image.getShape().getValue() != description.getShape().getValue() && !image.getCustomFeatures().contains(DiagramPackage.Literals.BUNDLED_IMAGE__SHAPE.getName())) { |
1057 |
private void updateNote(final Note style, final NoteDescription description, Option<NodeStyle> previousStyle) { |
1057 |
image.setShape(description.getShape()); |
1058 |
if (style.getDescription() != description) { |
1058 |
} |
1059 |
style.setDescription(description); |
1059 |
} |
1060 |
} |
1060 |
} |
1061 |
|
1061 |
|
1062 |
updateLabelStyleFeatures(description, style, previousStyle); |
1062 |
private Note createNote(final NoteDescription description) { |
1063 |
} |
1063 |
final Note style = DiagramFactory.eINSTANCE.createNote(); |
1064 |
|
1064 |
Option<NodeStyle> noPreviousStyle = Options.newNone(); |
1065 |
private GaugeCompositeStyle createGaugeCompositeStyle(final GaugeCompositeStyleDescription description) { |
1065 |
updateNote(style, description, noPreviousStyle); |
1066 |
final GaugeCompositeStyle style = DiagramFactory.eINSTANCE.createGaugeCompositeStyle(); |
1066 |
return style; |
1067 |
Option<NodeStyle> noPreviousStyle = Options.newNone(); |
1067 |
} |
1068 |
updateGaugeCompositeStyle(style, description, noPreviousStyle); |
1068 |
|
1069 |
return style; |
1069 |
private void updateNote(final Note style, final NoteDescription description, Option<NodeStyle> previousStyle) { |
1070 |
} |
1070 |
if (style.getDescription() != description) { |
1071 |
|
1071 |
style.setDescription(description); |
1072 |
private void updateGaugeCompositeStyle(final GaugeCompositeStyle style, final GaugeCompositeStyleDescription description, Option<NodeStyle> previousStyle) { |
1072 |
} |
1073 |
if (style.getDescription() != description) { |
1073 |
|
1074 |
style.setDescription(description); |
1074 |
updateLabelStyleFeatures(description, style, previousStyle); |
1075 |
} |
1075 |
} |
1076 |
|
1076 |
|
1077 |
updateLabelStyleFeatures(description, style, previousStyle); |
1077 |
private GaugeCompositeStyle createGaugeCompositeStyle(final GaugeCompositeStyleDescription description) { |
1078 |
|
1078 |
final GaugeCompositeStyle style = DiagramFactory.eINSTANCE.createGaugeCompositeStyle(); |
1079 |
EList<GaugeSection> newGaugeSections = new BasicEList<GaugeSection>(); |
1079 |
Option<NodeStyle> noPreviousStyle = Options.newNone(); |
1080 |
|
1080 |
updateGaugeCompositeStyle(style, description, noPreviousStyle); |
1081 |
for (final GaugeSectionDescription section : description.getSections()) { |
1081 |
return style; |
1082 |
final GaugeSection styleSection = DiagramFactory.eINSTANCE.createGaugeSection(); |
1082 |
} |
1083 |
styleSection.setLabel(section.getLabel()); |
1083 |
|
1084 |
|
1084 |
private void updateGaugeCompositeStyle(final GaugeCompositeStyle style, final GaugeCompositeStyleDescription description, Option<NodeStyle> previousStyle) { |
1085 |
// The context. |
1085 |
if (style.getDescription() != description) { |
1086 |
EObject context = null; |
1086 |
style.setDescription(description); |
1087 |
if (style.eContainer() instanceof DSemanticDecorator) { |
1087 |
} |
1088 |
context = ((DSemanticDecorator) style.eContainer()).getTarget(); |
1088 |
|
1089 |
} |
1089 |
updateLabelStyleFeatures(description, style, previousStyle); |
1090 |
if (context != null && context.eResource() != null) { |
1090 |
|
1091 |
// |
1091 |
EList<GaugeSection> newGaugeSections = new BasicEList<GaugeSection>(); |
1092 |
// refresh all sections. |
1092 |
|
1093 |
final Integer min = getIntFromExpression(context, section, StylePackage.eINSTANCE.getGaugeSectionDescription_MinValueExpression()); |
1093 |
for (final GaugeSectionDescription section : description.getSections()) { |
1094 |
final Integer max = getIntFromExpression(context, section, StylePackage.eINSTANCE.getGaugeSectionDescription_MaxValueExpression()); |
1094 |
final GaugeSection styleSection = DiagramFactory.eINSTANCE.createGaugeSection(); |
1095 |
final Integer value = getIntFromExpression(context, section, StylePackage.eINSTANCE.getGaugeSectionDescription_ValueExpression()); |
1095 |
styleSection.setLabel(section.getLabel()); |
1096 |
styleSection.setMin(min); |
1096 |
|
1097 |
styleSection.setMax(max); |
1097 |
// The context. |
1098 |
if (value == null) { |
1098 |
EObject context = null; |
1099 |
styleSection.setValue(min); |
1099 |
if (style.eContainer() instanceof DSemanticDecorator) { |
1100 |
} else { |
1100 |
context = ((DSemanticDecorator) style.eContainer()).getTarget(); |
1101 |
styleSection.setValue(value); |
1101 |
} |
1102 |
} |
1102 |
if (context != null && context.eResource() != null) { |
1103 |
styleSection.setBackgroundColor(colorUpdater.getRGBValuesFromColorDescription(context, section.getBackgroundColor())); |
1103 |
// |
1104 |
styleSection.setForegroundColor(colorUpdater.getRGBValuesFromColorDescription(context, section.getForegroundColor())); |
1104 |
// refresh all sections. |
1105 |
} |
1105 |
final Integer min = getIntFromExpression(context, section, StylePackage.eINSTANCE.getGaugeSectionDescription_MinValueExpression()); |
1106 |
newGaugeSections.add(styleSection); |
1106 |
final Integer max = getIntFromExpression(context, section, StylePackage.eINSTANCE.getGaugeSectionDescription_MaxValueExpression()); |
1107 |
} |
1107 |
final Integer value = getIntFromExpression(context, section, StylePackage.eINSTANCE.getGaugeSectionDescription_ValueExpression()); |
1108 |
|
1108 |
styleSection.setMin(min); |
1109 |
org.eclipse.emf.ecore.util.EcoreUtil.EqualityHelper equalityHelper = new org.eclipse.emf.ecore.util.EcoreUtil.EqualityHelper(); |
1109 |
styleSection.setMax(max); |
1110 |
// Change sections only if new list is different from original one |
1110 |
if (value == null) { |
1111 |
if (!equalityHelper.equals((List) style.getSections(), (List) newGaugeSections) && !style.getCustomFeatures().contains(DiagramPackage.Literals.GAUGE_COMPOSITE_STYLE__SECTIONS.getName())) { |
1111 |
styleSection.setValue(min); |
1112 |
style.getSections().clear(); |
1112 |
} else { |
1113 |
style.getSections().addAll(newGaugeSections); |
1113 |
styleSection.setValue(value); |
1114 |
} |
1114 |
} |
1115 |
|
1115 |
styleSection.setBackgroundColor(colorUpdater.getRGBValuesFromColorDescription(context, section.getBackgroundColor())); |
1116 |
if (style.getAlignment().getValue() != description.getAlignment().getValue() && !style.getCustomFeatures().contains(DiagramPackage.Literals.GAUGE_COMPOSITE_STYLE__ALIGNMENT.getName())) { |
1116 |
styleSection.setForegroundColor(colorUpdater.getRGBValuesFromColorDescription(context, section.getForegroundColor())); |
1117 |
style.setAlignment(description.getAlignment()); |
1117 |
} |
1118 |
} |
1118 |
newGaugeSections.add(styleSection); |
1119 |
} |
1119 |
} |
1120 |
|
1120 |
|
1121 |
private Integer getIntFromExpression(final EObject context, final EObject descriptionObject, final EStructuralFeature eFeature) { |
1121 |
org.eclipse.emf.ecore.util.EcoreUtil.EqualityHelper equalityHelper = new org.eclipse.emf.ecore.util.EcoreUtil.EqualityHelper(); |
1122 |
final String computationExpression = (String) descriptionObject.eGet(eFeature); |
1122 |
// Change sections only if new list is different from original one |
1123 |
try { |
1123 |
if (!equalityHelper.equals((List) style.getSections(), (List) newGaugeSections) && !style.getCustomFeatures().contains(DiagramPackage.Literals.GAUGE_COMPOSITE_STYLE__SECTIONS.getName())) { |
1124 |
return interpreter.evaluateInteger(context, computationExpression); |
1124 |
style.getSections().clear(); |
1125 |
} catch (final EvaluationException e) { |
1125 |
style.getSections().addAll(newGaugeSections); |
1126 |
RuntimeLoggerManager.INSTANCE.error(descriptionObject, eFeature, e); |
1126 |
} |
1127 |
} |
1127 |
|
1128 |
return Integer.valueOf(0); |
1128 |
if (style.getAlignment().getValue() != description.getAlignment().getValue() && !style.getCustomFeatures().contains(DiagramPackage.Literals.GAUGE_COMPOSITE_STYLE__ALIGNMENT.getName())) { |
1129 |
} |
1129 |
style.setAlignment(description.getAlignment()); |
1130 |
|
1130 |
} |
1131 |
private Dot createDot(final DotDescription description) { |
1131 |
} |
1132 |
final Dot style = DiagramFactory.eINSTANCE.createDot(); |
1132 |
|
1133 |
Option<NodeStyle> noPreviousStyle = Options.newNone(); |
1133 |
private Integer getIntFromExpression(final EObject context, final EObject descriptionObject, final EStructuralFeature eFeature) { |
1134 |
updateDot(style, description, noPreviousStyle); |
1134 |
final String computationExpression = (String) descriptionObject.eGet(eFeature); |
1135 |
return style; |
1135 |
try { |
1136 |
} |
1136 |
return interpreter.evaluateInteger(context, computationExpression); |
1137 |
|
1137 |
} catch (final EvaluationException e) { |
1138 |
private void updateDot(final Dot style, final DotDescription description, Option<NodeStyle> previousStyle) { |
1138 |
RuntimeLoggerManager.INSTANCE.error(descriptionObject, eFeature, e); |
1139 |
if (style.getDescription() != description) { |
1139 |
} |
1140 |
style.setDescription(description); |
1140 |
return Integer.valueOf(0); |
1141 |
} |
1141 |
} |
1142 |
|
1142 |
|
1143 |
updateLabelStyleFeatures(description, style, previousStyle); |
1143 |
private Dot createDot(final DotDescription description) { |
1144 |
|
1144 |
final Dot style = DiagramFactory.eINSTANCE.createDot(); |
1145 |
if (previousStyle.some() && previousStyle.get().getCustomFeatures().contains(DiagramPackage.Literals.DOT__STROKE_SIZE_COMPUTATION_EXPRESSION.getName()) && previousStyle.get() instanceof Dot) { |
1145 |
Option<NodeStyle> noPreviousStyle = Options.newNone(); |
1146 |
style.setStrokeSizeComputationExpression(((Dot) previousStyle.get()).getStrokeSizeComputationExpression()); |
1146 |
updateDot(style, description, noPreviousStyle); |
1147 |
style.getCustomFeatures().add(DiagramPackage.Literals.DOT__STROKE_SIZE_COMPUTATION_EXPRESSION.getName()); |
1147 |
return style; |
1148 |
} else { |
1148 |
} |
1149 |
if (!style.getStrokeSizeComputationExpression().equals(description.getStrokeSizeComputationExpression()) |
1149 |
|
1150 |
&& !style.getCustomFeatures().contains(DiagramPackage.Literals.DOT__STROKE_SIZE_COMPUTATION_EXPRESSION.getName())) { |
1150 |
private void updateDot(final Dot style, final DotDescription description, Option<NodeStyle> previousStyle) { |
1151 |
style.setStrokeSizeComputationExpression(description.getStrokeSizeComputationExpression()); |
1151 |
if (style.getDescription() != description) { |
1152 |
} |
1152 |
style.setDescription(description); |
1153 |
} |
1153 |
} |
1154 |
} |
1154 |
|
1155 |
|
1155 |
updateLabelStyleFeatures(description, style, previousStyle); |
1156 |
private Square createSquare(final SquareDescription description) { |
1156 |
|
1157 |
final Square style = DiagramFactory.eINSTANCE.createSquare(); |
1157 |
if (previousStyle.some() && previousStyle.get().getCustomFeatures().contains(DiagramPackage.Literals.DOT__STROKE_SIZE_COMPUTATION_EXPRESSION.getName()) && previousStyle.get() instanceof Dot) { |
1158 |
Option<NodeStyle> noPreviousStyle = Options.newNone(); |
1158 |
style.setStrokeSizeComputationExpression(((Dot) previousStyle.get()).getStrokeSizeComputationExpression()); |
1159 |
updateSquare(style, description, noPreviousStyle); |
1159 |
style.getCustomFeatures().add(DiagramPackage.Literals.DOT__STROKE_SIZE_COMPUTATION_EXPRESSION.getName()); |
1160 |
return style; |
1160 |
} else { |
1161 |
} |
1161 |
if (!style.getStrokeSizeComputationExpression().equals(description.getStrokeSizeComputationExpression()) |
1162 |
|
1162 |
&& !style.getCustomFeatures().contains(DiagramPackage.Literals.DOT__STROKE_SIZE_COMPUTATION_EXPRESSION.getName())) { |
1163 |
private void updateSquare(final Square style, final SquareDescription description, Option<NodeStyle> previousStyle) { |
1163 |
style.setStrokeSizeComputationExpression(description.getStrokeSizeComputationExpression()); |
1164 |
// If the style's color is null or one of either the style or |
1164 |
} |
1165 |
// description color is not a scale value (recomputed later), reset it |
1165 |
} |
1166 |
if (style.getDescription() != description) { |
1166 |
} |
1167 |
style.setDescription(description); |
1167 |
|
1168 |
} |
1168 |
private Square createSquare(final SquareDescription description) { |
1169 |
|
1169 |
final Square style = DiagramFactory.eINSTANCE.createSquare(); |
1170 |
updateLabelStyleFeatures(description, style, previousStyle); |
1170 |
Option<NodeStyle> noPreviousStyle = Options.newNone(); |
1171 |
if (style.getHeight().intValue() != description.getHeight().intValue() && !style.getCustomFeatures().contains(DiagramPackage.Literals.SQUARE__HEIGHT.getName())) { |
1171 |
updateSquare(style, description, noPreviousStyle); |
1172 |
style.setHeight(description.getHeight()); |
1172 |
return style; |
1173 |
} |
1173 |
} |
1174 |
if (style.getWidth().intValue() != description.getWidth().intValue() && !style.getCustomFeatures().contains(DiagramPackage.Literals.SQUARE__WIDTH.getName())) { |
1174 |
|
1175 |
style.setWidth(description.getWidth()); |
1175 |
private void updateSquare(final Square style, final SquareDescription description, Option<NodeStyle> previousStyle) { |
1176 |
} |
1176 |
// If the style's color is null or one of either the style or |
1177 |
if (style.eContainer() instanceof DNode) { |
1177 |
// description color is not a scale value (recomputed later), reset it |
1178 |
final DNode node = (DNode) style.eContainer(); |
1178 |
if (style.getDescription() != description) { |
1179 |
if (style.getWidth() != 0 && style.getHeight() != 0) { |
1179 |
style.setDescription(description); |
1180 |
if (node.getWidth() == null || node.getWidth().intValue() != style.getWidth().intValue()) { |
1180 |
} |
1181 |
node.setWidth(style.getWidth()); |
1181 |
|
1182 |
} |
1182 |
updateLabelStyleFeatures(description, style, previousStyle); |
1183 |
if (node.getHeight() == null || node.getHeight().intValue() != style.getHeight().intValue()) { |
1183 |
if (style.getHeight().intValue() != description.getHeight().intValue() && !style.getCustomFeatures().contains(DiagramPackage.Literals.SQUARE__HEIGHT.getName())) { |
1184 |
node.setHeight(style.getHeight()); |
1184 |
style.setHeight(description.getHeight()); |
1185 |
} |
1185 |
} |
1186 |
} else { |
1186 |
if (style.getWidth().intValue() != description.getWidth().intValue() && !style.getCustomFeatures().contains(DiagramPackage.Literals.SQUARE__WIDTH.getName())) { |
1187 |
setComputedSize(node, description); |
1187 |
style.setWidth(description.getWidth()); |
1188 |
} |
1188 |
} |
1189 |
if (style.getBorderSizeComputationExpression() != null && !style.getCustomFeatures().contains(DiagramPackage.Literals.BORDERED_STYLE__BORDER_SIZE.getName())) { |
1189 |
if (style.eContainer() instanceof DNode) { |
1190 |
try { |
1190 |
final DNode node = (DNode) style.eContainer(); |
1191 |
style.setBorderSize(interpreter.evaluateInteger(node.getTarget(), description.getBorderSizeComputationExpression())); |
1191 |
if (style.getWidth() != 0 && style.getHeight() != 0) { |
1192 |
} catch (final EvaluationException e) { |
1192 |
if (node.getWidth() == null || node.getWidth().intValue() != style.getWidth().intValue()) { |
1193 |
RuntimeLoggerManager.INSTANCE.error(description, StylePackage.eINSTANCE.getBorderedStyleDescription_BorderSizeComputationExpression(), e); |
1193 |
node.setWidth(style.getWidth()); |
1194 |
} |
1194 |
} |
1195 |
} |
1195 |
if (node.getHeight() == null || node.getHeight().intValue() != style.getHeight().intValue()) { |
1196 |
} |
1196 |
node.setHeight(style.getHeight()); |
1197 |
} |
1197 |
} |
1198 |
|
1198 |
} else { |
1199 |
private CustomStyle createCustomStyle(final CustomStyleDescription description) { |
1199 |
setComputedSize(node, description); |
1200 |
final CustomStyle style = DiagramFactory.eINSTANCE.createCustomStyle(); |
1200 |
} |
1201 |
Option<NodeStyle> noPreviousStyle = Options.newNone(); |
1201 |
if (style.getBorderSizeComputationExpression() != null && !style.getCustomFeatures().contains(DiagramPackage.Literals.BORDERED_STYLE__BORDER_SIZE.getName())) { |
1202 |
updateCustomStyle(style, description, noPreviousStyle); |
1202 |
try { |
1203 |
return style; |
1203 |
style.setBorderSize(interpreter.evaluateInteger(node.getTarget(), description.getBorderSizeComputationExpression())); |
1204 |
} |
1204 |
} catch (final EvaluationException e) { |
1205 |
|
1205 |
RuntimeLoggerManager.INSTANCE.error(description, StylePackage.eINSTANCE.getBorderedStyleDescription_BorderSizeComputationExpression(), e); |
1206 |
private void updateCustomStyle(final CustomStyle style, final CustomStyleDescription description, Option<NodeStyle> previousStyle) { |
1206 |
} |
1207 |
if (style.getDescription() != description) { |
1207 |
} |
1208 |
style.setDescription(description); |
1208 |
} |
1209 |
} |
1209 |
} |
1210 |
|
1210 |
|
1211 |
updateLabelStyleFeatures(description, style, previousStyle); |
1211 |
private CustomStyle createCustomStyle(final CustomStyleDescription description) { |
1212 |
|
1212 |
final CustomStyle style = DiagramFactory.eINSTANCE.createCustomStyle(); |
1213 |
if (previousStyle.some() && previousStyle.get().getCustomFeatures().contains(DiagramPackage.Literals.CUSTOM_STYLE__ID.getName()) && previousStyle.get() instanceof CustomStyle) { |
1213 |
Option<NodeStyle> noPreviousStyle = Options.newNone(); |
1214 |
style.setId(((CustomStyle) previousStyle.get()).getId()); |
1214 |
updateCustomStyle(style, description, noPreviousStyle); |
1215 |
style.getCustomFeatures().add(DiagramPackage.Literals.CUSTOM_STYLE__ID.getName()); |
1215 |
return style; |
1216 |
} else { |
1216 |
} |
1217 |
if (style.getId() == null || !style.getId().equals(description.getId()) && !style.getCustomFeatures().contains(DiagramPackage.Literals.CUSTOM_STYLE__ID.getName())) { |
1217 |
|
1218 |
style.setId(description.getId()); |
1218 |
private void updateCustomStyle(final CustomStyle style, final CustomStyleDescription description, Option<NodeStyle> previousStyle) { |
1219 |
} |
1219 |
if (style.getDescription() != description) { |
1220 |
} |
1220 |
style.setDescription(description); |
1221 |
} |
1221 |
} |
1222 |
|
1222 |
|
1223 |
private Lozenge createLozenge(final LozengeNodeDescription description) { |
1223 |
updateLabelStyleFeatures(description, style, previousStyle); |
1224 |
final Lozenge style = DiagramFactory.eINSTANCE.createLozenge(); |
1224 |
|
1225 |
Option<NodeStyle> noPreviousStyle = Options.newNone(); |
1225 |
if (previousStyle.some() && previousStyle.get().getCustomFeatures().contains(DiagramPackage.Literals.CUSTOM_STYLE__ID.getName()) && previousStyle.get() instanceof CustomStyle) { |
1226 |
updateLozenge(style, description, noPreviousStyle); |
1226 |
style.setId(((CustomStyle) previousStyle.get()).getId()); |
1227 |
return style; |
1227 |
style.getCustomFeatures().add(DiagramPackage.Literals.CUSTOM_STYLE__ID.getName()); |
1228 |
} |
1228 |
} else { |
1229 |
|
1229 |
if (style.getId() == null || !style.getId().equals(description.getId()) && !style.getCustomFeatures().contains(DiagramPackage.Literals.CUSTOM_STYLE__ID.getName())) { |
1230 |
private void updateLozenge(final Lozenge style, final LozengeNodeDescription description, Option<NodeStyle> previousStyle) { |
1230 |
style.setId(description.getId()); |
1231 |
if (style.getDescription() != description) { |
1231 |
} |
1232 |
style.setDescription(description); |
1232 |
} |
1233 |
} |
1233 |
} |
1234 |
|
1234 |
|
1235 |
updateLabelStyleFeatures(description, style, previousStyle); |
1235 |
private Lozenge createLozenge(final LozengeNodeDescription description) { |
1236 |
|
1236 |
final Lozenge style = DiagramFactory.eINSTANCE.createLozenge(); |
1237 |
if (style.eContainer() instanceof DNode) { |
1237 |
Option<NodeStyle> noPreviousStyle = Options.newNone(); |
1238 |
final DNode node = (DNode) style.eContainer(); |
1238 |
updateLozenge(style, description, noPreviousStyle); |
1239 |
Integer width = Integer.valueOf(0); |
1239 |
return style; |
1240 |
Integer height = Integer.valueOf(0); |
1240 |
} |
1241 |
if (description.getWidthComputationExpression() != null && description.getHeightComputationExpression() != null) { |
1241 |
|
1242 |
|
1242 |
private void updateLozenge(final Lozenge style, final LozengeNodeDescription description, Option<NodeStyle> previousStyle) { |
1243 |
try { |
1243 |
if (style.getDescription() != description) { |
1244 |
width = interpreter.evaluateInteger(node.getTarget(), description.getWidthComputationExpression()); |
1244 |
style.setDescription(description); |
1245 |
} catch (final EvaluationException e) { |
1245 |
} |
1246 |
RuntimeLoggerManager.INSTANCE.error(description, StylePackage.eINSTANCE.getLozengeNodeDescription_WidthComputationExpression(), e); |
1246 |
|
1247 |
} |
1247 |
updateLabelStyleFeatures(description, style, previousStyle); |
1248 |
try { |
1248 |
|
1249 |
height = interpreter.evaluateInteger(node.getTarget(), description.getHeightComputationExpression()); |
1249 |
if (style.eContainer() instanceof DNode) { |
1250 |
} catch (final EvaluationException e) { |
1250 |
final DNode node = (DNode) style.eContainer(); |
1251 |
RuntimeLoggerManager.INSTANCE.error(description, StylePackage.eINSTANCE.getLozengeNodeDescription_HeightComputationExpression(), e); |
1251 |
Integer width = Integer.valueOf(0); |
1252 |
} |
1252 |
Integer height = Integer.valueOf(0); |
1253 |
if (height != null && width != null && width.intValue() != 0 && height.intValue() != 0) { |
1253 |
if (description.getWidthComputationExpression() != null && description.getHeightComputationExpression() != null) { |
1254 |
if (node.getWidth() == null || node.getWidth().intValue() != width.intValue()) { |
1254 |
|
1255 |
node.setWidth(width); |
1255 |
try { |
1256 |
} |
1256 |
width = interpreter.evaluateInteger(node.getTarget(), description.getWidthComputationExpression()); |
1257 |
if (previousStyle.some() && previousStyle.get().getCustomFeatures().contains(DiagramPackage.Literals.LOZENGE__WIDTH.getName()) && previousStyle.get() instanceof Lozenge) { |
1257 |
} catch (final EvaluationException e) { |
1258 |
style.setWidth(((Lozenge) previousStyle.get()).getWidth()); |
1258 |
RuntimeLoggerManager.INSTANCE.error(description, StylePackage.eINSTANCE.getLozengeNodeDescription_WidthComputationExpression(), e); |
1259 |
style.getCustomFeatures().add(DiagramPackage.Literals.LOZENGE__WIDTH.getName()); |
1259 |
} |
1260 |
} else if (previousStyle.some() && previousStyle.get().getCustomFeatures().contains(DiagramPackage.Literals.ELLIPSE__HORIZONTAL_DIAMETER.getName()) |
1260 |
try { |
1261 |
&& previousStyle.get() instanceof Ellipse) { |
1261 |
height = interpreter.evaluateInteger(node.getTarget(), description.getHeightComputationExpression()); |
1262 |
style.setWidth(((Ellipse) previousStyle.get()).getHorizontalDiameter()); |
1262 |
} catch (final EvaluationException e) { |
1263 |
style.getCustomFeatures().add(DiagramPackage.Literals.LOZENGE__WIDTH.getName()); |
1263 |
RuntimeLoggerManager.INSTANCE.error(description, StylePackage.eINSTANCE.getLozengeNodeDescription_HeightComputationExpression(), e); |
1264 |
} else { |
1264 |
} |
1265 |
if (style.getWidth().intValue() != width.intValue() && !style.getCustomFeatures().contains(DiagramPackage.Literals.LOZENGE__WIDTH.getName())) { |
1265 |
if (height != null && width != null && width.intValue() != 0 && height.intValue() != 0) { |
1266 |
style.setWidth(width); |
1266 |
if (node.getWidth() == null || node.getWidth().intValue() != width.intValue()) { |
1267 |
} |
1267 |
node.setWidth(width); |
1268 |
} |
1268 |
} |
1269 |
if (node.getHeight() == null || node.getHeight().intValue() != height.intValue()) { |
1269 |
if (previousStyle.some() && previousStyle.get().getCustomFeatures().contains(DiagramPackage.Literals.LOZENGE__WIDTH.getName()) && previousStyle.get() instanceof Lozenge) { |
1270 |
node.setHeight(height); |
1270 |
style.setWidth(((Lozenge) previousStyle.get()).getWidth()); |
1271 |
} |
1271 |
style.getCustomFeatures().add(DiagramPackage.Literals.LOZENGE__WIDTH.getName()); |
1272 |
|
1272 |
} else if (previousStyle.some() && previousStyle.get().getCustomFeatures().contains(DiagramPackage.Literals.ELLIPSE__HORIZONTAL_DIAMETER.getName()) |
1273 |
if (previousStyle.some() && previousStyle.get().getCustomFeatures().contains(DiagramPackage.Literals.LOZENGE__HEIGHT.getName()) && previousStyle.get() instanceof Lozenge) { |
1273 |
&& previousStyle.get() instanceof Ellipse) { |
1274 |
style.setHeight(((Lozenge) previousStyle.get()).getHeight()); |
1274 |
style.setWidth(((Ellipse) previousStyle.get()).getHorizontalDiameter()); |
1275 |
style.getCustomFeatures().add(DiagramPackage.Literals.LOZENGE__HEIGHT.getName()); |
1275 |
style.getCustomFeatures().add(DiagramPackage.Literals.LOZENGE__WIDTH.getName()); |
1276 |
} else if (previousStyle.some() && previousStyle.get().getCustomFeatures().contains(DiagramPackage.Literals.ELLIPSE__VERTICAL_DIAMETER.getName()) |
1276 |
} else { |
1277 |
&& previousStyle.get() instanceof Ellipse) { |
1277 |
if (style.getWidth().intValue() != width.intValue() && !style.getCustomFeatures().contains(DiagramPackage.Literals.LOZENGE__WIDTH.getName())) { |
1278 |
style.setHeight(((Ellipse) previousStyle.get()).getVerticalDiameter()); |
1278 |
style.setWidth(width); |
1279 |
style.getCustomFeatures().add(DiagramPackage.Literals.LOZENGE__HEIGHT.getName()); |
1279 |
} |
1280 |
} else { |
1280 |
} |
1281 |
if (style.getHeight().intValue() != height.intValue() && !style.getCustomFeatures().contains(DiagramPackage.Literals.LOZENGE__HEIGHT.getName())) { |
1281 |
if (node.getHeight() == null || node.getHeight().intValue() != height.intValue()) { |
1282 |
style.setHeight(height); |
1282 |
node.setHeight(height); |
1283 |
} |
1283 |
} |
1284 |
} |
1284 |
|
1285 |
} else { |
1285 |
if (previousStyle.some() && previousStyle.get().getCustomFeatures().contains(DiagramPackage.Literals.LOZENGE__HEIGHT.getName()) && previousStyle.get() instanceof Lozenge) { |
1286 |
setComputedSize(node, description); |
1286 |
style.setHeight(((Lozenge) previousStyle.get()).getHeight()); |
1287 |
} |
1287 |
style.getCustomFeatures().add(DiagramPackage.Literals.LOZENGE__HEIGHT.getName()); |
1288 |
} else { |
1288 |
} else if (previousStyle.some() && previousStyle.get().getCustomFeatures().contains(DiagramPackage.Literals.ELLIPSE__VERTICAL_DIAMETER.getName()) |
1289 |
setComputedSize(node, description); |
1289 |
&& previousStyle.get() instanceof Ellipse) { |
1290 |
} |
1290 |
style.setHeight(((Ellipse) previousStyle.get()).getVerticalDiameter()); |
1291 |
} |
1291 |
style.getCustomFeatures().add(DiagramPackage.Literals.LOZENGE__HEIGHT.getName()); |
1292 |
} |
1292 |
} else { |
1293 |
|
1293 |
if (style.getHeight().intValue() != height.intValue() && !style.getCustomFeatures().contains(DiagramPackage.Literals.LOZENGE__HEIGHT.getName())) { |
1294 |
private NodeStyle createEllipse(final EllipseNodeDescription description) { |
1294 |
style.setHeight(height); |
1295 |
final Ellipse style = DiagramFactory.eINSTANCE.createEllipse(); |
1295 |
} |
1296 |
Option<NodeStyle> noPreviousStyle = Options.newNone(); |
1296 |
} |
1297 |
updateEllipse(style, description, noPreviousStyle); |
1297 |
} else { |
1298 |
return style; |
1298 |
setComputedSize(node, description); |
1299 |
} |
1299 |
} |
1300 |
|
1300 |
} else { |
1301 |
private void updateEllipse(final Ellipse style, final EllipseNodeDescription description, Option<NodeStyle> previousStyle) { |
1301 |
setComputedSize(node, description); |
1302 |
if (style.getDescription() != description) { |
1302 |
} |
1303 |
style.setDescription(description); |
1303 |
} |
1304 |
} |
1304 |
} |
1305 |
|
1305 |
|
1306 |
updateLabelStyleFeatures(description, style, previousStyle); |
1306 |
private NodeStyle createEllipse(final EllipseNodeDescription description) { |
1307 |
|
1307 |
final Ellipse style = DiagramFactory.eINSTANCE.createEllipse(); |
1308 |
if (style.eContainer() instanceof DNode) { |
1308 |
Option<NodeStyle> noPreviousStyle = Options.newNone(); |
1309 |
final DNode node = (DNode) style.eContainer(); |
1309 |
updateEllipse(style, description, noPreviousStyle); |
1310 |
Integer width = Integer.valueOf(0); |
1310 |
return style; |
1311 |
Integer height = Integer.valueOf(0); |
1311 |
} |
1312 |
if (description.getHorizontalDiameterComputationExpression() != null && description.getVerticalDiameterComputationExpression() != null) { |
1312 |
|
1313 |
try { |
1313 |
private void updateEllipse(final Ellipse style, final EllipseNodeDescription description, Option<NodeStyle> previousStyle) { |
1314 |
width = interpreter.evaluateInteger(node.getTarget(), description.getHorizontalDiameterComputationExpression()); |
1314 |
if (style.getDescription() != description) { |
1315 |
} catch (final EvaluationException e) { |
1315 |
style.setDescription(description); |
1316 |
RuntimeLoggerManager.INSTANCE.error(description, StylePackage.eINSTANCE.getEllipseNodeDescription_HorizontalDiameterComputationExpression(), e); |
1316 |
} |
1317 |
} |
1317 |
|
1318 |
try { |
1318 |
updateLabelStyleFeatures(description, style, previousStyle); |
1319 |
height = interpreter.evaluateInteger(node.getTarget(), description.getVerticalDiameterComputationExpression()); |
1319 |
|
1320 |
} catch (final EvaluationException e) { |
1320 |
if (style.eContainer() instanceof DNode) { |
1321 |
RuntimeLoggerManager.INSTANCE.error(description, StylePackage.eINSTANCE.getEllipseNodeDescription_VerticalDiameterComputationExpression(), e); |
1321 |
final DNode node = (DNode) style.eContainer(); |
1322 |
} |
1322 |
Integer width = Integer.valueOf(0); |
1323 |
if (height != null && width != null && width.intValue() != 0 && height.intValue() != 0) { |
1323 |
Integer height = Integer.valueOf(0); |
1324 |
if (node.getWidth() == null || node.getWidth().intValue() != width.intValue()) { |
1324 |
if (description.getHorizontalDiameterComputationExpression() != null && description.getVerticalDiameterComputationExpression() != null) { |
1325 |
node.setWidth(width); |
1325 |
try { |
1326 |
} |
1326 |
width = interpreter.evaluateInteger(node.getTarget(), description.getHorizontalDiameterComputationExpression()); |
1327 |
if (previousStyle.some() && previousStyle.get().getCustomFeatures().contains(DiagramPackage.Literals.LOZENGE__WIDTH.getName()) && previousStyle.get() instanceof Lozenge) { |
1327 |
} catch (final EvaluationException e) { |
1328 |
style.setHorizontalDiameter(((Lozenge) previousStyle.get()).getWidth()); |
1328 |
RuntimeLoggerManager.INSTANCE.error(description, StylePackage.eINSTANCE.getEllipseNodeDescription_HorizontalDiameterComputationExpression(), e); |
1329 |
style.getCustomFeatures().add(DiagramPackage.Literals.ELLIPSE__HORIZONTAL_DIAMETER.getName()); |
1329 |
} |
1330 |
} else if (previousStyle.some() && previousStyle.get().getCustomFeatures().contains(DiagramPackage.Literals.ELLIPSE__HORIZONTAL_DIAMETER.getName()) |
1330 |
try { |
1331 |
&& previousStyle.get() instanceof Ellipse) { |
1331 |
height = interpreter.evaluateInteger(node.getTarget(), description.getVerticalDiameterComputationExpression()); |
1332 |
style.setHorizontalDiameter(((Ellipse) previousStyle.get()).getHorizontalDiameter()); |
1332 |
} catch (final EvaluationException e) { |
1333 |
style.getCustomFeatures().add(DiagramPackage.Literals.ELLIPSE__HORIZONTAL_DIAMETER.getName()); |
1333 |
RuntimeLoggerManager.INSTANCE.error(description, StylePackage.eINSTANCE.getEllipseNodeDescription_VerticalDiameterComputationExpression(), e); |
1334 |
} else { |
1334 |
} |
1335 |
if (style.getHorizontalDiameter().intValue() != width.intValue() && !style.getCustomFeatures().contains(DiagramPackage.Literals.ELLIPSE__HORIZONTAL_DIAMETER.getName())) { |
1335 |
if (height != null && width != null && width.intValue() != 0 && height.intValue() != 0) { |
1336 |
style.setHorizontalDiameter(width); |
1336 |
if (node.getWidth() == null || node.getWidth().intValue() != width.intValue()) { |
1337 |
} |
1337 |
node.setWidth(width); |
1338 |
} |
1338 |
} |
1339 |
if (node.getHeight() == null || node.getHeight().intValue() != height.intValue()) { |
1339 |
if (previousStyle.some() && previousStyle.get().getCustomFeatures().contains(DiagramPackage.Literals.LOZENGE__WIDTH.getName()) && previousStyle.get() instanceof Lozenge) { |
1340 |
node.setHeight(height); |
1340 |
style.setHorizontalDiameter(((Lozenge) previousStyle.get()).getWidth()); |
1341 |
} |
1341 |
style.getCustomFeatures().add(DiagramPackage.Literals.ELLIPSE__HORIZONTAL_DIAMETER.getName()); |
1342 |
if (previousStyle.some() && previousStyle.get().getCustomFeatures().contains(DiagramPackage.Literals.LOZENGE__HEIGHT.getName()) && previousStyle.get() instanceof Lozenge) { |
1342 |
} else if (previousStyle.some() && previousStyle.get().getCustomFeatures().contains(DiagramPackage.Literals.ELLIPSE__HORIZONTAL_DIAMETER.getName()) |
1343 |
style.setVerticalDiameter(((Lozenge) previousStyle.get()).getHeight()); |
1343 |
&& previousStyle.get() instanceof Ellipse) { |
1344 |
style.getCustomFeatures().add(DiagramPackage.Literals.ELLIPSE__VERTICAL_DIAMETER.getName()); |
1344 |
style.setHorizontalDiameter(((Ellipse) previousStyle.get()).getHorizontalDiameter()); |
1345 |
} else if (previousStyle.some() && previousStyle.get().getCustomFeatures().contains(DiagramPackage.Literals.ELLIPSE__VERTICAL_DIAMETER.getName()) |
1345 |
style.getCustomFeatures().add(DiagramPackage.Literals.ELLIPSE__HORIZONTAL_DIAMETER.getName()); |
1346 |
&& previousStyle.get() instanceof Ellipse) { |
1346 |
} else { |
1347 |
style.setVerticalDiameter(((Ellipse) previousStyle.get()).getVerticalDiameter()); |
1347 |
if (style.getHorizontalDiameter().intValue() != width.intValue() && !style.getCustomFeatures().contains(DiagramPackage.Literals.ELLIPSE__HORIZONTAL_DIAMETER.getName())) { |
1348 |
style.getCustomFeatures().add(DiagramPackage.Literals.ELLIPSE__VERTICAL_DIAMETER.getName()); |
1348 |
style.setHorizontalDiameter(width); |
1349 |
} else { |
1349 |
} |
1350 |
if (style.getVerticalDiameter().intValue() != height.intValue() && !style.getCustomFeatures().contains(DiagramPackage.Literals.ELLIPSE__VERTICAL_DIAMETER.getName())) { |
1350 |
} |
1351 |
style.setVerticalDiameter(height); |
1351 |
if (node.getHeight() == null || node.getHeight().intValue() != height.intValue()) { |
1352 |
} |
1352 |
node.setHeight(height); |
1353 |
} |
1353 |
} |
1354 |
} else { |
1354 |
if (previousStyle.some() && previousStyle.get().getCustomFeatures().contains(DiagramPackage.Literals.LOZENGE__HEIGHT.getName()) && previousStyle.get() instanceof Lozenge) { |
1355 |
setComputedSize(node, description); |
1355 |
style.setVerticalDiameter(((Lozenge) previousStyle.get()).getHeight()); |
1356 |
} |
1356 |
style.getCustomFeatures().add(DiagramPackage.Literals.ELLIPSE__VERTICAL_DIAMETER.getName()); |
1357 |
} else { |
1357 |
} else if (previousStyle.some() && previousStyle.get().getCustomFeatures().contains(DiagramPackage.Literals.ELLIPSE__VERTICAL_DIAMETER.getName()) |
1358 |
setComputedSize(node, description); |
1358 |
&& previousStyle.get() instanceof Ellipse) { |
1359 |
} |
1359 |
style.setVerticalDiameter(((Ellipse) previousStyle.get()).getVerticalDiameter()); |
1360 |
} |
1360 |
style.getCustomFeatures().add(DiagramPackage.Literals.ELLIPSE__VERTICAL_DIAMETER.getName()); |
1361 |
} |
1361 |
} else { |
1362 |
|
1362 |
if (style.getVerticalDiameter().intValue() != height.intValue() && !style.getCustomFeatures().contains(DiagramPackage.Literals.ELLIPSE__VERTICAL_DIAMETER.getName())) { |
1363 |
/** |
1363 |
style.setVerticalDiameter(height); |
1364 |
* Refreshes all colors of the given style. |
1364 |
} |
1365 |
* |
1365 |
} |
1366 |
* @param style |
1366 |
} else { |
1367 |
* the style. |
1367 |
setComputedSize(node, description); |
1368 |
* @param previousStyle |
1368 |
} |
1369 |
* the previous style (if existing) to keep compatible |
1369 |
} else { |
1370 |
* customization. |
1370 |
setComputedSize(node, description); |
1371 |
*/ |
1371 |
} |
1372 |
protected void refreshColors(final Style style, Option<? extends Style> previousStyle) { |
1372 |
} |
1373 |
EObject context = style.eContainer(); |
1373 |
} |
1374 |
/* |
1374 |
|
1375 |
* If there is no description we won't have a lot of chance to update |
1375 |
/** |
1376 |
* anything.. |
1376 |
* Refreshes all colors of the given style. |
1377 |
*/ |
1377 |
* |
1378 |
if (style.getDescription() != null) { |
1378 |
* @param style |
1379 |
if (context != null) { |
1379 |
* the style. |
1380 |
if (context instanceof DSemanticDecorator) { |
1380 |
* @param previousStyle |
1381 |
context = ((DSemanticDecorator) context).getTarget(); |
1381 |
* the previous style (if existing) to keep compatible |
1382 |
} |
1382 |
* customization. |
1383 |
colorUpdater.updateColors(context, style, style.getDescription(), previousStyle); |
1383 |
*/ |
1384 |
refreshEdgeStyleWithContext(style, context, previousStyle); |
1384 |
protected void refreshColors(final Style style, Option<? extends Style> previousStyle) { |
1385 |
} else { |
1385 |
EObject context = style.eContainer(); |
1386 |
colorUpdater.updateColors(style, style.getDescription(), previousStyle); |
1386 |
/* |
1387 |
refreshEdgeStyle(style, previousStyle); |
1387 |
* If there is no description we won't have a lot of chance to update |
1388 |
} |
1388 |
* anything.. |
1389 |
} |
1389 |
*/ |
1390 |
|
1390 |
if (style.getDescription() != null) { |
1391 |
} |
1391 |
if (context != null) { |
1392 |
|
1392 |
if (context instanceof DSemanticDecorator) { |
1393 |
/** |
1393 |
context = ((DSemanticDecorator) context).getTarget(); |
1394 |
* @param style |
1394 |
} |
1395 |
*/ |
1395 |
colorUpdater.updateColors(context, style, style.getDescription(), previousStyle); |
1396 |
private void refreshEdgeStyle(final Style style, Option<? extends Style> previousStyle) { |
1396 |
refreshEdgeStyleWithContext(style, context, previousStyle); |
1397 |
if (style instanceof EdgeStyle && (!previousStyle.some() || previousStyle.get() instanceof EdgeStyle)) { |
1397 |
} else { |
1398 |
CenterLabelStyle centerLabelStyle = ((EdgeStyle) style).getCenterLabelStyle(); |
1398 |
colorUpdater.updateColors(style, style.getDescription(), previousStyle); |
1399 |
if (centerLabelStyle != null) { |
1399 |
refreshEdgeStyle(style, previousStyle); |
1400 |
Option<CenterLabelStyle> previousCenterLabelStyle = Options.newNone(); |
1400 |
} |
1401 |
if (previousStyle.some()) { |
1401 |
} |
1402 |
previousCenterLabelStyle = Options.newSome(((EdgeStyle) previousStyle.get()).getCenterLabelStyle()); |
1402 |
|
1403 |
} |
1403 |
} |
1404 |
colorUpdater.updateColors(centerLabelStyle, centerLabelStyle.getDescription(), previousCenterLabelStyle); |
1404 |
|
1405 |
} |
1405 |
/** |
1406 |
BeginLabelStyle beginLabelStyle = ((EdgeStyle) style).getBeginLabelStyle(); |
1406 |
* @param style |
1407 |
if (beginLabelStyle != null) { |
1407 |
*/ |
1408 |
Option<BeginLabelStyle> previousBeginLabelStyle = Options.newNone(); |
1408 |
private void refreshEdgeStyle(final Style style, Option<? extends Style> previousStyle) { |
1409 |
if (previousStyle.some()) { |
1409 |
if (style instanceof EdgeStyle && (!previousStyle.some() || previousStyle.get() instanceof EdgeStyle)) { |
1410 |
previousBeginLabelStyle = Options.newSome(((EdgeStyle) previousStyle.get()).getBeginLabelStyle()); |
1410 |
CenterLabelStyle centerLabelStyle = ((EdgeStyle) style).getCenterLabelStyle(); |
1411 |
} |
1411 |
if (centerLabelStyle != null) { |
1412 |
colorUpdater.updateColors(beginLabelStyle, beginLabelStyle.getDescription(), previousBeginLabelStyle); |
1412 |
Option<CenterLabelStyle> previousCenterLabelStyle = Options.newNone(); |
1413 |
} |
1413 |
if (previousStyle.some()) { |
1414 |
EndLabelStyle endLabelStyle = ((EdgeStyle) style).getEndLabelStyle(); |
1414 |
previousCenterLabelStyle = Options.newSome(((EdgeStyle) previousStyle.get()).getCenterLabelStyle()); |
1415 |
if (endLabelStyle != null) { |
1415 |
} |
1416 |
Option<EndLabelStyle> previousEndLabelStyle = Options.newNone(); |
1416 |
colorUpdater.updateColors(centerLabelStyle, centerLabelStyle.getDescription(), previousCenterLabelStyle); |
1417 |
if (previousStyle.some()) { |
1417 |
} |
1418 |
previousEndLabelStyle = Options.newSome(((EdgeStyle) previousStyle.get()).getEndLabelStyle()); |
1418 |
BeginLabelStyle beginLabelStyle = ((EdgeStyle) style).getBeginLabelStyle(); |
1419 |
} |
1419 |
if (beginLabelStyle != null) { |
1420 |
colorUpdater.updateColors(endLabelStyle, endLabelStyle.getDescription(), previousEndLabelStyle); |
1420 |
Option<BeginLabelStyle> previousBeginLabelStyle = Options.newNone(); |
1421 |
} |
1421 |
if (previousStyle.some()) { |
1422 |
} |
1422 |
previousBeginLabelStyle = Options.newSome(((EdgeStyle) previousStyle.get()).getBeginLabelStyle()); |
1423 |
} |
1423 |
} |
1424 |
|
1424 |
colorUpdater.updateColors(beginLabelStyle, beginLabelStyle.getDescription(), previousBeginLabelStyle); |
1425 |
/** |
1425 |
} |
1426 |
* @param style |
1426 |
EndLabelStyle endLabelStyle = ((EdgeStyle) style).getEndLabelStyle(); |
1427 |
* @param context |
1427 |
if (endLabelStyle != null) { |
1428 |
*/ |
1428 |
Option<EndLabelStyle> previousEndLabelStyle = Options.newNone(); |
1429 |
private void refreshEdgeStyleWithContext(final Style style, EObject context, Option<? extends Style> previousStyle) { |
1429 |
if (previousStyle.some()) { |
1430 |
if (style instanceof EdgeStyle) { |
1430 |
previousEndLabelStyle = Options.newSome(((EdgeStyle) previousStyle.get()).getEndLabelStyle()); |
1431 |
CenterLabelStyle centerLabelStyle = ((EdgeStyle) style).getCenterLabelStyle(); |
1431 |
} |
1432 |
if (centerLabelStyle != null) { |
1432 |
colorUpdater.updateColors(endLabelStyle, endLabelStyle.getDescription(), previousEndLabelStyle); |
1433 |
Option<CenterLabelStyle> previousCenterLabelStyle = Options.newNone(); |
1433 |
} |
1434 |
if (previousStyle.some()) { |
1434 |
} |
1435 |
previousCenterLabelStyle = Options.newSome(((EdgeStyle) previousStyle.get()).getCenterLabelStyle()); |
1435 |
} |
1436 |
} |
1436 |
|
1437 |
colorUpdater.updateColors(context, centerLabelStyle, centerLabelStyle.getDescription(), previousCenterLabelStyle); |
1437 |
/** |
1438 |
} |
1438 |
* @param style |
1439 |
BeginLabelStyle beginLabelStyle = ((EdgeStyle) style).getBeginLabelStyle(); |
1439 |
* @param context |
1440 |
if (beginLabelStyle != null) { |
1440 |
*/ |
1441 |
Option<BeginLabelStyle> previousBeginLabelStyle = Options.newNone(); |
1441 |
private void refreshEdgeStyleWithContext(final Style style, EObject context, Option<? extends Style> previousStyle) { |
1442 |
if (previousStyle.some()) { |
1442 |
if (style instanceof EdgeStyle) { |
1443 |
previousBeginLabelStyle = Options.newSome(((EdgeStyle) previousStyle.get()).getBeginLabelStyle()); |
1443 |
CenterLabelStyle centerLabelStyle = ((EdgeStyle) style).getCenterLabelStyle(); |
1444 |
} |
1444 |
if (centerLabelStyle != null) { |
1445 |
colorUpdater.updateColors(context, beginLabelStyle, beginLabelStyle.getDescription(), previousBeginLabelStyle); |
1445 |
Option<CenterLabelStyle> previousCenterLabelStyle = Options.newNone(); |
1446 |
} |
1446 |
if (previousStyle.some()) { |
1447 |
EndLabelStyle endLabelStyle = ((EdgeStyle) style).getEndLabelStyle(); |
1447 |
previousCenterLabelStyle = Options.newSome(((EdgeStyle) previousStyle.get()).getCenterLabelStyle()); |
1448 |
if (endLabelStyle != null) { |
1448 |
} |
1449 |
Option<EndLabelStyle> previousEndLabelStyle = Options.newNone(); |
1449 |
colorUpdater.updateColors(context, centerLabelStyle, centerLabelStyle.getDescription(), previousCenterLabelStyle); |
1450 |
if (previousStyle.some()) { |
1450 |
} |
1451 |
previousEndLabelStyle = Options.newSome(((EdgeStyle) previousStyle.get()).getEndLabelStyle()); |
1451 |
BeginLabelStyle beginLabelStyle = ((EdgeStyle) style).getBeginLabelStyle(); |
1452 |
} |
1452 |
if (beginLabelStyle != null) { |
1453 |
colorUpdater.updateColors(context, endLabelStyle, endLabelStyle.getDescription(), previousEndLabelStyle); |
1453 |
Option<BeginLabelStyle> previousBeginLabelStyle = Options.newNone(); |
1454 |
} |
1454 |
if (previousStyle.some()) { |
1455 |
} |
1455 |
previousBeginLabelStyle = Options.newSome(((EdgeStyle) previousStyle.get()).getBeginLabelStyle()); |
1456 |
} |
1456 |
} |
1457 |
|
1457 |
colorUpdater.updateColors(context, beginLabelStyle, beginLabelStyle.getDescription(), previousBeginLabelStyle); |
1458 |
/** |
1458 |
} |
1459 |
* Set the style if needed and refresh it. |
1459 |
EndLabelStyle endLabelStyle = ((EdgeStyle) style).getEndLabelStyle(); |
1460 |
* |
1460 |
if (endLabelStyle != null) { |
1461 |
* @param diagramElement |
1461 |
Option<EndLabelStyle> previousEndLabelStyle = Options.newNone(); |
1462 |
* The diagram element to which apply the style |
1462 |
if (previousStyle.some()) { |
1463 |
* @param currentStyle |
1463 |
previousEndLabelStyle = Options.newSome(((EdgeStyle) previousStyle.get()).getEndLabelStyle()); |
1464 |
* The current style of the diagram element |
1464 |
} |
1465 |
* @param bestStyle |
1465 |
colorUpdater.updateColors(context, endLabelStyle, endLabelStyle.getDescription(), previousEndLabelStyle); |
1466 |
* The new style to apply |
1466 |
} |
1467 |
*/ |
1467 |
} |
1468 |
public void setAndRefreshStyle(final DDiagramElement diagramElement, final Style currentStyle, final Style bestStyle) { |
1468 |
} |
1469 |
if (currentStyle == null) { |
1469 |
|
1470 |
/* |
1470 |
/** |
1471 |
* The element has no style. Let's assign the best style. |
1471 |
* Set the style if needed and refresh it. |
1472 |
*/ |
1472 |
* |
1473 |
new SetStyleSwitch(bestStyle).doSwitch(diagramElement); |
1473 |
* @param diagramElement |
1474 |
// Refresh the style |
1474 |
* The diagram element to which apply the style |
1475 |
new RefreshStyleSwitch().doSwitch(diagramElement); |
1475 |
* @param currentStyle |
1476 |
} else if (bestStyle == currentStyle) { |
1476 |
* The current style of the diagram element |
1477 |
// Refresh the style |
1477 |
* @param bestStyle |
1478 |
new RefreshStyleSwitch().doSwitch(diagramElement); |
1478 |
* The new style to apply |
1479 |
} else if (bestStyle != null && (currentStyle.getDescription() == null || isDifferentDescription(bestStyle, currentStyle))) { |
1479 |
*/ |
1480 |
/* Let's affect the new style. */ |
1480 |
public void setAndRefreshStyle(final DDiagramElement diagramElement, final Style currentStyle, final Style bestStyle) { |
1481 |
new SetStyleSwitch(bestStyle).doSwitch(diagramElement); |
1481 |
if (currentStyle == null) { |
1482 |
// Refresh the style |
1482 |
/* |
1483 |
new RefreshStyleSwitch(Options.newSome(currentStyle)).doSwitch(diagramElement); |
1483 |
* The element has no style. Let's assign the best style. |
1484 |
} |
1484 |
*/ |
1485 |
} |
1485 |
new SetStyleSwitch(bestStyle).doSwitch(diagramElement); |
1486 |
|
1486 |
// Refresh the style |
1487 |
/** |
1487 |
new RefreshStyleSwitch().doSwitch(diagramElement); |
1488 |
* |
1488 |
} else if (bestStyle == currentStyle) { |
1489 |
* @param bestStyle |
1489 |
// Refresh the style |
1490 |
* the new style |
1490 |
new RefreshStyleSwitch().doSwitch(diagramElement); |
1491 |
* @param currentStyle |
1491 |
} else if (bestStyle != null && (currentStyle.getDescription() == null || isDifferentDescription(bestStyle, currentStyle))) { |
1492 |
* the current style |
1492 |
/* Let's affect the new style. */ |
1493 |
* @return if the description is the same type as the style |
1493 |
new SetStyleSwitch(bestStyle).doSwitch(diagramElement); |
1494 |
*/ |
1494 |
// Refresh the style |
1495 |
private boolean isDifferentDescription(Style bestStyle, Style currentStyle) { |
1495 |
new RefreshStyleSwitch(Options.newSome(currentStyle)).doSwitch(diagramElement); |
1496 |
return !EqualityHelper.areEquals(bestStyle.getDescription(), currentStyle.getDescription()) || !bestStyle.getClass().equals(currentStyle.getClass()) |
1496 |
} |
1497 |
&& currentStyle.getCustomFeatures().isEmpty(); |
1497 |
} |
1498 |
} |
1498 |
|
1499 |
|
1499 |
/** |
1500 |
/** |
1500 |
* |
1501 |
* Switch to set the style of a diagram element. |
1501 |
* @param bestStyle |
1502 |
* |
1502 |
* the new style |
1503 |
* @author ymortier |
1503 |
* @param currentStyle |
1504 |
*/ |
1504 |
* the current style |
1505 |
private final class SetStyleSwitch extends DiagramSwitch<Object> { |
1505 |
* @return if the description is the same type as the style |
1506 |
|
1506 |
*/ |
1507 |
/** |
1507 |
private boolean isDifferentDescription(Style bestStyle, Style currentStyle) { |
1508 |
* The style to affect. |
1508 |
return !EqualityHelper.areEquals(bestStyle.getDescription(), currentStyle.getDescription()) || !bestStyle.getClass().equals(currentStyle.getClass()) |
1509 |
*/ |
1509 |
&& currentStyle.getCustomFeatures().isEmpty(); |
1510 |
private final Style style; |
1510 |
} |
1511 |
|
1511 |
|
1512 |
/** |
1512 |
/** |
1513 |
* Default constructor. |
1513 |
* Switch to set the style of a diagram element. |
1514 |
* |
1514 |
* |
1515 |
* @param style |
1515 |
* @author ymortier |
1516 |
* the style to affect, should be <code>null</code>. |
1516 |
*/ |
1517 |
*/ |
1517 |
private final class SetStyleSwitch extends DiagramSwitch<Object> { |
1518 |
private SetStyleSwitch(final Style style) { |
1518 |
|
1519 |
this.style = style; |
1519 |
/** |
1520 |
} |
1520 |
* The style to affect. |
1521 |
|
1521 |
*/ |
1522 |
@Override |
1522 |
private final Style style; |
1523 |
public Object caseDEdge(final DEdge object) { |
1523 |
|
1524 |
object.setOwnedStyle((EdgeStyle) this.style); |
1524 |
/** |
1525 |
return null; |
1525 |
* Default constructor. |
1526 |
} |
1526 |
* |
1527 |
|
1527 |
* @param style |
1528 |
/** |
1528 |
* the style to affect, should be <code>null</code>. |
1529 |
* {@inheritDoc} |
1529 |
*/ |
1530 |
* |
1530 |
private SetStyleSwitch(final Style style) { |
1531 |
* @see org.eclipse.sirius.diagram.util.DiagramSwitch#caseDNode(org.eclipse.sirius.diagram.DNode) |
1531 |
this.style = style; |
1532 |
*/ |
1532 |
} |
1533 |
@Override |
1533 |
|
1534 |
public Object caseDNode(final DNode object) { |
1534 |
@Override |
1535 |
object.setOwnedStyle((NodeStyle) this.style); |
1535 |
public Object caseDEdge(final DEdge object) { |
1536 |
return null; |
1536 |
object.setOwnedStyle((EdgeStyle) this.style); |
1537 |
} |
1537 |
return null; |
1538 |
|
1538 |
} |
1539 |
/** |
1539 |
|
1540 |
* {@inheritDoc} |
1540 |
/** |
1541 |
* |
1541 |
* {@inheritDoc} |
1542 |
* @see org.eclipse.sirius.diagram.util.DiagramSwitch#caseDNodeListElement(org.eclipse.sirius.diagram.DNodeListElement) |
1542 |
* |
1543 |
*/ |
1543 |
* @see org.eclipse.sirius.diagram.util.DiagramSwitch#caseDNode(org.eclipse.sirius.diagram.DNode) |
1544 |
@Override |
1544 |
*/ |
1545 |
public Object caseDNodeListElement(final DNodeListElement object) { |
1545 |
@Override |
1546 |
object.setOwnedStyle((NodeStyle) this.style); |
1546 |
public Object caseDNode(final DNode object) { |
1547 |
return null; |
1547 |
object.setOwnedStyle((NodeStyle) this.style); |
1548 |
} |
1548 |
return null; |
1549 |
|
1549 |
} |
1550 |
/** |
1550 |
|
1551 |
* {@inheritDoc} |
1551 |
/** |
1552 |
* |
1552 |
* {@inheritDoc} |
1553 |
* @see org.eclipse.sirius.diagram.util.DiagramSwitch#caseDNodeContainer(org.eclipse.sirius.diagram.DNodeContainer) |
1553 |
* |
1554 |
*/ |
1554 |
* @see org.eclipse.sirius.diagram.util.DiagramSwitch#caseDNodeListElement(org.eclipse.sirius.diagram.DNodeListElement) |
1555 |
@Override |
1555 |
*/ |
1556 |
public Object caseDNodeContainer(final DNodeContainer object) { |
1556 |
@Override |
1557 |
object.setOwnedStyle((ContainerStyle) this.style); |
1557 |
public Object caseDNodeListElement(final DNodeListElement object) { |
1558 |
return null; |
1558 |
object.setOwnedStyle((NodeStyle) this.style); |
1559 |
} |
1559 |
return null; |
1560 |
|
1560 |
} |
1561 |
/** |
1561 |
|
1562 |
* {@inheritDoc} |
1562 |
/** |
1563 |
* |
1563 |
* {@inheritDoc} |
1564 |
* @see org.eclipse.sirius.diagram.util.DiagramSwitch#caseDNodeList(org.eclipse.sirius.diagram.DNodeList) |
1564 |
* |
1565 |
*/ |
1565 |
* @see org.eclipse.sirius.diagram.util.DiagramSwitch#caseDNodeContainer(org.eclipse.sirius.diagram.DNodeContainer) |
1566 |
@Override |
1566 |
*/ |
1567 |
public Object caseDNodeList(final DNodeList object) { |
1567 |
@Override |
1568 |
object.setOwnedStyle((ContainerStyle) this.style); |
1568 |
public Object caseDNodeContainer(final DNodeContainer object) { |
1569 |
return null; |
1569 |
object.setOwnedStyle((ContainerStyle) this.style); |
1570 |
} |
1570 |
return null; |
1571 |
|
1571 |
} |
1572 |
} |
1572 |
|
1573 |
|
1573 |
/** |
1574 |
/** |
1574 |
* {@inheritDoc} |
1575 |
* Switch to refresh the style of a diagram element. |
1575 |
* |
1576 |
* |
1576 |
* @see org.eclipse.sirius.diagram.util.DiagramSwitch#caseDNodeList(org.eclipse.sirius.diagram.DNodeList) |
1577 |
* @author <a href="mailto:laurent.redor@obeo.fr">Laurent Redor</a> |
1577 |
*/ |
1578 |
*/ |
1578 |
@Override |
1579 |
private final class RefreshStyleSwitch extends DiagramSwitch<Object> { |
1579 |
public Object caseDNodeList(final DNodeList object) { |
1580 |
Option<? extends Style> previousStyle = Options.newNone(); |
1580 |
object.setOwnedStyle((ContainerStyle) this.style); |
1581 |
|
1581 |
return null; |
1582 |
/** |
1582 |
} |
1583 |
* Default constructor. |
1583 |
|
1584 |
* |
1584 |
} |
1585 |
* @param previousStyle |
1585 |
|
1586 |
* |
1586 |
/** |
1587 |
*/ |
1587 |
* Switch to refresh the style of a diagram element. |
1588 |
private RefreshStyleSwitch() { |
1588 |
* |
1589 |
} |
1589 |
* @author <a href="mailto:laurent.redor@obeo.fr">Laurent Redor</a> |
1590 |
|
1590 |
*/ |
1591 |
/** |
1591 |
private final class RefreshStyleSwitch extends DiagramSwitch<Object> { |
1592 |
* Default constructor. |
1592 |
Option<? extends Style> previousStyle = Options.newNone(); |
1593 |
* |
1593 |
|
1594 |
* @param previousStyle |
1594 |
/** |
1595 |
* the previous style (if existing) to keep compatible |
1595 |
* Default constructor. |
1596 |
* customization. |
1596 |
* |
1597 |
* |
1597 |
* @param previousStyle |
1598 |
*/ |
1598 |
* |
1599 |
private RefreshStyleSwitch(Option<? extends Style> previousStyle) { |
1599 |
*/ |
1600 |
this.previousStyle = previousStyle; |
1600 |
private RefreshStyleSwitch() { |
1601 |
} |
1601 |
} |
1602 |
|
1602 |
|
1603 |
@Override |
1603 |
/** |
1604 |
public Object caseDEdge(final DEdge object) { |
1604 |
* Default constructor. |
1605 |
refreshStyle(object.getOwnedStyle(), previousStyle); |
1605 |
* |
1606 |
return null; |
1606 |
* @param previousStyle |
1607 |
} |
1607 |
* the previous style (if existing) to keep compatible |
1608 |
|
1608 |
* customization. |
1609 |
/** |
1609 |
* |
1610 |
* {@inheritDoc} |
1610 |
*/ |
1611 |
* |
1611 |
private RefreshStyleSwitch(Option<? extends Style> previousStyle) { |
1612 |
* @see org.eclipse.sirius.diagram.util.DiagramSwitch#caseDNode(org.eclipse.sirius.viewpoint.DNode) |
1612 |
this.previousStyle = previousStyle; |
1613 |
*/ |
1613 |
} |
1614 |
@Override |
1614 |
|
1615 |
public Object caseDNode(final DNode object) { |
1615 |
@Override |
1616 |
refreshStyle(object.getOwnedStyle(), previousStyle); |
1616 |
public Object caseDEdge(final DEdge object) { |
1617 |
return null; |
1617 |
refreshStyle(object.getOwnedStyle(), previousStyle); |
1618 |
} |
1618 |
return null; |
1619 |
|
1619 |
} |
1620 |
/** |
1620 |
|
1621 |
* {@inheritDoc} |
1621 |
/** |
1622 |
* |
1622 |
* {@inheritDoc} |
1623 |
* @see org.eclipse.sirius.diagram.util.DiagramSwitch#caseDNodeListElement(org.eclipse.sirius.viewpoint.DNodeListElement) |
1623 |
* |
1624 |
*/ |
1624 |
* @see org.eclipse.sirius.diagram.util.DiagramSwitch#caseDNode(org.eclipse.sirius.viewpoint.DNode) |
1625 |
@Override |
1625 |
*/ |
1626 |
public Object caseDNodeListElement(final DNodeListElement object) { |
1626 |
@Override |
1627 |
refreshStyle(object.getOwnedStyle(), previousStyle); |
1627 |
public Object caseDNode(final DNode object) { |
1628 |
return null; |
1628 |
refreshStyle(object.getOwnedStyle(), previousStyle); |
1629 |
} |
1629 |
return null; |
1630 |
|
1630 |
} |
1631 |
/** |
1631 |
|
1632 |
* {@inheritDoc} |
1632 |
/** |
1633 |
* |
1633 |
* {@inheritDoc} |
1634 |
* @see org.eclipse.sirius.diagram.util.DiagramSwitch#caseDNodeContainer(org.eclipse.sirius.viewpoint.DNodeContainer) |
1634 |
* |
1635 |
*/ |
1635 |
* @see org.eclipse.sirius.diagram.util.DiagramSwitch#caseDNodeListElement(org.eclipse.sirius.viewpoint.DNodeListElement) |
1636 |
@Override |
1636 |
*/ |
1637 |
public Object caseDNodeContainer(final DNodeContainer object) { |
1637 |
@Override |
1638 |
refreshStyle(object.getOwnedStyle(), previousStyle); |
1638 |
public Object caseDNodeListElement(final DNodeListElement object) { |
1639 |
return null; |
1639 |
refreshStyle(object.getOwnedStyle(), previousStyle); |
1640 |
} |
1640 |
return null; |
1641 |
|
1641 |
} |
1642 |
/** |
1642 |
|
1643 |
* {@inheritDoc} |
1643 |
/** |
1644 |
* |
1644 |
* {@inheritDoc} |
1645 |
* @see org.eclipse.sirius.diagram.util.DiagramSwitch#caseDNodeList(org.eclipse.sirius.viewpoint.DNodeList) |
1645 |
* |
1646 |
*/ |
1646 |
* @see org.eclipse.sirius.diagram.util.DiagramSwitch#caseDNodeContainer(org.eclipse.sirius.viewpoint.DNodeContainer) |
1647 |
@Override |
1647 |
*/ |
1648 |
public Object caseDNodeList(final DNodeList object) { |
1648 |
@Override |
1649 |
refreshStyle(object.getOwnedStyle(), previousStyle); |
1649 |
public Object caseDNodeContainer(final DNodeContainer object) { |
1650 |
return null; |
1650 |
refreshStyle(object.getOwnedStyle(), previousStyle); |
1651 |
} |
1651 |
return null; |
1652 |
|
1652 |
} |
1653 |
} |
1653 |
|
1654 |
|
1654 |
/** |
1655 |
/** |
1655 |
* {@inheritDoc} |
1656 |
* Set width and height from "SizeComputationExpression". |
1656 |
* |
1657 |
* |
1657 |
* @see org.eclipse.sirius.diagram.util.DiagramSwitch#caseDNodeList(org.eclipse.sirius.viewpoint.DNodeList) |
1658 |
* @param node |
1658 |
*/ |
1659 |
* Node |
1659 |
@Override |
1660 |
* @param style |
1660 |
public Object caseDNodeList(final DNodeList object) { |
1661 |
* Node style. May be <code>null</code> |
1661 |
refreshStyle(object.getOwnedStyle(), previousStyle); |
1662 |
*/ |
1662 |
return null; |
1663 |
public void setComputedSize(DNode node, NodeStyleDescription style) { |
1663 |
} |
1664 |
if (style != null && !StringUtil.isEmpty(style.getSizeComputationExpression())) { |
1664 |
|
1665 |
Integer computedSize = computeStyleSize(node.getTarget(), style); |
1665 |
} |
1666 |
safeSetComputedSize(node, computedSize); |
1666 |
|
1667 |
} |
1667 |
/** |
1668 |
} |
1668 |
* Set width and height from "SizeComputationExpression". |
1669 |
|
1669 |
* |
1670 |
private void safeSetComputedSize(DNode node, Integer computedSize) { |
1670 |
* @param node |
1671 |
if (computedSize.intValue() >= 0) { |
1671 |
* Node |
1672 |
if (!computedSize.equals(node.getWidth())) { |
1672 |
* @param style |
1673 |
node.setWidth(computedSize); |
1673 |
* Node style. May be <code>null</code> |
1674 |
} |
1674 |
*/ |
1675 |
if (!computedSize.equals(node.getHeight())) { |
1675 |
public void setComputedSize(DNode node, NodeStyleDescription style) { |
1676 |
node.setHeight(computedSize); |
1676 |
if (style != null && !StringUtil.isEmpty(style.getSizeComputationExpression())) { |
1677 |
} |
1677 |
Integer computedSize = computeStyleSize(node.getTarget(), style); |
1678 |
} |
1678 |
safeSetComputedSize(node, computedSize); |
1679 |
} |
1679 |
} |
1680 |
|
1680 |
} |
1681 |
/** |
1681 |
|
1682 |
* Compute node style description size. |
1682 |
private void safeSetComputedSize(DNode node, Integer computedSize) { |
1683 |
* |
1683 |
if (computedSize.intValue() >= 0) { |
1684 |
* @param target |
1684 |
if (!computedSize.equals(node.getWidth())) { |
1685 |
* Target object |
1685 |
node.setWidth(computedSize); |
1686 |
* @param nodeStyle |
1686 |
} |
1687 |
* Node style |
1687 |
if (!computedSize.equals(node.getHeight())) { |
1688 |
* @return Size. Cannot be <code>null</code>. |
1688 |
node.setHeight(computedSize); |
1689 |
*/ |
1689 |
} |
1690 |
private Integer computeStyleSize(final EObject target, final NodeStyleDescription nodeStyle) { |
1690 |
} |
1691 |
Integer computedSize = null; |
1691 |
} |
1692 |
try { |
1692 |
|
1693 |
computedSize = interpreter.evaluateInteger(target, nodeStyle.getSizeComputationExpression()); |
1693 |
private void safeSetComputedSizeForContainer(DDiagramElementContainer container, Integer computedSize) { |
1694 |
} catch (final EvaluationException e) { |
1694 |
if (computedSize.intValue() >= 0) { |
1695 |
RuntimeLoggerManager.INSTANCE.error(nodeStyle, StylePackage.eINSTANCE.getNodeStyleDescription_SizeComputationExpression(), e); |
1695 |
if (!computedSize.equals(container.getWidth())) { |
1696 |
} |
1696 |
container.setWidth(computedSize); |
1697 |
if (computedSize == null) { |
1697 |
} |
1698 |
try { |
1698 |
if (!computedSize.equals(container.getHeight())) { |
1699 |
computedSize = Integer.parseInt(StylePackage.eINSTANCE.getNodeStyleDescription_SizeComputationExpression().getDefaultValueLiteral()); |
1699 |
container.setHeight(computedSize); |
1700 |
} catch (NumberFormatException e) { |
1700 |
} |
1701 |
// Nothing, default magic number will be used. |
1701 |
} |
1702 |
RuntimeLoggerManager.INSTANCE.error(nodeStyle, StylePackage.eINSTANCE.getNodeStyleDescription_SizeComputationExpression(), e); |
1702 |
} |
1703 |
} |
1703 |
|
1704 |
} |
1704 |
/** |
1705 |
if (computedSize == null) { |
1705 |
* Compute node style description size. |
1706 |
computedSize = DEFAULT_SIZE; |
1706 |
* |
1707 |
} |
1707 |
* @param target |
1708 |
return computedSize; |
1708 |
* Target object |
1709 |
} |
1709 |
* @param nodeStyle |
1710 |
|
1710 |
* Node style |
1711 |
} |
1711 |
* @return Size. Cannot be <code>null</code>. |
|
|
1712 |
*/ |
1713 |
private Integer computeStyleSize(final EObject target, final NodeStyleDescription nodeStyle) { |
1714 |
Integer computedSize = null; |
1715 |
try { |
1716 |
computedSize = interpreter.evaluateInteger(target, nodeStyle.getSizeComputationExpression()); |
1717 |
} catch (final EvaluationException e) { |
1718 |
RuntimeLoggerManager.INSTANCE.error(nodeStyle, StylePackage.eINSTANCE.getNodeStyleDescription_SizeComputationExpression(), e); |
1719 |
} |
1720 |
if (computedSize == null) { |
1721 |
try { |
1722 |
computedSize = Integer.parseInt(StylePackage.eINSTANCE.getNodeStyleDescription_SizeComputationExpression().getDefaultValueLiteral()); |
1723 |
} catch (NumberFormatException e) { |
1724 |
// Nothing, default magic number will be used. |
1725 |
RuntimeLoggerManager.INSTANCE.error(nodeStyle, StylePackage.eINSTANCE.getNodeStyleDescription_SizeComputationExpression(), e); |
1726 |
} |
1727 |
} |
1728 |
if (computedSize == null) { |
1729 |
computedSize = DEFAULT_SIZE; |
1730 |
} |
1731 |
return computedSize; |
1732 |
} |
1733 |
|
1734 |
} |