| /******************************************************************************* |
| * Copyright (c) 2011, 2012 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 Ivar Meikas |
| ******************************************************************************/ |
| package org.eclipse.bpmn2.modeler.core.features; |
| |
| import org.eclipse.bpmn2.BaseElement; |
| import org.eclipse.bpmn2.modeler.core.utils.BusinessObjectUtil; |
| import org.eclipse.graphiti.features.IDeleteFeature; |
| import org.eclipse.graphiti.features.IDirectEditingFeature; |
| import org.eclipse.graphiti.features.IFeatureProvider; |
| import org.eclipse.graphiti.features.ILayoutFeature; |
| import org.eclipse.graphiti.features.IMoveConnectionDecoratorFeature; |
| import org.eclipse.graphiti.features.IReconnectionFeature; |
| import org.eclipse.graphiti.features.IRemoveFeature; |
| import org.eclipse.graphiti.features.IUpdateFeature; |
| import org.eclipse.graphiti.features.context.IAddContext; |
| import org.eclipse.graphiti.features.context.IContext; |
| import org.eclipse.graphiti.features.context.ICustomContext; |
| import org.eclipse.graphiti.features.context.IPictogramElementContext; |
| import org.eclipse.graphiti.features.context.IReconnectionContext; |
| import org.eclipse.graphiti.features.custom.ICustomFeature; |
| import org.eclipse.graphiti.mm.pictograms.PictogramElement; |
| |
| /** |
| * This is the Graphiti FeatureContainer class for all BPMN2 model connection |
| * elements that subclass {@link BaseElement}. |
| */ |
| public abstract class BaseElementConnectionFeatureContainer implements IConnectionFeatureContainer { |
| |
| /* (non-Javadoc) |
| * @see org.eclipse.bpmn2.modeler.core.features.IFeatureContainer#getApplyObject(org.eclipse.graphiti.features.context.IContext) |
| */ |
| @Override |
| public Object getApplyObject(IContext context) { |
| if (context instanceof IAddContext) { |
| return ((IAddContext) context).getNewObject(); |
| } |
| else if (context instanceof IPictogramElementContext) { |
| return BusinessObjectUtil.getFirstElementOfType( |
| (((IPictogramElementContext) context).getPictogramElement()), BaseElement.class); |
| } |
| else if (context instanceof IReconnectionContext) { |
| IReconnectionContext rc = (IReconnectionContext)context; |
| return BusinessObjectUtil.getFirstElementOfType(rc.getConnection(), BaseElement.class); |
| } |
| else if (context instanceof ICustomContext) { |
| PictogramElement[] pes = ((ICustomContext) context).getPictogramElements(); |
| if (pes.length==1) |
| return BusinessObjectUtil.getFirstElementOfType(pes[0], BaseElement.class); |
| } |
| return null; |
| } |
| |
| /* (non-Javadoc) |
| * @see org.eclipse.bpmn2.modeler.core.features.IFeatureContainer#canApplyTo(java.lang.Object) |
| */ |
| @Override |
| public boolean canApplyTo(Object o) { |
| return o instanceof BaseElement; |
| } |
| |
| /* (non-Javadoc) |
| * @see org.eclipse.bpmn2.modeler.core.features.IFeatureContainer#isAvailable(org.eclipse.graphiti.features.IFeatureProvider) |
| */ |
| @Override |
| public boolean isAvailable(IFeatureProvider fp) { |
| return true; |
| } |
| |
| /* (non-Javadoc) |
| * @see org.eclipse.bpmn2.modeler.core.features.IConnectionFeatureContainer#getReconnectionFeature(org.eclipse.graphiti.features.IFeatureProvider) |
| */ |
| @Override |
| public IReconnectionFeature getReconnectionFeature(IFeatureProvider fp) { |
| return new ReconnectBaseElementFeature(fp); |
| } |
| |
| /* (non-Javadoc) |
| * @see org.eclipse.bpmn2.modeler.core.features.IFeatureContainer#getDeleteFeature(org.eclipse.graphiti.features.IFeatureProvider) |
| */ |
| @Override |
| public IDeleteFeature getDeleteFeature(IFeatureProvider context) { |
| return null; |
| } |
| |
| /* (non-Javadoc) |
| * @see org.eclipse.bpmn2.modeler.core.features.IFeatureContainer#getRemoveFeature(org.eclipse.graphiti.features.IFeatureProvider) |
| */ |
| @Override |
| public IRemoveFeature getRemoveFeature(IFeatureProvider fp) { |
| return null; |
| } |
| |
| /* (non-Javadoc) |
| * @see org.eclipse.bpmn2.modeler.core.features.IFeatureContainer#getLayoutFeature(org.eclipse.graphiti.features.IFeatureProvider) |
| */ |
| @Override |
| public ILayoutFeature getLayoutFeature(IFeatureProvider fp) { |
| return new DefaultLayoutBPMNConnectionFeature(fp); |
| } |
| |
| /* (non-Javadoc) |
| * @see org.eclipse.bpmn2.modeler.core.features.IFeatureContainer#getUpdateFeature(org.eclipse.graphiti.features.IFeatureProvider) |
| */ |
| @Override |
| public IUpdateFeature getUpdateFeature(IFeatureProvider fp) { |
| return null; |
| } |
| |
| /* (non-Javadoc) |
| * @see org.eclipse.bpmn2.modeler.core.features.IFeatureContainer#getCustomFeatures(org.eclipse.graphiti.features.IFeatureProvider) |
| */ |
| @Override |
| public ICustomFeature[] getCustomFeatures(IFeatureProvider fp) { |
| return new ICustomFeature[] { |
| new ShowDocumentationFeature(fp), |
| new ShowPropertiesFeature(fp) |
| }; |
| } |
| |
| /* (non-Javadoc) |
| * @see org.eclipse.bpmn2.modeler.core.features.IFeatureContainer#getDirectEditingFeature(org.eclipse.graphiti.features.IFeatureProvider) |
| */ |
| @Override |
| public IDirectEditingFeature getDirectEditingFeature(IFeatureProvider fp) { |
| return new DirectEditBaseElementFeature(fp); |
| } |
| |
| @Override |
| public IMoveConnectionDecoratorFeature getMoveConnectionDecoratorFeature(IFeatureProvider fp) { |
| // TODO Auto-generated method stub |
| return null; |
| } |
| } |