protected void addListeners() {
   VirtualFileManager.getInstance().addVirtualFileManagerListener(myRefreshListener);
   SModelRepository.getInstance().addModelRepositoryListener(mySModelRepositoryListener);
   ModelAccess.instance().addCommandListener(myModelAccessListener);
   MPSModuleRepository.getInstance().addModuleRepositoryListener(myRepositoryListener);
   if (IMakeService.INSTANCE.isSessionActive()) {
     IMakeService.INSTANCE.get().addListener(myMakeNotificationListener);
   }
   ClassLoaderManager.getInstance().addReloadHandler(myReloadListener);
 }
 protected void removeListeners() {
   ClassLoaderManager.getInstance().removeReloadHandler(myReloadListener);
   SModelRepository.getInstance().removeModelRepositoryListener(mySModelRepositoryListener);
   ModelAccess.instance().removeCommandListener(myModelAccessListener);
   MPSModuleRepository.getInstance().removeModuleRepositoryListener(myRepositoryListener);
   if (IMakeService.INSTANCE.hasMakeService()) {
     IMakeService.INSTANCE.get().removeListener(myMakeNotificationListener);
   }
   VirtualFileManager.getInstance().removeVirtualFileManagerListener(myRefreshListener);
 }
 public boolean isApplicable(AnActionEvent event, final Map<String, Object> _params) {
   List<SModel> models =
       ListSequence.fromListWithValues(
           new ArrayList<SModel>(),
           (Iterable<SModel>)
               VcsActionsUtil.getModels(
                   ((VirtualFile[]) MapSequence.fromMap(_params).get("virtualFiles"))));
   if (!(VcsActionsUtil.isMakePluginInstalled())
       || IMakeService.INSTANCE.get().isSessionActive()
       || ListSequence.fromList(models).isEmpty()) {
     return false;
   }
   String text =
       new MakeActionParameters(
               ((IOperationContext) MapSequence.fromMap(_params).get("context")),
               models,
               ListSequence.fromList(models).first(),
               null,
               null)
           .actionText(MakeOrRebuildModelsFromChangeList_Action.this.rebuild);
   if (text != null) {
     event.getPresentation().setText(text);
     return true;
   }
   return false;
 }
  @Override
  protected void doRefactoringAction() {
    final boolean needToRegenerate = myRegenerateLanguage.getModel().isSelected();

    final String fqName = getCurrentValue();
    if (MPSModuleRepository.getInstance().getModuleByFqName(fqName) != null) {
      setErrorText("Duplicate language name");
      return;
    }
    if (!((SourceVersion.isName(fqName)))) {
      setErrorText("Language namespace should be valid Java package");
      return;
    }
    final LanguageRenamer renamer = new LanguageRenamer(myProject, myLanguage, fqName);
    ModelAccess modelAccess = myProject.getRepository().getModelAccess();
    modelAccess.executeCommand(
        new Runnable() {
          public void run() {
            renamer.rename(needToRegenerate);
            renamer.update();
          }
        });
    if (needToRegenerate) {
      final Map<SModule, List<SModel>> langs = new LinkedHashMap<SModule, List<SModel>>();
      modelAccess.runReadAction(
          new Runnable() {
            public void run() {
              RefactoringUtil.fillLanguageAndItsExtendingLanguageModels(myLanguage, langs);
            }
          });
      for (final List<SModel> models : langs.values()) {
        ModuleContext context = new ModuleContext(myLanguage, myProject);
        MakeSession sess = new MakeSession(context);
        if (IMakeService.INSTANCE.get().openNewSession(sess)) {
          IMakeService.INSTANCE
              .get()
              .make(sess, new ModelsToResources(context, models).resources(false));
        }
        //         GeneratorUIFacade.getInstance().generateModels(new ModuleContext(myLanguage,
        // myProject), params.getModelDescriptors(),
        // GeneratorUIFacade.getInstance().getDefaultGenerationHandler(), true, false);
      }
    }
    super.doRefactoringAction();
  }
  @Override
  protected void doRefactoringAction() {
    final boolean needToRegenerate = myRegenerateLanguage.getModel().isSelected();

    final String fqName = getCurrentValue();
    if (MPSModuleRepository.getInstance().getModuleByFqName(fqName) != null) {
      setErrorText("Duplicate language name");
      return;
    }
    if (!((SourceVersion.isName(fqName)))) {
      setErrorText("Language namespace should be valid Java package");
      return;
    }
    final LanguageRenamer renamer = new LanguageRenamer(myProject, myLanguage, fqName);
    ModelAccess.instance()
        .runWriteActionInCommand(
            new Runnable() {
              public void run() {
                renamer.rename(needToRegenerate);
                renamer.update();
              }
            });
    if (needToRegenerate) {
      final Set<Language> langs = new LinkedHashSet<Language>();
      ModelAccess.instance()
          .runReadAction(
              new Runnable() {
                @Override
                public void run() {
                  langs.add(myLanguage);
                  langs.addAll(
                      ModuleRepositoryFacade.getInstance().getAllExtendingLanguages(myLanguage));
                }
              });
      for (final Language l : langs) {
        GenParameters params =
            ModelAccess.instance()
                .runReadAction(
                    new Computable<GenParameters>() {
                      @Override
                      public GenParameters compute() {
                        ModuleTestConfiguration languageConfig = new ModuleTestConfiguration();
                        languageConfig.setModuleRef(l.getModuleReference());
                        languageConfig.setName("tmp");
                        try {
                          return languageConfig.getGenParams(
                              myProject.getComponent(MPSProject.class), true);
                        } catch (IllegalGeneratorConfigurationException e) {
                          return null;
                        }
                      }
                    });
        if (params == null) {
          setErrorText("Rebuild configuration is invalid");
          return;
        }
        ModuleContext context =
            new ModuleContext(myLanguage, ProjectHelper.toMPSProject(myProject));
        MakeSession sess = new MakeSession(context);
        if (IMakeService.INSTANCE.get().openNewSession(sess)) {
          IMakeService.INSTANCE
              .get()
              .make(
                  sess,
                  new ModelsToResources(
                          context,
                          ListSequence.fromListWithValues(
                              new ArrayList<SModel>(),
                              (Iterable<SModel>) params.getModelDescriptors()))
                      .resources(false));
        }
        //         GeneratorUIFacade.getInstance().generateModels(new ModuleContext(myLanguage,
        // myProject), params.getModelDescriptors(),
        // GeneratorUIFacade.getInstance().getDefaultGenerationHandler(), true, false);
      }
    }
    super.doRefactoringAction();
  }