blob: 5589b63bcbce2962841a029ed9a694633468db01 [file] [log] [blame]
/*******************************************************************************
* <copyright>
*
* Copyright (c) 2013, 2013 SAP AG.
* 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:
* SAP AG - initial API, implementation and documentation
*
* </copyright>
*
*******************************************************************************/
package org.eclipse.fmc.blockdiagram.editor.meta.features.add;
import org.eclipse.graphiti.features.IFeatureProvider;
import org.eclipse.graphiti.features.IUpdateFeature;
import org.eclipse.graphiti.features.context.IAddContext;
import org.eclipse.graphiti.features.context.impl.UpdateContext;
import org.eclipse.graphiti.mm.pictograms.AnchorContainer;
import org.eclipse.graphiti.mm.pictograms.Connection;
import org.eclipse.graphiti.mm.pictograms.PictogramElement;
import org.eclipse.fmc.blockdiagram.editor.features.add.DotsConnectionAddFeature;
import org.eclipse.fmc.blockdiagram.editor.model.ConnectionStyle;
import org.eclipse.fmc.blockdiagram.editor.util.FMCUtil;
import org.eclipse.fmc.mm.FMCNode;
import org.eclipse.fmc.mm.MultiplicityType;
/**
* Feature Class for adding the graphical representation of a multiplicity of an
* existing FMCNode business object.
*
* @author Patrick Jahnke
*
*/
public class DotsConnectionAddMetaFeature extends DotsConnectionAddFeature {
/**
* Call the constructor of the super class and set the linked property as
* false because this dots connection represent a multipliciy and has only a
* source and no target.
*
* @param fp
* @param style
*/
public DotsConnectionAddMetaFeature(IFeatureProvider fp,
ConnectionStyle style) {
super(fp, style);
this.linked = false;
}
/**
* Draw a dots connection without a target to represent a multiplicity.
*/
@Override
public PictogramElement add(IAddContext context) {
Connection cShape = (Connection) super.add(context);
// Change the Target BO to Source BO.
FMCNode sourceObj = (FMCNode) FMCUtil.getBO(cShape.getStart()
.getParent());
AnchorContainer aContainer = cShape.getEnd().getParent();
// Delete the overridden BO from the Model.
aContainer.getLink().getBusinessObjects().remove(0);
this.link(aContainer, sourceObj);
// Update the Graphic Elements.
UpdateContext uContext = new UpdateContext(aContainer);
IUpdateFeature updateFeature = this.getFeatureProvider()
.getUpdateFeature(uContext);
if (updateFeature.canUpdate(uContext))
updateFeature.execute(uContext);
uContext = new UpdateContext(cShape.getStart().getParent());
updateFeature = this.getFeatureProvider().getUpdateFeature(uContext);
if (updateFeature.canUpdate(uContext))
updateFeature.execute(uContext);
// Set Multiplicity to BO
sourceObj.setMultiplicity(MultiplicityType.MANY);
return cShape;
}
}