blob: cdbbc5079a3989d74f8376b96120747dcdb2772d [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.features.add;
import org.eclipse.fmc.blockdiagram.editor.model.ConnectionStyle;
import org.eclipse.fmc.blockdiagram.editor.model.FMCType;
import org.eclipse.graphiti.features.IFeatureProvider;
import org.eclipse.graphiti.features.context.IAddConnectionContext;
import org.eclipse.graphiti.features.context.IAddContext;
import org.eclipse.graphiti.mm.algorithms.Polyline;
import org.eclipse.graphiti.mm.pictograms.CompositeConnection;
import org.eclipse.graphiti.mm.pictograms.Connection;
import org.eclipse.graphiti.mm.pictograms.CurvedConnection;
import org.eclipse.graphiti.mm.pictograms.PictogramElement;
import org.eclipse.graphiti.services.Graphiti;
import org.eclipse.graphiti.services.IGaService;
import org.eclipse.graphiti.services.IPeService;
/**
* Feature responsible for adding the graphical representation of access
* connections.
*
* @author Benjamin Schmeling
*
*/
public class AccessAddFeature extends ConnectionAddFeature {
/**
*
* @param fp
* The feature provider.
* @param style
* The style of the connection: normal or manhattan are
* supported.
*/
public AccessAddFeature(IFeatureProvider fp, ConnectionStyle style) {
super(fp, style);
}
@Override
/*
* (non-Javadoc)
*
* @see
* org.eclipse.graphiti.func.IAdd#canAdd(org.eclipse.graphiti.features.context
* .IAddContext)
*/
public boolean canAdd(IAddContext context) {
return true;
}
@Override
/*
* (non-Javadoc)
*
* @see
* org.eclipse.graphiti.func.IAdd#add(org.eclipse.graphiti.features.context
* .IAddContext)
*/
public PictogramElement add(IAddContext context) {
IGaService ga = Graphiti.getGaService();
IPeService pe = Graphiti.getPeService();
IAddConnectionContext cContext = (IAddConnectionContext) context;
Connection con = super.createConnection();
Polyline line = ga.createPolyline(con);
con.setStart(cContext.getSourceAnchor());
con.setEnd(cContext.getTargetAnchor());
line.setForeground(manageColor(0, 0, 0));
if (context.getNewObject() == FMCType.UnidirectionalAccess) {
createArrowDecorator(getDiagram(), con, true);
} else if (context.getNewObject() == FMCType.ModifyAccess) {
CompositeConnection compCon = (CompositeConnection) con;
CurvedConnection curved1 = pe.createCurvedConnection(new double[] {
0.50d, 50d }, getDiagram());
CurvedConnection curved2 = pe.createCurvedConnection(new double[] {
0.50d, -50d }, getDiagram());
compCon.getChildren().add(curved1);
compCon.getChildren().add(curved2);
ga.createPolyline(curved1);
ga.createPolyline(curved2);
createArrowDecorator(getDiagram(), curved1, true);
createArrowDecorator(getDiagram(), curved2, false);
line.setLineVisible(false);
} else
addDomainModelContent(context, con, line);
link(con, (context.getNewObject()));
return con;
}
/**
* This method should be overridden if alternative meta models are used.
* This method's intention is to change the graphical representation of the
* connection according to the new object stored in the context. For the
* simple enumeration based meta model nothing is done.
*
* @param context
* The add context.
* @param con
* The connection to add the domain model element to.
* @param line
* The polyline representing the connection.
*/
protected void addDomainModelContent(IAddContext context, Connection con,
Polyline line) {
// Do nothing because the simple meta model provides only a type but
// without any further properties
}
}