blob: 330554ed1b8400f6b180596619975dc3f328acff [file] [log] [blame]
//------------------------------------------------------------------------------
// 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.layout.elements;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.epf.library.configuration.ConfigurationHelper;
import org.eclipse.epf.library.layout.ElementLayoutManager;
import org.eclipse.epf.library.layout.IElementLayout;
import org.eclipse.epf.library.layout.util.XmlElement;
import org.eclipse.epf.library.util.LibraryUtil;
import org.eclipse.epf.uma.MethodElement;
import org.eclipse.epf.uma.UmaPackage;
/**
* The layout for a TaskDescriptor.
*
* @author Jinhua Xi
* @author Phong Nguyen Le
* @since 1.0
*/
public class TaskDescriptorLayout extends DescriptorLayout {
public static final Collection<EStructuralFeature> extraFeaturesFromTask = Arrays.asList(new EStructuralFeature[] {
UmaPackage.eINSTANCE.getTask_ToolMentors()
});
public TaskDescriptorLayout() {
super();
}
public void init(ElementLayoutManager layoutManager, MethodElement element) {
super.__init(layoutManager, element);
}
public XmlElement getXmlElement(boolean includeReferences) {
return super.getXmlElement(includeReferences);
}
/**
* @see org.eclipse.epf.library.layout.elements.AbstractElementLayout#loadReferences(XmlElement, boolean)
*/
public void loadReferences(XmlElement elementXml, boolean includeReferences) {
List features = LibraryUtil.getStructuralFeatures(element);
// List properties = element.getInstanceProperties();
if (features != null) {
for (int i = 0; i < features.size(); i++) {
EStructuralFeature feature = (EStructuralFeature) features
.get(i);
if (feature == UmaPackage.eINSTANCE
.getTaskDescriptor_SelectedSteps()) {
// need to handle the step contents by fixing the links
processSteps(elementXml, includeReferences);
} else if (feature == UmaPackage.eINSTANCE
.getWorkBreakdownElement_LinkToPredecessor()) {
super.loadWorkOrder(elementXml);
} else if (feature.getEType() instanceof EClass) {
loadFeature(feature, elementXml, includeReferences);
}
}
}
elementXml.setAttribute("ShowFullMethodContent", (layoutManager.getValidator().showExtraInfoForDescriptors()) ? "true" : "false");
if ((super.elementLayout != null ) && layoutManager.getValidator().showExtraInfoForDescriptors() ) {
// also load the linked element referenced information
for (Iterator<EStructuralFeature> iterator = getExtraFeaturesFromContentElement().iterator(); iterator.hasNext();) {
EStructuralFeature feature = iterator.next();
super.elementLayout.loadFeature(feature, elementXml, false);
}
}
}
private void processSteps(XmlElement elementXml, boolean includeReferences) {
EStructuralFeature feature = UmaPackage.eINSTANCE
.getTaskDescriptor_SelectedSteps();
List items = ConfigurationHelper.calc0nFeatureValue(element, feature,
getLayoutMgr().getElementRealizer());
XmlElement stepXml = elementXml
.newChild("referenceList").setAttribute("name", feature.getName()); //$NON-NLS-1$ //$NON-NLS-2$
if (items != null && items.size() > 0) {
for (Iterator it = items.iterator(); it.hasNext();) {
Object e = it.next();
if (e instanceof MethodElement) {
MethodElement me = (MethodElement) e;
e = ConfigurationHelper.getCalculatedElement(me,
layoutManager.getConfiguration());
if (e != null) {
IElementLayout l = layoutManager.getLayout(me, true);
if (l != null) {
l.setContentTarget(element);
stepXml.addChild(l
.getXmlElement(ConfigurationHelper
.isDescriptionElement(me) ? true
: includeReferences));
}
}
}
}
}
}
@Override
protected Collection<EStructuralFeature> getExtraFeaturesFromContentElement() {
ArrayList<EStructuralFeature> features = new ArrayList<EStructuralFeature>(extraFeaturesFromTask);
features.addAll(super.getExtraFeaturesFromContentElement());
return features;
}
}