Search in sources :

Example 1 with DiagramProvider

use of com.intellij.diagram.DiagramProvider in project intellij-plugins by JetBrains.

the class FlashUmlTest method doTestImpl.

private DiagramBuilder doTestImpl(@Nullable File projectRoot, String[] files, String[] additionalClasses, Computable<GlobalSearchScope> scopeProvider, @Nullable EnumSet<FlashUmlDependenciesSettingsOption> dependencies, @Nullable String expectedFileNamePrefix) throws Exception {
    List<VirtualFile> vFiles = new ArrayList<>(files.length);
    for (String file : files) {
        vFiles.add(getVirtualFile(BASE_PATH + file));
    }
    ApplicationManager.getApplication().runWriteAction(() -> {
        final ModuleRootManager rootManager = ModuleRootManager.getInstance(myModule);
        final ModifiableRootModel rootModel = rootManager.getModifiableModel();
        ContentEntry[] contentEntries = rootModel.getContentEntries();
        for (ContentEntry contentEntry : contentEntries) {
            rootModel.removeContentEntry(contentEntry);
        }
        rootModel.commit();
    });
    configureByFiles(projectRoot, VfsUtilCore.toVirtualFileArray(vFiles));
    final LinkedHashMap<Integer, String> markers = JSTestUtils.extractPositionMarkers(getProject(), getEditor().getDocument());
    assertFalse(markers.isEmpty());
    DiagramBuilder builder = null;
    int i = 1;
    for (Map.Entry<Integer, String> marker : markers.entrySet()) {
        getEditor().getCaretModel().moveToOffset(marker.getKey());
        i++;
        String expectedPrefix = StringUtil.isNotEmpty(marker.getValue()) ? marker.getValue() : expectedFileNamePrefix;
        final DataContext dataContext = DataManager.getInstance().getDataContext();
        final DiagramProvider[] providers = DiagramProvider.findProviders(dataContext, "unknown");
        final FlashUmlProvider provider = ContainerUtil.findInstance(providers, FlashUmlProvider.class);
        assertNotNull("Flash UML provider not found", provider);
        final String actualOriginFqn = provider.getVfsResolver().getQualifiedName(provider.getElementManager().findInDataContext(dataContext));
        final Object actualOrigin = provider.getVfsResolver().resolveElementByFQN(actualOriginFqn, getProject());
        builder = UmlGraphBuilderFactory.create(myProject, provider, actualOrigin, null);
        Disposer.register(getTestRootDisposable(), builder);
        final DiagramDataModel<Object> model = builder.getDataModel();
        DiagramConfiguration configuration = DiagramConfiguration.getConfiguration();
        String originalCategories = configuration.categories.get(provider.getID());
        if (dependencies != null) {
            model.setShowDependencies(true);
            EnumSet<FlashUmlDependenciesSettingsOption> disabledOptions = EnumSet.complementOf(dependencies);
            configuration.categories.put(provider.getID(), StringUtil.join(disabledOptions, option -> option.getDisplayName(), ";"));
        } else {
            model.setShowDependencies(false);
        }
        try {
            model.refreshDataModel();
            // first limit elements by scope
            Collection<DiagramNode<Object>> nodesToRemove = new ArrayList<>();
            for (DiagramNode<Object> node : model.getNodes()) {
                if (node.getIdentifyingElement() instanceof JSClass && !scopeProvider.compute().contains(((JSClass) node.getIdentifyingElement()).getContainingFile().getVirtualFile())) {
                    nodesToRemove.add(node);
                }
            }
            for (DiagramNode<Object> node : nodesToRemove) {
                model.removeNode(node);
            }
            builder.updateGraph();
            // then add explicitly required classes
            for (String aClass : additionalClasses) {
                JSClass c = JSTestUtils.findClassByQName(aClass, GlobalSearchScope.allScope(myProject));
                final DiagramNode node = model.addElement(c);
                if (node != null) {
                    builder.createDraggedNode(node, node.getTooltip(), DiagramUtils.getBestPositionForNode(builder));
                    builder.updateGraph();
                }
            }
            assertModel(expectedPrefix, provider, actualOriginFqn, model);
        } finally {
            configuration.categories.put(provider.getID(), originalCategories);
        }
    }
    assert builder != null;
    return builder;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) VfsRootAccess(com.intellij.openapi.vfs.newvfs.impl.VfsRootAccess) VirtualFile(com.intellij.openapi.vfs.VirtualFile) ContentEntry(com.intellij.openapi.roots.ContentEntry) FlexStylesIndexableSetContributor(com.intellij.javascript.flex.css.FlexStylesIndexableSetContributor) ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) Disposer(com.intellij.openapi.util.Disposer) CommonDataKeys(com.intellij.openapi.actionSystem.CommonDataKeys) LoadTextUtil(com.intellij.openapi.fileEditor.impl.LoadTextUtil) DiagramBuilder(com.intellij.diagram.DiagramBuilder) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) ModifiableFlexBuildConfiguration(com.intellij.lang.javascript.flex.projectStructure.model.ModifiableFlexBuildConfiguration) JDOMCompare(com.intellij.util.JDOMCompare) Nullable(org.jetbrains.annotations.Nullable) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) ModuleRootManager(com.intellij.openapi.roots.ModuleRootManager) VfsUtilCore.convertFromUrl(com.intellij.openapi.vfs.VfsUtilCore.convertFromUrl) UmlDataModelDumper(com.intellij.diagram.util.UmlDataModelDumper) JdomKt(com.intellij.util.JdomKt) JSTestOptions(com.intellij.lang.javascript.JSTestOptions) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) ApplicationManager(com.intellij.openapi.application.ApplicationManager) DiagramProvider(com.intellij.diagram.DiagramProvider) VfsUtilCore.urlToPath(com.intellij.openapi.vfs.VfsUtilCore.urlToPath) java.util(java.util) CodeInsightTestCase(com.intellij.codeInsight.CodeInsightTestCase) ArrayUtil(com.intellij.util.ArrayUtil) DataContext(com.intellij.openapi.actionSystem.DataContext) JSTestOption(com.intellij.lang.javascript.JSTestOption) FlexModuleType(com.intellij.lang.javascript.flex.FlexModuleType) DiagramConfiguration(com.intellij.diagram.settings.DiagramConfiguration) FlashUmlDataModel(com.intellij.lang.javascript.uml.FlashUmlDataModel) Computable(com.intellij.openapi.util.Computable) ContainerUtil(com.intellij.util.containers.ContainerUtil) JDOMResult(org.jdom.transform.JDOMResult) UmlGraphBuilderFactory(com.intellij.uml.UmlGraphBuilderFactory) JDOMUtil(com.intellij.openapi.util.JDOMUtil) ModuleType(com.intellij.openapi.module.ModuleType) FlexTestUtils(com.intellij.flex.util.FlexTestUtils) DataManager(com.intellij.ide.DataManager) VfsUtilCore(com.intellij.openapi.vfs.VfsUtilCore) StringUtil(com.intellij.openapi.util.text.StringUtil) FlexSchemaHandler(com.intellij.javascript.flex.mxml.schema.FlexSchemaHandler) DiagramUtils(com.intellij.diagram.util.DiagramUtils) FlashUmlDependenciesSettingsOption(com.intellij.lang.javascript.uml.FlashUmlDependenciesSettingsOption) Sdk(com.intellij.openapi.projectRoots.Sdk) File(java.io.File) JSTestUtils(com.intellij.lang.javascript.JSTestUtils) SkipInHeadlessEnvironment(com.intellij.testFramework.SkipInHeadlessEnvironment) FlashUmlProvider(com.intellij.lang.javascript.uml.FlashUmlProvider) DiagramNode(com.intellij.diagram.DiagramNode) TargetElementUtil(com.intellij.codeInsight.TargetElementUtil) DiagramDataModel(com.intellij.diagram.DiagramDataModel) Element(org.jdom.Element) DiagramNode(com.intellij.diagram.DiagramNode) ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) DiagramBuilder(com.intellij.diagram.DiagramBuilder) DataContext(com.intellij.openapi.actionSystem.DataContext) DiagramConfiguration(com.intellij.diagram.settings.DiagramConfiguration) FlashUmlProvider(com.intellij.lang.javascript.uml.FlashUmlProvider) FlashUmlDependenciesSettingsOption(com.intellij.lang.javascript.uml.FlashUmlDependenciesSettingsOption) DiagramProvider(com.intellij.diagram.DiagramProvider) ModuleRootManager(com.intellij.openapi.roots.ModuleRootManager) ContentEntry(com.intellij.openapi.roots.ContentEntry) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass)

