blob: a19c76801d77bcc2a5fcb50e9eaec17dde626768 [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.features;
import org.eclipse.fmc.blockdiagram.editor.meta.profile.IStereotypeProvider;
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.PictogramElement;
import org.eclipse.fmc.blockdiagram.editor.util.FMCUtil;
import org.eclipse.fmc.mm.FMCElement;
/**
* Feature Class for editing the text of a business object.
*
* @author Patrick Jahnke
*
*/
public class TextDirectEditingMetaFeature extends
org.eclipse.fmc.blockdiagram.editor.features.TextDirectEditingFeature {
/**
* The stereotype provider (is not null only if the Stereotype Extension is
* installed).
*/
private IStereotypeProvider stereotypeProvider;
/**
* Instantiates a new TextDirectEditingMetaFeature.
*
* @param fp
* the FeatureProvider Class.
* @param stereotypeProvider
* the StereotypeProvider Class.
*/
public TextDirectEditingMetaFeature(IFeatureProvider fp,
IStereotypeProvider stereotypeProvider) {
super(fp);
this.stereotypeProvider = stereotypeProvider;
}
/**
* Instantiate and call the TextDirectEditingVisitor.
*/
@Override
public void setValue(String value, IDirectEditingContext context) {
FMCElement element = (FMCElement) FMCUtil
.getBO((PictogramElement) context.getPictogramElement());
TextDirectEditingVisitor visitor = new TextDirectEditingVisitor(context);
visitor.visit(element, value);
if (stereotypeProvider != null)
value = stereotypeProvider.getStereotypeText(element) + value;
super.setValue(value, context);
}
/**
* Get the initial Value when the direct Text editing phase begins.
*/
@Override
public String getInitialValue(IDirectEditingContext context) {
AbstractText text = getText(context);
if (text != null) {
String value = text.getValue();
if (stereotypeProvider != null)
value = FMCUtil.substringStereotype(value);
return value;
} else
return "";
}
}