summaryrefslogtreecommitdiffstats
path: root/rba.tool.editor/src/rba/tool/editor/validation/ContentAllocatableListValidationHelper.xtend
diff options
context:
space:
mode:
authorKenji Hosokawa <khosokawa@jp.adit-jv.com>2021-08-03 18:42:39 +0900
committerKenji Hosokawa <khosokawa@jp.adit-jv.com>2021-08-06 19:32:38 +0900
commitbe4f78978faba3d3ceb88df02a7f93a2e09ff1e0 (patch)
tree1f3f1a96251ac4f655c8a96fc33d5d4ee779cd06 /rba.tool.editor/src/rba/tool/editor/validation/ContentAllocatableListValidationHelper.xtend
parent71ca7c6cab863767ef30c8bd05b2bbfda8731cb5 (diff)
Initial commit
Bug-AGL: SPEC-4033 Signed-off-by: Kenji Hosokawa <khosokawa@jp.adit-jv.com>
Diffstat (limited to 'rba.tool.editor/src/rba/tool/editor/validation/ContentAllocatableListValidationHelper.xtend')
-rw-r--r--rba.tool.editor/src/rba/tool/editor/validation/ContentAllocatableListValidationHelper.xtend105
1 files changed, 105 insertions, 0 deletions
diff --git a/rba.tool.editor/src/rba/tool/editor/validation/ContentAllocatableListValidationHelper.xtend b/rba.tool.editor/src/rba/tool/editor/validation/ContentAllocatableListValidationHelper.xtend
new file mode 100644
index 0000000..d9f1911
--- /dev/null
+++ b/rba.tool.editor/src/rba/tool/editor/validation/ContentAllocatableListValidationHelper.xtend
@@ -0,0 +1,105 @@
+package rba.tool.editor.validation
+
+import com.google.inject.Inject
+import org.eclipse.emf.common.util.URI
+import org.eclipse.emf.ecore.EObject
+import org.eclipse.emf.ecore.EStructuralFeature
+import org.eclipse.emf.ecore.resource.Resource
+import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl
+import org.eclipse.xtext.resource.IResourceServiceProvider
+import org.eclipse.xtext.resource.impl.ResourceDescriptionsProvider
+import org.eclipse.xtext.service.OperationCanceledManager
+import org.eclipse.xtext.util.CancelIndicator
+import org.eclipse.xtext.validation.ValidationMessageAcceptor
+import rba.core.AbstractContent
+import rba.core.RBACorePackage
+import rba.sound.SoundContent
+import rba.tool.editor.messages.Messages
+import rba.tool.editor.resource.IRBAModelResourceLoader
+import rba.view.ViewContent
+
+class ContentAllocatableListValidationHelper {
+
+ @Inject
+ private IResourceServiceProvider.Registry resourceServiceProviderRegistry = IResourceServiceProvider.Registry.INSTANCE;
+
+ @Inject
+ private ResourceDescriptionsProvider resourceDescriptionsProvider;
+
+ @Inject
+ private IRBAModelResourceLoader resourceLoader;
+
+ @Inject
+ private ResourceSetImpl resourceSet;
+
+ @Inject
+ private OperationCanceledManager operationCanceledManager = new OperationCanceledManager();
+
+ private String CONTENT_ALLOCATABLE_SIZE = Messages.CONTENT_ALLOCATABLE_SIZE;
+
+ private String SOUND_ALLOCATABLE_SIZE = Messages.SOUND_ALLOCATABLE_SIZE;
+
+ def public void checkCrossReferenceEmpty(Resource resource, CancelIndicator cancelIndicator, ValidationMessageAcceptor acceptor) {
+ val resourceServiceProvider = resourceServiceProviderRegistry.getResourceServiceProvider(resource.getURI());
+ if (resourceServiceProvider === null) {
+ return;
+ }
+
+ demandGetResources(resource.getURI());
+ if (resourceSet === null) {
+ return;
+ }
+
+ val loadedResource = resourceSet.getResource(resource.getURI(), false);
+ if (loadedResource !== null) {
+ checkForAbstractContent_getAllocatableList(loadedResource, cancelIndicator, acceptor);
+ }
+ }
+
+ def private void demandGetResources(URI uri) {
+ if (!resourceSet.resources.isEmpty()) {
+ resourceSet.resources.clear();
+ }
+
+ val projectName = if (uri.segmentCount > 2) URI.decode(uri.segment(1)) else "";
+ val resourceDescriptions = resourceDescriptionsProvider.createResourceDescriptions();
+ val URIs = resourceDescriptions.allResourceDescriptions.map(d|d.URI).filter(u|projectName.equals(if (u.segmentCount > 2) URI.decode(u.segment(1)) else null));
+ resourceLoader.loadAndResolveResource(resourceSet, URIs, null);
+ }
+
+ def protected void checkForAbstractContent_getAllocatableList(Resource resource, CancelIndicator cancelIndicator, ValidationMessageAcceptor acceptor) {
+ resource.allContents.toIterable.filter(ViewContent).forEach [ viewContent |
+ if (viewContent.allocatableList.isEmpty) {
+ val feature = getContainmentFeature(viewContent);
+ if (feature !== null) {
+ acceptor.acceptError(String.format(CONTENT_ALLOCATABLE_SIZE, viewContent.name), viewContent, feature, ValidationMessageAcceptor.INSIGNIFICANT_INDEX,
+ getErrorCode());
+ }
+ }
+ operationCanceledManager.checkCanceled(cancelIndicator);
+ ];
+ resource.allContents.toIterable.filter(SoundContent).forEach [ soundContent |
+ if (soundContent.allocatableList.isEmpty) {
+ val feature = getContainmentFeature(soundContent);
+ if (feature !== null) {
+ acceptor.acceptError(String.format(SOUND_ALLOCATABLE_SIZE, soundContent.name), soundContent, feature, ValidationMessageAcceptor.INSIGNIFICANT_INDEX,
+ getErrorCode());
+ }
+ }
+ operationCanceledManager.checkCanceled(cancelIndicator);
+ ];
+ }
+
+ def protected EStructuralFeature getContainmentFeature(EObject object) {
+ switch (object) {
+ AbstractContent:
+ return RBACorePackage.Literals.ABSTRACT_CONTENT__ALLOCATABLE
+ default:
+ return null
+ }
+ }
+
+ def protected String getErrorCode() {
+ return null;
+ }
+}