/******************************************************************************* | |
* <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.IFeature; | |
import org.eclipse.graphiti.features.IFeatureProvider; | |
import org.eclipse.graphiti.features.context.IContext; | |
/** | |
* | |
* @author Benjamin Schmeling | |
* | |
*/ | |
public class CompositeFeature implements IFeature { | |
private final IFeature[] features; | |
protected IFeature getFeature(int i) { | |
return features[i]; | |
} | |
public CompositeFeature(IFeature... features) { | |
this.features = features; | |
} | |
@Override | |
public String getName() { | |
return "Composite feature"; | |
} | |
@Override | |
public String getDescription() { | |
return "Executes mutiple features at the same time"; | |
} | |
@Override | |
public IFeatureProvider getFeatureProvider() { | |
return features[0].getFeatureProvider(); | |
} | |
@Override | |
public boolean isAvailable(IContext context) { | |
for (IFeature feature : features) { | |
if (!feature.isAvailable(context)) | |
return false; | |
} | |
return true; | |
} | |
@Override | |
public boolean canExecute(IContext context) { | |
for (IFeature feature : features) { | |
if (!feature.canExecute(context)) | |
return false; | |
} | |
return true; | |
} | |
@Override | |
public void execute(IContext context) { | |
for (IFeature feature : features) { | |
feature.execute(context); | |
} | |
} | |
@Override | |
public boolean canUndo(IContext context) { | |
for (IFeature feature : features) { | |
if (!feature.canUndo(context)) | |
return false; | |
} | |
return true; | |
} | |
@Override | |
public boolean hasDoneChanges() { | |
for (IFeature feature : features) { | |
if (feature.hasDoneChanges()) | |
return true; | |
} | |
return true; | |
} | |
} |