/******************************************************************************* | |
* <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.graphiti.features.IFeatureProvider; | |
import org.eclipse.graphiti.features.impl.AbstractAddFeature; | |
import org.eclipse.graphiti.mm.algorithms.Polygon; | |
import org.eclipse.graphiti.mm.pictograms.Connection; | |
import org.eclipse.graphiti.mm.pictograms.ConnectionDecorator; | |
import org.eclipse.graphiti.mm.pictograms.Diagram; | |
import org.eclipse.graphiti.services.Graphiti; | |
import org.eclipse.graphiti.services.IPeService; | |
/** | |
* This is the super class of all add features for connections. It provides | |
* functionality to support the different connection styles | |
* {@link ConnectionStyle#NORMAL} and {@link ConnectionStyle#MANHATTAN}. | |
* | |
* @author Benjamin Schmeling | |
* | |
*/ | |
public abstract class ConnectionAddFeature extends AbstractAddFeature { | |
/** | |
* The connection style. | |
*/ | |
protected ConnectionStyle style; | |
/** | |
* Main constructor. | |
* | |
* @param featureProvider The feature provider. | |
* @param type The style of the connection line. | |
*/ | |
public ConnectionAddFeature(IFeatureProvider featureProvider, ConnectionStyle type) { | |
super(featureProvider); | |
this.style = type; | |
} | |
/** | |
* Creates a new Freeform or Manhattan Connection by using the PeService. | |
* | |
* @return Connection with the style set by the {@linkplain #style} | |
* attribute. | |
*/ | |
protected Connection createConnection() { | |
IPeService pe = Graphiti.getPeService(); | |
switch (this.style) { | |
case NORMAL: | |
return pe.createFreeFormConnection(getDiagram()); | |
case MANHATTAN: | |
return pe.createManhattanConnection(getDiagram()); | |
case COMPOSITE: | |
return pe.createCompositeConnection(getDiagram()); | |
default: | |
return pe.createManhattanConnection(getDiagram()); | |
} | |
} | |
/** | |
* Creates the arrow decorator for the line. | |
* | |
* @param diagram | |
* The diagram the connection belongs to. | |
* @param con | |
* The connection the decorator should be created for. | |
* @param defaultDirection | |
* True if default direction should be used (from source to | |
* target), false otherwise. | |
*/ | |
public static void createArrowDecorator(Diagram diagram, Connection con, | |
boolean defaultDirection) { | |
ConnectionDecorator deco = Graphiti.getPeService() | |
.createConnectionDecorator(con, false, | |
defaultDirection ? 1.0 : 0.0, true); | |
Polygon poly = Graphiti.getGaService().createPolygon(deco, | |
new int[] { -15, 6, 0, 0, -15, -6, -12, 0 }); | |
poly.setBackground(Graphiti.getGaService() | |
.manageColor(diagram, 0, 0, 0)); | |
} | |
} |