/******************************************************************************* | |
* <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.custom; | |
import org.eclipse.fmc.blockdiagram.editor.algorithm.element.FMCElementAlgorithm; | |
import org.eclipse.fmc.blockdiagram.editor.algorithm.element.FMCElementAlgorithmFactory; | |
import org.eclipse.fmc.blockdiagram.editor.algorithm.node.RotatableNode; | |
import org.eclipse.fmc.blockdiagram.editor.diagram.BlockDiagramImageProvider; | |
import org.eclipse.graphiti.features.IFeatureProvider; | |
import org.eclipse.graphiti.features.context.ICustomContext; | |
import org.eclipse.graphiti.mm.algorithms.GraphicsAlgorithm; | |
import org.eclipse.graphiti.mm.pictograms.ContainerShape; | |
import org.eclipse.graphiti.mm.pictograms.PictogramElement; | |
/** | |
* Flips the selected element horizontally. | |
* | |
* @author Heiko Witteborg | |
* | |
*/ | |
public class FlipHorizontallyCustomFeature extends FMCCustomFeature { | |
/** | |
* Default constructor. | |
* | |
* @param featureProvider | |
* The feature provider. | |
*/ | |
public FlipHorizontallyCustomFeature(IFeatureProvider featureProvider) { | |
super(featureProvider, "Transform"); | |
} | |
/* | |
* (non-Javadoc) | |
* | |
* @see org.eclipse.graphiti.features.impl.AbstractFeature#getName() | |
*/ | |
@Override | |
public String getName() { | |
return "Flip horizontally"; | |
} | |
/* | |
* (non-Javadoc) | |
* | |
* @see | |
* org.eclipse.graphiti.features.custom.AbstractCustomFeature#getImageId() | |
*/ | |
@Override | |
public String getImageId() { | |
return BlockDiagramImageProvider.ICON_FLIP_HORIZONTALLY | |
+ BlockDiagramImageProvider.SIZE_16; | |
} | |
/* | |
* (non-Javadoc) | |
* | |
* @see | |
* org.eclipse.graphiti.features.custom.AbstractCustomFeature#getDescription | |
* () | |
*/ | |
@Override | |
public String getDescription() { | |
return "Flip element horizontally"; | |
} | |
/* | |
* (non-Javadoc) | |
* | |
* @see | |
* org.eclipse.graphiti.features.custom.AbstractCustomFeature#canExecute | |
* (org.eclipse.graphiti.features.context.ICustomContext) | |
*/ | |
@Override | |
public boolean canExecute(ICustomContext context) { | |
PictogramElement[] pes = context.getPictogramElements(); | |
if (pes != null && pes.length == 1 | |
&& context.getPictogramElements()[0] instanceof ContainerShape) { | |
ContainerShape container = (ContainerShape) context | |
.getPictogramElements()[0]; | |
FMCElementAlgorithm ea = FMCElementAlgorithmFactory.getInstance() | |
.getShape(container); | |
if (ea instanceof RotatableNode) { | |
return true; | |
} | |
} | |
return false; | |
} | |
/* | |
* (non-Javadoc) | |
* | |
* @see | |
* org.eclipse.graphiti.features.custom.ICustomFeature#execute(org.eclipse | |
* .graphiti.features.context.ICustomContext) | |
*/ | |
@Override | |
public void execute(ICustomContext context) { | |
PictogramElement[] pes = context.getPictogramElements(); | |
if (pes != null && pes.length == 1) { | |
ContainerShape container = (ContainerShape) context | |
.getPictogramElements()[0]; | |
FMCElementAlgorithm ea = FMCElementAlgorithmFactory.getInstance() | |
.getShape(container); | |
GraphicsAlgorithm invisibleGa = container.getGraphicsAlgorithm(); | |
if (ea instanceof RotatableNode) { | |
((RotatableNode) ea).flipHorizontally(invisibleGa); | |
} | |
} | |
} | |
} |