blob: 1cb8052ab5fb949240e8225bc3266e2bd3a04194 [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.algorithm.node.LStorageAlgorithm;
import org.eclipse.fmc.blockdiagram.editor.algorithm.node.RectangleStorageAlgorithm;
import org.eclipse.fmc.blockdiagram.editor.algorithm.node.StorageAlgorithm;
import org.eclipse.fmc.blockdiagram.editor.algorithm.node.FMCNodeAlgorithmFactory;
import org.eclipse.fmc.blockdiagram.editor.algorithm.node.UStorageAlgorithm;
import org.eclipse.fmc.blockdiagram.editor.model.ShapeStyle;
import org.eclipse.graphiti.features.IFeatureProvider;
import org.eclipse.graphiti.features.context.IAddContext;
import org.eclipse.graphiti.mm.GraphicsAlgorithmContainer;
import org.eclipse.graphiti.mm.algorithms.GraphicsAlgorithm;
/**
* This feature is responsible for adding storage shapes to the diagram.
*
* @author Benjamin Schmeling
*
*/
public class StorageAddFeature extends FMCNodeAddFeature {
/**
* Minimum width of the shape.
*/
private static int MIN_WIDTH = 70;
/**
* Minimum height of the shape.
*/
private static int MIN_HEIGHT = 30;
/**
* Default constructor.
*
* @param featureProvider
* The feature provider.
*/
public StorageAddFeature(IFeatureProvider featureProvider) {
super(featureProvider);
minimumWidth = MIN_WIDTH;
minimumHeight = MIN_HEIGHT;
}
/**
* Constructor for setting the style of the shape.
*
* @param featureProvider
* The feature provider.
* @param style
* The style of the shape.
*/
public StorageAddFeature(IFeatureProvider featureProvider, ShapeStyle style) {
super(featureProvider, style);
setDefaultSize(style);
}
/**
* Sets the default size depending on the style.
*
* @param style
* The style of the shape.
*/
private void setDefaultSize(ShapeStyle style) {
if (style != null) {
switch (style) {
case RECT:
minimumWidth = RectangleStorageAlgorithm.STORAGE_DEFAULT_WIDTH;
minimumHeight = RectangleStorageAlgorithm.STORAGE_DEFAULT_HEIGHT;
break;
case L:
minimumWidth = LStorageAlgorithm.LSTORAGE_DEFAULT_WIDTH;
minimumHeight = LStorageAlgorithm.LSTORAGE_DEFAULT_HEIGHT;
break;
case U:
minimumWidth = UStorageAlgorithm.USTORAGE_DEFAULT_WIDTH;
minimumHeight = UStorageAlgorithm.USTORAGE_DEFAULT_HEIGHT;
break;
default:
assert false : "No style literal matched in switch";
break;
}
} else {
minimumWidth = MIN_WIDTH;
minimumHeight = MIN_HEIGHT;
}
}
/*
* (non-Javadoc)
*
* @see
* org.eclipse.fmc.blockdiagram.editor.features.add.FMCNodeAddFeature#createGraphics
* (org.eclipse.graphiti.mm.GraphicsAlgorithmContainer,
* org.eclipse.graphiti.features.context.IAddContext)
*/
@Override
protected GraphicsAlgorithm createGraphics(
GraphicsAlgorithmContainer gaContainer, IAddContext context) {
StorageAlgorithm algorithm = FMCNodeAlgorithmFactory.getInstance()
.getStorageByShapestyle(this.shapeType);
return algorithm.createGraphics(getDiagram(), gaContainer, 0, 0,
getWidth(context), getHeight(context));
}
}