summaryrefslogtreecommitdiffstats
path: root/rba.tool.editor.ui/src/rba/tool/editor/ui/marker/RBAModelResourceUIValidatorExtension.xtend
blob: cbb9b510d5bc65ce2fd6159c6a29f9a6f09ffc85 (plain)
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
package rba.tool.editor.ui.marker

import org.eclipse.core.resources.IFile
import org.eclipse.core.resources.IFolder
import org.eclipse.core.resources.IMarker
import org.eclipse.core.resources.IResource
import org.eclipse.core.runtime.CoreException
import org.eclipse.core.runtime.IProgressMonitor
import org.eclipse.core.runtime.OperationCanceledException
import org.eclipse.emf.ecore.resource.Resource
import org.eclipse.xtext.ui.validation.DefaultResourceUIValidatorExtension
import org.eclipse.xtext.validation.CheckMode
import rba.tool.editor.util.RBAModelEditorNameUtil

class RBAModelResourceUIValidatorExtension extends DefaultResourceUIValidatorExtension {

	private var path = new String

	override updateValidationMarkers(IFile file, Resource resource, CheckMode mode,
		IProgressMonitor monitor) throws OperationCanceledException {
		path = new String
		var exist = existInBuildFolder(file.parent)
		if (exist) {
			if (!path.equals("")) {
				path = "model" + "//" + path
			} else {
				path = "model"
			}
			val p = file.project
			val d = p.getFolder(path)
			val f = d.getFile(file.name)
			super.updateValidationMarkers(f, resource, mode, monitor)
		}
	}

	def boolean existInBuildFolder(IResource res) {
		if (res instanceof IFolder) {
			if (res.name.equals(RBAModelEditorNameUtil.BUILD_FOLDER_NAME)) {
				return true
			} else {
				if (!path.equals("")) {
					path = res.name + "//" + path
				} else {
					path = res.name
				}
				return existInBuildFolder(res.parent)
			}
		}
		return false
	}

	override deleteValidationMarkers(IFile file, CheckMode checkMode, IProgressMonitor monitor) {
		path = new String
		var exist = existInBuildFolder(file.parent)
		if (exist) {
			if (!path.equals("")) {
				path += "model" + "//" + path
			} else {
				path = "model"
			}
			val p = file.project
			val d = p.getFolder(path)
			val f = d.getFile(file.name)
			super.deleteValidationMarkers(f, checkMode, monitor)
		}
	}
}