package es.iiia.sgi.handlers;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.IHandler;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.handlers.HandlerUtil;
import es.iiia.shapegrammar.model.ShapeGrammarModel;
import es.iiia.shapegrammar.shape.ShapeModel;
public class SetStartingShapeHandler extends AbstractHandler implements
IHandler {
public Object execute(ExecutionEvent event) throws ExecutionException {
// replace current left shape with the one selected
ISelection selection = HandlerUtil.getActivePart(event).getSite()
.getSelectionProvider().getSelection();
if (selection != null && selection instanceof IStructuredSelection) {
Object obj = ((IStructuredSelection) selection).getFirstElement();
// If we had a selection lets open the editor
if (obj != null) {
ShapeModel shape = (ShapeModel) obj;
ShapeGrammarModel.ACTIVE_SHAPE_GRAMMAR.setStartShape(shape);
}
}
return null;
}
}