/******************************************************************************* * 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 ******************************************************************************/ package org.eclipse.bpmn2.modeler.core.features.gateway; import org.eclipse.bpmn2.FlowElementsContainer; import org.eclipse.bpmn2.Gateway; import org.eclipse.bpmn2.modeler.core.features.AbstractBpmnAddFeature; import org.eclipse.bpmn2.modeler.core.features.BusinessObjectUtil; import org.eclipse.bpmn2.modeler.core.features.UpdateBaseElementNameFeature; import org.eclipse.bpmn2.modeler.core.utils.AnchorUtil; import org.eclipse.bpmn2.modeler.core.utils.FeatureSupport; import org.eclipse.bpmn2.modeler.core.utils.GraphicsUtil; import org.eclipse.bpmn2.modeler.core.utils.StyleUtil; import org.eclipse.graphiti.features.IFeatureProvider; import org.eclipse.graphiti.features.context.IAddContext; import org.eclipse.graphiti.mm.algorithms.Polygon; import org.eclipse.graphiti.mm.algorithms.Rectangle; import org.eclipse.graphiti.mm.algorithms.Text; import org.eclipse.graphiti.mm.algorithms.styles.Orientation; import org.eclipse.graphiti.mm.pictograms.ContainerShape; import org.eclipse.graphiti.mm.pictograms.PictogramElement; import org.eclipse.graphiti.mm.pictograms.Shape; import org.eclipse.graphiti.services.Graphiti; import org.eclipse.graphiti.services.IGaService; import org.eclipse.graphiti.services.IPeService; public class DefaultAddGatewayFeature extends AbstractBpmnAddFeature { public DefaultAddGatewayFeature(IFeatureProvider fp) { super(fp); } @Override public boolean canAdd(IAddContext context) { boolean intoDiagram = context.getTargetContainer().equals(getDiagram()); boolean intoLane = FeatureSupport.isTargetLane(context) && FeatureSupport.isTargetLaneOnTop(context); boolean intoParticipant = FeatureSupport.isTargetParticipant(context); boolean intoFlowELementContainer = BusinessObjectUtil.containsElementOfType(context.getTargetContainer(), FlowElementsContainer.class); return intoDiagram || intoLane || intoParticipant || intoFlowELementContainer; } @Override public PictogramElement add(IAddContext context) { Gateway addedGateway = (Gateway) context.getNewObject(); IGaService gaService = Graphiti.getGaService(); IPeService peService = Graphiti.getPeService(); int d = 2 * GraphicsUtil.GATEWAY_RADIUS; int p = GraphicsUtil.GATEWAY_TEXT_AREA; ContainerShape containerShape = peService.createContainerShape(context.getTargetContainer(), true); Rectangle rect = gaService.createInvisibleRectangle(containerShape); gaService.setLocationAndSize(rect, context.getX(), context.getY(), d, d + p); Shape gatewayShape = peService.createShape(containerShape, false); Polygon gateway = GraphicsUtil.createGateway(gatewayShape); StyleUtil.applyBGStyle(gateway, this); gaService.setLocationAndSize(gateway, 0, 0, d, d); decorateGateway(containerShape); Shape textShape = peService.createShape(containerShape, false); peService.setPropertyValue(textShape, UpdateBaseElementNameFeature.TEXT_ELEMENT, Boolean.toString(true)); Text text = gaService.createDefaultText(getDiagram(), textShape, addedGateway.getName()); text.setStyle(StyleUtil.getStyleForText(getDiagram())); text.setHorizontalAlignment(Orientation.ALIGNMENT_CENTER); text.setVerticalAlignment(Orientation.ALIGNMENT_TOP); gaService.setLocationAndSize(text, 0, d, d, p); createDIShape(containerShape, addedGateway); peService.createChopboxAnchor(containerShape); AnchorUtil.addFixedPointAnchors(containerShape, gateway); layoutPictogramElement(containerShape); return containerShape; } protected void decorateGateway(ContainerShape container) { } }