blob: 1055d41d27a705b6e62e6dbddad23da5506bd6e5 [file] [log] [blame]
/**
* Copyright (c)2020 CEA LIST, Committer Name, and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* CEA LIST - Initial API and implementation
* Gabriel Pedroza (CEA LIST) gabriel.pedroza@cea.fr
*
*/
package org.eclipse.papyrus.pdp4eng.designer.engine.api.internal;
import java.util.ArrayList;
import java.util.ListIterator;
import org.eclipse.papyrus.pdp4eng.designer.engine.api.IStrategy;
import org.eclipse.papyrus.pdp4eng.designer.engine.api.IStrategyCatalog;
import org.eclipse.papyrus.pdp4eng.designer.engine.api.IStrategyEngine;
public class StrategyEngine implements IStrategyEngine {
protected IStrategy selectedStrategy=null;
protected ArrayList<IStrategyCatalog> currentCatalogList=new ArrayList<>(); //maybe a collection?
@Override
public IStrategy getStrategyToExecute() {
return selectedStrategy;
}
@Override
public void connectACatalog(IStrategyCatalog catalog) {
this.currentCatalogList.add(catalog);
}
@Override
public ArrayList<IStrategyCatalog> getCurrentCatalogList(){
return currentCatalogList;
}
@Override
public IStrategyCatalog getCatalog(int index) {
if (currentCatalogList.size()>0 && index<currentCatalogList.size()) {
return currentCatalogList.get(index);
}
return null;
}
@Override
public IStrategyCatalog getCatalog(String name){
if (currentCatalogList.size()>0) {
ListIterator<IStrategyCatalog> catalogListIterator = currentCatalogList.listIterator();
while (catalogListIterator.hasNext()) {
IStrategyCatalog currentCatalog = catalogListIterator.next();
if (currentCatalog!=null && currentCatalog.getId().equals(name)) {
return currentCatalog;
}
}
}
return null;
}
@Override
public void clearExecutableStrategy() {
this.selectedStrategy=null;
}
@Override
public void setStrategyToExecute(IStrategy strategy) {
selectedStrategy= strategy;
}
@Override
public boolean isReadyToRun() {
if( currentCatalogList.size()!=0) {
return true;
}
return false;
}
}