| //------------------------------------------------------------------------------ |
| // Copyright (c) 2005, 2006 IBM Corporation and others. |
| // All rights reserved. This program and the accompanying materials |
| // are made available under the terms of the Eclipse Public License v1.0 |
| // which accompanies this distribution, and is available at |
| // http://www.eclipse.org/legal/epl-v10.html |
| // |
| // Contributors: |
| // IBM Corporation - initial implementation |
| //------------------------------------------------------------------------------ |
| package org.eclipse.epf.library.edit.category; |
| |
| import java.util.ArrayList; |
| import java.util.Collection; |
| import java.util.Iterator; |
| |
| import org.eclipse.epf.library.edit.util.TngUtil; |
| |
| import com.ibm.uma.ContentCategory; |
| import com.ibm.uma.ContentPackage; |
| import com.ibm.uma.Discipline; |
| import com.ibm.uma.DisciplineGrouping; |
| import com.ibm.uma.UmaFactory; |
| import com.ibm.uma.VariabilityElement; |
| import com.ibm.uma.util.AssociationHelper; |
| |
| /** |
| * @author Phong Nguyen Le |
| * @since 1.0 |
| */ |
| public class InheritedDisciplinePackageListener extends |
| InheritedCategoryPackageListener { |
| |
| /** |
| * @param pkg |
| */ |
| public InheritedDisciplinePackageListener(ContentPackage pkg) { |
| super(pkg); |
| } |
| |
| /* |
| * (non-Javadoc) |
| * |
| * @see com.ibm.library.edit.category.InheritedCategoryPackageListener#isEmpty(com.ibm.uma.ContentCategory) |
| */ |
| public boolean isEmpty(ContentCategory element) { |
| if (element instanceof DisciplineGrouping) { |
| for (Iterator iter = ((DisciplineGrouping) element) |
| .getDisciplines().iterator(); iter.hasNext();) { |
| Discipline discipline = (Discipline) iter.next(); |
| if (discipline.getVariabilityBasedOnElement() == null |
| || !discipline.getTasks().isEmpty()) { |
| return false; |
| } |
| } |
| return true; |
| } else if (element instanceof Discipline) { |
| return ((Discipline) element).getTasks().isEmpty(); |
| } |
| return false; |
| } |
| |
| /* |
| * (non-Javadoc) |
| * |
| * @see com.ibm.library.edit.category.InheritedCategoryPackageListener#accept(java.lang.Object) |
| */ |
| public boolean accept(Object obj) { |
| return (obj instanceof DisciplineGrouping || obj instanceof Discipline) |
| && ((ContentCategory) obj).getVariabilityBasedOnElement() == null; |
| } |
| |
| /* |
| * (non-Javadoc) |
| * |
| * @see com.ibm.library.edit.category.InheritedCategoryPackageListener#createCategory() |
| */ |
| protected ContentCategory createCategory(ContentCategory targetCategory) { |
| if (targetCategory instanceof DisciplineGrouping) { |
| return UmaFactory.eINSTANCE.createDisciplineGrouping(); |
| } else if (targetCategory instanceof Discipline) { |
| return UmaFactory.eINSTANCE.createDiscipline(); |
| } |
| return null; |
| } |
| |
| // /* (non-Javadoc) |
| // * @see |
| // com.ibm.library.edit.category.InheritedCategoryPackageListener#addInherited(com.ibm.uma.ContentCategory) |
| // */ |
| // protected void addInherited(ContentCategory targetCategory) { |
| // ContentCategory category = createInherited(targetCategory); |
| // ContentElement baseCategory = category.getVariabilityBasedOnElement(); |
| // if(baseCategory instanceof DisciplineGrouping) { |
| // DisciplineGrouping disciplineGrouping = (DisciplineGrouping) category; |
| // for (Iterator iterator = |
| // ((DisciplineGrouping)baseCategory).getDisciplines().iterator(); |
| // iterator.hasNext();) { |
| // Discipline element = (Discipline) iterator.next(); |
| // disciplineGrouping.getDisciplines().add(TngUtil.findInherited(categoryPackage.getContentElements(), |
| // element)); |
| // } |
| // } |
| // else if(baseCategory instanceof Discipline) { |
| // Discipline discipline = (Discipline) category; |
| // for (Iterator iter = |
| // ((Discipline)baseCategory).getDisciplineGroups().iterator(); |
| // iter.hasNext();) { |
| // DisciplineGrouping element = (DisciplineGrouping) iter.next(); |
| // discipline.getDisciplineGroups().add(TngUtil.findInherited(categoryPackage.getContentElements(), |
| // element)); |
| // } |
| // } |
| // categoryPackage.getContentElements().add(category); |
| // |
| // } |
| |
| protected void prepareInherited(Collection inheritedList) { |
| ArrayList categories = new ArrayList(inheritedList); |
| categories.addAll(categoryPackage.getContentElements()); |
| for (Iterator iter = inheritedList.iterator(); iter.hasNext();) { |
| ContentCategory category = (ContentCategory) iter.next(); |
| VariabilityElement baseCategory = category |
| .getVariabilityBasedOnElement(); |
| if (baseCategory instanceof DisciplineGrouping) { |
| DisciplineGrouping disciplineGrouping = (DisciplineGrouping) category; |
| for (Iterator iterator = ((DisciplineGrouping) baseCategory) |
| .getDisciplines().iterator(); iterator.hasNext();) { |
| Discipline element = (Discipline) iterator.next(); |
| ContentCategory inherited = TngUtil.findInherited( |
| categories, element); |
| if (inherited != null) { |
| disciplineGrouping.getDisciplines().add(inherited); |
| } |
| } |
| } else if (baseCategory instanceof Discipline) { |
| Discipline discipline = (Discipline) category; |
| for (Iterator iteration = AssociationHelper |
| .getDisciplineGroups((Discipline) baseCategory) |
| .iterator(); iteration.hasNext();) { |
| DisciplineGrouping element = (DisciplineGrouping) iteration |
| .next(); |
| ContentCategory inherited = TngUtil.findInherited( |
| categories, element); |
| if (inherited != null) { |
| ((DisciplineGrouping) inherited).getDisciplines().add( |
| discipline); |
| // MethodLibraryHelper.getDisciplineGroups(discipline).add(inherited); |
| } |
| } |
| } |
| } |
| } |
| |
| /* |
| * (non-Javadoc) |
| * |
| * @see com.ibm.library.edit.category.InheritedCategoryPackageListener#prepareRemove(com.ibm.uma.ContentCategory) |
| */ |
| protected void prepareRemove(ContentCategory element) { |
| if (element instanceof Discipline) { |
| AssociationHelper.getDisciplineGroups((Discipline) element).clear(); |
| } |
| } |
| |
| } |