blob: 4231cb236c5d1797947f82020a77d29d58753112 [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;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.graphiti.features.IFeatureProvider;
import org.eclipse.graphiti.features.context.IDirectEditingContext;
import org.eclipse.graphiti.mm.algorithms.AbstractText;
import org.eclipse.graphiti.mm.pictograms.ContainerShape;
import org.eclipse.graphiti.mm.pictograms.Shape;
/**
* This is the direct editing feature class for containers. If a container is
* clicked for direct editing the nested text will be found and edited.
*
* @author Benjamin Schmeling
*
*/
public class ContainerTextDirectEditingFeature extends TextDirectEditingFeature {
/**
* Main constructor.
*
* @param featureProvider The feature provider.
*/
public ContainerTextDirectEditingFeature(IFeatureProvider featureProvider) {
super(featureProvider);
}
/**
* Finds the next nested text in a container.
*
* @param container
* The ContainerShape to search in.
* @return The found AbstractText, else null.
*/
private AbstractText findTextInContainer(ContainerShape container) {
for (Shape shape : container.getChildren()) {
if (shape.getGraphicsAlgorithm() instanceof AbstractText)
return (AbstractText) shape.getGraphicsAlgorithm();
}
return null;
}
/*
* (non-Javadoc)
*
* @see
* org.eclipse.fmc.blockdiagram.editor.features.TextDirectEditingFeature#getText
* (org.eclipse.graphiti.features.context.IDirectEditingContext)
*/
@Override
protected AbstractText getText(IDirectEditingContext context) {
EObject container = context.getPictogramElement().eContainer();
if (container instanceof ContainerShape) {
ContainerShape containerShape = (ContainerShape) container;
int containerCounter = 0;
for (Shape shape : containerShape.getChildren()) {
if (shape instanceof ContainerShape) {
containerCounter++;
if (containerCounter == 2) {
return findTextInContainer((ContainerShape) shape);
}
}
}
return null;
} else
return null;
}
}