Example 2 with DiagramProvider

use of com.intellij.diagram.DiagramProvider in project intellij-plugins by JetBrains.

the class ShowUiRouterStatesNewDiagramAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    UsageTrigger.trigger(USAGE_KEY);
    final Project project = e.getProject();
    if (project == null)
        return;
    final AngularUiRouterDiagramProvider diagramProvider = (AngularUiRouterDiagramProvider) DiagramProvider.findByID(AngularUiRouterDiagramProvider.ANGULAR_UI_ROUTER);
    if (diagramProvider == null)
        return;
    List<Pair<String, AngularUiRouterGraphBuilder>> graphBuilders = new ArrayList<>();
    ProgressManager.getInstance().runProcessWithProgressSynchronously(() -> {
        ApplicationManager.getApplication().runReadAction(() -> {
            final AngularUiRouterDiagramBuilder builder = new AngularUiRouterDiagramBuilder(project);
            builder.build();
            final Map<VirtualFile, RootTemplate> rootTemplates = builder.getRootTemplates();
            for (Map.Entry<VirtualFile, Map<String, UiRouterState>> entry : builder.getDefiningFiles2States().entrySet()) {
                final AngularUiRouterGraphBuilder graphBuilder = new AngularUiRouterGraphBuilder(project, entry.getValue(), builder.getTemplatesMap(), null, entry.getKey());
                graphBuilders.add(Pair.create(entry.getKey().getName(), graphBuilder));
            }
            for (Map.Entry<VirtualFile, Map<String, UiRouterState>> entry : builder.getRootTemplates2States().entrySet()) {
                final AngularUiRouterGraphBuilder graphBuilder = new AngularUiRouterGraphBuilder(project, entry.getValue(), builder.getTemplatesMap(), rootTemplates.get(entry.getKey()), entry.getKey());
                graphBuilders.add(Pair.create(entry.getKey().getName(), graphBuilder));
            }
        });
    }, "Building " + diagramProvider.getPresentableName() + " diagram", false, project);
    final AngularUiRouterProviderContext routerProviderContext = AngularUiRouterProviderContext.getInstance(project);
    routerProviderContext.reset();
    final Consumer<AngularUiRouterGraphBuilder> consumer = graphBuilder -> {
        final AngularUiRouterGraphBuilder.GraphNodesBuilder nodesBuilder = graphBuilder.createDataModel(diagramProvider);
        routerProviderContext.registerNodesBuilder(nodesBuilder);
        final DiagramObject element = nodesBuilder.getRootNode().getIdentifyingElement();
        final Runnable callback = show(element, diagramProvider, project, null, Collections.emptyList());
        if (callback != null) {
            callback.run();
        }
    };
    if (graphBuilders.isEmpty()) {
        Messages.showInfoMessage(project, "No router states found.", DESCRIPTION);
        return;
    }
    if (graphBuilders.size() == 1)
        consumer.consume(graphBuilders.get(0).getSecond());
    else
        filterGraphBuilders(project, graphBuilders, consumer);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) DiagramProvider(com.intellij.diagram.DiagramProvider) ProgressManager(com.intellij.openapi.progress.ProgressManager) JBList(com.intellij.ui.components.JBList) ArrayUtil(com.intellij.util.ArrayUtil) VirtualFile(com.intellij.openapi.vfs.VirtualFile) AngularJSIcons(icons.AngularJSIcons) ArrayList(java.util.ArrayList) List(java.util.List) AngularIndexUtil(org.angularjs.index.AngularIndexUtil) JBPopupFactory(com.intellij.openapi.ui.popup.JBPopupFactory) ShowDiagram(com.intellij.uml.core.actions.ShowDiagram) Map(java.util.Map) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) Pair(com.intellij.openapi.util.Pair) ApplicationManager(com.intellij.openapi.application.ApplicationManager) Project(com.intellij.openapi.project.Project) Messages(com.intellij.openapi.ui.Messages) Collections(java.util.Collections) Consumer(com.intellij.util.Consumer) UsageTrigger(com.intellij.internal.statistic.UsageTrigger) ArrayList(java.util.ArrayList) Project(com.intellij.openapi.project.Project) Map(java.util.Map) Pair(com.intellij.openapi.util.Pair)

