/******************************************************************************* | |
* <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.graphiti.features.IFeatureProvider; | |
import org.eclipse.graphiti.features.context.IDirectEditingContext; | |
import org.eclipse.graphiti.features.impl.AbstractDirectEditingFeature; | |
import org.eclipse.graphiti.func.IDirectEditing; | |
import org.eclipse.graphiti.mm.algorithms.AbstractText; | |
/** | |
* | |
* @author Benjamin Schmeling | |
* | |
*/ | |
public class TextDirectEditingFeature extends AbstractDirectEditingFeature { | |
public TextDirectEditingFeature(IFeatureProvider fp) { | |
super(fp); | |
} | |
/* | |
* (non-Javadoc) | |
* | |
* @see org.eclipse.graphiti.func.IDirectEditing#getEditingType() | |
*/ | |
@Override | |
public int getEditingType() { | |
return IDirectEditing.TYPE_MULTILINETEXT; | |
} | |
/** | |
* If the selected element is a text, this method will return it, otherwise | |
* null. | |
* | |
* @param context | |
* The direct editing context. | |
* | |
* @return The text if one was selected, otherwise null. | |
*/ | |
protected AbstractText getText(IDirectEditingContext context) { | |
if (context.getGraphicsAlgorithm() instanceof AbstractText) | |
return (AbstractText) context.getGraphicsAlgorithm(); | |
else | |
return null; | |
} | |
/* | |
* (non-Javadoc) | |
* | |
* @see | |
* org.eclipse.graphiti.func.IDirectEditing#getInitialValue(org.eclipse. | |
* graphiti.features.context.IDirectEditingContext) | |
*/ | |
@Override | |
public String getInitialValue(IDirectEditingContext context) { | |
AbstractText text = getText(context); | |
if (text != null) { | |
return text.getValue(); | |
} else | |
return ""; | |
} | |
/* | |
* (non-Javadoc) | |
* | |
* @see | |
* org.eclipse.graphiti.features.impl.AbstractDirectEditingFeature#setValue | |
* (java.lang.String, | |
* org.eclipse.graphiti.features.context.IDirectEditingContext) | |
*/ | |
@Override | |
public void setValue(String value, IDirectEditingContext context) { | |
AbstractText text = getText(context); | |
if (text != null) { | |
text.setValue(value); | |
} | |
} | |
} |