Search in sources :

Example 1 with Identifiable

use of com.intellij.openapi.externalSystem.model.project.Identifiable in project intellij-community by JetBrains.

the class ExternalProjectDataSelectorDialog method createRoot.

private Couple<CheckedTreeNode> createRoot() {
    final Map<DataNode, DataNodeCheckedTreeNode> treeNodeMap = ContainerUtil.newIdentityTroveMap();
    final DataNodeCheckedTreeNode[] preselectedNode = { null };
    final DataNodeCheckedTreeNode[] rootModuleNode = { null };
    final MultiMap<String, String> moduleDependenciesMap = MultiMap.create();
    final Map<String, DataNode<Identifiable>> modulesNodeMap = ContainerUtil.newHashMap();
    for (DataNode<ModuleDependencyData> moduleDependencyDataNode : ExternalSystemApiUtil.findAllRecursively(myProjectInfo.getExternalProjectStructure(), ProjectKeys.MODULE_DEPENDENCY)) {
        final ModuleDependencyData moduleDependencyData = moduleDependencyDataNode.getData();
        moduleDependenciesMap.putValue(moduleDependencyData.getOwnerModule().getId(), moduleDependencyData.getTarget().getId());
    }
    final int[] modulesCount = { 0 };
    ExternalSystemApiUtil.visit(myProjectInfo.getExternalProjectStructure(), node -> {
        final Key key = node.getKey();
        if (!myPublicKeys.contains(key))
            return;
        DataNode modifiableDataNode = getModifiableDataNode(node);
        if (myDependencyAwareDataKeys.contains(key)) {
            modulesCount[0]++;
        }
        if (modifiableDataNode.isIgnored() && myShowSelectedRowsOnly)
            return;
        DataNodeCheckedTreeNode treeNode = treeNodeMap.get(node);
        if (treeNode == null) {
            treeNode = new DataNodeCheckedTreeNode(node);
            if (myDependencyAwareDataKeys.contains(key)) {
                final Identifiable moduleData = (Identifiable) node.getData();
                modulesNodeMap.put(moduleData.getId(), (DataNode<Identifiable>) node);
            }
            if (myPreselectedNodeObject != null && myPreselectedNodeObject.equals(node.getData())) {
                preselectedNode[0] = treeNode;
            }
            if (node.getData() instanceof ModuleData) {
                if (key.equals(ProjectKeys.MODULE) && myProjectInfo.getExternalProjectPath().equals(((ModuleData) node.getData()).getLinkedExternalProjectPath())) {
                    rootModuleNode[0] = treeNode;
                }
            }
            treeNode.setEnabled(myIgnorableKeys.contains(key));
            treeNodeMap.put(node, treeNode);
            final DataNode parent = node.getParent();
            if (parent != null) {
                final CheckedTreeNode parentTreeNode = treeNodeMap.get(parent);
                if (parentTreeNode != null) {
                    parentTreeNode.add(treeNode);
                }
            }
        }
    });
    myModulesCount = modulesCount[0];
    dependentNodeMap.clear();
    for (String moduleId : moduleDependenciesMap.keySet()) {
        final Collection<String> moduleDependencies = moduleDependenciesMap.get(moduleId);
        final DataNode<Identifiable> moduleNode = modulesNodeMap.get(moduleId);
        if (moduleNode != null) {
            dependentNodeMap.putValues(moduleNode, ContainerUtil.mapNotNull(moduleDependencies, modulesNodeMap::get));
        }
    }
    final CheckedTreeNode root = new CheckedTreeNode(null);
    final DataNodeCheckedTreeNode projectNode = treeNodeMap.get(myProjectInfo.getExternalProjectStructure());
    String rootModuleComment = "root module";
    if (rootModuleNode[0] != null && projectNode != null) {
        rootModuleNode[0].comment = rootModuleComment;
        if (!projectNode.isNodeChild(rootModuleNode[0])) {
            projectNode.add(rootModuleNode[0]);
        }
    }
    List<TreeNode> nodes = projectNode != null ? TreeUtil.listChildren(projectNode) : ContainerUtil.emptyList();
    Collections.sort(nodes, (o1, o2) -> {
        if (o1 instanceof DataNodeCheckedTreeNode && o2 instanceof DataNodeCheckedTreeNode) {
            if (rootModuleComment.equals(((DataNodeCheckedTreeNode) o1).comment))
                return -1;
            if (rootModuleComment.equals(((DataNodeCheckedTreeNode) o2).comment))
                return 1;
            return StringUtil.naturalCompare(((DataNodeCheckedTreeNode) o1).text, ((DataNodeCheckedTreeNode) o2).text);
        }
        return 0;
    });
    TreeUtil.addChildrenTo(root, nodes);
    return Couple.of(root, preselectedNode[0]);
}
Also used : Identifiable(com.intellij.openapi.externalSystem.model.project.Identifiable) DataNode(com.intellij.openapi.externalSystem.model.DataNode) TreeNode(javax.swing.tree.TreeNode) ModuleData(com.intellij.openapi.externalSystem.model.project.ModuleData) ModuleDependencyData(com.intellij.openapi.externalSystem.model.project.ModuleDependencyData) Key(com.intellij.openapi.externalSystem.model.Key)

Example 2 with Identifiable

use of com.intellij.openapi.externalSystem.model.project.Identifiable in project intellij-community by JetBrains.

the class ExternalProjectDataSelectorDialog method getDependencyAwareDataKeys.

@NotNull
private static Set<Key<? extends Identifiable>> getDependencyAwareDataKeys() {
    Set<Key<? extends Identifiable>> result = ContainerUtil.newHashSet();
    result.add(ProjectKeys.MODULE);
    for (ExternalProjectStructureCustomizer customizer : ExternalProjectStructureCustomizer.EP_NAME.getExtensions()) {
        result.addAll(customizer.getDependencyAwareDataKeys());
    }
    return result;
}
Also used : ExternalProjectStructureCustomizer(com.intellij.openapi.externalSystem.importing.ExternalProjectStructureCustomizer) Key(com.intellij.openapi.externalSystem.model.Key) Identifiable(com.intellij.openapi.externalSystem.model.project.Identifiable) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

Key (com.intellij.openapi.externalSystem.model.Key)2 Identifiable (com.intellij.openapi.externalSystem.model.project.Identifiable)2 ExternalProjectStructureCustomizer (com.intellij.openapi.externalSystem.importing.ExternalProjectStructureCustomizer)1 DataNode (com.intellij.openapi.externalSystem.model.DataNode)1 ModuleData (com.intellij.openapi.externalSystem.model.project.ModuleData)1 ModuleDependencyData (com.intellij.openapi.externalSystem.model.project.ModuleDependencyData)1 TreeNode (javax.swing.tree.TreeNode)1 NotNull (org.jetbrains.annotations.NotNull)1