Package es.iiia.sgi.handlers

Source Code of es.iiia.sgi.handlers.SetStartingShapeHandler

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;
  }
}
TOP

Related Classes of es.iiia.sgi.handlers.SetStartingShapeHandler

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.