Search in sources :

Example 1 with GraphNode

use of com.intellij.vcs.log.graph.api.elements.GraphNode in project intellij-community by JetBrains.

the class ColorGetterByLayoutIndex method getColorId.

public int getColorId(@NotNull GraphElement element) {
    int upNodeIndex, downNodeIndex;
    if (element instanceof GraphNode) {
        upNodeIndex = ((GraphNode) element).getNodeIndex();
        downNodeIndex = upNodeIndex;
    } else {
        GraphEdge edge = (GraphEdge) element;
        NormalEdge normalEdge = LinearGraphUtils.asNormalEdge(edge);
        if (normalEdge != null) {
            upNodeIndex = normalEdge.up;
            downNodeIndex = normalEdge.down;
        } else {
            upNodeIndex = LinearGraphUtils.getNotNullNodeIndex(edge);
            downNodeIndex = upNodeIndex;
        }
    }
    int upLayoutIndex = getLayoutIndex(upNodeIndex);
    int downLayoutIndex = getLayoutIndex(downNodeIndex);
    CommitId headCommitId = getOneOfHeads(upNodeIndex);
    if (upLayoutIndex != downLayoutIndex) {
        return myColorManager.getColorOfFragment(headCommitId, Math.max(upLayoutIndex, downLayoutIndex));
    }
    if (upLayoutIndex == myPermanentGraphInfo.getPermanentGraphLayout().getLayoutIndex(getHeadNodeId(upNodeIndex))) {
        return myColorManager.getColorOfBranch(headCommitId);
    } else {
        return myColorManager.getColorOfFragment(headCommitId, upLayoutIndex);
    }
}
Also used : NormalEdge(com.intellij.vcs.log.graph.utils.NormalEdge) GraphNode(com.intellij.vcs.log.graph.api.elements.GraphNode) GraphEdge(com.intellij.vcs.log.graph.api.elements.GraphEdge)

Example 2 with GraphNode

use of com.intellij.vcs.log.graph.api.elements.GraphNode in project intellij-community by JetBrains.

the class GraphElementComparatorByLayoutIndex method compare.

@Override
public int compare(@NotNull GraphElement o1, @NotNull GraphElement o2) {
    if (o1 instanceof GraphEdge && o2 instanceof GraphEdge) {
        GraphEdge edge1 = (GraphEdge) o1;
        GraphEdge edge2 = (GraphEdge) o2;
        NormalEdge normalEdge1 = asNormalEdge(edge1);
        NormalEdge normalEdge2 = asNormalEdge(edge2);
        if (normalEdge1 == null)
            return -compare2(edge2, new GraphNode(getNotNullNodeIndex(edge1)));
        if (normalEdge2 == null)
            return compare2(edge1, new GraphNode(getNotNullNodeIndex(edge2)));
        if (normalEdge1.up == normalEdge2.up) {
            if (getLayoutIndex(normalEdge1.down) != getLayoutIndex(normalEdge2.down)) {
                return getLayoutIndex(normalEdge1.down) - getLayoutIndex(normalEdge2.down);
            } else {
                return normalEdge1.down - normalEdge2.down;
            }
        }
        if (normalEdge1.up < normalEdge2.up) {
            return compare2(edge1, new GraphNode(normalEdge2.up));
        } else {
            return -compare2(edge2, new GraphNode(normalEdge1.up));
        }
    }
    if (o1 instanceof GraphEdge && o2 instanceof GraphNode)
        return compare2((GraphEdge) o1, (GraphNode) o2);
    if (o1 instanceof GraphNode && o2 instanceof GraphEdge)
        return -compare2((GraphEdge) o2, (GraphNode) o1);
    // both GraphNode
    assert false;
    return 0;
}
Also used : NormalEdge(com.intellij.vcs.log.graph.utils.NormalEdge) LinearGraphUtils.asNormalEdge(com.intellij.vcs.log.graph.utils.LinearGraphUtils.asNormalEdge) GraphNode(com.intellij.vcs.log.graph.api.elements.GraphNode) GraphEdge(com.intellij.vcs.log.graph.api.elements.GraphEdge)

Example 3 with GraphNode

use of com.intellij.vcs.log.graph.api.elements.GraphNode in project intellij-community by JetBrains.

the class LinearFragmentGenerator method getRelativeFragment.

