package jetbrains.mps.ide.devkit.actions; /*Generated by MPS */ import jetbrains.mps.workbench.action.BaseAction; import javax.swing.Icon; import com.intellij.icons.AllIcons; import com.intellij.openapi.actionSystem.AnActionEvent; import java.util.Map; import jetbrains.mps.ide.actions.MPSCommonDataKeys; import jetbrains.mps.smodel.Language; import org.jetbrains.mps.openapi.model.SModel; import jetbrains.mps.util.IterableUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.mps.openapi.module.SModule; import com.intellij.openapi.project.Project; import com.intellij.openapi.actionSystem.CommonDataKeys; import org.jetbrains.mps.openapi.module.SearchScope; import jetbrains.mps.project.GlobalScope; import jetbrains.mps.ide.findusages.model.SearchQuery; import jetbrains.mps.ide.findusages.model.IResultProvider; import jetbrains.mps.ide.findusages.view.FindUtils; import jetbrains.mps.ide.findusages.findalgorithm.finders.specific.LanguageConceptsUsagesFinder; import jetbrains.mps.ide.findusages.view.UsageToolOptions; import jetbrains.mps.ide.findusages.view.UsagesViewTool; public class FindLanguageConceptsUsages_Action extends BaseAction { private static final Icon ICON = AllIcons.Actions.Find; public FindLanguageConceptsUsages_Action() { super("Find Concepts Usages", "", ICON); this.setIsAlwaysVisible(false); this.setExecuteOutsideCommand(false); } @Override public boolean isDumbAware() { return true; } @Override public boolean isApplicable(AnActionEvent event, final Map<String, Object> _params) { if (!(event.getData(MPSCommonDataKeys.MODULE) instanceof Language)) { return false; } Language language = (Language) event.getData(MPSCommonDataKeys.MODULE); SModel structureModelDescriptor = language.getStructureModelDescriptor(); if (structureModelDescriptor == null) { return false; } if (IterableUtil.asCollection(structureModelDescriptor.getRootNodes()).size() == 0) { return false; } return true; } @Override public void doUpdate(@NotNull AnActionEvent event, final Map<String, Object> _params) { this.setEnabledState(event.getPresentation(), this.isApplicable(event, _params)); } @Override protected boolean collectActionData(AnActionEvent event, final Map<String, Object> _params) { if (!(super.collectActionData(event, _params))) { return false; } { SModule p = event.getData(MPSCommonDataKeys.MODULE); if (p == null) { return false; } } { Project p = event.getData(CommonDataKeys.PROJECT); if (p == null) { return false; } } return true; } @Override public void doExecute(@NotNull final AnActionEvent event, final Map<String, Object> _params) { SearchScope scope = GlobalScope.getInstance(); final SearchQuery query = new SearchQuery(event.getData(MPSCommonDataKeys.MODULE), scope); final IResultProvider provider = FindUtils.makeProvider(new LanguageConceptsUsagesFinder()); UsageToolOptions opt = new UsageToolOptions().allowRunAgain(true).forceNewTab(false).navigateIfSingle(false).notFoundMessage("There are no usages of language's concepts"); UsagesViewTool.showUsages(event.getData(CommonDataKeys.PROJECT), provider, query, opt); } }