Package es.iiia.sgi.handlers

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

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.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.handlers.HandlerUtil;
import org.eclipse.ui.services.IEvaluationService;

import es.iiia.sgi.views.RuleView;
import es.iiia.sgi.views.ShapeView;
import es.iiia.shapegrammar.model.ShapeGrammarModel;

public class CloseGrammarHandler extends AbstractHandler implements IHandler {

  public Object execute(ExecutionEvent event) throws ExecutionException {
    IWorkbenchWindow workbenchWindow = HandlerUtil
        .getActiveWorkbenchWindow(event);
    // first close all editors and save current data
    boolean canContinue = workbenchWindow.getActivePage().closeAllEditors(
        true);

    if (canContinue) {
      // disable grammar
      ShapeGrammarModel.ACTIVE_SHAPE_GRAMMAR = null;
     
      // TODO: reload views
      ShapeView shapes = (ShapeView) workbenchWindow.getActivePage()
          .findView(ShapeView.ID);
      RuleView rules = (RuleView) workbenchWindow.getActivePage()
          .findView(RuleView.ID);     

      shapes.setContent(null);
      rules.setContent(null);
     
      // recreate menu
      IEvaluationService service = (IEvaluationService) PlatformUI
          .getWorkbench().getService(IEvaluationService.class);
      service.requestEvaluation("es.iiia.sgi.propertytesters.isFileOpen");

    }

    return null;
  }
}
TOP

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

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.