Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: dea21632e013d310328c33d872c8fcbe7d484793 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/*
 * Copyright (c) 2007 Borland Software Corporation
 * 
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    bblajer (Borland) - initial API and implementation
 */

«IMPORT "http://www.eclipse.org/gmf/2006/GenModel"»
«IMPORT "http://www.eclipse.org/emf/2002/Ecore"»
«IMPORT "http://www.eclipse.org/emf/2002/GenModel"»

«DEFINE MarkerNavigationProvider FOR gmfgen::GenDiagram-»
«EXPAND xpt::Common::copyright FOR editorGen»
package «providersPackageName»;

«EXPAND xpt::Common::generatedClassComment»
public class «markerNavigationProviderClassName» implements org.eclipse.gmf.runtime.lite.validation.IValidationStateListener {
«EXPAND markerType-»
«EXPAND validationStateChanged-»
«EXPAND adjustMarker-»
«EXPAND adjustDiagnosticMarker-»
«EXPAND adjustConstraintMarker-»
«EXPAND addMarker-»

«EXPAND ReplaceMarkersJob-»
}
«ENDDEFINE»

«DEFINE markerType FOR gmfgen::GenDiagram-»
	«EXPAND xpt::Common::generatedMemberComment»
	public static final String MARKER_TYPE = «editorGen.plugin.getActivatorQualifiedClassName()».ID + ".diagnostic"; «EXPAND xpt::Common::nonNLS»
«ENDDEFINE»

«DEFINE validationStateChanged FOR gmfgen::GenDiagram-»
	«EXPAND xpt::Common::generatedMemberComment»
	public void validationStateChanged(org.eclipse.gmf.runtime.lite.validation.ValidationStateEvent event) {
		org.eclipse.emf.common.util.URI diagramUri = event.getSourceValidationState().getDiagramUri();
		org.eclipse.core.resources.IFile file = org.eclipse.emf.workspace.util.WorkspaceSynchronizer.getFile(new org.eclipse.emf.ecore.resource.impl.ResourceImpl(diagramUri));
		if (file != null && file.exists()) {
			new ReplaceMarkersJob(file, event).schedule();
		}
	}
«ENDDEFINE»

«DEFINE adjustMarker FOR gmfgen::GenDiagram-»
	«EXPAND xpt::Common::generatedMemberComment»
	public static void adjustMarker(org.eclipse.core.resources.IMarker marker, Object referent) {
		if (referent instanceof org.eclipse.emf.common.util.Diagnostic) {
			adjustMarker(marker, (org.eclipse.emf.common.util.Diagnostic) referent);
		} else if (referent instanceof org.eclipse.emf.validation.model.IConstraintStatus) {
			adjustMarker(marker, (org.eclipse.emf.validation.model.IConstraintStatus) referent);
		} else {
		}
	}
«ENDDEFINE»

«DEFINE adjustDiagnosticMarker FOR gmfgen::GenDiagram-»
	«EXPAND xpt::Common::generatedMemberComment»
	public static void adjustMarker(org.eclipse.core.resources.IMarker marker, org.eclipse.emf.common.util.Diagnostic sourceDiagnostic) {
		assert marker != null && sourceDiagnostic != null;
	}
«ENDDEFINE»

«DEFINE adjustConstraintMarker FOR gmfgen::GenDiagram-»
	«EXPAND xpt::Common::generatedMemberComment»
	public static void adjustMarker(org.eclipse.core.resources.IMarker marker, org.eclipse.emf.validation.model.IConstraintStatus sourceStatus) {
		assert marker != null && sourceStatus != null;
	}
«ENDDEFINE»

