/******************************************************************************* | |
* <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.extension; | |
import java.util.ArrayList; | |
import java.util.Arrays; | |
import java.util.Collection; | |
import java.util.List; | |
import org.eclipse.graphiti.dt.IDiagramTypeProvider; | |
import org.eclipse.graphiti.features.IAddFeature; | |
import org.eclipse.graphiti.features.ICopyFeature; | |
import org.eclipse.graphiti.features.IPasteFeature; | |
import org.eclipse.graphiti.features.IPrintFeature; | |
import org.eclipse.graphiti.features.ISaveImageFeature; | |
import org.eclipse.graphiti.features.context.IAddContext; | |
import org.eclipse.graphiti.features.context.ICopyContext; | |
import org.eclipse.graphiti.features.context.ICustomContext; | |
import org.eclipse.graphiti.features.context.IPasteContext; | |
import org.eclipse.graphiti.features.custom.ICustomFeature; | |
import org.eclipse.graphiti.features.impl.AbstractFeatureProvider; | |
/** | |
* The CompositeFeatureProvider is a container for other feature providers. It | |
* maintains a list of feature providers which are called in order to get an | |
* feature. If the first feature returns a non-null result, this result is | |
* returned immediately. | |
* | |
* @author Benjamin Schmeling | |
* | |
*/ | |
public class CompositeFeatureProvider extends AbstractFeatureProvider { | |
private List<AbstractFeatureProvider> featureProviders = new ArrayList<AbstractFeatureProvider>(); | |
/** | |
* | |
* @param diagramTypeProvider | |
*/ | |
public CompositeFeatureProvider(IDiagramTypeProvider diagramTypeProvider) { | |
super(diagramTypeProvider); | |
} | |
/** | |
* Add a new provider. | |
* | |
* @param provider | |
* The provider to be added. | |
*/ | |
public void addFeatureProvider(AbstractFeatureProvider provider) { | |
featureProviders.add(provider); | |
} | |
/* | |
* (non-Javadoc) | |
* | |
* @see | |
* org.eclipse.graphiti.features.impl.AbstractFeatureProvider#getAddFeature | |
* (org.eclipse.graphiti.features.context.IAddContext) | |
*/ | |
@Override | |
public IAddFeature getAddFeature(IAddContext context) { | |
for (AbstractFeatureProvider provider : featureProviders) { | |
IAddFeature feature = provider.getAddFeature(context); | |
if (feature != null) { | |
return feature; | |
} | |
} | |
return super.getAddFeature(context); | |
} | |
/* | |
* (non-Javadoc) | |
* | |
* @see | |
* org.eclipse.graphiti.features.impl.AbstractFeatureProvider#getCustomFeatures | |
* (org.eclipse.graphiti.features.context.ICustomContext) | |
*/ | |
@Override | |
public ICustomFeature[] getCustomFeatures(ICustomContext context) { | |
Collection<ICustomFeature> features = new ArrayList<ICustomFeature>(); | |
for (AbstractFeatureProvider provider : featureProviders) { | |
ICustomFeature[] featureArray = provider.getCustomFeatures(context); | |
features.addAll(Arrays.asList(featureArray)); | |
} | |
return features.toArray(new ICustomFeature[] {}); | |
} | |
/* | |
* (non-Javadoc) | |
* | |
* @see | |
* org.eclipse.graphiti.features.IFeatureProvider#getCopyFeature(org.eclipse | |
* .graphiti.features.context.ICopyContext) | |
*/ | |
@Override | |
public ICopyFeature getCopyFeature(ICopyContext context) { | |
return null; | |
} | |
/* | |
* (non-Javadoc) | |
* | |
* @see | |
* org.eclipse.graphiti.features.IFeatureProvider#getPasteFeature(org.eclipse | |
* .graphiti.features.context.IPasteContext) | |
*/ | |
@Override | |
public IPasteFeature getPasteFeature(IPasteContext context) { | |
return null; | |
} | |
@Override | |
public IPrintFeature getPrintFeature() { | |
// TODO Auto-generated method stub | |
return null; | |
} | |
@Override | |
public ISaveImageFeature getSaveImageFeature() { | |
// TODO Auto-generated method stub | |
return null; | |
} | |
} |