blob: b38945d537acfeac8521a5c8a5da6acecc2b8d59 [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.meta;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.core.runtime.Platform;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.fmc.blockdiagram.editor.meta.features.ReconnectionMetaFeature;
import org.eclipse.fmc.blockdiagram.editor.meta.features.ShapePasteMetaFeature;
import org.eclipse.fmc.blockdiagram.editor.meta.features.FMCNodeDeleteFeature;
import org.eclipse.fmc.blockdiagram.editor.meta.features.TextDirectEditingMetaFeature;
import org.eclipse.fmc.blockdiagram.editor.meta.features.add.DotsConnectionAddMetaFeature;
import org.eclipse.fmc.blockdiagram.editor.meta.features.create.CommunicationChannelCreateFeature;
import org.eclipse.fmc.blockdiagram.editor.meta.features.create.ConnectionCreateMetaFeature;
import org.eclipse.fmc.blockdiagram.editor.meta.features.create.DotsCreateFeature;
import org.eclipse.fmc.blockdiagram.editor.meta.features.create.HumanAgentCreateMetaFeature;
import org.eclipse.fmc.blockdiagram.editor.meta.features.create.ShapeCreateMetaFeature;
import org.eclipse.fmc.blockdiagram.editor.meta.features.update.AccessUpdateFeature;
import org.eclipse.fmc.blockdiagram.editor.meta.features.update.AgentUpdateFeature;
import org.eclipse.fmc.blockdiagram.editor.meta.features.update.CommentUpdateMetaFeature;
import org.eclipse.fmc.blockdiagram.editor.meta.features.update.CommunicationChannelUpdateFeature;
import org.eclipse.fmc.blockdiagram.editor.meta.features.update.StorageUpdateMetaFeature;
import org.eclipse.fmc.blockdiagram.editor.meta.features.update.FMCNodeUpdateFeature;
import org.eclipse.fmc.blockdiagram.editor.meta.profile.IStereotypeProvider;
import org.eclipse.graphiti.dt.IDiagramTypeProvider;
import org.eclipse.graphiti.features.IAddFeature;
import org.eclipse.graphiti.features.ICreateConnectionFeature;
import org.eclipse.graphiti.features.ICreateFeature;
import org.eclipse.graphiti.features.IDeleteFeature;
import org.eclipse.graphiti.features.IDirectEditingFeature;
import org.eclipse.graphiti.features.IPasteFeature;
import org.eclipse.graphiti.features.IReconnectionFeature;
import org.eclipse.graphiti.features.IUpdateFeature;
import org.eclipse.graphiti.features.context.IAddContext;
import org.eclipse.graphiti.features.context.IDeleteContext;
import org.eclipse.graphiti.features.context.IDirectEditingContext;
import org.eclipse.graphiti.features.context.IPasteContext;
import org.eclipse.graphiti.features.context.IReconnectionContext;
import org.eclipse.graphiti.features.context.IUpdateContext;
import org.eclipse.graphiti.mm.algorithms.MultiText;
import org.eclipse.graphiti.mm.algorithms.Text;
import org.eclipse.graphiti.mm.pictograms.Connection;
import org.eclipse.graphiti.mm.pictograms.ContainerShape;
import org.eclipse.graphiti.ui.editor.DiagramBehavior;
import org.eclipse.graphiti.ui.features.DefaultDeleteFeature;
import org.eclipse.fmc.blockdiagram.editor.BlockDiagramConstants;
import org.eclipse.fmc.blockdiagram.editor.diagram.BlockDiagramFeatureProvider;
import org.eclipse.fmc.blockdiagram.editor.diagram.BlockDiagramImageProvider;
import org.eclipse.fmc.blockdiagram.editor.features.add.AnchorAddFeature;
import org.eclipse.fmc.blockdiagram.editor.features.add.InvisibleShapeAddFeature;
import org.eclipse.fmc.blockdiagram.editor.features.create.ConnectionCreateFeature;
import org.eclipse.fmc.blockdiagram.editor.features.create.ShapeCreateFeature;
import org.eclipse.fmc.blockdiagram.editor.model.ConnectionStyle;
import org.eclipse.fmc.blockdiagram.editor.model.ShapeStyle;
import org.eclipse.fmc.blockdiagram.editor.model.FMCType;
import org.eclipse.fmc.blockdiagram.editor.util.FMCUtil;
import org.eclipse.fmc.mm.AccessType;
import org.eclipse.fmc.mm.CommentType;
import org.eclipse.fmc.mm.DataflowDirection;
import org.eclipse.fmc.mm.FMCElement;
import org.eclipse.fmc.mm.FMCNode;
import org.eclipse.fmc.mm.FmcPackage;
import org.eclipse.fmc.mm.RequestDirection;
/**
* Feature provider class.
*
* @author Patrick Jahnke
*
*/
public class BlockDiagramMetaFeatureProvider extends BlockDiagramFeatureProvider {
/**
* The stereotype provider (is not null only if the Stereotype Extension is
* installed).
*/
private IStereotypeProvider stereoTypeProvider;
/**
* Constructor calls the super constructor and try to load the Stereotype
* Extension.
*
* @param diagramTypeProvider
* The diagram provider.
*/
public BlockDiagramMetaFeatureProvider(IDiagramTypeProvider diagramTypeProvider) {
super(diagramTypeProvider);
setIndependenceSolver(null);
IExtensionRegistry reg = Platform.getExtensionRegistry();
IConfigurationElement[] extensions = reg
.getConfigurationElementsFor("org.eclipse.fmc.blockdiagram.editor.meta.profile");
if (extensions.length == 1) {
try {
stereoTypeProvider = (IStereotypeProvider) extensions[0]
.createExecutableExtension("stereotypeProvider");
} catch (CoreException e) {
e.printStackTrace();
}
}
}
/**
* Returns the right UpdateFeature object for the given context.
*/
@Override
public IUpdateFeature getUpdateFeature(IUpdateContext context) {
if (context.getPictogramElement() instanceof ContainerShape) {
if (typeChecker.isAgent(context.getPictogramElement()))
return new AgentUpdateFeature(this, stereoTypeProvider);
else if (typeChecker.isStorage(context.getPictogramElement()))
return new StorageUpdateMetaFeature(this, stereoTypeProvider);
else if (typeChecker.isAreaBorder(context.getPictogramElement()))
return new CommentUpdateMetaFeature(this);
else
return new FMCNodeUpdateFeature(this, stereoTypeProvider);
}
if (context.getPictogramElement() instanceof Connection) {
if (typeChecker.isCommunicationChannel((Connection) context
.getPictogramElement())) {
return new CommunicationChannelUpdateFeature(this,
stereoTypeProvider);
} else
return new AccessUpdateFeature(this, stereoTypeProvider);
} else
return super.getUpdateFeature(context);
}
/**
* Returns the right DeleteFeature object for the given context.
*/
@Override
public IDeleteFeature getDeleteFeature(IDeleteContext context) {
if (context != null
&& FMCUtil.getBO(context.getPictogramElement()) instanceof FMCNode)
return new FMCNodeDeleteFeature(this);
else
return new DefaultDeleteFeature(this);
}
/**
* Returns the right CreateFeature object for the given context.
*/
@Override
public ICreateFeature[] getCreateFeatures() {
return new ICreateFeature[] {
new ShapeCreateMetaFeature(this, "Agent", "Agent",
FmcPackage.Literals.AGENT, BlockDiagramImageProvider.ICON_AGENT),
new ShapeCreateMetaFeature(this, "Agent L", "Agent L",
FmcPackage.Literals.AGENT, ShapeStyle.L,
BlockDiagramImageProvider.ICON_AGENT_L),
new ShapeCreateMetaFeature(this, "Agent U", "Agent U",
FmcPackage.Literals.AGENT, ShapeStyle.U,
BlockDiagramImageProvider.ICON_AGENT_U),
new ShapeCreateMetaFeature(this, "Storage", "Storage",
FmcPackage.Literals.STORAGE,
BlockDiagramImageProvider.ICON_STORAGE),
new ShapeCreateMetaFeature(this, "Storage_L", "Storage_L",
FmcPackage.Literals.STORAGE, ShapeStyle.L,
BlockDiagramImageProvider.ICON_STORAGE_L),
new ShapeCreateMetaFeature(this, "Storage_U", "Storage_U",
FmcPackage.Literals.STORAGE, ShapeStyle.U,
BlockDiagramImageProvider.ICON_STORAGE_U),
new HumanAgentCreateMetaFeature(this, "HumanAgent",
"HumanAgent", FmcPackage.Literals.AGENT,
BlockDiagramImageProvider.ICON_HUMAN_AGENT),
new ShapeCreateMetaFeature(this, "StructureVariance",
"StructureVariance",
FmcPackage.Literals.STRUCTURE_VARIANCE,
BlockDiagramImageProvider.ICON_STRUCTURE_VARIANCE),
new ShapeCreateMetaFeature(this, "Text",
CommentType.TEXT.toString(),
FmcPackage.Literals.COMMENT, BlockDiagramImageProvider.ICON_TEXT),
new ShapeCreateMetaFeature(this, "Common Feature Area",
CommentType.COMMONFEATUREAREA.toString(),
FmcPackage.Literals.COMMENT,
BlockDiagramImageProvider.ICON_COMMON_FEATURE_AREA),
new ShapeCreateMetaFeature(this, "Brace",
CommentType.BRACE.toString(),
FmcPackage.Literals.COMMENT,
BlockDiagramImageProvider.ICON_BRACE),
new ShapeCreateMetaFeature(this, "AreaBorder",
CommentType.AREABORDER.toString(),
FmcPackage.Literals.COMMENT,
BlockDiagramImageProvider.ICON_AREABORDER),
new ShapeCreateMetaFeature(this, "Dots",
CommentType.DOTS.toString(),
FmcPackage.Literals.COMMENT, BlockDiagramImageProvider.ICON_DOTS),
new ShapeCreateFeature(this, "Anchor", "", FMCType.Anchor,
BlockDiagramImageProvider.ICON_ANCHOR) };
}
/**
* Returns the right DirectEditingFeature object for the given context.
*/
@Override
public IDirectEditingFeature getDirectEditingFeature(
IDirectEditingContext context) {
if (context.getGraphicsAlgorithm() instanceof Text
|| context.getGraphicsAlgorithm() instanceof MultiText)
return new TextDirectEditingMetaFeature(this, stereoTypeProvider);
else {
return super.getDirectEditingFeature(context);
}
}
/**
* Returns the right AddFeature object for the given context.
*/
@Override
public IAddFeature getAddFeature(IAddContext context) {
if (context.getNewObject() == FMCType.Invisible) {
return new InvisibleShapeAddFeature(this);
} else if (context.getNewObject() == FMCType.Dots) {
return new DotsConnectionAddMetaFeature(
this,
(ConnectionStyle) context
.getProperty(BlockDiagramConstants.GRAPHICAL_TYPE_KEY));
} else if (context.getNewObject() == FMCType.Anchor) {
return new AnchorAddFeature(this);
} else {
AddFeatureVisitor visitor = new AddFeatureVisitor(this);
return (IAddFeature) visitor.visit(
(FMCElement) context.getNewObject(), context);
}
}
/**
* Returns the right PasteFeature object for the given context.
*/
@Override
public IPasteFeature getPasteFeature(IPasteContext context) {
DiagramBehavior diagramBehavior = (DiagramBehavior) this
.getDiagramTypeProvider().getDiagramBehavior();
Point mouseLoc = diagramBehavior.getMouseLocation();
context.putProperty("mouseX", mouseLoc.x());
context.putProperty("mouseY", mouseLoc.y());
return new ShapePasteMetaFeature(this);
}
/**
* Returns the right CreateConnectionFeature object for the given context.
*/
@Override
public ICreateConnectionFeature[] getCreateConnectionFeatures() {
return new ICreateConnectionFeature[] {
new ConnectionCreateMetaFeature(this, "Modify Access", "",
FmcPackage.Literals.ACCESS, ConnectionStyle.COMPOSITE,
BlockDiagramImageProvider.ICON_MODIFY_ACCESS, AccessType.RW),
new ConnectionCreateMetaFeature(this, "Unidirectional Access",
"", FmcPackage.Literals.ACCESS,
ConnectionStyle.MANHATTAN,
BlockDiagramImageProvider.ICON_UNIDIRECTIONAL_ACCESS_MH),
new ConnectionCreateMetaFeature(this, "Unidirectional Access",
"", FmcPackage.Literals.ACCESS, ConnectionStyle.NORMAL,
BlockDiagramImageProvider.ICON_UNIDIRECTIONAL_ACCESS),
new ConnectionCreateMetaFeature(this, "Bidirectional Access",
"", FmcPackage.Literals.ACCESS,
ConnectionStyle.MANHATTAN,
BlockDiagramImageProvider.ICON_BIDIRECTIONAL_ACCESS_MH,
AccessType.UNSPECIFIED),
new ConnectionCreateMetaFeature(this, "Bidirectional Access",
"", FmcPackage.Literals.ACCESS, ConnectionStyle.NORMAL,
BlockDiagramImageProvider.ICON_BIDIRECTIONAL_ACCESS,
AccessType.UNSPECIFIED),
new CommunicationChannelCreateFeature(this,
"Unidirectional Communication Channel", "",
FmcPackage.Literals.CHANNEL, ConnectionStyle.MANHATTAN,
BlockDiagramImageProvider.ICON_UNIDIRECTIONAL_COMM_CHANNEL_MH,
DataflowDirection.DEFAULT, RequestDirection.UNSPECIFIED),
new CommunicationChannelCreateFeature(this,
"Unidirectional Communication Channel", "",
FmcPackage.Literals.CHANNEL, ConnectionStyle.NORMAL,
BlockDiagramImageProvider.ICON_UNIDIRECTIONAL_COMM_CHANNEL,
DataflowDirection.DEFAULT, RequestDirection.UNSPECIFIED),
new CommunicationChannelCreateFeature(this,
"Bidirectional Communication Channel", "",
FmcPackage.Literals.CHANNEL, ConnectionStyle.MANHATTAN,
BlockDiagramImageProvider.ICON_BIDIRECTIONAL_COMM_CHANNEL_MH,
DataflowDirection.UNSPECIFIED,
RequestDirection.UNSPECIFIED),
new CommunicationChannelCreateFeature(this,
"Bidirectional Communication Channel", "",
FmcPackage.Literals.CHANNEL, ConnectionStyle.NORMAL,
BlockDiagramImageProvider.ICON_BIDIRECTIONAL_COMM_CHANNEL,
DataflowDirection.UNSPECIFIED,
RequestDirection.UNSPECIFIED),
new CommunicationChannelCreateFeature(this,
"Request-Response Communication Channel", "",
FmcPackage.Literals.CHANNEL, ConnectionStyle.MANHATTAN,
BlockDiagramImageProvider.ICON_REQ_RESP_COMM_CHANNEL_MH,
DataflowDirection.UNSPECIFIED, RequestDirection.REQUEST),
new CommunicationChannelCreateFeature(this,
"Request-Response Communication Channel", "",
FmcPackage.Literals.CHANNEL, ConnectionStyle.NORMAL,
BlockDiagramImageProvider.ICON_REQ_RESP_COMM_CHANNEL,
DataflowDirection.DEFAULT, RequestDirection.REQUEST),
// new ConnectionCreateMetaFeature(this, "Dots Meta",
// "", FmcPackage.Literals.COMMENT, ConnectionStyle.NORMAL,
// BlockDiagramImageProvider.ICON_DOTS),
new DotsCreateFeature(this, "Dots", "", FMCType.Dots,
ConnectionStyle.NORMAL, BlockDiagramImageProvider.ICON_DOTS),
new ConnectionCreateFeature(this, "Dots", "", FMCType.Dots,
ConnectionStyle.MANHATTAN,
BlockDiagramImageProvider.ICON_DOTS_MH) };
}
/**
* Returns the right ReconnectionFeature object for the given context.
*/
@Override
public IReconnectionFeature getReconnectionFeature(
IReconnectionContext context) {
return new ReconnectionMetaFeature(this);
}
}