«DEFINE addMarker FOR gmfgen::GenDiagram-»
	«EXPAND xpt::Common::generatedMemberComment»
	private static org.eclipse.core.resources.IMarker addMarker(org.eclipse.core.resources.IFile file, org.eclipse.emf.common.util.URI diagramUri, org.eclipse.emf.common.util.URI viewUri, String message, int statusSeverity) {
		org.eclipse.core.resources.IMarker marker = null;
		try {
			marker = file.createMarker(MARKER_TYPE);
			marker.setAttribute(org.eclipse.core.resources.IMarker.MESSAGE, message);
			marker.setAttribute(org.eclipse.core.resources.IMarker.LOCATION, diagramUri.toString());
			marker.setAttribute(org.eclipse.emf.ecore.EValidator.URI_ATTRIBUTE, viewUri.toString());
			int markerSeverity = org.eclipse.core.resources.IMarker.SEVERITY_INFO;
			if (statusSeverity == org.eclipse.core.runtime.IStatus.WARNING) {
				markerSeverity = org.eclipse.core.resources.IMarker.SEVERITY_WARNING;
			} else if (statusSeverity == org.eclipse.core.runtime.IStatus.ERROR || statusSeverity == org.eclipse.core.runtime.IStatus.CANCEL) {
				markerSeverity = org.eclipse.core.resources.IMarker.SEVERITY_ERROR;
			}
			marker.setAttribute(org.eclipse.core.resources.IMarker.SEVERITY, markerSeverity);
		} catch (org.eclipse.core.runtime.CoreException e) {
			«editorGen.plugin.getActivatorQualifiedClassName()».getInstance().logError("Failed to create validation marker", e);
		}
		return marker;
	}
«ENDDEFINE»

«DEFINE ReplaceMarkersJob FOR gmfgen::GenDiagram-»
	«EXPAND xpt::Common::generatedClassComment»
	private static class ReplaceMarkersJob extends org.eclipse.core.resources.WorkspaceJob {
		«EXPAND xpt::Common::generatedMemberComment»
		private final java.util.Collection myDescriptorsToAdd;
		«EXPAND xpt::Common::generatedMemberComment»
		private final org.eclipse.core.resources.IFile myFile;
		«EXPAND xpt::Common::generatedMemberComment»
		private final org.eclipse.emf.common.util.URI myDiagramUri;
		«EXPAND xpt::Common::generatedMemberComment»
		public ReplaceMarkersJob(org.eclipse.core.resources.IFile file, org.eclipse.gmf.runtime.lite.validation.ValidationStateEvent event) {
			super("Replace markers");
			setRule(file.getWorkspace().getRuleFactory().markerRule(file));
			myFile = file;
			myDiagramUri = event.getSourceValidationState().getDiagramUri();
			myDescriptorsToAdd = new java.util.ArrayList();
			for (java.util.Iterator it = event.getViolationKeys().iterator(); it.hasNext(); ) {
				org.eclipse.emf.common.util.URI next = (org.eclipse.emf.common.util.URI) it.next();
				myDescriptorsToAdd.addAll(event.getNewViolations(next));
			}
		}

		«EXPAND xpt::Common::generatedMemberComment»
		public org.eclipse.core.runtime.IStatus runInWorkspace(org.eclipse.core.runtime.IProgressMonitor monitor) throws org.eclipse.core.runtime.CoreException {
			String expectedLocation = myDiagramUri.toString();
			org.eclipse.core.resources.IMarker[] markers = myFile.findMarkers(MARKER_TYPE, false, org.eclipse.core.resources.IResource.DEPTH_INFINITE);
			for (int i = 0; i < markers.length; i++) {
				org.eclipse.core.resources.IMarker next = markers[i];
				if (expectedLocation.equals(next.getAttribute(org.eclipse.core.resources.IMarker.LOCATION))) {
					next.delete();
				}
			}
			for (java.util.Iterator it = myDescriptorsToAdd.iterator(); it.hasNext(); ) {
				org.eclipse.gmf.runtime.lite.validation.ViolationDescriptor next = (org.eclipse.gmf.runtime.lite.validation.ViolationDescriptor) it.next();
				org.eclipse.core.resources.IMarker nextMarker = addMarker(myFile, myDiagramUri, next.getUri(), next.getMessage(), next.getSeverity().toStatusSeverity());
				if (nextMarker != null) {
					adjustMarker(nextMarker, next.getReferent());
				}
			}
			return org.eclipse.core.runtime.Status.OK_STATUS;
		}
	}
«ENDDEFINE»

Back to the top