blob: 75ca87ded36b7ef8dc3867472e65c71866dff0d4 [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
* Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr
*
*/
package org.eclipse.papyrus.pdp4eng.designer.ui;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
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.StrategyEngineFactory;
import org.eclipse.papyrus.pdp4eng.designer.ui.internal.StrategyDialog;
import org.eclipse.papyrus.requirements.sysml14.common.PapyrusAbstractHandler;
import org.eclipse.uml2.uml.Element;
public class DataStrategyHandler extends PapyrusAbstractHandler {
protected org.eclipse.uml2.uml.Element selectedElement=null;
public Object execute(ExecutionEvent event) throws ExecutionException {
super.execute(event);
selectedElement=getSelection();
if(selectedElement!=null){
callEngine(transactionalEditingDomain,selectedElement);
}
return null;
}
/**
*
* @see org.eclipse.core.commands.AbstractHandler#isEnabled()
*
* @return
*/
@Override
public boolean isEnabled() {
return super.isEnabled();
}
public void callEngine(TransactionalEditingDomain transactionalEditingDomain,Element element){
StrategyEngineFactory strategyEngineFactory = StrategyEngineFactory.getInstance();
if( strategyEngineFactory.getCurrentEngine().isReadyToRun()) {
strategyEngineFactory.getCurrentEngine().clearExecutableStrategy();
IStrategyCatalog dataStrategyCatalog = strategyEngineFactory.getCurrentEngine().getCatalog("Data-oriented Strategies");
StrategyDialog dialog= new StrategyDialog(element,
strategyEngineFactory.getCurrentEngine(),
dataStrategyCatalog);
dialog.open();
if(dialog.canExecute()){
if (strategyEngineFactory.getCurrentEngine().getStrategyToExecute() !=null) {
IStrategy selectedStrategy=strategyEngineFactory.getCurrentEngine().getStrategyToExecute();
transactionalEditingDomain.getCommandStack().execute(selectedStrategy.getCommand(element,transactionalEditingDomain));
} else {
System.out.printf("Data-oriented strategy not selected!\n");
}
} else {
System.out.printf("Can not execute data-oriented choice!\n");
}
}
else {
System.err.println("Engine not ready!");
}
}
}