/** * Unapply profiles duplicated for control action * * @param selection * @param target the resource target */ private void unapplyDuplicateProfiles(final EObject selection, Resource target) { Package _package = (Package) selection; EList<Profile> allAppliedProfiles = _package.getAllAppliedProfiles(); if (!allAppliedProfiles.isEmpty()) { for (Profile profile : new ArrayList<Profile>(_package.getAppliedProfiles())) { if (allAppliedProfiles.contains(profile)) { // profile is duplicated, unapply it ProfileApplicationHelper.removeProfileApplicationDuplication(_package, profile, true); } } } }
/** * Handle the case when a stereotype application is removed : - Forbid direct removal of a * duplicated profile application (with eAnnotation) - Inspect controlled sub-packages - Remove * duplicated profile applications on these (with eAnnotation) * * @param packageElement the package from which stereotype application has been removed * @param profileAppl the removed profile application * @param profile the unapplied profile * @return whether removal is allowed */ private boolean stereotypeApplicationRemoved( Package packageElement, ProfileApplication profileAppl, Profile profile) { // Forbid direct removal of a duplicated profile application (with eAnnotation) if (ProfileApplicationHelper.isDuplicatedProfileApplication(profileAppl)) { Package parentPack = ProfileApplicationHelper.getParentPackageWithProfile(packageElement, profile, true); // restore stereotype application when it is called from parent intermediate package ProfileApplicationHelper.duplicateProfileApplication(packageElement, profile); String msg; if (parentPack != null) { msg = NLS.bind( Messages.warning_cannot_delete_duplicated, EMFCoreUtil.getQualifiedName(packageElement, true), EMFCoreUtil.getQualifiedName(parentPack, true)); } else { // parent package can not be reached as it is in a different maybe not accessible resource // (working on controlled resource) msg = NLS.bind( Messages.warning_cannot_delete_duplicated_alt, EMFCoreUtil.getQualifiedName(packageElement, true)); } NotificationBuilder notifBuild = NotificationBuilder.createAsyncPopup(msg); notifBuild.run(); return true; } // Inspect controlled sub-packages Set<Package> controlledPack = getControlledSubPackages(packageElement); boolean update = checkControlledPackagesUpdateable(controlledPack); if (update) { for (Package pack : controlledPack) { ProfileApplicationHelper.removeProfileApplicationDuplication(pack, profile, false); } return true; } else { return false; } }
/** * Handle the case when a stereotype application is added : - Inspect controlled sub-packages - * Duplicate profile applicationss on these - Create eAnnotation for duplicated profiles * * @param packageElement the package on which stereotype application has been added * @param profileAppl the added profile application * @return whether addition is allowed */ private boolean stereotypeApplicationAdded( Package packageElement, ProfileApplication profileAppl) { // Inspect controlled sub-packages Set<Package> controlledPack = getControlledSubPackages(packageElement); boolean update = checkControlledPackagesUpdateable(controlledPack); if (update) { for (Package pack : controlledPack) { ProfileApplicationHelper.duplicateProfileApplication(pack, profileAppl.getAppliedProfile()); } return true; } else { return false; } }