From be4f78978faba3d3ceb88df02a7f93a2e09ff1e0 Mon Sep 17 00:00:00 2001 From: Kenji Hosokawa Date: Tue, 3 Aug 2021 18:42:39 +0900 Subject: Initial commit Bug-AGL: SPEC-4033 Signed-off-by: Kenji Hosokawa --- .../model/manager/GlobalIndexResourceSorter.java | 36 ++++ .../editor/model/manager/ResourceManager.xtend | 209 +++++++++++++++++++++ 2 files changed, 245 insertions(+) create mode 100644 rba.tool.editor/src/rba/tool/editor/model/manager/GlobalIndexResourceSorter.java create mode 100644 rba.tool.editor/src/rba/tool/editor/model/manager/ResourceManager.xtend (limited to 'rba.tool.editor/src/rba/tool/editor/model') diff --git a/rba.tool.editor/src/rba/tool/editor/model/manager/GlobalIndexResourceSorter.java b/rba.tool.editor/src/rba/tool/editor/model/manager/GlobalIndexResourceSorter.java new file mode 100644 index 0000000..559e9d5 --- /dev/null +++ b/rba.tool.editor/src/rba/tool/editor/model/manager/GlobalIndexResourceSorter.java @@ -0,0 +1,36 @@ +package rba.tool.editor.model.manager; + +import java.util.Comparator; + +import org.eclipse.emf.common.util.URI; +import org.eclipse.emf.ecore.resource.Resource; + +public class GlobalIndexResourceSorter implements Comparator { + + int sort(URI o1, URI o2) { + /* first compare folder */ + int size1 = o1.segmentCount() - 1; + int size2 = o2.segmentCount() - 1; + for (int i = 0; i < size1 && i < size2; i++) { + int result = o1.segment(i).toLowerCase().compareTo(o2.segment(i).toLowerCase()); + if (result != 0) { + return result; + } + } + + if (size1 == size2) { + /* order of name that last segment(file). */ + return o1.lastSegment().toLowerCase().compareTo(o2.lastSegment().toLowerCase()); + } else if (size1 > size2) { + /* prioritize folder over file */ + return -1; + } else { + return 1; + } + } + + @Override + public int compare(Resource o1, Resource o2) { + return sort(o1.getURI(), o2.getURI()); + } +} diff --git a/rba.tool.editor/src/rba/tool/editor/model/manager/ResourceManager.xtend b/rba.tool.editor/src/rba/tool/editor/model/manager/ResourceManager.xtend new file mode 100644 index 0000000..856eada --- /dev/null +++ b/rba.tool.editor/src/rba/tool/editor/model/manager/ResourceManager.xtend @@ -0,0 +1,209 @@ +package rba.tool.editor.model.manager + +import com.google.common.collect.Iterables +import java.util.List +import org.eclipse.emf.ecore.EObject +import org.eclipse.emf.ecore.resource.Resource +import org.eclipse.emf.ecore.resource.ResourceSet +import org.eclipse.xtext.EcoreUtil2 +import org.eclipse.xtext.xbase.lib.Functions.Function1 +import rba.core.Allocatable +import rba.core.Constraint +import rba.core.Content +import rba.core.Expression +import rba.core.ExpressionType +import rba.core.NamedElement +import rba.core.Package +import rba.core.Scene +import rba.core.SetOfOperator +import rba.core.State +import rba.core.Variable +import rba.sound.SoundContent +import rba.sound.SoundContentSet +import rba.sound.Zone +import rba.sound.ZoneSet +import rba.tool.editor.rbaEditorModel.TopLevel +import rba.view.Area +import rba.view.AreaSet +import rba.view.Display +import rba.view.PositionContainer +import rba.view.Size +import rba.view.ViewContent +import rba.view.ViewContentSet +import rba.core.Tag +import rba.core.Stereotype + +class ResourceManager { + + public static ResourceManager INSTANCE = new ResourceManager(); + + private Function1 pseudoViewConstraintPredicate = [ e | + e.type === ExpressionType.CONTENT || e.type === ExpressionType.SET_OF_CONTENT || e.type === ExpressionType.AREA || e.type === ExpressionType.SET_OF_AREA + ]; + + private Function1 pseudoSoundConstraintPredicate = [ e | + e.type === ExpressionType.SOUND || e.type === ExpressionType.SET_OF_SOUND || e.type === ExpressionType.ZONE || e.type === ExpressionType.SET_OF_ZONE + ]; + + private Function1 generalConstraintPredicate = [ e | + e.type === ExpressionType.SCENE || e.type === ExpressionType.PROPERTY || e.type === ExpressionType.BOOLEAN || e.type === ExpressionType.VALUE || + e.type === ExpressionType.LAMBDA + ]; + + private new() { + } + + def private List filter(ResourceSet set, Class filterClass) { + return set.resources.sort.map(r|r.allContents.toIterable.filter(filterClass)).flatten.toList; + } + + def private List sort(List list) { + return list.sortWith(new GlobalIndexResourceSorter()); + } + + def public List getNamedElement(ResourceSet resourceSet) { + val elements = resourceSet.resources.sort.map(r|r.allContents.toIterable.filter(NamedElement)).flatten; + return elements.toList; + } + + def public List getRbaAllocatables(ResourceSet resourceSet) { + val allAllocatables = resourceSet.resources.sort.map(r|r.allContents.toIterable.filter(Allocatable)).flatten; + return allAllocatables.toList; + } + + def public List getRbaAreas(ResourceSet resourceSet) { + val allAreas = resourceSet.resources.sort.map(r|r.allContents.toIterable.filter(Area)).flatten; + return allAreas.toList; + } + + def public List getRbaZones(ResourceSet resourceSet) { + return filter(resourceSet, Zone); + } + + def public List getRbaAreaSets(ResourceSet resourceSet) { + val allAreaSets = resourceSet.resources.sort.map(r|r.allContents.toIterable.filter(AreaSet)).flatten; + return allAreaSets.toList; + } + + def public List getRbaZoneSets(ResourceSet resourceSet) { + val allZoneSets = resourceSet.resources.sort.map(r|r.allContents.toIterable.filter(ZoneSet)).flatten; + return allZoneSets.toList; + } + + def public List getRbaContents(ResourceSet resourceSet) { + val allContents = resourceSet.resources.sort.map(r|r.allContents.toIterable.filter(Content)).flatten; + return allContents.toList; + } + + def public List getRbaViewContents(ResourceSet resourceSet) { + val allContents = resourceSet.resources.sort.map(r|r.allContents.toIterable.filter(ViewContent)).flatten; + return allContents.toList; + } + + def public List getRbaViewContentSets(ResourceSet resourceSet) { + val allContentSets = resourceSet.resources.sort.map(r|r.allContents.toIterable.filter(ViewContentSet)).flatten; + return allContentSets.toList; + } + + def public List getRbaSoundContentSets(ResourceSet resourceSet) { + val allContentSets = resourceSet.resources.sort.map(r|r.allContents.toIterable.filter(SoundContentSet)).flatten; + return allContentSets.toList; + } + + def public List getRbaSoundContents(ResourceSet resourceSet) { + return filter(resourceSet, SoundContent); + } + + def public List getRbaState(ResourceSet resourceSet) { + val allStates = resourceSet.resources.sort.map(r|r.allContents.toIterable.filter(State)).flatten; + return allStates.toList; + } + + def public List getRbaScenes(ResourceSet resourceSet) { + val allScenes = resourceSet.resources.sort.map(r|r.allContents.toIterable.filter(Scene)).flatten; + return allScenes.toList; + } + + def public List getRbaSizes(ResourceSet resourceSet) { + val allSizes = resourceSet.resources.sort.map(r|r.allContents.toIterable.filter(Size)).flatten; + return allSizes.toList; + } + + def public List getRbaDisplays(ResourceSet resourceSet) { + val allDisplays = resourceSet.resources.sort.map(r|r.allContents.toIterable.filter(Display)).flatten; + return allDisplays.toList; + } + + def public List getRbaPositionContainers(ResourceSet resourceSet) { + val allPositionContainers = resourceSet.resources.sort.map(r|r.allContents.toIterable.filter(PositionContainer)).flatten; + return allPositionContainers.toList; + } + + def public List getRbaPackages(ResourceSet resourceSet) { + val allPackages = resourceSet.resources.sort.map(r|r.allContents.toIterable.filter(Package)).flatten; + return allPackages.toList; + } + + def public List getRbaRootPackages(ResourceSet resourceSet) { + val allPackages = resourceSet.resources.sort.map(r|r.allContents.toIterable.filter(Package).filter(package|package.eContainer instanceof TopLevel)).flatten; + return allPackages.toList; + } + + def public List getRbaConstraints(ResourceSet resourceSet) { + val allConstraints = resourceSet.resources.sort.map(r|r.allContents.toIterable.filter(Constraint)).flatten; + return allConstraints.toList; + } + + def public List getRbaOnlineConstraints(ResourceSet resourceSet) { + val allOnlineConstraints = getRbaConstraints(resourceSet).filter(c|c.runtime === true); + return allOnlineConstraints.toList; + } + + def public List getRbaOfflineConstraints(ResourceSet resourceSet) { + val allOfflineConstraints = getRbaConstraints(resourceSet).reject(c|c.runtime === true); + return allOfflineConstraints.toList; + } + + def public List getRbaViewConstraints(ResourceSet resourceSet) { + val allOnlineconstraints = getRbaOnlineConstraints(resourceSet); + val allPseudoViewConstraints = allOnlineconstraints.filter(c|EcoreUtil2.getAllContentsOfType(c, Expression).exists(pseudoViewConstraintPredicate)); + val allGeneralConstraints = allOnlineconstraints.filter(c|EcoreUtil2.getAllContentsOfType(c, Expression).forall(generalConstraintPredicate)); + val allViewConstraints = Iterables.concat(allPseudoViewConstraints, allGeneralConstraints).toList; + val allOrderedViewConstraints = allOnlineconstraints.filter(c|allViewConstraints.contains(c)); + return allOrderedViewConstraints.toList; + } + + def public List getRbaSoundConstraints(ResourceSet resourceSet) { + val allOnlineconstraints = getRbaOnlineConstraints(resourceSet); + val allPseudoSoundConstraints = allOnlineconstraints.filter(c|EcoreUtil2.getAllContentsOfType(c, Expression).exists(pseudoSoundConstraintPredicate)); + val allGeneralConstraints = allOnlineconstraints.filter(c|EcoreUtil2.getAllContentsOfType(c, Expression).forall(generalConstraintPredicate)); + val allSoundConstraints = Iterables.concat(allPseudoSoundConstraints, allGeneralConstraints).toList; + val allOrderedSoundConstraints = allOnlineconstraints.filter(c|allSoundConstraints.contains(c)); + return allOrderedSoundConstraints.toList; + } + + def public List getRbaVariables(ResourceSet resourceSet) { + val allVariables = resourceSet.resources.sort.map(r|r.allContents.toIterable.filter(Variable)).flatten; + return allVariables.toList; + } + + def public List getRbaSetOfOperators(ResourceSet resourceSet) { + val allSetOfOperators = resourceSet.resources.sort.map(r|r.allContents.toIterable.filter(SetOfOperator)).flatten; + return allSetOfOperators.toList; + } + + def public List getRbaTags(ResourceSet resourceSet) { + val allSetOfOperators = resourceSet.resources.sort.map(r|r.allContents.toIterable.filter(Tag)).flatten; + return allSetOfOperators.toList; + } + + def public List getRbaStereotypes(ResourceSet resourceSet) { + val allSetOfOperators = resourceSet.resources.sort.map(r|r.allContents.toIterable.filter(Stereotype)).flatten; + return allSetOfOperators.toList; + } + + def public List getRbaAllContents(ResourceSet resourceSet) { + val allContents = resourceSet.resources.sort.map(r|r.allContents.toIterable.filter(EObject)).flatten; + return allContents.toList; + } +} -- cgit 1.2.3-korg