blob: 994ae6326bacab1fda33293e19592f752b3187d6 [file] [log] [blame]
package org.eclipse.epf.library.realization.impl;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import org.eclipse.emf.ecore.EAttribute;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.epf.library.configuration.ConfigurationHelper;
import org.eclipse.epf.library.configuration.DefaultElementRealizer;
import org.eclipse.epf.library.configuration.ElementRealizer;
import org.eclipse.epf.library.edit.realization.IRealizedDescriptor;
import org.eclipse.epf.library.edit.realization.IRealizedElement;
import org.eclipse.epf.library.edit.util.DescriptorPropUtil;
import org.eclipse.epf.uma.Activity;
import org.eclipse.epf.uma.Descriptor;
import org.eclipse.epf.uma.MethodElement;
import org.eclipse.epf.uma.RoleDescriptor;
import org.eclipse.epf.uma.TaskDescriptor;
import org.eclipse.epf.uma.UmaPackage;
import org.eclipse.epf.uma.WorkProductDescriptor;
import org.eclipse.epf.uma.ecore.util.OppositeFeature;
public class RealizedDescriptor extends RealizedElement implements
IRealizedDescriptor, IRealizedElement {
private static Set<EStructuralFeature> featureSet = new HashSet<EStructuralFeature>();
static {
UmaPackage up = UmaPackage.eINSTANCE;
featureSet.add(up.getNamedElement_Name());
featureSet.add(up.getMethodElement_PresentationName());
}
public RealizedDescriptor(Descriptor descriptor) {
super(descriptor);
}
public boolean handleFeature(EStructuralFeature feature) {
return featureSet.contains(feature);
}
public Object getFeatureValue(EStructuralFeature feature) {
if (! featureSet.contains(feature)) {
return null;
}
MethodElement linkedElement = getLinkedElement();
if (feature instanceof EAttribute) {
MethodElement elementUsed = linkedElement == null ? getDescriptor() : linkedElement;
Object value = ConfigurationHelper.calcAttributeFeatureValue(elementUsed, feature, getConfig());
return value;
}
return super.getFeatureValue(feature);
}
public Object getOFeatureValue(OppositeFeature ofeature) {
return super.getOFeatureValue(ofeature);
}
protected MethodElement getLinkedElement() {
throw new UnsupportedOperationException();
}
protected Descriptor getDescriptor() {
return (Descriptor) getElement();
}
protected List<? extends Descriptor> getDescriptorList(EReference elementFeature,
EReference[] descriptorFeatures) {
ElementRealizer realizer = DefaultElementRealizer
.newElementRealizer(getConfig());
EReference dFeature = descriptorFeatures[0];
EReference dFeatureExclude = descriptorFeatures[1];
EReference dFeatureInclude = descriptorFeatures[2];
MethodElement element = getLinkedElement();
if (element == null) {
return ConfigurationHelper.calc0nFeatureValue(getDescriptor(),
dFeature, realizer);
}
List<MethodElement> elementList = ConfigurationHelper.calc0nFeatureValue(element,
elementFeature, realizer);
List<Descriptor> includeList = ConfigurationHelper.calc0nFeatureValue(getDescriptor(),
dFeatureInclude, realizer);
List<Descriptor> resultDescriptorList = new ArrayList<Descriptor>();
List<Descriptor> excludeList = null;
if (elementList != null && !elementList.isEmpty() ||
includeList != null && !includeList.isEmpty()) {
excludeList = ConfigurationHelper.calc0nFeatureValue(getDescriptor(),
dFeatureExclude, realizer);
}
Set<MethodElement> excludeElements = new HashSet<MethodElement>();
if (excludeList != null && !excludeList.isEmpty()) {
for (Descriptor des : excludeList) {
MethodElement elem = getLinkedElement();
if (elem != null) {
excludeElements.add(elem);
}
}
}
Set<MethodElement> elementSet = new LinkedHashSet<MethodElement>();
if (elementList != null) {
for (MethodElement elem : elementList) {
if (! excludeElements.contains(elem)) {
elementSet.add(elem);
}
}
}
if (includeList != null) {
for (MethodElement elem : includeList) {
if (! includeList.contains(elem)) {
elementSet.add(elem);
}
}
}
List<Descriptor> descriptorList = ConfigurationHelper.calc0nFeatureValue(
getDescriptor(), dFeature, realizer);
for (Descriptor des : descriptorList) {
MethodElement me = getLinkedElement(des);
if (me == null
|| DescriptorPropUtil.getDesciptorPropUtil().staticUse(des,
getDescriptor())) {
resultDescriptorList.add(des);
} else if (elementSet.contains(me)) {
resultDescriptorList.add(des);
elementSet.remove(me);
}
}
if (elementSet.isEmpty()) {
return resultDescriptorList;
}
Activity parentAct = getDescriptor().getSuperActivities();
if (parentAct == null) {
return resultDescriptorList;
}
for (MethodElement me : elementSet) {
Descriptor des = (Descriptor) getMgr().getDescriptor(
getDescriptor(), parentAct, me, dFeature);
resultDescriptorList.add(des);
}
return resultDescriptorList;
}
private MethodElement getLinkedElement(Descriptor des) {
if (des instanceof TaskDescriptor) {
return ((TaskDescriptor) des).getTask();
}
if (des instanceof RoleDescriptor) {
return ((RoleDescriptor) des).getRole();
}
if (des instanceof WorkProductDescriptor) {
return ((WorkProductDescriptor) des).getWorkProduct();
}
return null;
}
}