@Nullable
public GraphFragment getRelativeFragment(@NotNull GraphElement element) {
    int upNodeIndex;
    int downNodeIndex;
    if (element instanceof GraphNode) {
        upNodeIndex = ((GraphNode) element).getNodeIndex();
        downNodeIndex = upNodeIndex;
    } else {
        NormalEdge graphEdge = LinearGraphUtils.asNormalEdge(((GraphEdge) element));
        if (graphEdge == null)
            return null;
        upNodeIndex = graphEdge.up;
        downNodeIndex = graphEdge.down;
    }
    for (int i = 0; i < MAX_SEARCH_SIZE; i++) {
        GraphFragment graphFragment = getDownFragment(upNodeIndex);
        if (graphFragment != null && graphFragment.downNodeIndex >= downNodeIndex)
            return graphFragment;
        List<Integer> upNodes = myLinearGraph.getNodes(upNodeIndex, UP);
        if (upNodes.size() != 1) {
            break;
        }
        upNodeIndex = upNodes.get(0);
    }
    return null;
}
Also used : NormalEdge(com.intellij.vcs.log.graph.utils.NormalEdge) GraphNode(com.intellij.vcs.log.graph.api.elements.GraphNode) GraphEdge(com.intellij.vcs.log.graph.api.elements.GraphEdge) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with GraphNode

use of com.intellij.vcs.log.graph.api.elements.GraphNode in project intellij-community by JetBrains.

the class PrintElementManagerImpl method isSelected.

@Override
public boolean isSelected(@NotNull PrintElementWithGraphElement printElement) {
    if (printElement.equals(mySelectedPrintElement))
        return true;
    GraphElement graphElement = printElement.getGraphElement();
    if (graphElement instanceof GraphNode) {
        int nodeId = myLinearGraph.getNodeId(((GraphNode) graphElement).getNodeIndex());
        return mySelectedNodeIds.contains(nodeId);
    }
    if (graphElement instanceof GraphEdge) {
        GraphEdge edge = (GraphEdge) graphElement;
        boolean selected = edge.getTargetId() == null || mySelectedNodeIds.contains(edge.getTargetId());
        selected &= edge.getUpNodeIndex() == null || mySelectedNodeIds.contains(myLinearGraph.getNodeId(edge.getUpNodeIndex()));
        selected &= edge.getDownNodeIndex() == null || mySelectedNodeIds.contains(myLinearGraph.getNodeId(edge.getDownNodeIndex()));
        return selected;
    }
    return false;
}
Also used : GraphElement(com.intellij.vcs.log.graph.api.elements.GraphElement) PrintElementWithGraphElement(com.intellij.vcs.log.graph.impl.print.elements.PrintElementWithGraphElement) GraphNode(com.intellij.vcs.log.graph.api.elements.GraphNode) GraphEdge(com.intellij.vcs.log.graph.api.elements.GraphEdge)

Example 5 with GraphNode

use of com.intellij.vcs.log.graph.api.elements.GraphNode in project intellij-community by JetBrains.

the class CollapsedController method convertToDelegate.

@Nullable
public static GraphElement convertToDelegate(@NotNull GraphElement graphElement, CollapsedGraph collapsedGraph) {
    if (graphElement instanceof GraphEdge) {
        Integer upIndex = ((GraphEdge) graphElement).getUpNodeIndex();
        Integer downIndex = ((GraphEdge) graphElement).getDownNodeIndex();
        if (upIndex != null && downIndex != null && collapsedGraph.isMyCollapsedEdge(upIndex, downIndex))
            return null;
        Integer convertedUpIndex = upIndex == null ? null : collapsedGraph.convertToDelegateNodeIndex(upIndex);
        Integer convertedDownIndex = downIndex == null ? null : collapsedGraph.convertToDelegateNodeIndex(downIndex);
        return new GraphEdge(convertedUpIndex, convertedDownIndex, ((GraphEdge) graphElement).getTargetId(), ((GraphEdge) graphElement).getType());
    } else if (graphElement instanceof GraphNode) {
        return new GraphNode(collapsedGraph.convertToDelegateNodeIndex((((GraphNode) graphElement).getNodeIndex())), ((GraphNode) graphElement).getType());
    }
    return null;
}
Also used : GraphNode(com.intellij.vcs.log.graph.api.elements.GraphNode) GraphEdge(com.intellij.vcs.log.graph.api.elements.GraphEdge) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

GraphNode (com.intellij.vcs.log.graph.api.elements.GraphNode)10 GraphEdge (com.intellij.vcs.log.graph.api.elements.GraphEdge)9 Nullable (org.jetbrains.annotations.Nullable)4 GraphElement (com.intellij.vcs.log.graph.api.elements.GraphElement)3 NormalEdge (com.intellij.vcs.log.graph.utils.NormalEdge)3 NotNull (org.jetbrains.annotations.NotNull)2 Pair (com.intellij.openapi.util.Pair)1 SmartList (com.intellij.util.SmartList)1 GraphEdgeType (com.intellij.vcs.log.graph.api.elements.GraphEdgeType)1 PrintElementWithGraphElement (com.intellij.vcs.log.graph.impl.print.elements.PrintElementWithGraphElement)1 EdgeNodeCharConverter.parseGraphEdgeType (com.intellij.vcs.log.graph.parser.EdgeNodeCharConverter.parseGraphEdgeType)1 LinearGraphUtils.asNormalEdge (com.intellij.vcs.log.graph.utils.LinearGraphUtils.asNormalEdge)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1