diff --git a/plugins/org.polarsys.capella.filtering.tools/src/org/polarsys/capella/filtering/tools/Messages.java b/plugins/org.polarsys.capella.filtering.tools/src/org/polarsys/capella/filtering/tools/Messages.java index 32eadde4..6e15b584 100644 --- a/plugins/org.polarsys.capella.filtering.tools/src/org/polarsys/capella/filtering/tools/Messages.java +++ b/plugins/org.polarsys.capella.filtering.tools/src/org/polarsys/capella/filtering/tools/Messages.java @@ -67,7 +67,7 @@ public class Messages extends NLS { public static String FilteringDirtyReferencedModels_dialog_continue_without_saving; public static String FilteringDirtyReferencedModels_dialog_continue_with_saving; - public static String filtering_error_image_path_change; + public static String filteringErrorImagePathChange; static { // initialize resource bundle diff --git a/plugins/org.polarsys.capella.filtering.tools/src/org/polarsys/capella/filtering/tools/actions/FilteringExtractionJob.java b/plugins/org.polarsys.capella.filtering.tools/src/org/polarsys/capella/filtering/tools/actions/FilteringExtractionJob.java index e88a075f..1bff3fef 100644 --- a/plugins/org.polarsys.capella.filtering.tools/src/org/polarsys/capella/filtering/tools/actions/FilteringExtractionJob.java +++ b/plugins/org.polarsys.capella.filtering.tools/src/org/polarsys/capella/filtering/tools/actions/FilteringExtractionJob.java @@ -241,7 +241,7 @@ public void run() { try { wipc.perform(subMonitor); } catch (CoreException e) { - FilteringToolsPlugin.getDefault().getLog().error(NLS.bind(org.polarsys.capella.filtering.tools.Messages.filtering_error_image_path_change, clonedProject.getName()), e); + FilteringToolsPlugin.getDefault().getLog().error(NLS.bind(org.polarsys.capella.filtering.tools.Messages.filteringErrorImagePathChange, clonedProject.getName()), e); } } }); diff --git a/plugins/org.polarsys.capella.filtering.tools/src/org/polarsys/capella/filtering/tools/messages.properties b/plugins/org.polarsys.capella.filtering.tools/src/org/polarsys/capella/filtering/tools/messages.properties index 0e8b633f..0ba15868 100644 --- a/plugins/org.polarsys.capella.filtering.tools/src/org/polarsys/capella/filtering/tools/messages.properties +++ b/plugins/org.polarsys.capella.filtering.tools/src/org/polarsys/capella/filtering/tools/messages.properties @@ -43,4 +43,4 @@ FilteringDirtyReferencedModels_dialog_message=The following model(s): [{0}] must FilteringDirtyReferencedModels_dialog_continue_without_saving=Continue without Saving FilteringDirtyReferencedModels_dialog_continue_with_saving=Save and Continue -filtering_error_image_path_change=Error during WorkspaceImagePath update on derived project: {0} \ No newline at end of file +filteringErrorImagePathChange=Error during WorkspaceImagePath update on derived project: {0} \ No newline at end of file diff --git a/plugins/org.polarsys.capella.filtering.tools/src/org/polarsys/capella/filtering/tools/utils/FilteringUtils.java b/plugins/org.polarsys.capella.filtering.tools/src/org/polarsys/capella/filtering/tools/utils/FilteringUtils.java index d85f8441..e7994b6d 100644 --- a/plugins/org.polarsys.capella.filtering.tools/src/org/polarsys/capella/filtering/tools/utils/FilteringUtils.java +++ b/plugins/org.polarsys.capella.filtering.tools/src/org/polarsys/capella/filtering/tools/utils/FilteringUtils.java @@ -117,1304 +117,1288 @@ */ public class FilteringUtils { - private static final Logger logger = ReportManagerRegistry.getInstance() - .subscribe(IReportManagerDefaultComponents.DEFAULT); + private static final Logger logger = ReportManagerRegistry.getInstance().subscribe(IReportManagerDefaultComponents.DEFAULT); - public static Set computeDerivation(AbstractFilteringResult abstractFResult, EObject root) { + public static Set computeDerivation(AbstractFilteringResult abstractFResult, EObject root) { - Predicate predicate = computePredicate(abstractFResult); - Set derivation = computeDerivation(predicate, root); - return derivation; - } + Predicate predicate = computePredicate(abstractFResult); + Set derivation = computeDerivation(predicate, root); + return derivation; + } - private static Set computeDerivation(Predicate predicate, EObject root) { + private static Set computeDerivation(Predicate predicate, EObject root) { - Set result = new HashSet(); + Set result = new HashSet(); - if (null != root) { - if (predicate.test(root)) { - result.add(root); - } - TreeIterator it = root.eAllContents(); + if (null != root) { + if (predicate.test(root)) { + result.add(root); + } + TreeIterator it = root.eAllContents(); - EObject current = null; + EObject current = null; - while (it.hasNext()) { - current = it.next(); - if (predicate.test(current)) { - result.add(current); + while (it.hasNext()) { + current = it.next(); + if (predicate.test(current)) { + result.add(current); + } + } } - } + return result; + } - return result; - } + /** + * Compute a predicate on ModelElement corresponding to specified filtering result + * + * @param filteringResult + * @return + */ + public static Predicate computePredicate(FilteringResult filteringResult) { - /** - * Compute a predicate on ModelElement corresponding to specified filtering result - * - * @param filteringResult - * @return - */ - public static Predicate computePredicate(FilteringResult filteringResult) { + Set filteringCriteria = new HashSet(filteringResult.getFilteringCriteria()); - Set filteringCriteria = new HashSet(filteringResult.getFilteringCriteria()); + return elt -> isAssociatedWithAtLeastOneCriterionInclundingImplicits(elt, filteringCriteria); + } + + /** + * True if modelElement is associated with at least on criteria from specified criterionSet including implicit + * criteria + * + * @param eObj + * @param criterionSet + * @return + */ + private static boolean isAssociatedWithAtLeastOneCriterionInclundingImplicits(EObject eObj, Set criterionSet) { - Predicate predicate = elt -> isAssociatedWithAtLeastOneCriterionInclundingImplicits(elt, - filteringCriteria); + List explicitCriteria = getAssociatedCriteria(eObj); - return predicate; - } + Set intersectionOf = intersectionOf(new HashSet<>(explicitCriteria), new HashSet(criterionSet)); - /** - * True if modelElement is associated with at least on criteria from specified criterionSet including implicit - * criteria - * - * @param eObj - * @param criterionSet - * @return - */ - private static boolean isAssociatedWithAtLeastOneCriterionInclundingImplicits(EObject eObj, - Set criterionSet) { + return !intersectionOf.isEmpty(); - List explicitCriteria = getAssociatedCriteria(eObj); + } - Set intersectionOf = intersectionOf(new HashSet<>(explicitCriteria), new HashSet(criterionSet)); + /** + * Compute set of elements corresponding to a derivation with a composed filtering result + * + * @param composedFResult + * @return + */ + public static Predicate computePredicate(ComposedFilteringResult composedFResult) { - return !intersectionOf.isEmpty(); + Predicate predicate = elt -> true; - } + UnionFilteringResultSet unionResultSet = composedFResult.getUnionFilteringResultSet(); + IntersectionFilteringResultSet intersectionResultSet = composedFResult.getIntersectionFilteringResultSet(); + ExclusionFilteringResultSet exclusionResultSet = composedFResult.getExclusionFilteringResultSet(); - /** - * Compute set of elements corresponding to a derivation with a composed filtering result - * - * @param composedFResult - * @return - */ - public static Predicate computePredicate(ComposedFilteringResult composedFResult) { + Predicate unionResultSetPredicate = computePredicate(unionResultSet); + Predicate intersectionResultSetPredicate = computePredicate(intersectionResultSet); + Predicate exclusionResultSetPredicate = computePredicate(exclusionResultSet); - Predicate predicate = elt -> true; + predicate = predicate.and(unionResultSetPredicate).and(intersectionResultSetPredicate).and(exclusionResultSetPredicate); - UnionFilteringResultSet unionResultSet = composedFResult.getUnionFilteringResultSet(); - IntersectionFilteringResultSet intersectionResultSet = composedFResult.getIntersectionFilteringResultSet(); - ExclusionFilteringResultSet exclusionResultSet = composedFResult.getExclusionFilteringResultSet(); + return predicate; + } - Predicate unionResultSetPredicate = computePredicate(unionResultSet); - Predicate intersectionResultSetPredicate = computePredicate(intersectionResultSet); - Predicate exclusionResultSetPredicate = computePredicate(exclusionResultSet); + /** + * Compute derivation for each child filtering result then compute their union + * + * @param unionResultSet + * @param root + * @return + */ + private static Predicate computePredicate(UnionFilteringResultSet unionResultSet) { + + if (unionResultSet == null) { + return elt -> true; + } - predicate = predicate.and(unionResultSetPredicate).and(intersectionResultSetPredicate) - .and(exclusionResultSetPredicate); + Predicate predicate = elt -> false; - return predicate; - } + for (AbstractFilteringResult fR : unionResultSet.getFilteringResults()) { + predicate = predicate.or(computePredicate(fR)); + } - /** - * Compute derivation for each child filtering result then compute their union - * - * @param unionResultSet - * @param root - * @return - */ - private static Predicate computePredicate(UnionFilteringResultSet unionResultSet) { + return predicate; - if (unionResultSet == null) { - return elt -> true; } - Predicate predicate = elt -> false; + private static Predicate computePredicate(ExclusionFilteringResultSet exclusionResultSet) { + + if (exclusionResultSet == null) { + return elt -> true; + } + + Predicate predicate = elt -> true; + + for (AbstractFilteringResult fR : exclusionResultSet.getFilteringResults()) { + predicate = predicate.and(computePredicate(fR)); + } + + return predicate.negate(); - for (AbstractFilteringResult fR : unionResultSet.getFilteringResults()) { - predicate = predicate.or(computePredicate(fR)); } - return predicate; + private static Predicate computePredicate(IntersectionFilteringResultSet intersectionResultSet) { + if (intersectionResultSet == null) { + return elt -> true; + } - } + Predicate predicate = elt -> true; - private static Predicate computePredicate(ExclusionFilteringResultSet exclusionResultSet) { + for (AbstractFilteringResult fR : intersectionResultSet.getFilteringResults()) { + predicate = predicate.and(computePredicate(fR)); + } + + return predicate; - if (exclusionResultSet == null) { - return elt -> true; } - Predicate predicate = elt -> true; + public static Predicate computePredicate(AbstractFilteringResult abstractFilteringResult) { + + // init predicate: element should not be an instance of a Filtering Metaclass (e.g. FilteringCriterion) + Predicate predicate = eObj -> notInstanceOfFilteringPackageMetaclass(eObj); - for (AbstractFilteringResult fR : exclusionResultSet.getFilteringResults()) { - predicate = predicate.and(computePredicate(fR)); + if (abstractFilteringResult == null) { + return predicate; + } + + if (abstractFilteringResult instanceof FilteringResult) + return predicate.and(computePredicate((FilteringResult) abstractFilteringResult)); + else if (abstractFilteringResult instanceof ComposedFilteringResult) + return predicate.and(computePredicate((ComposedFilteringResult) abstractFilteringResult)); + else + return elt -> true; + } + + private static Set unionOf(List> derivations) { + Set union = new HashSet<>(); + derivations.forEach(union::addAll); + return union; } - return predicate.negate(); + /** + * Recursive implementation of intersection of multiple Sets of EObjects + * + * @param derivations + * @return + */ + private static Set intersectionOf(List> derivations) { + + Set intersection = new HashSet<>(); + + if (derivations.size() == 0) { + return Collections.emptySet(); + } + + if (derivations.size() == 1) { + return derivations.get(0); + } + + if (derivations.size() > 1) { - } + return intersectionOf(derivations.get(0), intersectionOf(derivations.subList(1, derivations.size()))); + } - private static Predicate computePredicate(IntersectionFilteringResultSet intersectionResultSet) { - if (intersectionResultSet == null) { - return elt -> true; + derivations.forEach(intersection::addAll); + + return intersection; } - Predicate predicate = elt -> true; + private static Set intersectionOf(Set set1, Set set2) { + return set1.stream().filter(set2::contains).collect(Collectors.toSet()); + } - for (AbstractFilteringResult fR : intersectionResultSet.getFilteringResults()) { - predicate = predicate.and(computePredicate(fR)); + public static boolean isVariantModel(EObject modelObject, boolean includeReferencedLibraries) { + List filteringModels = getFilteringModels(modelObject, includeReferencedLibraries); + return !filteringModels.isEmpty() && hasFilteringFeatures(filteringModels); } - return predicate; + /** + * @param aird + * @return + */ + public static Session openSession(IFile aird, IProgressMonitor monitor) { + // since this method is already executed in a job + // override the run method in order to avoid the runnable + + OpenSessionAction openSessionAction = new OpenSessionAction() { - } + @Override + public void run() { + doOpenSessions(monitor); + } + }; - public static Predicate computePredicate(AbstractFilteringResult abstractFilteringResult) { + openSessionAction.setRunInProgressService(false); + openSessionAction.setOpenActivityExplorer(false); + openSessionAction.selectionChanged(new StructuredSelection(aird)); - // init predicate: element should not be an instance of a Filtering Metaclass (e.g. FilteringCriterion) - Predicate predicate = eObj -> notInstanceOfFilteringPackageMetaclass(eObj); + openSessionAction.run(); - if (abstractFilteringResult == null) { - return predicate; + return SessionHelper.getSession(aird); } - if (abstractFilteringResult instanceof FilteringResult) - return predicate.and(computePredicate((FilteringResult) abstractFilteringResult)); - else if (abstractFilteringResult instanceof ComposedFilteringResult) - return predicate.and(computePredicate((ComposedFilteringResult) abstractFilteringResult)); - else - return elt -> true; - } + /** + * Get the FilteringResultPkgs given any eObject of the model + * + * @param eObject + * @return the Feature model + */ + public static FilteringResultPkg getFilteringResultPkg(SystemEngineering systemEngineering) { + if (null != systemEngineering) { + for (ElementExtension elementExtension : systemEngineering.getOwnedExtensions()) { + if (elementExtension instanceof CreationDefaultFilteringCriterionSet) { + return (FilteringResultPkg) elementExtension; + } + } + } + return null; + } - private static Set unionOf(List> derivations) { - Set union = new HashSet<>(); - derivations.forEach(union::addAll); - return union; - } + public static Collection getMainAndReferencedVariantProjects(EObject object) { + Collection result = new HashSet(); + Project mainPrj = CapellaProjectHelper.getProject(object); + if (mainPrj != null) { + List projects = FilteringUtils.getReferencedProjects(mainPrj); + projects.add(mainPrj); + for (Project prj : projects) { + if (FilteringUtils.isVariantModel(prj, false)) { + result.add(prj); + } + } + } + return result; + } - /** - * Recursive implementation of intersection of multiple Sets of EObjects - * - * @param derivations - * @return - */ - private static Set intersectionOf(List> derivations) { + /** + * @param project + * @return + */ + public static List getReferencedProjects(Project project) { + List res = new ArrayList(); + Session session = SessionManager.INSTANCE.getSession(project); + if (session != null) { + TransactionalEditingDomain transactionalEditingDomain = session.getTransactionalEditingDomain(); + IModel model = ILibraryManager.INSTANCE.getModel(project); + Collection allReferences = LibraryManagerExt.getAllReferences(model); + for (IModel lib : allReferences) { + if (lib instanceof ICapellaModel) { + res.add(((ICapellaModel) lib).getProject(transactionalEditingDomain)); + } + } + } + return res; + } + + /** + * @param session + * @return + */ + public static List getReferencedProjects(Session session) { + List res = new ArrayList(); + TransactionalEditingDomain transactionalEditingDomain = session.getTransactionalEditingDomain(); + IModel abstractModel = ILibraryManager.INSTANCE.getModel(transactionalEditingDomain); + Collection referencedLibraries = LibraryManagerExt.getAllReferences(abstractModel); + for (IModel lib : referencedLibraries) { + if (lib instanceof ICapellaModel) { + res.add(((ICapellaModel) lib).getProject(transactionalEditingDomain)); + } + } + return res; + } - Set intersection = new HashSet<>(); + /** + * @param session + * @return + */ + public static List getReferencedLibraries(Session session) { + List res = new ArrayList(); - if (derivations.size() == 0) { - return Collections.emptySet(); + for (Project project : getReferencedProjects(session)) { + res.add(project.eResource()); + } + return res; + } + + /** + * @param project + * @return + */ + public static List getReferencedLibraries(Project project) { + return getReferencedLibraries(SessionManager.INSTANCE.getSession(project)); } - if (derivations.size() == 1) { - return derivations.get(0); + /** + * Get the AssociatedFilteringCriterionSet of a Capella element or null if it doesn't have + * + * @param melodyElement + * @return + */ + public static AssociatedFilteringCriterionSet getAssociatedFilteringCriterionSet(EObject melodyElement) { + if (melodyElement instanceof ExtensibleElement) { + + List ownedExtensions = ((ExtensibleElement) melodyElement).getOwnedExtensions(); + + for (ElementExtension elementExtension : ownedExtensions) { + if (elementExtension instanceof AssociatedFilteringCriterionSet) { + return (AssociatedFilteringCriterionSet) elementExtension; + } + } + } + return null; } - if (derivations.size() > 1) { + public static List getAssociatedCriteria(EObject element, List visitedElements) { + List featureList = new ArrayList(); + + if (element instanceof CapellaElement) { + CapellaElement capellaElement = (CapellaElement) CapellaAdapterHelper.resolveBusinessObject(element); - return intersectionOf(derivations.get(0), intersectionOf(derivations.subList(1, derivations.size()))); + // Add its own features. Explicit + featureList.addAll(getExplicitAssociatedCriteria(capellaElement)); + + // If the explicit is empty then add the implicit + if (featureList.isEmpty()) { + // Add implicit features + Set features = getImplicitAssociatedCriteria(capellaElement, visitedElements); + for (FilteringCriterion feature : features) { + if (!featureList.contains(feature)) { + featureList.add(feature); + } + } + } + } + return featureList; } - derivations.forEach(intersection::addAll); + /** + * Get the associated features of an EObject + * + * @param element + * @return list of features + */ + public static List getAssociatedCriteria(EObject element) { + return getAssociatedCriteria(element, new ArrayList()); + } + + /** + * @param element + * @return + */ + public static List getExplicitAssociatedCriteria(EObject element) { + List featureList = new ArrayList(); + + if (element instanceof CapellaElement) { - return intersection; - } + // Get the feature set + FilteringCriterionSet featureSet = getAssociatedFilteringCriterionSet(element); - private static Set intersectionOf(Set set1, Set set2) { - return set1.stream().filter(set2::contains).collect(Collectors.toSet()); - } + // Return empty list if no associated feature set + if (featureSet == null) { + return featureList; + } + // Get filtering features + for (FilteringCriterion feature : featureSet.getFilteringCriteria()) { + if (!featureList.contains(feature)) { + featureList.add(feature); + } + } + } + return featureList; + } - public static boolean isVariantModel(EObject modelObject, boolean includeReferencedLibraries) { - List filteringModels = getFilteringModels(modelObject, includeReferencedLibraries); - return !filteringModels.isEmpty() && hasFilteringFeatures(filteringModels); - } + public static Set getImplicitAssociatedCriteria(EObject element) { + return getImplicitAssociatedCriteria(element, new ArrayList()); + } - /** - * @param aird - * @return - */ - public static Session openSession(IFile aird, IProgressMonitor monitor) { - // since this method is already executed in a job - // override the run method in order to avoid the runnable + /** + * @param element + * @return + */ + public static Set getImplicitAssociatedCriteria(EObject element, List visitedElements) { - OpenSessionAction openSessionAction = new OpenSessionAction() { + Set res = new HashSet(); + List filteringModels = getFilteringModels(element, true); + if (!FilteringUtils.hasFilteringFeatures(filteringModels)) { + return res; + } - @Override - public void run() { - doOpenSessions(monitor); - } - }; + for (FilteringCriterion currentFeature : FilteringUtils.getOwnedFilteringCriteria(filteringModels)) { - openSessionAction.setRunInProgressService(false); - openSessionAction.setOpenActivityExplorer(false); - openSessionAction.selectionChanged(new StructuredSelection(aird)); + if (FilteringToolsPlugin.getImplicitImpactCache().containsKey(currentFeature)) { - openSessionAction.run(); + logger.debug("Cache hit: " + currentFeature.hashCode() + " on " + FilteringToolsPlugin.getImplicitImpactCache().size() + " elements"); - return SessionHelper.getSession(aird); - } + Collection expanded = FilteringToolsPlugin.getImplicitImpactCache().get(currentFeature); + if (expanded.contains(element)) { + res.add(currentFeature); - /** - * Get the FilteringResultPkgs given any eObject of the model - * - * @param eObject - * @return the Feature model - */ - public static FilteringResultPkg getFilteringResultPkg(SystemEngineering systemEngineering) { - if (null != systemEngineering) { - for (ElementExtension elementExtension : systemEngineering.getOwnedExtensions()) { - if (elementExtension instanceof CreationDefaultFilteringCriterionSet) { - return (FilteringResultPkg) elementExtension; + } + continue; + } + + List referencedElements = CrossReferencerHelper.getReferencingElements(currentFeature); + List explictlyReferencedElements = new ArrayList(); + + for (EObject referencedElement : referencedElements) { + if (referencedElement instanceof AssociatedFilteringCriterionSet && referencedElement.eContainer() instanceof CapellaElement) { + explictlyReferencedElements.add((CapellaElement) referencedElement.eContainer()); + } + } + + if (explictlyReferencedElements.contains(element)) { + continue; + } + + ExecutionManager executionManager = TransactionHelper.getExecutionManager(element); + CapellaDeleteCommand deleteCmd = new ModelOnlyFilteringDeleteCommand(executionManager, explictlyReferencedElements, true, false, false); + Set expandedElements = deleteCmd.getAllElementsToDelete(); + + if (expandedElements.contains(element)) { + res.add(currentFeature); + } + + FilteringToolsPlugin.getImplicitImpactCache().put(currentFeature, expandedElements); } - } - } - return null; - } - - public static Collection getMainAndReferencedVariantProjects(EObject object) { - Collection result = new HashSet(); - Project mainPrj = CapellaProjectHelper.getProject(object); - if (mainPrj != null) { - List projects = FilteringUtils.getReferencedProjects(mainPrj); - projects.add(mainPrj); - for (Project prj : projects) { - if (FilteringUtils.isVariantModel(prj, false)) { - result.add(prj); + return res; + } + + public static Set getImpactedElements(Collection element) { + Set relatedElements = new HashSet(); + + if (element == null || element.isEmpty()) { + return relatedElements; } - } - } - return result; - } - - /** - * @param project - * @return - */ - public static List getReferencedProjects(Project project) { - List res = new ArrayList(); - Session session = SessionManager.INSTANCE.getSession(project); - if (session != null) { - TransactionalEditingDomain transactionalEditingDomain = session.getTransactionalEditingDomain(); - IModel model = ILibraryManager.INSTANCE.getModel(project); - Collection allReferences = LibraryManagerExt.getAllReferences(model); - for (IModel lib : allReferences) { - if (lib instanceof ICapellaModel) { - res.add(((ICapellaModel) lib).getProject(transactionalEditingDomain)); + + ExecutionManager executionManager = TransactionHelper.getExecutionManager(element); + CapellaDeleteCommand mdc = new ModelOnlyFilteringDeleteCommand(executionManager, element, true, false, false); + Set impactedElements = mdc.getAllElementsToDelete(); + for (Object impactedElem : impactedElements) { + if (impactedElem instanceof EObject) { + relatedElements.add((EObject) impactedElem); + } } - } - } - return res; - } - - /** - * @param session - * @return - */ - public static List getReferencedProjects(Session session) { - List res = new ArrayList(); - TransactionalEditingDomain transactionalEditingDomain = session.getTransactionalEditingDomain(); - IModel abstractModel = ILibraryManager.INSTANCE.getModel(transactionalEditingDomain); - Collection referencedLibraries = LibraryManagerExt.getAllReferences(abstractModel); - for (IModel lib : referencedLibraries) { - if (lib instanceof ICapellaModel) { - res.add(((ICapellaModel) lib).getProject(transactionalEditingDomain)); - } - } - return res; - } - - /** - * @param session - * @return - */ - public static List getReferencedLibraries(Session session) { - List res = new ArrayList(); - - for (Project project : getReferencedProjects(session)) { - res.add(project.eResource()); - } - return res; - } - - /** - * @param project - * @return - */ - public static List getReferencedLibraries(Project project) { - return getReferencedLibraries(SessionManager.INSTANCE.getSession(project)); - } - - /** - * Get the AssociatedFilteringCriterionSet of a Capella element or null if it doesn't have - * - * @param melodyElement - * @return - */ - public static AssociatedFilteringCriterionSet getAssociatedFilteringCriterionSet(EObject melodyElement) { - if (melodyElement instanceof ExtensibleElement) { - - List ownedExtensions = ((ExtensibleElement) melodyElement).getOwnedExtensions(); - - for (ElementExtension elementExtension : ownedExtensions) { - if (elementExtension instanceof AssociatedFilteringCriterionSet) { - return (AssociatedFilteringCriterionSet) elementExtension; + return relatedElements; + } + + /** + * Get the FilteringModel given any eObject of the model + * + * @param eObject + * @return the Feature model + */ + public static FilteringModel getFilteringModel(EObject eObject) { + List filteringModels = getFilteringModels(eObject, false); + return !filteringModels.isEmpty() ? filteringModels.get(0) : null; + } + + /** + * + * @param eObjects + * @param includeReferencedLibraries + * @return The intersection of FilteringModels for the given list of eObjects + */ + public static Collection getCommonFilteringModels(Collection eObjects, boolean includeReferencedLibraries) { + Collection filteringModels = null; + for (EObject element : eObjects) { + List currentElementFilteringModels = FilteringUtils.getFilteringModels(element, includeReferencedLibraries); + if (filteringModels == null) { // If first iteration + filteringModels = new HashSet(); + filteringModels.addAll(currentElementFilteringModels); + } else { + filteringModels.retainAll(currentElementFilteringModels); + } } - } + return filteringModels != null ? filteringModels : Collections. emptySet(); } - return null; - } - public static List getAssociatedCriteria(EObject element, List visitedElements) { - List featureList = new ArrayList(); + /** + * Get the list of FilteringModel given any eObject of the model + * + * @param eObject + * @return the Feature model + */ + public static List getFilteringModels(EObject eObject, boolean includeReferencedLibraries) { + List result = new ArrayList(); + if (null != eObject) { + if (!includeReferencedLibraries) { + SystemEngineering systemEngineering = getSystemEngineering(eObject); + FilteringModel filteringModel = getFilteringModel(systemEngineering); + if (filteringModel != null) { + result.add(filteringModel); + } + } else { + for (Project prj : FilteringUtils.getMainAndReferencedVariantProjects(eObject)) { + FilteringModel filteringModel = getFilteringModel(prj); + if (filteringModel != null) { + result.add(filteringModel); + } + } + } + } + return result; + } - if (element instanceof CapellaElement) { - CapellaElement capellaElement = (CapellaElement) CapellaAdapterHelper.resolveBusinessObject(element); + public static List getOwnedFilteringCriteria(Collection filteringModels) { + List result = new ArrayList(); - // Add its own features. Explicit - featureList.addAll(getExplicitAssociatedCriteria(capellaElement)); + for (FilteringModel filteringModel : filteringModels) { + + filteringModel.eAllContents().forEachRemaining(eObj -> { + if (eObj instanceof FilteringCriterion) + result.add((FilteringCriterion) eObj); + }); - // If the explicit is empty then add the implicit - if (featureList.isEmpty()) { - // Add implicit features - Set features = getImplicitAssociatedCriteria(capellaElement, visitedElements); - for (FilteringCriterion feature : features) { - if (!featureList.contains(feature)) { - featureList.add(feature); - } - } - } - } - return featureList; - } - - /** - * Get the associated features of an EObject - * - * @param element - * @return list of features - */ - public static List getAssociatedCriteria(EObject element) { - return getAssociatedCriteria(element, new ArrayList()); - } - - /** - * @param element - * @return - */ - public static List getExplicitAssociatedCriteria(EObject element) { - List featureList = new ArrayList(); - - if (element instanceof CapellaElement) { - - // Get the feature set - FilteringCriterionSet featureSet = getAssociatedFilteringCriterionSet(element); - - // Return empty list if no associated feature set - if (featureSet == null) { - return featureList; - } - // Get filtering features - for (FilteringCriterion feature : featureSet.getFilteringCriteria()) { - if (!featureList.contains(feature)) { - featureList.add(feature); } - } + + return result; + } + + public static Collection getAllFilteringCriteria(EObject modelElement) { + List filteringModels = getFilteringModels(modelElement, true); + return getOwnedFilteringCriteria(filteringModels); } - return featureList; - } - public static Set getImplicitAssociatedCriteria(EObject element) { - return getImplicitAssociatedCriteria(element, new ArrayList()); - } + public static boolean hasFilteringFeatures(List filteringModels) { + return !getOwnedFilteringCriteria(filteringModels).isEmpty(); + } - /** - * @param element - * @return - */ - public static Set getImplicitAssociatedCriteria(EObject element, List visitedElements) { + public static List getOwnedFilteringCriteriaAndPkgs(Collection filteringModels) { + List result = new ArrayList(); + for (FilteringModel filteringModel : filteringModels) { + EList ownedCriteria = filteringModel.getOwnedFilteringCriteria(); + EList ownedCriteriaPkgs = filteringModel.getOwnedFilteringCriterionPkgs(); + if (ownedCriteria != null) + result.addAll(ownedCriteria); + if (ownedCriteriaPkgs != null) + result.addAll(ownedCriteriaPkgs); - Set res = new HashSet(); - List filteringModels = getFilteringModels(element, true); - if (!FilteringUtils.hasFilteringFeatures(filteringModels)) { - return res; + } + + return result; } - for (FilteringCriterion currentFeature : FilteringUtils.getOwnedFilteringCriteria(filteringModels)) { + public static List getOwnedFilteringCriteriaAndPkgs(FilteringCriterionPkg criterionPkg) { + List result = new ArrayList(); + EList ownedCriteria = criterionPkg.getOwnedFilteringCriteria(); + EList ownedCriteriaPkgs = criterionPkg.getOwnedFilteringCriterionPkgs(); + if (ownedCriteria != null) + result.addAll(ownedCriteria); + if (ownedCriteriaPkgs != null) + result.addAll(ownedCriteriaPkgs); - if (FilteringToolsPlugin.getImplicitImpactCache().containsKey(currentFeature)) { + return result; + } - logger.debug("Cache hit: " + currentFeature.hashCode() + " on " - + FilteringToolsPlugin.getImplicitImpactCache().size() + " elements"); + /** + * Append to a filtering result/criterion name all its parent packages (e.g. pkg1/subpkg/filteringResult) + * + * @param filteringResult + * @return + */ + public static String formatFilteringItemName(NamedElement filteringItem) { + + Stack stack = new Stack(); + EObject parentPkg = filteringItem.eContainer(); + + // collect parent pkg names + while (parentPkg instanceof Namespace) { + stack.push(((NamedElement) parentPkg).getName()); + parentPkg = parentPkg.eContainer(); + } + + if (stack.isEmpty()) + return filteringItem.getName(); - Collection expanded = FilteringToolsPlugin.getImplicitImpactCache().get(currentFeature); - if (expanded.contains(element)) { - res.add(currentFeature); + StringBuilder sb = new StringBuilder(); + while (!stack.isEmpty()) { + sb.append(stack.pop() + "/"); } - continue; - } - List referencedElements = CrossReferencerHelper.getReferencingElements(currentFeature); - List explictlyReferencedElements = new ArrayList(); + sb.append(filteringItem.getName()); + return sb.toString(); + } - for (EObject referencedElement : referencedElements) { - if (referencedElement instanceof AssociatedFilteringCriterionSet - && referencedElement.eContainer() instanceof CapellaElement) { - explictlyReferencedElements.add((CapellaElement) referencedElement.eContainer()); + /** + * @param systemEngineering + */ + public static FilteringModel getFilteringModel(SystemEngineering systemEngineering) { + if (null != systemEngineering) { + for (ElementExtension elementExtension : systemEngineering.getOwnedExtensions()) { + if (elementExtension instanceof FilteringModel) { + return (FilteringModel) elementExtension; + } + } } - } - - if (explictlyReferencedElements.contains(element)) { - continue; - } - - ExecutionManager executionManager = TransactionHelper.getExecutionManager(element); - CapellaDeleteCommand deleteCmd = new ModelOnlyFilteringDeleteCommand(executionManager, - explictlyReferencedElements, true, false, false); - Set expandedElements = deleteCmd.getAllElementsToDelete(); - - if (expandedElements.contains(element)) { - res.add(currentFeature); - } - - FilteringToolsPlugin.getImplicitImpactCache().put(currentFeature, expandedElements); - } - return res; - } - - public static Set getImpactedElements(Collection element) { - Set relatedElements = new HashSet(); - - if (element == null || element.isEmpty()) { - return relatedElements; - } - - ExecutionManager executionManager = TransactionHelper.getExecutionManager(element); - CapellaDeleteCommand mdc = new ModelOnlyFilteringDeleteCommand(executionManager, element, true, false, false); - Set impactedElements = mdc.getAllElementsToDelete(); - for (Object impactedElem : impactedElements) { - if (impactedElem instanceof EObject) { - relatedElements.add((EObject) impactedElem); - } - } - return relatedElements; - } - - /** - * Get the FilteringModel given any eObject of the model - * - * @param eObject - * @return the Feature model - */ - public static FilteringModel getFilteringModel(EObject eObject) { - List filteringModels = getFilteringModels(eObject, false); - return !filteringModels.isEmpty() ? filteringModels.get(0) : null; - } - - /** - * - * @param eObjects - * @param includeReferencedLibraries - * @return The intersection of FilteringModels for the given list of eObjects - */ - public static Collection getCommonFilteringModels(Collection eObjects, - boolean includeReferencedLibraries) { - Collection filteringModels = null; - for (EObject element : eObjects) { - List currentElementFilteringModels = FilteringUtils.getFilteringModels(element, - includeReferencedLibraries); - if (filteringModels == null) { // If first iteration - filteringModels = new HashSet(); - filteringModels.addAll(currentElementFilteringModels); - } else { - filteringModels.retainAll(currentElementFilteringModels); - } - } - return filteringModels != null ? filteringModels : Collections. emptySet(); - } - - /** - * Get the list of FilteringModel given any eObject of the model - * - * @param eObject - * @return the Feature model - */ - public static List getFilteringModels(EObject eObject, boolean includeReferencedLibraries) { - List result = new ArrayList(); - if (null != eObject) { - if (!includeReferencedLibraries) { - SystemEngineering systemEngineering = getSystemEngineering(eObject); - FilteringModel filteringModel = getFilteringModel(systemEngineering); - if (filteringModel != null) { - result.add(filteringModel); + return null; + } + + /** + * Get the FilteringResults given any eObject of the model + * + * @param eObject + * @return the Feature model + */ + public static FilteringResults getFilteringResults(EObject eObject) { + if (null != eObject) { + SystemEngineering systemEngineering = getSystemEngineering(eObject); + return getFilteringResults(systemEngineering); } - } else { - for (Project prj : FilteringUtils.getMainAndReferencedVariantProjects(eObject)) { - FilteringModel filteringModel = getFilteringModel(prj); - if (filteringModel != null) { - result.add(filteringModel); - } + return null; + } + + /** + * Method for override if needed. For example when working with diagrams. get all filtering results in a list + * + * @param object + * @return + */ + public static List getFilteringResults(Collection projects) { + + if (projects == null) + return Collections.emptyList(); + + List result = new ArrayList<>(); + for (Project prj : projects) { + FilteringResults filteringResults = FilteringUtils.getFilteringResults(prj); + if (filteringResults != null) { + result.addAll(getAllFilteringResults(filteringResults)); + } } - } + return result; } - return result; - } - public static List getOwnedFilteringCriteria(Collection filteringModels) { - List result = new ArrayList(); + /** + * Get all contained Filtering Result (e.g. traverse all sub packages) + * + * @param filteringResults + * @return + */ + public static List getAllFilteringResults(FilteringResults filteringResults) { + List filteringResultList = new ArrayList<>(); + + if (filteringResults != null) { + + filteringResults.eAllContents().forEachRemaining(eObj -> { + if (eObj instanceof AbstractFilteringResult) + filteringResultList.add((AbstractFilteringResult) eObj); + }); + } - for (FilteringModel filteringModel : filteringModels) { + return filteringResultList; + } - filteringModel.eAllContents().forEachRemaining(eObj -> { - if (eObj instanceof FilteringCriterion) - result.add((FilteringCriterion) eObj); - }); + /** + * @param systemEngineering + * @return + */ + public static FilteringResults getFilteringResults(SystemEngineering systemEngineering) { + if (null != systemEngineering) { + for (ElementExtension elementExtension : systemEngineering.getOwnedExtensions()) { + + if (elementExtension instanceof FilteringResults) { + return (FilteringResults) elementExtension; + } + } + } + return null; + } + /** + * Get the FilteringModel given any eObject of the model + * + * @param eObject + * @return the Feature model + */ + public static CreationDefaultFilteringCriterionSet getCreationDefaultFeatureSet(EObject eObject) { + if (null != eObject) { + SystemEngineering systemEngineering = getSystemEngineering(eObject); + return getCreationDefaultFeatureSet(systemEngineering); + } + return null; } - return result; - } + /** + * @param systemEngineering + * @return + */ + public static CreationDefaultFilteringCriterionSet getCreationDefaultFeatureSet(SystemEngineering systemEngineering) { + if (null != systemEngineering) { + for (ElementExtension elementExtension : systemEngineering.getOwnedExtensions()) { + if (elementExtension instanceof CreationDefaultFilteringCriterionSet) { + return (CreationDefaultFilteringCriterionSet) elementExtension; + } + } + } + return null; + } - public static Collection getAllFilteringCriteria(EObject modelElement) { - List filteringModels = getFilteringModels(modelElement, true); - return getOwnedFilteringCriteria(filteringModels); - } + /** + * Get the SystemEngineering element given any eObject of the model + * + * @param eObject + * @return + */ + public static SystemEngineering getSystemEngineering(EObject eObject) { + if (eObject != null) { + Project project = CapellaProjectHelper.getProject(eObject); + if ((project != null) && (project.getOwnedModelRoots() != null)) { + for (EObject modelRoot : project.getOwnedModelRoots()) { + if (modelRoot instanceof SystemEngineering) { + return (SystemEngineering) modelRoot; + } + } + } + } + return null; + } - public static boolean hasFilteringFeatures(List filteringModels) { - return !getOwnedFilteringCriteria(filteringModels).isEmpty(); - } + /** + * Get a comma separated String of the associated features of an element + * + * @param element + * @return + */ + public static String getCommaSeparatedExplicitFeatures(EObject element) { + List featureList = getExplicitAssociatedCriteria(element); + return getCommaSeparatedFilteringCriteriaList(featureList); + } - public static List getOwnedFilteringCriteriaAndPkgs(Collection filteringModels) { - List result = new ArrayList(); - for (FilteringModel filteringModel : filteringModels) { - EList ownedCriteria = filteringModel.getOwnedFilteringCriteria(); - EList ownedCriteriaPkgs = filteringModel.getOwnedFilteringCriterionPkgs(); - if (ownedCriteria != null) - result.addAll(ownedCriteria); - if (ownedCriteriaPkgs != null) - result.addAll(ownedCriteriaPkgs); + /** + * Get a comma separated String of the given filtering features list + */ + public static String getCommaSeparatedFilteringCriteriaList(List featureList) { + if ((featureList == null) || featureList.isEmpty()) { + return null; + } + String features = ""; //$NON-NLS-1$ + for (FilteringCriterion feature : featureList) { + features = features + feature.getName() + ", "; //$NON-NLS-1$ + } + // remove last comma + if (features.length() > 0) { + features = features.substring(0, features.length() - ", ".length()); //$NON-NLS-1$ + } + return features; + } + /** + * Add associated features + * + * @param capellaElement + * @param filteringCriterions + */ + public static void addAssociatedCriteria(EObject capellaElement, Collection filteringCriterions) { + // Get associated feature set + AssociatedFilteringCriterionSet featureSet = FilteringUtils.getAssociatedFilteringCriterionSet(capellaElement); + // Create it if empty + if ((featureSet == null) && !filteringCriterions.isEmpty()) { + featureSet = FilteringFactory.eINSTANCE.createAssociatedFilteringCriterionSet(); + ((ExtensibleElement) capellaElement).getOwnedExtensions().add(featureSet); + } + // Add the features + for (FilteringCriterion filteringCriterion : filteringCriterions) { + if (!featureSet.getFilteringCriteria().contains(filteringCriterion)) { + featureSet.getFilteringCriteria().add(filteringCriterion); + } + } } - return result; - } + /** + * Remove associated features + * + * @param melodyElement + * @param filteringCriterions + */ + public static void removeAssociatedCriteria(EObject melodyElement, Collection filteringCriterions) { + // Get associated feature set + AssociatedFilteringCriterionSet featureSet = FilteringUtils.getAssociatedFilteringCriterionSet(melodyElement); + // Remove features + if ((featureSet != null) && !filteringCriterions.isEmpty()) { + featureSet.getFilteringCriteria().removeAll(filteringCriterions); + } + // Remove associated feature set if empty + if ((featureSet != null) && featureSet.getFilteringCriteria().isEmpty()) { + removeAssociatedFeatureSet(melodyElement); + } + } - public static List getOwnedFilteringCriteriaAndPkgs(FilteringCriterionPkg criterionPkg) { - List result = new ArrayList(); - EList ownedCriteria = criterionPkg.getOwnedFilteringCriteria(); - EList ownedCriteriaPkgs = criterionPkg.getOwnedFilteringCriterionPkgs(); - if (ownedCriteria != null) - result.addAll(ownedCriteria); - if (ownedCriteriaPkgs != null) - result.addAll(ownedCriteriaPkgs); + /** + * Remove associated features + * + * @param melodyElement + * @param filteringCriterions + */ + public static void removeAssociatedFeatureSet(EObject melodyElement) { + // Get associated feature set + AssociatedFilteringCriterionSet featureSet = FilteringUtils.getAssociatedFilteringCriterionSet(melodyElement); + if (featureSet != null) { + // Remove it. Other elements, as transfo links, should be removed + // also so we call CapellaDeleteCommand to be on + // the safe side + ArrayList list = new ArrayList(); + list.add(featureSet); + CapellaDeleteCommand mdc = new CapellaDeleteCommand(TransactionHelper.getExecutionManager(melodyElement), list, true, false, true); + if (mdc.canExecute()) { + mdc.execute(); + } + } + } + + /** + * get the eclipse project {@link IProject} corresponding to the given EObject + * + * @param eObject + * @return null whether selection does not fit any supported case . + */ + public static IProject getEclipseProject(EObject eObject) { + // We need to get the uri through the session to have cdo uri + // compatibility + Session session = SessionManager.INSTANCE.getSession(eObject); + URI resURI = session.getSessionResource().getURI(); + IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(resURI.toPlatformString(true))); + return file.getProject(); + } - return result; - } + public static Set computeDerivation(FilteringResult filteringResult, ModelElement root) { - /** - * Append to a filtering result/criterion name all its parent packages (e.g. pkg1/subpkg/filteringResult) - * - * @param filteringResult - * @return - */ - public static String formatFilteringItemName(NamedElement filteringItem) { + Set allElementsWithAssociatedCriteria = getAllElementsWithAssociatedCriteria(root, new HashSet<>(filteringResult.getFilteringCriteria())); - Stack stack = new Stack(); - EObject parentPkg = filteringItem.eContainer(); + allElementsWithAssociatedCriteria = allElementsWithAssociatedCriteria.stream().filter(FilteringUtils::notInstanceOfFilteringPackageMetaclass).collect(Collectors.toSet()); + + return allElementsWithAssociatedCriteria; - // collect parent pkg names - while (parentPkg instanceof Namespace) { - stack.push(((NamedElement) parentPkg).getName()); - parentPkg = parentPkg.eContainer(); } - if (stack.isEmpty()) - return filteringItem.getName(); + /** + * Get all elements in the hierarchy of a given eObject that contains associated criteria + * + * @param root + * @return list + */ + public static Set getAllElementsWithAssociatedCriteria(ModelElement root, Set criterionSet) { - StringBuilder sb = new StringBuilder(); + Set result = new HashSet(); - while (!stack.isEmpty()) { - sb.append(stack.pop() + "/"); - } + if (null != root) { + if (isAssociatedWithAtLeastOneCriterion(root, criterionSet)) { + result.add(root); + } + TreeIterator it = root.eAllContents(); - sb.append(filteringItem.getName()); - return sb.toString(); - } + EObject current = null; - /** - * @param systemEngineering - */ - public static FilteringModel getFilteringModel(SystemEngineering systemEngineering) { - if (null != systemEngineering) { - for (ElementExtension elementExtension : systemEngineering.getOwnedExtensions()) { - if (elementExtension instanceof FilteringModel) { - return (FilteringModel) elementExtension; + while (it.hasNext()) { + current = it.next(); + if (isAssociatedWithAtLeastOneCriterion(current, criterionSet)) { + result.add(current); + } + } } - } - } - return null; - } - - /** - * Get the FilteringResults given any eObject of the model - * - * @param eObject - * @return the Feature model - */ - public static FilteringResults getFilteringResults(EObject eObject) { - if (null != eObject) { - SystemEngineering systemEngineering = getSystemEngineering(eObject); - return getFilteringResults(systemEngineering); - } - return null; - } - - /** - * Method for override if needed. For example when working with diagrams. get all filtering results in a list - * - * @param object - * @return - */ - public static List getFilteringResults(Collection projects) { - - if (projects == null) - return Collections.emptyList(); - - List result = new ArrayList<>(); - for (Project prj : projects) { - FilteringResults filteringResults = FilteringUtils.getFilteringResults(prj); - if (filteringResults != null) { - result.addAll(getAllFilteringResults(filteringResults)); - } - } - return result; - } - - /** - * Get all contained Filtering Result (e.g. traverse all sub packages) - * - * @param filteringResults - * @return - */ - public static List getAllFilteringResults(FilteringResults filteringResults) { - List filteringResultList = new ArrayList<>(); - - if (filteringResults != null) { - - filteringResults.eAllContents().forEachRemaining(eObj -> { - if (eObj instanceof AbstractFilteringResult) - filteringResultList.add((AbstractFilteringResult) eObj); - }); - } - - return filteringResultList; - } - - /** - * @param systemEngineering - * @return - */ - public static FilteringResults getFilteringResults(SystemEngineering systemEngineering) { - if (null != systemEngineering) { - for (ElementExtension elementExtension : systemEngineering.getOwnedExtensions()) { - - if (elementExtension instanceof FilteringResults) { - return (FilteringResults) elementExtension; + return result; + } + + /** + * Get all the elements in the hierarchy of a given eObject that contains associated criteria + * + * @param root + * @return list + */ + public static Set getAllElementsWithAssociatedCriteria(EObject root) { + Set result = new HashSet(); + + if (null != root) { + if (hasAssociatedCriteria(root)) { + result.add(root); + } + TreeIterator it = root.eAllContents(); + EObject current = null; + while (it.hasNext()) { + current = it.next(); + if (hasAssociatedCriteria(current)) { + result.add(current); + } + } } - } - } - return null; - } - - /** - * Get the FilteringModel given any eObject of the model - * - * @param eObject - * @return the Feature model - */ - public static CreationDefaultFilteringCriterionSet getCreationDefaultFeatureSet(EObject eObject) { - if (null != eObject) { - SystemEngineering systemEngineering = getSystemEngineering(eObject); - return getCreationDefaultFeatureSet(systemEngineering); - } - return null; - } - - /** - * @param systemEngineering - * @return - */ - public static CreationDefaultFilteringCriterionSet getCreationDefaultFeatureSet(SystemEngineering systemEngineering) { - if (null != systemEngineering) { - for (ElementExtension elementExtension : systemEngineering.getOwnedExtensions()) { - if (elementExtension instanceof CreationDefaultFilteringCriterionSet) { - return (CreationDefaultFilteringCriterionSet) elementExtension; + return result; + } + + /** + * True if modelElement is associated to all criteria in specified criterionSet + * + * @param eObj + * @param criterionSet + * @return + */ + private static boolean isAssociatedWithAtLeastOneCriterion(EObject eObj, Set criterionSet) { + + List explicitCriteria = getExplicitAssociatedCriteria(eObj); + + Set intersectionOf = intersectionOf(new HashSet<>(explicitCriteria), new HashSet(criterionSet)); + + return !intersectionOf.isEmpty(); + + } + + /** + * If the element has associated features + * + * @param eObject + * @return boolean + */ + public static boolean hasAssociatedCriteria(EObject eObject) { + if (FilteringUtils.getAssociatedCriteria(eObject).isEmpty()) { + return false; } - } - } - return null; - } - - /** - * Get the SystemEngineering element given any eObject of the model - * - * @param eObject - * @return - */ - public static SystemEngineering getSystemEngineering(EObject eObject) { - if (eObject != null) { - Project project = CapellaProjectHelper.getProject(eObject); - if ((project != null) && (project.getOwnedModelRoots() != null)) { - for (EObject modelRoot : project.getOwnedModelRoots()) { - if (modelRoot instanceof SystemEngineering) { - return (SystemEngineering) modelRoot; - } + return true; + } + + /** + * This method verifies if there is an active transaction.
+ * If such case, the command is simply run.
+ * If not, the command is executed through the execution manager.
+ * + * @param command + * the command to be executed + * @param editingDomain + */ + public static void executeCommand(ICommand command, TransactionalEditingDomain editingDomain) { + ExecutionManager executionManager = ExecutionManagerRegistry.getInstance().getExecutionManager(editingDomain); + if (null != executionManager) { + if (editingDomain instanceof InternalTransactionalEditingDomain) { + InternalTransaction activeTransaction = ((InternalTransactionalEditingDomain) editingDomain).getActiveTransaction(); + if ((null != activeTransaction) && activeTransaction.isActive()) { + command.run(); + } else { + executionManager.execute(command); + } + } } - } - } - return null; - } - - /** - * Get a comma separated String of the associated features of an element - * - * @param element - * @return - */ - public static String getCommaSeparatedExplicitFeatures(EObject element) { - List featureList = getExplicitAssociatedCriteria(element); - return getCommaSeparatedFilteringCriteriaList(featureList); - } - - /** - * Get a comma separated String of the given filtering features list - */ - public static String getCommaSeparatedFilteringCriteriaList(List featureList) { - if ((featureList == null) || featureList.isEmpty()) { - return null; - } - String features = ""; //$NON-NLS-1$ - for (FilteringCriterion feature : featureList) { - features = features + feature.getName() + ", "; //$NON-NLS-1$ - } - // remove last comma - if (features.length() > 0) { - features = features.substring(0, features.length() - ", ".length()); //$NON-NLS-1$ - } - return features; - } - - /** - * Add associated features - * - * @param capellaElement - * @param filteringCriterions - */ - public static void addAssociatedCriteria(EObject capellaElement, Collection filteringCriterions) { - // Get associated feature set - AssociatedFilteringCriterionSet featureSet = FilteringUtils.getAssociatedFilteringCriterionSet(capellaElement); - // Create it if empty - if ((featureSet == null) && !filteringCriterions.isEmpty()) { - featureSet = FilteringFactory.eINSTANCE.createAssociatedFilteringCriterionSet(); - ((ExtensibleElement) capellaElement).getOwnedExtensions().add(featureSet); - } - // Add the features - for (FilteringCriterion filteringCriterion : filteringCriterions) { - if (!featureSet.getFilteringCriteria().contains(filteringCriterion)) { - featureSet.getFilteringCriteria().add(filteringCriterion); - } - } - } - - /** - * Remove associated features - * - * @param melodyElement - * @param filteringCriterions - */ - public static void removeAssociatedCriteria(EObject melodyElement, - Collection filteringCriterions) { - // Get associated feature set - AssociatedFilteringCriterionSet featureSet = FilteringUtils.getAssociatedFilteringCriterionSet(melodyElement); - // Remove features - if ((featureSet != null) && !filteringCriterions.isEmpty()) { - featureSet.getFilteringCriteria().removeAll(filteringCriterions); - } - // Remove associated feature set if empty - if ((featureSet != null) && featureSet.getFilteringCriteria().isEmpty()) { - removeAssociatedFeatureSet(melodyElement); - } - } - - /** - * Remove associated features - * - * @param melodyElement - * @param filteringCriterions - */ - public static void removeAssociatedFeatureSet(EObject melodyElement) { - // Get associated feature set - AssociatedFilteringCriterionSet featureSet = FilteringUtils.getAssociatedFilteringCriterionSet(melodyElement); - if (featureSet != null) { - // Remove it. Other elements, as transfo links, should be removed - // also so we call CapellaDeleteCommand to be on - // the safe side - ArrayList list = new ArrayList(); - list.add(featureSet); - CapellaDeleteCommand mdc = new CapellaDeleteCommand(TransactionHelper.getExecutionManager(melodyElement), list, - true, false, true); - if (mdc.canExecute()) { - mdc.execute(); - } - } - } - - /** - * get the eclipse project {@link IProject} corresponding to the given EObject - * - * @param eObject - * @return null whether selection does not fit any supported case . - */ - public static IProject getEclipseProject(EObject eObject) { - // We need to get the uri through the session to have cdo uri - // compatibility - Session session = SessionManager.INSTANCE.getSession(eObject); - URI resURI = session.getSessionResource().getURI(); - IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(resURI.toPlatformString(true))); - return file.getProject(); - } - - public static Set computeDerivation(FilteringResult filteringResult, ModelElement root) { - - Set allElementsWithAssociatedCriteria = getAllElementsWithAssociatedCriteria(root, - new HashSet(filteringResult.getFilteringCriteria())); - - allElementsWithAssociatedCriteria = allElementsWithAssociatedCriteria.stream() - .filter(elt -> FilteringUtils.notInstanceOfFilteringPackageMetaclass(elt)).collect(Collectors.toSet()); - - return allElementsWithAssociatedCriteria; - - } - - /** - * Get all elements in the hierarchy of a given eObject that contains associated criteria - * - * @param root - * @return list - */ - public static Set getAllElementsWithAssociatedCriteria(ModelElement root, - Set criterionSet) { - - Set result = new HashSet(); - - if (null != root) { - if (isAssociatedWithAtLeastOneCriterion(root, criterionSet)) { - result.add(root); - } - TreeIterator it = root.eAllContents(); - - EObject current = null; - - while (it.hasNext()) { - current = it.next(); - if (isAssociatedWithAtLeastOneCriterion(current, criterionSet)) { - result.add(current); + } + + /** + * This method verifies if there is an active transaction.
+ * If such case, the command is simply run.
+ * If not, the command is executed through the execution manager.
+ * + * @param command + * the command to be executed + * @param eObject + */ + public static void executeCommand(ICommand command, EObject eObject) { + executeCommand(command, TransactionHelper.getEditingDomain(eObject)); + } + + /** + * This method verifies if there is an active transaction.
+ * If such case, the command is simply run.
+ * If not, the command is executed through the execution manager.
+ * + * @param command + * @param session + */ + public static void executeCommand(AbstractReadWriteCommand command, Session session) { + executeCommand(command, session.getTransactionalEditingDomain()); + } + + /** + * @param command + * @param elements + */ + public static void executeCommand(AbstractReadWriteCommand command, Collection elements) { + executeCommand(command, TransactionHelper.getEditingDomain(elements)); + } + + /** + * Some classes should not have associated feature sets + * + * All filtering classes except Exclusion/Intersection/Union are allowed + * + * @param obj + * @return true if it is excluded from having associated features + */ + public static boolean isInstanceOfFilteringExcludedElements(Object obj) { + return obj instanceof EObject && FilteringPackage.eINSTANCE.equals(((EObject) obj).eClass().getEPackage()); + } + + public static boolean notInstanceOfFilteringPackageMetaclass(Object obj) { + return (obj instanceof EObject) && !isInstanceOfFilteringExcludedElements(obj); + } + + /** + * Get the semantic models of a project + * + * @param project + * @return non null list + * @throws CoreException + */ + public static List getSemanticModels(IProject project) throws CoreException { + List result = new ArrayList(); + for (IResource resource : project.members()) { + String ext = resource.getFileExtension(); + if (CapellaResourceHelper.CAPELLA_MODEL_FILE_EXTENSION.equals(ext)) { + result.add((IFile) resource); + } } - } - } - return result; - } - - /** - * Get all the elements in the hierarchy of a given eObject that contains associated criteria - * - * @param root - * @return list - */ - public static Set getAllElementsWithAssociatedCriteria(EObject root) { - Set result = new HashSet(); - - if (null != root) { - if (hasAssociatedCriteria(root)) { - result.add(root); - } - TreeIterator it = root.eAllContents(); - EObject current = null; - while (it.hasNext()) { - current = it.next(); - if (hasAssociatedCriteria(current)) { - result.add(current); + return result; + } + + /** + * Get the aird models of a project + * + * @param project + * @return non null list + * @throws CoreException + */ + public static List getAirdModels(IProject project) throws CoreException { + List result = new ArrayList(); + for (IResource resource : project.members()) { + String ext = resource.getFileExtension(); + if (CapellaResourceHelper.AIRD_FILE_EXTENSION.equals(ext)) { + result.add((IFile) resource); + } } - } - } - return result; - } - - /** - * True if modelElement is associated to all criteria in specified criterionSet - * - * @param eObj - * @param criterionSet - * @return - */ - private static boolean isAssociatedWithAtLeastOneCriterion(EObject eObj, Set criterionSet) { - - List explicitCriteria = getExplicitAssociatedCriteria(eObj); - - Set intersectionOf = intersectionOf(new HashSet<>(explicitCriteria), new HashSet(criterionSet)); - - return !intersectionOf.isEmpty(); - - } - - /** - * If the element has associated features - * - * @param eObject - * @return boolean - */ - public static boolean hasAssociatedCriteria(EObject eObject) { - if (FilteringUtils.getAssociatedCriteria(eObject).isEmpty()) { - return false; - } - return true; - } - - /** - * This method verifies if there is an active transaction.
- * If such case, the command is simply run.
- * If not, the command is executed through the execution manager.
- * - * @param command - * the command to be executed - * @param editingDomain - */ - public static void executeCommand(ICommand command, TransactionalEditingDomain editingDomain) { - ExecutionManager executionManager = ExecutionManagerRegistry.getInstance().getExecutionManager(editingDomain); - if (null != executionManager) { - if (editingDomain instanceof InternalTransactionalEditingDomain) { - InternalTransaction activeTransaction = ((InternalTransactionalEditingDomain) editingDomain) - .getActiveTransaction(); - if ((null != activeTransaction) && activeTransaction.isActive()) { - command.run(); - } else { - executionManager.execute(command); + return result; + } + + /** + * Get the SuperSet of a list of Feature Sets + * + * @param featureSets + * @return + */ + public static Set getSuperSet(List featureSets) { + Set featureList = new HashSet<>(); + + for (EObject featureSet : featureSets) { + if (featureSet instanceof FilteringCriterionSet) { + for (FilteringCriterion feature : ((FilteringCriterionSet) featureSet).getFilteringCriteria()) { + if (!featureList.contains(feature)) { + featureList.add(feature); + } + } + } } - } - } - } - - /** - * This method verifies if there is an active transaction.
- * If such case, the command is simply run.
- * If not, the command is executed through the execution manager.
- * - * @param command - * the command to be executed - * @param eObject - */ - public static void executeCommand(ICommand command, EObject eObject) { - executeCommand(command, TransactionHelper.getEditingDomain(eObject)); - } - - /** - * This method verifies if there is an active transaction.
- * If such case, the command is simply run.
- * If not, the command is executed through the execution manager.
- * - * @param command - * @param session - */ - public static void executeCommand(AbstractReadWriteCommand command, Session session) { - executeCommand(command, session.getTransactionalEditingDomain()); - } - - /** - * @param command - * @param elements - */ - public static void executeCommand(AbstractReadWriteCommand command, Collection elements) { - executeCommand(command, TransactionHelper.getEditingDomain(elements)); - } - - /** - * Some classes should not have associated feature sets - * - * All filtering classes except Exclusion/Intersection/Union are allowed - * - * @param obj - * @return true if it is excluded from having associated features - */ - public static boolean isInstanceOfFilteringExcludedElements(Object obj) { - return obj instanceof EObject && FilteringPackage.eINSTANCE.equals(((EObject) obj).eClass().getEPackage()); - } - - public static boolean notInstanceOfFilteringPackageMetaclass(Object obj) { - return (obj instanceof EObject) && !isInstanceOfFilteringExcludedElements(obj); - } - - /** - * Get the semantic models of a project - * - * @param project - * @return non null list - * @throws CoreException - */ - public static List getSemanticModels(IProject project) throws CoreException { - List result = new ArrayList(); - for (IResource resource : project.members()) { - String ext = resource.getFileExtension(); - if (CapellaResourceHelper.CAPELLA_MODEL_FILE_EXTENSION.equals(ext)) { - result.add((IFile) resource); - } - } - return result; - } - - /** - * Get the aird models of a project - * - * @param project - * @return non null list - * @throws CoreException - */ - public static List getAirdModels(IProject project) throws CoreException { - List result = new ArrayList(); - for (IResource resource : project.members()) { - String ext = resource.getFileExtension(); - if (CapellaResourceHelper.AIRD_FILE_EXTENSION.equals(ext)) { - result.add((IFile) resource); - } - } - return result; - } - - /** - * Get the SuperSet of a list of Feature Sets - * - * @param featureSets - * @return - */ - public static Set getSuperSet(List featureSets) { - Set featureList = new HashSet<>(); - - for (EObject featureSet : featureSets) { - if (featureSet instanceof FilteringCriterionSet) { - for (FilteringCriterion feature : ((FilteringCriterionSet) featureSet).getFilteringCriteria()) { - if (!featureList.contains(feature)) { - featureList.add(feature); - } + return featureList; + } + + /** + * Check if a filteringResult contains a given filtering feature + * + * @param filteringResult + * @param filteringCriterion + * @return if a filteringResult contains a given filtering feature + */ + public static boolean isCriterionInResult(AbstractFilteringResult filteringResult, FilteringCriterion filteringCriterion) { + if (filteringResult == null || filteringCriterion == null) + return false; + + FilteringCriterionSet criterionSet = filteringResult.computeFilteringCriterionSet(); + + if (criterionSet != null) { + return criterionSet.getFilteringCriteria().contains(filteringCriterion); } - } - } - return featureList; - } - - /** - * Check if a filteringResult contains a given filtering feature - * - * @param filteringResult - * @param filteringCriterion - * @return if a filteringResult contains a given filtering feature - */ - public static boolean isCriterionInResult(AbstractFilteringResult filteringResult, - FilteringCriterion filteringCriterion) { - if (filteringResult == null || filteringCriterion == null) - return false; - - FilteringCriterionSet criterionSet = filteringResult.computeFilteringCriterionSet(); - - if (criterionSet != null) { - return criterionSet.getFilteringCriteria().contains(filteringCriterion); - } - return false; - } - - /** - * Refresh a given diagram. - * - * - * @param graphicalEditor - */ - public static void forceRefreshDiagram(GraphicalEditor graphicalEditor) { - // Set focus refresh nodes - graphicalEditor.setFocus(); - // But then we need to do this for Edges, otherwise it won't be - // refreshed... - Object adaptation = graphicalEditor.getAdapter(GraphicalViewer.class); - if (adaptation != null) { - GraphicalViewer gv = (GraphicalViewer) adaptation; - for (Iterator ite = gv.getEditPartRegistry().values().iterator(); ite.hasNext();) { - EditPart editpart = (EditPart) ite.next(); - if (editpart instanceof ConnectionEditPart) { - editpart.refresh(); + return false; + } + + /** + * Refresh a given diagram. + * + * + * @param graphicalEditor + */ + public static void forceRefreshDiagram(GraphicalEditor graphicalEditor) { + // Set focus refresh nodes + graphicalEditor.setFocus(); + // But then we need to do this for Edges, otherwise it won't be + // refreshed... + Object adaptation = graphicalEditor.getAdapter(GraphicalViewer.class); + if (adaptation != null) { + GraphicalViewer gv = (GraphicalViewer) adaptation; + for (Iterator ite = gv.getEditPartRegistry().values().iterator(); ite.hasNext();) { + EditPart editpart = (EditPart) ite.next(); + if (editpart instanceof ConnectionEditPart) { + editpart.refresh(); + } + } } - } - } - } - - /** - * force the Refresh of all open Diagrams - */ - public static void forceRefreshAllDiagrams() { - IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); - if ((window != null) && (window.getActivePage() != null)) { - IEditorReference[] editors = window.getActivePage().getEditorReferences(); - if (editors != null) { - for (IEditorReference editor : editors) { - IEditorPart editorPart = editor.getEditor(true); - if (editorPart.getEditorSite() != null) { - if (editorPart.getEditorSite().getId().equals(DDiagramEditor.EDITOR_ID)) { - forceRefreshDiagram((GraphicalEditor) editorPart); + } + + /** + * force the Refresh of all open Diagrams + */ + public static void forceRefreshAllDiagrams() { + IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); + if ((window != null) && (window.getActivePage() != null)) { + IEditorReference[] editors = window.getActivePage().getEditorReferences(); + if (editors != null) { + for (IEditorReference editor : editors) { + IEditorPart editorPart = editor.getEditor(true); + if (editorPart.getEditorSite() != null) { + if (editorPart.getEditorSite().getId().equals(DDiagramEditor.EDITOR_ID)) { + forceRefreshDiagram((GraphicalEditor) editorPart); + } + } + } } - } } - } - } - } - - /** - * force the Refresh of active diagram - */ - public static void forceRefreshActiveDiagram() { - IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); - if (window != null) { - IWorkbenchPage workbenchPage = window.getActivePage(); - if (workbenchPage != null) { - IEditorPart editorPart = workbenchPage.getActiveEditor(); - if (editorPart instanceof GraphicalEditor) { - forceRefreshDiagram((GraphicalEditor) editorPart); + } + + /** + * force the Refresh of active diagram + */ + public static void forceRefreshActiveDiagram() { + IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); + if (window != null) { + IWorkbenchPage workbenchPage = window.getActivePage(); + if (workbenchPage != null) { + IEditorPart editorPart = workbenchPage.getActiveEditor(); + if (editorPart instanceof GraphicalEditor) { + forceRefreshDiagram((GraphicalEditor) editorPart); + } + } } - } - } - } - - /** - * Refresh all representations - * - * @param session - * @param executionManager - */ - public static void refreshAllRepresentations(final Session session, ExecutionManager executionManager) { - // Refresh all diagrams on session - // See RefreshDiagramsCommandHandler if this refresh implementation - // causes problems - Collection representationsToRefresh = DialectManager.INSTANCE.getAllRepresentations(session); - for (final DRepresentation representation : representationsToRefresh) { - if (DialectManager.INSTANCE.canRefresh(representation)) { - executionManager.execute(new AbstractNonDirtyingCommand() { - @Override - public void run() { - DialectManager.INSTANCE.refresh(representation, true, new NullProgressMonitor()); - if (representation instanceof DDiagram) { - synchronizeGMFModel(session, (DDiagram) representation); + } + + /** + * Refresh all representations + * + * @param session + * @param executionManager + */ + public static void refreshAllRepresentations(final Session session, ExecutionManager executionManager) { + // Refresh all diagrams on session + // See RefreshDiagramsCommandHandler if this refresh implementation + // causes problems + Collection representationsToRefresh = DialectManager.INSTANCE.getAllRepresentations(session); + for (final DRepresentation representation : representationsToRefresh) { + if (DialectManager.INSTANCE.canRefresh(representation)) { + executionManager.execute(new AbstractNonDirtyingCommand() { + @Override + public void run() { + DialectManager.INSTANCE.refresh(representation, true, new NullProgressMonitor()); + if (representation instanceof DDiagram) { + synchronizeGMFModel(session, (DDiagram) representation); + } + } + }); } - } - }); - } - } - } - - private static void synchronizeGMFModel(Session session, DDiagram dDiagram) { - Diagram gmfDiagram = SiriusGMFHelper.getGmfDiagram(dDiagram, session); - CanonicalSynchronizer canonicalSynchronizer = CanonicalSynchronizerFactory.INSTANCE - .createCanonicalSynchronizer(gmfDiagram); - canonicalSynchronizer.synchronize(); - } - - /** - * @param resource - * @return if the resource exists in the workspace or in the file system - */ - public static boolean resourceExists(IResource resource) { - // Check that the resource exists in the workspace - if (resource.exists()) { - return true; - } - // Check that the resource exists in the fileSystem - // May be a project was deleted from the workspace without deleting its - // real contents - File file = resource.getWorkspace().getRoot().getLocation().append(resource.getName()).toFile(); - return ((file != null) && file.exists()); - } - - /** - * @param resource - * @return if the resource exists in the workspace or in the file system - */ - public static boolean projectExists(String projectName) { - IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName); - - // Check that the resource exists in the workspace - if (project.exists()) { - return true; - } - // Check that the resource exists in the fileSystem - // May be a project was deleted from the workspace without deleting its - // real contents - File file = project.getFullPath().toFile(); - return ((file != null) && file.exists()); - } - - public static Collection getComposedResultChildren(ComposedFilteringResult composedResult) { - - Collection children = new HashSet<>(); - - Optional.ofNullable(composedResult.getIntersectionFilteringResultSet()).ifPresent(children::add); - Optional.ofNullable(composedResult.getUnionFilteringResultSet()).ifPresent(children::add); - Optional.ofNullable(composedResult.getExclusionFilteringResultSet()).ifPresent(children::add); - - return children; - } - - /** - * Returns a map of dirty referenced [model, session] for the current project. The analysis takes into account the - * project itself and all the referenced libraries. - * - * @param project - * the project. - * @return a map of dirty referenced [model, session] for the current project. - */ - public static Map getDirtyReferencedModels(Project project) { - TransactionalEditingDomain editingDomain = TransactionHelper.getEditingDomain(project); - - if (editingDomain != null) { - IModel rootModel = ILibraryManager.INSTANCE.getModel(editingDomain); - - if (rootModel != null) { - Collection referencedLibraries = LibraryManagerExt.getAllReferences(rootModel); - Set modelsToAnalyse = new HashSet<>(referencedLibraries); - modelsToAnalyse.add(rootModel); - - Map modelToUnsavedSession = new HashMap<>(); - - for (Session session : SessionManager.INSTANCE.getSessions()) { - if (session.getStatus() == SessionStatus.DIRTY) { - TransactionalEditingDomain sessionEditingDomain = session.getTransactionalEditingDomain(); - IModel sessionModel = ILibraryManager.INSTANCE.getModel(sessionEditingDomain); - - if (modelsToAnalyse.contains(sessionModel)) { - modelToUnsavedSession.put(sessionModel, session); + } + } + + private static void synchronizeGMFModel(Session session, DDiagram dDiagram) { + Diagram gmfDiagram = SiriusGMFHelper.getGmfDiagram(dDiagram, session); + CanonicalSynchronizer canonicalSynchronizer = CanonicalSynchronizerFactory.INSTANCE.createCanonicalSynchronizer(gmfDiagram); + canonicalSynchronizer.synchronize(); + } + + /** + * @param resource + * @return if the resource exists in the workspace or in the file system + */ + public static boolean resourceExists(IResource resource) { + // Check that the resource exists in the workspace + if (resource.exists()) { + return true; + } + // Check that the resource exists in the fileSystem + // May be a project was deleted from the workspace without deleting its + // real contents + File file = resource.getWorkspace().getRoot().getLocation().append(resource.getName()).toFile(); + return ((file != null) && file.exists()); + } + + /** + * @param resource + * @return if the resource exists in the workspace or in the file system + */ + public static boolean projectExists(String projectName) { + IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName); + + // Check that the resource exists in the workspace + if (project.exists()) { + return true; + } + // Check that the resource exists in the fileSystem + // May be a project was deleted from the workspace without deleting its + // real contents + File file = project.getFullPath().toFile(); + return ((file != null) && file.exists()); + } + + public static Collection getComposedResultChildren(ComposedFilteringResult composedResult) { + + Collection children = new HashSet<>(); + + Optional.ofNullable(composedResult.getIntersectionFilteringResultSet()).ifPresent(children::add); + Optional.ofNullable(composedResult.getUnionFilteringResultSet()).ifPresent(children::add); + Optional.ofNullable(composedResult.getExclusionFilteringResultSet()).ifPresent(children::add); + + return children; + } + + /** + * Returns a map of dirty referenced [model, session] for the current project. The analysis takes into account the + * project itself and all the referenced libraries. + * + * @param project + * the project. + * @return a map of dirty referenced [model, session] for the current project. + */ + public static Map getDirtyReferencedModels(Project project) { + TransactionalEditingDomain editingDomain = TransactionHelper.getEditingDomain(project); + + if (editingDomain != null) { + IModel rootModel = ILibraryManager.INSTANCE.getModel(editingDomain); + + if (rootModel != null) { + Collection referencedLibraries = LibraryManagerExt.getAllReferences(rootModel); + Set modelsToAnalyse = new HashSet<>(referencedLibraries); + modelsToAnalyse.add(rootModel); + + Map modelToUnsavedSession = new HashMap<>(); + + for (Session session : SessionManager.INSTANCE.getSessions()) { + if (session.getStatus() == SessionStatus.DIRTY) { + TransactionalEditingDomain sessionEditingDomain = session.getTransactionalEditingDomain(); + IModel sessionModel = ILibraryManager.INSTANCE.getModel(sessionEditingDomain); + + if (modelsToAnalyse.contains(sessionModel)) { + modelToUnsavedSession.put(sessionModel, session); + } + } + } + return modelToUnsavedSession; } - } } - return modelToUnsavedSession; - } - } - - return Collections.emptyMap(); - } - - public static String extractModelNames(Collection models) { - - return models.stream() // - .map(model -> model.getIdentifier().getName()) // - .map(name -> new Path(name).removeFileExtension().toString()) // - .collect(Collectors.joining(", ")); - } - - /** - * TODO doc - * @param project - */ - public static FilteringResult clearFilteringResultsForProject(Project project) { - FilteringResult noCriteriaResult = FilteringFactory.eINSTANCE.createFilteringResult(); - FilteringToolsPlugin.getGlobalFilteringCache().setCurrentFilteringResult(project, noCriteriaResult); - return noCriteriaResult; - } + + return Collections.emptyMap(); + } + + public static String extractModelNames(Collection models) { + + return models.stream() // + .map(model -> model.getIdentifier().getName()) // + .map(name -> new Path(name).removeFileExtension().toString()) // + .collect(Collectors.joining(", ")); + } + + /** + * Clear Global Filtering Cache filtering results for {@code project}. + * + * @param project + * The project for which filtering results are cleared. + * @return The empty {@code FilteringResult} assigned to {@code project} + */ + public static FilteringResult clearFilteringResultsForProject(Project project) { + FilteringResult noCriteriaResult = FilteringFactory.eINSTANCE.createFilteringResult(); + FilteringToolsPlugin.getGlobalFilteringCache().setCurrentFilteringResult(project, noCriteriaResult); + return noCriteriaResult; + } }