| /* |
| * Copyright 2000-2014 JetBrains s.r.o. |
| * |
| * Licensed under the Apache License, Version 2.0 (the "License"); |
| * you may not use this file except in compliance with the License. |
| * You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software |
| * distributed under the License is distributed on an "AS IS" BASIS, |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| * See the License for the specific language governing permissions and |
| * limitations under the License. |
| */ |
| |
| package com.intellij.vcs.log.graph.impl.facade; |
| |
| import com.intellij.openapi.util.Condition; |
| import com.intellij.vcs.log.graph.GraphCommit; |
| import com.intellij.vcs.log.graph.actions.GraphAnswer; |
| import com.intellij.vcs.log.graph.api.LinearGraphWithCommitInfo; |
| import com.intellij.vcs.log.graph.api.permanent.PermanentGraphInfo; |
| import com.intellij.vcs.log.graph.api.elements.GraphElement; |
| import com.intellij.vcs.log.graph.api.printer.PrintElementsManager; |
| import com.intellij.vcs.log.graph.impl.print.FilterPrintElementsManager; |
| import com.intellij.vcs.log.graph.impl.visible.FilterGraphWithHiddenNodes; |
| import com.intellij.vcs.log.graph.impl.visible.adapters.GraphWithHiddenNodesAsGraphWithCommitInfo; |
| import com.intellij.vcs.log.graph.impl.visible.adapters.LinearGraphAsGraphWithHiddenNodes; |
| import org.jetbrains.annotations.NotNull; |
| import org.jetbrains.annotations.Nullable; |
| |
| import java.util.Map; |
| import java.util.Set; |
| |
| public class FilterVisibleGraph<CommitId> extends AbstractVisibleGraph<CommitId> { |
| |
| @NotNull |
| public static <CommitId> FilterVisibleGraph<CommitId> newInstance(@NotNull final PermanentGraphInfo<CommitId> permanentGraph, |
| @Nullable Set<CommitId> heads, |
| @NotNull final Condition<CommitId> filter) { |
| LinearGraphAsGraphWithHiddenNodes branchesGraph = createBranchesGraph(permanentGraph, heads); |
| Condition<Integer> isVisibleNode = new Condition<Integer>() { |
| @Override |
| public boolean value(Integer integer) { |
| CommitId commitId = permanentGraph.getPermanentCommitsInfo().getCommitId(integer); |
| return filter.value(commitId); |
| } |
| }; |
| FilterGraphWithHiddenNodes filterGraphWithHiddenNodes = new FilterGraphWithHiddenNodes(branchesGraph, isVisibleNode); |
| |
| GraphWithHiddenNodesAsGraphWithCommitInfo<CommitId> graphWithCommitInfo = |
| new GraphWithHiddenNodesAsGraphWithCommitInfo<CommitId>(filterGraphWithHiddenNodes, permanentGraph.getPermanentGraphLayout(), |
| permanentGraph.getPermanentCommitsInfo()); |
| |
| FilterPrintElementsManager printElementsManager = new FilterPrintElementsManager<CommitId>(graphWithCommitInfo, |
| permanentGraph.getGraphColorManager()); |
| return new FilterVisibleGraph<CommitId>(graphWithCommitInfo, filterGraphWithHiddenNodes, permanentGraph.getCommitsWithNotLoadParent(), |
| printElementsManager); |
| } |
| |
| @NotNull |
| @SuppressWarnings("all") |
| private final FilterGraphWithHiddenNodes myGraphWithHiddenNodes; |
| |
| private FilterVisibleGraph(@NotNull LinearGraphWithCommitInfo<CommitId> linearGraphWithCommitInfo, |
| @NotNull FilterGraphWithHiddenNodes graphWithHiddenNodes, |
| @NotNull Map<CommitId, GraphCommit<CommitId>> commitsWithNotLoadParent, |
| @NotNull PrintElementsManager printElementsManager) { |
| super(linearGraphWithCommitInfo, commitsWithNotLoadParent, printElementsManager); |
| myGraphWithHiddenNodes = graphWithHiddenNodes; |
| } |
| |
| @Override |
| protected void setLinearBranchesExpansion(boolean collapse) { |
| // do nothing |
| } |
| |
| @NotNull |
| protected GraphAnswer<CommitId> clickByElement(@NotNull GraphElement graphElement) { |
| // do nothing |
| return COMMIT_ID_GRAPH_ANSWER; |
| } |
| } |