/******************************************************************************* 
 * Copyright (c) 2011 Red Hat, Inc. 
 *  All rights reserved. 
 * This program is 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: 
 * Red Hat, Inc. - initial API and implementation 
 *
 * @author Innar Made
 ******************************************************************************/
package org.camunda.bpm.modeler.ui.features.activity.subprocess;

import org.camunda.bpm.modeler.core.features.AbstractUpdateBaseElementFeature;
import org.camunda.bpm.modeler.core.features.MultiUpdateFeature;
import org.camunda.bpm.modeler.core.features.activity.task.DirectEditActivityFeature;
import org.camunda.bpm.modeler.ui.features.activity.AbstractActivityFeatureContainer;
import org.eclipse.bpmn2.BaseElement;
import org.eclipse.bpmn2.CallChoreography;
import org.eclipse.bpmn2.FlowElementsContainer;
import org.eclipse.graphiti.features.IDirectEditingFeature;
import org.eclipse.graphiti.features.IFeatureProvider;
import org.eclipse.graphiti.features.ILayoutFeature;
import org.eclipse.graphiti.features.IResizeShapeFeature;
import org.eclipse.graphiti.features.context.IUpdateContext;
import org.eclipse.graphiti.features.custom.ICustomFeature;

public abstract class AbstractExpandableActivityFeatureContainer extends AbstractActivityFeatureContainer {

	@Override
	public IDirectEditingFeature getDirectEditingFeature(IFeatureProvider fp) {
		return new DirectEditActivityFeature(fp);
	}

	@Override
	public ILayoutFeature getLayoutFeature(IFeatureProvider fp) {
		return new LayoutExpandableActivityFeature(fp);
	}
	
	@Override
	public MultiUpdateFeature getUpdateFeature(IFeatureProvider fp) {
		MultiUpdateFeature multiUpdate = super.getUpdateFeature(fp);
		AbstractUpdateBaseElementFeature nameUpdateFeature = new AbstractUpdateBaseElementFeature(fp) {
			@Override
			public boolean canUpdate(IUpdateContext context) {
				Object bo = getBusinessObjectForPictogramElement(context.getPictogramElement());
				return bo != null && bo instanceof BaseElement && canApplyTo((BaseElement) bo);
			}
		};
		multiUpdate.addUpdateFeature(nameUpdateFeature);
		return multiUpdate;
	}

	@Override
	public IResizeShapeFeature getResizeFeature(IFeatureProvider fp) {
		return new ResizeExpandableActivityFeature(fp);
	}
	
	@Override
	public ICustomFeature[] getCustomFeatures(IFeatureProvider fp) {
		ICustomFeature[] superFeatures = super.getCustomFeatures(fp);
		ICustomFeature[] thisFeatures = new ICustomFeature[2 + superFeatures.length];
		thisFeatures[0] = new ExpandFlowNodeFeature(fp);
		thisFeatures[1] = new CollapseFlowNodeFeature(fp);
		for (int i=0; i<superFeatures.length; ++i)
			thisFeatures[2+i] = superFeatures[i];
		return thisFeatures;
	}

	public static boolean isExpandableElement(Object be) {
		return be instanceof FlowElementsContainer
				|| be instanceof CallChoreography;
	}
}
@@ -1239,32 +1239,100 @@
 zeShapeFeature;%0A
+import org.eclipse.graphiti.features.context.IDirectEditingContext;%0A
 import org.eclip
@@ -1435,16 +1435,125 @@
 Feature;
+%0Aimport org.eclipse.graphiti.mm.pictograms.PictogramElement;%0Aimport org.eclipse.graphiti.mm.pictograms.Shape;
 %0A%0Apublic
@@ -1781,24 +1781,571 @@
 yFeature(fp)
+ %7B%0A%09%09%09@Override%0A%09%09%09public void setValue(String value, IDirectEditingContext context) %7B%0A%09%09%09%09// get old value for fix below%0A%09%09%09%09Object businessObject = getBusinessObject(context);%0A%09%09%09%09String oldValue = getNameValue(businessObject);%0A%0A%09%09%09%09// update the value%0A%09%09%09%09setNameValue(businessObject, value);%0A%09%09%09%09PictogramElement e = context.getPictogramElement();%0A%09%09%09%09updatePictogramElement(((Shape) e).getContainer());%0A%0A%09%09%09%09// fix for missing layout update when editing initial value%0A%09%09%09%09if (oldValue == null) %7B%0A%09%09%09%09%09layoutPictogramElement(e);%0A%09%09%09%09%7D%0A%09%09%09%7D%0A%09%09%7D
 ;%0A%09%7D%0A%0A%09@Over

Fix missing layout update of ExpandableActivityFeatureContainer