blob: 0cde3a31c6666eee38cc1462dc121b2d874886ac [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.custom;
import org.eclipse.fmc.blockdiagram.editor.BlockDiagramMessages;
import org.eclipse.graphiti.features.IFeatureProvider;
import org.eclipse.graphiti.features.context.ICustomContext;
import org.eclipse.graphiti.mm.algorithms.Text;
import org.eclipse.graphiti.mm.pictograms.Connection;
import org.eclipse.graphiti.mm.pictograms.ConnectionDecorator;
import org.eclipse.graphiti.mm.pictograms.PictogramElement;
import org.eclipse.graphiti.services.Graphiti;
import org.eclipse.graphiti.services.IGaService;
import org.eclipse.graphiti.services.IPeService;
/**
* This features adds a text to a connection. This is for example necessary if
* the user has removed the text previously.
*
* @author Benjamin Schmeling
*
*/
public class AddTextToConnectionCustomFeature extends FMCCustomFeature {
/**
* The default constructor.
*
* @param featureProvider
* The feature provider.
*/
public AddTextToConnectionCustomFeature(IFeatureProvider featureProvider) {
super(featureProvider);
}
/*
* (non-Javadoc)
*
* @see
* org.eclipse.graphiti.features.custom.ICustomFeature#execute(org.eclipse
* .graphiti.features.context.ICustomContext)
*/
@Override
public void execute(ICustomContext context) {
IGaService ga = Graphiti.getGaService();
IPeService pe = Graphiti.getPeService();
for (PictogramElement element : context.getPictogramElements()) {
Connection con = (Connection) element;
ConnectionDecorator letter = pe.createConnectionDecorator(con,
true, 0.4f, true);
Text txt = ga.createText(letter,
BlockDiagramMessages.FMCAddFeature_DefaultShapeTitle);
txt.setForeground(ga.manageColor(getDiagram(), 0, 0, 0));
ga.setLocation(txt, -8, 22);
}
}
/*
* (non-Javadoc)
*
* @see
* org.eclipse.graphiti.features.custom.AbstractCustomFeature#canExecute
* (org.eclipse.graphiti.features.context.ICustomContext)
*/
@Override
public boolean canExecute(ICustomContext context) {
if (context.getPictogramElements().length == 0)
return false;
for (PictogramElement element : context.getPictogramElements()) {
if (!(element instanceof Connection))
return false;
}
return true;
}
/*
* (non-Javadoc)
*
* @see org.eclipse.graphiti.features.impl.AbstractFeature#getName()
*/
@Override
public String getName() {
return "Add Text";
}
}