/******************************************************************************* | |
* <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.algorithm.comment.BraceAlgorithm; | |
import org.eclipse.fmc.blockdiagram.editor.algorithm.comment.CommentAlgorithmFactory; | |
import org.eclipse.fmc.blockdiagram.editor.util.StyleUtil; | |
import org.eclipse.graphiti.features.IFeatureProvider; | |
import org.eclipse.graphiti.features.context.IAddContext; | |
import org.eclipse.graphiti.mm.algorithms.GraphicsAlgorithm; | |
import org.eclipse.graphiti.mm.algorithms.Rectangle; | |
import org.eclipse.graphiti.mm.pictograms.ContainerShape; | |
import org.eclipse.graphiti.mm.pictograms.PictogramElement; | |
/** | |
* This feature adds the graphical representation of a brace shape to the | |
* diagram. | |
* | |
* @author Rainer Thome | |
* @author Benjamin Schmeling | |
* @author Heiko Witteborg | |
* | |
*/ | |
public class BraceAddFeature extends ShapeAddFeature { | |
/** | |
* Brace algorithm to create the graphical representation. | |
*/ | |
private BraceAlgorithm braceAlgorithm = CommentAlgorithmFactory.getInstance() | |
.getBrace(); | |
/** | |
* | |
* @param featureProvider | |
* The feature provider. | |
*/ | |
public BraceAddFeature(IFeatureProvider featureProvider) { | |
super(featureProvider); | |
super.minimumWidth = braceAlgorithm.getMinimumWidth(); | |
super.minimumHeight = braceAlgorithm.getMinimumHeight(); | |
} | |
/** | |
* | |
* @param featureProvider | |
* The feature provider. | |
* @param linked | |
* True if the pictogram element should be linked to a model | |
* object. | |
*/ | |
public BraceAddFeature(IFeatureProvider featureProvider, boolean linked) { | |
super(featureProvider); | |
super.minimumWidth = braceAlgorithm.getMinimumWidth(); | |
super.minimumHeight = braceAlgorithm.getMinimumHeight(); | |
super.linked = linked; | |
} | |
/* | |
* (non-Javadoc) | |
* | |
* @see | |
* org.eclipse.fmc.blockdiagram.editor.features.add.ShapeAddFeature#canAdd | |
* (org.eclipse.graphiti.features.context.IAddContext) | |
*/ | |
@Override | |
public boolean canAdd(IAddContext context) { | |
return true; | |
} | |
/* | |
* (non-Javadoc) | |
* | |
* @see | |
* org.eclipse.graphiti.func.IAdd#add(org.eclipse.graphiti.features.context | |
* .IAddContext) | |
*/ | |
@Override | |
public PictogramElement add(IAddContext context) { | |
ContainerShape container = context.getTargetContainer(); | |
ContainerShape newContainer = pe.createContainerShape(container, true); | |
Rectangle invRec = ga.createInvisibleRectangle(newContainer); | |
invRec.setStyle(StyleUtil.getStyle(getDiagram(), StyleUtil.SHAPE)); | |
if (linked) | |
link(newContainer, context.getNewObject()); | |
BraceAlgorithm algorithm = CommentAlgorithmFactory.getInstance() | |
.getBrace(); | |
GraphicsAlgorithm secondLevelGa = algorithm.createGraphics( | |
getDiagram(), invRec, context.getX(), context.getY(), | |
getWidth(context), getHeight(context)); | |
secondLevelGa.setParentGraphicsAlgorithm(invRec); | |
return newContainer; | |
} | |
} |