blob: 7c4ab730dc7fc3d0806ea8c7e95335309b987973 [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.create;
import org.eclipse.fmc.blockdiagram.editor.BlockDiagramConstants;
import org.eclipse.fmc.blockdiagram.editor.model.ShapeStyle;
import org.eclipse.graphiti.features.IFeatureProvider;
import org.eclipse.graphiti.features.context.IAreaContext;
import org.eclipse.graphiti.features.context.IContext;
import org.eclipse.graphiti.features.context.ICreateContext;
import org.eclipse.graphiti.features.context.impl.AddContext;
import org.eclipse.graphiti.features.impl.AbstractCreateFeature;
import org.eclipse.graphiti.mm.pictograms.PictogramElement;
/**
* Create feature for shapes. The class can be used for all types of
* shapes.
*
* @author Benjamin Schmeling
*
*/
public class ShapeCreateFeature extends AbstractCreateFeature {
/**
* The model object to be used for the shape.
*/
protected final Object modelType;
/**
* The shape style.
*/
private final ShapeStyle shapeStyle;
/**
* The id of the icon for the create image.
*/
private String icon = null;
/**
* Getter for modelType property.
*
* @return The model type to be used for the shape.
*/
public Object getModelType() {
return this.modelType;
}
/**
* Default constructor.
*
* @param featureProvider
* The feature provider.
* @param name
* name of the tool palette entry label.
* @param description
* The description of the tool palette entry label.
* @param modelType
* The model type to be created.
* @param icon
*/
public ShapeCreateFeature(IFeatureProvider featureProvider, String name,
String description, Object modelType, String icon) {
super(featureProvider, name, description);
this.modelType = modelType;
this.shapeStyle = null;
this.icon = icon;
}
/**
* Constructor for setting the shape style.
*
* @param featureProvider
* The feature provider.
* @param name
* The name of the tool palette entry label.
* @param description
* The description of the tool palette entry label.
* @param modelType
* The model type to be created.
* @param style
* The shape style.
* @param icon
* The icon id for the tool palette entry.
*/
public ShapeCreateFeature(IFeatureProvider fp, String name,
String description, Object modelType, ShapeStyle style,
String icon) {
super(fp, name, description);
this.modelType = modelType;
this.shapeStyle = style;
this.icon = icon;
}
/*
* (non-Javadoc)
*
* @see
* org.eclipse.graphiti.func.ICreate#canCreate(org.eclipse.graphiti.features
* .context.ICreateContext)
*/
@Override
public boolean canCreate(ICreateContext context) {
return true;
}
/*
* (non-Javadoc)
*
* @see
* org.eclipse.graphiti.features.impl.AbstractCreateFeature#execute(org.
* eclipse.graphiti.features.context.IContext)
*/
@Override
public void execute(IContext context) {
// TODO Auto-generated method stub
super.execute(context);
}
/*
* (non-Javadoc)
*
* @see
* org.eclipse.graphiti.func.ICreate#create(org.eclipse.graphiti.features
* .context.ICreateContext)
*/
@Override
public Object[] create(ICreateContext context) {
addGraphicalRepresentation(context, modelType);
return new Object[] { modelType };
}
/*
* (non-Javadoc)
*
* @see
* org.eclipse.graphiti.features.impl.AbstractFeature#addGraphicalRepresentation
* (org.eclipse.graphiti.features.context.IAreaContext, java.lang.Object)
*/
@Override
protected PictogramElement addGraphicalRepresentation(IAreaContext context,
Object newObject) {
AddContext addContext = new AddContext(context, newObject);
addContext.putProperty(BlockDiagramConstants.GRAPHICAL_TYPE_KEY, this.shapeStyle);
return getFeatureProvider().addIfPossible(addContext);
}
/*
* (non-Javadoc)
*
* @see
* org.eclipse.graphiti.features.impl.AbstractCreateFeature#getCreateImageId
* ()
*/
@Override
public String getCreateImageId() {
return icon;
}
}