blob: 0394c34af9e69aed7e7fdb5ee7e3ee36b26835c7 [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.ecore.features.pack;
import java.util.Collection;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.graphiti.features.IFeatureProvider;
import org.eclipse.graphiti.features.IReason;
import org.eclipse.graphiti.features.context.IUpdateContext;
import org.eclipse.graphiti.features.impl.AbstractUpdateFeature;
import org.eclipse.graphiti.features.impl.Reason;
import org.eclipse.graphiti.mm.algorithms.Text;
import org.eclipse.graphiti.mm.pictograms.ContainerShape;
import org.eclipse.graphiti.mm.pictograms.PictogramElement;
import org.eclipse.graphiti.mm.pictograms.Shape;
/**
* The Class TestUpdatePackageFeature.
*/
public class TestUpdatePackageFeature extends AbstractUpdateFeature {
/**
* The Constructor.
*
* @param fp
* the fp
*/
public TestUpdatePackageFeature(IFeatureProvider fp) {
super(fp);
}
public boolean canUpdate(IUpdateContext context) {
// return true, if linked business object is a package
Object bo = getBusinessObjectForPictogramElement(context.getPictogramElement());
return (bo instanceof EPackage);
}
public IReason updateNeeded(IUpdateContext context) {
// test
return Reason.createFalseReason();
}
public boolean update(IUpdateContext context) {
String businessName = null;
// Retrieve value from business model
PictogramElement pictogramElement = context.getPictogramElement();
Object bo = getBusinessObjectForPictogramElement(pictogramElement);
if (bo instanceof EPackage) {
EPackage p = (EPackage) bo;
businessName = p.getName();
}
// Set value in pictogram model
if (pictogramElement instanceof ContainerShape) {
ContainerShape cs = (ContainerShape) pictogramElement;
Collection<Shape> children = cs.getChildren();
for (Shape shape : children) {
if (shape.getGraphicsAlgorithm() instanceof Text) {
Text text = (Text) shape.getGraphicsAlgorithm();
text.setValue(businessName);
return true;
}
}
}
return false;
}
}