blob: d30fa07531c7cd06dd176052f434889eb8989989 [file] [log] [blame]
<%@ jet package="comrel.refactoring" class="RefactoringController"
imports="org.eclipse.emf.refactor.refactoring.generator.core.* comrel.generator.refactoring.*"%>
<%ComrelConfig refactoringConfig = (ComrelConfig) argument; %>
/**
* <copyright>
* </copyright>
*
* $Id: RefactoringController.javajet,v 1.3 2011/01/21 13:08:06 tarendt Exp $
*/
package <%=refactoringConfig.getPackageName()%>;
import comrel.InputPort;
import comrel.RefactoringUnit;
import comrel.SingleInputPort;
import comrel.interpreter.ComrelInterpreter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.refactor.refactoring.core.Refactoring;
import org.eclipse.emf.refactor.refactoring.interfaces.IController;
import org.eclipse.emf.refactor.refactoring.interfaces.IDataManagement;
import org.eclipse.emf.refactor.refactoring.runtime.ltk.LtkEmfRefactoringProcessorAdapter;
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
import org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor;
public final class RefactoringController implements IController {
/**
* Refactoring supported by the controller.
* @generated
*/
private Refactoring parent;
/**
* DataManagement object of the model refactoring.
* @generated
*/
private RefactoringDataManagement dataManagement =
new RefactoringDataManagement();
/**
* Invocation context of the model refactoring.
* @generated
*/
private List<EObject> selection = new ArrayList<EObject>();
/**
* Ltk RefactoringProcessor of the model refactoring.
* @generated
*/
private InternalRefactoringProcessor refactoringProcessor = null;
/**
* Gets the Refactoring supported by the controller.
* @return Refactoring supported by the controller.
* @see org.eclipse.emf.refactor.common.core.IController#getParent()
* @generated
*/
@Override
public Refactoring getParent() {
return this.parent;
}
/**
* Sets the Refactoring supported by the controller.
* @param Refactoring refactoring supported by the controller.
* @see org.eclipse.emf.refactor.common.core.IController#
* setParent(org.eclipse.emf.refactor.common.core.Refactoring)
* @generated
*/
@Override
public void setParent(Refactoring refactoring) {
this.parent = refactoring;
}
/**
* Returns the DataManagement object of the model refactoring.
* @return DataManagement object of the model refactoring.
* @see org.eclipse.emf.refactor.common.core.IController#
* getDataManagementObject()
* @generated
*/
@Override
public IDataManagement getDataManagementObject() {
return this.dataManagement;
}
/**
* Returns the ltk RefactoringProcessor of the model refactoring.
* @return Ltk RefactoringProcessor of the model refactoring.
* @see org.eclipse.emf.refactor.common.core.IController#
* getLtkRefactoringProcessor()
* @generated
*/
@Override
public RefactoringProcessor getLtkRefactoringProcessor() {
return this.refactoringProcessor;
}
/**
* Sets the selected EObject (invocation context of the model refactoring).
* @param selection Invocation context of the model refactoring.
* @see org.eclipse.emf.refactor.common.core.IController#
* setSelection(java.util.List)
* @generated
*/
@Override
public void setSelection(List<EObject> selection) {
this.selection = selection;
this.refactoringProcessor =
new InternalRefactoringProcessor(this.selection);
}
/**
* Returns a Runnable object that executes the model refactoring.
* @return Runnable object that executes the model refactoring.
* @generated
*/
private Runnable applyRefactoring() {
return new Runnable() {
/**
* @see java.lang.Runnable#run()
* @generated
*/
@Override
public void run() {
try {
<%=refactoringConfig.getSelectedEObjectClass()%> selectedEObject =
(<%=refactoringConfig.getSelectedEObjectClass()%>) dataManagement.
getInPortByName(dataManagement.SELECTEDEOBJECT).getValue();<%/*
*/%><%for (ParameterInfo pC : refactoringConfig.getParameters()) { %>
String <%=pC.getName()%> =
(String) dataManagement.getInPortByName("<%=pC.getName()%>").getValue();<%}%>
// begin prepare and execute comrel interpreter
ComrelInterpreter interpreter = new ComrelInterpreter(selectedEObject);
interpreter.loadComrelModel(dataManagement.getComrelFilePath());
setRootPortValues(interpreter, selectedEObject<%for (ParameterInfo pC : refactoringConfig.getParameters()) { %>,
<%=pC.getName()%><%}%>);
interpreter.execute();
// end prepare and execute comrel interpreter
} catch (IOException e) {
e.printStackTrace();
}
}
private void setRootPortValues(
ComrelInterpreter interpreter,
<%=refactoringConfig.getSelectedEObjectClass()%> selectedEObject<%for (ParameterInfo pC : refactoringConfig.getParameters()) { %>,
String <%=pC.getName()%><%}%>) {
RefactoringUnit rootRefactoringUnit = interpreter.getRootRefactoringUnit();
for (InputPort ip : rootRefactoringUnit.getAllInputPorts()) {
System.out.println(ip.getName());
if (ip.getName().equals("selectedEObject")) {
((SingleInputPort) ip).setValue(selectedEObject);
}<%for (ParameterInfo pC : refactoringConfig.getParameters()) { %>
if (ip.getName().equals("<%=pC.getName()%>")) {
((SingleInputPort) ip).setValue(<%=pC.getName()%>);
}<%}%>
}
}
};
}
/**
* Internal class for providing an instance of a LTK RefactoringProcessor
* used for EMF model refactorings.
* @generated
*/
public final class InternalRefactoringProcessor extends
LtkEmfRefactoringProcessorAdapter {
/**
* Constructor using the invocation context of the model refactoring.
* @param selection Invocation context of the model refactoring.
* @generated
*/
private InternalRefactoringProcessor(List<EObject> selection){
super(getParent(), selection, applyRefactoring());
}
/**
* @see org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor#
* checkInitialConditions(org.eclipse.core.runtime.IProgressMonitor)
* @generated
*/
@Override
public RefactoringStatus checkInitialConditions(){
RefactoringStatus result = new RefactoringStatus();
<%=refactoringConfig.getSelectedEObjectClass()%> selectedEObject =
(<%=refactoringConfig.getSelectedEObjectClass()%>) dataManagement.
getInPortByName(dataManagement.SELECTEDEOBJECT).getValue();
// TODO: implement initial check
return result;
}
/**
* @see org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor#
* checkFinalConditions(org.eclipse.core.runtime.IProgressMonitor,
* org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext)
* @generated
*/
@Override
public RefactoringStatus checkFinalConditions(){
RefactoringStatus result = new RefactoringStatus();
<%=refactoringConfig.getSelectedEObjectClass()%> selectedEObject =
(<%=refactoringConfig.getSelectedEObjectClass()%>) dataManagement.
getInPortByName(dataManagement.SELECTEDEOBJECT).getValue();<%/*
*/%><%for (ParameterInfo pC : refactoringConfig.getParameters()) {%>
String <%=pC.getName()%> =
(String) dataManagement.getInPortByName("<%=pC.getName()%>").getValue();<%}%>
// TODO: implement final check
return result;
}
}
}