Lines 11-53
Link Here
|
11 |
* Ansgar Radermacher (CEA LIST) - added support for EMF validation |
11 |
* Ansgar Radermacher (CEA LIST) - added support for EMF validation |
12 |
* bug fix and re-factoring (separating common class) |
12 |
* bug fix and re-factoring (separating common class) |
13 |
* specific version for Papyrus |
13 |
* specific version for Papyrus |
|
|
14 |
* Amine EL KOUHEN (CEA LIST) - Added decoration Service |
14 |
*/ |
15 |
*/ |
15 |
package org.eclipse.papyrus.diagram.common.providers; |
16 |
package org.eclipse.papyrus.diagram.common.providers; |
16 |
|
17 |
|
17 |
import static org.eclipse.papyrus.core.Activator.log; |
18 |
import static org.eclipse.papyrus.core.Activator.log; |
18 |
|
19 |
|
19 |
import java.util.HashMap; |
20 |
import java.util.HashMap; |
20 |
import java.util.Map; |
21 |
import java.util.Map; |
|
|
22 |
import java.util.Observable; |
23 |
import java.util.Observer; |
21 |
|
24 |
|
22 |
import org.eclipse.core.resources.IFile; |
|
|
23 |
import org.eclipse.core.resources.IMarker; |
24 |
import org.eclipse.core.resources.IResource; |
25 |
import org.eclipse.core.runtime.CoreException; |
26 |
import org.eclipse.draw2d.FlowLayout; |
27 |
import org.eclipse.draw2d.Label; |
25 |
import org.eclipse.draw2d.Label; |
28 |
import org.eclipse.emf.common.util.BasicEList; |
|
|
29 |
import org.eclipse.emf.common.util.EList; |
30 |
import org.eclipse.emf.ecore.EObject; |
31 |
import org.eclipse.emf.ecore.EValidator; |
32 |
import org.eclipse.emf.transaction.TransactionalEditingDomain; |
26 |
import org.eclipse.emf.transaction.TransactionalEditingDomain; |
33 |
import org.eclipse.emf.transaction.util.TransactionUtil; |
27 |
import org.eclipse.emf.transaction.util.TransactionUtil; |
34 |
import org.eclipse.emf.workspace.util.WorkspaceSynchronizer; |
|
|
35 |
import org.eclipse.gef.EditPart; |
28 |
import org.eclipse.gef.EditPart; |
36 |
import org.eclipse.gmf.runtime.common.core.service.AbstractProvider; |
29 |
import org.eclipse.gmf.runtime.common.core.service.AbstractProvider; |
37 |
import org.eclipse.gmf.runtime.common.core.service.IOperation; |
30 |
import org.eclipse.gmf.runtime.common.core.service.IOperation; |
38 |
import org.eclipse.gmf.runtime.common.ui.resources.FileChangeManager; |
|
|
39 |
import org.eclipse.gmf.runtime.common.ui.resources.IFileObserver; |
40 |
import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil; |
31 |
import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil; |
|
|
32 |
import org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramEditDomain; |
41 |
import org.eclipse.gmf.runtime.diagram.ui.services.decorator.AbstractDecorator; |
33 |
import org.eclipse.gmf.runtime.diagram.ui.services.decorator.AbstractDecorator; |
|
|
34 |
import org.eclipse.gmf.runtime.diagram.ui.services.decorator.IDecoration; |
42 |
import org.eclipse.gmf.runtime.diagram.ui.services.decorator.IDecorator; |
35 |
import org.eclipse.gmf.runtime.diagram.ui.services.decorator.IDecorator; |
43 |
import org.eclipse.gmf.runtime.diagram.ui.services.decorator.IDecoratorProvider; |
36 |
import org.eclipse.gmf.runtime.diagram.ui.services.decorator.IDecoratorProvider; |
44 |
import org.eclipse.gmf.runtime.diagram.ui.services.decorator.IDecoratorTarget; |
37 |
import org.eclipse.gmf.runtime.diagram.ui.services.decorator.IDecoratorTarget; |
45 |
import org.eclipse.gmf.runtime.draw2d.ui.mapmode.MapModeUtil; |
38 |
import org.eclipse.gmf.runtime.draw2d.ui.mapmode.MapModeUtil; |
46 |
import org.eclipse.gmf.runtime.notation.Edge; |
39 |
import org.eclipse.gmf.runtime.notation.Edge; |
47 |
import org.eclipse.gmf.runtime.notation.View; |
40 |
import org.eclipse.gmf.runtime.notation.View; |
48 |
import org.eclipse.papyrus.diagram.common.util.CrossReferencerUtil; |
41 |
import org.eclipse.jface.resource.ImageDescriptor; |
49 |
import org.eclipse.papyrus.validation.ValidationUtils; |
42 |
import org.eclipse.papyrus.core.services.ServicesRegistry; |
50 |
import org.eclipse.swt.graphics.Image; |
43 |
import org.eclipse.papyrus.decoration.DecorationService; |
|
|
44 |
import org.eclipse.papyrus.diagram.common.util.ServiceUtilsForGMF; |
51 |
import org.eclipse.ui.ISharedImages; |
45 |
import org.eclipse.ui.ISharedImages; |
52 |
import org.eclipse.ui.PlatformUI; |
46 |
import org.eclipse.ui.PlatformUI; |
53 |
|
47 |
|
Lines 56-87
Link Here
|
56 |
*/ |
50 |
*/ |
57 |
public abstract class ValidationDecoratorProvider extends AbstractProvider implements IDecoratorProvider { |
51 |
public abstract class ValidationDecoratorProvider extends AbstractProvider implements IDecoratorProvider { |
58 |
|
52 |
|
59 |
protected static final String KEY = "validationStatus"; //$NON-NLS-1$ |
53 |
protected static final String KEY = "validationStatus"; //$NON-NLS-1$ |
60 |
|
|
|
61 |
/** |
62 |
* generic marker for GMF validation (currently not used) |
63 |
*/ |
64 |
private static final String MARKER_TYPE = "org.eclipse.papyrus.diagram.common.diagnostic"; //$NON-NLS-1$ |
65 |
|
54 |
|
66 |
/** |
55 |
private static Map<String, IDecorator> allDecorators = new HashMap<String, IDecorator>(); |
67 |
* global map of fileObserver par editing domain |
|
|
68 |
*/ |
69 |
private static Map<TransactionalEditingDomain, MarkerObserver> fileObservers = new HashMap<TransactionalEditingDomain, MarkerObserver>(); |
70 |
|
56 |
|
71 |
private static Map<String, IDecorator> allDecorators = new HashMap<String, IDecorator> (); |
|
|
72 |
|
73 |
/** |
57 |
/** |
74 |
* Refined by generated class |
58 |
* Refined by generated class |
|
|
59 |
* |
75 |
* @see org.eclipse.gmf.runtime.diagram.ui.services.decorator.IDecoratorProvider#createDecorators(org.eclipse.gmf.runtime.diagram.ui.services.decorator.IDecoratorTarget) |
60 |
* @see org.eclipse.gmf.runtime.diagram.ui.services.decorator.IDecoratorProvider#createDecorators(org.eclipse.gmf.runtime.diagram.ui.services.decorator.IDecoratorTarget) |
76 |
* |
61 |
* |
77 |
* @param decoratorTarget |
62 |
* @param decoratorTarget |
78 |
*/ |
63 |
*/ |
79 |
public abstract void createDecorators (IDecoratorTarget decoratorTarget); |
64 |
public abstract void createDecorators(IDecoratorTarget decoratorTarget); |
80 |
|
65 |
|
81 |
/** |
66 |
/** |
82 |
* Refined by generated class |
67 |
* Refined by generated class |
|
|
68 |
* |
83 |
* @see org.eclipse.gmf.runtime.common.core.service.IProvider#provides(org.eclipse.gmf.runtime.common.core.service.IOperation) |
69 |
* @see org.eclipse.gmf.runtime.common.core.service.IProvider#provides(org.eclipse.gmf.runtime.common.core.service.IOperation) |
84 |
* |
70 |
* |
85 |
* @param operation |
71 |
* @param operation |
86 |
* @return |
72 |
* @return |
87 |
*/ |
73 |
*/ |
Lines 89-94
Link Here
|
89 |
|
75 |
|
90 |
/** |
76 |
/** |
91 |
* Refresh the decorators of a specific view |
77 |
* Refresh the decorators of a specific view |
|
|
78 |
* |
92 |
* @param view |
79 |
* @param view |
93 |
*/ |
80 |
*/ |
94 |
public static void refreshDecorators(View view) { |
81 |
public static void refreshDecorators(View view) { |
Lines 100-106
Link Here
|
100 |
*/ |
87 |
*/ |
101 |
private static void refreshDecorators(String viewId, final TransactionalEditingDomain domain) { |
88 |
private static void refreshDecorators(String viewId, final TransactionalEditingDomain domain) { |
102 |
final IDecorator decorator = viewId != null ? allDecorators.get(viewId) : null; |
89 |
final IDecorator decorator = viewId != null ? allDecorators.get(viewId) : null; |
103 |
if (decorator == null || domain == null) { |
90 |
if(decorator == null || domain == null) { |
104 |
return; |
91 |
return; |
105 |
} |
92 |
} |
106 |
PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() { |
93 |
PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() { |
Lines 120-126
Link Here
|
120 |
}); |
107 |
}); |
121 |
} |
108 |
} |
122 |
|
109 |
|
123 |
public static class StatusDecorator extends AbstractDecorator { |
110 |
public static class StatusDecorator extends AbstractDecorator implements Observer { |
124 |
|
111 |
|
125 |
/** |
112 |
/** |
126 |
* The ID of the view |
113 |
* The ID of the view |
Lines 133-144
Link Here
|
133 |
private TransactionalEditingDomain editingDomain; |
120 |
private TransactionalEditingDomain editingDomain; |
134 |
|
121 |
|
135 |
/** |
122 |
/** |
|
|
123 |
* Decoration Service |
124 |
*/ |
125 |
private DecorationService decorationService; |
126 |
|
127 |
/** |
128 |
* Diagram Decorator |
129 |
*/ |
130 |
private final DiagramDecorationAdapter diagramDecorationAdapter; |
131 |
|
132 |
/** |
136 |
* @generated |
133 |
* @generated |
137 |
*/ |
134 |
*/ |
138 |
public StatusDecorator(IDecoratorTarget decoratorTarget) { |
135 |
public StatusDecorator(IDecoratorTarget decoratorTarget) { |
139 |
super(decoratorTarget); |
136 |
super(decoratorTarget); |
|
|
137 |
diagramDecorationAdapter = new DiagramDecorationAdapter(decoratorTarget); |
140 |
try { |
138 |
try { |
141 |
final View view = (View)getDecoratorTarget().getAdapter(View.class); |
139 |
final View view = (View)getDecoratorTarget().getAdapter(View.class); |
|
|
140 |
EditPart editPart = (EditPart)getDecoratorTarget().getAdapter(EditPart.class); |
141 |
IDiagramEditDomain domain = (IDiagramEditDomain)editPart.getViewer().getEditDomain(); |
142 |
ServicesRegistry serviceRegistry = ServiceUtilsForGMF.getInstance().getServiceRegistry(domain); |
143 |
decorationService = serviceRegistry.getService(DecorationService.class); |
144 |
//Register As an Decoration service customer |
145 |
decorationService.addListener(this); |
142 |
TransactionUtil.getEditingDomain(view).runExclusive(new Runnable() { |
146 |
TransactionUtil.getEditingDomain(view).runExclusive(new Runnable() { |
143 |
|
147 |
|
144 |
public void run() { |
148 |
public void run() { |
Lines 157-162
Link Here
|
157 |
* @see org.eclipse.gmf.runtime.diagram.ui.services.decorator.IDecorator#refresh() |
161 |
* @see org.eclipse.gmf.runtime.diagram.ui.services.decorator.IDecorator#refresh() |
158 |
*/ |
162 |
*/ |
159 |
public void refresh() { |
163 |
public void refresh() { |
|
|
164 |
|
160 |
removeDecoration(); |
165 |
removeDecoration(); |
161 |
View view = (View)getDecoratorTarget().getAdapter(View.class); |
166 |
View view = (View)getDecoratorTarget().getAdapter(View.class); |
162 |
if(view == null || view.eResource() == null) { |
167 |
if(view == null || view.eResource() == null) { |
Lines 166-279
Link Here
|
166 |
if(editPart == null || editPart.getViewer() == null) { |
171 |
if(editPart == null || editPart.getViewer() == null) { |
167 |
return; |
172 |
return; |
168 |
} |
173 |
} |
169 |
|
|
|
170 |
// query for all the validation markers of the current resource |
171 |
String elementId = ViewUtil.getIdStr(view); |
172 |
if(elementId == null) { |
173 |
return; |
174 |
} |
175 |
int severity = IMarker.SEVERITY_INFO; |
176 |
IMarker foundMarker = null; |
177 |
IResource gmfResource = WorkspaceSynchronizer.getFile(view.eResource()); |
178 |
if(gmfResource == null || !gmfResource.exists()) { |
179 |
return; |
180 |
} |
181 |
IResource emfResource = null; |
182 |
if(view.getElement() != null) { |
183 |
emfResource = WorkspaceSynchronizer.getFile(view.getElement().eResource()); |
184 |
// allow emfResource being empty, since there might be gmf views without an EObject behind; |
185 |
} |
186 |
|
187 |
IMarker[] gmfMarkers = null; |
188 |
IMarker[] emfMarkers = new IMarker[0]; |
189 |
try { |
190 |
gmfMarkers = gmfResource.findMarkers(MARKER_TYPE, true, IResource.DEPTH_INFINITE); |
191 |
if(emfResource != null) { |
192 |
emfMarkers = emfResource.findMarkers(IMarker.PROBLEM, true, IResource.DEPTH_INFINITE); |
193 |
} |
194 |
} catch (CoreException e) { |
195 |
log.error("Validation markers refresh failure", e); //$NON-NLS-1$ |
196 |
} |
197 |
if(gmfMarkers == null) { |
198 |
// indicates an exception, findMarkers returns an empty array, if there are no markers |
199 |
return; |
200 |
} |
201 |
Label toolTip = null; |
202 |
// look for GMF markers |
203 |
for(int i = 0; i < gmfMarkers.length + emfMarkers.length; i++) { |
204 |
IMarker marker; |
205 |
boolean markerIsForMe = false; |
206 |
if(i < gmfMarkers.length) { |
207 |
// get marker from GMF list |
208 |
marker = gmfMarkers[i]; |
209 |
String attribute = marker.getAttribute(org.eclipse.gmf.runtime.common.ui.resources.IMarker.ELEMENT_ID, ""); //$NON-NLS-1$ |
210 |
markerIsForMe = attribute.equals(elementId); |
211 |
} else { |
212 |
// get marker from EMF list |
213 |
marker = emfMarkers[i - gmfMarkers.length]; |
214 |
EObject eObjectOfMarker = ValidationUtils.eObjectFromMarkerOrMap(marker, null, editingDomain); |
215 |
markerIsForMe = (eObjectOfMarker == view.getElement()); |
216 |
} |
217 |
if(markerIsForMe) { |
218 |
int nextSeverity = marker.getAttribute(IMarker.SEVERITY, IMarker.SEVERITY_INFO); |
219 |
Image nextImage = getImage(nextSeverity); |
220 |
if(foundMarker == null) { |
221 |
foundMarker = marker; |
222 |
toolTip = new Label(marker.getAttribute(IMarker.MESSAGE, ""), //$NON-NLS-1$ |
223 |
nextImage); |
224 |
} else { |
225 |
if(toolTip.getChildren().isEmpty()) { |
226 |
Label comositeLabel = new Label(); |
227 |
FlowLayout fl = new FlowLayout(false); |
228 |
fl.setMinorSpacing(0); |
229 |
comositeLabel.setLayoutManager(fl); |
230 |
comositeLabel.add(toolTip); |
231 |
toolTip = comositeLabel; |
232 |
} |
233 |
toolTip.add(new Label(marker.getAttribute(IMarker.MESSAGE, ""), //$NON-NLS-1$ |
234 |
nextImage)); |
235 |
} |
236 |
severity = (nextSeverity > severity) ? nextSeverity : severity; |
237 |
} |
238 |
} |
239 |
if(foundMarker == null) { |
240 |
return; |
241 |
} |
242 |
|
243 |
// add decoration |
174 |
// add decoration |
|
|
175 |
IDecoration deco = null; |
176 |
org.eclipse.papyrus.decoration.util.IDecoration decoration = null; |
244 |
if(editPart instanceof org.eclipse.gef.GraphicalEditPart) { |
177 |
if(editPart instanceof org.eclipse.gef.GraphicalEditPart) { |
|
|
178 |
decoration = decorationService.getDecoration(view.getElement(), false); |
179 |
decoration.setDecorationImage(getImageDescriptor(decoration.getSeverity())); |
245 |
if(view instanceof Edge) { |
180 |
if(view instanceof Edge) { |
246 |
setDecoration(getDecoratorTarget().addConnectionDecoration(getImage(severity), 50, true)); |
181 |
/* Test *///decoration.setDecorationImage(Activator.imageDescriptorFromPlugin(Activator.ID, "icons/obj16/Device.gif")); |
|
|
182 |
deco = diagramDecorationAdapter.setDecoration(decoration, 50, 0, true); |
247 |
} else { |
183 |
} else { |
248 |
int margin = -1; |
184 |
int margin = -1; |
249 |
if(editPart instanceof org.eclipse.gef.GraphicalEditPart) { |
185 |
if(editPart instanceof org.eclipse.gef.GraphicalEditPart) { |
250 |
margin = MapModeUtil.getMapMode(((org.eclipse.gef.GraphicalEditPart)editPart).getFigure()).DPtoLP(margin); |
186 |
margin = MapModeUtil.getMapMode(((org.eclipse.gef.GraphicalEditPart)editPart).getFigure()).DPtoLP(margin); |
251 |
} |
187 |
} |
252 |
setDecoration(getDecoratorTarget().addShapeDecoration(getImage(severity), IDecoratorTarget.Direction.NORTH_EAST, margin, true)); |
188 |
deco = diagramDecorationAdapter.setDecoration(decoration, 0, margin, true); |
253 |
} |
189 |
} |
|
|
190 |
} |
191 |
|
192 |
|
193 |
if(deco != null) { |
194 |
setDecoration(deco); |
195 |
String message = decoration.getMessage(); |
196 |
Label toolTip = diagramDecorationAdapter.getToolTip(message); |
254 |
getDecoration().setToolTip(toolTip); |
197 |
getDecoration().setToolTip(toolTip); |
255 |
} |
198 |
} |
256 |
} |
199 |
} |
257 |
|
200 |
|
258 |
|
201 |
private ImageDescriptor getImageDescriptor(int severity) { |
259 |
/** |
202 |
|
260 |
* Get the image for a given severity |
203 |
ISharedImages sharedImages = PlatformUI.getWorkbench().getSharedImages(); |
261 |
* @param severity |
204 |
ImageDescriptor overlay = null; |
262 |
* @return |
|
|
263 |
*/ |
264 |
private Image getImage(int severity) { |
265 |
String imageName = ISharedImages.IMG_OBJS_ERROR_TSK; |
266 |
switch(severity) { |
205 |
switch(severity) { |
267 |
case IMarker.SEVERITY_ERROR: |
206 |
case 2://Error |
268 |
imageName = ISharedImages.IMG_OBJS_ERROR_TSK; |
207 |
overlay = sharedImages.getImageDescriptor(ISharedImages.IMG_OBJS_ERROR_TSK); |
269 |
break; |
208 |
break; |
270 |
case IMarker.SEVERITY_WARNING: |
209 |
case 1://Warning |
271 |
imageName = ISharedImages.IMG_OBJS_WARN_TSK; |
210 |
overlay = sharedImages.getImageDescriptor(ISharedImages.IMG_OBJS_WARN_TSK); |
272 |
break; |
211 |
break; |
273 |
default: |
|
|
274 |
imageName = ISharedImages.IMG_OBJS_INFO_TSK; |
275 |
} |
212 |
} |
276 |
return PlatformUI.getWorkbench().getSharedImages().getImage(imageName); |
213 |
|
|
|
214 |
return overlay; |
277 |
} |
215 |
} |
278 |
|
216 |
|
279 |
/** |
217 |
/** |
Lines 287-315
Link Here
|
287 |
|
225 |
|
288 |
// add self to global decorators registry |
226 |
// add self to global decorators registry |
289 |
IDecorator decorator = allDecorators.get(viewId); |
227 |
IDecorator decorator = allDecorators.get(viewId); |
290 |
if (decorator == null) { |
228 |
if(decorator == null) { |
291 |
allDecorators.put(viewId, this); |
229 |
allDecorators.put(viewId, this); |
292 |
} |
230 |
} |
293 |
|
|
|
294 |
// stop listening to changes in resources if there are no more decorators |
295 |
MarkerObserver fileObserver = fileObservers.get(editingDomain); |
296 |
if (fileObserver == null) { |
297 |
fileObserver = new MarkerObserver(editingDomain); |
298 |
fileObservers.put(editingDomain, fileObserver); |
299 |
FileChangeManager.getInstance().addFileObserver(fileObserver); |
300 |
} |
301 |
// start listening to changes in resources |
302 |
View view = (View) getDecoratorTarget().getAdapter(View.class); |
303 |
if(view != null) { |
304 |
if (!fileObserver.views.contains(view)) { |
305 |
fileObserver.views.add(view); |
306 |
} |
307 |
} |
308 |
} |
231 |
} |
309 |
|
232 |
|
310 |
/** |
233 |
/** |
311 |
* deactivate the decorators of this view |
234 |
* deactivate the decorators of this view |
312 |
*/ |
235 |
*/ |
|
|
236 |
@Override |
313 |
public void deactivate() { |
237 |
public void deactivate() { |
314 |
if(viewId == null) { |
238 |
if(viewId == null) { |
315 |
return; |
239 |
return; |
Lines 317-445
Link Here
|
317 |
|
241 |
|
318 |
// remove self from global decorators registry |
242 |
// remove self from global decorators registry |
319 |
allDecorators.remove(viewId); |
243 |
allDecorators.remove(viewId); |
320 |
|
244 |
|
321 |
View view = (View)getDecoratorTarget().getAdapter(View.class); |
245 |
View view = (View)getDecoratorTarget().getAdapter(View.class); |
322 |
if ((view == null) || (editingDomain == null)) { |
246 |
if((view == null) || (editingDomain == null)) { |
323 |
// should not happen |
247 |
// should not happen |
324 |
super.deactivate(); |
248 |
super.deactivate(); |
325 |
return; |
249 |
return; |
326 |
} |
250 |
} |
327 |
|
|
|
328 |
// stop listening to changes in resources if there are no more decorators |
329 |
MarkerObserver fileObserver = fileObservers.get(editingDomain); |
330 |
if (fileObserver != null) { |
331 |
fileObserver.views.remove(view); |
332 |
if (fileObserver.views.isEmpty()) { |
333 |
// no more views registered for the listener => remove observer |
334 |
FileChangeManager.getInstance().removeFileObserver(fileObserver); |
335 |
fileObservers.remove(editingDomain); |
336 |
} |
337 |
} |
338 |
|
339 |
super.deactivate(); |
251 |
super.deactivate(); |
340 |
} |
252 |
} |
341 |
} |
|
|
342 |
|
253 |
|
343 |
/** |
254 |
//Refresh when the decoration service add a decoration |
344 |
* @generated |
255 |
public void update(Observable o, Object arg) { |
345 |
*/ |
256 |
refresh(); |
346 |
static class MarkerObserver implements IFileObserver { |
|
|
347 |
|
348 |
/** |
349 |
* store editing domain |
350 |
*/ |
351 |
private TransactionalEditingDomain domain; |
352 |
|
353 |
/** |
354 |
* store a list of all views for which the observer is responsible |
355 |
*/ |
356 |
private EList<View> views = new BasicEList<View>(); |
357 |
|
358 |
/** |
359 |
* Constructor. |
360 |
* |
361 |
* @param domain |
362 |
*/ |
363 |
private MarkerObserver(TransactionalEditingDomain domain) { |
364 |
this.domain = domain; |
365 |
} |
257 |
} |
366 |
|
|
|
367 |
/** |
368 |
* handle changes of file name |
369 |
*/ |
370 |
public void handleFileRenamed(IFile oldFile, IFile file) { |
371 |
} |
372 |
|
373 |
public void handleFileMoved(IFile oldFile, IFile file) { |
374 |
} |
375 |
|
376 |
public void handleFileDeleted(IFile file) { |
377 |
} |
378 |
|
379 |
public void handleFileChanged(IFile file) { |
380 |
} |
381 |
|
382 |
/** |
383 |
* A marker has been added, treat as change |
384 |
*/ |
385 |
public void handleMarkerAdded(IMarker marker) { |
386 |
handleMarkerChanged(marker); |
387 |
} |
388 |
|
389 |
/** |
390 |
* A marker has been deleted. Need to treat separately from change, since old values are not stored in |
391 |
* marker, but in attribute map |
392 |
*/ |
393 |
public void handleMarkerDeleted(IMarker marker, @SuppressWarnings("rawtypes") Map attributes) { |
394 |
String viewId = (String)attributes.get(org.eclipse.gmf.runtime.common.ui.resources.IMarker.ELEMENT_ID); |
395 |
if(viewId != null) { |
396 |
refreshDecorators(viewId, domain); |
397 |
} else { |
398 |
// no viewID => assume EMF validation marker |
399 |
EObject eObjectFromMarker = ValidationUtils.eObjectFromMarkerOrMap(null, attributes, domain); |
400 |
|
401 |
if(eObjectFromMarker != null) { |
402 |
// loop over all views that reference the eObject from the marker |
403 |
for(View view : CrossReferencerUtil.getCrossReferencingViews(eObjectFromMarker, null)) { |
404 |
refreshDecorators(view); |
405 |
} |
406 |
} |
407 |
} |
408 |
} |
409 |
|
410 |
/** |
411 |
* A marker has changed |
412 |
*/ |
413 |
public void handleMarkerChanged(IMarker marker) { |
414 |
try { |
415 |
if(getType(marker).equals(MARKER_TYPE)) { |
416 |
String viewId = marker.getAttribute(org.eclipse.gmf.runtime.common.ui.resources.IMarker.ELEMENT_ID, ""); //$NON-NLS-1$ |
417 |
refreshDecorators(viewId, domain); |
418 |
} else if(marker.isSubtypeOf((EValidator.MARKER))) { |
419 |
EObject eObjectFromMarker = ValidationUtils.eObjectFromMarkerOrMap(marker, null, domain); |
420 |
|
421 |
if(eObjectFromMarker != null) { |
422 |
// loop over all views that reference the eObject from the marker |
423 |
for(View view : CrossReferencerUtil.getCrossReferencingViews(eObjectFromMarker, null)) { |
424 |
refreshDecorators(view); |
425 |
} |
426 |
} |
427 |
} |
428 |
} catch (CoreException e) { |
429 |
// only reason: marker does not exist (ignore, should not happen) |
430 |
} |
431 |
} |
432 |
|
433 |
/** |
434 |
* Return the type of a marker |
435 |
*/ |
436 |
private String getType(IMarker marker) { |
437 |
try { |
438 |
return marker.getType(); |
439 |
} catch (CoreException e) { |
440 |
log.error("Validation marker refresh failure", e); //$NON-NLS-1$ |
441 |
return ""; //$NON-NLS-1$ |
442 |
} |
443 |
} |
444 |
} |
258 |
} |
|
|
259 |
|
445 |
} |
260 |
} |