blob: c597012b492a6b29d3c214605365a4b0d7f94007 [file] [log] [blame]
/*********************************************************************
* Copyright (c) 2005, 2019 SAP SE
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* Contributors:
* SAP SE - initial API, implementation and documentation
*
* SPDX-License-Identifier: EPL-2.0
**********************************************************************/
package org.eclipse.graphiti.testtool.sketch.features;
import java.util.List;
import org.eclipse.graphiti.features.IFeatureProvider;
import org.eclipse.graphiti.features.context.ICustomContext;
import org.eclipse.graphiti.features.custom.AbstractCustomFeature;
import org.eclipse.graphiti.mm.pictograms.ContainerShape;
import org.eclipse.graphiti.mm.pictograms.PictogramElement;
import org.eclipse.graphiti.mm.pictograms.Shape;
import org.eclipse.graphiti.services.Graphiti;
/**
* The Class BackgroundColorFeature.
*/
public class SendToFrontFeature extends AbstractCustomFeature {
private static final String NAME = "Send to front";
private static final String DESCRIPTION = "Send to the front";
/**
* The Constructor.
*
* @param fp
* the fp
*/
public SendToFrontFeature(IFeatureProvider fp) {
super(fp);
}
@Override
public String getDescription() {
return DESCRIPTION;
}
@Override
public String getName() {
return NAME;
}
@Override
public boolean canExecute(ICustomContext context) {
boolean ret = false;
PictogramElement[] pes = context.getPictogramElements();
if (pes != null && pes.length == 1) {
PictogramElement pe = pes[0];
if (pe instanceof Shape) {
Shape shape = (Shape) pe;
ContainerShape containerShape = shape.getContainer();
if (containerShape != null) {
List<Shape> childList = containerShape.getChildren();
int size = childList.size();
int index = childList.indexOf(shape);
if (size > 1 && index < size - 1) {
return true;
}
}
}
}
return ret;
}
public void execute(ICustomContext context) {
PictogramElement[] pes = context.getPictogramElements();
if (pes != null && pes.length == 1) {
PictogramElement pe = pes[0];
if (pe instanceof Shape) {
Shape shape = (Shape) pe;
ContainerShape containerShape = shape.getContainer();
List<Shape> childList = containerShape.getChildren();
int size = childList.size();
int index = childList.indexOf(shape);
if (size > 1 && index < size) {
Graphiti.getPeService().sendToFront(shape);
}
}
}
}
}