/** | |
* 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; | |
/** | |
* this class launch the command to remove propagation | |
* Req004.004: the system shall provide menus to execute Strategy | |
*/ | |
public class ProcessStrategyHandler 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 processStrategyCatalog = strategyEngineFactory.getCurrentEngine().getCatalog("Process-oriented Strategies"); | |
StrategyDialog dialog= new StrategyDialog(element, | |
strategyEngineFactory.getCurrentEngine(), | |
processStrategyCatalog); | |
dialog.open(); | |
if(dialog.canExecute()){ | |
IStrategy selectedStrategy=strategyEngineFactory.getCurrentEngine().getStrategyToExecute(); | |
transactionalEditingDomain.getCommandStack().execute(selectedStrategy.getCommand(element,transactionalEditingDomain)); | |
} else { | |
System.out.printf("Can not execute process-oriented choice!\n"); | |
} | |
} | |
else { | |
System.err.println("Engine not ready!"); | |
} | |
} | |
} |