Aggregations

DiagramProvider (com.intellij.diagram.DiagramProvider)2 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)2 ApplicationManager (com.intellij.openapi.application.ApplicationManager)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 ArrayUtil (com.intellij.util.ArrayUtil)2 CodeInsightTestCase (com.intellij.codeInsight.CodeInsightTestCase)1 TargetElementUtil (com.intellij.codeInsight.TargetElementUtil)1 DiagramBuilder (com.intellij.diagram.DiagramBuilder)1 DiagramDataModel (com.intellij.diagram.DiagramDataModel)1 DiagramNode (com.intellij.diagram.DiagramNode)1 DiagramConfiguration (com.intellij.diagram.settings.DiagramConfiguration)1 DiagramUtils (com.intellij.diagram.util.DiagramUtils)1 UmlDataModelDumper (com.intellij.diagram.util.UmlDataModelDumper)1 FlexTestUtils (com.intellij.flex.util.FlexTestUtils)1 DataManager (com.intellij.ide.DataManager)1 UsageTrigger (com.intellij.internal.statistic.UsageTrigger)1 FlexStylesIndexableSetContributor (com.intellij.javascript.flex.css.FlexStylesIndexableSetContributor)1 FlexSchemaHandler (com.intellij.javascript.flex.mxml.schema.FlexSchemaHandler)1 JSTestOption (com.intellij.lang.javascript.JSTestOption)1 JSTestOptions (com.intellij.lang.javascript.JSTestOptions)1